diff options
Diffstat (limited to 'server.py')
-rwxr-xr-x | server.py | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -10,7 +10,7 @@ from websock import WebSocketServer, WebSocket ## Local Modules from utils import stdout, now from consts import * -import sql, protocol, security +import sql, protocol, security, traceback ############################################################### # Configuration @@ -36,16 +36,20 @@ class WebSocketConn(WebSocket): If the frame is Binary then self.data is a bytearray object. """ print("Message received from %s - %s" % (self.address[0], self.data)) - r=protocol.parse(self.data) - print("Status: %s" % str(r[0])) - print("Reply: %s" % r[1]) - if r[0] is not True: - stdout("%s - %s" % (self.address[0], r[1])) - syslog.syslog(LOG_AUTH, "%s - %s" % (self.address[0], r[1])) - self.send_message("NACK\n") - security.score(self, 5) - else: - self.send_message(r[1]+"\n") + try: + r=protocol.parse(self.data) + print("Status: %s" % str(r[0])) + print("Reply: %s" % r[1]) + if r[0] is not True: + stdout("%s - %s" % (self.address[0], r[1])) + syslog.syslog(LOG_AUTH, "%s - %s" % (self.address[0], r[1])) + self.send_message("NACK\n") + security.score(self, 5) + else: + self.send_message(r[1]+"\n") + except: + traceback.print_exc() + self.send_message("ERROR\n") print("Message sent") #stdout(self.address[0] + u' - %s' % (self.data)) @@ -135,6 +139,10 @@ try: print("Serving at port %d" % PORT) while True: command=str(input("> ")) + # No command inserted? Do nothing + if command == "": + continue + # We have a command, prepare it for processing stdout("CONSOLE: %s" % command) cmd=command.split(' ')[0].lower() com=" ".join(command.split(' ')[1:]) @@ -151,7 +159,7 @@ try: stdout("ERROR: Unknown command.") except: stdout("Abrupt error: Terminating!") - #raise + traceback.print_exc() # TODO: Cleanup here time.sleep(0.5) |