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 39775c0c1718ad5d0b6f40286800650b21300b66 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Jun 4 11:52:15 2015 +0200 hostpage: module managment directly through the page (removed the old modal) --- app/websocket_func.py | 6 +- static/js/controllers/hostPageCtrl.js | 156 ++++++++++------------------------ views/hostpage.html | 102 +++++++++++----------- 3 files changed, 98 insertions(+), 166 deletions(-) diff --git a/app/websocket_func.py b/app/websocket_func.py index 5602f39..f97537b 100644 --- a/app/websocket_func.py +++ b/app/websocket_func.py @@ -98,12 +98,12 @@ def GET_LOADED_CONN_MOD(msg, ws, ml): ws.send(json.dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) -# asekd from notification parameters page +# asekd from dashboard def GET_LOADED_NOTIF_MOD(msg, ws, ml): ws.send(json.dumps({"RES_GET_LOADED_NOTIF_MOD": ml.get_info_mod_notification()})) -# asekd from notification parameters page +# asekd from dashboard def GET_ALL_SUBSCRIPTIONS(msg, ws, ml): ws.send(json.dumps({"RES_GET_ALL_SUBSCRIPTIONS": ml.get_all_subscriptions()})) @@ -117,7 +117,7 @@ def SET_IDLE_STATE(msg, ws, ml): ws.send(json.dumps({"RES_GET_HOSTS": ml.get_db().get_hosts()})) -# asked from hostpage, at the block activation conf +# asked from hostpage def SET_MOD_ACTIVATION(msg, ws, ml): ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) ws.send(json.dumps({"RES_GET_HOSTS": ml.db.get_hosts()})) diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index e802d61..319a75a 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -52,9 +52,22 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa $scope.selectedAll = false; + $scope.blocks = {}; /* + block_name: + { + mod_name: + { + 'modname':val, + 'activated': bool + } + } + */ + + $scope.selected_mod_part = ""; + $scope.rescan = function () { $location.path('/scan/' + $scope.addr_host); - } + }; $scope.update_nmap_attribute = function (attribute, new_value) { var args = {}; @@ -75,14 +88,14 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa } } $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_subpart', 'args': args}})); - } + }; $scope.checkAll = function (modname, bool) { $scope.selectedAll = bool; for(key in $scope.subparts_checked[modname]) { $scope.subparts_checked[modname][key] = bool; } - } + }; $scope.get_unit = function (mod_name) { res = ''; @@ -98,7 +111,7 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa res = Math.max(res, $scope.items.monitoring[modname].value[key]); } return res; - } + }; $scope.get_type_of = function (attr) { return typeof(attr); @@ -149,7 +162,7 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa $scope.set_idle_state = function () { $rootScope.$broadcast("sendViaWs", JSON.stringify({"SET_IDLE_STATE": $scope.addr_host})); - } + }; $scope.get_addr_host = function () { return($scope.addr_host); @@ -175,13 +188,39 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa } } } + else { // we take only monitoring updates $scope.items.monitoring = args.monitoring; $scope.items.status = args.status; } + + // Updating struct for activated modules selection in any case + $scope.blocks = {}; + for (mod in args.loaded_moni_mod) { + var activated = false; + var block = args.loaded_moni_mod[mod]['block']; + if (args.activated_monitoring.hasOwnProperty(mod)) { // if the module is known by the host + if (args.activated_monitoring[mod]) { // if the module is activated + activated = true; + } + } + if (!$scope.blocks.hasOwnProperty(block)) { + $scope.blocks[block] = []; + } + $scope.blocks[block][$scope.blocks[block].length] = {modname: mod, activated: activated}; + } }, 0); }); + $scope.update_module_activation = function (modname, bool_activation) { + var args = {}; + args['addr_host'] = $scope.addr_host; + args['activated'] = {}; + args['activated'][modname] = bool_activation; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"SET_MOD_ACTIVATION": args})); + }; + // refresh after full detection $scope.$on("success", function (event, args) { if (args == 'Full detection') { @@ -239,22 +278,6 @@ mumApp.controller('hostPageCtrl', function ($scope, $rootScope, $route, $routePa }); }; - $scope.open_modal_block = function () { - var modalInstance = $modal.open({ - templateUrl: 'modal_block_label.html', - controller: 'ModalBlockInstanceCtrl', - size: 'lg', - resolve: { - block_args: function () { - return {'addr_host' : $scope.addr_host, - 'activated_mod': $scope.items['activated_monitoring'], - 'os_host': $scope.items.detected.nmap.os, - 'loaded_moni_mod': $scope.items.loaded_moni_mod}; - } - } - }); - }; - $scope.open_modal_confirm_delete = function () { var modalInstance = $modal.open({ templateUrl: 'modal_confirm_delete_label.html', @@ -578,97 +601,6 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo }; }); -mumApp.controller('ModalBlockInstanceCtrl', function ($scope, $rootScope, $modalInstance, $route, $timeout, block_args) { - $scope.block_args = block_args; /* {'addr_host': val, - 'activated_mod':{ - mod_name: bool - }, - 'os_host': val, - "loaded_moni_mod": - { - mod_name: - { - 'compatible_os': [val1, val2, ...], => a list containing the compatibles os - 'unit': val, => the unit type of return ('%', 'bool' or other) - 'block': val, => the monitoring block of the module - 'part':val, => the part checked by the moni mod - 'compatible_conn': [val1, val2, ...] => a list containing the compatibles connection modules - } - } - } - */ - - $scope.blocks = {}; /* - block_name: - { - mod_name: - { - 'modname':val, - 'activated': bool - } - } - */ - - for (mod in $scope.block_args.loaded_moni_mod) { - var activated = false; - var block = $scope.block_args.loaded_moni_mod[mod]['block']; - if ($scope.block_args.activated_mod.hasOwnProperty(mod)) { // if the module is known by the host - if ($scope.block_args.activated_mod[mod]) { // if the module is activated - activated = true; - } - } - if (!$scope.blocks.hasOwnProperty(block)) { - $scope.blocks[block] = []; - } - $scope.blocks[block][$scope.blocks[block].length] = {modname: mod, activated: activated}; - } - - $scope.select_all = function (block) { - $timeout(function () { // to prevent "inprog" angular error - for (var i=0; i<block.length; i++) { - if (!$scope.is_not_compatible(block[i].modname)) { - block[i].activated = true; - } - } - }, 0); - }; - - $scope.select_none = function (block) { - $timeout(function () { // to prevent "inprog" angular error - for (var i=0; i<block.length; i++) { - block[i].activated = false; - } - }, 0); - }; - - $scope.is_not_compatible = function (modname) { - // returns true if the OS of the host is part of the compatible OS list of the module modname ; Or if the module - // modname is comatible with all OS. - return ($scope.block_args.loaded_moni_mod[modname].compatible_os.lastIndexOf($scope.block_args.os_host) < 0) && - ($scope.block_args.loaded_moni_mod[modname].compatible_os.lastIndexOf('all') < 0); - }; - - $scope.ok = function () { - var args = {}; - args['addr_host'] = $scope.block_args['addr_host']; - args['activated'] = {}; - for (block in $scope.blocks) { - for (mod in $scope.blocks[block]) { - args['activated'][$scope.blocks[block][mod]['modname']] = $scope.blocks[block][mod]['activated']; - } - } - - $rootScope.$broadcast("sendViaWs", JSON.stringify({"SET_MOD_ACTIVATION": args})); - - $modalInstance.close(); - - $route.reload(); - }; - - $scope.cancel = function () { - $modalInstance.close(); - }; -}); mumApp.controller('ModalConfirmDeleteInstanceCtrl', function ($scope, $rootScope, $modalInstance, $location, $timeout, confirm_delete_args) { $scope.confirm_delete_args = confirm_delete_args; diff --git a/views/hostpage.html b/views/hostpage.html index fc0309d..9abfbd8 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -12,12 +12,6 @@ <span class="glyphicon glyphicon-off" aria-hidden="true"></span> </button></small></h1> - <button type="button" class="btn btn-primary btn-xs" - ng-click="open_modal_block()" - popover="Activate or deactivate monitoring modules by section." - popover-trigger="mouseenter" - ng-disabled="items.status == 'idling'">Activate/Deactivate</button> - <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_conn()">Connection settings</button> @@ -49,18 +43,46 @@ class={{mod.state}} > <!-- ng-show="items.activated_monitoring[modname]" --> <td>{{modname}}</td> - <td ng-show="get_type_of(mod.value) != 'object'">{{mod.value}} {{get_unit(modname)}}</td> + <td ng-show="get_type_of(mod.value) != 'object'"> + {{mod.value}} {{get_unit(modname)}} + </td> <td ng-show="get_type_of(mod.value) == 'object'"> - <a ng-click="collapsed[modname] = !collapsed[modname]">{{get_maxvalue(modname)}} {{get_unit(modname)}} ▼</a> + <a ng-click="collapsed[modname] = !collapsed[modname]"> + {{get_maxvalue(modname)}} {{get_unit(modname)}} ▼ + </a> + </td> + <td> + {{mod.state}} + </td> + <td> + {{mod.date.split('.')[0]}} + </td> + <td> + <button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_conf(modname)">Configure + </button> + </td> + <td> + <button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_stats(addr_host, modname, '')">Archives + </button> + </td> + <td> + <button type="button" class="btn btn-info btn-xs" + ng-click="check(modname)">Check now + </button> + </td> + <td> + <button type="button" + class="btn btn-danger btn-xs" + aria-label="Stop monitoring of this part" + popover-placement="left" + popover="Stop the monitoring of this part" + popover-trigger="mouseenter" + ng-click="update_module_activation(modname, false)"> + <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> + </button> </td> - <td>{{mod.state}}</td> - <td>{{mod.date.split('.')[0]}}</td> - <td><button type="button" class="btn btn-primary btn-xs" - ng-click="open_modal_conf(modname)">Configure</button></td> - <td><button type="button" class="btn btn-primary btn-xs" - ng-click="open_modal_stats(addr_host, modname, '')">Archives</button></td> - <td><button type="button" class="btn btn-info btn-xs" - ng-click="check(modname)">Check now</button></td> </tr> <tr ng-repeat-end ng-repeat="(valname, val) in mod.value" @@ -74,6 +96,19 @@ </table> + <label for="add_mod_select">Add a part to monitore: </label> + <select id="add_mod_select" + ng-model="selected_mod_part"> + <optgroup ng-repeat="(blockname, block) in blocks" + label="{{blockname}}"> + <option ng-repeat="mod_obj in block" + ng-show="!mod_obj.activated" + ng-click="update_module_activation(mod_obj.modname, true)"> + {{mod_obj.modname}} + </option> + </optgroup> + </select> + <accordion close-others="false"> <accordion-group heading="Essential configuration (nmap detection)"> @@ -428,41 +463,6 @@ </div> </script> - <script type="text/ng-template" id="modal_block_label.html"> - <div class="modal-header"> - <h3 class="modal-title">Activate/Deactivate monitoring blocks</h3> - </div> - - <div class="modal-body"> - <table class="table table-bordered table-hover"> - <tr ng-repeat-start="(blockname, block) in blocks"> - <th>{{blockname}}</th> - <th><button type="button" class="btn" ng-click="select_all(block)">Select all</button> - <button type="button" class="btn" ng-click="select_none(block)">Select none</button> - </th> - <th>Compatible Connections</th> - <th>Compatible OS</th> - </tr> - <tr ng-repeat-end - ng-repeat="mod in block"> - <td>{{mod.modname}}</td> - <td><input type="checkbox" - ng-model="mod.activated" - ng-disabled="is_not_compatible(mod.modname)"></td> - <td>{{block_args.loaded_moni_mod[mod.modname].compatible_conn}}</td> - <td>{{block_args.loaded_moni_mod[mod.modname].compatible_os}}</td> - </tr> - </table> - </div> - - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal" - ng-click="cancel()">Close</button> - <button type="button" class="btn btn-primary" - ng-click="ok()">Save changes</button> - </div> - </script> - <script type="text/ng-template" id="modal_confirm_delete_label.html"> <div class="modal-header"> <h3 class="modal-title">Are you sure you want to delete {{confirm_delete_args.addr_host}} ?</h3> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.