Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2012 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3176646 to your computer and use it in GitHub Desktop.
Save anonymous/3176646 to your computer and use it in GitHub Desktop.
import webserver
def main():
try:
print "se intentara iniciar el webserver!"
webserver.Start()
print "se inicio?"
except KeyboardInterrupt:
print '^C received, cerrando main'
webserver.Close()
if __name__ == '__main__':
main()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Gestion de Entrada y Domotica</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Courier New, Courier, mono;
color: #999999;
}
body {
background-color: #000000;
}
-->
</style></head>
<body>
<table width="100" border="0" align="center">
<tr>
<td>
<p align="center"><strong>Bienvenido</strong></p>
<form name="form1" method="post" action=""><div align="center">
<table width="226" border="0">
<tr>
<td width="89">Usuario:</td>
<td width="682"><input name="user" type="text" id="user"></td>
</tr>
<tr>
<td>Contrase&ntilde;a:</td>
<td><input name="pass" type="password" id="pass"></td>
</tr>
</table>
</div>
<p align="center">
<input type="submit" name="Submit" value="Ingresar">
</p>
</form></td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
import cgi
from SocketServer import ThreadingMixIn
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
#import pri
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
print "Recibido GET de ", self.path
if self.path.endswith(".html"):
if self.path == "/Index.html":
f = open(curdir + sep + "WEB" + sep + self.path)
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
Pagina = (f.read())
self.wfile.write(Pagina)
f.close()
return
except IOError:
self.send_error(666, 'Keep trying Kiddie')
def do_POST(self):
global rootnode
try:
print "Recibido POST de ", self.path
if self.path.endswith(".html"):
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': self.headers['Content-Type'],
})
if self.path == "/Index.html":
print form["user"].value
print form["pass"].value
# acaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
except:
pass
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle requests in a separate thread."""
def Start():
server = ThreadedHTTPServer(('', 80), MyHandler)
print "Servidor Iniciado..."
server.serve_forever()
print "fucking mierda"
def Close():
server = ThreadedHTTPServer(('', 80), MyHandler)
server.socket.close()
print "server cerrado"
if __name__ == '__main__':
Start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment