branch develop updated (c657453 -> 017493c)
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 c657453 user page : OK pour la création et la suppression d'un utilisateur new b4322a1 notifications page : select ng-options pour groupes et hôtes OK new 017493c notifications page : possibilité d'ajouter un utilisateur à la liste des inscrits d'un groupe et d'un hôte The 2 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 017493c6b978fdcacf8d595bc4aa983f0dee34e1 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 19 15:40:29 2015 +0100 notifications page : possibilité d'ajouter un utilisateur à la liste des inscrits d'un groupe et d'un hôte commit b4322a11821943587daec3a27416275779d09d03 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 18 17:52:11 2015 +0100 notifications page : select ng-options pour groupes et hôtes OK Summary of changes: app/modules/storage_modules/shelve_db.py | 153 +++++++++++++++++++++++++---- static/js/controllers/notificationsCtrl.js | 106 ++++++++++++++++++++ static/js/mumApp.js | 4 +- views/index.html | 13 +-- views/notifications.html | 71 +++++++++---- views/users.html | 2 +- 6 files changed, 305 insertions(+), 44 deletions(-) create mode 100644 static/js/controllers/notificationsCtrl.js -- 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 b4322a11821943587daec3a27416275779d09d03 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 18 17:52:11 2015 +0100 notifications page : select ng-options pour groupes et hôtes OK --- static/js/controllers/notificationsCtrl.js | 34 ++++++++++++++++++++++ static/js/mumApp.js | 4 +-- views/index.html | 13 +++++---- views/notifications.html | 45 ++++++++++++++++++++---------- views/users.html | 2 +- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js new file mode 100644 index 0000000..95e2cf1 --- /dev/null +++ b/static/js/controllers/notificationsCtrl.js @@ -0,0 +1,34 @@ +mumApp.controller('notificationsCtrl', function($scope, $rootScope, DataHosts) { + $scope.items = DataHosts.Items; /* [ + { + "addr":"192.168.74.1", + "name":"www.example.com", + "status":val, //"success" or "warning" or "danger" or "" + "group":[ "all", ...], + "last_check":val //UNIX time + "subscribers":{ + "uid":val, + "priority":val + } + "warning": [mod_name, ...] + "danger": [mod_name, ...] + }, + ... + ] + */ + + $scope.allGroups = function(){ + var res = [] + for(var i = 0; i<$scope.items.length; i++){ + for(var j = 0; j<$scope.items[i].group.length; j++){ + res.push($scope.items[i].group[j]); + } + } + return res; + }; + + $scope.selected_grp = ""; + $scope.selected_host = ""; + + $scope.option_selected = ""; +}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 2068b61..3f76c6d 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -27,8 +27,8 @@ mumApp.config(function($routeProvider){ controller : 'hostPageCtrl' }) .when('/notifications',{ - templateUrl : 'notifications.html' - //controller : 'mainController' + templateUrl : 'notifications.html', + controller : 'notificationsCtrl' }) .when('/profile',{ templateUrl : 'profile.html' diff --git a/views/index.html b/views/index.html index d80e11c..bb44098 100644 --- a/views/index.html +++ b/views/index.html @@ -26,13 +26,14 @@ <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script> - <script src="static/js/mumApp.js"></script> - <script src="static/js/controllers/dashboardCtrl.js"></script> - <script src="static/js/controllers/headCtrl.js"></script> - <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/mumApp.js"></script> + <script src="static/js/controllers/dashboardCtrl.js"></script> + <script src="static/js/controllers/headCtrl.js"></script> + <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> + <script src="static/js/controllers/notificationsCtrl.js"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- diff --git a/views/notifications.html b/views/notifications.html index 172e172..17bd3ac 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -3,20 +3,37 @@ <h1 class="page-header">Who to notify?</h1> <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> <form> - <label for="grp_choice">Select one host or one group :</label> - <select class="form-control" id="grp_choice"> - <option value="142.42.13.37" class="optionChild">142.42.13.37 www.nerd.org</option> - <option value="mygroup1" class="optionGroup">mygroup1</option> - <option value="192.168.74.1" class="optionChild">192.168.74.1 www.example.com</option> - <option value="192.168.74.2" class="optionChild">192.168.74.2 www.example.com</option> - <option value="192.168.74.3" class="optionChild">192.168.74.3 www.example.com</option> - <option value="mygroup2" class="optionGroup">mygroup2</option> - <option value="135.47.86.11" class="optionChild">135.47.86.11 www.blabla.fr</option> - <option value="135.47.86.12" class="optionChild">135.47.86.12 www.blabla.fr</option> - <option value="mygroup3" class="optionGroup">mygroup3</option> - <option value="192.147.0.0" class="optionChild">192.147.0.0</option> - <option value="192.147.0.1" class="optionChild">192.147.0.1</option> - </select> + <div class="row"> + <div class="col-lg-6"> + <div class="input-group"> + <span class="input-group-addon"> + <input type="radio" ng-model="option_selected" value="grp" + ng-change="selected_host=''"> + </span> + <label for="grp_choice">Select one group :</label> + <select class="form-control input-sm" id="grp_choice" + ng-model="selected_grp" + ng-options="item for item in allGroups() | unique:'group'" + ng-disabled="option_selected!='grp'"></select> + </div> + </div> + <div class="col-lg-6"> + <div class="input-group"> + <span class="input-group-addon"> + <input type="radio" ng-model="option_selected" value="host" + ng-change="selected_grp=''"> + </span> + <label for="host_choice">or one host :</label> + <select class="form-control input-sm" id="host_choice" + ng-model="selected_host" + ng-options="host.addr group by host.group for host in items" + ng-disabled="option_selected!='host'"></select> + </div> + </div> + </div> + + + </form> <p>Check the box if you want the user to be notified by the correspondant service.</p> diff --git a/views/users.html b/views/users.html index eeb1f4d..dfe9c5c 100644 --- a/views/users.html +++ b/views/users.html @@ -11,5 +11,5 @@ 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> + <button type="button" class="btn btn-danger" ng-show="selected_user!='' && selected_user!=null" 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>.
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 017493c6b978fdcacf8d595bc4aa983f0dee34e1 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 19 15:40:29 2015 +0100 notifications page : possibilité d'ajouter un utilisateur à la liste des inscrits d'un groupe et d'un hôte --- app/modules/storage_modules/shelve_db.py | 153 +++++++++++++++++++++++++---- static/js/controllers/notificationsCtrl.js | 74 +++++++++++++- views/notifications.html | 30 +++++- 3 files changed, 233 insertions(+), 24 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 19e5776..69c6c65 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -735,7 +735,7 @@ class shelve_db: if group not in self.db['groups']: self.db['groups'][group] = {} self.db['groups'][group]['hosts'] = [] - self.db['groups'][group]['subscribers'] = [] + self.db['groups'][group]['subscribers'] = {} for host in host_list: if group not in self.db['hosts'][host]['conf']['groups']: self.db['groups'][group]['hosts'].append(host) @@ -765,6 +765,73 @@ class shelve_db: finally: self.close_db() + def subscribe_to_group(self, args): + """ + Add a list of users to the group notifications structure. + :param args: a dictionary containing : + { 'users': list<string>, 'group': val } + """ + users = args['users'] + group = args['group'] + self.open_db() + try: + for user in users: + self.db['groups'][group]['subscribers'][user] = {} + finally: + self.close_db() + + def update_subscription_to_group(self, args): + """ + Updates the subscription to a following user from a host. + :param args: + { 'group': val, + 'username': val, + 'subscription: [ + { notif_mod: priority }, + ... + ] + } + :return: + """ + group = args['group'] + username = args['username'] + self.open_db() + try: + self.db['groups'][group]['subscribers'][username] = args['subscription'] + finally: + self.close_db() + + def unsubscribe_to_group(self, args): + """ + Unsubscribes an user for a host notifications. + :param args: a dictionary containing : + { 'username': val, 'group': val } + """ + username = args['username'] + group = args['group'] + self.open_db() + try: + del self.db['groups'][group]['subscribers'][username] + finally: + self.close_db() + + def get_group_subscribers(self, args): + """ + + :param args: A dictionary containing : + { 'group': val } + :return: a list containing : + [{ 'username': val, 'priority': val }, ... ] + """ + group = args['group'] + res = [] + self.open_db() + try: + res = self.db['groups'][group]['subscribers'] + finally: + self.close_db() + return json.dumps(res) + def create_user(self, args): """ Create a basic empty structure on the database for a new user. @@ -799,7 +866,8 @@ class shelve_db: 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 + 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 args: a dictionary containing : { 'username': val } """ @@ -810,29 +878,78 @@ class shelve_db: del self.db['users'][username] # unregistering user from hosts for host in self.db['hosts']: - for subscriber in self.db['hosts'][host]['conf']['subscribers']: - if username in subscriber['username']: - self.db['hosts'][host]['conf']['subscribers'].remove(subscriber) + if username in self.db['hosts'][host]['subscribers']: + del self.db['hosts'][host]['conf']['subscribers'][username] # unregistering user form groups for group in self.db['groups']: - for subscriber in self.db['groups'][group]['subscribers']: - if username in subscriber['username']: - self.db['groups'][group]['subscribers'].remove(subscriber) + if username in self.db['groups'][group]['subscribers']: + del self.db['groups'][group]['subscribers'][username] finally: self.close_db() - def get_host_os(self, addr_host): + def subscribe_to_host(self, args): """ - Get the operating system corresponding to a host - :param addr_host: the IP adress of host to retreive os - :return: the os type corresponding to what have been detected + Add a list of users to the host notifications structure. + :param args: a dictionary containing : + { 'users': list<string>, 'addr_host': val } """ + users = args['users'] + addr_host = args['addr_host'] self.open_db() try: - detected = json.loads(self.db["hosts"][addr_host]["detected"]["nmap"]) - os = detected['os'].lower() - if os == "Unknown": - raise Exception('Os not detected') - return os + for user in users: + self.db['hosts'][addr_host]['conf']['subscribers'][user] = {} finally: - self.close_db() \ No newline at end of file + self.close_db() + + def update_subscription_to_host(self, args): + """ + Updates the subscription to a following user from a host. + :param args: + { 'addr_host': val, + 'username': val, + 'subscription: [ + { notif_mod: priority }, + ... + ] + } + :return: + """ + addr_host = args['addr_host'] + username = args['username'] + self.open_db() + try: + self.db['hosts'][addr_host]['conf']['subscribers'][username] = args['subscription'] + finally: + self.close_db() + + def unsubscribe_to_host(self, args): + """ + Unsubscribes an user for host notifications. + :param args: a dictionary containing : + { 'username': val, 'addr_host': val } + """ + username = args['username'] + addr_host = args['addr_host'] + self.open_db() + try: + del self.db['hosts'][addr_host]['conf']['subscribers'][username] + finally: + self.close_db() + + def get_host_subscribers(self, args): + """ + Get informations about the subscribers to a host. + :param args: A dictionary containing : + { 'addr_host': val } + :return: a dictionary containing : + { username: [{ 'notif_mod': val, 'priority': val }, ... ]} + """ + addr_host = args['addr_host'] + res = {} + self.open_db() + try: + res = self.db['hosts'][addr_host]['conf']['subscribers'] + finally: + self.close_db() + return json.dumps(res) \ No newline at end of file diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 95e2cf1..fc4af3e 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('notificationsCtrl', function($scope, $rootScope, DataHosts) { +mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, DataHosts) { $scope.items = DataHosts.Items; /* [ { "addr":"192.168.74.1", @@ -17,6 +17,8 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, DataHosts) { ] */ + $scope.subscriber_data = {}; + $scope.allGroups = function(){ var res = [] for(var i = 0; i<$scope.items.length; i++){ @@ -31,4 +33,74 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, DataHosts) { $scope.selected_host = ""; $scope.option_selected = ""; + + $scope.get_group_subscribers = function(){ + if($scope.selected_grp != ""){ + var args = {'group': $scope.selected_grp}; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_group_subscribers', 'args': args}})); + } + } + + $scope.get_host_subscribers = function(){ + if($scope.selected_host != ""){ + var args = {'addr_host': $scope.selected_host['addr']}; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_host_subscribers', 'args': args}})); + } + } + + $scope.$on("resCall", function (event, args) { + $scope.$apply(function(){ + $scope.subscriber_data = args; + }); + }); + + $scope.open_modal_add_subscriber = function (mod_name) { + var modalInstance = $modal.open({ + templateUrl: 'modal_add_subscriber_label.html', + controller: 'ModalAddSubscriberInstanceCtrl', + resolve: { + add_subscriber_args: function(){ + return {"grp" : $scope.selected_grp, + "host" : $scope.selected_host}; + } + } + }); + }; +}); + +mumApp.controller('ModalAddSubscriberInstanceCtrl', function ($scope, $rootScope, $modalInstance, $route, add_subscriber_args) { + $scope.add_subscriber_args = add_subscriber_args; /* {'grp': val, 'host': val */ + + $scope.users = {}; + + $scope.selected_users = []; + + $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.ok = function () { + var args = {}; + args['users'] = $scope.selected_users; + if($scope.add_subscriber_args['grp'] != ""){ + args['group'] = $scope.add_subscriber_args['grp']; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'subscribe_to_group', 'args': args}})); + } + else{ + args['addr_host'] = $scope.add_subscriber_args['host']['addr']; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'subscribe_to_host', 'args': args}})); + } + $modalInstance.close(); + + $route.reload(); + }; + + $scope.cancel = function () { + $modalInstance.close(); + }; }); \ No newline at end of file diff --git a/views/notifications.html b/views/notifications.html index 17bd3ac..f4afc3a 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -2,6 +2,7 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Who to notify?</h1> <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> + {{subscriber_data}} <form> <div class="row"> <div class="col-lg-6"> @@ -14,7 +15,8 @@ <select class="form-control input-sm" id="grp_choice" ng-model="selected_grp" ng-options="item for item in allGroups() | unique:'group'" - ng-disabled="option_selected!='grp'"></select> + ng-disabled="option_selected!='grp'" + ng-change="get_group_subscribers()"></select> </div> </div> <div class="col-lg-6"> @@ -27,7 +29,8 @@ <select class="form-control input-sm" id="host_choice" ng-model="selected_host" ng-options="host.addr group by host.group for host in items" - ng-disabled="option_selected!='host'"></select> + ng-disabled="option_selected!='host'" + ng-change="get_host_subscribers()"></select> </div> </div> </div> @@ -42,7 +45,7 @@ <table class="table table-bordered"> <thead> <tr> - <th>User <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_add">Add...</button></th> + <th>User <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_add_subscriber()">Add...</button></th> <th>Notification service </th> <th>Minor notifications</th> <th>Major notifications</th> @@ -171,7 +174,24 @@ <button type="button" class="btn btn-primary">Save changes</button> </div> - <div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="modal_add_label" aria-hidden="true"> + <script type="text/ng-template" id="modal_add_subscriber_label.html"> + <div class="modal-header"> + <h3 class="modal-title">Add users to this group/host</h3> + </div> + <div class="modal-body"> + {{add_subscriber_args}} + <select multiple class="form-control" + ng-model="selected_users" + ng-options="user as user for user in users"> + </select> + </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()" ng-disabled="selected_users.length==0">Add selected</button> + </div> + </script> + + <!--<div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-labelledby="modal_add_label" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> @@ -191,5 +211,5 @@ </div> </div> </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