meshenger/meshenger_nodeserve.py

66 lines
1.4 KiB
Python
Raw Normal View History

2014-04-28 22:44:59 +02:00
#!/usr/bin/python
import logging
import cgi
import os
import socket
2014-05-28 01:36:32 +02:00
import BaseHTTPServer
2014-04-28 22:44:59 +02:00
import SimpleHTTPServer
import urlparse
import logging
import logging.config
logging.config.fileConfig('pylog.conf')
logger = logging.getLogger('meshenger'+'.nodeserve')
2014-04-28 22:44:59 +02:00
2014-05-28 01:36:32 +02:00
#GOTTMITTUNS
def _bare_address_string(self):
host, port = self.client_address[:2]
return '%s' % host
BaseHTTPServer.BaseHTTPRequestHandler.address_string = \
_bare_address_string
#END
2014-04-28 22:44:59 +02:00
class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
messageDir = "/msg"
def do_GET(self):
2014-11-06 21:52:50 +01:00
"""
Serve index and messages
"""
2014-04-28 22:44:59 +02:00
if self.path == '/':
self.path = "/index"
if self.path == '/index' or self.path.startswith( self.messageDir ):
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
if self.path == '/alias' or self.path.startswith( self.messageDir ):
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
2014-04-28 22:44:59 +02:00
else:
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('404 - Not Found')
2014-05-28 01:36:32 +02:00
class HTTPServerV6(BaseHTTPServer.HTTPServer):
2014-04-28 22:44:59 +02:00
address_family = socket.AF_INET6
class NodeServe():
def __init__(self, port):
2014-11-06 21:52:50 +01:00
logger.info('NodeServe.__init__')
2014-04-28 22:44:59 +02:00
server = HTTPServerV6(('::', port), NodeServeHandler)
server.serve_forever()
def main():
nodeServe = NodeServe(13338)
if __name__ == '__main__':
main()