|
@ -14,7 +14,7 @@ logging.config.fileConfig('pylog.conf') |
|
|
logger = logging.getLogger('meshenger'+'.clientserve') |
|
|
logger = logging.getLogger('meshenger'+'.clientserve') |
|
|
|
|
|
|
|
|
# this variable is set from main, to be called when new messages available |
|
|
# this variable is set from main, to be called when new messages available |
|
|
build_index_callback = None |
|
|
# build_index_callback = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
@ -26,16 +26,7 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
""" |
|
|
""" |
|
|
def do_GET(self): |
|
|
def do_GET(self): |
|
|
|
|
|
|
|
|
if self.path == '/': |
|
|
if self.path == '/index' or self.path.startswith( "/"+self.messageDir ): |
|
|
self.send_response(200) |
|
|
|
|
|
self.send_header('Content-type', 'text/html') |
|
|
|
|
|
self.end_headers() |
|
|
|
|
|
f = os.path.relpath('webapp.html') |
|
|
|
|
|
# f = os.path.join('/root/meshenger/',"webapp.html") |
|
|
|
|
|
with open( f, 'r') as the_file: |
|
|
|
|
|
self.wfile.write(the_file.read()) |
|
|
|
|
|
|
|
|
|
|
|
elif self.path == '/index' or self.path.startswith( "/"+self.messageDir ): |
|
|
|
|
|
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) |
|
|
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) |
|
|
elif self.path == '/log': |
|
|
elif self.path == '/log': |
|
|
self.send_response(200) |
|
|
self.send_response(200) |
|
@ -48,7 +39,7 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
self.send_response(200) #serve the webapp on every url requested |
|
|
self.send_response(200) #serve the webapp on every url requested |
|
|
self.send_header('Content-type', 'text/html') |
|
|
self.send_header('Content-type', 'text/html') |
|
|
self.end_headers() |
|
|
self.end_headers() |
|
|
f = os.path.join( "webapp.html") |
|
|
f = os.path.relpath( 'webapp.html') |
|
|
with open( f, 'r') as the_file: |
|
|
with open( f, 'r') as the_file: |
|
|
self.wfile.write(the_file.read()) |
|
|
self.wfile.write(the_file.read()) |
|
|
|
|
|
|
|
@ -58,7 +49,7 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
""" |
|
|
""" |
|
|
def do_POST(self): |
|
|
def do_POST(self): |
|
|
if self.path == '/send': |
|
|
if self.path == '/send': |
|
|
|
|
|
logger.info('incoming message from client!') |
|
|
length = int(self.headers['Content-Length']) |
|
|
length = int(self.headers['Content-Length']) |
|
|
post_data = urlparse.parse_qs(self.rfile.read(length).decode('utf-8')) |
|
|
post_data = urlparse.parse_qs(self.rfile.read(length).decode('utf-8')) |
|
|
|
|
|
|
|
@ -70,8 +61,12 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
self.wfile.write('message created') |
|
|
self.wfile.write('message created') |
|
|
|
|
|
|
|
|
#let main rebuild message index |
|
|
#let main rebuild message index |
|
|
if build_index_callback: |
|
|
try: |
|
|
build_index_callback() |
|
|
logger.debug('try to call meshenger.build_index: %s', repr(meshenger)) |
|
|
|
|
|
meshenger.build_index() |
|
|
|
|
|
except: |
|
|
|
|
|
logger.error('failed to call meshenger.build_index') |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
def writeMessage(self, time, message): |
|
|
def writeMessage(self, time, message): |
|
|
|
|
|
|
|
@ -84,6 +79,7 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
|
|
|
|
|
|
class ClientServe(): |
|
|
class ClientServe(): |
|
|
def __init__(self, port): |
|
|
def __init__(self, port): |
|
|
|
|
|
logger.info('ClientServe.__init__') |
|
|
server = HTTPServer( ('', port), ClientServeHandler) |
|
|
server = HTTPServer( ('', port), ClientServeHandler) |
|
|
server.serve_forever() |
|
|
server.serve_forever() |
|
|
|
|
|
|
|
|