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 40c8d678e649aeb459a1891b03d877fdb9ddcda0 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Apr 16 18:03:42 2015 +0200 navbar: current tasks running on the center of navbar (number of max tasks defined on headCtrl) --- app/module_loader.py | 8 +++++ .../notification_modules/websocket_container.py | 6 +++- app/modules/storage_modules/shelve_db.py | 41 ++++++++++++++++++++++ app/mum.py | 32 ++++++++++------- static/js/controllers/headCtrl.js | 25 ++++++++++++- static/js/controllers/hostPageCtrl.js | 9 ----- views/index.html | 8 +++++ 7 files changed, 106 insertions(+), 23 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 72e265a..1ab1618 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -52,6 +52,14 @@ class ModuleLoader: def get_websocket_container(self): return self.wsc + def create_task(self, task_id): + self.db.store_task(task_id) + self.wsc.notify_task_change() + + def remove_task(self, task_id): + self.db.remove_task(task_id) + self.wsc.notify_task_change() + @staticmethod def add_to_waiting_list(instr): process_monitoring.add_to_waiting_list(instr) diff --git a/app/modules/notification_modules/websocket_container.py b/app/modules/notification_modules/websocket_container.py index b23abed..98dfb60 100644 --- a/app/modules/notification_modules/websocket_container.py +++ b/app/modules/notification_modules/websocket_container.py @@ -16,4 +16,8 @@ class WebSocketContainer: def notify_state_change(self): for ws in self.ws_set: - ws.send(json.dumps({"RES_GET_HOSTS": self.db.get_hosts()})) \ No newline at end of file + ws.send(json.dumps({"RES_GET_HOSTS": self.db.get_hosts()})) + + def notify_task_change(self): + for ws in self.ws_set: + ws.send(json.dumps({"RES_TASK_LIST": self.db.get_task_list()})) \ 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 4c24929..acecdd2 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -36,6 +36,7 @@ class shelve_db: self.db["users"] = {} self.db["groups"] = {} self.db["global_conf"] = {} + self.db["tasks"] = [] except: print "Database initilalization error" self.db.close() @@ -1271,4 +1272,44 @@ class shelve_db: print traceback.format_exc() finally: self.close_db() + return res + + def store_task(self, task_id): + """ + Stores a new task into the database + :param task_id: the id of the task + """ + self.open_db() + try: + self.db['tasks'].append(task_id) + except Exception: + print traceback.format_exc() + finally: + self.close_db() + + def remove_task(self, task_id): + """ + Removes a new task into the database + :param task_id: the id of the task + """ + self.open_db() + try: + self.db['tasks'].remove(task_id) + except Exception: + print traceback.format_exc() + finally: + self.close_db() + + def get_task_list(self): + """ + :return: The list of current tasks + """ + res = [] + self.open_db() + try: + res = self.db['tasks'] + except Exception: + print traceback.format_exc() + finally: + self.close_db() return res \ No newline at end of file diff --git a/app/mum.py b/app/mum.py index a4a43e7..016306f 100755 --- a/app/mum.py +++ b/app/mum.py @@ -21,24 +21,30 @@ class ThreadDetect(threading.Thread): self.ws = ws # websocket connection def run(self): + task_name = "Scanning " + self.param + self.ml.create_task(task_name) scanned_ip = self.ml.run_nmap_detection(self.param, self.opt, self.ws) if scanned_ip is not None: - self.ws.send(json.dumps({"SUCCESS_MODULE": scanned_ip})) + try: + self.ws.send(json.dumps({"SUCCESS_MODULE": scanned_ip})) + except WebSocketError: + pass for ip in json.loads(scanned_ip): monitoring_intructions = ml.get_db().get_monitoring_instructions(ip) for instr in monitoring_intructions: ml.add_to_waiting_list(instr) - """ - # 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, self.ws) - monitoring_intructions = db.get_monitoring_instructions(ip) - for instr in monitoring_intructions: - process_monitoring.add_to_waiting_list(instr) - #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) - # adding entries on process monitoring - """ + self.ml.remove_task(task_name) + """ + # 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, self.ws) + monitoring_intructions = db.get_monitoring_instructions(ip) + for instr in monitoring_intructions: + process_monitoring.add_to_waiting_list(instr) + #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) + # adding entries on process monitoring + """ # Launching of the detection after getting a ip range. @@ -172,6 +178,8 @@ def receive(ws): ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) elif code == "GET_KEYS_LIST": # asked from hostpage, at the connection configuration ws.send(json.dumps({"KEYS_LIST": ml.get_public_keys_list()})) + elif code == "TASK_LIST": + ws.send(json.dumps({"RES_TASK_LIST": ml.get_db().get_task_list()})) else: break except WebSocketError: # Should be WebSocketError when closing the connection diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index f162fd2..f21d1b8 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -5,6 +5,8 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.items = DataHosts.Items; + $scope.task_list = []; + $scope.$on("hostsUpdate", function (event) { $scope.items = DataHosts.Items; }); @@ -15,8 +17,24 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r ws.onopen = function() { var request = JSON.stringify({"GET_HOSTS": ""}); ws.send(request); + ws.send(JSON.stringify({"TASK_LIST": null})); }; + $scope.max_tasks = 2; + + $scope.format_task_list = function(task_list){ + res = ""; + var i = 0; + while(i<$scope.task_list.length && i<$scope.max_tasks){ + res += task_list[i] + ", "; + i++; + } + if($scope.task_list.length > $scope.max_tasks){ + res += "+ " + (task_list.length - $scope.max_tasks) + " other tasks"; + } + return res; + } + // instructions received from other controllers // args contains a json formatted string $scope.$on("sendViaWs", function (event, args) { @@ -89,7 +107,12 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r break; case "KEYS_LIST": $rootScope.$broadcast("keysList", obj[key]); - break + break; + case "RES_TASK_LIST": + $scope.$apply(function(){ + $scope.task_list = obj[key]; + }); + break; case "ERROR": toastr.error(obj[key], "Server error"); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 8376b82..858b796 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -419,14 +419,6 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo } } */ - /*$scope.loaded_conn_mods = $scope.loaded_conn_mods; /* { - mod_name: - { - 'class_name': val, => the name of the class to instanciate - 'imported': module, => the module imported - 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection - } - } */ $scope.conf_conn = {}; $scope.port = $scope.conf_conn_args["current_config"][$scope.conf_conn_args.modname]["port"]; @@ -440,7 +432,6 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo $scope.keys_list = []; $scope.show_form = function(param_name){ - //alert(JSON.stringify($scope.conf_conn_args.loaded_conn_mods[$scope.conf_conn_args.modname].params)); return $scope.conf_conn_args.loaded_conn_mods[$scope.conf_conn_args.modname].hasOwnProperty(param_name); } diff --git a/views/index.html b/views/index.html index c4c02a9..1025258 100644 --- a/views/index.html +++ b/views/index.html @@ -61,6 +61,14 @@ <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> <p class="navbar-text navbar-left"><a href="#dashboard/idling" style="color:grey">Idling : {{stateNumber()[3]}}</a></p> + <p class="navbar-text navbar-left" + style="colod:white" + ng-show="task_list.length > 0" + popover-placement="bottom" + popover="{{task_list}}" + popover-trigger="mouseenter">Current tasks: {{format_task_list(task_list)}} + <span class="glyphicon glyphicon-collapse-down"></span> + </p> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.