forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.php
279 lines (242 loc) · 9.82 KB
/
auth.php
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
<?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);
// save form
if ($form = data_submitted()) {
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
if (! isset($form->guestloginbutton)) {
$form->guestloginbutton = 1;
}
if (empty($form->alternateloginurl)) {
$form->alternateloginurl = '';
}
if (empty($form->register)) {
$form->register = 'manual';
}
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));
}
}
// grab GET/POST parameters
$params = new object();
$params->action = optional_param('action', '', PARAM_ACTION);
$params->auth = optional_param('auth', $CFG->auth, PARAM_ALPHANUM);
////////////////////////////////////////////////////////////////////////////////
// process actions
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(get_string('pluginnotinstalled', 'auth', $params->auth), $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(get_string('pluginnotenabled', 'auth', $params->auth), $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(get_string('pluginnotenabled', 'auth', $params->auth), $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;
}
// 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');
}
}
// 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\" class=\"icon\" alt=\"disable\" /></a>";
// $hideshow = "<a href=\"$url&action=disable&auth=$auth\"><input type=\"checkbox\" checked /></a>";
$enabled = true;
$displayname = "<span>$name</span>";
}
else {
$hideshow = "<a href=\"$url&action=enable&auth=$auth\">";
$hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
// $hideshow = "<a href=\"$url&action=enable&auth=$auth\"><input type=\"checkbox\" /></a>";
$enabled = false;
$displayname = "<span class=\"dimmed_text\">$name</span>";
}
// 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> ";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" /> ";
}
if ($updowncount < $authcount) {
$updown .= "<a href=\"$url&action=down&auth=$auth\">";
$updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
}
++ $updowncount;
}
// settings link
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=$auth\">{$txt->settings}</a>";
// add a row to the table
$table->add_data(array($displayname, $hideshow, $updown, $settings));
}
// output form
admin_externalpage_print_header($adminroot);
print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
echo "<form $CFG->frametarget id=\"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);
?>