branch develop updated (0a32ad4 -> 13ba585)
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 0a32ad4 hostpage: correction du nom de l'OS possible new 3eff4c3 restructuration des envois JSON new 3e312ae js : tous les appels websocket ont une réponse appropriée new 3dbc9ef profile: affichage et modif des parametres de l'utilisateur new 13ba585 notifications: corrigé bug d'affichage si plusieurs modules de notif chargés The 4 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 13ba585dc6f0c29b5b1bd5a63f52305570e87bfe Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 17:33:11 2015 +0100 notifications: corrigé bug d'affichage si plusieurs modules de notif chargés commit 3dbc9efd1a3a198d99af2e21aa47e98c46ec0c5e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 13:22:03 2015 +0100 profile: affichage et modif des parametres de l'utilisateur commit 3e312ae0f34cc32c79619dc75a08ccb53389ef63 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 11:19:38 2015 +0100 js : tous les appels websocket ont une réponse appropriée commit 3eff4c308f8a65005a94e2c3bdb8de23162a7068 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 10:51:14 2015 +0100 restructuration des envois JSON Summary of changes: app/app.py | 9 +- app/module_loader.py | 8 +- app/modules/notification_modules/sms_notif.py | 35 +++++ app/modules/storage_modules/shelve_db.py | 58 +++++++- static/js/controllers/groupCtrl.js | 17 ++- static/js/controllers/headCtrl.js | 36 ++--- static/js/controllers/hostPageCtrl.js | 93 ++++++++----- static/js/controllers/notificationsCtrl.js | 70 ++++++---- static/js/controllers/profileCtrl.js | 48 +++++++ static/js/controllers/usersCtrl.js | 8 +- static/js/mumApp.js | 4 +- views/hostpage.html | 187 +++++--------------------- views/index.html | 8 +- views/notifications.html | 27 ++-- views/profile.html | 27 ++-- 15 files changed, 360 insertions(+), 275 deletions(-) create mode 100644 app/modules/notification_modules/sms_notif.py create mode 100644 static/js/controllers/profileCtrl.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 3eff4c308f8a65005a94e2c3bdb8de23162a7068 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 10:51:14 2015 +0100 restructuration des envois JSON --- app/app.py | 9 +- app/module_loader.py | 8 +- app/modules/storage_modules/shelve_db.py | 14 +-- static/js/controllers/headCtrl.js | 36 +++--- static/js/controllers/hostPageCtrl.js | 54 +++++---- static/js/controllers/notificationsCtrl.js | 54 +++++---- static/js/controllers/profileCtrl.js | 26 ++++ static/js/controllers/usersCtrl.js | 8 +- static/js/mumApp.js | 4 +- views/hostpage.html | 187 ++++++----------------------- views/index.html | 8 +- views/profile.html | 7 +- 12 files changed, 173 insertions(+), 242 deletions(-) diff --git a/app/app.py b/app/app.py index c7b9743..829f32f 100755 --- a/app/app.py +++ b/app/app.py @@ -136,10 +136,11 @@ def receive(ws): ws.send(json.dumps({"RES_INFO_HOST": db.get_host_informations(msg["GET_HOST_INFO"])})) 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' + msg = json.dumps({"RES_CALL_FUNC_DB": { + "func": msg["CALL_FUNC_DB"]['func'], + "res": res + }}) + ws.send(msg) 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": # asked from hostpage, at the block activation conf diff --git a/app/module_loader.py b/app/module_loader.py index 97ce3be..4ad1949 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -239,7 +239,7 @@ class ModuleLoader: res[mod]['compatible_os'] = self.loaded_mod_moni[mod]['compatible_os'] res[mod]['unit'] = self.loaded_mod_moni[mod]['unit'] res[mod]['block'] = self.loaded_mod_moni[mod]['block'] - return json.dumps(res) + return res def load_all_connection_modules(self): """ @@ -293,7 +293,7 @@ class ModuleLoader: res = {} for mod in self.loaded_mod_conn: res[mod] = self.loaded_mod_conn[mod]['params'] - return json.dumps(res) + return res def load_all_notification_modules(self): """ @@ -329,7 +329,7 @@ class ModuleLoader: res = {} for mod in self.loaded_mod_notif: res[mod] = '' - return json.dumps(res) + return res def run_notification_modules(self, dict_notif): """ @@ -389,4 +389,4 @@ class ModuleLoader: self.db.config_mod_activation(args, self.get_monitoring_modules_list()) def get_public_keys_list(self): - return json.dumps(os.listdir(self.conf['keys_location'])) \ No newline at end of file + return os.listdir(self.conf['keys_location']) \ 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 749c831..e7f62fa 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -232,7 +232,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def get_monitoring_instructions(self, addr_host): """ @@ -340,7 +340,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def get_host_informations(self, addr_host): """ @@ -396,7 +396,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def remove_host(self, args): """ @@ -578,7 +578,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def set_conf_mod(self, args): """ @@ -949,7 +949,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def create_user(self, args): """ @@ -986,7 +986,7 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) + return res def remove_user(self, args): """ @@ -1100,4 +1100,4 @@ class shelve_db: print e.__str__() finally: self.close_db() - return json.dumps(res) \ No newline at end of file + return res \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 6560902..1d87198 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -24,47 +24,48 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r }); ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket - JSON.parse(evt.data, function (key, value) { + var obj = JSON.parse(evt.data); + for(key in obj){ switch(key){ case "SUCCESS_MODULE": // Success of a module execution - $rootScope.$broadcast("success", value); - toastr.success(value, "Success on module execution"); + $rootScope.$broadcast("success", obj[key]); + toastr.success(obj[key], "Success on module execution"); break; case "RES_INFO_HOST": // Informations concerning one host - $rootScope.$broadcast("hostInfos", JSON.parse(value)); + $rootScope.$broadcast("hostInfos", obj[key]); break; case "RES_GET_HOSTS": // List of hosts under monitoring - DataHosts.Items = JSON.parse(value); + DataHosts.Items = obj[key]; $rootScope.$broadcast("hostsUpdate"); $scope.$apply(function(){ $scope.items = DataHosts.Items; }); break; case "RES_GET_LOADED_CONN_MOD": - $rootScope.$broadcast("resGetLoadedConnMod", JSON.parse(value)); + $rootScope.$broadcast("resGetLoadedConnMod", obj[key]); break; case "RES_GET_LOADED_MONI_MOD": - $rootScope.$broadcast("resGetLoadedMoniMod", JSON.parse(value)); + $rootScope.$broadcast("resGetLoadedMoniMod", obj[key]); break; case "RES_GET_LOADED_NOTIF_MOD": - $rootScope.$broadcast("resGetLoadedNotifMod", JSON.parse(value)); + $rootScope.$broadcast("resGetLoadedNotifMod", obj[key]); break; case "RES_CALL_FUNC_DB": // Get a result after calling a funcion on the db - $rootScope.$broadcast("resCall", JSON.parse(value)); + $rootScope.$broadcast("resCall", obj[key]); break; case "CURRENT_STATE_INFO": $scope.$apply(function(){ - $scope.state = value; + $scope.state = obj[key]; }); - $rootScope.$broadcast("stateUpdate", value); - toastr.info(value, "Current status is :"); + $rootScope.$broadcast("stateUpdate", obj[key]); + toastr.info(obj[key], "Current status is :"); /* $scope.$apply(function(){ - $scope.state = value + $scope.state = obj[key] });*/ break; case "BROWSER_NOTIFICATION": - params = value.split(','); + params = obj[key].split(','); if(params[0]=='success'){ $scope.pop_success("Success on " + params[1], params[2]); } @@ -76,16 +77,15 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r } break; case "KEYS_LIST": - $rootScope.$broadcast("keysList", JSON.parse(value)); + $rootScope.$broadcast("keysList", obj[key]); break case "ERROR": - toastr.error(value, "Server error"); + toastr.error(obj[key], "Server error"); break; default: break; } - }); - + } }; $scope.pop_success = function(title, msg){ diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 0835013..a1d9669 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -177,26 +177,28 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI // when the actual conf of the module is received $scope.$on("resCall", function (event, args) { - $scope.$apply(function(){ - $scope.items = args; - $scope.freq_days = Math.floor(args.freq / 86400); - $scope.freq_hours = Math.floor((args.freq - $scope.freq_days * 86400) / 3600); - $scope.freq_minutes = Math.floor((args.freq - ($scope.freq_days * 86400) - ($scope.freq_hours * 3600)) / 60) - - if(args.unit == 'bool'){ - if(args.major_limit){ - $scope.limit_bool = 'major'; + if(args.func == 'get_conf_mod'){ + $scope.$apply(function(){ + $scope.items = args.res; + $scope.freq_days = Math.floor(args.res.freq / 86400); + $scope.freq_hours = Math.floor((args.res.freq - $scope.freq_days * 86400) / 3600); + $scope.freq_minutes = Math.floor((args.res.freq - ($scope.freq_days * 86400) - ($scope.freq_hours * 3600)) / 60) + + if(args.res.unit == 'bool'){ + if(args.res.major_limit){ + $scope.limit_bool = 'major'; + } } - } - else if(args.unit == '%'){ - $scope.minor_limit_percent = args.minor_limit; - $scope.major_limit_percent = args.major_limit; - } - else{ - $scope.minor_limit_unit = args.minor_limit; - $scope.major_limit_unit = args.major_limit; - } - }); + else if(args.res.unit == '%'){ + $scope.minor_limit_percent = args.res.minor_limit; + $scope.major_limit_percent = args.res.major_limit; + } + else{ + $scope.minor_limit_unit = args.res.minor_limit; + $scope.major_limit_unit = args.res.major_limit; + } + }); + } }); // after validation @@ -276,12 +278,14 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI // when the configuration of the connection is received $scope.$on("resCall", function (event, args) { - $scope.$apply(function(){ - $scope.current_config = args; - for(mod in args){ - $scope.priorities[mod] = args[mod]['priority'] - } - }); + if(args.func == 'get_conn_param'){ + $scope.$apply(function(){ + $scope.current_config = args.res; + for(mod in args.res){ + $scope.priorities[mod] = args.res[mod]['priority'] + } + }); + } }); $scope.ok = function () { diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 3557407..7b0d559 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -77,30 +77,32 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data { notif_mod: priority }, ... }}} */ - $scope.$apply(function(){ - var sd = {}; - for(user in args){ - sd[user] = {}; - sd[user]['minor'] = {}; - sd[user]['major'] = {}; - for(notif_mod in args[user]['minor']){ - sd[user]['minor'][notif_mod] = - {'activated': args[user]['minor'][notif_mod]['activated'], - 'priority':args[user]['minor'][notif_mod]['priority']}; - sd[user]['major'][notif_mod] = - {'activated': args[user]['major'][notif_mod]['activated'], - 'priority':args[user]['major'][notif_mod]['priority']}; - } - for(notif_mod in $scope.notif_mods){ - if(!sd[user]['minor'].hasOwnProperty(notif_mod)){ - sd[user]['minor'][notif_mod] = {'activated': false, 'priority': null}; - sd[user]['major'][notif_mod] = {'activated': false, 'priority': null}; + if(args.func == 'get_host_subscribers'){ + $scope.$apply(function(){ + var sd = {}; + for(user in args.res){ + sd[user] = {}; + sd[user]['minor'] = {}; + sd[user]['major'] = {}; + for(notif_mod in args.res[user]['minor']){ + sd[user]['minor'][notif_mod] = + {'activated': args.res[user]['minor'][notif_mod]['activated'], + 'priority':args.res[user]['minor'][notif_mod]['priority']}; + sd[user]['major'][notif_mod] = + {'activated': args.res[user]['major'][notif_mod]['activated'], + 'priority':args.res[user]['major'][notif_mod]['priority']}; + } + for(notif_mod in $scope.notif_mods){ + if(!sd[user]['minor'].hasOwnProperty(notif_mod)){ + sd[user]['minor'][notif_mod] = {'activated': false, 'priority': null}; + sd[user]['major'][notif_mod] = {'activated': false, 'priority': null}; + } } } - } - $scope.subscriber_data = sd; - $scope.subscriber_data_unchanged = sd; - }); + $scope.subscriber_data = sd; + $scope.subscriber_data_unchanged = sd; + }); + } }); $scope.discard = function(){ @@ -166,9 +168,11 @@ mumApp.controller('ModalAddSubscriberInstanceCtrl', function ($scope, $rootScope // receiving the user list $scope.$on("resCall", function (event, args) { - $scope.$apply(function(){ - $scope.users = args; - }); + if(args.func == 'get_users'){ + $scope.$apply(function(){ + $scope.users = args.res; + }); + } }); $scope.ok = function () { diff --git a/static/js/controllers/profileCtrl.js b/static/js/controllers/profileCtrl.js new file mode 100644 index 0000000..dd3e3ab --- /dev/null +++ b/static/js/controllers/profileCtrl.js @@ -0,0 +1,26 @@ +mumApp.controller('profileCtrl', function($scope, $rootScope){ + + $scope.users = {}; + + $scope.selected_user = ""; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); + + // receiving the user list + $scope.$on("resCall", function (event, args) { + if(args.func == 'get_users'){ + $scope.$apply(function(){ + $scope.users = args.res; + }); + } + }); + + $scope.get_user_settings = function(){ + args = {}; + if($scope.selected_user != ''){ + args['username'] = $scope.selected_user; + } + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); + } +}); \ No newline at end of file diff --git a/static/js/controllers/usersCtrl.js b/static/js/controllers/usersCtrl.js index dca6322..87237d3 100644 --- a/static/js/controllers/usersCtrl.js +++ b/static/js/controllers/usersCtrl.js @@ -11,9 +11,11 @@ mumApp.controller('usersCtrl', function($scope, $rootScope, $route) { // receiving the user list $scope.$on("resCall", function (event, args) { - $scope.$apply(function(){ - $scope.users = args; - }); + if(args.func == 'get_users'){ + $scope.$apply(function(){ + $scope.users = args.res; + }); + } }); $scope.addUser = function(){ diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 3f76c6d..75d3325 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -31,8 +31,8 @@ mumApp.config(function($routeProvider){ controller : 'notificationsCtrl' }) .when('/profile',{ - templateUrl : 'profile.html' - //controller : 'mainController' + templateUrl : 'profile.html', + controller : 'profileCtrl' }) .when('/scan',{ templateUrl : 'scan.html', diff --git a/views/hostpage.html b/views/hostpage.html index 689a4b6..c579267 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -22,8 +22,10 @@ <td>{{item.value}}</td> <td>{{item.state}}</td> <td>{{item.date.split('.')[0]}}</td> - <td><button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_conf(itemname)">Configure</button></td> - <td><button type="button" class="btn btn-info btn-xs" ng-click="check(itemname)">Check now</button></td> + <td><button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_conf(itemname)">Configure</button></td> + <td><button type="button" class="btn btn-info btn-xs" + ng-click="check(itemname)">Check now</button></td> </tr> </tbody> </table> @@ -54,7 +56,8 @@ </accordion-group> <accordion-group heading="Interventions done"> - <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_interv()">Add a new intervention</button> + <button type="button" class="btn btn-primary btn-xs" + ng-click="open_modal_interv()">Add a new intervention</button> <div ng-show="items.interventions != ''"> <table class="table table-bordered table-hover"> <thead> @@ -88,20 +91,25 @@ <label for="freq">Frequency check: each</label> <div class="row" id="freq"> <div class="col-xs-2"> - <input type="number" min="0" class="form-control" ng-model="freq_days"> days + <input type="number" min="0" class="form-control" + ng-model="freq_days"> days </div> <div class="col-xs-2"> - <input type="number" min="0" max="23" class="form-control" ng-model="freq_hours"> hours + <input type="number" min="0" max="23" class="form-control" + ng-model="freq_hours"> hours </div> <div class="col-xs-2"> - <input type="number" min="0" max="59" class="form-control" ng-model="freq_minutes"> minutes + <input type="number" min="0" max="59" class="form-control" + ng-model="freq_minutes"> minutes </div> </div> <div ng-show="items.unit == '%'"> <label for="minor_%">Minor notification at {{minor_limit_percent}}% of charge</label> - <input type="range" min="0" max="99" id="minor_%" ng-model="minor_limit_percent"> + <input type="range" min="0" max="99" id="minor_%" + ng-model="minor_limit_percent"> <label for="major_%">Major notification at {{major_limit_percent}}% of charge</label> - <input type="range" min="{{minor_limit_percent}}" max="100" id="major_%" ng-model="major_limit_percent"> + <input type="range" min="{{minor_limit_percent}}" max="100" id="major_%" + ng-model="major_limit_percent"> </div> <div ng-show="items.unit == 'bool'"> <label for="minor_bool">If down, send a </label> @@ -120,15 +128,18 @@ </div> <div ng-show="items.unit != '%' && items.unit != 'bool'"> <label for="minor_unit">Minor notif at {{minor_limit_unit}}</label> - <input type="number" class="form-control" id="minor_unit" min="0" ng-model="minor_limit_unit"> + <input type="number" class="form-control" id="minor_unit" min="0" + ng-model="minor_limit_unit"> <label for="maj_pack">Major notif at {{major_limit_unit}}</label> - <input type="number" class="form-control" id="maj_pack" min="0" ng-model="major_limit_unit"> + <input type="number" class="form-control" id="maj_pack" min="0" + ng-model="major_limit_unit"> </div> </div> </form> </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-default" data-dismiss="modal" + ng-click="cancel()">Close</button> <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button> </div> </script> @@ -177,9 +188,11 @@ <tbody> <tr ng-repeat="(modname, modconf) in current_config"> <td>{{modname}}</td> - <td><input type="number" min="0" ng-model="priorities[modname]" ng-disabled="isNotConfigured(modname)"></td> + <td><input type="number" min="0" ng-model="priorities[modname]" + ng-disabled="isNotConfigured(modname)"></td> <td> - <button type="button" class="btn btn-primary" ng-click="open_modal_conf_conn(modname)">Advanced configuration</button> + <button type="button" class="btn btn-primary" + ng-click="open_modal_conf_conn(modname)">Advanced configuration</button> <button type="button" class="btn btn-success">Test</button> </td> @@ -213,7 +226,9 @@ <div class="row"> <div class="col-xs-3"> <label for="private_key">Select a private key</label> - <select class="form-control input-sm" id="private_key" ng-model="private_key" ng-options="key as key for key in keys_list"></select> + <select class="form-control input-sm" id="private_key" + ng-model="private_key" + ng-options="key as key for key in keys_list"></select> </div> </div> <div class="row"> @@ -268,145 +283,17 @@ <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><input type="checkbox" + ng-model="mod.activated" + ng-disabled="is_not_compatible(mod.modname)"></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> + <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> - </div> - <!-- - <div class="modal fade bs-example-modal-lg" id="modal_conf_conn" tabindex="-1" role="dialog" aria-labelledby="modal_conf_conn_label" aria-hidden="true"> - <div class="modal-dialog modal-lg"> - <div class="modal-content"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="modal_conf_conn_label">Advanced settings for SSH</h4> - </div> - <div class="modal-body"> - <div class="row"> - <div class="col-xs-2"> - <label for="port">Port used</label> - <input type="number" id="port" min="0" placeholder="22"> - </div> - </div> - <div class="row"> - <div class="col-xs-3"> - <label for="usrname">Login</label> - <input type="text" id="usrname" placeholder="mylogin"> - </div> - </div> - <div class="row"> - <div class="col-xs-3"> - <label for="publickey">Public key</label> - <select class="form-control" id="publickey"> - <option>mykey1</option> - <option>mykey2</option> - </select> - </div> - <button type="button" class="btn btn-primary btn-xs">Add public key</button> - <button type="button" class="btn btn-danger btn-xs">Remove selected</button> - </div> - <div class="row"> - <div class="col-xs-3"> - <label for="privatekey">Private key</label> - <select class="form-control" id="privatekey"> - <option>mypkey1</option> - <option>mypkey2</option> - </select> - </div> - <button type="button" class="btn btn-primary btn-xs">Add private key</button> - <button type="button" class="btn btn-danger btn-xs">Remove selected</button> - </div> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> - <button type="button" class="btn btn-primary">Save changes</button> - </div> - </div> - </div> - </div> - - <div class="modal fade" id="modal_block" tabindex="-1" role="dialog" aria-labelledby="modal_block_label" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="modal_block_label">Activate/Deactivate monitoring blocks</h4> - </div> - <div class="modal-body"> - <form> - <div class="form-group"> - <h3>Network</h3> - <button type="button" class="btn btn-defaule">Select all</button> - <button type="button" class="btn btn-defaule">Select none</button> - <table class="table table-bordered table-hover"> - <thead> - <tr> - <th>Part </th> - <th>Activated </th> - </tr> - </thead> - <tbody> - <tr> - <td>HTTP</td> - <td><input type="checkbox" value="http" checked></td> - </tr> - <tr> - <td>SMTP</td> - <td><input type="checkbox" value="smtp" checked></td> - </tr> - </tbody> - </table> - <h3>Hardware</h3> - <button type="button" class="btn btn-defaule">Select all</button> - <button type="button" class="btn btn-defaule">Select none</button> - <table class="table table-bordered table-hover"> - <thead> - <tr> - <th>Part </th> - <th>Activated </th> - </tr> - </thead> - <tbody> - <tr> - <td>CPU</td> - <td><input type="checkbox" value="http" checked></td> - </tr> - <tr> - <td>Drive</td> - <td><input type="checkbox" value="smtp" checked></td> - </tr> - </tbody> - </table> - <h3>Software</h3> - <button type="button" class="btn btn-defaule">Select all</button> - <button type="button" class="btn btn-defaule">Select none</button> - <table class="table table-bordered table-hover"> - <thead> - <tr> - <th>Part </th> - <th>Activated </th> - </tr> - </thead> - <tbody> - <tr> - <td>Packages updated</td> - <td><input type="checkbox" value="http"></td> - </tr> - </tbody> - </table> - </div> - </form> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> - <button type="button" class="btn btn-primary">Save changes</button> - </div> - </div> - </div> - </div> - --> + </div> \ No newline at end of file diff --git a/views/index.html b/views/index.html index bb44098..13335ff 100644 --- a/views/index.html +++ b/views/index.html @@ -28,12 +28,14 @@ <script src="static/js/mumApp.js"></script> <script src="static/js/controllers/dashboardCtrl.js"></script> + <script src="static/js/controllers/groupCtrl.js"></script> + <script src="static/js/controllers/hostPageCtrl.js"></script> <script src="static/js/controllers/headCtrl.js"></script> + <script src="static/js/controllers/notificationsCtrl.js"></script> + <script src="static/js/controllers/profileCtrl.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/profile.html b/views/profile.html index df1c645..61553d3 100644 --- a/views/profile.html +++ b/views/profile.html @@ -1,13 +1,18 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Your account</h1> + <select class="form-control input-sm" id="usrlist" + ng-model="selected_user" + ng-options="user as user for user in users" + ng-change="get_user_settings()"> + </select> <!--<h2 class="sub-header">They will be applied on each new host you will add.</h2>--> <form> <div class="row"> <h3>Personal informations</h3> <div class="col-xs-3"> <label for="username">Username</label> - <input type="username" class="form-control" id="username" placeholder="Username"> + <input type="text" class="form-control" id="username" placeholder="Username"> </div> <div class="row"></div> <div class="col-xs-3"> -- 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 3e312ae0f34cc32c79619dc75a08ccb53389ef63 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 11:19:38 2015 +0100 js : tous les appels websocket ont une réponse appropriée --- static/js/controllers/groupCtrl.js | 17 ++++++++++--- static/js/controllers/hostPageCtrl.js | 39 +++++++++++++++++++++++------- static/js/controllers/notificationsCtrl.js | 18 ++++++++++---- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js index 5c40294..f4596a6 100644 --- a/static/js/controllers/groupCtrl.js +++ b/static/js/controllers/groupCtrl.js @@ -75,6 +75,12 @@ mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $ro } }; + $scope.$on("resCall", function (event, args) { + if(args.func == 'remove_host_list_to_group'){ + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_HOSTS": ""})); + } + }); + $scope.remove_host_list = function(){ var args = {}; args['host_list'] = []; @@ -86,7 +92,6 @@ mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $ro args['group'] = $scope.grp; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host_list_to_group','args': args}})); - $route.reload(); } @@ -119,6 +124,13 @@ mumApp.controller('ModalGroupInstanceCtrl', function ($scope, $rootScope, $route $scope.new_grp_name = ""; $scope.selected_grp = "all"; + $scope.$on("resCall", function (event, args) { + if(args.func == 'add_host_list_to_group'){ + $modalInstance.close(); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_HOSTS": ""})); + } + }); + $scope.ok = function () { var args = {}; args['host_list'] = $scope.group_args['selected']; @@ -130,9 +142,6 @@ mumApp.controller('ModalGroupInstanceCtrl', function ($scope, $rootScope, $route } $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'add_host_list_to_group','args': args}})); - - $modalInstance.close(); - $route.reload(); }; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index a1d9669..f3289aa 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, $modal) { +mumApp.controller('hostPageCtrl', function($scope, $rootScope, $route, $routeParams, $modal) { $scope.loaded = false; // indicates if this is the first loading of the page @@ -41,6 +41,18 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, $mo $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_os_name', 'args': args}})); } + $scope.$on("resCall", function (event, args) { + if(args.func == 'update_os_name'){ + $route.reload(); + } + if(args.func == 'update_custom_informations'){ + $route.reload(); + } + if(args.func == 'remove_host'){ + $route.reload(); + } + }); + $scope.model = {custom_infos : '', new_os : ''}; $scope.check = function(modname){ @@ -238,6 +250,13 @@ mumApp.controller('ModalIntervInstanceCtrl', function ($scope, $rootScope, $moda $scope.date = $filter('date')(new Date(), 'yyyy-MM-dd HH:mm'); $scope.details = ''; + $scope.$on("resCall", function (event, args) { + if(args.func == 'add_intervention'){ + $modalInstance.close(); + $route.reload(); + } + }); + $scope.ok = function () { var args = {}; args.addr_host = $scope.interv_args.addr_host; @@ -246,10 +265,6 @@ mumApp.controller('ModalIntervInstanceCtrl', function ($scope, $rootScope, $moda args.details = $scope.details; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'add_intervention', 'args': args}})); - - $modalInstance.close(); - - $route.reload(); }; $scope.cancel = function () { @@ -286,6 +301,10 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI } }); } + if(args.func == 'set_prio_conn'){ + $modalInstance.close(); + $route.reload(); + } }); $scope.ok = function () { @@ -294,10 +313,6 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI args['priorities'] = $scope.priorities; $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_prio_conn','args': args}})); - - $modalInstance.close(); - - $route.reload(); }; $scope.cancel = function () { @@ -380,6 +395,12 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo }); + $scope.$on("resCall", function (event, args) { + if(args.func == 'set_conf_conn'){ + $modalInstance.close(); + $route.reload(); + } + }); $scope.ok = function () { var args = conf_conn_args; diff --git a/static/js/controllers/notificationsCtrl.js b/static/js/controllers/notificationsCtrl.js index 7b0d559..71764f2 100644 --- a/static/js/controllers/notificationsCtrl.js +++ b/static/js/controllers/notificationsCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, DataHosts) { +mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, $route, DataHosts) { $scope.items = DataHosts.Items; /* [ { "addr":"192.168.74.1", @@ -77,7 +77,7 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data { notif_mod: priority }, ... }}} */ - if(args.func == 'get_host_subscribers'){ + if(args.func == 'get_host_subscribers' || args.func == 'get_group_subscribers'){ $scope.$apply(function(){ var sd = {}; for(user in args.res){ @@ -103,6 +103,12 @@ mumApp.controller('notificationsCtrl', function($scope, $rootScope, $modal, Data $scope.subscriber_data_unchanged = sd; }); } + if(args.func == 'update_subscription_to_group' || args.func == 'update_subscription_to_host'){ + $route.reload(); + } + if(args.func == 'unsubscribe_to_group' || args.func == 'unsubscribe_to_host'){ + $route.reload(); + } }); $scope.discard = function(){ @@ -173,6 +179,11 @@ mumApp.controller('ModalAddSubscriberInstanceCtrl', function ($scope, $rootScope $scope.users = args.res; }); } + + if(args.func == 'subscribe_to_group' || args.func == 'subscribe_to_host'){ + $modalInstance.close(); + $route.reload(); + } }); $scope.ok = function () { @@ -186,9 +197,6 @@ mumApp.controller('ModalAddSubscriberInstanceCtrl', function ($scope, $rootScope 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 () { -- 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 3dbc9efd1a3a198d99af2e21aa47e98c46ec0c5e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 13:22:03 2015 +0100 profile: affichage et modif des parametres de l'utilisateur --- app/modules/storage_modules/shelve_db.py | 44 ++++++++++++++++++++++++++++++++ static/js/controllers/profileCtrl.js | 28 +++++++++++++++++--- views/profile.html | 22 +++++++++------- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index e7f62fa..d24133a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -988,6 +988,50 @@ class shelve_db: self.close_db() return res + def get_user_settings(self, args): + """ + Called by the profile page. + :param args: a dictionary containing: + { 'username': string } + :return: a dictionary containing: + { + 'settings':{ + 'email': string, + ... + }} + """ + res = {} + res['settings'] = {} + self.open_db() + try: + res['settings'] = self.db['users'][args['username']]['settings'] + except Exception as e: + print e.__str__() + finally: + self.close_db() + return res + + def update_user_settings(self, args): + """ + Called from the profile page. Replaces the current settings of a given user. + :param args: a dictionary containing: + { + 'username': string, + 'settings':{ + 'email': string, + ... + } + } + :return: + """ + self.open_db() + try: + self.db['users'][args['username']]['settings'] = args['settings'] + except Exception as e: + print e.__str__() + finally: + self.close_db() + def remove_user(self, args): """ Removes a user from the database. If the user is registered to a host or a group, diff --git a/static/js/controllers/profileCtrl.js b/static/js/controllers/profileCtrl.js index dd3e3ab..fa3bbb9 100644 --- a/static/js/controllers/profileCtrl.js +++ b/static/js/controllers/profileCtrl.js @@ -1,9 +1,12 @@ -mumApp.controller('profileCtrl', function($scope, $rootScope){ +mumApp.controller('profileCtrl', function($scope, $rootScope, $route){ $scope.users = {}; $scope.selected_user = ""; + $scope.email = ""; + $scope.sms_url = ""; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); // receiving the user list @@ -13,14 +16,33 @@ mumApp.controller('profileCtrl', function($scope, $rootScope){ $scope.users = args.res; }); } + if(args.func == 'get_user_settings'){ + $scope.$apply(function(){ + $scope.email = args.res.settings.email; + $scope.sms_url = args.res.settings.sms_url; + }); + } + if(args.func == 'update_user_settings'){ + $route.reload(); + } }); $scope.get_user_settings = function(){ - args = {}; + var args = {}; if($scope.selected_user != ''){ args['username'] = $scope.selected_user; } - $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_users', 'args': null}})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'get_user_settings', 'args': args}})); + } + + $scope.save_settings = function(){ + var args = {}; + args['username'] = $scope.selected_user; + args['settings'] = {}; + args['settings']['email'] = $scope.email; + args['settings']['sms_url'] = $scope.sms_url; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'update_user_settings', 'args': args}})); } }); \ No newline at end of file diff --git a/views/profile.html b/views/profile.html index 61553d3..074c630 100644 --- a/views/profile.html +++ b/views/profile.html @@ -12,29 +12,33 @@ <h3>Personal informations</h3> <div class="col-xs-3"> <label for="username">Username</label> - <input type="text" class="form-control" id="username" placeholder="Username"> + <input type="text" class="form-control" id="username" + disabled + ng-model="selected_user"> </div> <div class="row"></div> <div class="col-xs-3"> <label for="pswd">Change password</label> - <input type="password" class="form-control" id="pswd" placeholder="New password"> + <input type="password" class="form-control" id="pswd" disabled> </div> <div class="col-xs-3"> <label for="pswd2">Repeat new password</label> - <input type="password" class="form-control" id="pswd2" placeholder="Repeat new password"> + <input type="password" class="form-control" id="pswd2" disabled> </div> <div class="row"></div> <div class="col-xs-4"> <label for="mail">Email address</label> - <input type="email" class="form-control" id="mail" placeholder="Enter email"> + <input type="email" class="form-control" id="mail" ng-model="email"> </div> <div class="row"></div> <div class="col-xs-4"> <label for="cellphone">SMS URL</label> - <input type="email" class="form-control" id="cellphone"> + <input type="text" class="form-control" id="cellphone" ng-model="sms_url"> </div> </div> - <h3>Preferences</h3> + + <button type="button" class="btn btn-primary" ng-click="save_settings()">Save changes</button> + <!--<h3>Preferences</h3> <div class="checkbox"> <label for="minornotif">Send minor notifications by :</label> @@ -68,10 +72,10 @@ </label> </div> - <button type="button" class="btn btn-primary">Save changes</button> +--> </form> - <h3>Summary of notification subscriptions</h3> + <!--<h3>Summary of notification subscriptions</h3> <p>Number of notifications between your last login</p> <table class="table table-hover"> <thead> @@ -117,5 +121,5 @@ <td class="success">5</td> </tr> </tbody> - </table> + </table>--> </div> \ 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 13ba585dc6f0c29b5b1bd5a63f52305570e87bfe Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Mar 25 17:33:11 2015 +0100 notifications: corrigé bug d'affichage si plusieurs modules de notif chargés --- app/modules/notification_modules/sms_notif.py | 35 +++++++++++++++++++++++++++ views/notifications.html | 27 +++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/modules/notification_modules/sms_notif.py b/app/modules/notification_modules/sms_notif.py new file mode 100644 index 0000000..b20438f --- /dev/null +++ b/app/modules/notification_modules/sms_notif.py @@ -0,0 +1,35 @@ +__author__ = 'aguilbaud' + +import urllib2 + +def get_class_name(): + return "SMS" + + +class SMS: + def __init__(self, user_data, title, msg, settings): + self.name = get_class_name() + self.user_data = user_data # {'email': val, ...} + self.title = title + self.msg = msg + self.settings = settings # = conf attribute on ModuleLoader class + + def get_name(self): + return self.name + + def notify(self): + url = self.user_data['sms_url'] + self.msg + + req = urllib2.Request(url) + try: + urllib2.urlopen(req) + except IOError, e: + if hasattr(e,'code'): + if e.code == 400: + print 'One of the url parameters is missing.' + if e.code == 402: + print 'Too many SMS have been sent in short time.' + if e.code == 403: + print 'The service is not activated or wrong login/key.' + if e.code == 500: + print 'Server error. Please try again later.' \ No newline at end of file diff --git a/views/notifications.html b/views/notifications.html index f150519..181a7eb 100644 --- a/views/notifications.html +++ b/views/notifications.html @@ -40,18 +40,29 @@ <table class="table table-bordered"> <thead> <tr> - <th>User <button type="button" class="btn btn-primary btn-xs" ng-click="open_modal_add_subscriber()">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> </tr> </thead> <tbody> - <tr ng-repeat="(username, user) in subscriber_data"> + <tr ng-repeat-start="(username, user) in subscriber_data"> <td>{{username}}<br/> - <button type="button" class="btn btn-danger btn-xs" ng-click="unsubscribe(username)">Unsubscribe</button></td> - <td ng-repeat="(mod_name, mod_param) in user.minor">{{mod_name}}</td> - <td ng-repeat="(mod_name, mod_param) in user.minor"> + <button type="button" class="btn btn-danger btn-xs" + ng-click="unsubscribe(username)">Unsubscribe + </button> + </td> + </tr> + <tr ng-repeat-end + ng-repeat="(mod_name, mod_param) in user.minor"> + <td></td> + <td>{{mod_name}}</td> + <td> <div class="input-group"> <span class="input-group-addon"> <input type="checkbox" ng-model="mod_param.activated"> @@ -59,12 +70,12 @@ <input type="number" min="1" class="form-control" ng-model="mod_param.priority"> </div> </td> - <td ng-repeat="(mod_name, mod_param) in user.major"> + <td> <div class="input-group"> <span class="input-group-addon"> - <input type="checkbox" ng-model="mod_param.activated"> + <input type="checkbox" ng-model="subscriber_data[username].major[mod_name].activated"> </span> - <input type="number" min="1" class="form-control" ng-model="mod_param.priority"> + <input type="number" min="1" class="form-control" ng-model="subscriber_data[username].major[mod_name].priority"> </div> </td> </tr> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm