[Nym3-commit] r333 - trunk/nymbaron/Server

laurent at conuropsis.org laurent at conuropsis.org
Wed Oct 12 16:25:25 CEST 2005


Author: laurent
Date: 2005-10-12 16:25:24 +0200 (Wed, 12 Oct 2005)
New Revision: 333

Modified:
   trunk/nymbaron/Server/Config.py
   trunk/nymbaron/Server/Main.py
   trunk/nymbaron/Server/User.py
Log:
Add support for configuration file in the server.


Modified: trunk/nymbaron/Server/Config.py
===================================================================
--- trunk/nymbaron/Server/Config.py	2005-10-12 13:49:25 UTC (rev 332)
+++ trunk/nymbaron/Server/Config.py	2005-10-12 14:25:24 UTC (rev 333)
@@ -23,30 +23,44 @@
 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-"""nymbaron.Server.Config
+import os
+import ConfigParser
 
-    This package is the configuration file of the server."""
+class Config:
 
-__all__ = ['DEBUG', "serverName", "path", "default_settings"]
-#path = '/var/lib/nymbaron'
+    def __init__(self, filename = None):
+	self.DEBUG = False
+	"""Whether the server sends the message it generates to mixminion or to
+	stdout"""
 
-DEBUG = False
-"""Whether the server sends the message it generates to mixminion 
-or to stdout"""
+	self.serverName = 'nymserv.komite.net'
+	"""The hostname of the host on which the nymserver is running."""
 
-serverName = 'nymserv.komite.net'
-"""The hostname of the host on which the nymserver is running."""
+	self.path = '/tmp'
+	"""The path to the directory containing the server data"""
 
-path = '/tmp'
-"""The path to the directory containing the server data"""
+	self.default_settings = { 'quota' : 10 * 2**20, 'usage' : 0,
+			    'idKey' : None, 'encKey' : None, 'policy' : None,
+			    'SendMsgAfter' : 24, 'SendSummaryAfter' : 12, 
+			    'MaxSURBsPerDay' : 10, 'EncryptSummaryAfter' : 24,
+			    'HoldUntilAck' : 'always', 'ShutdownPhrase' : None,
+			    'HoldSURBs' : 5, 'nSurbs' : 0, 'up' : False,
+			    'cr' : "", 'inidgst' : "" }
+	"""The default settings of a user account."""
+	
+	if filename:
+	    config = ConfigParser.RawConfigParser()
+	    config.read(filename)
+	    
+	    if config.has_section('general'):
+		if config.has_option('general', 'DEBUG'):
+		    self.DEBUG = config.getboolean('general', 'DEBUG')
+		if config.has_option('general', 'path'):
+		    self.path = config.get('general', 'path')
+		if config.has_option('general', 'serverName'):
+		    self.serverName = config.get('general', 'serverName')
 
-default_settings = { 'quota' : 10 * 2**20, 'usage' : 0,
-		     'idKey' : None, 'encKey' : None, 'policy' : None,
-		     'SendMsgAfter' : 24, 'SendSummaryAfter' : 12, 
-		     'MaxSURBsPerDay' : 10, 'EncryptSummaryAfter' : 24,
-		     'HoldUntilAck' : 'always', 'ShutdownPhrase' : None,
-		     'HoldSURBs' : 5,
-		     'nSurbs' : 0, 'up' : False, 'cr' : "", 'inidgst' : "" }
-"""The default settings of a user account."""
-#up : the user account has been initialized and the answer to the challenge is correct
-#cr : response to the challenge
+	    if config.has_section('accounts'):
+		for k in self.default_settings.keys():
+		    if config.has_option('accounts', k):
+			self.default_settings[k] = config.get('accounts', k)

Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py	2005-10-12 13:49:25 UTC (rev 332)
+++ trunk/nymbaron/Server/Main.py	2005-10-12 14:25:24 UTC (rev 333)
@@ -40,6 +40,9 @@
 lifeCycle = User.lifeCycle
 """The life cycle of a mail received by the server for a nym""" 
 
+config = Config.Config()
+"""Global configuration file for the server"""
+
 def processIncoming(localpart, msg):
     """Process incoming mail from the MTA
     - identifies the nym the mail is addressed to
@@ -194,7 +197,7 @@
 			nymUser.setKeys(com.kid,com.kenc)
 		    elif (com.ct() == Message.CToSCODE['Relay']):
 			ec = Mail.relay(h.nym, com.rt, com.ri,
-					Config.serverName, com.body)
+					config.serverName, com.body)
 			if (ec != 0):
 			    print "mixminion exited abnormally with error code %d" % ec
 			    sys.exit(2)
@@ -253,7 +256,7 @@
     optlist, pholder = getopt.getopt(argv[1:], 'D:d:m')
     for o, a in optlist:
 	if o == "-D":
-	    Config.DEBUG = True
+	    config.DEBUG = True
 	
     for o, a in optlist:
 	if o == "-d": # mail delivery

Modified: trunk/nymbaron/Server/User.py
===================================================================
--- trunk/nymbaron/Server/User.py	2005-10-12 13:49:25 UTC (rev 332)
+++ trunk/nymbaron/Server/User.py	2005-10-12 14:25:24 UTC (rev 333)
@@ -46,6 +46,8 @@
               'sent-in-full' : 2, 'deleted' : 3 }
 """The life cycle of a mail received by a nym"""
 
+config = Config.Config()
+
 class NoSuchUser(Exception): pass
 """Exception thrown when a user account identified by its nym can't be found
 """
@@ -90,7 +92,7 @@
         1 : create user data throw an error if the user exists
         _ : load a user data, if it doesn't exist create a new user silently
 	"""
-        self.datafile = Config.path + os.sep + username + '.dat'
+        self.datafile = config.path + os.sep + username + '.dat'
 	self.username = username
 	self.index = None
 	self.mbox = None
@@ -108,7 +110,7 @@
 	    f.close()
 	except IOError:
 	    if create == 0: raise NoSuchUser()
-	    self.data = Config.default_settings
+	    self.data = config.default_settings
 	    self.data['username'] = username
     	    self.data['received'] = []
 	    self.data['nSurbs'] = 0
@@ -135,7 +137,7 @@
 
     def _lock(self):
 	"""Lock the user. For well behaved functions."""
-	self.lock = mixminion.Common.Lockfile(Config.path + os.sep + 
+	self.lock = mixminion.Common.Lockfile(config.path + os.sep + 
 					      self.username + '.lck')
 	self.lock.acquire(blocking = 1)
 
@@ -248,7 +250,7 @@
     def surbfile(self):
 	"""Gets the path to file containing the surbs to send messages to the nymholder
 	"""
-	return Config.path + os.sep + self.data['username'] + '.surbs'
+	return config.path + os.sep + self.data['username'] + '.surbs'
 
     def advanced_send(self, msg, add_status = True):
 	"""Sends a message to the nymholder through the mixminion network,
@@ -297,7 +299,7 @@
     def send(self, msg):
 	"""Sends a message to the nymholder through the mixminion network,
 	using the surbs provided by the nymholder"""
-        if Config.DEBUG:
+        if config.DEBUG:
             print msg
             return 0
         else:
@@ -391,7 +393,7 @@
 
     def mboxfile(self):
 	"""Gets the mailbox file name"""
-	return Config.path + os.sep + self.data['username'] + '.mbox'
+	return config.path + os.sep + self.data['username'] + '.mbox'
 
     def _save_mbox(self):
 	"""Flushs the mailbox to the disk"""
@@ -403,11 +405,11 @@
 
     def synboxfile(self):
 	"""Gets the synbox file name"""
-	return Config.path + os.sep + self.data['username'] + '.syn'
+	return config.path + os.sep + self.data['username'] + '.syn'
 
     def indexfile(self):
 	"""Gets the index filename"""
-	return Config.path + os.sep + self.data['username'] + '.idx'
+	return config.path + os.sep + self.data['username'] + '.idx'
 	
     def load_synbox(self):
 	"""Loads the synbox, structure containing synopses, from the disk"""



More information about the Nym3-commit mailing list