summaryrefslogtreecommitdiffstats
path: root/Reaktor
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-03-25 15:35:52 +0100
committermakefu <github@syntax-fehler.de>2014-03-25 15:35:52 +0100
commitc5accb6ea72ac9612dddf37541661fa544d5b872 (patch)
tree5e9aa86d33804e49a11acd3169f6d388eaeb4107 /Reaktor
parent5d778bfb0fadd073e1e5ff324f00a2ea460ba843 (diff)
add authentication to Reaktor
using /query <reaktor> identify <password> configuration contains commands and public_commands
Diffstat (limited to 'Reaktor')
-rwxr-xr-xReaktor/IRC/reaktor.py27
-rwxr-xr-xReaktor/auth.lst1
-rwxr-xr-xReaktor/commands/caps3
-rwxr-xr-xReaktor/commands/identify22
-rw-r--r--Reaktor/config.py17
5 files changed, 61 insertions, 9 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)
-
diff --git a/Reaktor/auth.lst b/Reaktor/auth.lst
new file mode 100755
index 00000000..8b137891
--- /dev/null
+++ b/Reaktor/auth.lst
@@ -0,0 +1 @@
+
diff --git a/Reaktor/commands/caps b/Reaktor/commands/caps
index c47319f5..d0245575 100755
--- a/Reaktor/commands/caps
+++ b/Reaktor/commands/caps
@@ -9,4 +9,5 @@ def load_config(filename):
return imp.load_module(modname, file, pathname, description)
config = load_config(os.environ['config_filename'])
-print(' '.join(filter(None,[ x.get('capname',None) for x in config.commands])))
+print('Private: '+' '.join(filter(None,[ x.get('capname',None) for x in config.commands])))
+print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands])))
diff --git a/Reaktor/commands/identify b/Reaktor/commands/identify
new file mode 100755
index 00000000..c2fb2c58
--- /dev/null
+++ b/Reaktor/commands/identify
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import imp
+import os,sys
+
+def load_config(filename):
+ dirname = os.path.dirname(filename)
+ modname, ext = os.path.splitext(os.path.basename(filename))
+ file, pathname, description = imp.find_module(modname, [ dirname ])
+ return imp.load_module(modname, file, pathname, description)
+
+config = load_config(os.environ['config_filename'])
+
+with open(config.admin_file) as f:
+ for line in f:
+ nick,secret = line.split()
+ if sys.argv[1] == secret:
+ print("identified you as %s!"%nick)
+ with open(config.auth_file,'a+') as g:
+ g.write(os.environ['_prefix'] +"\n")
+ sys.exit(0)
+
+print("unable to identify you, sorry")
diff --git a/Reaktor/config.py b/Reaktor/config.py
index 928c49d7..88ae837c 100644
--- a/Reaktor/config.py
+++ b/Reaktor/config.py
@@ -10,21 +10,21 @@ irc_kill_timeout = 360
irc_nickname = name
irc_server = 'irc.freenode.org'
irc_port = 6667
-#irc_restart_timeout = 5
+irc_restart_timeout = 5
irc_channels = [
'#krebs'
]
-
+admin_file='admin.lst'
+auth_file='auth.lst'
def default_command(cmd):
return {
'capname': cmd,
'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P<args>.*))?$',
'argv': [ 'commands/' + cmd ] }
-commands = [
+public_commands = [
default_command('caps'),
default_command('hello'),
- default_command('reload'),
default_command('badcommand'),
default_command('rev'),
default_command('uptime'),
@@ -34,5 +34,12 @@ commands = [
'argv': [ 'commands/respond','You are made of stupid!'] },
# "highlight"
{ 'pattern': '.*\\b' + name + '\\b.*',
- 'argv': [ 'commands/say', 'I\'m famous' ] }
+ 'argv': [ 'commands/say', 'I\'m famous' ] },
+ # identify via direct connect
+ { 'capname': 'identify',
+ 'pattern': 'identify' + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'argv' : [ 'commands/identify' ]}
+]
+commands = [
+ default_command('reload')
]