Skip to content

Instantly share code, notes, and snippets.

@jamsyoung
Last active January 3, 2016 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamsyoung/8514607 to your computer and use it in GitHub Desktop.
Save jamsyoung/8514607 to your computer and use it in GitHub Desktop.
MediaWiki Radius Authentication Extension - RadiusAuthPlugin - http://jamsyoung.com/2010/02/17/mediawiki-radius-authentication-extension-radiusauthplugin/
require_once("./extensions/RadiusAuthPlugin.php");
$wgAuth = new RadiusAuthPlugin();
$wgGroupPermissions['*']['createaccount'] = false;
<?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'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment