diff options
author | ficus <ficus@robocracy.org> | 2012-09-15 22:11:53 +0200 |
---|---|---|
committer | ficus <ficus@robocracy.org> | 2012-09-15 22:11:53 +0200 |
commit | 57a1e70dee45f5cd9493d6d23f8fc7b6435d5388 (patch) | |
tree | 24665ec2db4fcafb3b9890d2ac3c06d32f51569c | |
parent | 22c3233245584dd4b20a8b654f421d766688f3d1 (diff) | |
download | tui-57a1e70dee45f5cd9493d6d23f8fc7b6435d5388.tar.gz tui-57a1e70dee45f5cd9493d6d23f8fc7b6435d5388.zip |
code style
-rw-r--r-- | helpers/__init__.py | 1 | ||||
-rw-r--r-- | helpers/netif.py | 8 | ||||
-rw-r--r-- | helpers/sysstatus.py | 2 | ||||
-rw-r--r-- | helpers/tor.py | 3 | ||||
-rwxr-xr-x | torouterui.py | 43 |
5 files changed, 31 insertions, 26 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index e69de29..8b13789 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -0,0 +1 @@ + diff --git a/helpers/netif.py b/helpers/netif.py index 529444d..d8347a0 100644 --- a/helpers/netif.py +++ b/helpers/netif.py @@ -66,7 +66,7 @@ def parse_iw(ifname): If the interface can not be found at all, raises a KeyError. Example `iw dev wlan0 link` string (sic): - + Connected to c0:25:06:51:22:9b (on wlan0) SSID: fleischfressendepflanze freq: 2427 @@ -212,7 +212,7 @@ def get_lan_settings(ifname='eth0'): d = read_augeas_ifinfo(ifname) return d -def save_lan_settings(ifname='eth0'): +def save_lan_settings(form, ifname='eth0'): write_augeas_ifinfo(ifname, method=form['ipv4method'], settings=form) if form['ipv4method'] == 'disabled': print "ifdown..." @@ -225,9 +225,9 @@ def save_lan_settings(ifname='eth0'): def get_wifi_settings(ifname='wlan0'): #d = read_augeas_ifinfo(ifname) d = dict() - if not d: + if not d: return d - d.update(dict()) # extra wireless settings + d.update(dict()) # extra wireless settings return d def save_wifi_settings(ifname='eth0'): diff --git a/helpers/sysstatus.py b/helpers/sysstatus.py index 99c209b..32caa26 100644 --- a/helpers/sysstatus.py +++ b/helpers/sysstatus.py @@ -80,7 +80,7 @@ def get_process_list(): Example ``ps aux`` output: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND - root 1 0.0 0.0 10636 676 ? Ss Sep08 0:05 init [2] + root 1 0.0 0.0 10636 676 ? Ss Sep08 0:05 init [2] root 2 0.0 0.0 0 0 ? S Sep08 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Sep08 0:40 [ksoftirqd/0] root 6 0.0 0.0 0 0 ? S Sep08 0:00 [migration/0] diff --git a/helpers/tor.py b/helpers/tor.py index d639ce2..ef585c5 100644 --- a/helpers/tor.py +++ b/helpers/tor.py @@ -3,13 +3,16 @@ Helper code for interacting with Tor and modifying the Tor system configuration. """ + def get_tor_status(): d = dict() d['state'] = 'DISABLED' return d + def get_tor_settings(): return dict() + def save_tor_settings(): pass diff --git a/torouterui.py b/torouterui.py index 4ef37fb..fe72475 100755 --- a/torouterui.py +++ b/torouterui.py @@ -26,7 +26,7 @@ app = Flask(__name__) @app.route('/') -def status(): +def statuspage(): status = dict() status['system'] = sysstatus.get_system_status() status['resources'] = sysstatus.get_resources_status() @@ -37,11 +37,11 @@ def status(): return render_template('home.html', settings=None, status=status) @app.route('/reboot/', methods=['GET', 'POST']) -def administer(): +def rebootpage(): msg = list() if request.method == 'GET': return render_template('reboot.html', status=None) - elif request.form.has_key('confirm'): + elif 'confirm' in request.form: # TODO: actually execute reboot #os.system('reboot &') return render_template('reboot.html', status='rebooting') @@ -50,7 +50,7 @@ def administer(): return render_template('reboot.html', status=None, messages=msg) @app.route('/wan/', methods=['GET', 'POST']) -def wan(): +def wanpage(): msg = list() status = dict(wan=netif.get_wan_status()) if not status['wan']: @@ -65,9 +65,9 @@ def wan(): # Got this far, need to validated form formerr = dict() if request.form['ipv4method'] == 'disabled': - pass # no further validation + pass # no further validation elif request.form['ipv4method'] == 'dhcp': - pass # no further validation + pass # no further validation elif request.form['ipv4method'] == 'static': if not netif.is_valid_ipv4(request.form['ipv4addr']): formerr['ipv4addr'] = "Not a valid IPv4 address" @@ -80,7 +80,7 @@ def wan(): print ke raise ke if len(formerr.keys()) > 0: - msg.append(("error", + msg.append(("error", "Please correct the validation issues below"),) else: # Ok, we have a valid form, now to commit it @@ -89,14 +89,14 @@ def wan(): msg.append(("success", "Configuration saved! Check logs for any errors"),) except IOError, ioerr: - msg.append(("error", - "Was unable to commit changes... permissions problem? \"%s\"" \ + msg.append(("error", + "Was unable to commit changes... permissions problem? \"%s\"" % ioerr)) return render_template('wan.html', form=request.form, status=status, formerr=formerr, messages=msg) @app.route('/lan/', methods=['GET', 'POST']) -def lan(): +def lanpage(): msg = list() status = dict() status['lan'] = netif.get_lan_status() @@ -112,7 +112,7 @@ def lan(): # Got this far, need to validated form formerr = dict() if request.form['ipv4method'] == 'disabled': - pass # no further validation + pass # no further validation elif request.form['ipv4method'] == 'static': if not netif.is_valid_ipv4(request.form['ipv4addr']): formerr['ipv4addr'] = "Not a valid IPv4 address" @@ -125,7 +125,7 @@ def lan(): print ke raise ke if len(formerr.keys()) > 0: - msg.append(("error", + msg.append(("error", "Please correct the validation issues below"),) else: # Ok, we have a valid form, now to commit it @@ -134,14 +134,15 @@ def lan(): msg.append(("success", "Configuration saved! Check logs for any errors"),) except IOError, ioerr: - msg.append(("error", - "Was unable to commit changes... permissions problem? \"%s\"" \ + msg.append(("error", + "Was unable to commit changes... permissions problem? \"%s\"" % ioerr)) return render_template('lan.html', form=request.form, status=status, formerr=formerr, messages=msg) @app.route('/wifi/', methods=['GET', 'POST']) -def wifi(): +def wifipage(): + msg = list() status = dict() status['wifi'] = netif.get_wifi_status() if not status['wifi']: @@ -156,7 +157,7 @@ def wifi(): # Got this far, need to validated form formerr = dict() if request.form['ipv4method'] == 'disabled': - pass # no further validation + pass # no further validation elif request.form['ipv4method'] == 'static': if not netif.is_valid_ipv4(request.form['ipv4addr']): formerr['ipv4addr'] = "Not a valid IPv4 address" @@ -169,7 +170,7 @@ def wifi(): print ke raise ke if len(formerr.keys()) > 0: - msg.append(("error", + msg.append(("error", "Please correct the validation issues below"),) else: # Ok, we have a valid form, now to commit it @@ -178,8 +179,8 @@ def wifi(): msg.append(("success", "Configuration saved! Check logs for any errors"),) except IOError, ioerr: - msg.append(("error", - "Was unable to commit changes... permissions problem? \"%s\"" \ + msg.append(("error", + "Was unable to commit changes... permissions problem? \"%s\"" % ioerr)) return render_template('wifi.html', form=request.form, status=status, formerr=formerr, messages=msg) @@ -193,7 +194,7 @@ def torpage(): form=request.form, formerr=None, messages=msg) @app.route('/logs/', methods=['GET']) -def logs(): +def logspage(): logs = dict() logs['dmesg'] = sysstatus.get_dmesg() logs['syslog'] = sysstatus.get_syslog() @@ -201,7 +202,7 @@ def logs(): return render_template('logs.html', logs=logs) @app.route('/processes/', methods=['GET']) -def processes(): +def processespage(): process_list = sysstatus.get_process_list() return render_template('processes.html', process_list=process_list) |