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 aa79f0791666ab7525283e8bec54c3e0ececc3e7 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 12 10:11:14 2015 +0100 sauvegarde conf de connection (sans formulaire dynamique) --- app/app.py | 7 ++++ app/module_loader.py | 12 +++++-- app/modules/storage_modules/shelve_db.py | 58 ++++++++++++++++++++++++++++++-- bower.json | 3 +- conf.txt | 3 +- static/js/controllers/headCtrl.js | 2 ++ static/js/controllers/hostPageCtrl.js | 46 +++++++++++++++++++++---- static/js/mumApp.js | 2 +- views/hostpage.html | 36 +++++++++++++++++--- views/index.html | 1 + 10 files changed, 152 insertions(+), 18 deletions(-) diff --git a/app/app.py b/app/app.py index 30de1e7..3057687 100755 --- a/app/app.py +++ b/app/app.py @@ -149,11 +149,18 @@ def receive(ws): elif code == "CHECK_NOW": args = msg["CHECK_NOW"] ml.run_one_monitoring_module(args['mod_name'], args['addr_host'], None, None) + elif code == "GET_KEYS_LIST": + ws.send(json_dumps({"KEYS_LIST": ml.get_public_keys_list()})) else: break except WebSocketError: # Should be WebSocketError when closing the connection wsc.remove_websocket(ws) break +""" +@route('/upload', method='POST') +def do_upload(): + upload.save(path) +""" # Lancement du serveur a l'adresse 0.0.0.0:1337 diff --git a/app/module_loader.py b/app/module_loader.py index 4a274e3..49eb291 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -13,6 +13,7 @@ import json import re import pkgutil import sys +import os class ModuleLoader: @@ -29,6 +30,7 @@ class ModuleLoader: fconf.close() self.db_loc = dict_conf['db_location'] self.external_mod_loc = dict_conf['external_modules_location'] + self.public_keys_loc = dict_conf['public_keys_location'] self.db = self.load_db(add_func, rem_func) self.loaded_mod_moni = {} # See load_all_monitoring_modules self.loaded_mod_conn = {} # See load_all_connection_modules @@ -69,6 +71,9 @@ class ModuleLoader: ws.send(json.dumps({"ERROR": hnfe.__str__()})) return None + def create_connection(self, addr_host): + avaliable_conn = self.db.get_conf_conn(addr_host) + def run_all_detection_modules(self, os, conn, db, ws): """ Instanciates and runs every detection_modules listed in the __init__.py file of the package corresponding to @@ -281,9 +286,12 @@ class ModuleLoader: "func" : func_name, "args" : [arg1, ...] } - :return: the result of the called function. Or None if the function does not returns a value. + :return: the result of the called function. Or None if the called function does not returns a value. """ return getattr(self.db, dict_instr['func'])(dict_instr['args']) def update_activated_modules(self, args): - self.db.config_mod_activation(args, self.get_monitoring_modules_list()) \ No newline at end of file + self.db.config_mod_activation(args, self.get_monitoring_modules_list()) + + def get_public_keys_list(self): + return json.dumps(os.listdir(self.public_keys_loc)) \ 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 052e712..1757bc1 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -100,7 +100,7 @@ class shelve_db: if port["portname"] in conn_infos: dict_conn[port["portname"]] = { "priority": 0, - "portid": int(port["portid"]) + "port": int(port["portid"]) } for param in conn_infos[port["portname"]]['params']: dict_conn[port["portname"]][param] = None @@ -390,7 +390,6 @@ class shelve_db: self.close_db() return json.dumps(res) - def remove_host(self, addr_host): """ Removes from the database the host at the adress on parameter. If the host is part of a group, it will be @@ -562,6 +561,61 @@ class shelve_db: finally: self.close_db() + def set_prio_conn(self, args): + """ + Save the priorities of connections modules for a host. + :param args: A dictionary containing: + {'addr_host' : val, + 'priorities':{ + mod_name: val + } + } + """ + addr_host = args['addr_host'] + self.open_db() + try: + for mod in args['priorities']: + self.db['hosts'][addr_host]['conf']['connections'][mod]['priority'] = args['priorities'][mod] + finally: + self.close_db() + + def set_conf_conn(self, args): + """ + Save the connection configuration of a host. + :param args: A dictionary containting: + {'addr_host': val, + 'modname': val, + 'current_config': val} + """ + addr_host = args['addr_host'] + modname = args['modname'] + self.open_db() + try: + for param in args['current_config'][modname]: + self.db['hosts'][addr_host]['conf']['connections'][modname][param] = \ + args['current_config']['ssh'][param] + finally: + self.close_db() + """ + def get_conf_conn(self, addr_host): + ''' + Get the configured connections by priority of a host. + :param addr_host: The IP address of the host. + :return: A list containing): + [{'conn_mod_name': val, 'priority': val, 'args': {arg1: val, ...}}] + ''' + res = [] + self.open_db() + try: + for conn in self.db['hosts'][addr_host]['conf']['connections']: + if self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] > 0: + dict_conn = {} + dict_conn['conn_mod_name'] = conn + dict_conn['priority'] = self.db['hosts'][addr_host]['conf']['connections'][conn]['priority'] + dict_conn['args'] = + finally: + self.close_db() + """ def add_check(self, addr_host, mod_name, val): """ Called by a monitoring module. diff --git a/bower.json b/bower.json index 2dd7dba..2b7c589 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "angular-toastr": "~0.5.2", "angular-route": "~1.2.28", "angular-bootstrap": "~0.12.1", - "angular-sanitize": "~1.2.28" + "angular-sanitize": "~1.2.28", + "angular-file-upload": "~1.1.5" }, "resolutions": { "angular": "~1.2.28" diff --git a/conf.txt b/conf.txt index 008cd5f..99f99da 100644 --- a/conf.txt +++ b/conf.txt @@ -1,2 +1,3 @@ db_location=mum.db -external_modules_location=/home/aguilbaud/external \ No newline at end of file +external_modules_location=/home/aguilbaud/external +public_keys_location=keys/ \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 10bbc86..f1467c7 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -70,6 +70,8 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.pop_danger("Danger on "+ params[1], params[2]); } break; + case "KEYS_LIST": + $rootScope.$broadcast("keysList", JSON.parse(value)); case "ERROR": toastr.error(value, "Server error"); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 62106c8..b905f2c 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -225,11 +225,11 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI $scope.isNotConfigured = function(modname){ res = false; - for(param in $scope.current_config[modname]){ + /*for(param in $scope.current_config[modname]){ if($scope.current_config[modname][param] == null){ res = true; } - } + }*/ return res; } @@ -247,7 +247,10 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI $scope.ok = function () { var args = {}; + args['addr_host'] = $scope.conn_args.addr_host; + args['priorities'] = $scope.priorities; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_prio_conn','args': args}})); $modalInstance.close(); }; @@ -270,7 +273,11 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI }; }); -mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $templateCache, conf_conn_args) { +mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $templateCache, conf_conn_args, FileUploader) { + $scope.uploader = new FileUploader({ + url: '/upload' + }); + $scope.conf_conn_args = conf_conn_args; /* {'addr_host': val, 'modname': val, 'current_config': val} */ @@ -283,16 +290,33 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection } } */ + $scope.conf_conn = {}; + + $scope.port = $scope.conf_conn_args["current_config"]["ssh"]["port"]; + + $scope.username = $scope.conf_conn_args["current_config"]["ssh"]["username"]; + $scope.public_key = $scope.conf_conn_args["current_config"]["ssh"]["public_key"]; + + $scope.keys_list = []; $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_CONN_MOD": ""})); + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_KEYS_LIST": ""})); + + $scope.$on("keysList", function (event, args) { + $scope.$apply(function(){ + $scope.keys_list = args; + }); + }); + $scope.$on("resGetLoadedConnMod", function (event, args) { $scope.$apply(function(){ $scope.loaded_conn_mods = args; - for(mod in args){ + /*for(mod in args){ //alert(args[mod]); for(param in args[mod]){ + $scope.conf_conn[param] = $scope.conf_conn_args["current_config"][param]; //alert(param); $scope.form += '<div class="row">'; $scope.form += ' <div class="col-xs-3">'; @@ -303,14 +327,22 @@ mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $mo $scope.form += ' </div>'; $scope.form += '</div>'; } - } - $templateCache.put('templateForm.html', $scope.form); + }*/ + //$templateCache.put('templateForm.html', $scope.form); }); + }); + $scope.ok = function () { - var args = {}; + var args = conf_conn_args; + args['current_config']['ssh'] = {} + args['current_config']['ssh']['port'] = $scope.port; + args['current_config']['ssh']['username'] = $scope.username; + args['current_config']['ssh']['public_key'] = $scope.public_key; + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'set_conf_conn','args': args}})); $modalInstance.close(); }; diff --git a/static/js/mumApp.js b/static/js/mumApp.js index c6c12c0..bc223ef 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -1,4 +1,4 @@ -var mumApp = angular.module('mumApp', ['ngSanitize', 'ngRoute', 'ui.bootstrap', 'toastr']); +var mumApp = angular.module('mumApp', ['angularFileUpload', 'ngSanitize', 'ngRoute', 'ui.bootstrap', 'toastr']); mumApp.factory('DataHosts', function(){ return {Items: []}; diff --git a/views/hostpage.html b/views/hostpage.html index a8d037c..b5af0d7 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -162,7 +162,7 @@ <tbody> <tr ng-repeat="(modname, modconf) in current_config"> <td>{{modname}}</td> - <td><input type="number" min="0" ng-model="priorities[modname]" 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-success">Test</button> @@ -184,11 +184,39 @@ <script type="text/ng-template" id="modal_conf_conn_label.html"> <div class="modal-header"> - <h3 class="modal-title">Advanced settings for {{conf_conn_args['modname']}}</h3>{{loaded_conn_mods}} + <h3 class="modal-title">Advanced settings for {{conf_conn_args['modname']}}</h3> </div> - {{form}} + <div class="modal-body"> - <div ng-include=" 'templateForm.html' "></div> + {{loaded_conn_mods}} + <!--<input type="file" nv-file-select uploader="uploader"/><br/> + <ul> + <li ng-repeat="item in uploader.queue"> + Upload a new key: <span ng-bind="item.file.name"></span><br/> + <button ng-click="item.upload(item, '\keys')">upload</button> + </li> + </ul>--> + <div class="row"> + <div class="col-xs-2"> + <label for="port">Port used</label> + <input type="number" id="port" min="0" ng-model="port"> + </div> + </div> + <div class="row"> + <div class="col-xs-2"> + <label for="public_key">Select a public key</label> + <select class="form-control input-sm" id="public_key" ng-model="public_key" ng-options="key as key for key in keys_list"></select> + </div> + </div> + <div class="row"> + <div class="col-xs-3"> + <label for="usrname">Login</label> + <input type="text" id="usrname" ng-model="username"/> + </div> + </div> + + + <!--<div ng-include=" 'templateForm.html' "></div>--> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="cancel()">Close</button> diff --git a/views/index.html b/views/index.html index 1ac05c3..1bb2ed5 100644 --- a/views/index.html +++ b/views/index.html @@ -19,6 +19,7 @@ <!-- AngularJS --> <script src="bower_components/angular/angular.min.js"></script> + <script src="bower_components/angular-file-upload/angular-file-upload.min.js"></script> <script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script> <script src="bower_components/angular-route/angular-route.min.js"></script> <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.