def __init__(self, config, net=None): self._conf = None if net is not None and net.find("acl"): conffile = net.find("acl").get("file", None) elif config.find("acl") is not None: conffile = config.find("acl").get("file", None) else: log.debug("No ACL file to load") return if conffile is None: raise ConfigError("<acl> tag is missing the file attribute!"); if not os.path.isabs(conffile): confdir = config.get('config', None) if not confdir: log.error("Unable to resolve relative path to ACL") return confdir = os.path.dirname(confdir) conffile = os.path.join(confdir, conffile) if not os.access(conffile, os.R_OK): raise ConfigError("Cannot read ACL file %s" % conffile); log.debug("Loading ACL file %s" % conffile) self._conf = ElementTree.parse(conffile)
def _add_command(self, cmd, func): assert callable(func) if cmd in self.commands: log.error("Redefining command: %s" % cmd) else: log.debug("Registering command: %s" % cmd) self.commands[cmd] = func
def __init__(self, config, net=None): self._conf = None if net is not None and net.find("acl"): conffile = net.find("acl").get("file", None) elif config.find("acl") is not None: conffile = config.find("acl").get("file", None) else: log.debug("No ACL file to load") return if conffile is None: raise ConfigError("<acl> tag is missing the file attribute!") if not os.path.isabs(conffile): confdir = config.get('config', None) if not confdir: log.error("Unable to resolve relative path to ACL") return confdir = os.path.dirname(confdir) conffile = os.path.join(confdir, conffile) if not os.access(conffile, os.R_OK): raise ConfigError("Cannot read ACL file %s" % conffile) log.debug("Loading ACL file %s" % conffile) self._conf = ElementTree.parse(conffile)
def hook(self, conn, event): log.trace("event: %s" % str(event)) for func in self.hooks[event['type']]: try: d = func(conn, event.copy()) except: log.error(failure.Failure()) else: self._add_pending(d)
def command(self, conn, event): log.trace("command: %s: %s" % (event['command'], event['text'])) if event['command'] in self.commands: try: d = self.commands[event['command']](conn, event.copy()) except: log.error(failure.Failure()) else: self._add_pending(d) else: self.hook(conn, event)
def signedOn(self): log.info("Signed On!") self.factory.clientConnected(self) for automsg in self.factory.config.findall('automsg'): to = automsg.get('to', None) msg = automsg.get('msg', None) if to and msg: self.msg(to, msg) else: log.error("Invalid automsg: %s" % ElementTree.tostring(automsg)) for autojoin in self.factory.config.findall('autojoin'): chan = autojoin.get('chan', None) password = autojoin.get('password', None) if chan: self.join(chan, password) else: log.error("Invalid autojoin: %s" % ElementTree.tostring(autojoin))
def check(self, event): """Check if a command can be run by a user. Returns a tuple: (True/False, message) """ if self._conf is None: acl = None elif event['private']: acl = self.check_private(event['command'], event['sent_by']) else: acl = self.check_public(event['command'], event['sent_by'], event['sent_to']) if acl is None: log.debug("No acl") return (True, "") else: log.debug("Using acl: %s" % ElementTree.tostring(acl).strip()) action = acl.get("action", "") if action == "" or action not in ("allow", "deny"): log.error('Invalid acl action="%s", allowing.' % action) return (action != "deny", acl.get("msg", ""))
def _error(self, result, conn, event): conn.msg(event['reply_to'], "DB Failure :-(") log.error(result) return