diff options
author | makefu <github@syntax-fehler.de> | 2014-03-25 15:35:52 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-03-25 15:35:52 +0100 |
commit | c5accb6ea72ac9612dddf37541661fa544d5b872 (patch) | |
tree | 5e9aa86d33804e49a11acd3169f6d388eaeb4107 /Reaktor/IRC | |
parent | 5d778bfb0fadd073e1e5ff324f00a2ea460ba843 (diff) |
add authentication to Reaktor
using /query <reaktor> identify <password>
configuration contains commands and public_commands
Diffstat (limited to 'Reaktor/IRC')
-rwxr-xr-x | Reaktor/IRC/reaktor.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/Reaktor/IRC/reaktor.py b/Reaktor/IRC/reaktor.py index 7ef8d70d..e73a3d79 100755 --- a/Reaktor/IRC/reaktor.py +++ b/Reaktor/IRC/reaktor.py @@ -20,6 +20,16 @@ logging.basicConfig(level = logging.DEBUG if getconf('debug') else logging.INFO) restart_timeout = getconf('irc_restart_timeout') or 5 +def is_admin(prefix): + try: + with open(getconf('auth_file')) as f: + for line in f: + if line.strip() == prefix: + return True + except Exception as e: + log.info(e) + return False + class Reaktor(asybot): def __init__(self): asybot.__init__(self, getconf('irc_server'), getconf('irc_port'), getconf('irc_nickname'), getconf('irc_channels'), hammer_interval=getconf('irc_hammer_interval'), alarm_timeout=getconf('irc_alarm_timeout'), kill_timeout=getconf('irc_kill_timeout')) @@ -28,8 +38,16 @@ class Reaktor(asybot): for command in getconf('commands'): y = match(command['pattern'], rest) if y: - self.execute_command(command, y, prefix, params) - break + if not is_admin(prefix): + self.PRIVMSG(params,'unauthorized!') + else: + return self.execute_command(command, y, prefix, params) + + for command in getconf('public_commands'): + y = match(command['pattern'], rest) + if y: + return self.execute_command(command, y, prefix, params) + def execute_command(self, command, match, prefix, target): from os.path import realpath, dirname, join @@ -43,12 +61,16 @@ class Reaktor(asybot): myargv += shlex.split(match.groupdict()['args']) env = {} + env['_prefix'] = prefix env['_from'] = prefix.split('!', 1)[0] + log.debug('self:' +self.nickname) + # when receiving /query, answer to the user, not to self if self.nickname in target: target.remove(self.nickname) target.append(env['_from']) log.debug('target:' +str(target)) + env['config_filename'] = os.path.abspath(config_filename) start = time() try: @@ -84,4 +106,3 @@ if __name__ == "__main__": waiting for %d seconds" % restart_timeout) log.debug("Exception: %s" % str(e)) sleep(restart_timeout) - |