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 c6574534099a656b63c3ff5851b33f28e711fa6b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 18 16:04:39 2015 +0100 user page : OK pour la création et la suppression d'un utilisateur --- app/app.py | 24 +++++++++--------- app/modules/storage_modules/shelve_db.py | 42 +++++++++++++++++++++++++++++--- static/js/controllers/usersCtrl.js | 32 ++++++++++++++++++++++++ static/js/mumApp.js | 4 +-- views/index.html | 1 + views/scan.html | 6 ++--- views/users.html | 20 +++++---------- 7 files changed, 94 insertions(+), 35 deletions(-) diff --git a/app/app.py b/app/app.py index 1d89861..15a5180 100755 --- a/app/app.py +++ b/app/app.py @@ -123,40 +123,40 @@ def receive(ws): if response is not None: msg = json.loads(response) for code in msg: - if code == "NMAP_SCAN_DEMAND": + if code == "NMAP_SCAN_DEMAND": # asked from scan page start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) - elif code == "LAUNCH_FULL_DETECTION": + elif code == "LAUNCH_FULL_DETECTION": # asked from hostpage ml.run_all_detection_modules(msg["LAUNCH_FULL_DETECTION"]) ws.send(json_dumps({"SUCCESS_MODULE": "Full detection"})) - elif code == "GET_HOSTS": + elif code == "GET_HOSTS": # asked from head controller db = ml.get_db() ws.send(json.dumps({"RES_GET_HOSTS": db.get_hosts()})) - elif code == "GET_HOST_INFO": + elif code == "GET_HOST_INFO": # asked from hostpage db = ml.get_db() ws.send(json.dumps({"RES_INFO_HOST": db.get_host_informations(msg["GET_HOST_INFO"])})) - elif code == "CALL_FUNC_DB": + elif code == "CALL_FUNC_DB": # asked when the request can directly pass by database res = ml.launch_db_function(msg["CALL_FUNC_DB"]) if res is not None: ws.send(json.dumps({"RES_CALL_FUNC_DB": res})) else: print 'res is None' - elif code == "GET_LOADED_CONN_MOD": + elif code == "GET_LOADED_CONN_MOD": # asked from hostpage, at the connection configuration ws.send(json_dumps({"RES_GET_LOADED_CONN_MOD": ml.get_info_mod_conn()})) - elif code == "GET_LOADED_MONI_MOD": + elif code == "GET_LOADED_MONI_MOD": # asked from hostpage, at the block activation conf ws.send(json_dumps({"RES_GET_LOADED_MONI_MOD": ml.get_info_mod_monitoring()})) - elif code == "SET_MOD_ACTIVATION": + elif code == "SET_MOD_ACTIVATION": # asked from hostpage, at the block activation conf ml.update_activated_modules(msg["SET_MOD_ACTIVATION"]) - elif code == "SET_CONF_MOD": + elif code == "SET_CONF_MOD": # asked from hostpage, at the monitoring module configuration ml.launch_db_function({'func': 'set_conf_mod', 'args': msg["SET_CONF_MOD"]}) process_monitoring.update_mod_on_waiting_list(msg["SET_CONF_MOD"]) - elif code == "CHECK_NOW": + elif code == "CHECK_NOW": # asekd from hostpage args = msg["CHECK_NOW"] ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) - elif code == "GET_KEYS_LIST": + elif code == "GET_KEYS_LIST": # asked from hostpage, at the connection configuration ws.send(json_dumps({"KEYS_LIST": ml.get_public_keys_list()})) else: break - except WebSocketError: # Should be WebSocketError when closing the connection + except WebSocketError: # Should be WebSocketError when closing the connection wsc.remove_websocket(ws) break diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 97e993e..19e5776 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -631,6 +631,7 @@ class shelve_db: :param mod_name: the name of the monitoring_module which have done the check :param val: the value observed """ + #failure = None self.open_db() new_val = {"date": str(datetime.now()), "value": val} try: @@ -673,6 +674,19 @@ class shelve_db: and not state == 'danger': state = 'warning' self.db['hosts'][addr_host]['status']['state'] = state + # create a notify structure if the state is not a success + """ + if not new_val['state'] == 'success': + failure = {} + failure['addr_host'] = addr_host + failure['mod_name'] = mod_name + failure['state'] = new_val['state'] + failure['subscribers'] = {} + for subscriber in self.db['hosts'][addr_host]['conf']['subscribers']: + failure['subscribers'][subscriber] = {} + failure['subscribers'][subscriber][''] + failure['groups_to_notify'] = self.db['hosts'][addr_host]['conf']['groups'] + """ # now performing archiving """ if mod_name in self.db['hosts'][addr_host]['archive']: @@ -681,6 +695,7 @@ class shelve_db: """ finally: self.close_db() + #return failure def update_stats(self, stats, val): """ @@ -750,11 +765,13 @@ class shelve_db: finally: self.close_db() - def create_user(self, username): + def create_user(self, args): """ Create a basic empty structure on the database for a new user. - :param username:string containing the name of the user + :param args: a dictionary containing : + { 'username': val } """ + username = args['username'] self.open_db() try: self.db['users'][username] = {} @@ -765,11 +782,28 @@ class shelve_db: finally: self.close_db() - def remove_user(self, username): + def get_users(self, args): + """ + Called by the user managment page. + :param args: None (necessary for dynamic call via websocket) + :return: A list containing the users registered. + """ + res = [] + self.open_db() + try: + for user in self.db['users']: + res.append(user) + finally: + self.close_db() + return json.dumps(res) + + def remove_user(self, args): """ Removes a user from the database. If the user is registered to a host or a group, it is also deleted from these lists - :param username: string containing the name of the user + :param args: a dictionary containing : + { 'username': val } """ + username = args['username'] self.open_db() try: # deletion of the user diff --git a/static/js/controllers/usersCtrl.js b/static/js/controllers/usersCtrl.js new file mode 100644 index 0000000..dca6322 --- /dev/null +++ b/static/js/controllers/usersCtrl.js @@ -0,0 +1,32 @@ +mumApp.controller('usersCtrl', function($scope, $rootScope, $route) { + $scope.users = {}; + + $scope.selected_user = ""; + + $scope.show_new_user = false; + + $scope.new_username = ""; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); + + // receiving the user list + $scope.$on("resCall", function (event, args) { + $scope.$apply(function(){ + $scope.users = args; + }); + }); + + $scope.addUser = function(){ + var args = {}; + args['username'] = $scope.new_username; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'create_user', 'args': args}})); + $route.reload(); + } + + $scope.removeUser = function(){ + var args = {}; + args['username'] = $scope.selected_user; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_user', 'args': args}})); + $route.reload(); + } +}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index bc223ef..2068b61 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -51,8 +51,8 @@ mumApp.config(function($routeProvider){ //controller : 'mainController' }) .when('/users',{ - templateUrl : 'users.html' - //controller : 'mainController' + templateUrl : 'users.html', + controller : 'usersCtrl' }) .otherwise({ redirectTo: '/' diff --git a/views/index.html b/views/index.html index f273638..d80e11c 100644 --- a/views/index.html +++ b/views/index.html @@ -32,6 +32,7 @@ <script src="static/js/controllers/scanCtrl.js"></script> <script src="static/js/controllers/hostPageCtrl.js"></script> <script src="static/js/controllers/groupCtrl.js"></script> + <script src="static/js/controllers/usersCtrl.js"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- diff --git a/views/scan.html b/views/scan.html index 4eb2162..1a94296 100644 --- a/views/scan.html +++ b/views/scan.html @@ -1,16 +1,16 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Scan for new machines</h1> - <div ng-show="validated == false" class="ng-hide"> + <div ng-show="!validated" class="ng-hide"> <form class="form-inline" ng_submit="post_val()"> <label for="input_ip_range">Enter a hostname, a single IP or an IP range to scan (example : 198.116.0.1-10)</label> <input type="text" class="form-control" id="input_ip_range" ng-model="ip_range"/><br/> <button type="button" class="btn btn-danger" ng-click="show_opt = !show_opt">Show nmap options (careful)</button> - <input type="text" class="form-control" ng-show="show_opt == true" ng-model="nmap_options"/> + <input type="text" class="form-control" ng-show="show_opt" ng-model="nmap_options"/> <button type="submit" class="btn btn-primary" ng-click="validated = true">Scan now</button> </form> </div> - <div ng-show="validated == true"> + <div ng-show="validated"> <p>{{state}}</p> <p>Scanned IP : {{ip_scanned}}</p> </div> diff --git a/views/users.html b/views/users.html index 10d7d23..eeb1f4d 100644 --- a/views/users.html +++ b/views/users.html @@ -4,20 +4,12 @@ <div class="row"> <div class="col-xs-4"> <label for="usrlist">Registered users</label> - <select class="form-control" id="usrlist"> - <option>D.D.</option> - <option>G.G.</option> - <option>J.C.</option> - <option>J.D.</option> - <option>X.R.</option> - </select> - </div> - </div> - <div class="row"> - <div class="col-xs-4"> - <button type="button" class="btn btn-primary btn-xs" data-toggle="popover" - data-placement="bottom" title="Add user..." data-content="ger">Add user</button> - <button type="button" class="btn btn-danger btn-xs">Remove selected</button> + <select class="form-control input-sm" id="usrlist" ng-model="selected_user" ng-options="user as user for user in users"></select> </div> </div> + <button type="button" class="btn btn-primary" data-toggle="popover" + data-placement="bottom" title="Add user..." data-content="ger" ng-click="show_new_user=!show_new_user">Add user</button> + <input type="text" ng-show="show_new_user" ng-model="new_username"> + <button type="button" class="btn btn-primary" ng-show="show_new_user && new_username!=''" ng-click="addUser()">Create user</button> + <button type="button" class="btn btn-danger" ng-show="selected_user!=''" ng-click="removeUser()">Remove {{selected_user}}</button> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.