Exemplo n.º 1
0
Arquivo: ircd.py Projeto: ojii/txircd
 def load_options(self, options):
     # Populate attributes with options
     for var in default_options.iterkeys():
         setattr(self, var, options[var] if var in options else default_options[var])
     # Unserialize xlines
     for key in self.xlines.iterkeys():
         self.xlines[key] = CaseInsensitiveDictionary()
         xlines = getattr(self, "server_xlines_{}".format(key.lower()), None)
         if not xlines:
             continue
         for user, data in xlines.iteritems():
             self.xlines[key][user] = {
                 "created": datetime.datetime.strptime(data["created"], "%Y-%m-%d %H:%M:%S"),
                 "duration": parse_duration(data["duration"]),
                 "setter": data["setter"],
                 "reason": data["reason"],
             }
     # Create database connection
     if self.db:
         self.db.close()
     if self.db_library:
         self.db = adbapi.ConnectionPool(
             self.db_library,
             host=self.db_host,
             port=self.db_port,
             db=self.db_database,
             user=self.db_username,
             passwd=self.db_password,
             cp_reconnect=True,
         )
Exemplo n.º 2
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "ELINE",
                          ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(
             irc.ERR_NOPRIVILEGES,
             ":Permission denied - You do not have the correct operator privileges"
         )
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE",
                          ":Not enough parameters")
         return {}
     banmask = params[0]
     if banmask in self.ircd.users:
         udata = self.ircd.users[banmask]
         banmask = "{}@{}".format(udata.username, udata.hostname)
     elif "@" not in banmask:
         banmask = "*@{}".format(banmask)
     self.expire_elines()
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE",
                              ":Not enough parameters")
             return {}
         if banmask not in self.exceptList:
             user.sendMessage(
                 "NOTICE",
                 ":*** E:line for {} not found! Check /stats E to view currently set e:lines."
                 .format(banmask))
             return {}
         return {"user": user, "mask": banmask}
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE",
                          ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE",
                              ":Not enough parameters")
             return {}
     if banmask in self.exceptList:
         user.sendMessage(
             "NOTICE",
             ":*** An e:line is already set on {}!  Check /stats E to view currently set e:lines."
             .format(banmask))
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }
Exemplo n.º 3
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "KLINE",
                          ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(
             irc.ERR_NOPRIVILEGES,
             ":Permission denied - You do not have the correct operator privileges"
         )
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE",
                          ":Not enough parameters")
         return {}
     banmask = params[0]
     if banmask in self.ircd.users:
         banmask = "{}@{}".format(user.username, user.hostname)
     elif "@" not in banmask:
         banmask = "*@{}".format(banmask)
     self.expire_klines()
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE",
                              ":Not enough parameters")
             return {}
         if banmask not in self.banList:
             user.sendMessage(
                 "NOTICE",
                 ":*** K:line for {} does not currently exist; check /stats K for a list of active k:lines"
                 .format(banmask))
             return {}
         return {"user": user, "mask": banmask}
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE",
                          ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE",
                              ":Not enough parameters")
             return {}
     if banmask in self.banList:
         user.sendMessage(
             "NOTICE",
             ":*** There's already a k:line set on {}!  Check /stats K for a list of active k:lines."
             .format(banmask))
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }
Exemplo n.º 4
0
 def data_serialize(self):
     expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
     remove = []
     for nick, data in self.whowasCmd.history.iteritems():
         while data and epoch(data[0]["time"]) < expiryTime:
             data.pop(0)
         if not data:
             remove.append(nick)
     for nick in remove:
         del self.whowasCmd.history[nick]
     return [self.whowasCmd.history._data, {}]
Exemplo n.º 5
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "QLINE", ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(irc.ERR_NOPRIVILEGES, ":Permission denied - You do not have the correct operator privileges")
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE", ":Not enough parameters")
         return {}
     self.expire_qlines()
     banmask = params[0]
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE", ":Not enough parameters")
             return {}
         if banmask not in self.banList:
             user.sendMessage("NOTICE", ":*** There is not a q:line set on {}; check /stats Q for a list of existing q:lines".format(banmask))
             return {}
         return {
             "user": user,
             "mask": banmask
         }
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE", ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE", ":Not enough parameters")
             return {}
     if banmask in self.banList:
         user.sendMessage("NOTICE", ":*** Q:line already exists for {}!  Check /stats Q for a list of existing q:lines.".format(params[0]))
         return {}
     bancheck = banmask.replace("*", "")
     if not bancheck or ("*" in banmask and bancheck == "?"):
         user.sendMessage("NOTICE", ":*** That q:line will match all nicks!  Please check your nick mask and try again.")
         return {}
     if not VALID_NICKNAME.match(params[0].replace("*", "").replace("?", "a")):
         user.sendMessage("NOTICE", ":*** That isn't a valid nick mask and won't match any nicks.  Please check your nick mask and try again.")
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }
Exemplo n.º 6
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTYETREGISTERED, "ELINE", ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(
             irc.ERR_NOPRIVILEGES, ":Permission denied - You do not have the correct operator privileges"
         )
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE", ":Not enough parameters")
         return {}
     banmask = params[0]
     if banmask in self.ircd.users:
         udata = self.ircd.users[banmask]
         banmask = "{}@{}".format(udata.username, udata.hostname)
     elif "@" not in banmask:
         banmask = "*@{}".format(banmask)
     self.expire_elines()
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE", ":Not enough parameters")
             return {}
         if banmask not in self.exceptList:
             user.sendMessage(
                 "NOTICE",
                 ":*** E:line for {} not found! Check /stats E to view currently set e:lines.".format(banmask),
             )
             return {}
         return {"user": user, "mask": banmask}
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE", ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ELINE", ":Not enough parameters")
             return {}
     if banmask in self.exceptList:
         user.sendMessage(
             "NOTICE",
             ":*** An e:line is already set on {}!  Check /stats E to view currently set e:lines.".format(banmask),
         )
         return {}
     return {"user": user, "mask": banmask, "duration": parse_duration(params[1]), "reason": " ".join(params[2:])}
Exemplo n.º 7
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "KLINE", ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(irc.ERR_NOPRIVILEGES, ":Permission denied - You do not have the correct operator privileges")
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE", ":Not enough parameters")
         return {}
     banmask = params[0]
     if banmask in self.ircd.users:
         banmask = "{}@{}".format(user.username, user.hostname)
     elif "@" not in banmask:
         banmask = "*@{}".format(banmask)
     self.expire_klines()
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE", ":Not enough parameters")
             return {}
         if banmask not in self.banList:
             user.sendMessage("NOTICE", ":*** K:line for {} does not currently exist; check /stats K for a list of active k:lines".format(banmask))
             return {}
         return {
             "user": user,
             "mask": banmask
         }
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE", ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "KLINE", ":Not enough parameters")
             return {}
     if banmask in self.banList:
         user.sendMessage("NOTICE", ":*** There's already a k:line set on {}!  Check /stats K for a list of active k:lines.".format(banmask))
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }
Exemplo n.º 8
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "ZLINE", ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(irc.ERR_NOPRIVILEGES, ":Permission denied - You do not have the correct operator privileges")
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ZLINE", ":Not enough parameters")
         return {}
     banmask = params[0]
     if banmask in self.ircd.users:
         banmask = self.ircd.users[banmask].ip
     self.expire_zlines()
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ZLINE", ":Not enough parameters")
             return {}
         if banmask not in self.banList:
             user.sendMessage("NOTICE", ":*** Z:line on {} not found!  Check /stats Z for a list of active z:lines.".format(banmask))
             return {}
         return {
             "user": user,
             "mask": banmask
         }
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ZLINE", ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "ZLINE", ":Not enough parameters")
             return {}
     if banmask in self.banList:
         user.sendMessage("NOTICE", ":*** There is already a z:line set on {}!  Check /stats Z for a list of active z:lines.".format(banmask))
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }
Exemplo n.º 9
0
 def addToWhowas(self, user, reason):
     if user.registered > 0:
         return # don't process users who haven't yet registered
     newEntry = {
         "nick": user.nickname,
         "ident": user.username,
         "host": user.hostname,
         "gecos": user.realname,
         "server": user.server,
         "time": now()
     }
     if user.nickname in self.history:
         self.history[user.nickname].append(newEntry)
         self.history[user.nickname] = self.history[user.nickname][-self.ircd.servconfig["client_whowas_limit"]:]
         expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
         while epoch(self.history[user.nickname][0]["time"]) < expiryTime:
             self.history[user.nickname].pop(0)
     else:
         self.history[user.nickname] = [newEntry]
Exemplo n.º 10
0
 def addToWhowas(self, user, reason):
     if user.registered > 0:
         return # don't process users who haven't yet registered
     newEntry = {
         "nick": user.nickname,
         "ident": user.username,
         "host": user.hostname,
         "realhost": user.realhost,
         "ip": user.ip,
         "gecos": user.realname,
         "server": user.server,
         "time": now()
     }
     if user.nickname in self.history:
         self.history[user.nickname].append(newEntry)
         self.history[user.nickname] = self.history[user.nickname][-self.ircd.servconfig["client_whowas_limit"]:]
         expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
         while epoch(self.history[user.nickname][0]["time"]) < expiryTime:
             self.history[user.nickname].pop(0)
     else:
         self.history[user.nickname] = [newEntry]
Exemplo n.º 11
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "QLINE",
                          ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(
             irc.ERR_NOPRIVILEGES,
             ":Permission denied - You do not have the correct operator privileges"
         )
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE",
                          ":Not enough parameters")
         return {}
     self.expire_qlines()
     banmask = params[0]
     if banmask[0] == "-":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE",
                              ":Not enough parameters")
             return {}
         if banmask not in self.banList:
             user.sendMessage(
                 "NOTICE",
                 ":*** There is not a q:line set on {}; check /stats Q for a list of existing q:lines"
                 .format(banmask))
             return {}
         return {"user": user, "mask": banmask}
     if len(params) < 3 or not params[2]:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE",
                          ":Not enough parameters")
         return {}
     if banmask[0] == "+":
         banmask = banmask[1:]
         if not banmask:
             user.sendMessage(irc.ERR_NEEDMOREPARAMS, "QLINE",
                              ":Not enough parameters")
             return {}
     if banmask in self.banList:
         user.sendMessage(
             "NOTICE",
             ":*** Q:line already exists for {}!  Check /stats Q for a list of existing q:lines."
             .format(params[0]))
         return {}
     bancheck = banmask.replace("*", "")
     if not bancheck or ("*" in banmask and bancheck == "?"):
         user.sendMessage(
             "NOTICE",
             ":*** That q:line will match all nicks!  Please check your nick mask and try again."
         )
         return {}
     if not VALID_NICKNAME.match(params[0].replace("*", "").replace(
             "?", "a")):
         user.sendMessage(
             "NOTICE",
             ":*** That isn't a valid nick mask and won't match any nicks.  Please check your nick mask and try again."
         )
         return {}
     return {
         "user": user,
         "mask": banmask,
         "duration": parse_duration(params[1]),
         "reason": " ".join(params[2:])
     }