From 9afc1920fd5234bb8a19a67494dd2316585e021b Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Wed, 16 Dec 2020 21:16:50 -0300 Subject: Initial protocol processing system --- server.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index af694d7..c50e00f 100755 --- a/server.py +++ b/server.py @@ -1,17 +1,17 @@ #!/usr/bin/python3 ## Global Modules -import threading, time, json#, ssl -#from simple_websocket_server import WebSocketServer, WebSocket +import threading, time, json, syslog +LOG_AUTH=syslog.LOG_AUTH ## Semi-local modules from websock import WebSocketServer, WebSocket -#from endpoint import MainEndpoint -#### Local Modules +## Local Modules from utils import stdout as stdout +from utils import now as now from consts import * -import sql +import sql, protocol ############################################################### # Configuration @@ -37,8 +37,19 @@ 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") + else: + self.send_message(r[1]) + + print("Message sent") #stdout(self.address[0] + u' - %s' % (self.data)) - self.send_message('ACK') + #self.send_message('ACK') def connected(self): global clients @@ -109,13 +120,14 @@ def sendmsg(m, t="raw"): ############################################################### # Begin stuff -stdout("Starting...") +stdout("Starting at: T-%d" % (now())) +syslog.openlog() MainWebsocket() try: - print("Running...") + print("Serving at port %d" % PORT) while True: time.sleep(15) - sendmsg("Hello from SRV") + #sendmsg("PING") except: stdout("Terminating!") -- cgit v1.2.3-70-g09d2