Example #1
0
 def socket_remote_access_connection_handler(self, conn, s_key):
     import logger
     import cryptographer as cr
     import main
     loggerloc = "File: main.py | Class: Handler | Function: socket_remote_access_connection_handler | "
     logger.write("i", loggerloc+"Started new connection handler!")
     logger.write("i", loggerloc+"Waiting for client to authenticate!")
     authenticated = False
     text = "[send];[Please authenticate with username:password !];[info]"
     text = cr.encrypt(s_key, text)
     conn.send(text)
     while authenticated is False:
         edata = conn.recv(15360)
         if edata is "123":
             authenticated = True
     while True:
         edata = conn.recv(15360)
         logger.write("i", loggerloc+"Received data! Decrypting it! Data: "+str(edata))
         try:
             ddata = cr.decrypt(s_key, edata)
         except:
             logger.write("e", loggerloc+"Could not decrypt data: "+str(edata))
             conn.send("[send];[Server was not able to decrypt sent data!];[error]")
         logger.write("i", loggerloc+"Handing over decrypted data to socket_remote_access_command_handler! Data: "+str(ddata))
         Handler.socket_remote_access_command_handler(ddata, conn, VarKeeper.s_key)
def listener():
    while True:
        edata = socket.recv(15360)
        print "Edata: "+str(edata)
        if edata is not None:
            ddata = cr.decrypt(s_key, edata)
            print "Got: "+ddata
            string = ddata.split(";")
            action = string[0]
            message = string[1]
            state = string[2]

            action = action.strip("[")
            action = action.strip("]")
            message = message.strip("[")
            message = message.strip("]")
            state = state.strip("[")
            state = state.strip("]")

            print "Message: "+message
            print "State: "+state
            print "Action: "+action

            if action is "recv":
                sendlock = True
            if action is "send":
                sendlock = False
            if action is not "recv" and action is not "send":
                CSPrint("error", "Received corrupted data! Data: "+str(ddata))
            else:
                if message is "":
                    CSPrint("error", "Received corrupted data! Data: "+str(ddata))
                else:
                    if state is "":
                        CSPrint("", message)
                    if state is "ok":
                        CSPrint("ok", message)
                    if state is "error":
                        CSPrint("error", message)
                    if state is "warning":
                        CSPrint("warning", message)
                    if state is "info":
                        CSPrint("info", message)
                    if state is "debug":
                        CSPrint("debug", message)
                    if state is "sys":
                        CSPrint("sys", message)