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 515d017f2255bf8b30bdc28f4fa83d14931c5885 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Fri Mar 27 16:54:55 2015 +0100 app.py renommé en mum.py + le fichier de conf doit être passé en argument par ligne de commande + un argument en ligne de commande peut surcharger un champ du fichier de conf --- app/module_loader.py | 9 ++------- app/{app.py => mum.py} | 32 +++++++++++++++++++++++++++++--- run.sh | 2 +- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index f70696e..638692a 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -21,13 +21,8 @@ class ModuleLoader: Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules and contains several methods in order to call the methods once these modules loaded. """ - def __init__(self, add_func, rem_func): - self.conf = {} # See conf.txt - fconf = open('mum.conf', 'r') - for line in fconf.read().splitlines(): - fields = line.split('=') - self.conf[fields[0]] = fields[1] - fconf.close() + def __init__(self, add_func, rem_func, conf): + self.conf = conf ''' self.db_loc = dict_conf['db_location'] self.external_mod_loc = dict_conf['external_modules_location'] diff --git a/app/app.py b/app/mum.py similarity index 85% rename from app/app.py rename to app/mum.py index eca0266..89bf69c 100755 --- a/app/app.py +++ b/app/mum.py @@ -11,7 +11,7 @@ import threading from module_loader import ModuleLoader import process_monitoring from modules.notification_modules.websocket_container import WebSocketContainer -import traceback +import argparse # Pour lancer la detection nmap avec un nouveau thread class ThreadDetect(threading.Thread): @@ -186,7 +186,33 @@ def do_upload(): if __name__ == '__main__': global ml global wsc - ml = ModuleLoader(process_monitoring.add_to_waiting_list, process_monitoring.remove_to_waiting_list) + + # creating the parser for the command line arguments + parser = argparse.ArgumentParser() + parser.add_argument("conf_loc", help="the location of the configuration file (can be relative)") + parser.add_argument("--db_location", help="the location of the shelve database") + parser.add_argument("--external_modules_location", help="the location of the external monitoring modules") + parser.add_argument("--keys_location", help="the location of the directory containing the SSH keys") + parser.add_argument("--smtp_server", help="the name of the SMTP server to send e-mail notifications") + parser.add_argument("--smtp_port", help="the port of the SMTP server") + parser.add_argument("--smtp_address", help="the e-mail address of the sender for the e-mail notifications") + 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() + + # now, we overwrite each field of the configuration which are specified by command line argument + dict_args = vars(args) + for arg in dict_args: + if dict_args[arg] is not None: + conf[arg] = dict_args[arg] + + ml = ModuleLoader(process_monitoring.add_to_waiting_list, process_monitoring.remove_to_waiting_list, conf) ml.load_all_monitoring_modules() ml.load_all_connection_modules() ml.load_all_detection_modules() @@ -198,4 +224,4 @@ if __name__ == '__main__': port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) # after ending - process_monitoring.end = True + process_monitoring.end = True \ No newline at end of file diff --git a/run.sh b/run.sh index 7bb42c9..a0599c6 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ #!/bin/sh -exec ./in-venv.sh python app/app.py $* +exec ./in-venv.sh python app/mum.py $* -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.