From 3aae76170978a7557b0d7d2cbf10b3b856871538 Mon Sep 17 00:00:00 2001 From: ficus Date: Sun, 25 Nov 2012 02:24:27 +0100 Subject: add tor (re)starts --- torouterui/tor.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'torouterui/tor.py') diff --git a/torouterui/tor.py b/torouterui/tor.py index dd047ca..83ac866 100644 --- a/torouterui/tor.py +++ b/torouterui/tor.py @@ -88,18 +88,28 @@ def get_tor_settings(): conn.close() return d +def restart_tor(): + grepcode = os.system("grep '^DisableNetwork 1' /etc/tor/torrc") + if grepcode == 512: + # permission denied + raise IOError("Don't have permission to read /etc/tor/torrc") + elif grepcode == 0: + pass # found + else: + if os.system('echo "DisableNetwork 1" >> /etc/tor/torrc') != 0: + raise IOError("Don't have permission to write /etc/tor/torrc") + util.enable_service('tor') + time.sleep(3) + conn = TorCtl.connect() + if not conn: + raise Exception("Could not start tor daemon!") + conn.close() + def save_tor_settings(form): """Commit settings through torctl pipe, then send SAVECONF""" conn = TorCtl.connect() if not conn: - print "Warning: couldn't connect to tor daemon; need to boot up tor daemon in disabled state" - os.system('echo "DisableNetwork 1" >> /etc/tor/torrc') - # tor daemon should always be running, even if disabled - util.enable_service('tor') - time.sleep(3) - conn = TorCtl.connect() - if not conn: - raise Exception("Could not start tor daemon!") + raise Exception("couldn't connect to tor daemon; need to boot up tor daemon in disabled state") conn.set_option('RelayBandwidthRate', "%dKB" % int(form['tor_relaybandwidthrateKBps'])) -- cgit v1.2.3