aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorficus <ficus@robocracy.org>2012-09-25 11:46:08 +0200
committerficus <ficus@robocracy.org>2012-09-25 11:46:08 +0200
commitfe4b8a01fc87d1a76fca8e8733270a260aa23cc0 (patch)
tree54f0681925314972d25de0a68da398134123902c
parent49ec1f025b529c52eaee50af37ffc0b23a9f7124 (diff)
downloadtui-fe4b8a01fc87d1a76fca8e8733270a260aa23cc0.tar.gz
tui-fe4b8a01fc87d1a76fca8e8733270a260aa23cc0.zip
basic tor status using python-torctl
-rw-r--r--debian/control2
-rw-r--r--torouterui/templates/home.html16
-rw-r--r--torouterui/tor.py42
3 files changed, 54 insertions, 6 deletions
diff --git a/debian/control b/debian/control
index e91acfb..7733b3f 100644
--- a/debian/control
+++ b/debian/control
@@ -7,6 +7,6 @@ Standards-Version: 3.9.1
Package: torouterui
Architecture: all
-Depends: ${misc:Depends}, ${python:Depends}, python-setuptools, uaputl, python-flask, python-augeas, hostname, ifupdown, iw
+Depends: ${misc:Depends}, ${python:Depends}, python-setuptools, uaputl, python-flask, python-augeas, hostname, ifupdown, iw, python-torctl
Description: torouter configuration web interface
diff --git a/torouterui/templates/home.html b/torouterui/templates/home.html
index fa2ed2b..58ed2f2 100644
--- a/torouterui/templates/home.html
+++ b/torouterui/templates/home.html
@@ -57,13 +57,25 @@
</div>
<div class="span6">
<h3>Tor</h3>
- <table class="table table-condensed {% if status.tor.state in ["DISABLED"] %}muted{% endif %}">
+ <table class="table table-condensed {% if status.tor.state in ["DISABLED", "PERMISSION_DENIED"] %}muted{% endif %}">
<tr>
<th>Status
<td><span style="font-weight: bold;" class="label
- {% if status.tor.state == 'RUNNING' %}label-success{% elif status.tor.state == 'STARTING' %}label-info{% else %}label-important{% endif %}">
+ {% if status.tor.state == 'ESTABLISHED' %}label-success{% elif status.tor.state == 'CONNECTING' %}label-info{% else %}label-important{% endif %}">
{{ status.tor.state }}
</span>
+ <tr>
+ <th>Circuit Established?
+ <td style="font-family: monospace;">{{ status.tor.circuit_established }}
+ <tr>
+ <th>Version
+ <td style="font-family: monospace;">{% if status.tor.version %}{{ status.tor.version }} ({{ status.tor.version_current }}){% endif %}
+ <tr>
+ <th>Traffic TX
+ <td style="font-family: monospace;">{% if status.tor.traffic_written_bytes %}{{ status.tor.traffic_written_bytes }} bytes{% endif %}
+ <tr>
+ <th>Traffic RX
+ <td style="font-family: monospace;">{% if status.tor.traffic_read_bytes %}{{ status.tor.traffic_read_bytes }} bytes{% endif %}
</table>
</div>
</div>
diff --git a/torouterui/tor.py b/torouterui/tor.py
index ef585c5..cf18ce2 100644
--- a/torouterui/tor.py
+++ b/torouterui/tor.py
@@ -3,16 +3,52 @@ Helper code for interacting with Tor and modifying the Tor system
configuration.
"""
+from TorCtl import TorCtl
+
+def tor_getinfo(conn, key):
+ return conn.get_info(key)[key]
def get_tor_status():
+ """Ask for status over torctl pipe"""
d = dict()
- d['state'] = 'DISABLED'
+ try:
+ f = open('/var/run/tor/tor.pid', 'r')
+ f.close()
+ except IOError, ioe:
+ if ioe.errno == 13:
+ # "Permission denied"
+ d['state'] = 'PERMISSION_DENIED'
+ return d
+ elif ioe.errno == 2:
+ # "No such file or directory"
+ d['state'] = 'DISABLED'
+ return d
+ else:
+ raise ioe
+ conn = TorCtl.connect()
+ if not conn:
+ d['state'] = 'DISABLED'
+ return d
+ d['version'] = tor_getinfo(conn, 'version')
+ d['traffic_read_bytes'] = int(tor_getinfo(conn, 'traffic/read'))
+ d['traffic_written_bytes'] = int(tor_getinfo(conn, 'traffic/written'))
+ d['version_current'] = tor_getinfo(conn, 'status/version/current')
+ d['circuit_established'] = bool(
+ tor_getinfo(conn, 'status/circuit-established'))
+ if d['circuit_established']:
+ d['state'] = 'ESTABLISHED'
+ else:
+ d['state'] = 'CONNECTING'
+ conn.close()
return d
-
+
def get_tor_settings():
- return dict()
+ """Ask for settings over torctl pipe; don't use augeas"""
+ d = dict()
+ return d
def save_tor_settings():
+ """Commit settings through torctl pipe, then send SAVECONF"""
pass