'''Short description''' This patch allows users to authenticate on wiki trough php session cookie of Vanilla Forum http://getvanilla.com/ and is basicly extension of current php_session module {{{#!python myconfig=dict(host = '127.0.0.1', user = 'dbuser', passwd = 'somedbpassword', dbname = 'dbname', table_prefix = 'LUM_' ) from MoinMoin.auth.php_session import PHPSessionAuth auth = [PHPSessionAuth(apps=['vanilla'], s_path="/var/lib/php5", s_prefix="sess_", autocreate=True, appconfig=myconfig )] }}} auth has the following parameters: {{{#!python auth = [PHPSessionAuth(apps=['vanilla'], s_path="/var/lib/php5", s_prefix="sess_", autocreate=True, appconfig=myconfig )] }}} * `apps` is a list of enabled application (could be "egw" for eGroupware or "vanilla" for Vanilla Forum) * `s_path` is the path of the PHP session files * `s_prefix` is the prefix of the PHP session files * `autocreate` is parameter that ask should user preference be created automatically * `appconfig` is dictionary with configuration data passed to authenticator Patch follows: {{{#!python --- php_session.py 2008-08-31 21:00:51.000000000 +0200 +++ /usr/lib64/python2.5/site-packages/MoinMoin/auth/php_session.py 2008-11-19 00:28:10.000000000 +0100 @@ -15,25 +15,71 @@ import urllib from MoinMoin import user from MoinMoin.auth import _PHPsessionParser, BaseAuth +from MoinMoin import log +logging = log.getLogger(__name__) class PHPSessionAuth(BaseAuth): """ PHP session cookie authentication """ name = 'php_session' - def __init__(self, apps=['egw'], s_path="/tmp", s_prefix="sess_", autocreate=False): + def __init__(self, apps=['egw','vanilla'], s_path="/tmp", s_prefix="sess_", autocreate=False, appconfig=None): """ @param apps: A list of the enabled applications. See above for possible keys. @param s_path: The path where the PHP sessions are stored. @param s_prefix: The prefix of the session files. + @param appconfig: configuration for connecting to mysql if used with vanilla forum + example would be appconfig=dict(host='127.0.0.1',user='mysql',passwd='root', dbname='somedb',table_prefix='LUM_', role='Member') """ BaseAuth.__init__(self) self.s_path = s_path self.s_prefix = s_prefix self.apps = apps self.autocreate = autocreate + self.appconfig = appconfig def request(self, request, user_obj, **kw): + def handle_vanilla_forum(session): + """ just get LussumoUserID and SessionPostBackKey so we can get into db and see what to do next with it """ + if self.appconfig is None: + logging.exception("Please configure this authentication agent (mysql config missing)") + return None, None, None + import MySQLdb # only needed if used with vanilla auth method + #logging.debug(self.appconfig) ## WATCH OUT THIS ONE!!! will leave password for mysql in log if enabled and not supervised + try: + m = MySQLdb.connect(host=self.appconfig['host'], user=self.appconfig['user'], + passwd=self.appconfig['passwd'], db=self.appconfig['dbname']) + except: + logging.exception("authorization failed due to exception when connecting to DB, traceback follows...") + # now lets party :) + query = """SELECT + LUM_User.FirstName as FirstName, + LUM_User.LastName as LastName, + LUM_User.Email as UserEmail, + LUM_User.Name as UserName, + LUM_Role.Name as RoleName, + LUM_Role.Permissions as RolePermissions -- will look what to do with it ... + FROM + LUM_User, LUM_Role + WHERE + LUM_User.RoleID=LUM_Role.RoleID AND + LUM_User.UserID=%s ;""" + if self.appconfig['table_prefix'] != 'LUM_': # no need for regexp if will not gonna use it... + import re # it is nice to have it tho :) + rpl = re.compile('LUM_') + query = rpl.sub(self.appconfig['table_prefix'],query) % session['LussumoUserID'] + else: + query = query % session['LussumoUserID'] + logging.debug("query=%s" % query) + c = m.cursor(MySQLdb.cursors.DictCursor) + c.execute(query) + row = c.fetchone() + dec = lambda x: x and x.decode("iso-8859-1") + FullName = "%s%s" % (row['FirstName'], row['LastName']) + logging.debug("Username=%s UserEmail=%s FirstName+LastName=%s" % ( row['UserName'], row['UserEmail'], FullName ) ) + return dec(row['UserName']), dec(row['UserEmail']), dec(FullName) + + def handle_egroupware(session): """ Extracts name, fullname and email from the session. """ username = session['egw_session']['session_lid'].split("@", 1)[0] @@ -59,8 +105,15 @@ if "egw" in self.apps and session.get('egw_session', None): username, email, name = handle_egroupware(session) break + elif "vanilla" in self.apps and session.get('LussumoUserID', None) and session.get('SessionPostBackKey', None): + logging.info("calling handle_vanilla_forum") + username, email, name = handle_vanilla_forum(session) + if username is None: + logging.info ("no user from this session data, possible breakin maybe?!?!?") + return user_obj, True + break else: - return user_obj, True + return None, True u = user.User(request, name=username, auth_username=username, auth_method=self.name) }}} * ---- CategoryFeatureRequest CategoryFeatureImplemented