diff options
author | Filipp Lepalaan <f@230.to> | 2014-02-13 18:43:39 +0200 |
---|---|---|
committer | Filipp Lepalaan <f@230.to> | 2014-02-13 18:43:39 +0200 |
commit | 4360585272f9c32913bee2b4b203e9588717ddbb (patch) | |
tree | 8b6bcc7ade69673ca4cf3dcf17005a4424398405 | |
parent | de7e367e1c74940317a1188f44c72547f6dec837 (diff) | |
download | intercheck-4360585272f9c32913bee2b4b203e9588717ddbb.tar.gz intercheck-4360585272f9c32913bee2b4b203e9588717ddbb.tar.bz2 intercheck-4360585272f9c32913bee2b4b203e9588717ddbb.zip |
Better?
-rw-r--r-- | app.py | 43 | ||||
-rw-r--r-- | index.html | 63 |
2 files changed, 89 insertions, 17 deletions
@@ -1,5 +1,6 @@ import re import logging +import sqlite3 import subprocess import tornado.ioloop import tornado.web @@ -14,17 +15,49 @@ class MainHandler(tornado.web.RequestHandler): class ScanHandler(tornado.web.RequestHandler): + def initialize(self): + conn = sqlite3.connect(":memory:") + self.cursor = conn.cursor() + self.cursor.execute('CREATE TABLE notes kw text value text') + + def get(self): + commands = ('nmap', 'help', '?', '!',) + + out = {'results': list()} + cmd = self.get_argument('cmd', '') + + if cmd not in commands or cmd == 'help': + out['results'].append({'raw': 'Available commands:'}) + out['results'].append({'raw': '* nmap - scan your IP'}) + out['results'].append({'raw': '* ?<keyword> - query keyword'}) + out['results'].append({'raw': '* !<keyword> definition - learn <keyword>'}) + out['results'].append({'raw': '* !!<keyword> - forget <keyword>'}) + out['results'].append({'raw': '* help - shows this help message'}) + + if cmd == 'nmap': + logging.debug('SCANNING!') + result = subprocess.check_output(['nmap', self.request.remote_ip]) + for r in re.finditer(r'(\d+/[a-z]{3})\s([a-z]+)\s+(.+)', result): + t = r.groups() + out['results'].append({ + 'port': t[0], + 'state': t[1], + 'service': t[2], + 'raw': " ".join(r.groups(0)) + }) + + self.write(out) + + +class HelpHandler(tornado.web.RequestHandler): def get(self): - logging.debug('SCANNING!') - result = subprocess.check_output(['nmap', self.request.remote_ip]) - for r in re.finditer(r'(\d+/[a-z]{3})\s([a-z]+)\s+(.+)', result): - t = r.groups() - self.write({'port': t[0], 'state': t[1], 'service': t[2]}) + out = {'results': list()} application = tornado.web.Application([ (r'/', MainHandler), (r'/scan/', ScanHandler), + (r'/help/', HelpHandler), ]) if __name__ == '__main__': @@ -3,25 +3,64 @@ <head> <title>intercheck 0.001</title> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> - <style type="text/css"> - button { - width: 100px; - height: 50px; - } - </style> <script type="text/javascript"> $(function(){ - $('button').click(function(){ - console.log('SCANNING!!!'); - $.getJSON('/scan/', function(r){ - console.log(r); + $('.prompt').focus(); + $('form').submit(function(e){ + e.preventDefault(); + var args = $('.prompt').val(); + $('.prompt').val(''); + $.getJSON('/scan/', {'cmd': args}, function(r){ + $(r.results).each(function(i, e){ + $('<li/>').text(e.raw).appendTo('.output'); + }); + $('<li/>').addClass('divider').appendTo('.output'); }); }); }); </script> + <style type="text/css"> + body, html, ul { + padding: 0; + margin: 0; + } + body { + background-color: #222; + font: 12pt "Monaco"; + color: #fff; + } + .divider { + border: 1px solid #aaa; + } + .log { + width: 100%; + } + .output { + margin: 5px; + list-style: none; + } + .prompt { + bottom: 0; + height: 30px; + width: 100%; + border: none; + position: fixed; + font: 12pt "Monaco"; + background-color: #fff; + } + .prompt:focus { + outline-width: 0; + } + </style> </head> <body> - <button type="button">Go!</button> - <blockquote id="results"></blockquote> + <div class="wrapper"> + <div class="log"> + <ul class="output"></ul> + </div> + <form method="post" action=""> + <input type="text" class="prompt"></input> + </form> + </div> </body> </html> |