http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56409
Revision: 56409 Author: daniel Date: 2009-09-16 12:37:43 +0000 (Wed, 16 Sep 2009) Log Message: ----------- IPAuth: authenticate by fixed ip address Added Paths: ----------- trunk/extensions/IPAuth/ trunk/extensions/IPAuth/IPAuth.php Added: trunk/extensions/IPAuth/IPAuth.php =================================================================== --- trunk/extensions/IPAuth/IPAuth.php (rev 0) +++ trunk/extensions/IPAuth/IPAuth.php 2009-09-16 12:37:43 UTC (rev 56409) @@ -0,0 +1,56 @@ +<?php + +if( !defined( 'MEDIAWIKI' ) ) { + echo( "IPAuth.\n" ); + die( 1 ); +} + +$wgExtensionCredits['other'][] = array( + 'path' => __FILE__, + 'name' => 'IPAuth', + 'author' => 'Daniel Kinzler', + 'url' => 'http://mediawiki.org/wiki/Extension:IPAuth', + 'description' => 'Automatic login from fixed IPs', +); + +$wgIPAuthUsers = array( ); +# $wgIPAuthUsers = array( "127.0.0.1" => "LocalUser" ); + +$wgHooks['UserLoadAfterLoadFromSession'][] = 'ipAuthUserLoadAfterLoadFromSession'; + +function ipAuthUserLoadAfterLoadFromSession( $user ) { + global $wgIPAuthUsers; + + if ( $user->isLoggedIn() ) { + return true; + } + + $ip = wfGetIP(); + if ( isset( $wgIPAuthUsers[ $ip ] ) ) { + $name = $wgIPAuthUsers[ $ip ]; + + $xuser = User::newFromName( $name ); + + if($xuser->getID() == 0) { + wfDebug( "User $name assigned to IP $ip does not exist!\n" ); + } else { + #HACK: force user data reload by assigning members directly + $user->mId = $xuser->mId; + $user->mName = $xuser->mName; + $user->loadFromId(); + + wfDebug( "User $name assigned to IP $ip logged in.\n" ); + + if ( !isset( $_SESSION['wsUserID'] ) ) { + wfDebug( "Setting up a session for $name assigned to IP $ip logged in.\n" ); + wfSetupSession(); + $_SESSION['wsToken'] = "IP:$ip"; + $_SESSION['wsUserName'] = $name; + $user->setCookies(); + } + } + } + + return true; +} + _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs