Esempio n. 1
0
def handle(conn, addr, currentUser, server, command):
    try:
        target = command[1]
        pmData = command[2:]
        for k, v in server.users.items():
            if target == v.username:
                currentDT = datetime.datetime.now()
                dt = str(currentDT.strftime("%d-%m-%Y %H:%M:%S"))
                metadata = [
                    "[PM] " + currentUser.username,
                    ColorHash(currentUser.username).hex, dt
                ]

                sendMessage(currentUser.conn,
                            currentUser.secret,
                            "outboundMessage",
                            " ".join(pmData),
                            metadata=metadata)
                sendMessage(v.conn,
                            v.secret,
                            "outboundMessage",
                            " ".join(pmData),
                            metadata=metadata)

                if config.GetSetting("storePmlogs", "Logging") == "True":
                    dbLogger.logPM(server, currentUser, v, " ".join(pmData))
                return True
        return False
    except IndexError:
        return False
Esempio n. 2
0
 def CheckBlacklist(self, message):
     if config.GetSetting("useBlacklist", "Blacklist") == "False":
         return True
     messageSplit = message.split()
     for word in messageSplit:
         if word.lower() in self.blacklist:
             return False
     return True
Esempio n. 3
0
def parse(conn, addr, currentUser, server, data):
    splitCommand = data["data"].split()
    if server.IsValidCommand(splitCommand[0][1:]):
        if server.CanUseCommand(currentUser, splitCommand[0][1:]):
            logger.info("Client " + str(currentUser.addr) + " ran command " +
                        splitCommand[0][1:])
            #exec("from modules.commands.{0} import handle as {1}Handle".format(splitCommand[0][1:],splitCommand[0][1:]))
            #exec("{0}Handle(conn, addr, currentUser, server, splitCommand)".format(splitCommand[0][1:]))
            result = importedCommands[splitCommand[0][1:]](conn, addr,
                                                           currentUser, server,
                                                           splitCommand)
            if result == None:
                result = True
            if config.GetSetting("storeCommandlogs", "Logging") == "True":
                if config.GetSetting("logFailedCommands",
                                     "Logging") == "False" and result == False:
                    pass
                else:
                    try:
                        userObj = server.GetUserFromName(splitCommand[1])
                    except IndexError:
                        userObj = None
                    if splitCommand[0][1:] == "pm":
                        dbLogger.logCommand(server, currentUser, userObj,
                                            " ".join(splitCommand[:2]), result)
                    else:
                        dbLogger.logCommand(server, currentUser, userObj,
                                            data["data"], result)
        else:
            currentDT = datetime.datetime.now()
            dt = str(currentDT.strftime("%d-%m-%Y %H:%M:%S"))
            metadata = ["Server", "#0000FF", dt]
            sendMessage(currentUser.conn,
                        currentUser.secret,
                        "outboundMessage",
                        "You do not have permission to perform this command",
                        metadata=metadata)
    else:
        pass
Esempio n. 4
0
        except ConnectionResetError:
            logger.error("Received illegal disconnect from client " + str(addr))
            disconnect.handle(conn, addr, currentUser, server, data)
            currentUser.connectionValid = False
        except ConnectionAbortedError as e:
            if currentUser.connectionValid == False:
                pass
            else:
                logger.error(e)
    else:
        logger.warning("Client " + str(addr) + " failed handshake");
        sendMessage(conn, userSecret, "CRDenied", connInvalidReason)
        conn.close()

    conn.close()

name = config.GetSetting("name", "Server")
channels = config.GetSetting("channels", "Server")
password = config.GetSetting("password", "Server")
port = config.GetSetting("port", "Server")
clientnums = config.GetSetting("clientnum", "Server")
motd = config.GetSetting("motd", "Server")
compatibleClientVers = config.GetSetting("compatibleClientVers", "Server")
strictBanning = config.GetSetting("strictBanning", "Server")
logger.info("Config loaded")

server = echo.Echo(name, "127.0.0.1", port, password, channels, motd, clientnums, compatibleClientVers, strictBanning)
server.initDB()
server.StartServer(ClientConnectionThread)

Esempio n. 5
0
def handle(conn, addr, currentUser, server, data):
    if data["data"][0] == "/":  # Command
        commandParser.parse(conn, addr, currentUser, server, data)
    elif currentUser.channel == None:
        pass
    elif currentUser.isMuted == True:
        currentDT = datetime.datetime.now()
        dt = str(currentDT.strftime("%d-%m-%Y %H:%M:%S"))
        metadata = ["Server", "#0000FF", dt]

        sendMessage(currentUser.conn,
                    currentUser.secret,
                    "outboundMessage",
                    "You are muted",
                    metadata=metadata)
    else:  # Message
        if server.CheckBlacklist(data["data"]):
            mChannel = currentUser.channel
            channelUsers = server.channels[mChannel]
            colour = ColorHash(currentUser.username)
            currentDT = datetime.datetime.now()
            dt = str(currentDT.strftime("%d-%m-%Y %H:%M:%S"))
            metadata = [currentUser.username, colour.hex, dt]

            for eID in channelUsers:
                sendMessage(server.users[eID].conn,
                            server.users[eID].secret,
                            "outboundMessage",
                            data["data"],
                            metadata=metadata)

            dbLogger.logChatHistory(server, currentUser, data["data"],
                                    colour.hex)

            if config.GetSetting("storeChatlogs", "Logging") == "True":
                dbLogger.logMessage(server, currentUser, data["data"])
        else:
            if config.GetSetting("kickOnUse", "Blacklist") == "True":
                sendMessage(currentUser.conn,
                            currentUser.secret,
                            "connectionTerminated",
                            config.GetSetting("kickReason", "Blacklist"),
                            subtype="kick")
                del server.users[currentUser.eID]
                if currentUser.channel != None:
                    server.channels[currentUser.channel].remove(
                        currentUser.eID)

                    channelUsers = json.dumps(
                        server.GetChannelUsers(currentUser.channel))

                    for eID in server.channels[currentUser.channel]:
                        sendMessage(server.users[eID].conn,
                                    server.users[eID].secret, "channelUpdate",
                                    channelUsers)

                currentUser.connectionValid = False
                currentUser.conn.close()

                logger.info("Client " + str(v.addr) +
                            " was kicked from the server")
            else:
                server.ServerMessage(
                    currentUser,
                    "You used a word on the blacklist and your message was not sent."
                )