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 293d414a66bd69593baf4e9d51d6a0ec7c97f181 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Jan 29 15:23:20 2015 +0100 mise en place des websocket jusqu'au traitemenent des erreurs... --- app/app.py | 37 +++++++++++++---- requirements.txt | 2 +- res.xml | 6 +-- static/js/DetectCtrl.js | 44 -------------------- static/js/controllers/detectCtrl.js | 82 +++++++++++++++++++++++++++++++++++++ views/index.html | 4 +- 6 files changed, 118 insertions(+), 57 deletions(-) diff --git a/app/app.py b/app/app.py index 2052de6..01b77e4 100755 --- a/app/app.py +++ b/app/app.py @@ -2,6 +2,10 @@ __author__ = 'aguilbaud' from bottle import * from detection_modules.nmap_detection import check_ip_range, get_current_ip, get_scanned_ip +from bottle_websocket import GeventWebSocketServer +from bottle_websocket import websocket +import json + import threading state = "" @@ -24,16 +28,19 @@ def index(section='home'): def angular(): return template('angular') -@post('/detect/<ip_range>') -def start_first_detection(ip_range): +#@post('/detect/<ip_range>') +def start_first_detection(ip_range, ws): #ip_range = request.forms.get('ip_range') - global state + #global state + req = {} if re.search('^\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?$', ip_range): - state = "Scan de l'adresse : " + #state = "Scan de l'adresse : " t = ThreadDetect(ip_range) t.start() else: - state = "La plage d'IP est mal formatee" + req["error"] = "La plage d'IP est mal formatee" + ws.send(json.dumps(req)) + #state = "La plage d'IP est mal formatee" @error(404) def error404(error): @@ -53,13 +60,29 @@ def getstate(): global state scanned_ip = get_scanned_ip() res = state + get_current_ip() - print scanned_ip if scanned_ip != {}: res += "\n Completed : \n" for ip in scanned_ip: res += ip + ' : ' + scanned_ip[ip] return res + +@get('/websocket', apply=[websocket]) +def echo(ws): + while True: + response = ws.receive() + if response is not None: + msg = json.loads(response) + for title in msg: + if title == "Sending_ip_range": + #print "launching scan for" + msg["Sending_ip_range"] + start_first_detection(msg["Sending_ip_range"], ws) + #if msg is not None: + # ws.send(msg) + #else: + # break + + ''' app = Bottle() @@ -86,4 +109,4 @@ server.serve_forever() if __name__ == '__main__': port = int(os.environ.get('PORT', 1337)) - run(host='0.0.0.0', port=port, debug=True, reloader=True) + run(host='0.0.0.0', port=port, debug=True, reloader=True, server=GeventWebSocketServer) diff --git a/requirements.txt b/requirements.txt index 58a8847..b689fc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ bottle==0.12.7 pysnmp pexpect paramiko -gevent-websocket \ No newline at end of file +bottle-websocket \ No newline at end of file diff --git a/res.xml b/res.xml index 59b7716..d4a0732 100644 --- a/res.xml +++ b/res.xml @@ -1,10 +1,10 @@ <?xml version="1.0"?> <?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?> -<!-- Nmap 6.40 scan initiated Thu Jan 29 10:08:46 2015 as: /usr/bin/nmap -A -oX res.xml 198.116.0.10 --> -<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 198.116.0.10" start="1422522526" startstr="Thu Jan 29 10:08:46 2015" version="6.40" xmloutputversion="1.04"> +<!-- Nmap 6.40 scan initiated Thu Jan 29 12:45:57 2015 as: /usr/bin/nmap -A -oX res.xml 198.116.0.10 --> +<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 198.116.0.10" start="1422531957" startstr="Thu Jan 29 12:45:57 2015" version="6.40" xmloutputversion="1.04"> <scaninfo type="connect" protocol="tcp" numservices="1000" services="1,3-4,6-7,9,13,17,19-26,30,32-33,37,42-43,49,53,70,79-85,88-90,99-100,106,109-111,113,119,125,135,139,143-144,146,161,163,179,199,211-212,222,254-256,259,264,280,301,306,311,340,366,389,406-407,416-417,425,427,443-445,458,464-465,481,497,500,512-515,524,541,543-545,548,554-555,563,587,593,616-617,625,631,636,646,648,666-668,683,687,691,700,705,711,714,720,722,726,749,765,777,783,787,800-801,808,843,873,880,888,898,900-9 [...] <verbose level="0"/> <debugging level="0"/> -<runstats><finished time="1422522530" timestr="Thu Jan 29 10:08:50 2015" elapsed="3.14" summary="Nmap done at Thu Jan 29 10:08:50 2015; 1 IP address (0 hosts up) scanned in 3.14 seconds" exit="success"/><hosts up="0" down="1" total="1"/> +<runstats><finished time="1422531961" timestr="Thu Jan 29 12:46:01 2015" elapsed="3.15" summary="Nmap done at Thu Jan 29 12:46:01 2015; 1 IP address (0 hosts up) scanned in 3.15 seconds" exit="success"/><hosts up="0" down="1" total="1"/> </runstats> </nmaprun> diff --git a/static/js/DetectCtrl.js b/static/js/DetectCtrl.js deleted file mode 100644 index 08c781a..0000000 --- a/static/js/DetectCtrl.js +++ /dev/null @@ -1,44 +0,0 @@ -var app = angular.module("myApp", []); - -/* Contrôleur principal -================================================== */ - -app.controller("MainCtrl", ["$scope", "userService", - function($scope, userService) { - $scope.state = userService.getState(); - } -]); - -/* Un premier service -================================================== */ - -app.service("userService", ["utilsService", "$interval", - function(utilsService, $timeout) { - //Variable privée - var state = { - state: "a", - }; - - //Getter pour la variable state - this.getState = function() { - //Cette méthode fait appel à un autre service - $http.get('/whatstate'). - success(function(data, status, headers, config) { - state = data - }). - error(function(data, status, headers, config) { - // called asynchronously if an error occurs - // or server returns response with an error status. - }); - return state; - }; - - //5 secondes après le chargement de la page, la valeur d'une propriété change dans le service. - //La view est mise à jour automatiquement - $interval(function() { - app.service.getState() - }, 5000); - - - } -]); diff --git a/static/js/controllers/detectCtrl.js b/static/js/controllers/detectCtrl.js new file mode 100644 index 0000000..6ff43a1 --- /dev/null +++ b/static/js/controllers/detectCtrl.js @@ -0,0 +1,82 @@ +var formExample = angular.module('formExample', []); + +formExample.controller('ExampleController', ['$scope', '$http', '$interval', function($scope, $http, $interval) { + $scope.master = {}; + $scope.ip_range = "198.116.0.1-10" // 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 + var ws = new WebSocket("ws://0.0.0.0:1337/websocket"); + + /*ws.onopen = function() { + ws.send("Hello, world"); + };*/ + ws.onmessage = function (evt) { + JSON.parse(evt.data, function (key, value) { + if(key == "state"){ + $scope.$apply(function(){ + $scope.state = value + }); + } + if(key == "error"){ + $scope.$apply(function(){ + $scope.state = "Erreur : " + value + }); + } + }); + + }; + + //lace la detection apres remplissage du champ + $scope.post_val = function(){ + var request = '{"Sending_ip_range" : "' + $scope.ip_range + '"}'; + ws.send(request); + } + + /*$scope.check_state = function(){ + $interval(function() { + $http.get('/getstate'). + success(function(data, status, headers, config) { + $scope.state = data + // when the response is available + }). + error(function(data, status, headers, config) { + alert("Impossible d'acceder à l'état") + // called asynchronously if an error occurs + // or server returns response with an error status. + }); + }, 10000); + }*/ + + }]); + + +/*formExample.service("ipService", ["stateService", "$interval", + function(stateService, $timeout) { + //Variable privée + var current_ip = { + current_ip: "a", + }; + + //Getter pour la variable current_ip + this.get_current_ip = function() { + //Cette méthode fait appel à un autre service + $http.get('/getval'). + success(function(data, status, headers, config) { + current_ip = data + }). + error(function(data, status, headers, config) { + // called asynchronously if an error occurs + // or server returns response with an error status. + }); + return current_ip; + }; + + //5 secondes après le chargement de la page, la valeur d'une propriété change dans le service. + //La view est mise à jour automatiquement + $interval(function() { + formExample.service.get_current_ip() + }, 5000); + + + } +]);*/ diff --git a/views/index.html b/views/index.html index fd52f64..0c276a6 100644 --- a/views/index.html +++ b/views/index.html @@ -11,7 +11,7 @@ <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> <script src="bower_components/angular/angular.js"></script> - <script src="static/js/controllers/script.js"></script> + <script src="static/js/controllers/detectCtrl.js"></script> <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="static/css/main.css" rel="stylesheet" media="screen"> @@ -22,7 +22,7 @@ <form ng_submit="post_val()"> <div ng-show="validated == false" class="ng-hide"> Plage d'IP à scanner (exemple : 198.116.0.1-10) : <input name="ip_range" ng-model="ip_range" /> - <input value="Valider" type="submit" ng-click="validated = true ; check_state()"/> + <input value="Valider" type="submit" ng-click="validated = true"/> </div> <div ng-show="validated == true"> <p>{{state}}</p> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.