MDL-11351 Removed a redundant check for a multiLang JS variable
[moodle-pu.git] / auth / radius / auth.php
blobe01fe2c3d1e31bdf847d75e8d7c9fc598db3629f
1 <?php
3 /**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
8 * Authentication Plugin: RADIUS Authentication
10 * Authenticates against a RADIUS server.
11 * Contributed by Clive Gould <clive@ce.bromley.ac.uk>
13 * 2006-08-31 File created.
16 if (!defined('MOODLE_INTERNAL')) {
17 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
20 require_once($CFG->libdir.'/authlib.php');
22 /**
23 * RADIUS authentication plugin.
25 class auth_plugin_radius extends auth_plugin_base {
27 /**
28 * Constructor.
30 function auth_plugin_radius() {
31 $this->authtype = 'radius';
32 $this->config = get_config('auth/radius');
35 /**
36 * Returns true if the username and password work and false if they are
37 * wrong or don't exist.
39 * @param string $username The username (with system magic quotes)
40 * @param string $password The password (with system magic quotes)
41 * @return bool Authentication success or failure.
43 function user_login ($username, $password) {
44 require_once 'Auth/RADIUS.php';
46 // Added by Clive on 7th May for test purposes
47 // printf("Username: $username <br/>");
48 // printf("Password: $password <br/>");
49 // printf("host: $this->config->host <br/>");
50 // printf("nasport: $this->config->nasport <br/>");
51 // printf("secret: $this->config->secret <br/>");
53 $rauth = new Auth_RADIUS_PAP(stripslashes($username), stripslashes($password));
54 $rauth->addServer($this->config->host, $this->config->nasport, $this->config->secret);
56 if (!$rauth->start()) {
57 printf("Radius start: %s<br/>\n", $rauth->getError());
58 exit;
61 $result = $rauth->send();
62 if (PEAR::isError($result)) {
63 printf("Radius send failed: %s<br/>\n", $result->getMessage());
64 exit;
65 } else if ($result === true) {
66 // printf("Radius Auth succeeded<br/>\n");
67 return true;
68 } else {
69 // printf("Radius Auth rejected<br/>\n");
70 return false;
73 // get attributes, even if auth failed
74 if (!$rauth->getAttributes()) {
75 printf("Radius getAttributes: %s<br/>\n", $rauth->getError());
76 } else {
77 $rauth->dumpAttributes();
80 $rauth->close();
83 /**
84 * Returns true if this authentication plugin is 'internal'.
86 * @return bool
88 function is_internal() {
89 return false;
92 /**
93 * Returns true if this authentication plugin can change the user's
94 * password.
96 * @return bool
98 function can_change_password() {
99 return false;
103 * Prints a form for configuring this authentication plugin.
105 * This function is called from admin/auth.php, and outputs a full page with
106 * a form for configuring this plugin.
108 * @param array $page An object containing all the data for this page.
110 function config_form($config, $err, $user_fields) {
111 include "config.html";
115 * Processes and stores configuration data for this authentication plugin.
117 function process_config($config) {
118 // set to defaults if undefined
119 if (!isset ($config->host)) {
120 $config->host = '127.0.0.1';
122 if (!isset ($config->nasport)) {
123 $config->nasport = '1812';
125 if (!isset ($config->secret)) {
126 $config->secret = '';
128 if (!isset($config->changepasswordurl)) {
129 $config->changepasswordurl = '';
132 // save settings
133 set_config('host', $config->host, 'auth/radius');
134 set_config('nasport', $config->nasport, 'auth/radius');
135 set_config('secret', $config->secret, 'auth/radius');
136 set_config('changepasswordurl', $config->changepasswordurl, 'auth/radius');
138 return true;