nbhw16-ctrl.py: update to networkmanager, etc.
This commit is contained in:
parent
85a0f958b5
commit
a86f2b5cea
|
|
@ -30,39 +30,96 @@ def write_to_modem(data, read=False):
|
|||
return data
|
||||
|
||||
|
||||
def get_modem():
|
||||
interface = "eth2"
|
||||
try:
|
||||
call_and_throw("ifconfig {0} &> /dev/null".format(interface))
|
||||
except:
|
||||
interface = "usb0"
|
||||
# Make sure that we now have a valid modem
|
||||
call_and_throw("ifconfig {0} &> /dev/null".format(interface))
|
||||
return interface
|
||||
|
||||
|
||||
def setup_modem(provider):
|
||||
if provider == "swisscom":
|
||||
write_to_modem("AT^NDISDUP=1,1,\"gprs.swisscom.ch\"\r\n")
|
||||
|
||||
apn = "gprs.swisscom.ch"
|
||||
if provider == "salt":
|
||||
write_to_modem("AT^NDISDUP=1,1,\"click\"\r\n")
|
||||
apn = "click"
|
||||
|
||||
call_and_throw("udhcpc -i {0}".format(get_modem()))
|
||||
modem_config = """[connection]
|
||||
id=Modem
|
||||
type=gsm
|
||||
interface-name=ttyUSB2
|
||||
permissions=
|
||||
secondaries=
|
||||
|
||||
[gsm]
|
||||
apn={0}
|
||||
number=*99#
|
||||
|
||||
[ipv4]
|
||||
dns-search=
|
||||
method=auto
|
||||
|
||||
[ipv6]
|
||||
dns-search=
|
||||
method=auto
|
||||
""".format(apn)
|
||||
|
||||
f = open("/etc/NetworkManager/system-connections/Modem", "w")
|
||||
f.write(modem_config)
|
||||
f.close()
|
||||
|
||||
call_and_throw("chmod 600 /etc/NetworkManager/system-connections/Modem")
|
||||
call_and_throw("nmcli c load /etc/NetworkManager/system-connections/Modem")
|
||||
call_and_throw("nmcli c up Modem")
|
||||
|
||||
|
||||
def setup_ap():
|
||||
call_and_throw("ifconfig {0} 192.168.0.1".format(WLAN_INTERFACE))
|
||||
# Start udhcpd with config from /etc/udhcpd.conf
|
||||
call_and_throw("udhcpd")
|
||||
ap_config = """ [connection]
|
||||
id=Wifi
|
||||
type=wifi
|
||||
interface-name=wlan0
|
||||
autoconnect=true
|
||||
permissions=
|
||||
secondaries=
|
||||
|
||||
[wifi]
|
||||
band=bg
|
||||
mac-address-blacklist=
|
||||
mode=ap
|
||||
seen-bssids=
|
||||
ssid=test
|
||||
|
||||
[wifi-security]
|
||||
auth-alg=open
|
||||
group=ccmp;
|
||||
key-mgmt=wpa-psk
|
||||
pairwise=ccmp;
|
||||
proto=rsn;
|
||||
psk=NetModu1e
|
||||
|
||||
[ipv4]
|
||||
address1=192.168.0.1/24
|
||||
dns-search=
|
||||
method=manual
|
||||
|
||||
[ipv6]
|
||||
dns-search=
|
||||
method=auto
|
||||
"""
|
||||
f = open("/etc/NetworkManager/system-connections/Wifi", "w")
|
||||
f.write(ap_config)
|
||||
f.close()
|
||||
call_and_throw("chmod 600 /etc/NetworkManager/system-connections/Wifi")
|
||||
call_and_throw("nmcli c load /etc/NetworkManager/system-connections/Wifi")
|
||||
call_and_throw("nmcli c up Wifi")
|
||||
|
||||
dnsmasq_config = """
|
||||
domain-needed
|
||||
bogus-priv
|
||||
dhcp-range=192.168.0.100,192.168.0.200,12h
|
||||
"""
|
||||
f = open("/etc/dnsmasq.conf", "w")
|
||||
f.write(dnsmasq_config)
|
||||
f.close()
|
||||
call_and_throw("systemctl restart dnsmasq")
|
||||
|
||||
|
||||
def setup_routing():
|
||||
f = open("/proc/sys/net/ipv4/ip_forward", "w")
|
||||
f.write("1\n")
|
||||
f.close()
|
||||
call_and_throw("iptables -t nat -A POSTROUTING -o {0} -j MASQUERADE".
|
||||
format(get_modem()))
|
||||
call_and_throw("iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE")
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Reference in New Issue