branch develop updated (6ce6fa1 -> 4d7d99f)
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 6ce6fa1 l'url détermine l'adresse du websocket dans le controlleur new 98c7577 séparation des controlleurs angular new d195dd8 séparation des controlleurs angular new 7f6bf28 séparation des controlleurs angular (scanCtrl ajouté) new 419b9f7 hostpage : bilan des check => OK new 4d7d99f hostpage : detection (ràf mettre en forme) The 5 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 4d7d99f13b57a5e6314bf490c66f1807a8a21d7b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 18:05:59 2015 +0100 hostpage : detection (ràf mettre en forme) commit 419b9f75b2c2a84c5a91dae8e02490170e376241 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 17:16:25 2015 +0100 hostpage : bilan des check => OK commit 7f6bf28c6712f1dcea71cd66a8ba6b69030a6dd4 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 15:03:06 2015 +0100 séparation des controlleurs angular (scanCtrl ajouté) commit d195dd8ca8927dc09500ce056d9e0de07372d9c2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:23:15 2015 +0100 séparation des controlleurs angular commit 98c7577d5babe9c4dbf21e80197ef9cfb2a536a6 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:04:23 2015 +0100 séparation des controlleurs angular Summary of changes: app/app.py | 7 +- app/modules/storage_modules/shelve_db.py | 41 ++-- static/js/controllers/dashboardCtrl.js | 141 +++++++++++ static/js/controllers/headCtrl.js | 117 +++++++++ static/js/controllers/hostPageCtrl.js | 21 ++ static/js/controllers/mainCtrl.js | 404 ------------------------------- static/js/controllers/scanCtrl.js | 22 ++ static/js/mumApp.js | 147 +++++++++++ views/dashboard.html | 3 +- views/hostpage.html | 215 ++++------------ views/index.html | 141 +++++------ 11 files changed, 590 insertions(+), 669 deletions(-) create mode 100644 static/js/controllers/dashboardCtrl.js create mode 100644 static/js/controllers/headCtrl.js create mode 100644 static/js/controllers/hostPageCtrl.js delete mode 100644 static/js/controllers/mainCtrl.js create mode 100644 static/js/controllers/scanCtrl.js create mode 100644 static/js/mumApp.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 98c7577d5babe9c4dbf21e80197ef9cfb2a536a6 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:04:23 2015 +0100 séparation des controlleurs angular --- app/app.py | 4 +- static/js/controllers/mainCtrl.js | 249 +++++++++++++++++++++----------------- views/dashboard.html | 3 +- views/index.html | 136 ++++++++++----------- 4 files changed, 208 insertions(+), 184 deletions(-) diff --git a/app/app.py b/app/app.py index c51e833..c55e720 100755 --- a/app/app.py +++ b/app/app.py @@ -142,12 +142,12 @@ def receive(ws): elif code == GET_HOSTS_DEMAND: db = module_loader.load_db() hosts= db.get_hosts() - print hosts ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) del db elif code == HOST_INFO_DEMAND: db = module_loader.load_db() - ws.send({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])}) + ws.send(json.dumps({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])})) + del db else: break except: # Should be WebSocketError when closing the connection diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js index 79ca4a8..5bb8ee1 100644 --- a/static/js/controllers/mainCtrl.js +++ b/static/js/controllers/mainCtrl.js @@ -1,54 +1,58 @@ var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); +mumApp.factory('DataHosts', function(){ + return {Items: []}; +}); + mumApp.config(function($routeProvider){ $routeProvider .when('/',{ templateUrl : 'dashboard.html', - controller : 'mainController' + controller : 'dashboardController' }) .when('/dashboard',{ templateUrl : 'dashboard.html', - controller : 'mainController' + controller : 'dashboardController' }) .when('/dashboard/:param',{ templateUrl : 'dashboard.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/groups',{ templateUrl : 'groups.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/hostpage/:param',{ templateUrl : 'hostpage.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/notifications',{ templateUrl : 'notifications.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/profile',{ templateUrl : 'profile.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/scan',{ templateUrl : 'scan.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/settings',{ templateUrl : 'settings.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/signin',{ templateUrl : 'signin.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/stats',{ templateUrl : 'stats.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/users',{ templateUrl : 'users.html', - controller : 'mainController' + //controller : 'mainController' }) .otherwise({ redirectTo: '/' @@ -59,11 +63,7 @@ mumApp.config(function($routeProvider){ $locationProvider.html5Mode(false).hashPrefix("!"); });*/ -mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', '$routeParams', '$location', - function($scope, toastr, $interval, $filter, $routeParams, $location) { - - // init - $scope.master = {}; +mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ $scope.param = $routeParams.param; $scope.sort = { @@ -73,6 +73,12 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', $scope.gap = 5; + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + $scope.filteredItems = []; $scope.groupedItems = []; $scope.itemsPerPage = 25; @@ -91,105 +97,15 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', $scope.group_filter = ''; - $scope.items = []; - $scope.status = ''; $scope.grp = "all"; - // Concerning the scan form - - $scope.ip_range = "" // la plage d'ip entree dans le champ - $scope.state = ""; // l'etat general du scan en cours - $scope.validated = false; // pour afficher ou non certaines parties de la page - $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; - - /* - // Concerning the hostpage - $scope.host_informations = null; - $scope.get_host_informations = function(addr_host){ - var request = '{"13" : "'+ addr_host + '"}'; - ws.send(request); - }*/ - - // Concerning WebSocket - var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); - - ws.onopen = function() { - var request = '{"14" : ""}'; - ws.send(request); + $scope.toto = function(){ + $scope.items = DataHosts.Items; + alert(DataHosts.Items[0].status); }; - - ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket - JSON.parse(evt.data, function (key, value) { - switch(parseInt(key)){ - case 20: // Success of a module execution - $scope.$apply(function(){ - $scope.state = "Success!"; - $scope.ip_scanned = value; - }); - toastr.success(value, "Success on module execution"); - case 21: // Informations concerning one host - /*$scope.$apply(function(){ - $scope.host_informations = JSON.parse(value); - });*/ - break; - case 22: // List of hosts under monitoring - $scope.$apply(function(){ - $scope.items = JSON.parse(value); - }); - break; - case 30: - $scope.$apply(function(){ - $scope.state = value; - }); - toastr.info(value, "Current status is :"); - /* - $scope.$apply(function(){ - $scope.state = value - });*/ - break; - case 31: - params = value.split(','); - if(params[0]=='success'){ - $scope.pop_success("Success on " + params[1], params[2]); - } - else if(params[0] == 'warning'){ - $scope.pop_warning("Warning on " + params[1], params[2]); - } - else if(params[0] == 'danger'){ - $scope.pop_danger("Danger on "+ params[1], params[2]); - } - break; - case 40: - toastr.error(value, "Server error"); - break; - default: - break; - } - }); - - }; - - $scope.pop_success = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_warning = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_danger = function(title, msg){ - toastr.error(msg, title); - }; - - $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire - var request = '{"10" : "' + $scope.ip_range + '"}'; - ws.send(request); - } - // Concerning the table manipulation var searchMatch = function (haystack, needle) { if (!needle) { @@ -287,6 +203,117 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', } return res; }; +}); + +mumApp.controller('headController', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { + + // init + //$scope.master = {}; + + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + + // Concerning the scan form + + $scope.ip_range = "" // la plage d'ip entree dans le champ + $scope.state = ""; // l'etat general du scan en cours + $scope.validated = false; // pour afficher ou non certaines parties de la page + $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page + $scope.ip_scanned = {}; + + + // Concerning the hostpage + $scope.host_informations = null; + $scope.get_host_informations = function(addr_host){ + alert("jobep"); + var request = '{"13" : "'+ addr_host + '"}'; + ws.send(request); + } + + // Concerning WebSocket + var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); + + ws.onopen = function() { + var request = '{"14" : ""}'; + ws.send(request); + }; + + + ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket + JSON.parse(evt.data, function (key, value) { + switch(parseInt(key)){ + case 20: // Success of a module execution + $scope.$apply(function(){ + $scope.state = "Success!"; + $scope.ip_scanned = value; + }); + toastr.success(value, "Success on module execution"); + /*case 21: // Informations concerning one host + $scope.$apply(function(){ + DataHosts.Items = JSON.parse(value); + alert(value); + }); + break;*/ + case 22: // List of hosts under monitoring + DataHosts.Items = JSON.parse(value); + $rootScope.$broadcast("hostsUpdate"); + $scope.$apply(function(){ + $scope.items = DataHosts.Items; + }); + break; + case 30: + $scope.$apply(function(){ + $scope.state = value; + }); + toastr.info(value, "Current status is :"); + /* + $scope.$apply(function(){ + $scope.state = value + });*/ + break; + case 31: + params = value.split(','); + if(params[0]=='success'){ + $scope.pop_success("Success on " + params[1], params[2]); + } + else if(params[0] == 'warning'){ + $scope.pop_warning("Warning on " + params[1], params[2]); + } + else if(params[0] == 'danger'){ + $scope.pop_danger("Danger on "+ params[1], params[2]); + } + break; + case 40: + toastr.error(value, "Server error"); + break; + default: + break; + } + }); + + }; + + $scope.pop_success = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_warning = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_danger = function(title, msg){ + toastr.error(msg, title); + }; + + $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire + var request = '{"10" : "' + $scope.ip_range + '"}'; + ws.send(request); + } + + /* * Return a vector with the number of hosts with a status of : success, warning, danger @@ -318,7 +345,7 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', item.Selected = $scope.selectedAll; }); }; -}]); +}); mumApp.$inject = ['$scope', '$filter']; diff --git a/views/dashboard.html b/views/dashboard.html index 13e67b0..fc69e6a 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -2,7 +2,6 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Dashboard</h1> <h2 class="sub-header">Hosts currently on monitoring</h2> - <div class="row"> <div class="col-xs-3"> <label for="addr_f">Address filter</label> @@ -68,7 +67,7 @@ orderBy:sort.sortingOrder:sort.reverse | filter:{addr:addr_filter, name:name_filter, status:status_filter, group:{name:group_filter}}" class={{item.status}}> - <td><a href="#/hostpage/{{item.addr}}" ng-click="get_host_informations({{item.addr}})">{{item.addr}}</a></td> + <td><a href="#/hostpage/{{item.addr}}">{{item.addr}}</a></td> <td>{{item.name}}</td> <td>warning : {{item.warning}}<br/> danger : {{item.danger}}</td> diff --git a/views/index.html b/views/index.html index bce6dea..b3f0e29 100644 --- a/views/index.html +++ b/views/index.html @@ -1,81 +1,79 @@ <!DOCTYPE html> <html lang="en" ng-app="mumApp"> -<head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=2"> - <meta name="description" content=""> - <meta name="author" content=""> - <link rel="icon" href="favicon.ico"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=2"> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="favicon.ico"> - <title>Mum : Dashboard</title> + <title>Mum : Dashboard</title> - <!-- Bootstrap core CSS --> - <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> + <!-- Bootstrap core CSS --> + <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> - <!-- Custom styles for this template --> - <link href="static/css/dashboard.css" rel="stylesheet"> - <link href="bower_components/angular-toastr/dist/angular-toastr.min.css" rel="stylesheet"/> + <!-- Custom styles for this template --> + <link href="static/css/dashboard.css" rel="stylesheet"> + <link href="bower_components/angular-toastr/dist/angular-toastr.min.css" rel="stylesheet"/> - <script src="bower_components/angular/angular.min.js"></script> - <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> - <script src="bower_components/angular-route/angular-route.min.js"></script> - <script src="static/js/controllers/mainCtrl.js"></script> + <script src="bower_components/angular/angular.min.js"></script> + <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> + <script src="bower_components/angular-route/angular-route.min.js"></script> + <script src="static/js/controllers/mainCtrl.js"></script> - <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> - <!--[if lt IE 9]><!-- - <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> - <![endif]--> -</head> + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]><!-- + <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + </head> -<body ng-controller="mainController"> + <body> - <nav class="navbar navbar-inverse navbar-fixed-top"> - <div class="container-fluid"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" href="dashboard.html">Mum</a> - <p class="navbar-text navbar-left"><a href="#dashboard/success" style="color:green">OK : {{stateNumber()[0]}}</a></p> - <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> - <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> - </div> - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav navbar-right"> - <li><a href="#profile">Profile</a></li> - <li><a href="signin.html">Logout</a></li> - </ul> - </div> - </div> - </nav> - <div class="container-fluid"> - <div class="row"> - <div class="col-sm-3 col-md-2 sidebar"> - <ul class="nav nav-sidebar sidebar-fixed-left"> - <li><a href="#dashboard">Dashboard</a></li> - <li><a href="#scan">Scan for new machines</a></li> - <li><a href="#groups">Manage your groups</a></li> - <li><a href="#settings">Check the default settings</a></li> - <li><a href="#users">Users</a></li> - <li><a href="#notifications">Notification parameters</a></li> - <li><a href="#stats">See the statistics</a></li> - </ul> + <nav class="navbar navbar-inverse navbar-fixed-top"> + <div class="container-fluid"> + <div class="navbar-header" ng-controller="headController"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="dashboard.html">Mum</a> + <p class="navbar-text navbar-left"><a href="#dashboard/success" style="color:green">OK : {{stateNumber()[0]}}</a></p> + <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> + <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> + </div> + <div id="navbar" class="navbar-collapse collapse"> + <ul class="nav navbar-nav navbar-right"> + <li><a href="#profile">Profile</a></li> + <li><a href="signin.html">Logout</a></li> + </ul> + </div> </div> - - - <div id="main"> - <div ng-view></div> - </div> - <!-- Bootstrap core JavaScript - ================================================== --> - <!-- Placed at the end of the document so the pages load faster --> - <script src="bower_components/jquery/dist/jquery.min.js"></script> - <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> -</body> + </nav> + <div class="container-fluid"> + <div class="row"> + <div class="col-sm-3 col-md-2 sidebar"> + <ul class="nav nav-sidebar sidebar-fixed-left"> + <li><a href="#dashboard">Dashboard</a></li> + <li><a href="#scan">Scan for new machines</a></li> + <li><a href="#groups">Manage your groups</a></li> + <li><a href="#settings">Check the default settings</a></li> + <li><a href="#users">Users</a></li> + <li><a href="#notifications">Notification parameters</a></li> + <li><a href="#stats">See the statistics</a></li> + </ul> + </div> + <div id="main"> + <div ng-view></div> + </div> + <!-- Bootstrap core JavaScript + ================================================== --> + <!-- Placed at the end of the document so the pages load faster --> + <script src="bower_components/jquery/dist/jquery.min.js"></script> + <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> + </body> </html> -- 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 d195dd8ca8927dc09500ce056d9e0de07372d9c2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:23:15 2015 +0100 séparation des controlleurs angular --- static/js/controllers/dashboardCtrl.js | 141 +++++++++++ static/js/controllers/headCtrl.js | 141 +++++++++++ static/js/controllers/mainCtrl.js | 431 --------------------------------- static/js/mumApp.js | 147 +++++++++++ views/index.html | 5 +- 5 files changed, 433 insertions(+), 432 deletions(-) diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js new file mode 100644 index 0000000..f649cba --- /dev/null +++ b/static/js/controllers/dashboardCtrl.js @@ -0,0 +1,141 @@ +mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ + $scope.param = $routeParams.param; + + $scope.sort = { + sortingOrder : 'id', + reverse : false + }; + + $scope.gap = 5; + + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + + $scope.filteredItems = []; + $scope.groupedItems = []; + $scope.itemsPerPage = 25; + $scope.pagedItems = []; + $scope.currentPage = 0; + + $scope.addr_filter = ''; + $scope.name_filter = ''; + + if($routeParams.param == null){ + $scope.status_filter = ''; + } + else{ + $scope.status_filter = $routeParams.param; + } + + $scope.group_filter = ''; + + $scope.status = ''; + + $scope.grp = "all"; + + $scope.toto = function(){ + $scope.items = DataHosts.Items; + alert(DataHosts.Items[0].status); + }; + + // Concerning the table manipulation + var searchMatch = function (haystack, needle) { + if (!needle) { + return true; + } + return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1; + }; + + // init the filtered items + $scope.search = function () { + $scope.filteredItems = $filter('filter')($scope.items, function (item) { + for(var attr in item) { + if (searchMatch(item[attr], $scope.query)) + return true; + } + return false; + }); + // take care of the sorting order + if ($scope.sort.sortingOrder !== '') { + $scope.filteredItems = $filter('orderBy')($scope.filteredItems, $scope.sort.sortingOrder, $scope.sort.reverse); + } + $scope.currentPage = 0; + // now group by pages + $scope.groupToPages(); + }; + + + // calculate page in place + $scope.groupToPages = function () { + $scope.pagedItems = []; + + for (var i = 0; i < $scope.filteredItems.length; i++) { + if (i % $scope.itemsPerPage === 0) { + $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; + } else { + $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)].push($scope.filteredItems[i]); + } + } + }; + + $scope.range = function (size,start, end) { + var ret = []; + console.log(size,start, end); + + if (size < end) { + end = size; + start = size-$scope.gap; + } + for (var i = start; i < end; i++) { + ret.push(i); + } + console.log(ret); + return ret; + }; + + $scope.prevPage = function () { + if ($scope.currentPage > 0) { + $scope.currentPage--; + } + }; + + $scope.nextPage = function () { + if ($scope.currentPage < $scope.pagedItems.length - 1) { + $scope.currentPage++; + } + }; + + $scope.setPage = function () { + $scope.currentPage = this.n; + }; + + // functions have been describe process the data for display + $scope.search(); + + // $scope.groupsByAddr = {} + + $scope.getGroupsByAddr = function(addr) { + res = "" + for(var i = 0; i<$scope.items.length; i++){ + if($scope.items[i].addr === addr){ + for(var j = 0; j<$scope.items[i].group.length; j++){ + res += $scope.items[i].group[j].name + " "; + } + } + } + return res; + }; + + $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].name); + } + } + return res; + }; +}); \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js new file mode 100644 index 0000000..231c143 --- /dev/null +++ b/static/js/controllers/headCtrl.js @@ -0,0 +1,141 @@ +mumApp.controller('headController', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { + + // init + //$scope.master = {}; + + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + + // Concerning the scan form + + $scope.ip_range = "" // la plage d'ip entree dans le champ + $scope.state = ""; // l'etat general du scan en cours + $scope.validated = false; // pour afficher ou non certaines parties de la page + $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page + $scope.ip_scanned = {}; + + + // Concerning the hostpage + $scope.host_informations = null; + $scope.get_host_informations = function(addr_host){ + alert("jobep"); + var request = '{"13" : "'+ addr_host + '"}'; + ws.send(request); + } + + // Concerning WebSocket + var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); + + ws.onopen = function() { + var request = '{"14" : ""}'; + ws.send(request); + }; + + + ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket + JSON.parse(evt.data, function (key, value) { + switch(parseInt(key)){ + case 20: // Success of a module execution + $scope.$apply(function(){ + $scope.state = "Success!"; + $scope.ip_scanned = value; + }); + toastr.success(value, "Success on module execution"); + /*case 21: // Informations concerning one host + $scope.$apply(function(){ + DataHosts.Items = JSON.parse(value); + alert(value); + }); + break;*/ + case 22: // List of hosts under monitoring + DataHosts.Items = JSON.parse(value); + $rootScope.$broadcast("hostsUpdate"); + $scope.$apply(function(){ + $scope.items = DataHosts.Items; + }); + break; + case 30: + $scope.$apply(function(){ + $scope.state = value; + }); + toastr.info(value, "Current status is :"); + /* + $scope.$apply(function(){ + $scope.state = value + });*/ + break; + case 31: + params = value.split(','); + if(params[0]=='success'){ + $scope.pop_success("Success on " + params[1], params[2]); + } + else if(params[0] == 'warning'){ + $scope.pop_warning("Warning on " + params[1], params[2]); + } + else if(params[0] == 'danger'){ + $scope.pop_danger("Danger on "+ params[1], params[2]); + } + break; + case 40: + toastr.error(value, "Server error"); + break; + default: + break; + } + }); + + }; + + $scope.pop_success = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_warning = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_danger = function(title, msg){ + toastr.error(msg, title); + }; + + $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire + var request = '{"10" : "' + $scope.ip_range + '"}'; + ws.send(request); + } + + + + /* + * Return a vector with the number of hosts with a status of : success, warning, danger + */ + $scope.stateNumber = function(){ + var res = [0,0,0]; + for(var i = 0; i<$scope.items.length; i++){ + if($scope.items[i].status === "success"){ + res[0]++; + } + if($scope.items[i].status === "warning"){ + res[1]++; + } + if($scope.items[i].status === "danger"){ + res[2]++; + } + } + return res; + }; + + $scope.checkAll = function(){ + if($scope.selectedAll){ + $scope.selectedAll = true; + } + else{ + $scope.selectedAll = false; + } + angular.forEach($scope.items, function(item){ + item.Selected = $scope.selectedAll; + }); + }; +}); \ No newline at end of file diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js deleted file mode 100644 index 5bb8ee1..0000000 --- a/static/js/controllers/mainCtrl.js +++ /dev/null @@ -1,431 +0,0 @@ -var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); - -mumApp.factory('DataHosts', function(){ - return {Items: []}; -}); - -mumApp.config(function($routeProvider){ - $routeProvider - .when('/',{ - templateUrl : 'dashboard.html', - controller : 'dashboardController' - }) - .when('/dashboard',{ - templateUrl : 'dashboard.html', - controller : 'dashboardController' - }) - .when('/dashboard/:param',{ - templateUrl : 'dashboard.html', - //controller : 'mainController' - }) - .when('/groups',{ - templateUrl : 'groups.html', - //controller : 'mainController' - }) - .when('/hostpage/:param',{ - templateUrl : 'hostpage.html', - //controller : 'mainController' - }) - .when('/notifications',{ - templateUrl : 'notifications.html', - //controller : 'mainController' - }) - .when('/profile',{ - templateUrl : 'profile.html', - //controller : 'mainController' - }) - .when('/scan',{ - templateUrl : 'scan.html', - //controller : 'mainController' - }) - .when('/settings',{ - templateUrl : 'settings.html', - //controller : 'mainController' - }) - .when('/signin',{ - templateUrl : 'signin.html', - //controller : 'mainController' - }) - .when('/stats',{ - templateUrl : 'stats.html', - //controller : 'mainController' - }) - .when('/users',{ - templateUrl : 'users.html', - //controller : 'mainController' - }) - .otherwise({ - redirectTo: '/' - }); -}); - -/*mumApp.config(function($locationProvider)){ - $locationProvider.html5Mode(false).hashPrefix("!"); -});*/ - -mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ - $scope.param = $routeParams.param; - - $scope.sort = { - sortingOrder : 'id', - reverse : false - }; - - $scope.gap = 5; - - $scope.items = []; - - $scope.$on("hostsUpdate", function (event) { - $scope.items = DataHosts.Items; - }); - - $scope.filteredItems = []; - $scope.groupedItems = []; - $scope.itemsPerPage = 25; - $scope.pagedItems = []; - $scope.currentPage = 0; - - $scope.addr_filter = ''; - $scope.name_filter = ''; - - if($routeParams.param == null){ - $scope.status_filter = ''; - } - else{ - $scope.status_filter = $routeParams.param; - } - - $scope.group_filter = ''; - - $scope.status = ''; - - $scope.grp = "all"; - - $scope.toto = function(){ - $scope.items = DataHosts.Items; - alert(DataHosts.Items[0].status); - }; - - // Concerning the table manipulation - var searchMatch = function (haystack, needle) { - if (!needle) { - return true; - } - return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1; - }; - - // init the filtered items - $scope.search = function () { - $scope.filteredItems = $filter('filter')($scope.items, function (item) { - for(var attr in item) { - if (searchMatch(item[attr], $scope.query)) - return true; - } - return false; - }); - // take care of the sorting order - if ($scope.sort.sortingOrder !== '') { - $scope.filteredItems = $filter('orderBy')($scope.filteredItems, $scope.sort.sortingOrder, $scope.sort.reverse); - } - $scope.currentPage = 0; - // now group by pages - $scope.groupToPages(); - }; - - - // calculate page in place - $scope.groupToPages = function () { - $scope.pagedItems = []; - - for (var i = 0; i < $scope.filteredItems.length; i++) { - if (i % $scope.itemsPerPage === 0) { - $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; - } else { - $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)].push($scope.filteredItems[i]); - } - } - }; - - $scope.range = function (size,start, end) { - var ret = []; - console.log(size,start, end); - - if (size < end) { - end = size; - start = size-$scope.gap; - } - for (var i = start; i < end; i++) { - ret.push(i); - } - console.log(ret); - return ret; - }; - - $scope.prevPage = function () { - if ($scope.currentPage > 0) { - $scope.currentPage--; - } - }; - - $scope.nextPage = function () { - if ($scope.currentPage < $scope.pagedItems.length - 1) { - $scope.currentPage++; - } - }; - - $scope.setPage = function () { - $scope.currentPage = this.n; - }; - - // functions have been describe process the data for display - $scope.search(); - - // $scope.groupsByAddr = {} - - $scope.getGroupsByAddr = function(addr) { - res = "" - for(var i = 0; i<$scope.items.length; i++){ - if($scope.items[i].addr === addr){ - for(var j = 0; j<$scope.items[i].group.length; j++){ - res += $scope.items[i].group[j].name + " "; - } - } - } - return res; - }; - - $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].name); - } - } - return res; - }; -}); - -mumApp.controller('headController', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { - - // init - //$scope.master = {}; - - $scope.items = []; - - $scope.$on("hostsUpdate", function (event) { - $scope.items = DataHosts.Items; - }); - - // Concerning the scan form - - $scope.ip_range = "" // la plage d'ip entree dans le champ - $scope.state = ""; // l'etat general du scan en cours - $scope.validated = false; // pour afficher ou non certaines parties de la page - $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; - - - // Concerning the hostpage - $scope.host_informations = null; - $scope.get_host_informations = function(addr_host){ - alert("jobep"); - var request = '{"13" : "'+ addr_host + '"}'; - ws.send(request); - } - - // Concerning WebSocket - var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); - - ws.onopen = function() { - var request = '{"14" : ""}'; - ws.send(request); - }; - - - ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket - JSON.parse(evt.data, function (key, value) { - switch(parseInt(key)){ - case 20: // Success of a module execution - $scope.$apply(function(){ - $scope.state = "Success!"; - $scope.ip_scanned = value; - }); - toastr.success(value, "Success on module execution"); - /*case 21: // Informations concerning one host - $scope.$apply(function(){ - DataHosts.Items = JSON.parse(value); - alert(value); - }); - break;*/ - case 22: // List of hosts under monitoring - DataHosts.Items = JSON.parse(value); - $rootScope.$broadcast("hostsUpdate"); - $scope.$apply(function(){ - $scope.items = DataHosts.Items; - }); - break; - case 30: - $scope.$apply(function(){ - $scope.state = value; - }); - toastr.info(value, "Current status is :"); - /* - $scope.$apply(function(){ - $scope.state = value - });*/ - break; - case 31: - params = value.split(','); - if(params[0]=='success'){ - $scope.pop_success("Success on " + params[1], params[2]); - } - else if(params[0] == 'warning'){ - $scope.pop_warning("Warning on " + params[1], params[2]); - } - else if(params[0] == 'danger'){ - $scope.pop_danger("Danger on "+ params[1], params[2]); - } - break; - case 40: - toastr.error(value, "Server error"); - break; - default: - break; - } - }); - - }; - - $scope.pop_success = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_warning = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_danger = function(title, msg){ - toastr.error(msg, title); - }; - - $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire - var request = '{"10" : "' + $scope.ip_range + '"}'; - ws.send(request); - } - - - - /* - * Return a vector with the number of hosts with a status of : success, warning, danger - */ - $scope.stateNumber = function(){ - var res = [0,0,0]; - for(var i = 0; i<$scope.items.length; i++){ - if($scope.items[i].status === "success"){ - res[0]++; - } - if($scope.items[i].status === "warning"){ - res[1]++; - } - if($scope.items[i].status === "danger"){ - res[2]++; - } - } - return res; - }; - - $scope.checkAll = function(){ - if($scope.selectedAll){ - $scope.selectedAll = true; - } - else{ - $scope.selectedAll = false; - } - angular.forEach($scope.items, function(item){ - item.Selected = $scope.selectedAll; - }); - }; -}); - -mumApp.$inject = ['$scope', '$filter']; - -mumApp.directive("customSort", function() { -return { -restrict: 'A', -transclude: true, -scope: { - order: '=', - sort: '=' -}, -template : - ' <a ng-click="sort_by(order)" style="color: #555555;">'+ - ' <span ng-transclude></span>'+ - ' <i ng-class="selectedCls(order)"></i>'+ - '</a>', -link: function(scope) { - -// change sorting order -scope.sort_by = function(newSortingOrder) { - var sort = scope.sort; - - if (sort.sortingOrder == newSortingOrder){ - sort.reverse = !sort.reverse; - } - - sort.sortingOrder = newSortingOrder; -}; - - -scope.selectedCls = function(column) { - if(column == scope.sort.sortingOrder){ - return ('icon-chevron-' + ((scope.sort.reverse) ? 'down' : 'up')); - } - else{ - return'icon-sort' - } -}; -}// end link -} - - -}); - -// https://github.com/angular-ui/angular-ui-OLDREPO/blob/master/modules/filters... (MIT licence) -mumApp.filter('unique', function () { - -return function (items, filterOn) { - - if (filterOn === false) { - return items; - } - - if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { - var hashCheck = {}, newItems = []; - - var extractValueToCompare = function (item) { - if (angular.isObject(item) && angular.isString(filterOn)) { - return item[filterOn]; - } else { - return item; - } - }; - - angular.forEach(items, function (item) { - var valueToCheck, isDuplicate = false; - - for (var i = 0; i < newItems.length; i++) { - if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { - isDuplicate = true; - break; - } - } - if (!isDuplicate) { - newItems.push(item); - } - - }); - items = newItems; - } - return items; -}; -}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js new file mode 100644 index 0000000..3844456 --- /dev/null +++ b/static/js/mumApp.js @@ -0,0 +1,147 @@ +var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); + +mumApp.factory('DataHosts', function(){ + return {Items: []}; +}); + +mumApp.config(function($routeProvider){ + $routeProvider + .when('/',{ + templateUrl : 'dashboard.html', + controller : 'dashboardController' + }) + .when('/dashboard',{ + templateUrl : 'dashboard.html', + controller : 'dashboardController' + }) + .when('/dashboard/:param',{ + templateUrl : 'dashboard.html', + //controller : 'mainController' + }) + .when('/groups',{ + templateUrl : 'groups.html', + //controller : 'mainController' + }) + .when('/hostpage/:param',{ + templateUrl : 'hostpage.html', + //controller : 'mainController' + }) + .when('/notifications',{ + templateUrl : 'notifications.html', + //controller : 'mainController' + }) + .when('/profile',{ + templateUrl : 'profile.html', + //controller : 'mainController' + }) + .when('/scan',{ + templateUrl : 'scan.html', + //controller : 'mainController' + }) + .when('/settings',{ + templateUrl : 'settings.html', + //controller : 'mainController' + }) + .when('/signin',{ + templateUrl : 'signin.html', + //controller : 'mainController' + }) + .when('/stats',{ + templateUrl : 'stats.html', + //controller : 'mainController' + }) + .when('/users',{ + templateUrl : 'users.html', + //controller : 'mainController' + }) + .otherwise({ + redirectTo: '/' + }); +}); + +/*mumApp.config(function($locationProvider)){ + $locationProvider.html5Mode(false).hashPrefix("!"); +});*/ + +mumApp.$inject = ['$scope', '$filter']; + +mumApp.directive("customSort", function() { +return { +restrict: 'A', +transclude: true, +scope: { + order: '=', + sort: '=' +}, +template : + ' <a ng-click="sort_by(order)" style="color: #555555;">'+ + ' <span ng-transclude></span>'+ + ' <i ng-class="selectedCls(order)"></i>'+ + '</a>', +link: function(scope) { + +// change sorting order +scope.sort_by = function(newSortingOrder) { + var sort = scope.sort; + + if (sort.sortingOrder == newSortingOrder){ + sort.reverse = !sort.reverse; + } + + sort.sortingOrder = newSortingOrder; +}; + + +scope.selectedCls = function(column) { + if(column == scope.sort.sortingOrder){ + return ('icon-chevron-' + ((scope.sort.reverse) ? 'down' : 'up')); + } + else{ + return'icon-sort' + } +}; +}// end link +} + + +}); + +// https://github.com/angular-ui/angular-ui-OLDREPO/blob/master/modules/filters... (MIT licence) +mumApp.filter('unique', function () { + +return function (items, filterOn) { + + if (filterOn === false) { + return items; + } + + if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { + var hashCheck = {}, newItems = []; + + var extractValueToCompare = function (item) { + if (angular.isObject(item) && angular.isString(filterOn)) { + return item[filterOn]; + } else { + return item; + } + }; + + angular.forEach(items, function (item) { + var valueToCheck, isDuplicate = false; + + for (var i = 0; i < newItems.length; i++) { + if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { + isDuplicate = true; + break; + } + } + if (!isDuplicate) { + newItems.push(item); + } + + }); + items = newItems; + } + return items; +}; +}); \ No newline at end of file diff --git a/views/index.html b/views/index.html index b3f0e29..5df1a23 100644 --- a/views/index.html +++ b/views/index.html @@ -20,7 +20,10 @@ <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> <script src="bower_components/angular-route/angular-route.min.js"></script> - <script src="static/js/controllers/mainCtrl.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> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- -- 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 7f6bf28c6712f1dcea71cd66a8ba6b69030a6dd4 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 15:03:06 2015 +0100 séparation des controlleurs angular (scanCtrl ajouté) --- app/app.py | 2 +- static/js/controllers/dashboardCtrl.js | 4 ++-- static/js/controllers/headCtrl.js | 25 +++++++++---------------- static/js/controllers/scanCtrl.js | 17 +++++++++++++++++ static/js/mumApp.js | 8 ++++---- views/index.html | 3 ++- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/app.py b/app/app.py index c55e720..7805908 100755 --- a/app/app.py +++ b/app/app.py @@ -159,6 +159,6 @@ def receive(ws): if __name__ == '__main__': global wsc wsc = WebSocketContainer(module_loader.load_db()) - process_monitoring.init(module_loader.load_db(), wsc) + #process_monitoring.init(module_loader.load_db(), wsc) port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, server=GeventWebSocketServer) \ No newline at end of file diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js index f649cba..31c9e33 100644 --- a/static/js/controllers/dashboardCtrl.js +++ b/static/js/controllers/dashboardCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ +mumApp.controller('dashboardCtrl', function($scope, $filter, $routeParams, DataHosts){ $scope.param = $routeParams.param; $scope.sort = { @@ -8,7 +8,7 @@ mumApp.controller('dashboardController', function($scope, $filter, $routeParams, $scope.gap = 5; - $scope.items = []; + $scope.items = DataHosts.Items; $scope.$on("hostsUpdate", function (event) { $scope.items = DataHosts.Items; diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 231c143..d5da7ee 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -1,27 +1,17 @@ -mumApp.controller('headController', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { +mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { // init //$scope.master = {}; - $scope.items = []; + $scope.items = DataHosts.Items; $scope.$on("hostsUpdate", function (event) { $scope.items = DataHosts.Items; }); - // Concerning the scan form - - $scope.ip_range = "" // la plage d'ip entree dans le champ - $scope.state = ""; // l'etat general du scan en cours - $scope.validated = false; // pour afficher ou non certaines parties de la page - $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; - - // Concerning the hostpage $scope.host_informations = null; $scope.get_host_informations = function(addr_host){ - alert("jobep"); var request = '{"13" : "'+ addr_host + '"}'; ws.send(request); } @@ -34,6 +24,11 @@ mumApp.controller('headController', function($scope, $rootScope, toastr, $interv ws.send(request); }; + // instructions received from other controllers + // args contains a json formatted string + $scope.$on("sendViaWs", function (event, args) { + ws.send(args); + }); ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket JSON.parse(evt.data, function (key, value) { @@ -61,6 +56,7 @@ mumApp.controller('headController', function($scope, $rootScope, toastr, $interv $scope.$apply(function(){ $scope.state = value; }); + $rootScope.$broadcast("stateUpdate", value); toastr.info(value, "Current status is :"); /* $scope.$apply(function(){ @@ -101,10 +97,7 @@ mumApp.controller('headController', function($scope, $rootScope, toastr, $interv toastr.error(msg, title); }; - $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire - var request = '{"10" : "' + $scope.ip_range + '"}'; - ws.send(request); - } + diff --git a/static/js/controllers/scanCtrl.js b/static/js/controllers/scanCtrl.js new file mode 100644 index 0000000..3f40afd --- /dev/null +++ b/static/js/controllers/scanCtrl.js @@ -0,0 +1,17 @@ +mumApp.controller('scanCtrl', function($scope, $rootScope) { + // Concerning the scan form + $scope.ip_range = "" // la plage d'ip entree dans le champ + $scope.state = ""; // l'etat general du scan en cours + + $scope.$on("stateUpdate", function (event, args) { + $scope.state = args; + }); + + $scope.validated = false; // pour afficher ou non certaines parties de la page + $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page + $scope.ip_scanned = {}; + + $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire + $rootScope.$broadcast("sendViaWs", JSON.stringify({"10": $scope.ip_range})); + }; +}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 3844456..8edd37c 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -8,15 +8,15 @@ mumApp.config(function($routeProvider){ $routeProvider .when('/',{ templateUrl : 'dashboard.html', - controller : 'dashboardController' + controller : 'dashboardCtrl' }) .when('/dashboard',{ templateUrl : 'dashboard.html', - controller : 'dashboardController' + controller : 'dashboardCtrl' }) .when('/dashboard/:param',{ templateUrl : 'dashboard.html', - //controller : 'mainController' + controller : 'dashboardCtrl' }) .when('/groups',{ templateUrl : 'groups.html', @@ -36,7 +36,7 @@ mumApp.config(function($routeProvider){ }) .when('/scan',{ templateUrl : 'scan.html', - //controller : 'mainController' + controller : 'scanCtrl' }) .when('/settings',{ templateUrl : 'settings.html', diff --git a/views/index.html b/views/index.html index 5df1a23..36429c1 100644 --- a/views/index.html +++ b/views/index.html @@ -24,6 +24,7 @@ <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> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- @@ -36,7 +37,7 @@ <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid"> - <div class="navbar-header" ng-controller="headController"> + <div class="navbar-header" ng-controller="headCtrl"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> -- 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 419b9f75b2c2a84c5a91dae8e02490170e376241 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 17:16:25 2015 +0100 hostpage : bilan des check => OK --- app/app.py | 3 +- app/modules/storage_modules/shelve_db.py | 38 +++++++++++-------- static/js/controllers/headCtrl.js | 25 ++----------- static/js/controllers/hostPageCtrl.js | 14 +++++++ static/js/controllers/scanCtrl.js | 7 +++- static/js/mumApp.js | 2 +- views/hostpage.html | 63 ++++++-------------------------- views/index.html | 1 + 8 files changed, 60 insertions(+), 93 deletions(-) diff --git a/app/app.py b/app/app.py index 7805908..8745224 100755 --- a/app/app.py +++ b/app/app.py @@ -141,12 +141,11 @@ def receive(ws): start_first_detection(msg[NMAP_SCAN_DEMAND], ws) elif code == GET_HOSTS_DEMAND: db = module_loader.load_db() - hosts= db.get_hosts() ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) del db elif code == HOST_INFO_DEMAND: db = module_loader.load_db() - ws.send(json.dumps({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])})) + ws.send(json.dumps({INFO_HOST: db.get_host_informations(msg[HOST_INFO_DEMAND])})) del db else: break diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 7644003..19120e3 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -265,44 +265,50 @@ class shelve_db: self.close_db() return json.dumps(res) - def get_host_inoformations(self, addr_host): + def get_host_informations(self, addr_host): """ Get every informations necessary for the hostpage summary page. :param addr_host: the IP address of the host :return: informations concerning this host on the form : { - addr_host:{ - 'monitoring':{ - mod_name:{ - 'state':val, - 'value':val, - 'unit':val, - 'last_check':date - } + 'host_name': val, + 'monitoring':{ + mod_name:{ + 'state':val, + 'value':val, + 'unit':val, + 'last_check':date } - 'detection':{ - mod_name:res - } - 'custom_info';val - 'interventions':list } + 'detection':{ + mod_name:res + } + 'custom_info';val + 'interventions':list } """ self.open_db() res = {} try: + res_nmap = json.loads(self.db['hosts'][addr_host]['detected']['nmap']) + if 'hostname' in res_nmap: + res['hostname'] = json.loads(self.db['hosts'][addr_host]['detected']['nmap'])['hostname'] + else: + res['hostname'] = '' res['monitoring'] = {} for mod in self.db['hosts'][addr_host]['monitoring']: - print mod res['monitoring'][mod] = self.db['hosts'][addr_host]['monitoring'][mod] + res['monitoring'][mod]['name'] = mod res['detected'] = {} for mod in self.db['hosts'][addr_host]['detected']: res['detected'][mod] = json.loads(self.db['hosts'][addr_host]['detected'][mod]) res['custom_info'] = self.db['hosts'][addr_host]['conf']['custom_info'] res['interventions'] = self.db['hosts'][addr_host]['conf']['interventions'] + except Exception as e: + print e.__str__() finally: self.close_db() - return json.dumps({addr_host: res}) + return json.dumps(res) def remove_host(self, addr_host): diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index d5da7ee..8366485 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -9,13 +9,6 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.items = DataHosts.Items; }); - // Concerning the hostpage - $scope.host_informations = null; - $scope.get_host_informations = function(addr_host){ - var request = '{"13" : "'+ addr_host + '"}'; - ws.send(request); - } - // Concerning WebSocket var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); @@ -34,17 +27,11 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r JSON.parse(evt.data, function (key, value) { switch(parseInt(key)){ case 20: // Success of a module execution - $scope.$apply(function(){ - $scope.state = "Success!"; - $scope.ip_scanned = value; - }); + $rootScope.$broadcast("success", value); toastr.success(value, "Success on module execution"); - /*case 21: // Informations concerning one host - $scope.$apply(function(){ - DataHosts.Items = JSON.parse(value); - alert(value); - }); - break;*/ + case 21: // Informations concerning one host + $rootScope.$broadcast("hostInfos", JSON.parse(value)); + break; case 22: // List of hosts under monitoring DataHosts.Items = JSON.parse(value); $rootScope.$broadcast("hostsUpdate"); @@ -97,10 +84,6 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r toastr.error(msg, title); }; - - - - /* * Return a vector with the number of hosts with a status of : success, warning, danger */ diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js new file mode 100644 index 0000000..8d9bd9c --- /dev/null +++ b/static/js/controllers/hostPageCtrl.js @@ -0,0 +1,14 @@ +mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, DataHosts) { + $scope.host_informations = null; + + $scope.addr_host = $routeParams.param + $rootScope.$broadcast("sendViaWs", JSON.stringify({"13": $routeParams.param})); + + $scope.items = []; + + $scope.$on("hostInfos", function (event, args) { + $scope.$apply(function(){ + $scope.items = args; + }); + }); +}); \ No newline at end of file diff --git a/static/js/controllers/scanCtrl.js b/static/js/controllers/scanCtrl.js index 3f40afd..63ecab5 100644 --- a/static/js/controllers/scanCtrl.js +++ b/static/js/controllers/scanCtrl.js @@ -2,6 +2,12 @@ mumApp.controller('scanCtrl', function($scope, $rootScope) { // Concerning the scan form $scope.ip_range = "" // la plage d'ip entree dans le champ $scope.state = ""; // l'etat general du scan en cours + $scope.ip_scanned = {}; + + $scope.$on("success", function (event, args) { + $scope.state = "Success!"; + $scope.ip_scanned = args; + }); $scope.$on("stateUpdate", function (event, args) { $scope.state = args; @@ -9,7 +15,6 @@ mumApp.controller('scanCtrl', function($scope, $rootScope) { $scope.validated = false; // pour afficher ou non certaines parties de la page $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire $rootScope.$broadcast("sendViaWs", JSON.stringify({"10": $scope.ip_range})); diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 8edd37c..e4dfd70 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -24,7 +24,7 @@ mumApp.config(function($routeProvider){ }) .when('/hostpage/:param',{ templateUrl : 'hostpage.html', - //controller : 'mainController' + controller : 'hostPageCtrl' }) .when('/notifications',{ templateUrl : 'notifications.html', diff --git a/views/hostpage.html b/views/hostpage.html index f25aec8..709acea 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -1,6 +1,6 @@ <div class="col-md-offset-2 main"> - <h1 class="page-header">Current state of {{param}} <small>www.example.com</small></h1> + <h1 class="page-header">Current state of {{addr_host}} <small>{{items.hostname}}</small></h1> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_block">Activate/Deactivate</button> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conn">Connection settings</button> <button type="button" class="btn btn-info btn-xs">Launch a new detection</button> @@ -10,60 +10,19 @@ <thead> <tr> - <th class="id" custom-sort order="'addr'" sort="sort">Part </th> - <th class="name" custom-sort order="'name'" sort="sort">Value </th> - <th class="description" custom-sort order="'status'" sort="sort">State </th> - <th class="field3" custom-sort order="'group'" sort="sort">Last check </th> + <th>Part </th> + <th>Value </th> + <th>State </th> + <th>Last check </th> </tr> </thead> + <tbody> - <tr class=success> - <td>HTTP</td> - <td>up</td> - <td>success</td> - <td>12:00</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>SMTP</td> - <td>up</td> - <td>success</td> - <td>12:04</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>CPU</td> - <td>28%</td> - <td>success</td> - <td>14:51</td> - <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> - Configure - </button> - </td> - <td><button type="button" class="btn btn-info btn-xs"> - Check now - </button> - </td> - </tr> - <tr class=success> - <td>Drive</td> - <td>37% used</td> - <td>success</td> - <td>14:51</td> + <tr ng-repeat="item in items.monitoring" class={{item.state}}> + <td>{{item.name}}</td> + <td>{{item.value}}</td> + <td>{{item.state}}</td> + <td>{{item.date}}</td> <td><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conf"> Configure </button> diff --git a/views/index.html b/views/index.html index 36429c1..56cec09 100644 --- a/views/index.html +++ b/views/index.html @@ -25,6 +25,7 @@ <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> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- -- 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 4d7d99f13b57a5e6314bf490c66f1807a8a21d7b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 18:05:59 2015 +0100 hostpage : detection (ràf mettre en forme) --- app/modules/storage_modules/shelve_db.py | 3 +- static/js/controllers/hostPageCtrl.js | 7 ++ views/hostpage.html | 152 +++++++------------------------ 3 files changed, 40 insertions(+), 122 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 19120e3..9cfac2a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -302,7 +302,8 @@ class shelve_db: res['detected'] = {} for mod in self.db['hosts'][addr_host]['detected']: res['detected'][mod] = json.loads(self.db['hosts'][addr_host]['detected'][mod]) - res['custom_info'] = self.db['hosts'][addr_host]['conf']['custom_info'] + res['detected'][mod]['name'] = mod + res['custom_infos'] = self.db['hosts'][addr_host]['conf']['custom_info'] res['interventions'] = self.db['hosts'][addr_host]['conf']['interventions'] except Exception as e: print e.__str__() diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 8d9bd9c..d5ad3ef 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -6,9 +6,16 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, Dat $scope.items = []; + $scope.custom_infos = ''; + $scope.$on("hostInfos", function (event, args) { $scope.$apply(function(){ $scope.items = args; + $scope.custom_infos = args.custom_infos; }); }); + + $scope.toto = function(item){ + return(Object.keys($scope.items.detected)); + } }); \ No newline at end of file diff --git a/views/hostpage.html b/views/hostpage.html index 709acea..aaa6588 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -34,128 +34,38 @@ </tr> </tbody> </table> - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingOne"> - <h4 class="panel-title"> - <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> - Detected configuration - </a> - </h4> - </div> - <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> - <div class="panel-body"> - <p>Date of this detection : Sat, 07 Feb 2015 12:00:00 </p> - <h2>Global informations</h2> - <table class="table table-bordered table-hover"> - <tr> - <td>addr</td> - <td>192.168.74.1</td> - </tr> - <tr> - <td>hostname</td> - <td>www.example.com</td> - </tr> - </table> - <h2>Open ports</h2> - <table class="table table-bordered table-hover"> - <tr> - <th>portid </th> - <th>portname </th> - </tr> - <tr> - <td>22</td> - <td>ssh</td> - </tr> - <tr> - <td>25</td> - <td>smtp</td> - </tr> - <tr> - <td>111</td> - <td>rpcbind</td> - </tr> - <tr> - <td>631</td> - <td>ipp</td> - </tr> - <tr> - <td>8080</td> - <td>http</td> - </tr> - </table> - <h2>Operating system</h2> - <table class="table table-bordered table-hover"> - <tr> - <td>os-name</td> - <td>Debian GNU/Linux</td> - </tr> - <tr> - <td>version</td> - <td>7 (wheezy)</td> - </tr> - <tr> - <td>kernel</td> - <td>Linux version 3.16.0-0.bpo.4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) )</td> - </tr> - </table> - </div> - </div> - </div> - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingTwo"> - <h4 class="panel-title"> - <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> - Custom informations - </a> - </h4> - </div> - <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> - <div class="panel-body"> - <label for="custom_info">Add any information here :</label> - <textarea class="form-control" rows="3" id="custom_info"></textarea> - <button type="button" class="btn btn-info btn-xs">Save</button> - </div> - </div> - </div> - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingThree"> - <h4 class="panel-title"> - <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree"> - Interventions done - </a> - </h4> - </div> - <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree"> - <div class="panel-body"> - <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_interv">Add a new intervention</button> - <table class="table table-bordered table-hover"> - <thead> - <tr> - <th>Date </th> - <th>Person </th> - <th>Details </th> - </tr> - </thead> - <tbody> - <tr> - <td>Mon, 01 Feb 2015 10:01:57</td> - <td>J.C.</td> - <td>Package update.</td> - </tr> - <tr> - <td>Thu, 11 Dec 2014 16:54:17</td> - <td>G.G.</td> - <td>Database backup.</td> - </tr> - </tbody> - </table> - </div> - </div> - </div> - </div> + <h2>Detected Configuration</h2> + <div ng-repeat="mod in items.detected"> + <h3>{{mod.name}}</h3> + {{mod}} + + </div> + + + <h2>Custom informations</h2> + <label for="custom_info">Add any information here :</label> + <textarea class="form-control" rows="3" id="custom_info" ng-model="custom_infos"></textarea> + <button type="button" class="btn btn-info btn-xs">Save</button> + + <h2>Interventions done</h2> + <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_interv">Add a new intervention</button> + <table class="table table-bordered table-hover"> + <thead> + <tr> + <th>Date </th> + <th>Person </th> + <th>Details </th> + </tr> + </thead> + <tbody> + <tr ng-repeat="interv in items.interventions"> + <td>{{interv.date}}</td> + <td>{{interv.person}}</td> + <td>{{interv.details}}</td> + </tr> + </tbody> + </table> - </div> <div class="modal fade" id="modal_conf" tabindex="-1" role="dialog" aria-labelledby="modal_conf_label" aria-hidden="true"> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm