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 5cf361fc0f680ada9c4a246df27f68c44a86a0cb Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Jan 28 15:10:38 2015 +0100 index.html dynamique avec angular. mais serveur avec thread et le client demande regulierement l'etat du serveur --- app/app.py | 53 +++++++++++++++++++---- app/detection_modules/nmap_detection.py | 4 ++ requirements.txt | 3 +- res.xml | 74 ++------------------------------- static/js/controllers/script.js | 26 ++++++++++-- views/index.html | 6 +-- 6 files changed, 78 insertions(+), 88 deletions(-) diff --git a/app/app.py b/app/app.py index 8ee89da..71aac06 100755 --- a/app/app.py +++ b/app/app.py @@ -2,9 +2,21 @@ __author__ = 'aguilbaud' from bottle import * from detection_modules.nmap_detection import check_ip_range, get_current_ip +import threading state = "" + +class ThreadDetect(threading.Thread): + def __init__(self, ip_range): + print 'init' + threading.Thread.__init__(self) + self.ip_range = ip_range + def run(self): + global state + check_ip_range(self.ip_range) + state = "Scan termine" + @route('/') def index(section='home'): return template('index') @@ -16,15 +28,14 @@ def angular(): @post('/detect/<ip_range>') def start_first_detection(ip_range): #ip_range = request.forms.get('ip_range') + global state print ip_range - ''' 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 = "Scanning" - check_ip_range(ip_range) + state = "Scan de l'adresse : " + t = ThreadDetect(ip_range) + t.start() else: - return '<p>La plage d\'IP est mal formatee</p>' - ''' - + state = "La plage d'IP est mal formatee" @error(404) def error404(error): @@ -39,9 +50,33 @@ def static(filepath): def bower_files(filepath): return static_file(filepath, root='bower_components') -@get('/getval') -def getval(): - return get_current_ip() +@get('/getstate') +def getstate(): + global state + return state + get_current_ip() + +''' +app = Bottle() + +@app.route('/websocket') +def handle_websocket(): + wsock = request.environ.get('wsgi.websocket') + if not wsock: + abort(400, 'Expected WebSocket request.') + while True: + try: + message = wsock.receive() + print message + wsock.send("Your message was: %r" % message) + except WebSocketError: + break +from gevent.pywsgi import WSGIServer +from geventwebsocket import WebSocketError +from geventwebsocket.handler import WebSocketHandler +server = WSGIServer(("0.0.0.0", 8181), app, + handler_class=WebSocketHandler) +server.serve_forever() +''' if __name__ == '__main__': diff --git a/app/detection_modules/nmap_detection.py b/app/detection_modules/nmap_detection.py index 0722001..b1d43cc 100644 --- a/app/detection_modules/nmap_detection.py +++ b/app/detection_modules/nmap_detection.py @@ -68,6 +68,7 @@ def check_order_and_under_255(tab_val): # lance la detection a l'aide de nmap sur l'ip representee par les 4 octets passes en parametres def launch_detection(b1, b2, b3, b4): + global current_ip ip = str(b1) + '.' + str(b2) + '.' + str(b3) + '.' + str(b4) current_ip = ip child = pexpect.spawn('nmap', ['-A', ip, '-oX', 'res.xml']) @@ -82,12 +83,15 @@ def launch_detection(b1, b2, b3, b4): parse_res() except pexpect.TIMEOUT: res += ' TIMEOUT' + current_ip = "" return res def get_current_ip(): + global current_ip return current_ip + # parse le resultat xml de nmap pour ne conserver que les valeurs interssantes # envoie directement le resultat sur le service ElasticSearch def parse_res(): diff --git a/requirements.txt b/requirements.txt index bd14cb8..58a8847 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ bottle==0.12.7 pysnmp pexpect -paramiko \ No newline at end of file +paramiko +gevent-websocket \ No newline at end of file diff --git a/res.xml b/res.xml index cbbe419..f27de2a 100644 --- a/res.xml +++ b/res.xml @@ -1,78 +1,10 @@ <?xml version="1.0"?> <?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?> -<!-- Nmap 6.40 scan initiated Mon Jan 26 14:06:22 2015 as: /usr/bin/nmap -A -oX res.xml 127.0.0.1 --> -<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 127.0.0.1" start="1422277582" startstr="Mon Jan 26 14:06:22 2015" version="6.40" xmloutputversion="1.04"> +<!-- Nmap 6.40 scan initiated Wed Jan 28 14:53:28 2015 as: /usr/bin/nmap -A -oX res.xml 109.190.17.195 --> +<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 109.190.17.195" start="1422453208" startstr="Wed Jan 28 14:53:28 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"/> -<host starttime="1422277583" endtime="1422277589"><status state="up" reason="conn-refused" reason_ttl="0"/> -<address addr="127.0.0.1" addrtype="ipv4"/> -<hostnames> -<hostname name="localhost" type="PTR"/> -</hostnames> -<ports><extraports state="closed" count="995"> -<extrareasons reason="conn-refused" count="995"/> -</extraports> -<port protocol="tcp" portid="22"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="ssh" product="OpenSSH" version="6.6.1p1 Debian 4~bpo70+1" extrainfo="protocol 2.0" ostype="Linux" method="probed" conf="10"><cpe>cpe:/a:openbsd:openssh:6.6.1p1</cpe><cpe>cpe:/o:linux:linux_kernel</cpe></service><script id="ssh-hostkey" output="1024 91:dc:b9:10:b4:5c:21:bd:9d:53:53:03:58:96:18:1f (DSA) 2048 11:aa:0d:50:8d:a4:f2:43:7e:86:b2:02:e9:29:ca:e2 (RSA) 256 cf:22:d5:4b:e4:48 [...] -<elem key="fingerprint">91dcb910b45c21bd9d5353035896181f</elem> -<elem key="type">ssh-dss</elem> -<elem key="key">AAAAB3NzaC1kc3MAAACBANd0aGmv9wNOWbaMqW5VbHc5ybC7FSyg+8feAPUAkwOyLs1lw2X/VUbstHVjCDbSLfChtrh5apIq+z+zbBZS90qJSmjkS0ENKRV5pTG5op4iMDHEdKtxvoEo+6cUo4LiTgdD/TG7ckuVbu98oJDG0Ug+2Y6UNcJ2JdFnhiOxHOJhAAAAFQDE8Uvj6YjrnI+hT/fwHR9m1GW2pQAAAIAa6juP1IrZJYy1dzumFlGh3IL2FhPtR+jalO9Nd5Fbl5vFL/Qvn7AH87jTLUEUFEXyxwEDXD09rDhgXRpqOWPY68EOax4ElCvP3VcMEomrTwgTyxqTfkYiPfuEsrRYAlA+nTgK0ydXx4mgLfk0igHkNR0Ec8Njq7TVpV6ahgT19wAAAIA0FxIqx9VTOLQ1bmBDGlcdcAwLfDhWYqJJBrVtClf2s1kqcv7K4u6atbeOo/lCHHBMYS0h [...] -<elem key="bits">1024</elem> -</table> -<table> -<elem key="fingerprint">11aa0d508da4f2437e86b202e929cae2</elem> -<elem key="type">ssh-rsa</elem> -<elem key="key">AAAAB3NzaC1yc2EAAAADAQABAAABAQDcc3P+5Izgre8YSBrDtgkZyqxrH3CkyELs/xyjIVvGEhPD4VPd5Gx7rOTeAHnyDzJ0ca+YGnJjUISh+FDWxrzk5QmO1nVNEG+bRaZcdok/kzgJnj58IfEIeVB/NCPQJkOPW7asD5/SowBVRynnViPd42OhQVeyfMkhI1PMf8QZRSteGOyX7XrMgCEkFbmlF3jZTruYrAp+TjItQv0p+v16fL69uBHCSh/j+aVm00l5S29sNmMex+NGgfFGDWBouz3y5SE3KyKz9ECKw0MH2M8tCv/Tj6PlS8kuAulsJLQQ3wO0u9o/UaLbKuLBwz7dBHPNrD1XY8zyIco8u4QdubqJ</elem> -<elem key="bits">2048</elem> -</table> -<table> -<elem key="fingerprint">cf22d54be448cae1585dffebc266ff18</elem> -<elem key="type">ecdsa-sha2-nistp256</elem> -<elem key="key">AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI0QKwQluKYrYw2Heu9AYeeSLXi9fBZZvk/acMftAaFwEoUZhgqEPQNyQODw1K+WsbtY4c4ZAS9l34hqqrX0ZTg=</elem> -<elem key="bits">256</elem> -</table> -</script></port> -<port protocol="tcp" portid="25"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="smtp" product="Exim smtpd" version="4.80" hostname="bou.codelutin.home" method="probed" conf="10"><cpe>cpe:/a:exim:exim:4.80</cpe></service><script id="smtp-commands" output="bou.codelutin.home Hello localhost [127.0.0.1], SIZE 52428800, 8BITMIME, PIPELINING, HELP, Commands supported: AUTH HELO EHLO MAIL RCPT DATA NOOP QUIT RSET HELP "/></port> -<port protocol="tcp" portid="111"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="rpcbind" version="2-4" extrainfo="RPC #100000" method="probed" conf="10"/><script id="rpcinfo" output=" program version port/proto service 100000 2,3,4 111/tcp rpcbind 100000 2,3,4 111/udp rpcbind 100024 1 43928/tcp status 100024 1 60874/udp status "><table key="100000"> -<table key="udp"> -<elem key="port">111</elem> -<table key="version"> -<elem>2</elem> -<elem>3</elem> -<elem>4</elem> -</table> -</table> -<table key="tcp"> -<elem key="port">111</elem> -<table key="version"> -<elem>2</elem> -<elem>3</elem> -<elem>4</elem> -</table> -</table> -</table> -<table key="100024"> -<table key="tcp"> -<elem key="port">43928</elem> -<table key="version"> -<elem>1</elem> -</table> -</table> -<table key="udp"> -<elem key="port">60874</elem> -<table key="version"> -<elem>1</elem> -</table> -</table> -</table> -</script></port> -<port protocol="tcp" portid="631"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="ipp" product="CUPS" version="1.5" method="probed" conf="10"/><script id="http-methods" output="Potentially risky methods: PUT See http://nmap.org/nsedoc/scripts/http-methods.html"/><script id="http-robots.txt" output="1 disallowed entry /"/><script id="http-title" output="Home - CUPS 1.5.3"><elem key="title">Home - CUPS 1.5.3</elem> -</script></port> -<port protocol="tcp" portid="8080"><state state="open" reason="syn-ack" reason_ttl="0"/><service name="http" product="Apache Tomcat/Coyote JSP engine" version="1.1" method="probed" conf="10"/><script id="http-methods" output="Potentially risky methods: PUT DELETE See http://nmap.org/nsedoc/scripts/http-methods.html"/><script id="http-open-proxy" output="Proxy might be redirecting requests"/><script id="http-title" output="Apache Tomcat"><elem key="title">Apache Tomcat</elem> -</script></port> -</ports> -<times srtt="211" rttvar="59" to="100000"/> -</host> -<runstats><finished time="1422277589" timestr="Mon Jan 26 14:06:29 2015" elapsed="6.50" summary="Nmap done at Mon Jan 26 14:06:29 2015; 1 IP address (1 host up) scanned in 6.50 seconds" exit="success"/><hosts up="1" down="0" total="1"/> +<runstats><finished time="1422453211" timestr="Wed Jan 28 14:53:31 2015" elapsed="3.15" summary="Nmap done at Wed Jan 28 14:53:31 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/controllers/script.js b/static/js/controllers/script.js index 95ff8cd..41a8b90 100644 --- a/static/js/controllers/script.js +++ b/static/js/controllers/script.js @@ -1,10 +1,12 @@ var formExample = angular.module('formExample', []); -formExample.controller('ExampleController', ['$scope', '$http', function($scope, $http) { +formExample.controller('ExampleController', ['$scope', '$http', '$interval', function($scope, $http, $interval) { $scope.master = {}; - $scope.ip_range = "198.116.0.1-10" - $scope.ip = "v"; - $scope.validated = false; + $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 + + //lace la detection apres remplissage du champ $scope.post_val = function(){ $http.post('/detect/' + $scope.ip_range). success(function(data, status, headers, config) { @@ -16,6 +18,22 @@ formExample.controller('ExampleController', ['$scope', '$http', function($scope, // or server returns response with an error status. }); } + + $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. + }); + }, 1000); + } + }]); diff --git a/views/index.html b/views/index.html index 223c04b..fd52f64 100644 --- a/views/index.html +++ b/views/index.html @@ -22,13 +22,13 @@ <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"/> + <input value="Valider" type="submit" ng-click="validated = true ; check_state()"/> </div> <div ng-show="validated == true"> - <p>Lancé</p> + <p>{{state}}</p> </div> </form> -{{validated}} + </div> </body> </html> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.