aboutsummaryrefslogtreecommitdiffstats
path: root/torouterui/tor.py
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 /torouterui/tor.py
parent49ec1f025b529c52eaee50af37ffc0b23a9f7124 (diff)
downloadtui-fe4b8a01fc87d1a76fca8e8733270a260aa23cc0.tar.gz
tui-fe4b8a01fc87d1a76fca8e8733270a260aa23cc0.zip
basic tor status using python-torctl
Diffstat (limited to 'torouterui/tor.py')
-rw-r--r--torouterui/tor.py42
1 files changed, 39 insertions, 3 deletions
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