diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-12-18 00:29:57 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-12-18 00:29:57 -0300 |
commit | e1d78e89f4bdac76e9a5bbe43c8dab56fccf3e8b (patch) | |
tree | 852f2bd0671798894419730839b0a648a427a004 /server.py | |
parent | 7f8cfa2e8d1fcd25ae1afce90c8ae5854b2bd62e (diff) | |
download | server-e1d78e89f4bdac76e9a5bbe43c8dab56fccf3e8b.tar.gz server-e1d78e89f4bdac76e9a5bbe43c8dab56fccf3e8b.tar.bz2 server-e1d78e89f4bdac76e9a5bbe43c8dab56fccf3e8b.tar.xz server-e1d78e89f4bdac76e9a5bbe43c8dab56fccf3e8b.zip |
Allow empty commands, and start printing tracebacks if something goes wrong
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) |