branch develop updated (9d8f7dd -> 34f7267)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository mum. See http://git.chorem.org/mum.git from 9d8f7dd memory module added new 097e279 disk space monitoring added new 782a408 ModuleNotCompatibleException and CommandNotFoundException created new b3798b1 exception messages error are sent by websocket if available new ff95e7d autoconfiguration of host connections new 34f7267 scanned ip printed after scan The 5 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 34f72679048bc828c3844403b16a8b40a557a3b6 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 16:38:05 2015 +0100 scanned ip printed after scan commit ff95e7da31e16f9e61daa8480d30ec70475c348e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 15:42:23 2015 +0100 autoconfiguration of host connections commit b3798b16db5760adf26a21f849325c2345ec0a4e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 13:48:12 2015 +0100 exception messages error are sent by websocket if available commit 782a408b6b0ad52e965f9b53a792982f45ebf1cf Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 12:38:54 2015 +0100 ModuleNotCompatibleException and CommandNotFoundException created commit 097e279bd6af30b88b3069734e0a810b725bacd2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 10:24:27 2015 +0100 disk space monitoring added Summary of changes: app/app.py | 34 +++++++------ app/module_loader.py | 65 ++++++++++++++++++++----- app/modules/CommandNotFoundException.py | 14 ++++++ app/modules/ModuleNotCompatibleException.py | 14 ++++++ app/modules/connection_modules/ssh.py | 13 +++-- app/modules/detection_modules/nmap_detection.py | 14 +++--- app/modules/monitoring_modules/unix/__init__.py | 5 +- app/modules/monitoring_modules/unix/disk.py | 36 ++++++++++++++ app/modules/monitoring_modules/unix/memory.py | 17 ++++++- app/modules/storage_modules/shelve_db.py | 39 ++++++++++----- static/js/controllers/detectCtrl.js | 1 + views/scan.html | 1 + 12 files changed, 201 insertions(+), 52 deletions(-) create mode 100644 app/modules/CommandNotFoundException.py create mode 100644 app/modules/ModuleNotCompatibleException.py create mode 100644 app/modules/monitoring_modules/unix/disk.py -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 097e279bd6af30b88b3069734e0a810b725bacd2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 10:24:27 2015 +0100 disk space monitoring added --- app/modules/monitoring_modules/unix/__init__.py | 5 +++-- app/modules/monitoring_modules/unix/disk.py | 30 +++++++++++++++++++++++++ app/modules/monitoring_modules/unix/memory.py | 8 ++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/modules/monitoring_modules/unix/__init__.py b/app/modules/monitoring_modules/unix/__init__.py index 8efe043..0554872 100644 --- a/app/modules/monitoring_modules/unix/__init__.py +++ b/app/modules/monitoring_modules/unix/__init__.py @@ -1,6 +1,7 @@ __author__ = 'aguilbaud' -__all__=['updated_packages', 'memory'] +__all__=['updated_packages', 'memory', 'disk'] info_mod = { 'updated_packages': {'block': 'software', 'unit': 'bool'}, - 'memory': {'block': 'hardware', 'unit': 'kB'} + 'memory': {'block': 'hardware', 'unit': '%'}, + 'disk': {'block' : 'hardware', 'unit': '%'} } \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/disk.py b/app/modules/monitoring_modules/unix/disk.py new file mode 100644 index 0000000..48586cc --- /dev/null +++ b/app/modules/monitoring_modules/unix/disk.py @@ -0,0 +1,30 @@ +__author__ = 'aguilbaud' + +import json +import re + +""" +Check and returns the percentage of disk used ( = percentage of use of the partition mounted on /) +""" + + +class disk: + def __init__(self, conn, db): + self.conn = conn + self.db = db + + def check(self): + cmd = "df -h" + stdout = self.conn.exec_command(cmd) + disk_used = 0 + ignore = True + for line in stdout.splitlines(): + # we ignore the first line which contains no value + if ignore: + ignore = False + else: + values = line.split() + if values[len(values)-1] == "/": + disk_used = re.sub("[^0-9]", "", values[len(values)-2]) + res_check = json.dumps({"disk": int(disk_used)}) + self.db.add_check(self.conn.get_addr_host(), "disk", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/memory.py b/app/modules/monitoring_modules/unix/memory.py index 2b36cf5..c58cdcb 100644 --- a/app/modules/monitoring_modules/unix/memory.py +++ b/app/modules/monitoring_modules/unix/memory.py @@ -2,6 +2,10 @@ __author__ = 'aguilbaud' import json import re +""" +Check and returns the percentage of total memory used of the machine +""" + class memory: def __init__(self, conn, db): self.conn = conn @@ -18,5 +22,7 @@ class memory: memtotal = re.sub("[^0-9]", "", tab_res[1]) elif(tab_res[0]) == 'MemFree': memfree = re.sub("[^0-9]", "", tab_res[1]) - res_check = json.dumps({"memory": (int(memfree) * 100) / int(memtotal)}) + #TODO si memfree ou memtotal = 0, retourner une exception comme quoi le module n'est pas compatible avec l'hote + memused = int(memtotal) - int(memfree) + res_check = json.dumps({"memory": memused * 100 / int(memtotal)}) self.db.add_check(self.conn.get_addr_host(), "memory", res_check) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 782a408b6b0ad52e965f9b53a792982f45ebf1cf Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 12:38:54 2015 +0100 ModuleNotCompatibleException and CommandNotFoundException created --- app/module_loader.py | 27 +++++++++++++++++++++------ app/modules/CommandNotFoundException.py | 14 ++++++++++++++ app/modules/ModuleNotCompatibleException.py | 14 ++++++++++++++ app/modules/connection_modules/ssh.py | 9 ++++++++- app/modules/monitoring_modules/unix/disk.py | 10 ++++++++-- app/modules/monitoring_modules/unix/memory.py | 11 +++++++++-- 6 files changed, 74 insertions(+), 11 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 8ea04d2..a782900 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -4,6 +4,8 @@ import modules.connection_modules import modules.detection_modules import modules.monitoring_modules import modules.storage_modules +import modules.ModuleNotCompatibleException as moduleNotCompatibleException +import modules.CommandNotFoundException as commandNotFoundException """ Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules. @@ -42,7 +44,7 @@ def load_conn(conn_name, addr_host, username, key_location): # /home/aguilbau :return: the instance of connection module created """ conn = __import__("modules.connection_modules." + conn_name, fromlist=modules.connection_modules) - conn_instance = getattr(conn, conn_name)(addr_host, username, key_location) + conn_instance = getattr(conn, conn_name)(addr_host, username, key_location, commandNotFoundException) return conn_instance @@ -59,7 +61,10 @@ def run_all_detection_modules(os, conn, db): for mod_name in pack_mod_os.__all__: mod = __import__ ("modules.detection_modules." + os + "." + mod_name, fromlist=modules.detection_modules.unix.__all__) # on charge le module mod_instance = getattr(mod, mod_name)(conn, db) # on appelle le constructeur - mod_instance.run_detection() + try: + mod_instance.run_detection() + except commandNotFoundException as cnfe: + print cnfe.__str__ def run_all_monitoring_modules(os, conn, db): @@ -74,8 +79,13 @@ def run_all_monitoring_modules(os, conn, db): pack_mod_os = __import__("modules.monitoring_modules." + os, fromlist=modules.monitoring_modules.__all__) for mod_name in pack_mod_os.__all__: mod = __import__ ("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) # on charge le module - mod_instance = getattr(mod, mod_name)(conn, db) # on appelle le constructeur - mod_instance.check() + mod_instance = getattr(mod, mod_name)(conn, db, moduleNotCompatibleException) # on appelle le constructeur + try: + mod_instance.check() + except moduleNotCompatibleException as mnce: + print mnce.__str__ + except commandNotFoundException as cnfe: + print cnfe.__str__ def run_one_monitoring_module(mod_name, os, conn, db): @@ -89,8 +99,13 @@ def run_one_monitoring_module(mod_name, os, conn, db): """ __import__("modules.monitoring_modules." + os) mod = __import__("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) - mod_instance = getattr(mod, mod_name)(conn, db) # on appelle le constructeur - mod_instance.check() + mod_instance = getattr(mod, mod_name)(conn, db, moduleNotCompatibleException) # on appelle le constructeur + try: + mod_instance.check() + except moduleNotCompatibleException as mnce: + print mnce.__str__ + except commandNotFoundException as cnfe: + print cnfe.__str__ def get_info_mod_monitoring(os): diff --git a/app/modules/CommandNotFoundException.py b/app/modules/CommandNotFoundException.py new file mode 100644 index 0000000..3492ec6 --- /dev/null +++ b/app/modules/CommandNotFoundException.py @@ -0,0 +1,14 @@ +__author__ = 'aguilbaud' + +""" +Raised if a command called with a connection does not exists on the host +""" + + +class CommandNotFoundException(Exception): + def __init__(self, command, addr_host): + self.command = command + self.addr_host = addr_host + + def __str__(self): + return "Command '" + self.command + "' not found on host " + self.addr_host \ No newline at end of file diff --git a/app/modules/ModuleNotCompatibleException.py b/app/modules/ModuleNotCompatibleException.py new file mode 100644 index 0000000..86db67b --- /dev/null +++ b/app/modules/ModuleNotCompatibleException.py @@ -0,0 +1,14 @@ +__author__ = 'aguilbaud' + +""" +Raised if the module cannot have perform his treatment on a host (command not found or result unexpected) +""" + + +class ModuleNotCompatibleException(Exception): + def __init__(self, mod_name, addr_host): + self.mod_name = mod_name + self.addr_host = addr_host + + def __str__(self): + return "Module '" + self.mod_name + "' not compatible on host " + self.addr_host \ No newline at end of file diff --git a/app/modules/connection_modules/ssh.py b/app/modules/connection_modules/ssh.py index 0d799b9..7eaee28 100644 --- a/app/modules/connection_modules/ssh.py +++ b/app/modules/connection_modules/ssh.py @@ -3,12 +3,13 @@ import paramiko class ssh: - def __init__(self, addr_host, usrname, key_location): + def __init__(self, addr_host, usrname, key_location, cnfe): key = paramiko.RSAKey.from_private_key_file(key_location) # "/home/aguilbaud/.ssh/id_rsa" self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.ssh.connect(addr_host, username=usrname, pkey=key) self.addr_host = addr_host + self.CommandNotFoundException = cnfe def get_addr_host(self): return self.addr_host @@ -16,6 +17,12 @@ class ssh: def exec_command(self, cmd): stdin, stdout, stderr = self.ssh.exec_command(cmd) res = stdout.read() + err = stderr.read() + if not err == "" and res == "": + exception_inst = getattr(self.CommandNotFoundException, "CommandNotFoundException")( + cmd, self.addr_host + ) + raise exception_inst return res def disconnect(self): diff --git a/app/modules/monitoring_modules/unix/disk.py b/app/modules/monitoring_modules/unix/disk.py index 48586cc..4e7ac7d 100644 --- a/app/modules/monitoring_modules/unix/disk.py +++ b/app/modules/monitoring_modules/unix/disk.py @@ -9,14 +9,15 @@ Check and returns the percentage of disk used ( = percentage of use of the parti class disk: - def __init__(self, conn, db): + def __init__(self, conn, db, mnce): self.conn = conn self.db = db + self.ModuleNotCompatibleException = mnce def check(self): cmd = "df -h" stdout = self.conn.exec_command(cmd) - disk_used = 0 + disk_used = None ignore = True for line in stdout.splitlines(): # we ignore the first line which contains no value @@ -26,5 +27,10 @@ class disk: values = line.split() if values[len(values)-1] == "/": disk_used = re.sub("[^0-9]", "", values[len(values)-2]) + if disk_used is None: + exception_inst = getattr(self.ModuleNotCompatibleException, "ModuleNotCompatibleException")( + "disk", self.conn.get_addr_host() + ) + raise exception_inst res_check = json.dumps({"disk": int(disk_used)}) self.db.add_check(self.conn.get_addr_host(), "disk", res_check) \ No newline at end of file diff --git a/app/modules/monitoring_modules/unix/memory.py b/app/modules/monitoring_modules/unix/memory.py index c58cdcb..adc30d4 100644 --- a/app/modules/monitoring_modules/unix/memory.py +++ b/app/modules/monitoring_modules/unix/memory.py @@ -2,14 +2,17 @@ __author__ = 'aguilbaud' import json import re + """ Check and returns the percentage of total memory used of the machine """ + class memory: - def __init__(self, conn, db): + def __init__(self, conn, db, mnce): self.conn = conn self.db = db + self.ModuleNotCompatibleException = mnce def check(self): cmd = "cat /proc/meminfo" @@ -22,7 +25,11 @@ class memory: memtotal = re.sub("[^0-9]", "", tab_res[1]) elif(tab_res[0]) == 'MemFree': memfree = re.sub("[^0-9]", "", tab_res[1]) - #TODO si memfree ou memtotal = 0, retourner une exception comme quoi le module n'est pas compatible avec l'hote memused = int(memtotal) - int(memfree) + if memused == 0: + exception_inst = getattr(self.ModuleNotCompatibleException, "ModuleNotCompatibleException")( + "memory", self.conn.get_addr_host() + ) + raise exception_inst res_check = json.dumps({"memory": memused * 100 / int(memtotal)}) self.db.add_check(self.conn.get_addr_host(), "memory", res_check) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 b3798b16db5760adf26a21f849325c2345ec0a4e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 13:48:12 2015 +0100 exception messages error are sent by websocket if available --- app/app.py | 3 +-- app/module_loader.py | 24 ++++++++++++++++++++---- app/modules/connection_modules/ssh.py | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/app.py b/app/app.py index 522f56d..33fbdbd 100755 --- a/app/app.py +++ b/app/app.py @@ -39,7 +39,7 @@ class ThreadDetect(threading.Thread): # now launching full detection for ip in json.loads(scanned_ip): conn = module_loader.load_conn("ssh", ip, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") - module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db) + module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db, self.ws) @route('/') @@ -134,7 +134,6 @@ def receive(ws): break - # Lancement du serveur a l'adresse 0.0.0.0:1337 if __name__ == '__main__': port = int(os.environ.get('PORT', 1337)) diff --git a/app/module_loader.py b/app/module_loader.py index a782900..71f0268 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -7,6 +7,8 @@ import modules.storage_modules import modules.ModuleNotCompatibleException as moduleNotCompatibleException import modules.CommandNotFoundException as commandNotFoundException +import json + """ Loads dynamically modules from packages connection_modules, detection_modules, monitoring_modules, storage_modules. """ @@ -48,13 +50,14 @@ def load_conn(conn_name, addr_host, username, key_location): # /home/aguilbau return conn_instance -def run_all_detection_modules(os, conn, db): +def run_all_detection_modules(os, conn, db, ws): """ Instanciates and runs every detection_modules listed in the __init__.py file of the package corresponding to the operating system entered in parameters. :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.detection_modules." + os) pack_mod_os = __import__("modules.detection_modules." + os, fromlist=modules.detection_modules.__all__) @@ -65,18 +68,22 @@ def run_all_detection_modules(os, conn, db): mod_instance.run_detection() except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) + -def run_all_monitoring_modules(os, conn, db): +def run_all_monitoring_modules(os, conn, db, ws): """ Instanciates and runs every monitoring_modules listed in the __init__.py file of the package corresponding to the operating system entered in parameters. :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.monitoring_modules." + os) - pack_mod_os = __import__("modules.monitoring_modules." + os, fromlist=modules.monitoring_modules.__all__) + pack_mod_os = __import__("modules.monitoring_modules." + os, fromlist=modules.monitoring_modules.__all__) for mod_name in pack_mod_os.__all__: mod = __import__ ("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) # on charge le module mod_instance = getattr(mod, mod_name)(conn, db, moduleNotCompatibleException) # on appelle le constructeur @@ -84,11 +91,15 @@ def run_all_monitoring_modules(os, conn, db): mod_instance.check() except moduleNotCompatibleException as mnce: print mnce.__str__ + if ws is not None: + ws.send(json.dumps({"40": mnce.__str__})) except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) -def run_one_monitoring_module(mod_name, os, conn, db): +def run_one_monitoring_module(mod_name, os, conn, db, ws): """ Instanciates and runs one monitoring_module of the package corresponding to the operating system entered in parameters. @@ -96,6 +107,7 @@ def run_one_monitoring_module(mod_name, os, conn, db): :param os: the oprating system of the host :param conn: an instance of a connection module :param db: an instance of a storage module + :param ws: a websocket connection if the function have been called from a client. Is None otherwise """ __import__("modules.monitoring_modules." + os) mod = __import__("modules.monitoring_modules." + os + "." + mod_name, fromlist=modules.monitoring_modules.unix.__all__) @@ -104,8 +116,12 @@ def run_one_monitoring_module(mod_name, os, conn, db): mod_instance.check() except moduleNotCompatibleException as mnce: print mnce.__str__ + if ws is not None: + ws.send(json.dumps({"40": mnce.__str__})) except commandNotFoundException as cnfe: print cnfe.__str__ + if ws is not None: + ws.send(json.dumps({"40": cnfe.__str__})) def get_info_mod_monitoring(os): diff --git a/app/modules/connection_modules/ssh.py b/app/modules/connection_modules/ssh.py index 7eaee28..74786cb 100644 --- a/app/modules/connection_modules/ssh.py +++ b/app/modules/connection_modules/ssh.py @@ -16,14 +16,14 @@ class ssh: def exec_command(self, cmd): stdin, stdout, stderr = self.ssh.exec_command(cmd) - res = stdout.read() + out = stdout.read() err = stderr.read() - if not err == "" and res == "": + if not err == "" and out == "": exception_inst = getattr(self.CommandNotFoundException, "CommandNotFoundException")( cmd, self.addr_host ) raise exception_inst - return res + return out def disconnect(self): self.ssh.close() \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 ff95e7da31e16f9e61daa8480d30ec70475c348e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 15:42:23 2015 +0100 autoconfiguration of host connections --- app/app.py | 30 ++++++++++++++----------- app/module_loader.py | 16 ++++++++++--- app/modules/detection_modules/nmap_detection.py | 13 ++++++----- app/modules/storage_modules/shelve_db.py | 27 +++++++++++++++++----- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/app/app.py b/app/app.py index 33fbdbd..ba84339 100755 --- a/app/app.py +++ b/app/app.py @@ -34,7 +34,8 @@ class ThreadDetect(threading.Thread): def run(self): db = module_loader.load_db() - scanned_ip = module_loader.run_nmap_detection(self.ip_range, db, self.ws) + conn_mod_list = module_loader.get_conection_modules_list() + scanned_ip = module_loader.run_nmap_detection(self.ip_range, db, self.ws, conn_mod_list) self.ws.send(json.dumps({SUCCESS_MODULE: scanned_ip})) # now launching full detection for ip in json.loads(scanned_ip): @@ -120,18 +121,21 @@ def bower_files(filepath): @get('/websocket', apply=[websocket]) def receive(ws): while True: - response = ws.receive() - if response is not None: - msg = json.loads(response) - for code in msg: - if code == NMAP_SCAN_DEMAND: - start_first_detection(msg[NMAP_SCAN_DEMAND], ws) - elif code == GET_HOSTS_DEMAND: - db = module_loader.load_db() - ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) - del db - else: - break + try: + response = ws.receive() + if response is not None: + msg = json.loads(response) + for code in msg: + if code == NMAP_SCAN_DEMAND: + start_first_detection(msg[NMAP_SCAN_DEMAND], ws) + elif code == GET_HOSTS_DEMAND: + db = module_loader.load_db() + ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) + del db + else: + break + except: + break # Lancement du serveur a l'adresse 0.0.0.0:1337 diff --git a/app/module_loader.py b/app/module_loader.py index 71f0268..e61caed 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -24,7 +24,7 @@ def load_db(): return db_instance -def run_nmap_detection(ip_range, db, ws): +def run_nmap_detection(ip_range, db, ws, conn_mod_list): """ Instanciates the nmap_detection module from detection_modules, and runs the detection. :param ip_range: addresses to execute the nmap detection @@ -33,7 +33,7 @@ def run_nmap_detection(ip_range, db, ws): :return: a list containing the IP adresses checked """ nmap_mod = __import__("modules.detection_modules.nmap_detection", fromlist=modules.detection_modules) - nmap_mod_instance = getattr(nmap_mod, "nmap_detection")(db, ws) + nmap_mod_instance = getattr(nmap_mod, "nmap_detection")(db, ws, conn_mod_list) return nmap_mod_instance.check_ip_range(ip_range) @@ -72,7 +72,6 @@ def run_all_detection_modules(os, conn, db, ws): ws.send(json.dumps({"40": cnfe.__str__})) - def run_all_monitoring_modules(os, conn, db, ws): """ Instanciates and runs every monitoring_modules listed in the __init__.py file of the package corresponding to @@ -139,6 +138,17 @@ def get_info_mod_monitoring(os): return pack_mod_os.info_mod +def get_conection_modules_list(): + """ + Get a list containing the names of the different connection modules declared on the __init__.py file + of the connection_modules package. + :return: a list containing the names of the different connection modules declared on the __init__.py file + of the connection_modules package. + """ + pack_conn_os = __import__("modules.connection_modules", fromlist=modules.connection_modules.__all__) + return pack_conn_os.__all__ + + def create_global_conf(db): """ Asks the database to create a global configuration in function of the monitoring modules descibed on the __init__.py diff --git a/app/modules/detection_modules/nmap_detection.py b/app/modules/detection_modules/nmap_detection.py index f8c379e..eb9bf21 100644 --- a/app/modules/detection_modules/nmap_detection.py +++ b/app/modules/detection_modules/nmap_detection.py @@ -6,10 +6,11 @@ import json class nmap_detection: - def __init__(self, db, ws): + def __init__(self, db, ws, conn_mod_list): self.db = db self.ws = ws self.scanned_ip = [] + self.conn_mod_list = conn_mod_list # function for splitting the different ranges of the IP adress # launch the nmap detection of each ip under this range @@ -85,10 +86,10 @@ class nmap_detection: while child.isalive(): child.expect('Completed', timeout=None) except pexpect.EOF: - try: - self.parse_res(ip) - except: - self.ws.send(json.dumps({"40": "Database error"})) + #try: + self.parse_res(ip) + #except: + # self.ws.send(json.dumps({"40": "Database error"})) except pexpect.TIMEOUT: self.ws.send(json.dumps({"40": "Timeout on nmap execution"})) except pexpect.ExceptionPexpect: @@ -142,6 +143,6 @@ class nmap_detection: dict_host['openports'] = list_dict_port # the host have its IP for ID on the db print dict_host - self.db.add_host(dict_host['addr'], json.dumps(dict_host)) + self.db.add_host(dict_host['addr'], json.dumps(dict_host), self.conn_mod_list) pexpect.run("rm -f res.xml") self.scanned_ip.append(ip) \ No newline at end of file diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index b3c2d7e..968d379 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -43,7 +43,7 @@ class shelve_db: # Add and save a new host after its first nmap detection # It also preconfigure with the default configuration, add the host to the group "all" and # creates empty structures for the monitoring and archive data. - def add_host(self, addr_host, nmap_res): + def add_host(self, addr_host, nmap_res, conn_mod_list): """ Called by the nmap_detection module. Add and save a new host after its first nmap detection @@ -63,7 +63,7 @@ class shelve_db: self.db["hosts"][addr_host]["conf"] = {} self.db["hosts"][addr_host]["conf"]["monitoring"] = self.db["global_conf"] self.db["hosts"][addr_host]["conf"]["groups"] = ["all"] # Every host is in group "all" - self.db["hosts"][addr_host]["conf"]["connections"] = {} + self.db["hosts"][addr_host]["conf"]["connections"] = self.init_conn(json.loads(nmap_res), conn_mod_list) self.db["hosts"][addr_host]["conf"]["subscribers"] = {} # Add current user automatically ? self.db["hosts"][addr_host]["conf"]["custom_info"] = "" self.db["hosts"][addr_host]["conf"]["interventions"] = [] @@ -74,9 +74,26 @@ class shelve_db: finally: self.close_db() - # Returns the essential data about all hosts under monitoring - # These are used by the front-end - # If no hosts have been added, the function will return an empty list + def init_conn(self, dict_nmap_res, conn_list): + """ + Returns an initialization for the connection configuration on a host. + :param dict_nmap_res: The result of the nmap detection formatted to datastructures. + :param conn_list: A list of all connection modules avaliable + :return: + """ + res = [] + cpt = 1 + for port in dict_nmap_res['openports']: + if port["portname"] in conn_list: + dict_conn = {} + dict_conn[port["portname"]] = { + "priority": cpt, + "portid": int(port["portid"]), + } + res.append(dict_conn) + cpt += 1 + return res + def get_hosts(self): """ Returns the essential data about all hosts under monitoring -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 34f72679048bc828c3844403b16a8b40a557a3b6 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Feb 23 16:38:05 2015 +0100 scanned ip printed after scan --- app/app.py | 3 ++- app/modules/detection_modules/nmap_detection.py | 1 - app/modules/storage_modules/shelve_db.py | 12 ++++++------ static/js/controllers/detectCtrl.js | 1 + views/scan.html | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/app.py b/app/app.py index ba84339..0e9f74f 100755 --- a/app/app.py +++ b/app/app.py @@ -25,6 +25,7 @@ BROWSER_NOTIFICATION = "31" ERROR = "40" + # Pour lancer la detection nmap avec un nouveau thread class ThreadDetect(threading.Thread): def __init__(self, ip_range, ws): @@ -134,7 +135,7 @@ def receive(ws): del db else: break - except: + except: # Should be WebSocketError when closing the connection break diff --git a/app/modules/detection_modules/nmap_detection.py b/app/modules/detection_modules/nmap_detection.py index eb9bf21..7d77fb5 100644 --- a/app/modules/detection_modules/nmap_detection.py +++ b/app/modules/detection_modules/nmap_detection.py @@ -142,7 +142,6 @@ class nmap_detection: list_dict_port.append(dict_port) dict_host['openports'] = list_dict_port # the host have its IP for ID on the db - print dict_host self.db.add_host(dict_host['addr'], json.dumps(dict_host), self.conn_mod_list) pexpect.run("rm -f res.xml") self.scanned_ip.append(ip) \ No newline at end of file diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 968d379..00b1d88 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -275,21 +275,21 @@ class shelve_db: stats['M2'] += stats['delta'] * (val - stats['mean']) return stats - def create_global_conf(self, dict): + def create_global_conf(self, dict_mod_info): """ Create an entry on the global_conf for each new monitoring module. - :param dict: dictionary containing informations about all notification modules, by os, in the form: + :param dict_mod_info: dictionary containing informations about all notification modules, by os, in the form: [os_name][monitoring_module_name][{'block':val, 'unit': val}] """ self.open_db() try: - for os in dict: + for os in dict_mod_info: if os not in self.db['global_conf']: self.db['global_conf'][os] = {} - for mod in dict[os]: + for mod in dict_mod_info[os]: if mod not in self.db['global_conf'][os]: self.db['global_conf'][os][mod] = {} - self.db['global_conf'][os][mod]['block'] = dict[os][mod]['block'] + self.db['global_conf'][os][mod]['block'] = dict_mod_info[os][mod]['block'] self.db['global_conf'][os][mod]['activated'] = True self.db['global_conf'][os][mod]['check_frequency'] = 3600 self.db['global_conf'][os][mod]['nb_minute'] = 30 @@ -298,7 +298,7 @@ class shelve_db: self.db['global_conf'][os][mod]['nb_week'] = 2 self.db['global_conf'][os][mod]['nb_month'] = 6 self.db['global_conf'][os][mod]['nb_year'] = None - unit = dict[os][mod]['unit'] + unit = dict_mod_info[os][mod]['unit'] self.db['global_conf'][os][mod]['unit'] = unit if unit == '%': self.db['global_conf'][os][mod]['minor_limit'] = 95 diff --git a/static/js/controllers/detectCtrl.js b/static/js/controllers/detectCtrl.js index deed7f1..344182f 100644 --- a/static/js/controllers/detectCtrl.js +++ b/static/js/controllers/detectCtrl.js @@ -20,6 +20,7 @@ formExample.controller('DetectController', ['$scope', 'toastr', '$interval', fun case 20: // Success of a module execution $scope.$apply(function(){ $scope.state = "Success!"; + $scope.ip_scanned = value; }); toastr.success(value, "Success on module execution"); case 21: // Informations concerning one host diff --git a/views/scan.html b/views/scan.html index f879936..2ee59af 100644 --- a/views/scan.html +++ b/views/scan.html @@ -71,6 +71,7 @@ </div> <div ng-show="validated == true"> {{state}} + {{ip_scanned}} </div> </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm