http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56415
Revision: 56415 Author: daniel Date: 2009-09-16 14:15:07 +0000 (Wed, 16 Sep 2009) Log Message: ----------- Lockout extension: prevent blocked users from logging in. Added Paths: ----------- trunk/extensions/Lockout/ trunk/extensions/Lockout/Lockout.php Removed Paths: ------------- trunk/extensions/Lockout/IPAuth.php Property changes on: trunk/extensions/Lockout ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/extensions/Lockout/IPAuth.php =================================================================== --- trunk/extensions/IPAuth/IPAuth.php 2009-09-16 12:37:43 UTC (rev 56409) +++ trunk/extensions/Lockout/IPAuth.php 2009-09-16 14:15:07 UTC (rev 56415) @@ -1,56 +0,0 @@ -<?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; -} - Added: trunk/extensions/Lockout/Lockout.php =================================================================== --- trunk/extensions/Lockout/Lockout.php (rev 0) +++ trunk/extensions/Lockout/Lockout.php 2009-09-16 14:15:07 UTC (rev 56415) @@ -0,0 +1,69 @@ +<?php +/* + Copyright (c) 2009, Wikimedia Deutschland (Daniel Kinzler) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Wikimedia Deutschland nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY WIKIMEDIA DEUTSCHLAND ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL WIKIMEDIA DEUTSCHLAND BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + NOTE: This software is not released as a product. It was written primarily for + Wikimedia Deutschland's own use, and is made public as is, in the hope it may + be useful. Wikimedia Deutschland may at any time discontinue developing or + supporting this software. There is no guarantee any new versions or even fixes + for security issues will be released. +*/ + +if( !defined( 'MEDIAWIKI' ) ) { + echo( "Lockout.\n" ); + die( 1 ); +} + +$wgExtensionCredits['other'][] = array( + 'path' => __FILE__, + 'name' => 'Lockout', + 'author' => 'Daniel Kinzler for Wikimedia Deutschland', + 'url' => 'http://mediawiki.org/wiki/Extension:Lockout', + 'description' => 'Prevent blocked users from logging in.', +); + +$wgHooks['UserLoadAfterLoadFromSession'][] = 'lockoutUserLoadAfterLoadFromSession'; +$wgHooks['AbortLogin'][] = 'lockoutAbortLogin'; + + +function lockoutUserLoadAfterLoadFromSession( $user ) { + if ( $user->isBlocked() && $user->isLoggedIn() ) { + $user->logout(); + $user->loadDefaults(); + return false; + } + + return true; +} + +function lockoutAbortLogin( $user, $pw, &$result ) { + if ( $user->isBlocked() ) { + $result = LoginForm::CREATE_BLOCKED; //TODO: a better code, triggering a better message. + return false; + } + + return true; +} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs