示例#1
0
文件: acl.py 项目: B-Rich/hackabot
    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)
示例#2
0
文件: plugin.py 项目: B-Rich/hackabot
 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
示例#3
0
    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)
示例#4
0
 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
示例#5
0
文件: plugin.py 项目: B-Rich/hackabot
    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)
示例#6
0
    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)
示例#7
0
文件: plugin.py 项目: B-Rich/hackabot
    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)
示例#8
0
    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)
示例#9
0
文件: core.py 项目: B-Rich/hackabot
    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))
示例#10
0
文件: acl.py 项目: B-Rich/hackabot
    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", ""))
示例#11
0
    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))
示例#12
0
    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", ""))
示例#13
0
 def _error(self, result, conn, event):
     conn.msg(event['reply_to'], "DB Failure :-(")
     log.error(result)
     return
示例#14
0
 def _error(self, result, conn, event):
     conn.msg(event['reply_to'], "DB Failure :-(")
     log.error(result)
     return