[tor-commits] [arm/release] Adding wizard option to shutdown tor with arm

atagar at torproject.org atagar at torproject.org
Sun Jul 17 06:08:32 UTC 2011


commit c29f5fdf9b2da2c097b8b2be8148f6b3dc45d26f
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jul 10 18:56:04 2011 -0700

    Adding wizard option to shutdown tor with arm
    
    This option adds a comment flag to the torrc that tells arm to shut down tor
    when it quits. This will also take advantage of Robert's 'ownership' feature
    when it's available.
---
 src/cli/controller.py           |   23 +++++++++++++++++++++++
 src/cli/wizard.py               |   15 +++++++++++----
 src/resources/torrcTemplate.txt |    7 +++++++
 src/settings.cfg                |    8 ++++++++
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/src/cli/controller.py b/src/cli/controller.py
index e30af3f..c6534b3 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -407,6 +407,22 @@ class Controller:
     
     self._isDone = True
     
+    # check if the torrc has a "ARM_SHUTDOWN" comment flag, if so then shut
+    # down the instance
+    
+    isShutdownFlagPresent = False
+    torrcContents = torConfig.getTorrc().getContents()
+    
+    if torrcContents:
+      for line in torrcContents:
+        if "# ARM_SHUTDOWN" in line:
+          isShutdownFlagPresent = True
+          break
+    
+    if isShutdownFlagPresent:
+      try: torTools.getConn().shutdown()
+      except IOError, exc: cli.popups.showMsg(str(exc), 3, curses.A_BOLD)
+    
     if CONFIG["features.offerTorShutdownOnQuit"]:
       conn = torTools.getConn()
       
@@ -551,6 +567,13 @@ def connResetListener(conn, eventType):
     resolver.setPaused(eventType == torTools.State.CLOSED)
     
     if eventType in (torTools.State.INIT, torTools.State.RESET):
+      # Reload the torrc contents. If the torrc panel is present then it will
+      # do this instead since it wants to do validation and redraw _after_ the
+      # new contents are loaded.
+      
+      if getController().getPanel("torrc") == None:
+        torConfig.getTorrc().load(True)
+      
       torPid = conn.getMyPid()
       
       if torPid and torPid != resolver.getPid():
diff --git a/src/cli/wizard.py b/src/cli/wizard.py
index 9b8c1d7..e5d6257 100644
--- a/src/cli/wizard.py
+++ b/src/cli/wizard.py
@@ -23,7 +23,7 @@ TORRC_TEMPLATE = "resources/torrcTemplate.txt"
 RelayType = enum.Enum("RESUME", "RELAY", "EXIT", "BRIDGE", "CLIENT")
 
 # all options that can be configured
-Options = enum.Enum("DIVIDER", "CONTROL", "NICKNAME", "CONTACT", "NOTIFY", "BANDWIDTH", "LIMIT", "CLIENT", "LOWPORTS", "PORTFORWARD", "STARTUP", "NOTICE", "POLICY", "WEBSITES", "EMAIL", "IM", "MISC", "PLAINTEXT", "DISTRIBUTE", "BRIDGED", "BRIDGE1", "BRIDGE2", "BRIDGE3", "REUSE")
+Options = enum.Enum("DIVIDER", "CONTROL", "NICKNAME", "CONTACT", "NOTIFY", "BANDWIDTH", "LIMIT", "CLIENT", "LOWPORTS", "PORTFORWARD", "STARTUP", "RSHUTDOWN", "CSHUTDOWN", "NOTICE", "POLICY", "WEBSITES", "EMAIL", "IM", "MISC", "PLAINTEXT", "DISTRIBUTE", "BRIDGED", "BRIDGE1", "BRIDGE2", "BRIDGE3", "REUSE")
 RelayOptions = {RelayType.RELAY:   (Options.NICKNAME,
                                     Options.CONTACT,
                                     Options.NOTIFY,
@@ -32,7 +32,8 @@ RelayOptions = {RelayType.RELAY:   (Options.NICKNAME,
                                     Options.CLIENT,
                                     Options.LOWPORTS,
                                     Options.PORTFORWARD,
-                                    Options.STARTUP),
+                                    Options.STARTUP,
+                                    Options.RSHUTDOWN),
                 RelayType.EXIT:    (Options.NICKNAME,
                                     Options.CONTACT,
                                     Options.NOTIFY,
@@ -42,6 +43,7 @@ RelayOptions = {RelayType.RELAY:   (Options.NICKNAME,
                                     Options.LOWPORTS,
                                     Options.PORTFORWARD,
                                     Options.STARTUP,
+                                    Options.RSHUTDOWN,
                                     Options.DIVIDER,
                                     Options.NOTICE,
                                     Options.POLICY,
@@ -56,12 +58,14 @@ RelayOptions = {RelayType.RELAY:   (Options.NICKNAME,
                                     Options.CLIENT,
                                     Options.LOWPORTS,
                                     Options.PORTFORWARD,
-                                    Options.STARTUP),
+                                    Options.STARTUP,
+                                    Options.RSHUTDOWN),
                 RelayType.CLIENT:  (Options.BRIDGED,
                                     Options.BRIDGE1,
                                     Options.BRIDGE2,
                                     Options.BRIDGE3,
-                                    Options.REUSE)}
+                                    Options.REUSE,
+                                    Options.CSHUTDOWN)}
 
 # option sets
 CUSTOM_POLICIES = (Options.WEBSITES, Options.EMAIL, Options.IM, Options.MISC, Options.PLAINTEXT)
@@ -489,6 +493,9 @@ def getTorrc(relayType, config):
   Provides the torrc generated for the given options.
   """
   
+  # TODO: When Robert's 'ownership' feature is available take advantage of it
+  # for the RSHUTDOWN and CSHUTDOWN options.
+  
   pathPrefix = os.path.dirname(sys.argv[0])
   if pathPrefix and not pathPrefix.endswith("/"):
     pathPrefix = pathPrefix + "/"
diff --git a/src/resources/torrcTemplate.txt b/src/resources/torrcTemplate.txt
index 072f847..c31b209 100644
--- a/src/resources/torrcTemplate.txt
+++ b/src/resources/torrcTemplate.txt
@@ -6,6 +6,13 @@
 #
 # Descriptions of all of these configuraiton attibutes (and many more) are
 # available in the tor man page.
+
+[IF RSHUTDOWN | CSHUTDOWN]
+  [NEWLINE]
+  # The following flag tells arm to shut down tor when it quits.
+  # ARM_SHUTDOWN
+[END IF]
+
 [NEWLINE]
 ControlPort 9052              # port controllers can connect to
 CookieAuthentication 1        # method for controller authentication
diff --git a/src/settings.cfg b/src/settings.cfg
index 2734c4a..c6d483d 100644
--- a/src/settings.cfg
+++ b/src/settings.cfg
@@ -352,6 +352,8 @@ wizard.toggle Client => Enabled, Disabled
 wizard.toggle Lowports => Yes, No
 wizard.toggle Portforward => Enabled, Disabled
 wizard.toggle Startup => Yes, No
+wizard.toggle Rshutdown => Yes, No
+wizard.toggle Cshutdown => Yes, No
 wizard.toggle Notice => Yes, No
 wizard.toggle Policy => Custom, Default
 wizard.toggle Websites => Allow, Block
@@ -379,6 +381,8 @@ wizard.default Control => 9052
 wizard.default Notify => true
 wizard.default Bandwidth => 5 MB/s
 wizard.default Startup => true
+wizard.default Rshutdown => false
+wizard.default Cshutdown => true
 wizard.default Client => false
 wizard.default Lowports => true
 wizard.default Portforward => true
@@ -415,6 +419,8 @@ wizard.label.opt Client => Client Usage
 wizard.label.opt Lowports => Low Relaying Ports
 wizard.label.opt Portforward => Port Forwarding
 wizard.label.opt Startup => Run At Startup
+wizard.label.opt Rshutdown => Shutdown With Arm
+wizard.label.opt Cshutdown => Shutdown With Arm
 wizard.label.opt Notice => Disclaimer Notice
 wizard.label.opt Policy => Exit Policy
 wizard.label.opt Websites => Web Browsing
@@ -444,6 +450,8 @@ wizard.description.opt Client => Enable this if you would like to use Tor yourse
 wizard.description.opt Lowports => Relays using port 443 rather than 9001. This helps some users that would otherwise be blocked, but requires that tor is started with root permissions (after that it lowers itself to those of a 'tor-arm' user).
 wizard.description.opt Portforward => If needed, attempts NAT traversal using UPnP and NAT-PMP. This allows for automatic port forwarding on most home routers.
 wizard.description.opt Startup => Runs Tor in the background when the system starts.
+wizard.description.opt Rshutdown => When you quit arm the Tor process is stopped thirty seconds later. This delay is so people using you can gracefully switch their circuits.
+wizard.description.opt Cshutdown => Stops the Tor process when you quit arm.
 wizard.description.opt Notice => Provides a disclaimer that this is an exit on port 80 (http://www.atagar.com/exitNotice).
 wizard.description.opt Policy => Ports allowed to exit from your relay. The default policy allows for common services while limiting the chance of getting a DMCA takedown for torrent traffic (http://www.atagar.com/exitPolicy).
 wizard.description.opt Websites => General Internet browsing including HTTP (80), HTTPS (443), common alternatives (81, 8008), and proxies (3128, 8080)





More information about the tor-commits mailing list