aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--torouterui/netif.py57
-rw-r--r--torouterui/server.py24
-rw-r--r--torouterui/sysstatus.py5
3 files changed, 71 insertions, 15 deletions
diff --git a/torouterui/netif.py b/torouterui/netif.py
index d8347a0..9922025 100644
--- a/torouterui/netif.py
+++ b/torouterui/netif.py
@@ -6,6 +6,7 @@ Helper functions for working with network interfaces and network configuration
import os
import augeas
+from torouterui import app
from util import *
def parse_ip(ifname):
@@ -170,7 +171,10 @@ def write_augeas_ifinfo(ifname, settings, method='disabled'):
print "augeas errors: %s" % aug.get("/augeas/error")
aug.close()
-def get_wan_status(ifname='eth0'):
+def get_wan_status(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WAN_IF']
d = dict()
try:
d.update(parse_ip(ifname))
@@ -178,7 +182,10 @@ def get_wan_status(ifname='eth0'):
return None
return d
-def get_lan_status(ifname='eth0'):
+def get_lan_status(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['LAN_IF']
d = dict()
try:
d.update(parse_ip(ifname))
@@ -186,19 +193,31 @@ def get_lan_status(ifname='eth0'):
return None
return d
-def get_wifi_status(ifname='wlan0'):
+def get_wifi_status(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WIFI_IF']
d = dict()
try:
d.update(parse_ip(ifname))
except KeyError, ke:
return None
- d.update(parse_iw(ifname))
+ if ifname.startswith('wlan'):
+ d.update(parse_iw(ifname))
+ else:
+ raise NotImplementedError("uap wifi status not yet implemented")
return d
-def get_wan_settings(ifname='eth0'):
+def get_wan_settings(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WAN_IF']
return read_augeas_ifinfo(ifname)
-def save_wan_settings(form, ifname='eth0'):
+def save_wan_settings(form, ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WAN_IF']
write_augeas_ifinfo(ifname, method=form['ipv4method'], settings=form)
if form['ipv4method'] == 'disabled':
print "ifdown..."
@@ -208,11 +227,17 @@ def save_wan_settings(form, ifname='eth0'):
os.system("ifdown %s" % ifname)
os.system("ifup %s &" % ifname)
-def get_lan_settings(ifname='eth0'):
+def get_lan_settings(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['LAN_IF']
d = read_augeas_ifinfo(ifname)
return d
-def save_lan_settings(form, ifname='eth0'):
+def save_lan_settings(form, ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['LAN_IF']
write_augeas_ifinfo(ifname, method=form['ipv4method'], settings=form)
if form['ipv4method'] == 'disabled':
print "ifdown..."
@@ -222,15 +247,24 @@ def save_lan_settings(form, ifname='eth0'):
os.system("ifdown %s" % ifname)
os.system("ifup %s &" % ifname)
-def get_wifi_settings(ifname='wlan0'):
+def get_wifi_settings(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WIFI_IF']
#d = read_augeas_ifinfo(ifname)
d = dict()
if not d:
return d
- d.update(dict()) # extra wireless settings
+ if ifname.startswith('wlan'):
+ d.update(dict()) # extra wireless settings
+ else:
+ raise NotImplementedError("uap wifi settings not yet implemented")
return d
-def save_wifi_settings(ifname='eth0'):
+def save_wifi_settings(ifname=None):
+ if not ifname:
+ # grab configuration at run time, not earlier
+ ifname = app.config['WIFI_IF']
pass
def is_valid_ipv4(s):
@@ -260,3 +294,4 @@ def is_valid_ipv4mask(s):
if l[0] > 255 or l[1] > 255 or l[2] > 255 or l[3] > 255:
return False
return True
+
diff --git a/torouterui/server.py b/torouterui/server.py
index 17cd5ca..8ae4a3a 100644
--- a/torouterui/server.py
+++ b/torouterui/server.py
@@ -7,7 +7,27 @@ def main():
"""Primary entry-point for torouterui.
"""
parser = argparse.ArgumentParser()
- parser.add_argument('--debug', action='store_true',
+ parser.add_argument('--debug',
+ action='store_true',
help="enable debugging interface")
+ parser.add_argument('--host',
+ default="127.0.0.1",
+ help="listen on this host/IP")
+ parser.add_argument('--port',
+ type=int,
+ default=5050,
+ help="listen on this port")
+ parser.add_argument('--lanif',
+ default="eth1",
+ help="local ethernet interface (eth0 or eth1)")
+ parser.add_argument('--wanif',
+ default="eth0",
+ help="upstream ethernet interface (eth0 or eth1)")
+ parser.add_argument('--wifiif',
+ default="uap0",
+ help="wifi interface (uap0 or wlan0)")
args = parser.parse_args()
- app.run(debug=args.debug)
+ app.config['LAN_IF'] = args.lanif
+ app.config['WAN_IF'] = args.wanif
+ app.config['WIFI_IF'] = args.wifiif
+ app.run(debug=args.debug, host=args.host, port=args.port)
diff --git a/torouterui/sysstatus.py b/torouterui/sysstatus.py
index 32caa26..2d19458 100644
--- a/torouterui/sysstatus.py
+++ b/torouterui/sysstatus.py
@@ -10,10 +10,11 @@ from util import *
def get_system_status():
d = dict()
d['hostname'] = cli_read('hostname')
- d['fqdn'] = cli_read('hostname -f')
- d['domain'] = cli_read('hostname -d')
d['current_time'] = cli_read('date -R')
d['uptime'] = cli_read('uptime')
+ # the following do DNS lookups and execute very slowly
+ #d['fqdn'] = cli_read('hostname -f')
+ #d['domain'] = cli_read('hostname -d')
return d
def get_resources_status():