Permalink
Browse files

working on the auth system. pretty much parses nickserv to see if a u…

…ser if identified.
  • Loading branch information...
1 parent 3d9fa58 commit a4e9752044ae8234bd17f21366cfd18c5d859812 uberj committed May 7, 2011
Showing with 81 additions and 6 deletions.
  1. +2 −0 config.cfg
  2. +0 −1 derp/__init__.py
  3. 0 derp/lib/__init__.py
  4. +60 −0 derp/lib/irc_auth.py
  5. +19 −5 herpderp.py
View
@@ -9,3 +9,5 @@ token=.
nick=derpxes
[plugin_control]
pswd=asdf
+[admin]
+nick=uberj
View
@@ -1 +0,0 @@
-import plugins
No changes.
View
@@ -0,0 +1,60 @@
+import re
+"""
+ A class to hold a state machine to determine if someone is who they say they are.
+ Parse the /msg info <nick> output.
+"""
+class admin_auth( object ):
+ """
+ NickServ derpxes Information on uberj (account uberj):
+ NickServ derpxes Registered : Jun 21 23:52:09 2010 (45 weeks, 4 days, 19:51:10 ago)
+ NickServ derpxes Last addr : ~uberj@shell.onid.oregonstate.edu
+ NickServ derpxes Last seen : now
+ NickServ derpxes Flags : HideMail
+ NickServ derpxes *** End of Info ***
+
+ The plan:
+ If the user has last seen "now" then they are online and registered (no one else can have their nick).
+ If the user trying to authenticate has that same nick, then we know it's them and we confirm.
+ """
+ def __init__( self ):
+ self.phase = 1
+ self.authed = False
+ self.user = ""
+
+ def new_line( self, admin, line ):
+ if self.phase is 1:
+ m = re.search("account \x02(.*)\x02",line)
+ if m:
+ print m.groups(0)[0]
+ # Are we dealing with an authorized user
+ if m.groups(0)[0] == admin:
+ self.phase = 2
+ print "Phase 1 passed"
+ elif self.phase is 2:
+ m = re.match("Registered",line])
+ if m:
+ print "Phase 2 passed"
+ self.phase = 3
+ elif self.phase is 3:
+ m = re.match("Last addr",line)
+ if m:
+ print "Phase 3 passed"
+ self.phase = 4
+ elif self.phase is 4:
+ m = re.match("Last seen",line)
+ status = line.split(":")
+ self.phase = 5
+ print "status is"
+ print status
+ elif self.phase is 5:
+ self.phase is 6
+ elif self.phase is 6:
+ self.authed = True
+
+
+
+ def de_auth( self ):
+ self.authed = False
+
+ def q_auth( self ):
+ return self.authed
View
@@ -9,6 +9,7 @@
from derp import brain
GLOBAL_CONFIG = 'config.cfg'
from ConfigParser import ConfigParser
+from derp.lib import irc_auth
class MessageLogger:
"""
@@ -37,6 +38,9 @@ class HerpBot(irc.IRCClient):
def connectionMade(self):
irc.IRCClient.connectionMade(self)
self.logger = MessageLogger(open(self.factory.filename, "a"))
+ self.factory.config.read(GLOBAL_CONFIG)
+ self.admin = self.factory.config.get('admin','nick')
+ self.auth = irc_auth.admin_auth()
self.logger.log("[connected at %s]" %
time.asctime(time.localtime(time.time())))
@@ -70,25 +74,35 @@ def privmsg(self, user, channel, msg):
# Check to see if they're sending me a private message
if channel == self.nickname:
- print user+" "+channel+" "+msg
-
- msg = msg.split(' ')
- if msg[0] == "!loadplugins":
+ if user == "NickServ":
+ print user+" "+channel+" "+msg
+ if not self.auth.q_auth(): # We haven't confirmed anything
+ self.auth.new_line(self.admin,msg)
+ else:
+ print "No auth"
+
+ con_msg = msg.split(' ')
+ if con_msg[0] == "!loadplugins":
+ self.msg("NickServ","info "+user)
+ """
self.factory.config.read(GLOBAL_CONFIG)
if len(msg) is 2 and msg[1] == self.factory.config.get('plugin_control','pswd'):
print "Loading plugins"
self.factory.brain.load_plugins()
# I should work in an error message into the plugin loading process.
self.msg(user,"Loaded plugins, check the log for success/failure")
return
+ """
- msg = "I don't talk to people like you."
+ """
if user == "NickServ":
#We don't want to respond to NickServ or ChanServ. We get stuck in an infinite loop.
# BUGGGGGGYYYYY HAAACKK MY FACE
print "NickServ: "+msg
return
self.msg(user, msg)
+ """
+ return
# Otherwise check to see if it is a message directed at me
if msg.startswith(self.nickname + ":"):

0 comments on commit a4e9752

Please sign in to comment.