1
|
<?php
|
2
|
/*
|
3
|
* system_usermanager.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
7
|
* Copyright (c) 2008 Shrew Soft Inc.
|
8
|
* Copyright (c) 2005 Paul Taylor <paultaylor@winn-dixie.com>
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
* All rights reserved.
|
14
|
*
|
15
|
* Redistribution and use in source and binary forms, with or without
|
16
|
* modification, are permitted provided that the following conditions are met:
|
17
|
*
|
18
|
* 1. Redistributions of source code must retain the above copyright notice,
|
19
|
* this list of conditions and the following disclaimer.
|
20
|
*
|
21
|
* 2. Redistributions in binary form must reproduce the above copyright
|
22
|
* notice, this list of conditions and the following disclaimer in
|
23
|
* the documentation and/or other materials provided with the
|
24
|
* distribution.
|
25
|
*
|
26
|
* 3. All advertising materials mentioning features or use of this software
|
27
|
* must display the following acknowledgment:
|
28
|
* "This product includes software developed by the pfSense Project
|
29
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
30
|
*
|
31
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
32
|
* endorse or promote products derived from this software without
|
33
|
* prior written permission. For written permission, please contact
|
34
|
* coreteam@pfsense.org.
|
35
|
*
|
36
|
* 5. Products derived from this software may not be called "pfSense"
|
37
|
* nor may "pfSense" appear in their names without prior written
|
38
|
* permission of the Electric Sheep Fencing, LLC.
|
39
|
*
|
40
|
* 6. Redistributions of any form whatsoever must retain the following
|
41
|
* acknowledgment:
|
42
|
*
|
43
|
* "This product includes software developed by the pfSense Project
|
44
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
45
|
*
|
46
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
47
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
48
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
49
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
50
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
51
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
52
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
53
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
54
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
55
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
56
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
57
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
58
|
*/
|
59
|
|
60
|
##|+PRIV
|
61
|
##|*IDENT=page-system-usermanager
|
62
|
##|*NAME=System: User Manager
|
63
|
##|*DESCR=Allow access to the 'System: User Manager' page.
|
64
|
##|*MATCH=system_usermanager.php*
|
65
|
##|-PRIV
|
66
|
|
67
|
require_once("certs.inc");
|
68
|
require_once("guiconfig.inc");
|
69
|
|
70
|
// start admin user code
|
71
|
if (isset($_POST['userid']) && is_numericint($_POST['userid'])) {
|
72
|
$id = $_POST['userid'];
|
73
|
}
|
74
|
|
75
|
if (isset($_GET['userid']) && is_numericint($_GET['userid'])) {
|
76
|
$id = $_GET['userid'];
|
77
|
}
|
78
|
|
79
|
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
|
80
|
$config['system']['user'] = array();
|
81
|
}
|
82
|
|
83
|
$a_user = &$config['system']['user'];
|
84
|
$act = $_GET['act'];
|
85
|
|
86
|
if (isset($_SERVER['HTTP_REFERER'])) {
|
87
|
$referer = $_SERVER['HTTP_REFERER'];
|
88
|
} else {
|
89
|
$referer = '/system_usermanager.php';
|
90
|
}
|
91
|
|
92
|
if (isset($id) && $a_user[$id]) {
|
93
|
$pconfig['usernamefld'] = $a_user[$id]['name'];
|
94
|
$pconfig['descr'] = $a_user[$id]['descr'];
|
95
|
$pconfig['expires'] = $a_user[$id]['expires'];
|
96
|
$pconfig['customsettings'] = isset($a_user[$id]['customsettings']);
|
97
|
$pconfig['webguicss'] = $a_user[$id]['webguicss'];
|
98
|
$pconfig['webguifixedmenu'] = $a_user[$id]['webguifixedmenu'];
|
99
|
$pconfig['webguihostnamemenu'] = $a_user[$id]['webguihostnamemenu'];
|
100
|
$pconfig['dashboardcolumns'] = $a_user[$id]['dashboardcolumns'];
|
101
|
$pconfig['dashboardavailablewidgetspanel'] = isset($a_user[$id]['dashboardavailablewidgetspanel']);
|
102
|
$pconfig['systemlogsfilterpanel'] = isset($a_user[$id]['systemlogsfilterpanel']);
|
103
|
$pconfig['systemlogsmanagelogpanel'] = isset($a_user[$id]['systemlogsmanagelogpanel']);
|
104
|
$pconfig['statusmonitoringsettingspanel'] = isset($a_user[$id]['statusmonitoringsettingspanel']);
|
105
|
$pconfig['webguileftcolumnhyper'] = isset($a_user[$id]['webguileftcolumnhyper']);
|
106
|
$pconfig['pagenamefirst'] = isset($a_user[$id]['pagenamefirst']);
|
107
|
$pconfig['groups'] = local_user_get_groups($a_user[$id]);
|
108
|
$pconfig['utype'] = $a_user[$id]['scope'];
|
109
|
$pconfig['uid'] = $a_user[$id]['uid'];
|
110
|
$pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
|
111
|
$pconfig['priv'] = $a_user[$id]['priv'];
|
112
|
$pconfig['ipsecpsk'] = $a_user[$id]['ipsecpsk'];
|
113
|
$pconfig['disabled'] = isset($a_user[$id]['disabled']);
|
114
|
}
|
115
|
|
116
|
if ($_GET['act'] == "deluser") {
|
117
|
|
118
|
if (!isset($_GET['username']) || !isset($a_user[$id]) || ($_GET['username'] != $a_user[$id]['name'])) {
|
119
|
pfSenseHeader("system_usermanager.php");
|
120
|
exit;
|
121
|
}
|
122
|
|
123
|
if ($_GET['username'] == $_SESSION['Username']) {
|
124
|
$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_GET['username']);
|
125
|
} else {
|
126
|
conf_mount_rw();
|
127
|
local_user_del($a_user[$id]);
|
128
|
conf_mount_ro();
|
129
|
$userdeleted = $a_user[$id]['name'];
|
130
|
unset($a_user[$id]);
|
131
|
write_config();
|
132
|
$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
|
133
|
}
|
134
|
} else if ($act == "new") {
|
135
|
/*
|
136
|
* set this value cause the text field is read only
|
137
|
* and the user should not be able to mess with this
|
138
|
* setting.
|
139
|
*/
|
140
|
$pconfig['utype'] = "user";
|
141
|
$pconfig['lifetime'] = 3650;
|
142
|
}
|
143
|
|
144
|
if (isset($_POST['dellall'])) {
|
145
|
|
146
|
$del_users = $_POST['delete_check'];
|
147
|
$deleted_users = "";
|
148
|
$deleted_count = 0;
|
149
|
$comma = "";
|
150
|
|
151
|
if (!empty($del_users)) {
|
152
|
foreach ($del_users as $userid) {
|
153
|
if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
|
154
|
if ($a_user[$userid]['name'] == $_SESSION['Username']) {
|
155
|
$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
|
156
|
} else {
|
157
|
conf_mount_rw();
|
158
|
$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
|
159
|
$comma = ", ";
|
160
|
$deleted_count++;
|
161
|
local_user_del($a_user[$userid]);
|
162
|
conf_mount_ro();
|
163
|
unset($a_user[$userid]);
|
164
|
}
|
165
|
} else {
|
166
|
$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
|
167
|
}
|
168
|
}
|
169
|
|
170
|
if ($deleted_count > 0) {
|
171
|
if ($deleted_count == 1) {
|
172
|
$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
|
173
|
} else {
|
174
|
$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
|
175
|
}
|
176
|
write_config($savemsg);
|
177
|
}
|
178
|
}
|
179
|
}
|
180
|
|
181
|
if ($_POST['act'] == "delcert") {
|
182
|
|
183
|
if (!$a_user[$id]) {
|
184
|
pfSenseHeader("system_usermanager.php");
|
185
|
exit;
|
186
|
}
|
187
|
|
188
|
$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
|
189
|
$certdeleted = $certdeleted['descr'];
|
190
|
unset($a_user[$id]['cert'][$_POST['certid']]);
|
191
|
write_config();
|
192
|
$_POST['act'] = "edit";
|
193
|
$savemsg = sprintf(gettext("Certificate %s association removed."), $certdeleted);
|
194
|
}
|
195
|
|
196
|
if ($_POST['act'] == "delprivid") {
|
197
|
$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
|
198
|
unset($a_user[$id]['priv'][$_POST['privid']]);
|
199
|
local_user_set($a_user[$id]);
|
200
|
write_config();
|
201
|
$_POST['act'] = "edit";
|
202
|
$savemsg = sprintf(gettext("Privilege %s removed."), $privdeleted);
|
203
|
}
|
204
|
|
205
|
if ($_POST['save']) {
|
206
|
unset($input_errors);
|
207
|
$pconfig = $_POST;
|
208
|
|
209
|
/* input validation */
|
210
|
if (isset($id) && ($a_user[$id])) {
|
211
|
$reqdfields = explode(" ", "usernamefld");
|
212
|
$reqdfieldsn = array(gettext("Username"));
|
213
|
} else {
|
214
|
if (empty($_POST['name'])) {
|
215
|
$reqdfields = explode(" ", "usernamefld passwordfld1");
|
216
|
$reqdfieldsn = array(
|
217
|
gettext("Username"),
|
218
|
gettext("Password"));
|
219
|
} else {
|
220
|
$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
|
221
|
$reqdfieldsn = array(
|
222
|
gettext("Username"),
|
223
|
gettext("Password"),
|
224
|
gettext("Descriptive name"),
|
225
|
gettext("Certificate authority"),
|
226
|
gettext("Key length"),
|
227
|
gettext("Lifetime"));
|
228
|
}
|
229
|
}
|
230
|
|
231
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
232
|
|
233
|
if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld'])) {
|
234
|
$input_errors[] = gettext("The username contains invalid characters.");
|
235
|
}
|
236
|
|
237
|
if (strlen($_POST['usernamefld']) > 16) {
|
238
|
$input_errors[] = gettext("The username is longer than 16 characters.");
|
239
|
}
|
240
|
|
241
|
if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
|
242
|
$input_errors[] = gettext("The passwords do not match.");
|
243
|
}
|
244
|
|
245
|
if (isset($_POST['ipsecpsk']) && !preg_match('/^[[:ascii:]]*$/', $_POST['ipsecpsk'])) {
|
246
|
$input_errors[] = gettext("IPsec Pre-Shared Key contains invalid characters.");
|
247
|
}
|
248
|
|
249
|
/* Check the POSTed groups to ensure they are valid and exist */
|
250
|
if (is_array($_POST['groups'])) {
|
251
|
foreach ($_POST['groups'] as $newgroup) {
|
252
|
if (empty(getGroupEntry($newgroup))) {
|
253
|
$input_errors[] = gettext("One or more invalid groups was submitted.");
|
254
|
}
|
255
|
}
|
256
|
}
|
257
|
|
258
|
if (isset($id) && $a_user[$id]) {
|
259
|
$oldusername = $a_user[$id]['name'];
|
260
|
} else {
|
261
|
$oldusername = "";
|
262
|
}
|
263
|
/* make sure this user name is unique */
|
264
|
if (!$input_errors) {
|
265
|
foreach ($a_user as $userent) {
|
266
|
if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
|
267
|
$input_errors[] = gettext("Another entry with the same username already exists.");
|
268
|
break;
|
269
|
}
|
270
|
}
|
271
|
}
|
272
|
/* also make sure it is not reserved */
|
273
|
if (!$input_errors) {
|
274
|
$system_users = explode("\n", file_get_contents("/etc/passwd"));
|
275
|
foreach ($system_users as $s_user) {
|
276
|
$ent = explode(":", $s_user);
|
277
|
if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
|
278
|
$input_errors[] = gettext("That username is reserved by the system.");
|
279
|
break;
|
280
|
}
|
281
|
}
|
282
|
}
|
283
|
|
284
|
/*
|
285
|
* Check for a valid expiration date if one is set at all (valid means,
|
286
|
* DateTime puts out a time stamp so any DateTime compatible time
|
287
|
* format may be used. to keep it simple for the enduser, we only
|
288
|
* claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
|
289
|
* like "+1 day", which will be converted to MM/DD/YYYY based on "now".
|
290
|
* Otherwise such an entry would lead to an invalid expiration data.
|
291
|
*/
|
292
|
if ($_POST['expires']) {
|
293
|
try {
|
294
|
$expdate = new DateTime($_POST['expires']);
|
295
|
//convert from any DateTime compatible date to MM/DD/YYYY
|
296
|
$_POST['expires'] = $expdate->format("m/d/Y");
|
297
|
} catch (Exception $ex) {
|
298
|
$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
|
299
|
}
|
300
|
}
|
301
|
|
302
|
if (!empty($_POST['name'])) {
|
303
|
$ca = lookup_ca($_POST['caref']);
|
304
|
if (!$ca) {
|
305
|
$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
|
306
|
}
|
307
|
}
|
308
|
|
309
|
/* if this is an AJAX caller then handle via JSON */
|
310
|
if (isAjax() && is_array($input_errors)) {
|
311
|
input_errors2Ajax($input_errors);
|
312
|
exit;
|
313
|
}
|
314
|
|
315
|
if (!$input_errors) {
|
316
|
|
317
|
conf_mount_rw();
|
318
|
$userent = array();
|
319
|
if (isset($id) && $a_user[$id]) {
|
320
|
$userent = $a_user[$id];
|
321
|
}
|
322
|
|
323
|
isset($_POST['utype']) ? $userent['scope'] = $_POST['utype'] : $userent['scope'] = "system";
|
324
|
|
325
|
/* the user name was modified */
|
326
|
if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
|
327
|
$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
|
328
|
local_user_del($userent);
|
329
|
}
|
330
|
|
331
|
/* the user password was modified */
|
332
|
if ($_POST['passwordfld1']) {
|
333
|
local_user_set_password($userent, $_POST['passwordfld1']);
|
334
|
}
|
335
|
|
336
|
/* only change description if sent */
|
337
|
if (isset($_POST['descr'])) {
|
338
|
$userent['descr'] = $_POST['descr'];
|
339
|
}
|
340
|
|
341
|
$userent['name'] = $_POST['usernamefld'];
|
342
|
$userent['expires'] = $_POST['expires'];
|
343
|
$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
|
344
|
$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
|
345
|
$userent['ipsecpsk'] = $_POST['ipsecpsk'];
|
346
|
|
347
|
if ($_POST['disabled']) {
|
348
|
$userent['disabled'] = true;
|
349
|
} else {
|
350
|
unset($userent['disabled']);
|
351
|
}
|
352
|
|
353
|
if ($_POST['customsettings']) {
|
354
|
$userent['customsettings'] = true;
|
355
|
} else {
|
356
|
unset($userent['customsettings']);
|
357
|
}
|
358
|
|
359
|
if ($_POST['webguicss']) {
|
360
|
$userent['webguicss'] = $_POST['webguicss'];
|
361
|
} else {
|
362
|
unset($userent['webguicss']);
|
363
|
}
|
364
|
|
365
|
if ($_POST['webguifixedmenu']) {
|
366
|
$userent['webguifixedmenu'] = $_POST['webguifixedmenu'];
|
367
|
} else {
|
368
|
unset($userent['webguifixedmenu']);
|
369
|
}
|
370
|
|
371
|
if ($_POST['webguihostnamemenu']) {
|
372
|
$userent['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
|
373
|
} else {
|
374
|
unset($userent['webguihostnamemenu']);
|
375
|
}
|
376
|
|
377
|
if ($_POST['dashboardavailablewidgetspanel']) {
|
378
|
$userent['dashboardavailablewidgetspanel'] = true;
|
379
|
} else {
|
380
|
unset($userent['dashboardavailablewidgetspanel']);
|
381
|
}
|
382
|
|
383
|
if ($_POST['systemlogsfilterpanel']) {
|
384
|
$userent['systemlogsfilterpanel'] = true;
|
385
|
} else {
|
386
|
unset($userent['systemlogsfilterpanel']);
|
387
|
}
|
388
|
|
389
|
if ($_POST['systemlogsmanagelogpanel']) {
|
390
|
$userent['systemlogsmanagelogpanel'] = true;
|
391
|
} else {
|
392
|
unset($userent['systemlogsmanagelogpanel']);
|
393
|
}
|
394
|
|
395
|
if ($_POST['statusmonitoringsettingspanel']) {
|
396
|
$userent['statusmonitoringsettingspanel'] = true;
|
397
|
} else {
|
398
|
unset($userent['statusmonitoringsettingspanel']);
|
399
|
}
|
400
|
|
401
|
if ($_POST['webguileftcolumnhyper']) {
|
402
|
$userent['webguileftcolumnhyper'] = true;
|
403
|
} else {
|
404
|
unset($userent['webguileftcolumnhyper']);
|
405
|
}
|
406
|
|
407
|
if ($_POST['pagenamefirst']) {
|
408
|
$userent['pagenamefirst'] = true;
|
409
|
} else {
|
410
|
unset($userent['pagenamefirst']);
|
411
|
}
|
412
|
|
413
|
if (isset($id) && $a_user[$id]) {
|
414
|
$a_user[$id] = $userent;
|
415
|
} else {
|
416
|
if (!empty($_POST['name'])) {
|
417
|
$cert = array();
|
418
|
$cert['refid'] = uniqid();
|
419
|
$userent['cert'] = array();
|
420
|
|
421
|
$cert['descr'] = $_POST['name'];
|
422
|
|
423
|
$subject = cert_get_subject_array($ca['crt']);
|
424
|
|
425
|
$dn = array(
|
426
|
'countryName' => $subject[0]['v'],
|
427
|
'stateOrProvinceName' => $subject[1]['v'],
|
428
|
'localityName' => $subject[2]['v'],
|
429
|
'organizationName' => $subject[3]['v'],
|
430
|
'emailAddress' => $subject[4]['v'],
|
431
|
'commonName' => $userent['name']);
|
432
|
|
433
|
cert_create($cert, $_POST['caref'], $_POST['keylen'],
|
434
|
(int)$_POST['lifetime'], $dn);
|
435
|
|
436
|
if (!is_array($config['cert'])) {
|
437
|
$config['cert'] = array();
|
438
|
}
|
439
|
$config['cert'][] = $cert;
|
440
|
$userent['cert'][] = $cert['refid'];
|
441
|
}
|
442
|
$userent['uid'] = $config['system']['nextuid']++;
|
443
|
/* Add the user to All Users group. */
|
444
|
foreach ($config['system']['group'] as $gidx => $group) {
|
445
|
if ($group['name'] == "all") {
|
446
|
if (!is_array($config['system']['group'][$gidx]['member'])) {
|
447
|
$config['system']['group'][$gidx]['member'] = array();
|
448
|
}
|
449
|
$config['system']['group'][$gidx]['member'][] = $userent['uid'];
|
450
|
break;
|
451
|
}
|
452
|
}
|
453
|
|
454
|
$a_user[] = $userent;
|
455
|
}
|
456
|
|
457
|
/* Add user to groups so PHP can see the memberships properly or else the user's shell account does not get proper permissions (if applicable) See #5152. */
|
458
|
local_user_set_groups($userent, $_POST['groups']);
|
459
|
local_user_set($userent);
|
460
|
/* Add user to groups again to ensure they are set everywhere, otherwise the user may not appear to be a member of the group. See commit:5372d26d9d25d751d16865ed9d46869d3b0ec5e1. */
|
461
|
local_user_set_groups($userent, $_POST['groups']);
|
462
|
write_config();
|
463
|
|
464
|
if (is_dir("/etc/inc/privhooks")) {
|
465
|
run_plugins("/etc/inc/privhooks");
|
466
|
}
|
467
|
|
468
|
conf_mount_ro();
|
469
|
|
470
|
pfSenseHeader("system_usermanager.php");
|
471
|
}
|
472
|
}
|
473
|
|
474
|
function build_priv_table() {
|
475
|
global $a_user, $id;
|
476
|
|
477
|
$privhtml = '<div class="table-responsive">';
|
478
|
$privhtml .= '<table class="table table-striped table-hover table-condensed">';
|
479
|
$privhtml .= '<thead>';
|
480
|
$privhtml .= '<tr>';
|
481
|
$privhtml .= '<th>' . gettext('Inherited from') . '</th>';
|
482
|
$privhtml .= '<th>' . gettext('Name') . '</th>';
|
483
|
$privhtml .= '<th>' . gettext('Description') . '</th>';
|
484
|
$privhtml .= '<th>' . gettext('Action') . '</th>';
|
485
|
$privhtml .= '</tr>';
|
486
|
$privhtml .= '</thead>';
|
487
|
$privhtml .= '<tbody>';
|
488
|
|
489
|
$i = 0;
|
490
|
|
491
|
foreach (get_user_privdesc($a_user[$id]) as $priv) {
|
492
|
$group = false;
|
493
|
if ($priv['group']) {
|
494
|
$group = $priv['group'];
|
495
|
}
|
496
|
|
497
|
$privhtml .= '<tr>';
|
498
|
$privhtml .= '<td>' . htmlspecialchars($priv['group']) . '</td>';
|
499
|
$privhtml .= '<td>' . htmlspecialchars($priv['name']) . '</td>';
|
500
|
$privhtml .= '<td>' . htmlspecialchars($priv['descr']) . '</td>';
|
501
|
$privhtml .= '<td>';
|
502
|
if (!$group) {
|
503
|
$privhtml .= '<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
|
504
|
}
|
505
|
|
506
|
$privhtml .= '</td>';
|
507
|
$privhtml .= '</tr>';
|
508
|
|
509
|
if (!$group) {
|
510
|
$i++;
|
511
|
}
|
512
|
}
|
513
|
|
514
|
$privhtml .= '</tbody>';
|
515
|
$privhtml .= '</table>';
|
516
|
$privhtml .= '</div>';
|
517
|
|
518
|
$privhtml .= '<nav class="action-buttons">';
|
519
|
$privhtml .= '<a href="system_usermanager_addprivs.php?userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
|
520
|
$privhtml .= '</nav>';
|
521
|
|
522
|
return($privhtml);
|
523
|
}
|
524
|
|
525
|
function build_cert_table() {
|
526
|
global $a_user, $id;
|
527
|
|
528
|
$certhtml = '<div class="table-responsive">';
|
529
|
$certhtml .= '<table class="table table-striped table-hover table-condensed">';
|
530
|
$certhtml .= '<thead>';
|
531
|
$certhtml .= '<tr>';
|
532
|
$certhtml .= '<th>' . gettext('Name') . '</th>';
|
533
|
$certhtml .= '<th>' . gettext('CA') . '</th>';
|
534
|
$certhtml .= '<th></th>';
|
535
|
$certhtml .= '</tr>';
|
536
|
$certhtml .= '</thead>';
|
537
|
$certhtml .= '<tbody>';
|
538
|
|
539
|
$a_cert = $a_user[$id]['cert'];
|
540
|
if (is_array($a_cert)) {
|
541
|
$i = 0;
|
542
|
foreach ($a_cert as $certref) {
|
543
|
$cert = lookup_cert($certref);
|
544
|
$ca = lookup_ca($cert['caref']);
|
545
|
$revokedstr = is_cert_revoked($cert) ? '<b> Revoked</b>':'';
|
546
|
|
547
|
$certhtml .= '<tr>';
|
548
|
$certhtml .= '<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
|
549
|
$certhtml .= '<td>' . htmlspecialchars($ca['descr']) . '</td>';
|
550
|
$certhtml .= '<td>';
|
551
|
$certhtml .= '<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
|
552
|
$certhtml .= gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
|
553
|
$certhtml .= '</td>';
|
554
|
$certhtml .= '</tr>';
|
555
|
$i++;
|
556
|
}
|
557
|
|
558
|
}
|
559
|
|
560
|
$certhtml .= '</tbody>';
|
561
|
$certhtml .= '</table>';
|
562
|
$certhtml .= '</div>';
|
563
|
|
564
|
$certhtml .= '<nav class="action-buttons">';
|
565
|
$certhtml .= '<a href="system_certmanager.php?act=new&userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
|
566
|
$certhtml .= '</nav>';
|
567
|
|
568
|
return($certhtml);
|
569
|
}
|
570
|
|
571
|
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
|
572
|
|
573
|
if ($act == "new" || $act == "edit" || $input_errors) {
|
574
|
$pgtitle[] = gettext('Edit');
|
575
|
}
|
576
|
include("head.inc");
|
577
|
|
578
|
if ($delete_errors) {
|
579
|
print_input_errors($delete_errors);
|
580
|
}
|
581
|
|
582
|
if ($input_errors) {
|
583
|
print_input_errors($input_errors);
|
584
|
}
|
585
|
|
586
|
if ($savemsg) {
|
587
|
print_info_box($savemsg, 'success');
|
588
|
}
|
589
|
|
590
|
$tab_array = array();
|
591
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
592
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
593
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
594
|
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
|
595
|
display_top_tabs($tab_array);
|
596
|
|
597
|
if (!($act == "new" || $act == "edit" || $input_errors)) {
|
598
|
?>
|
599
|
<form method="post">
|
600
|
<div class="panel panel-default">
|
601
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
|
602
|
<div class="panel-body">
|
603
|
<div class="table-responsive">
|
604
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
|
605
|
<thead>
|
606
|
<tr>
|
607
|
<th> </th>
|
608
|
<th><?=gettext("Username")?></th>
|
609
|
<th><?=gettext("Full name")?></th>
|
610
|
<th><?=gettext("Disabled")?></th>
|
611
|
<th><?=gettext("Groups")?></th>
|
612
|
<th><?=gettext("Actions")?></th>
|
613
|
</tr>
|
614
|
</thead>
|
615
|
<tbody>
|
616
|
<?php
|
617
|
foreach ($a_user as $i => $userent):
|
618
|
?>
|
619
|
<tr>
|
620
|
<td>
|
621
|
<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
|
622
|
</td>
|
623
|
<td>
|
624
|
<?php
|
625
|
if ($userent['scope'] != "user") {
|
626
|
$usrimg = 'eye-open';
|
627
|
} else {
|
628
|
$usrimg = 'user';
|
629
|
}
|
630
|
?>
|
631
|
<i class="fa fa-<?=$usrimg?>"></i>
|
632
|
<?=htmlspecialchars($userent['name'])?>
|
633
|
</td>
|
634
|
<td><?=htmlspecialchars($userent['descr'])?></td>
|
635
|
<td><?php if (isset($userent['disabled'])) echo "*"?></td>
|
636
|
<td><?=implode(",", local_user_get_groups($userent))?></td>
|
637
|
<td>
|
638
|
<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&userid=<?=$i?>"></a>
|
639
|
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
|
640
|
<a class="fa fa-trash" title="<?=gettext("Delete user")?>" href="?act=deluser&userid=<?=$i?>&username=<?=$userent['name']?>"></a>
|
641
|
<?php endif; ?>
|
642
|
</td>
|
643
|
</tr>
|
644
|
<?php endforeach; ?>
|
645
|
</tbody>
|
646
|
</table>
|
647
|
</div>
|
648
|
</div>
|
649
|
</div>
|
650
|
<nav class="action-buttons">
|
651
|
<a href="?act=new" class="btn btn-sm btn-success">
|
652
|
<i class="fa fa-plus icon-embed-btn"></i>
|
653
|
<?=gettext("Add")?>
|
654
|
</a>
|
655
|
|
656
|
<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
|
657
|
<i class="fa fa-trash icon-embed-btn"></i>
|
658
|
<?=gettext("Delete")?>
|
659
|
</button>
|
660
|
</nav>
|
661
|
</form>
|
662
|
<div class="infoblock">
|
663
|
<?php
|
664
|
print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
|
665
|
"the webConfigurator can be assigned directly or inherited from group memberships. " .
|
666
|
"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
|
667
|
'<p>' . gettext("Accounts added here are also used for other parts of the system " .
|
668
|
"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
|
669
|
);
|
670
|
?></div><?php
|
671
|
include("foot.inc");
|
672
|
exit;
|
673
|
}
|
674
|
|
675
|
$form = new Form;
|
676
|
|
677
|
if ($act == "new" || $act == "edit" || $input_errors):
|
678
|
|
679
|
$form->addGlobal(new Form_Input(
|
680
|
'act',
|
681
|
null,
|
682
|
'hidden',
|
683
|
''
|
684
|
));
|
685
|
|
686
|
$form->addGlobal(new Form_Input(
|
687
|
'userid',
|
688
|
null,
|
689
|
'hidden',
|
690
|
isset($id) ? $id:''
|
691
|
));
|
692
|
|
693
|
$form->addGlobal(new Form_Input(
|
694
|
'privid',
|
695
|
null,
|
696
|
'hidden',
|
697
|
''
|
698
|
));
|
699
|
|
700
|
$form->addGlobal(new Form_Input(
|
701
|
'certid',
|
702
|
null,
|
703
|
'hidden',
|
704
|
''
|
705
|
));
|
706
|
|
707
|
$ro = "";
|
708
|
if ($pconfig['utype'] == "system") {
|
709
|
$ro = "readonly";
|
710
|
}
|
711
|
|
712
|
$section = new Form_Section('User Properties');
|
713
|
|
714
|
$section->addInput(new Form_StaticText(
|
715
|
'Defined by',
|
716
|
strtoupper($pconfig['utype'])
|
717
|
));
|
718
|
|
719
|
$form->addGlobal(new Form_Input(
|
720
|
'utype',
|
721
|
null,
|
722
|
'hidden',
|
723
|
$pconfig['utype']
|
724
|
));
|
725
|
|
726
|
$section->addInput(new Form_Checkbox(
|
727
|
'disabled',
|
728
|
'Disabled',
|
729
|
'This user cannot login',
|
730
|
$pconfig['disabled']
|
731
|
));
|
732
|
|
733
|
$section->addInput($input = new Form_Input(
|
734
|
'usernamefld',
|
735
|
'Username',
|
736
|
'text',
|
737
|
$pconfig['usernamefld']
|
738
|
));
|
739
|
|
740
|
if ($ro) {
|
741
|
$input->setReadonly();
|
742
|
}
|
743
|
|
744
|
$form->addGlobal(new Form_Input(
|
745
|
'oldusername',
|
746
|
null,
|
747
|
'hidden',
|
748
|
$pconfig['usernamefld']
|
749
|
));
|
750
|
|
751
|
$group = new Form_Group('Password');
|
752
|
$group->add(new Form_Input(
|
753
|
'passwordfld1',
|
754
|
'Password',
|
755
|
'password'
|
756
|
));
|
757
|
$group->add(new Form_Input(
|
758
|
'passwordfld2',
|
759
|
'Confirm Password',
|
760
|
'password'
|
761
|
));
|
762
|
|
763
|
$section->add($group);
|
764
|
|
765
|
$section->addInput($input = new Form_Input(
|
766
|
'descr',
|
767
|
'Full name',
|
768
|
'text',
|
769
|
htmlspecialchars($pconfig['descr'])
|
770
|
))->setHelp('User\'s full name, for administrative information only');
|
771
|
|
772
|
if ($ro) {
|
773
|
$input->setDisabled();
|
774
|
}
|
775
|
|
776
|
$section->addInput(new Form_Input(
|
777
|
'expires',
|
778
|
'Expiration date',
|
779
|
'text',
|
780
|
$pconfig['expires']
|
781
|
))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
|
782
|
'the expiration date');
|
783
|
|
784
|
$section->addInput(new Form_Checkbox(
|
785
|
'customsettings',
|
786
|
'Custom Settings',
|
787
|
'Use individual customized GUI options and dashboard layout for this user.',
|
788
|
$pconfig['customsettings']
|
789
|
));
|
790
|
|
791
|
gen_user_settings_fields($section, $pconfig);
|
792
|
|
793
|
// ==== Group membership ==================================================
|
794
|
$group = new Form_Group('Group membership');
|
795
|
|
796
|
// Make a list of all the groups configured on the system, and a list of
|
797
|
// those which this user is a member of
|
798
|
$systemGroups = array();
|
799
|
$usersGroups = array();
|
800
|
|
801
|
$usergid = [$pconfig['usernamefld']];
|
802
|
|
803
|
foreach ($config['system']['group'] as $Ggroup) {
|
804
|
if ($Ggroup['name'] != "all") {
|
805
|
if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
|
806
|
$usersGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the user's list
|
807
|
} else {
|
808
|
$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
|
809
|
}
|
810
|
}
|
811
|
}
|
812
|
|
813
|
$group->add(new Form_Select(
|
814
|
'sysgroups',
|
815
|
null,
|
816
|
array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
|
817
|
$systemGroups,
|
818
|
true
|
819
|
))->setHelp('Not member of');
|
820
|
|
821
|
$group->add(new Form_Select(
|
822
|
'groups',
|
823
|
null,
|
824
|
array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
|
825
|
$usersGroups,
|
826
|
true
|
827
|
))->setHelp('Member of');
|
828
|
|
829
|
$section->add($group);
|
830
|
|
831
|
$group = new Form_Group('');
|
832
|
|
833
|
$group->add(new Form_Button(
|
834
|
'movetoenabled',
|
835
|
'Move to "Member of" list',
|
836
|
null,
|
837
|
'fa-angle-double-right'
|
838
|
))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
|
839
|
|
840
|
$group->add(new Form_Button(
|
841
|
'movetodisabled',
|
842
|
'Move to "Not member of" list',
|
843
|
null,
|
844
|
'fa-angle-double-left'
|
845
|
))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
|
846
|
|
847
|
$group->setHelp('Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items.');
|
848
|
$section->add($group);
|
849
|
|
850
|
// ==== Button for adding user certificate ================================
|
851
|
if ($act == 'new') {
|
852
|
$section->addInput(new Form_Checkbox(
|
853
|
'showcert',
|
854
|
'Certificate',
|
855
|
'Click to create a user certificate',
|
856
|
false
|
857
|
));
|
858
|
}
|
859
|
|
860
|
$form->add($section);
|
861
|
|
862
|
// ==== Effective privileges section ======================================
|
863
|
if (isset($pconfig['uid'])) {
|
864
|
// We are going to build an HTML table and add it to an Input_StaticText. It may be ugly, but it
|
865
|
// is the best way to make the display we need.
|
866
|
|
867
|
$section = new Form_Section('Effective Privileges');
|
868
|
|
869
|
$section->addInput(new Form_StaticText(
|
870
|
null,
|
871
|
build_priv_table()
|
872
|
));
|
873
|
|
874
|
$form->add($section);
|
875
|
|
876
|
// ==== Certificate table section =====================================
|
877
|
$section = new Form_Section('User Certificates');
|
878
|
|
879
|
$section->addInput(new Form_StaticText(
|
880
|
null,
|
881
|
build_cert_table()
|
882
|
));
|
883
|
|
884
|
$form->add($section);
|
885
|
}
|
886
|
|
887
|
// ==== Add user certificate for a new user
|
888
|
if (is_array($config['ca']) && count($config['ca']) > 0) {
|
889
|
$section = new Form_Section('Create Certificate for User');
|
890
|
$section->addClass('cert-options');
|
891
|
|
892
|
$nonPrvCas = array();
|
893
|
foreach ($config['ca'] as $ca) {
|
894
|
if (!$ca['prv']) {
|
895
|
continue;
|
896
|
}
|
897
|
|
898
|
$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
|
899
|
}
|
900
|
|
901
|
if (!empty($nonPrvCas)) {
|
902
|
$section->addInput(new Form_Input(
|
903
|
'name',
|
904
|
'Descriptive name',
|
905
|
'text',
|
906
|
$pconfig['name']
|
907
|
));
|
908
|
|
909
|
$section->addInput(new Form_Select(
|
910
|
'caref',
|
911
|
'Certificate authority',
|
912
|
null,
|
913
|
$nonPrvCas
|
914
|
));
|
915
|
|
916
|
$section->addInput(new Form_Select(
|
917
|
'keylen',
|
918
|
'Key length',
|
919
|
2048,
|
920
|
array(
|
921
|
512 => '512 bits',
|
922
|
1024 => '1024 bits',
|
923
|
2048 => '2048 bits',
|
924
|
4096 => '4096 bits',
|
925
|
)
|
926
|
));
|
927
|
|
928
|
$section->addInput(new Form_Input(
|
929
|
'lifetime',
|
930
|
'Lifetime',
|
931
|
'number',
|
932
|
$pconfig['lifetime']
|
933
|
));
|
934
|
}
|
935
|
|
936
|
$form->add($section);
|
937
|
}
|
938
|
|
939
|
endif;
|
940
|
// ==== Paste a key for the new user
|
941
|
$section = new Form_Section('Keys');
|
942
|
|
943
|
$section->addInput(new Form_Checkbox(
|
944
|
'showkey',
|
945
|
'Authorized keys',
|
946
|
'Click to paste an authorized key',
|
947
|
false
|
948
|
));
|
949
|
|
950
|
$section->addInput(new Form_Textarea(
|
951
|
'authorizedkeys',
|
952
|
'Authorized SSH Keys',
|
953
|
$pconfig['authorizedkeys']
|
954
|
))->setHelp('Enter authorized SSH keys for this user');
|
955
|
|
956
|
$section->addInput(new Form_Input(
|
957
|
'ipsecpsk',
|
958
|
'IPsec Pre-Shared Key',
|
959
|
'text',
|
960
|
$pconfig['ipsecpsk']
|
961
|
));
|
962
|
|
963
|
$form->add($section);
|
964
|
|
965
|
print $form;
|
966
|
|
967
|
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
|
968
|
?>
|
969
|
<script type="text/javascript">
|
970
|
//<![CDATA[
|
971
|
events.push(function() {
|
972
|
|
973
|
function setcustomoptions() {
|
974
|
var adv = $('#customsettings').prop('checked');
|
975
|
|
976
|
hideInput('webguicss', !adv);
|
977
|
hideInput('webguifixedmenu', !adv);
|
978
|
hideInput('webguihostnamemenu', !adv);
|
979
|
hideInput('dashboardcolumns', !adv);
|
980
|
hideCheckbox('dashboardavailablewidgetspanel', !adv);
|
981
|
hideCheckbox('systemlogsfilterpanel', !adv);
|
982
|
hideCheckbox('systemlogsmanagelogpanel', !adv);
|
983
|
hideCheckbox('statusmonitoringsettingspanel', !adv);
|
984
|
hideCheckbox('webguileftcolumnhyper', !adv);
|
985
|
hideCheckbox('pagenamefirst', !adv);
|
986
|
}
|
987
|
|
988
|
// Handle displaying a warning message if a user-created theme is selected.
|
989
|
function setThemeWarning() {
|
990
|
if ($('#webguicss').val().startsWith("pfSense")) {
|
991
|
$('#csstxt').html("").addClass("text-default");
|
992
|
} else {
|
993
|
$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
|
994
|
}
|
995
|
}
|
996
|
|
997
|
$('#webguicss').change(function() {
|
998
|
setThemeWarning();
|
999
|
});
|
1000
|
|
1001
|
setThemeWarning();
|
1002
|
|
1003
|
// On click . .
|
1004
|
$('#customsettings').click(function () {
|
1005
|
setcustomoptions();
|
1006
|
});
|
1007
|
|
1008
|
$("#movetodisabled").click(function() {
|
1009
|
moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
|
1010
|
});
|
1011
|
|
1012
|
$("#movetoenabled").click(function() {
|
1013
|
moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
|
1014
|
});
|
1015
|
|
1016
|
$("#showcert").click(function() {
|
1017
|
hideClass('cert-options', !this.checked);
|
1018
|
});
|
1019
|
|
1020
|
$("#showkey").click(function() {
|
1021
|
hideInput('authorizedkeys', false);
|
1022
|
hideCheckbox('showkey', true);
|
1023
|
});
|
1024
|
|
1025
|
$('[id^=delcert]').click(function(event) {
|
1026
|
if (confirm(event.target.title)) {
|
1027
|
$('#certid').val(event.target.id.match(/\d+$/)[0]);
|
1028
|
$('#userid').val('<?=$id;?>');
|
1029
|
$('#act').val('delcert');
|
1030
|
$('form').submit();
|
1031
|
}
|
1032
|
});
|
1033
|
|
1034
|
$('[id^=delprivid]').click(function(event) {
|
1035
|
if (confirm(event.target.title)) {
|
1036
|
$('#privid').val(event.target.id.match(/\d+$/)[0]);
|
1037
|
$('#userid').val('<?=$id;?>');
|
1038
|
$('#act').val('delprivid');
|
1039
|
$('form').submit();
|
1040
|
}
|
1041
|
});
|
1042
|
|
1043
|
$('#expires').datepicker();
|
1044
|
|
1045
|
// ---------- On initial page load ------------------------------------------------------------
|
1046
|
|
1047
|
hideClass('cert-options', true);
|
1048
|
//hideInput('authorizedkeys', true);
|
1049
|
hideCheckbox('showkey', true);
|
1050
|
setcustomoptions();
|
1051
|
|
1052
|
// On submit mark all the user's groups as "selected"
|
1053
|
$('form').submit(function() {
|
1054
|
AllServers($('[name="groups[]"] option'), true);
|
1055
|
});
|
1056
|
});
|
1057
|
//]]>
|
1058
|
</script>
|
1059
|
<?php
|
1060
|
include('foot.inc');
|
1061
|
?>
|