[tor-commits] [arm/master] Moving messages to settings.cfg

atagar at torproject.org atagar at torproject.org
Sun Sep 15 22:29:21 UTC 2013


commit cf68d98e686c53868335605ef953516e6481538e
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Sep 15 11:22:52 2013 -0700

    Moving messages to settings.cfg
    
    Swapping more of our messages from global constants to configuration values
    that use format().
---
 arm/settings.cfg |    5 +++++
 arm/starter.py   |   54 +++++++++++++++++++++++-------------------------------
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/arm/settings.cfg b/arm/settings.cfg
index dc3a44d..627905c 100644
--- a/arm/settings.cfg
+++ b/arm/settings.cfg
@@ -46,6 +46,11 @@ msg.unreadable_cookie_file
 |  Path: {path}
 |  Issue: {issue}
 
+msg.tor_is_running_as_root Tor is currently running with root permissions. This isn't a good idea, nor should it be necessary. See the 'User UID' option on Tor's man page for an easy method of reducing its permissions after startup.
+msg.arm_is_running_as_root Arm is currently running with root permissions. This isn't a good idea, nor should it be necessary. Try starting arm with "sudo -u {tor_user} arm" instead.
+msg.config_not_found No armrc loaded, using defaults. You can customize arm by placing a configuration file at {path} (see the armrc.sample for its options).
+msg.unable_to_read_config Failed to load configuration (using defaults): "{error}"
+
 # Important tor configuration options (shown by default)
 config.important BandwidthRate
 config.important BandwidthBurst
diff --git a/arm/starter.py b/arm/starter.py
index efcda91..53c24ff 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 """
 Command line application for monitoring Tor relays, providing real time status
 information. This starts the applicatin, getting a tor connection and parsing
@@ -9,53 +7,47 @@ arguments.
 import collections
 import getopt
 import getpass
-import os
-import sys
-
-import stem.util.connection
-
-import time
 import locale
 import logging
+import os
 import platform
+import sys
+import time
 
 import arm.controller
 import arm.logPanel
-import arm.util.connections
 import arm.util.sysTools
 import arm.util.torConfig
 import arm.util.torTools
 import arm.util.uiTools
 
-from arm import __version__, __release_date__
-from stem.control import Controller
-
 import stem.connection
 import stem.util.conf
+import stem.util.connection
 import stem.util.log
 import stem.util.system
 
+from arm import __version__, __release_date__
+from stem.control import Controller
+
 LOG_DUMP_PATH = os.path.expanduser("~/.arm/log")
 
 CONFIG = stem.util.conf.config_dict("arm", {
-  "tor.password": None,
-  "startup.blindModeEnabled": False,
-  "startup.events": "N3",
-  "msg.help": "",
-  "msg.wrong_port_type": "",
-  "msg.wrong_socket_type": "",
-  "msg.uncrcognized_auth_type": "",
-  "msg.missing_password_bug": "",
-  "msg.unreadable_cookie_file": "",
+  'tor.password': None,
+  'startup.blindModeEnabled': False,
+  'startup.events': 'N3',
+  'msg.help': '',
+  'msg.wrong_port_type': '',
+  'msg.wrong_socket_type': '',
+  'msg.uncrcognized_auth_type': '',
+  'msg.missing_password_bug': '',
+  'msg.unreadable_cookie_file': '',
+  'msg.tor_is_running_as_root': '',
+  'msg.arm_is_running_as_root': '',
+  'msg.unable_to_read_config': '',
 })
 
-# notices given if the user is running arm or tor as root
-TOR_ROOT_NOTICE = "Tor is currently running with root permissions. This is not a good idea and shouldn't be necessary. See the 'User UID' option from Tor's man page for an easy method of reducing its permissions after startup."
-ARM_ROOT_NOTICE = "Arm is currently running with root permissions. This is not a good idea, and will still work perfectly well if it's run with the same user as Tor (ie, starting with \"sudo -u %s arm\")."
-
 NO_INTERNAL_CFG_MSG = "Failed to load the parsing configuration. This will be problematic for a few things like torrc validation and log duplication detection (%s)"
-STANDARD_CFG_LOAD_FAILED_MSG = "Failed to load configuration (using defaults): \"%s\""
-STANDARD_CFG_NOT_FOUND_MSG = "No armrc loaded, using defaults. You can customize arm by placing a configuration file at '%s' (see the armrc.sample for its options)."
 
 # torrc entries that are scrubbed when dumping
 PRIVATE_TORRC_ENTRIES = ["HashedControlPassword", "Bridge", "HiddenServiceDir"]
@@ -330,10 +322,10 @@ def main():
     try:
       config.load(args.config)
     except IOError, exc:
-      stem.util.log.warn(STANDARD_CFG_LOAD_FAILED_MSG % arm.util.sysTools.getFileErrorMsg(exc))
+      stem.util.log.warn(CONFIG['msg.unable_to_read_config'].format(error = arm.util.sysTools.getFileErrorMsg(exc)))
   else:
     # no armrc found, falling back to the defaults in the source
-    stem.util.log.notice(STANDARD_CFG_NOT_FOUND_MSG % args.config)
+    stem.util.log.notice(CONFIG['msg.config_not_found'].format(path = args.config))
   
   # validates and expands log event flags
   try:
@@ -367,7 +359,7 @@ def main():
     # give a notice if tor is running with root
     torUser = controllerWrapper.getMyUser()
     if torUser == "root":
-      stem.util.log.notice(TOR_ROOT_NOTICE)
+      stem.util.log.notice(CONFIG['msg.tor_is_running_as_root'])
   
   # Give a notice if arm is running with root. Querying connections usually
   # requires us to have the same permissions as tor so if tor is running as
@@ -376,7 +368,7 @@ def main():
   
   if torUser != "root" and os.getuid() == 0:
     torUserLabel = torUser if torUser else "<tor user>"
-    stem.util.log.notice(ARM_ROOT_NOTICE % torUserLabel)
+    stem.util.log.notice(msg.arm_is_running_as_root.format(tor_user = torUserLabel))
   
   # fetches descriptions for tor's configuration options
   arm.util.torConfig.loadConfigurationDescriptions(pathPrefix)





More information about the tor-commits mailing list