diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-12-16 21:16:50 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-12-16 21:16:50 -0300 |
commit | 9afc1920fd5234bb8a19a67494dd2316585e021b (patch) | |
tree | 6a44a89e56daf2d191078806c73f5f0d62700afb /server.py | |
parent | fdbbdcf40f300e38a08bb3b6a4bc809156cb52aa (diff) | |
download | server-9afc1920fd5234bb8a19a67494dd2316585e021b.tar.gz server-9afc1920fd5234bb8a19a67494dd2316585e021b.tar.bz2 server-9afc1920fd5234bb8a19a67494dd2316585e021b.tar.xz server-9afc1920fd5234bb8a19a67494dd2316585e021b.zip |
Initial protocol processing system
Diffstat (limited to 'server.py')
-rwxr-xr-x | server.py | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -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!") |