1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
<?PHP // $Id: auth.php,v 1.35.2.1 2006/07/18 01:31:45 martinlanghoff Exp $
// config.php - allows admin to edit all configuration variables
require_once('../config.php');
$auth = optional_param('auth', '', PARAM_SAFEDIR);
require_login();
if (!$site = get_site()) {
redirect("index.php");
}
if (!isadmin()) {
error("Only the admin can use this page");
}
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
$focus = '';
/// If data submitted, then process and store.
if ($config = data_submitted()) {
$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;
}
$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;
}
// 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','');
}
$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($config->alternateloginurl)) {
$config->alternateloginurl = '';
}
if (! isset($config->auth_instructions)) {
$config->auth_instructions = "";
}
if (! isset($config->changepassword)) {
$config->changepassword = "";
}
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");
$stradministration = get_string("administration");
$strauthentication = get_string("authentication");
$strauthenticationoptions = get_string("authenticationoptions","auth");
$strsettings = get_string("settings");
$strusers = get_string("users");
print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
"<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strauthenticationoptions", "$focus");
echo "<center><b>";
echo "<form target=\"{$CFG->framename}\" name=\"authmenu\" method=\"post\" action=\"auth.php\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
print_string("chooseauthmethod","auth");
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>";
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>";
}
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>";
}
/// 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>';
echo '</form>';
print_simple_box_end();
print_footer();
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'));
}
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
if(empty($pluginconfig->{"field_map_$field"})) {
$pluginconfig->{"field_map_$field"} = '';
}
if(empty($pluginconfig->{"field_updatelocal_$field"})) {
$pluginconfig->{"field_updatelocal_$field"} = '';
}
if (empty($pluginconfig->{"field_updateremote_$field"})) {
$pluginconfig->{"field_updateremote_$field"} = '';
}
if (empty($pluginconfig->{"field_lock_$field"})) {
$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=\"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>';
}
}
?>
|