-<?PHP // $Id$
- // config.php - allows admin to edit all configuration variables
-
- require_once('../config.php');
-
- require_once($CFG->libdir.'/adminlib.php');
-
- $adminroot = admin_get_root();
- admin_externalpage_setup('userauthentication', $adminroot);
-
- $auth = optional_param('auth', '', PARAM_SAFEDIR);
-
-
- $focus = '';
-
-/// If data submitted, then process and store.
-
- if ($config = data_submitted()) {
-
- if (!confirm_sesskey()) {
- error(get_string('confirmsesskeybad', 'error'));
- }
-
- $config = (array)$config;
-
- // extract and sanitize the auth key explicitly
- $modules = get_list_of_plugins("auth");
- if (in_array($config['auth'], $modules)) {
- $auth = $config['auth'];
- } else {
- notify("Error defining the authentication method");
- }
-
- // load the auth plugin library
- require_once("{$CFG->dirroot}/auth/$auth/lib.php");
-
- $err = array();
- if (function_exists('auth_validate_form')) {
- auth_validate_form($config, $err);
- }
-
- if (count($err) == 0) {
- foreach ($config as $name => $value) {
- if (preg_match('/^pluginconfig_(.+?)$/', $name, $matches)) {
- $plugin = "auth/$auth";
- $name = $matches[1];
- if (! set_config($name, $value, $plugin)) {
- notify("Problem saving config $name as $value for plugin $plugin");
- }
- } else { // normal handling for
- if (! set_config($name, $value)) {
- notify("Problem saving config $name as $value");
- }
- }
- }
- redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
- exit;
-
- } else {
- foreach ($err as $key => $value) {
- $focus = "form.$key";
- }
- }
- }
-
-/// Otherwise fill and print the form.
-
- if (empty($config)) {
- $config = $CFG;
- }
+<?php
+
+/**
+ * Allows admin to edit all auth plugin settings.
+ *
+ * JH: copied and Hax0rd from admin/enrol.php and admin/filters.php
+ *
+ */
+
+require_once dirname(dirname(__FILE__)) . '/config.php';
+require_once $CFG->libdir . '/tablelib.php';
+require_once($CFG->libdir.'/adminlib.php');
+
+$adminroot = admin_get_root();
+admin_externalpage_setup('userauthentication', $adminroot);
+
+// get currently installed and enabled auth plugins
+$authsavailable = get_list_of_plugins('auth');
+if (empty($CFG->auth_plugins_enabled)) {
+ set_config('auth_plugins_enabled', $CFG->auth);
+ $CFG->auth_plugins_enabled = $CFG->auth;
+}
+$authsenabled = explode(',', $CFG->auth_plugins_enabled);
- $modules = get_list_of_plugins("auth");
- $options = array();
- foreach ($modules as $module) {
- $options[$module] = get_string("auth_$module"."title", "auth");
- }
- asort($options);
- if (!empty($auth) && in_array($auth, $modules)) {
- } else {
- $auth = $config->auth;
- }
+// save form
+if ($form = data_submitted()) {
- // changepassword link replaced by individual auth setting
- if (!empty($config->changepassword)) {
- if (empty($config->{'auth_'.$auth.'_changepasswordurl'})) {
- $config->{'auth_'.$auth.'_changepasswordurl'} = $config->changepassword;
- }
- set_config('changepassword','');
+ if (!confirm_sesskey()) {
+ error(get_string('confirmsesskeybad', 'error'));
}
- $auth = clean_param($auth,PARAM_SAFEDIR);
- require_once("$CFG->dirroot/auth/$auth/lib.php"); //just to make sure that current authentication functions are loaded
- if (! isset($config->guestloginbutton)) {
- $config->guestloginbutton = 1;
+ if (! isset($form->guestloginbutton)) {
+ $form->guestloginbutton = 1;
}
- if (! isset($config->alternateloginurl)) {
- $config->alternateloginurl = '';
+ if (empty($form->alternateloginurl)) {
+ $form->alternateloginurl = '';
}
- if (! isset($config->auth_instructions)) {
- $config->auth_instructions = "";
+ if (empty($form->register)) {
+ $form->register = 'manual';
}
- if (! isset($config->changepassword)) {
- $config->changepassword = "";
+ set_config('guestloginbutton', $form->guestloginbutton);
+ set_config('alternateloginurl', $form->alternateloginurl);
+ set_config('auth', $form->register);
+
+ // add $CFG->auth to auth_plugins_enabled list
+ if (!array_search($form->register, $authsenabled)) {
+ $authsenabled[] = $form->register;
+ $authsenabled = array_unique($authsenabled);
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
}
- if (! isset($config->{'auth_'.$auth.'_changepasswordurl'})) {
- $config->{'auth_'.$auth.'_changepasswordurl'} = '';
- }
- if (! isset($config->{'auth_'.$auth.'_changepasswordhelp'})) {
- $config->{'auth_'.$auth.'_changepasswordhelp'} = '';
- }
- $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
-
- $guestoptions[0] = get_string("hide");
- $guestoptions[1] = get_string("show");
-
- $createoptions[0] = get_string("no");
- $createoptions[1] = get_string("yes");
-
- $strauthentication = get_string("authentication");
- $strauthenticationoptions = get_string("authenticationoptions","auth");
- $strsettings = get_string("settings");
- $strusers = get_string("users");
+}
- admin_externalpage_print_header($adminroot);
+// grab GET/POST parameters
+$params = new object();
+$params->action = optional_param('action', '', PARAM_ACTION);
+$params->auth = optional_param('auth', $CFG->auth, PARAM_ALPHANUM);
- if (empty($CFG->framename) or $CFG->framename=='_top') {
- $target = '';
- } else {
- $target = ' target="'.$CFG->framename.'"';
- }
+////////////////////////////////////////////////////////////////////////////////
+// process actions
- echo "<form$target name=\"authmenu\" method=\"post\" action=\"auth.php\">";
- echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
- echo "<center><b>";
- print_string("chooseauthmethod","auth");
- echo "</b></center>";
- echo ' ';
-
- choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
-
- //echo "</b></center><br />";
- echo "<br />";
- print_simple_box_start("center", "100%");
- print_heading($options[$auth]);
-
- print_simple_box_start("center", "60%", '', 5, 'informationbox');
- print_string("auth_$auth"."description", "auth");
- print_simple_box_end();
-
- echo "<hr />";
-
- print_heading($strsettings);
-
- echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
-
- require_once("$CFG->dirroot/auth/$auth/config.html");
- $CFG->pagepath = 'auth/' . $auth;
-
- echo '<tr><td colspan="3">';
- print_heading(get_string('auth_common_settings', 'auth'));
- echo '</td></tr>';
-
- if ($auth != "email" and $auth != "none" and $auth != "manual") {
- // display box for URL to change password. NB now on a per-method basis (multiple auth)
- echo "<tr valign=\"top\">";
- echo "<td align=\"right\" nowrap=\"nowrap\">";
- print_string("changepassword", "auth");
- echo ":</td>";
- echo "<td>";
- $passurl = $config->{'auth_'.$auth.'_changepasswordurl'};
- echo "<input type=\"text\" name=\"auth_{$auth}_changepasswordurl\" size=\"40\" value=\"$passurl\" />";
- echo "</td>";
- echo "<td>";
- print_string("auth_changepasswordurl_expl","auth",$auth);
- echo "</td></tr>";
-
- // display textbox for lost password help. NB now on a per-method basis (multiple auth)
- echo "<tr valign=\"top\">";
- echo "<td align=\"right\" nowrap=\"nowrap\">";
- print_string("auth_changepasswordhelp", "auth");
- echo ":</td>";
- echo "<td>";
- $passhelp = $config->{'auth_'.$auth.'_changepasswordhelp'};
- echo "<textarea name=\"auth_{$auth}_changepasswordhelp\" cols=\"30\" rows=\"10\" wrap=\"virtual\">";
- echo $passhelp;
- echo "</textarea>\n";
- echo "</td>";
- echo "<td>";
- print_string("auth_changepasswordhelp_expl","auth",$auth);
- echo "</td></tr>";
+switch ($params->action) {
- }
+ case 'disable':
+ // remove from enabled list
+ $key = array_search($params->auth, $authsenabled);
+ if ($key !== false and $params->auth != $CFG->auth) {
+ unset($authsenabled[$key]);
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ }
+ break;
+
+ case 'enable':
+ // check auth plugin is valid first
+ if (!exists_auth_plugin($params->auth)) {
+ error("Authentication plugin '{$params->auth}' is not installed.", $url);
+ }
+ // add to enabled list
+ if (!array_search($params->auth, $authsenabled)) {
+ $authsenabled[] = $params->auth;
+ $authsenabled = array_unique($authsenabled);
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ }
+ break;
+
+ case 'down':
+ $key = array_search($params->auth, $authsenabled);
+ // check auth plugin is valid
+ if ($key === false) {
+ error("Authentication plugin '{$params->auth}' is not enabled.", $url);
+ }
+ // move down the list
+ if ($key < (count($authsenabled) - 1)) {
+ $fsave = $authsenabled[$key];
+ $authsenabled[$key] = $authsenabled[$key + 1];
+ $authsenabled[$key + 1] = $fsave;
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ }
+ break;
+
+ case 'up':
+ $key = array_search($params->auth, $authsenabled);
+ // check auth is valid
+ if ($key === false) {
+ error("Authentication plugin '{$params->auth}' is not enabled.", $url);
+ }
+ // move up the list
+ if ($key >= 1) {
+ $fsave = $authsenabled[$key];
+ $authsenabled[$key] = $authsenabled[$key - 1];
+ $authsenabled[$key - 1] = $fsave;
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ }
+ break;
+
+ case 'save':
+ // save settings
+ set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ set_config('auth', $authsenabled[0]);
+ redirect("auth.php?sesskey=$USER->sesskey", get_string('changessaved'), 1);
+ break;
+
+ default:
+ break;
+}
- echo "<tr valign=\"top\">";
- echo "<td align=\"right\" nowrap=\"nowrap\">";
- print_string("guestloginbutton", "auth");
- echo ":</td>";
- echo "<td>";
- choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, "");
- echo "</td>";
- echo "<td>";
- print_string("showguestlogin","auth");
- echo "</td></tr>";
-
- if (function_exists('auth_user_create')){
- echo "<tr valign=\"top\">";
- echo "<td align=\"right\" nowrap=\"nowrap\">";
- print_string("auth_user_create", "auth");
- echo ":</td>";
- echo "<td>";
- choose_from_menu($createoptions, "auth_user_create", $config->auth_user_create, "");
- echo "</td>";
- echo "<td>";
- print_string("auth_user_creation","auth");
- echo "</td></tr>";
+// display strings
+$txt = get_strings(array('authenticationplugins', 'users', 'administration',
+ 'settings', 'edit', 'name', 'enable', 'disable',
+ 'up', 'down', 'none'));
+$txt->updown = "$txt->up/$txt->down";
+
+// construct the display array, with enabled auth plugins at the top, in order
+$displayauths = array();
+$registrationauths = array();
+$registrationauths['manual'] = $txt->disable;
+foreach ($authsenabled as $auth) {
+ $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
+ $authplugin = get_auth_plugin($auth);
+ if (method_exists($authplugin, 'user_signup')) {
+ $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
+ }
+}
+foreach ($authsavailable as $auth) {
+ if (!array_key_exists($auth, $displayauths)) {
+ $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
}
+ $authplugin = get_auth_plugin($auth);
+ if (method_exists($authplugin, 'user_signup')) {
+ $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
+ }
+}
-
-/// An alternate url for the login form. It means we can use login forms that are integrated
-/// into non-moodle pages
- echo '<tr valign="top">';
- echo '<td algin="right" nowrap="nowrap">';
- print_string('alternateloginurl', 'auth');
- echo '</td>';
- echo '<td>';
- echo '<input type="text" size="40" name="alternateloginurl" alt="'.get_string('alternateloginurl', 'auth').'" value="'.$config->alternateloginurl.'" />';
- echo '</td>';
- echo '<td>';
- print_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php'));
- echo '</td>';
- echo '</tr>';
-
-
- echo '</table>';
- echo '<p align="center"><input type="submit" value="'.get_string('savechanges').'" /></p>';
-
- print_simple_box_end();
-
- echo '</form>';
-
- admin_externalpage_print_footer($adminroot);
- exit;
-
-/// Functions /////////////////////////////////////////////////////////////////
-
-//
-// Good enough for most auth plugins
-// but some may want a custom one if they are offering
-// other options
-// Note: pluginconfig_ fields have special handling.
-function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
-
- echo '<tr><td colspan="3">';
- if ($retrieveopts) {
- print_heading(get_string('auth_data_mapping', 'auth'));
- } else {
- print_heading(get_string('auth_fieldlocks', 'auth'));
+// build the display table
+$table = new flexible_table('auth_admin_table');
+$table->define_columns(array('name', 'enable', 'order', 'settings'));
+$table->column_style('enable', 'text-align', 'center');
+$table->column_style('order', 'text-align', 'center');
+$table->column_style('settings', 'text-align', 'center');
+$table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
+$table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
+$table->set_attribute('id', 'blocks');
+$table->set_attribute('class', 'flexible generaltable generalbox');
+$table->set_attribute('style', 'margin:auto;');
+$table->set_attribute('cellpadding', '5');
+$table->setup();
+
+// iterate through auth plugins and add to the display table
+$updowncount = 1;
+$authcount = count($authsenabled);
+$url = "auth.php?sesskey=" . sesskey();
+foreach ($displayauths as $auth => $name) {
+ // hide/show link
+ if (in_array($auth, $authsenabled)) {
+ $hideshow = "<a href=\"$url&action=disable&auth=$auth\">";
+ $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" height=\"16\" width=\"16\" alt=\"disable\" /></a>";
+ // $hideshow = "<a href=\"$url&action=disable&auth=$auth\"><input type=\"checkbox\" checked></a>";
+ $enabled = true;
+ $displayname = "<span>$name</span>";
}
- echo '</td></tr>';
-
- $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
- 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
- 'locked' => get_string('locked', 'auth'));
- $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
- 'onlogin' => get_string('update_onlogin', 'auth'));
- $updateextoptions = array('0' => get_string('update_never', 'auth'),
- '1' => get_string('update_onupdate', 'auth'));
-
- $pluginconfig = get_config("auth/$auth");
-
- // helptext is on a field with rowspan
- if (empty($helptext)) {
- $helptext = ' ';
+ else {
+ $hideshow = "<a href=\"$url&action=enable&auth=$auth\">";
+ $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" height=\"16\" width=\"16\" alt=\"enable\" /></a>";
+ // $hideshow = "<a href=\"$url&action=enable&auth=$auth\"><input type=\"checkbox\"></a>";
+ $enabled = false;
+ $displayname = "<span class=\"dimmed_text\">$name</span>";
}
- foreach ($user_fields as $field) {
-
- // Define some vars we'll work with
- if(empty($pluginconfig->{"field_map_$field"})) {
- $pluginconfig->{"field_map_$field"} = '';
+ // up/down link (only if auth is enabled)
+ $updown = '';
+ if ($enabled) {
+ if ($updowncount > 1) {
+ $updown .= "<a href=\"$url&action=up&auth=$auth\">";
+ $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a> ";
}
- if(empty($pluginconfig->{"field_updatelocal_$field"})) {
- $pluginconfig->{"field_updatelocal_$field"} = '';
+ else {
+ $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" height=\"16\" width=\"16\" alt=\"\" /> ";
}
- if (empty($pluginconfig->{"field_updateremote_$field"})) {
- $pluginconfig->{"field_updateremote_$field"} = '';
+ if ($updowncount < $authcount) {
+ $updown .= "<a href=\"$url&action=down&auth=$auth\">";
+ $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
}
- if (empty($pluginconfig->{"field_lock_$field"})) {
- $pluginconfig->{"field_lock_$field"} = '';
+ else {
+ $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" height=\"16\" width=\"16\" alt=\"\" />";
}
+ ++ $updowncount;
+ }
+
+ // settings link
+ $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=$auth\">{$txt->settings}</a>";
- // define the fieldname we display to the user
- $fieldname = $field;
- if ($fieldname === 'lang') {
- $fieldname = get_string('language');
- } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
- $fieldname = get_string($matches[1]) . ' ' . $matches[2];
- } else {
- $fieldname = get_string($fieldname);
- }
+ // add a row to the table
+ $table->add_data(array($displayname, $hideshow, $updown, $settings));
+}
- echo '<tr valign="top"><td align="right">';
- echo $fieldname;
- echo '</td><td>';
-
- if ($retrieveopts) {
- $varname = 'field_map_' . $field;
-
- echo "<input name=\"pluginconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\">";
- echo '<div align="right">';
- echo get_string('auth_updatelocal', 'auth') . ' ';
- choose_from_menu($updatelocaloptions, "pluginconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
- echo '<br />';
- if ($updateopts) {
- echo get_string('auth_updateremote', 'auth') . ' ';
- ' ';
- choose_from_menu($updateextoptions, "pluginconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
- echo '<br />';
-
-
- }
- echo get_string('auth_fieldlock', 'auth') . ' ';
- choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
- echo '</div>';
- } else {
- choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
- }
- echo '</td>';
- if (!empty($helptext)) {
- echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
- $helptext = '';
- }
- echo '</tr>';
- }
+// output form
+admin_externalpage_print_header($adminroot);
+print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
+
+if (empty($CFG->framename) or $CFG->framename=='_top') {
+ $target = '';
+} else {
+ $target = ' target="'.$CFG->framename.'"';
}
+echo "<form$target name=\"authmenu\" method=\"post\" action=\"auth.php\">";
+echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
+print_table($table);
+
+////////////////////////////////////////////////////////////////////////////////
+
+$guestoptions[0] = get_string("hide");
+$guestoptions[1] = get_string("show");
+
+echo '<hr>';
+print_heading(get_string('auth_common_settings', 'auth'));
+echo '<table cellspacing="0" cellpadding="5" border="0" align="center">';
+
+// User self registration
+echo "<tr valign=\"top\">\n";
+echo "<td align=\"right\" nowrap=\"nowrap\">\n";
+print_string("selfregistration", "auth");
+echo ":</td>\n";
+echo "<td>\n";
+choose_from_menu($registrationauths, "register", $CFG->auth, "");
+echo "</td>\n";
+echo "<td>\n";
+print_string("selfregistration_help", "auth");
+echo "</td></tr>\n";
+
+// Login as guest button enabled
+echo "<tr valign=\"top\">\n";
+echo "<td align=\"right\" nowrap=\"nowrap\">\n";
+print_string("guestloginbutton", "auth");
+echo ":</td>\n";
+echo "<td>\n";
+choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
+echo "</td>\n";
+echo "<td>\n";
+print_string("showguestlogin","auth");
+echo "</td></tr>\n";
+
+/// An alternate url for the login form. It means we can use login forms that are integrated
+/// into non-moodle pages
+echo "<tr valign=\"top\">\n";
+echo "<td algin=\"right\" nowrap=\"nowrap\">\n";
+print_string('alternateloginurl', 'auth');
+echo "</td>\n";
+echo "<td>\n";
+echo '<input type="text" size="40" name="alternateloginurl" alt="'.get_string('alternateloginurl', 'auth').'" value="'.$CFG->alternateloginurl."\" />\n";
+echo "</td>\n";
+echo "<td>\n";
+print_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php'));
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "</table>\n";
+
+////////////////////////////////////////////////////////////////////////////////
+
+
+echo '<center><input type="submit" value="'.get_string('savechanges').'"></center>';
+echo '</form>';
+admin_externalpage_print_footer($adminroot);
?>
--- /dev/null
+<?php
+/**
+ * Edit configuration for an individual auth plugin
+ */
+
+require_once '../config.php';
+require_once $CFG->libdir.'/adminlib.php';
+
+$adminroot = admin_get_root();
+admin_externalpage_setup('userauthentication', $adminroot);
+$auth = optional_param('auth', '', PARAM_SAFEDIR);
+$authplugin = get_auth_plugin($auth);
+$err = array();
+
+// save configuration changes
+if ($frm = data_submitted()) {
+
+ if (!confirm_sesskey()) {
+ error(get_string('confirmsesskeybad', 'error'));
+ }
+
+ if (method_exists($authplugin, 'validate_form')) {
+ $authplugin->validate_form($frm, $err);
+ }
+
+ if (count($err) == 0) {
+
+ // save plugin config
+ if ($authplugin->process_config($frm)) {
+
+ // save field lock configuration
+ foreach ($frm as $name => $value) {
+ if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
+ $plugin = "auth/$auth";
+ $name = $matches[1];
+ if (!set_config($name, $value, $plugin)) {
+ notify("Problem saving config $name as $value for plugin $plugin");
+ }
+ }
+ }
+ redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
+ exit;
+ }
+ } else {
+ foreach ($err as $key => $value) {
+ $focus = "form.$key";
+ }
+ }
+} else {
+ $frm = get_config("auth/$auth");
+}
+
+$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
+
+$modules = get_list_of_plugins('auth');
+foreach ($modules as $module) {
+ $options[$module] = get_string("auth_{$module}title", 'auth');
+}
+asort($options);
+
+// output configuration form
+admin_externalpage_print_header($adminroot);
+
+if (empty($CFG->framename) or $CFG->framename=='_top') {
+ $target = '';
+} else {
+ $target = ' target="'.$CFG->framename.'"';
+}
+// choose an authentication method
+echo "<form$target name=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
+echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">\n";
+echo "<div align=\"center\"><p><b>\n";
+echo get_string('chooseauthmethod').': ';
+choose_from_menu ($options, "auth", $auth, '', "document.location='auth_config.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", '');
+echo "</b></p></div>\n\n";
+
+// auth plugin description
+print_simple_box_start('center', '80%');
+print_heading($options[$auth]);
+print_simple_box_start('center', '60%', '', 5, 'informationbox');
+print_string("auth_{$auth}description", 'auth');
+print_simple_box_end();
+echo "<hr />\n";
+$authplugin->config_form($frm, $err);
+print_simple_box_end();
+echo '<center><p><input type="submit" value="' . get_string("savechanges") . "\"></p></center>\n";
+echo "</form>\n";
+
+admin_externalpage_print_footer($adminroot);
+exit;
+
+/// Functions /////////////////////////////////////////////////////////////////
+
+// Good enough for most auth plugins
+// but some may want a custom one if they are offering
+// other options
+// Note: lockconfig_ fields have special handling.
+function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
+
+ echo '<tr><td colspan="3">';
+ if ($retrieveopts) {
+ print_heading(get_string('auth_data_mapping', 'auth'));
+ } else {
+ print_heading(get_string('auth_fieldlocks', 'auth'));
+ }
+ echo '</td></tr>';
+
+ $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
+ 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
+ 'locked' => get_string('locked', 'auth'));
+ $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
+ 'onlogin' => get_string('update_onlogin', 'auth'));
+ $updateextoptions = array('0' => get_string('update_never', 'auth'),
+ '1' => get_string('update_onupdate', 'auth'));
+
+ $pluginconfig = get_config("auth/$auth");
+
+ // helptext is on a field with rowspan
+ if (empty($helptext)) {
+ $helptext = ' ';
+ }
+
+ foreach ($user_fields as $field) {
+
+ // Define some vars we'll work with
+ optional_variable($pluginconfig->{"field_map_$field"}, '');
+ optional_variable($pluginconfig->{"field_updatelocal_$field"}, '');
+ optional_variable($pluginconfig->{"field_updateremote_$field"}, '');
+ optional_variable($pluginconfig->{"field_lock_$field"}, '');
+
+ // define the fieldname we display to the user
+ $fieldname = $field;
+ if ($fieldname === 'lang') {
+ $fieldname = get_string('language');
+ } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
+ $fieldname = get_string($matches[1]) . ' ' . $matches[2];
+ } else {
+ $fieldname = get_string($fieldname);
+ }
+
+ echo '<tr valign="top"><td align="right">';
+ echo $fieldname;
+ echo '</td><td>';
+
+ if ($retrieveopts) {
+ $varname = 'field_map_' . $field;
+
+ echo "<input name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\">";
+ echo '<div align="right">';
+ echo get_string('auth_updatelocal', 'auth') . ' ';
+ choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
+ echo '<br />';
+ if ($updateopts) {
+ echo get_string('auth_updateremote', 'auth') . ' ';
+ ' ';
+ choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
+ echo '<br />';
+
+
+ }
+ echo get_string('auth_fieldlock', 'auth') . ' ';
+ choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
+ echo '</div>';
+ } else {
+ choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
+ }
+ echo '</td>';
+ if (!empty($helptext)) {
+ echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
+ $helptext = '';
+ }
+ echo '</tr>';
+ }
+}
+
+?>
$search = trim(optional_param('search', '', PARAM_RAW));
$lastinitial = optional_param('lastinitial', '', PARAM_CLEAN); // only show students with this last initial
$firstinitial = optional_param('firstinitial', '', PARAM_CLEAN); // only show students with this first initial
+ $ru = optional_param('ru', '2', PARAM_INT); // show remote users
+ $lu = optional_param('lu', '2', PARAM_INT); // show local users
+ $acl = optional_param('acl', '0', PARAM_INT); // id of user to tweak mnet ACL (requires $access)
+
+ // Determine which users we are looking at (local, remote, or both). Start with both.
+ if (!isset($_SESSION['admin-user-remoteusers'])) {
+ $_SESSION['admin-user-remoteusers'] = 1;
+ $_SESSION['admin-user-localusers'] = 1;
+ }
+ if ($ru == 0 or $ru == 1) {
+ $_SESSION['admin-user-remoteusers'] = $ru;
+ }
+ if ($lu == 0 or $lu == 1) {
+ $_SESSION['admin-user-localusers'] = $lu;
+ }
+ $remoteusers = $_SESSION['admin-user-remoteusers'];
+ $localusers = $_SESSION['admin-user-localusers'];
+
+ // if neither remote nor local, set to sensible local only
+ if (!$remoteusers and !$localusers) {
+ $_SESSION['admin-user-localusers'] = 1;
+ $localusers = 1;
+ }
if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) { // Should never happen
redirect('index.php');
$user->password = hash_internal_user_password('admin');
$user->email = 'root@localhost';
$user->confirmed = 1;
+ $user->mnethostid = $CFG->mnet_localhost_id;
$user->lang = $CFG->lang;
$user->maildisplay = 1;
$user->timemodified = time();
$user->lang = $CFG->lang;
$user->confirmed = 1;
$user->timemodified = time();
+ $user->mnethostid = $CFG->mnet_localhost_id;
if (! $user->id = insert_record('user', $user)) {
error('Could not start a new user!');
notify(get_string('deletednot', '', fullname($user, true)));
}
}
+ } else if ($acl and confirm_sesskey()) {
+ if (!has_capability('moodle/user:delete', $sitecontext)) {
+ // TODO: this should be under a separate capability
+ error('You are not permitted to modify the MNET access control list.');
+ }
+ if (!$user = get_record('user', 'id', $acl)) {
+ error("No such user.");
+ }
+ if (!is_mnet_remote_user($user)) {
+ error('Users in the MNET access control list must be remote MNET users.');
+ }
+ $access = strtolower(required_param('access', PARAM_ALPHA));
+ if ($access != 'allow' and $access != 'deny') {
+ error('Invalid access parameter.');
+ }
+ $aclrecord = get_record('mnet_sso_access_control', 'username', $user->username, 'mnet_host_id', $user->mnethostid);
+ if (empty($aclrecord)) {
+ $aclrecord = new object();
+ $aclrecord->mnet_host_id = $user->mnethostid;
+ $aclrecord->username = $user->username;
+ $aclrecord->access = $access;
+ if (!insert_record('mnet_sso_access_control', $aclrecord)) {
+ error("Database error - Couldn't modify the MNET access control list.");
+ }
+ } else {
+ $aclrecord->access = $access;
+ if (!update_record('mnet_sso_access_control', $aclrecord)) {
+ error("Database error - Couldn't modify the MNET access control list.");
+ }
+ }
+ $mnethosts = get_records('mnet_host', '', '', 'id', 'id,wwwroot,name');
+ notify("MNET access control list updated: username '$user->username' from host '"
+ . $mnethosts[$user->mnethostid]->name
+ . "' access now set to '$access'.");
}
// Carry on with the user listing
if ($sort == "name") {
$sort = "firstname";
}
-
- $users = get_users_listing($sort, $dir, $page*$perpage, $perpage, $search, $firstinitial, $lastinitial);
+
+ // tell the query which users we are looking at (local, remote, or both)
+ $remotewhere = '';
+ if ($localusers) {
+ $remotewhere .= " and mnethostid = {$CFG->mnet_localhost_id} ";
+ }
+ if ($remoteusers) {
+ if ($localusers) {
+ $remotewhere = ''; // more efficient SQL
+ } else {
+ $remotewhere .= " and mnethostid <> {$CFG->mnet_localhost_id} ";
+ }
+ }
+
+ $users = get_users_listing($sort, $dir, $page*$perpage, $perpage, $search, $firstinitial, $lastinitial, $remotewhere);
$usercount = get_users(false);
$usersearchcount = get_users(false, $search, true, "", "", $firstinitial, $lastinitial);
} else {
$countries = get_list_of_countries();
+ if (empty($mnethosts)) {
+ $mnethosts = get_records('mnet_host', '', '', 'id', 'id,wwwroot,name');
+ }
foreach ($users as $key => $user) {
if (!empty($user->country)) {
}
}
- if (has_capability('moodle/user:update', $sitecontext)) {
+ if (has_capability('moodle/user:update', $sitecontext) and ! is_mnet_remote_user($user)) {
$editbutton = "<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>";
if ($user->confirmed == 0) {
$confirmbutton = "<a href=\"user.php?confirmuser=$user->id&sesskey=$USER->sesskey\">" . get_string('confirm') . "</a>";
}
}
+ // for remote users, shuffle columns around and display MNET stuff
+ if (is_mnet_remote_user($user)) {
+ $access = 'allow';
+ if ($acl = get_record('mnet_sso_access_control', 'username', $user->username, 'mnet_host_id', $user->mnethostid)) {
+ $access = $acl->access;
+ }
+ $changeaccessto = ($access == 'deny' ? 'allow' : 'deny');
+ // delete button in confirm column - remote users should already be confirmed
+ // TODO: no delete for remote users, for now. new userid, delete flag, unique on username/host...
+ $confirmbutton = "";
+ // ACL in delete column
+ $deletebutton = ucfirst($access);
+ if (has_capability('moodle/user:delete', $sitecontext)) {
+ // TODO: this should be under a separate capability
+ $deletebutton .= " (<a href=\"?acl={$user->id}&access=$changeaccessto&sesskey={$USER->sesskey}\">"
+ . ucfirst($changeaccessto) . " access</a>)";
+ }
+ // mnet info in edit column
+ $editbutton = $mnethosts[$user->mnethostid]->name;
+ }
+
if ($user->lastaccess) {
$strlastaccess = format_time(time() - $user->lastaccess);
} else {
}
}
+ echo "<p style=\"text-align:center\">";
+ if ($remoteusers == 1) {
+ echo "<a href=\"?ru=0\">Hide remote users</a> | ";
+ } else {
+ echo "<a href=\"?ru=1\">Show remote users</a> | ";
+ }
+ if ($localusers == 1) {
+ echo "<a href=\"?lu=0\">Hide local users</a>";
+ } else {
+ echo "<a href=\"?lu=1\">Show local users</a>";
+ }
+ echo "</p>";
+
echo "<table class=\"searchbox\" align=\"center\" cellpadding=\"10\"><tr><td>";
echo "<form action=\"user.php\" method=\"get\">";
echo "<input type=\"text\" name=\"search\" value=\"".s($search, true)."\" size=\"20\" />";