jamsyoung
1/20/2014 - 3:51 AM

MediaWiki Radius Authentication Extension - RadiusAuthPlugin - http://jamsyoung.com/2010/02/17/mediawiki-radius-authentication-extension-rad

MediaWiki Radius Authentication Extension - RadiusAuthPlugin - http://jamsyoung.com/2010/02/17/mediawiki-radius-authentication-extension-radiusauthplugin/

<?php
require_once('AuthPlugin.php');
require_once('radius.class.php');

error_reporting(E_ALL);

class RadiusAuthPlugin extends AuthPlugin
{
    function userExists($username) { return TRUE; }


    function authenticate($username, $password)
    {
        $username = strtolower($username);

        $radius = new Radius('RADIUS_SERVER', 'SHARED_SECRET');
        $radius->SetNasIpAddress('NAS_IP_ADDRESS'); // Needed for some devices (not always auto-detected)
        if ($radius->AccessRequest($username, $password))
        {
            return TRUE;
        }

        return FALSE;
    }


    function modifyUITemplate(&$template)
    {
        $template->set('usedomain', FALSE);
        $template->set('useemail', FALSE);
        $template->set('create', FALSE);
    }


    function autoCreate() { return TRUE; }


    function validDomain($domain) { return TRUE; }


    function updateUser(&$user) { return TRUE; }


    function allowPasswordChange() { return FALSE; }


    function setPassword($password) { return FALSE; }


    function updateExternalDB($user) { return FALSE; }


    function canCreateAccounts() { return FALSE; }


    function adduser($user, $password) { return FALSE; }


    function strict() { return TRUE; }


    function initUser(&$user) { }
}


$wgExtensionCredits['other'][] = array(
    'name' => 'RadiusAuthPlugin',
    'version' => '1.0.0',
    'author' => 'Your-Name',
    'description' => 'Automatic login with a RADIUS server'
);
require_once("./extensions/RadiusAuthPlugin.php");
$wgAuth = new RadiusAuthPlugin();
$wgGroupPermissions['*']['createaccount'] = false;