This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 592b0acaa93bb5c66b84f9f561377f77fd417f86 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed May 27 10:47:37 2015 +0200 shelve doesn't need the key loc to instanciate + conf file loc argument can be a folder (.conf files read in lex order) --- app/module_loader.py | 6 +++--- app/modules/storage_modules/shelve_db.py | 3 +-- app/mum.py | 33 +++++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 99501b1..6ca0034 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -26,7 +26,7 @@ class ModuleLoader: """ def __init__(self, conf): self.conf = conf - self.db = self.load_db(self.conf['keys_location']) + self.db = self.load_db() self.db.reset_tasks() self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_detect = {} # See load_all_detection_modules @@ -35,14 +35,14 @@ class ModuleLoader: self.compatible_os_list = ['other'] # Will contain the list of os compatibles for every monitoring module loaded self.wsc = WebSocketContainer(self.db) - def load_db(self, key_loc): + def load_db(self): """ Creates an instance of the class shelve_db from storage_modules. :return: an instance of the shelve_db class """ db_name = "shelve_db" db = __import__("modules.storage_modules." + db_name, fromlist=modules.storage_modules) - db_instance = getattr(db, db_name)(self.conf['db_location'], key_loc) + db_instance = getattr(db, db_name)(self.conf['db_location']) return db_instance def get_db(self): diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 4786513..579b56f 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -18,11 +18,10 @@ class shelve_db: Storage module for the persistant objects in Python : Shelve. Every function in need to access the database have to be implemented on this class. """ - def __init__(self, db_loc, key_loc): + def __init__(self, db_loc): self.db = None self.lock = threading.Lock() self.db_loc = db_loc - self.key_loc = key_loc def open_db(self): """ diff --git a/app/mum.py b/app/mum.py index efc48bd..d369a3e 100755 --- a/app/mum.py +++ b/app/mum.py @@ -120,15 +120,38 @@ if __name__ == '__main__': parser.add_argument("--smtp_server", help="name of the SMTP server to send e-mail notifications") parser.add_argument("--smtp_port", help="port number of the SMTP server") parser.add_argument("--smtp_address", help="e-mail address of the sender for e-mail notifications") + parser.add_argument("--scan", help="nmap scan option in JSON format : {str_name_scan: str_scan_options}") args = parser.parse_args() # creating the default conf structure from the configuration file conf = {} - fconf = open(args.conf_loc, 'r') - for line in fconf.read().splitlines(): - fields = line.split('=') - conf[fields[0]] = fields[1] - fconf.close() + + files_to_read = [] + + if os.path.isfile(args.conf_loc): + # the argument is a file name + files_to_read.append(args.conf_loc) + else: + # the argument is a directory name + path = args.conf_loc + '/' + for dir_content in os.listdir(args.conf_loc): + files_to_read.append(str(path + dir_content)) + # sorting the list in lexicographic order + files_to_read = sorted(files_to_read, key=str.lower) + + found_conf_file = False + for file_name in files_to_read: + # we read only files with '.conf' extension + if re.search('^.+\.conf$', file_name): + found_conf_file = True + fconf = open(file_name, 'r') + for line in fconf.read().splitlines(): + fields = line.split('=') + conf[fields[0]] = fields[1] + fconf.close() + if not found_conf_file: + p = argparse.ArgumentParser() + p.exit(status=0, message="No configuration file found in the path given. Does at least one '.conf' file exists?\n") # now, we overwrite each field of the configuration which are specified by command line argument dict_args = vars(args) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.