Project

General

Profile

Download (32.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * system_usermanager.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2008 Shrew Soft Inc.
10
 * Copyright (c) 2005 Paul Taylor <paultaylor@winn-dixie.com>
11
 * All rights reserved.
12
 *
13
 * originally based on m0n0wall (http://m0n0.ch/wall)
14
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
15
 * All rights reserved.
16
 *
17
 * Licensed under the Apache License, Version 2.0 (the "License");
18
 * you may not use this file except in compliance with the License.
19
 * You may obtain a copy of the License at
20
 *
21
 * http://www.apache.org/licenses/LICENSE-2.0
22
 *
23
 * Unless required by applicable law or agreed to in writing, software
24
 * distributed under the License is distributed on an "AS IS" BASIS,
25
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
 * See the License for the specific language governing permissions and
27
 * limitations under the License.
28
 */
29

    
30
##|+PRIV
31
##|*IDENT=page-system-usermanager
32
##|*NAME=System: User Manager
33
##|*DESCR=Allow access to the 'System: User Manager' page.
34
##|*WARN=standard-warning-root
35
##|*MATCH=system_usermanager.php*
36
##|-PRIV
37

    
38
require_once("certs.inc");
39
require_once("guiconfig.inc");
40
require_once("pfsense-utils.inc");
41

    
42
$logging_level = LOG_WARNING;
43
$logging_prefix = gettext("Local User Database");
44

    
45
// start admin user code
46
if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
47
	$id = $_REQUEST['userid'];
48
}
49

    
50
init_config_arr(array('system', 'user'));
51
$a_user = &$config['system']['user'];
52
$act = $_REQUEST['act'];
53

    
54
if (isset($_SERVER['HTTP_REFERER'])) {
55
	$referer = $_SERVER['HTTP_REFERER'];
56
} else {
57
	$referer = '/system_usermanager.php';
58
}
59

    
60
if (isset($id) && $a_user[$id]) {
61
	$pconfig['usernamefld'] = $a_user[$id]['name'];
62
	$pconfig['descr'] = $a_user[$id]['descr'];
63
	$pconfig['expires'] = $a_user[$id]['expires'];
64
	$pconfig['customsettings'] = isset($a_user[$id]['customsettings']);
65
	$pconfig['webguicss'] = $a_user[$id]['webguicss'];
66
	$pconfig['webguifixedmenu'] = $a_user[$id]['webguifixedmenu'];
67
	$pconfig['webguihostnamemenu'] = $a_user[$id]['webguihostnamemenu'];
68
	$pconfig['dashboardcolumns'] = $a_user[$id]['dashboardcolumns'];
69
	$pconfig['interfacessort'] = isset($a_user[$id]['interfacessort']);
70
	$pconfig['dashboardavailablewidgetspanel'] = isset($a_user[$id]['dashboardavailablewidgetspanel']);
71
	$pconfig['systemlogsfilterpanel'] = isset($a_user[$id]['systemlogsfilterpanel']);
72
	$pconfig['systemlogsmanagelogpanel'] = isset($a_user[$id]['systemlogsmanagelogpanel']);
73
	$pconfig['statusmonitoringsettingspanel'] = isset($a_user[$id]['statusmonitoringsettingspanel']);
74
	$pconfig['webguileftcolumnhyper'] = isset($a_user[$id]['webguileftcolumnhyper']);
75
	$pconfig['disablealiaspopupdetail'] = isset($a_user[$id]['disablealiaspopupdetail']);
76
	$pconfig['pagenamefirst'] = isset($a_user[$id]['pagenamefirst']);
77
	$pconfig['groups'] = local_user_get_groups($a_user[$id]);
78
	$pconfig['utype'] = $a_user[$id]['scope'];
79
	$pconfig['uid'] = $a_user[$id]['uid'];
80
	$pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
81
	$pconfig['priv'] = $a_user[$id]['priv'];
82
	$pconfig['ipsecpsk'] = $a_user[$id]['ipsecpsk'];
83
	$pconfig['disabled'] = isset($a_user[$id]['disabled']);
84
}
85

    
86
/*
87
 * Check user privileges to test if the user is allowed to make changes.
88
 * Otherwise users can end up in an inconsistent state where some changes are
89
 * performed and others denied. See https://redmine.pfsense.org/issues/9259
90
 */
91
phpsession_begin();
92
$guiuser = getUserEntry($_SESSION['Username']);
93
$read_only = (is_array($guiuser) && userHasPrivilege($guiuser, "user-config-readonly"));
94
phpsession_end();
95

    
96
if (!empty($_POST) && $read_only) {
97
	$input_errors = array(gettext("Insufficient privileges to make the requested change (read only)."));
98
}
99

    
100
if (($_POST['act'] == "deluser") && !$read_only) {
101

    
102
	if (!isset($_POST['username']) || !isset($a_user[$id]) || ($_POST['username'] != $a_user[$id]['name'])) {
103
		pfSenseHeader("system_usermanager.php");
104
		exit;
105
	}
106

    
107
	if ($_POST['username'] == $_SESSION['Username']) {
108
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_POST['username']);
109
	} else {
110
		local_user_del($a_user[$id]);
111
		$userdeleted = $a_user[$id]['name'];
112
		unset($a_user[$id]);
113
		/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
114
		$a_user = array_values($a_user);
115
		$savemsg = sprintf(gettext("Successfully deleted user: %s"), $userdeleted);
116
		write_config($savemsg);
117
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
118
	}
119

    
120
} else if ($act == "new") {
121
	/*
122
	 * set this value cause the text field is read only
123
	 * and the user should not be able to mess with this
124
	 * setting.
125
	 */
126
	$pconfig['utype'] = "user";
127
	$pconfig['lifetime'] = 3650;
128

    
129
	$nonPrvCas = array();
130
	if (is_array($config['ca']) && count($config['ca']) > 0) {
131
		foreach ($config['ca'] as $ca) {
132
			if (!$ca['prv']) {
133
				continue;
134
			}
135

    
136
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
137
		}
138
	}
139

    
140
}
141

    
142
if (isset($_POST['dellall']) && !$read_only) {
143

    
144
	$del_users = $_POST['delete_check'];
145
	$deleted_users = array();
146

    
147
	if (!empty($del_users)) {
148
		foreach ($del_users as $userid) {
149
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
150
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
151
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
152
				} else {
153
					$deleted_users[] = $a_user[$userid]['name'];
154
					local_user_del($a_user[$userid]);
155
					unset($a_user[$userid]);
156
				}
157
			} else {
158
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
159
			}
160
		}
161

    
162
		if (count($deleted_users) > 0) {
163
			$savemsg = sprintf(gettext("Successfully deleted %s: %s"), (count($deleted_users) == 1) ? gettext("user") : gettext("users"), implode(', ', $deleted_users));
164
			/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
165
			$a_user = array_values($a_user);
166
			write_config($savemsg);
167
			syslog($logging_level, "{$logging_prefix}: {$savemsg}");
168
		}
169
	}
170
}
171

    
172
if (($_POST['act'] == "delcert") && !$read_only) {
173

    
174
	if (!$a_user[$id]) {
175
		pfSenseHeader("system_usermanager.php");
176
		exit;
177
	}
178

    
179
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
180
	$certdeleted = $certdeleted['descr'];
181
	unset($a_user[$id]['cert'][$_POST['certid']]);
182
	$savemsg = sprintf(gettext("Removed certificate association \"%s\" from user %s"), $certdeleted, $a_user[$id]['name']);
183
	write_config($savemsg);
184
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
185
	$_POST['act'] = "edit";
186
}
187

    
188
if (($_POST['act'] == "delprivid") && !$read_only) {
189
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
190
	unset($a_user[$id]['priv'][$_POST['privid']]);
191
	local_user_set($a_user[$id]);
192
	$savemsg = sprintf(gettext("Removed Privilege \"%s\" from user %s"), $privdeleted, $a_user[$id]['name']);
193
	write_config($savemsg);
194
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
195
	$_POST['act'] = "edit";
196
}
197

    
198
if ($_POST['save'] && !$read_only) {
199
	unset($input_errors);
200
	$pconfig = $_POST;
201

    
202
	/* input validation */
203
	if (isset($id) && ($a_user[$id])) {
204
		$reqdfields = explode(" ", "usernamefld");
205
		$reqdfieldsn = array(gettext("Username"));
206
	} else {
207
		if (empty($_POST['name'])) {
208
			$reqdfields = explode(" ", "usernamefld passwordfld1");
209
			$reqdfieldsn = array(
210
				gettext("Username"),
211
				gettext("Password"));
212
		} else {
213
			$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
214
			$reqdfieldsn = array(
215
				gettext("Username"),
216
				gettext("Password"),
217
				gettext("Descriptive name"),
218
				gettext("Certificate authority"),
219
				gettext("Key length"),
220
				gettext("Lifetime"));
221
		}
222
	}
223

    
224
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
225

    
226
	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld'])) {
227
		$input_errors[] = gettext("The username contains invalid characters.");
228
	}
229

    
230
	if (strlen($_POST['usernamefld']) > 32) {
231
		$input_errors[] = gettext("The username is longer than 32 characters.");
232
	}
233

    
234
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
235
		$input_errors[] = gettext("The passwords do not match.");
236
	}
237

    
238
	if (isset($_POST['ipsecpsk']) && !preg_match('/^[[:ascii:]]*$/', $_POST['ipsecpsk'])) {
239
		$input_errors[] = gettext("IPsec Pre-Shared Key contains invalid characters.");
240
	}
241

    
242
	/* Check the POSTed groups to ensure they are valid and exist */
243
	if (is_array($_POST['groups'])) {
244
		foreach ($_POST['groups'] as $newgroup) {
245
			if (empty(getGroupEntry($newgroup))) {
246
				$input_errors[] = gettext("One or more invalid groups was submitted.");
247
			}
248
		}
249
	}
250

    
251
	if (isset($id) && $a_user[$id]) {
252
		$oldusername = $a_user[$id]['name'];
253
	} else {
254
		$oldusername = "";
255
	}
256
	/* make sure this user name is unique */
257
	if (!$input_errors) {
258
		foreach ($a_user as $userent) {
259
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
260
				$input_errors[] = gettext("Another entry with the same username already exists.");
261
				break;
262
			}
263
		}
264
	}
265
	/* also make sure it is not reserved */
266
	if (!$input_errors) {
267
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
268
		foreach ($system_users as $s_user) {
269
			$ent = explode(":", $s_user);
270
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
271
				$input_errors[] = gettext("That username is reserved by the system.");
272
				break;
273
			}
274
		}
275
	}
276

    
277
	/*
278
	 * Check for a valid expiration date if one is set at all (valid means,
279
	 * DateTime puts out a time stamp so any DateTime compatible time
280
	 * format may be used. to keep it simple for the enduser, we only
281
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
282
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
283
	 * Otherwise such an entry would lead to an invalid expiration data.
284
	 */
285
	if ($_POST['expires']) {
286
		try {
287
			$expdate = new DateTime($_POST['expires']);
288
			//convert from any DateTime compatible date to MM/DD/YYYY
289
			$_POST['expires'] = $expdate->format("m/d/Y");
290
		} catch (Exception $ex) {
291
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
292
		}
293
	}
294

    
295
	if (!empty($_POST['name'])) {
296
		$ca = lookup_ca($_POST['caref']);
297
		if (!$ca) {
298
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
299
		}
300
	}
301
	validate_webguicss_field($input_errors, $_POST['webguicss']);
302
	validate_webguifixedmenu_field($input_errors, $_POST['webguifixedmenu']);
303
	validate_webguihostnamemenu_field($input_errors, $_POST['webguihostnamemenu']);
304
	validate_dashboardcolumns_field($input_errors, $_POST['dashboardcolumns']);
305

    
306
	if (!$input_errors) {
307

    
308
		$userent = array();
309
		if (isset($id) && $a_user[$id]) {
310
			$userent = $a_user[$id];
311
		}
312

    
313
		isset($_POST['utype']) ? $userent['scope'] = $_POST['utype'] : $userent['scope'] = "system";
314

    
315
		/* the user name was modified */
316
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
317
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
318
			local_user_del($userent);
319
		}
320

    
321
		/* the user password was modified */
322
		if ($_POST['passwordfld1']) {
323
			local_user_set_password($userent, $_POST['passwordfld1']);
324
		}
325

    
326
		/* only change description if sent */
327
		if (isset($_POST['descr'])) {
328
			$userent['descr'] = $_POST['descr'];
329
		}
330

    
331
		$userent['name'] = $_POST['usernamefld'];
332
		$userent['expires'] = $_POST['expires'];
333
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
334
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
335
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
336

    
337
		if ($_POST['disabled']) {
338
			$userent['disabled'] = true;
339
		} else {
340
			unset($userent['disabled']);
341
		}
342

    
343
		if ($_POST['customsettings']) {
344
			$userent['customsettings'] = true;
345
		} else {
346
			unset($userent['customsettings']);
347
		}
348

    
349
		if ($_POST['webguicss']) {
350
			$userent['webguicss'] = $_POST['webguicss'];
351
		} else {
352
			unset($userent['webguicss']);
353
		}
354

    
355
		if ($_POST['webguifixedmenu']) {
356
			$userent['webguifixedmenu'] = $_POST['webguifixedmenu'];
357
		} else {
358
			unset($userent['webguifixedmenu']);
359
		}
360

    
361
		if ($_POST['webguihostnamemenu']) {
362
			$userent['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
363
		} else {
364
			unset($userent['webguihostnamemenu']);
365
		}
366

    
367
		if ($_POST['interfacessort']) {
368
			$userent['interfacessort'] = true;
369
		} else {
370
			unset($userent['interfacessort']);
371
		}
372

    
373
		if ($_POST['dashboardavailablewidgetspanel']) {
374
			$userent['dashboardavailablewidgetspanel'] = true;
375
		} else {
376
			unset($userent['dashboardavailablewidgetspanel']);
377
		}
378

    
379
		if ($_POST['systemlogsfilterpanel']) {
380
			$userent['systemlogsfilterpanel'] = true;
381
		} else {
382
			unset($userent['systemlogsfilterpanel']);
383
		}
384

    
385
		if ($_POST['systemlogsmanagelogpanel']) {
386
			$userent['systemlogsmanagelogpanel'] = true;
387
		} else {
388
			unset($userent['systemlogsmanagelogpanel']);
389
		}
390

    
391
		if ($_POST['statusmonitoringsettingspanel']) {
392
			$userent['statusmonitoringsettingspanel'] = true;
393
		} else {
394
			unset($userent['statusmonitoringsettingspanel']);
395
		}
396

    
397
		if ($_POST['webguileftcolumnhyper']) {
398
			$userent['webguileftcolumnhyper'] = true;
399
		} else {
400
			unset($userent['webguileftcolumnhyper']);
401
		}
402

    
403
		if ($_POST['disablealiaspopupdetail']) {
404
			$userent['disablealiaspopupdetail'] = true;
405
		} else {
406
			unset($userent['disablealiaspopupdetail']);
407
		}
408

    
409
		if ($_POST['pagenamefirst']) {
410
			$userent['pagenamefirst'] = true;
411
		} else {
412
			unset($userent['pagenamefirst']);
413
		}
414

    
415
		if (isset($id) && $a_user[$id]) {
416
			$a_user[$id] = $userent;
417
		} else {
418
			if (!empty($_POST['name'])) {
419
				$cert = array();
420
				$cert['refid'] = uniqid();
421
				$userent['cert'] = array();
422

    
423
				$cert['descr'] = $_POST['name'];
424

    
425
				$subject = cert_get_subject_hash($ca['crt']);
426

    
427
				$dn = array();
428
				if (!empty($subject['C'])) {
429
					$dn['countryName'] = $subject['C'];
430
				}
431
				if (!empty($subject['ST'])) {
432
					$dn['stateOrProvinceName'] = $subject['ST'];
433
				}
434
				if (!empty($subject['L'])) {
435
					$dn['localityName'] = $subject['L'];
436
				}
437
				if (!empty($subject['O'])) {
438
					$dn['organizationName'] = $subject['O'];
439
				}
440
				if (!empty($subject['OU'])) {
441
					$dn['organizationalUnitName'] = $subject['OU'];
442
				}
443
				$dn['commonName'] = $userent['name'];
444
				$cn_altname = cert_add_altname_type($userent['name']);
445
				if (!empty($cn_altname)) {
446
					$dn['subjectAltName'] = $cn_altname;
447
				}
448

    
449
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
450
					(int)$_POST['lifetime'], $dn);
451

    
452
				if (!is_array($config['cert'])) {
453
					$config['cert'] = array();
454
				}
455
				$config['cert'][] = $cert;
456
				$userent['cert'][] = $cert['refid'];
457
			}
458
			$userent['uid'] = $config['system']['nextuid']++;
459
			/* Add the user to All Users group. */
460
			foreach ($config['system']['group'] as $gidx => $group) {
461
				if ($group['name'] == "all") {
462
					if (!is_array($config['system']['group'][$gidx]['member'])) {
463
						$config['system']['group'][$gidx]['member'] = array();
464
					}
465
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
466
					break;
467
				}
468
			}
469

    
470
			$a_user[] = $userent;
471
		}
472

    
473
		/* Sort it alphabetically */
474
		usort($config['system']['user'], function($a, $b) {
475
			return strcmp($a['name'], $b['name']);
476
		});
477

    
478
		local_user_set_groups($userent, $_POST['groups']);
479
		local_user_set($userent);
480
		$savemsg = sprintf(gettext("Successfully %s user %s"), (isset($id)) ? gettext("edited") : gettext("created"), $userent['name']);
481
		write_config($savemsg);
482
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
483
		if (is_dir("/etc/inc/privhooks")) {
484
			run_plugins("/etc/inc/privhooks");
485
		}
486

    
487
		pfSenseHeader("system_usermanager.php");
488
	}
489
}
490

    
491
function build_priv_table() {
492
	global $a_user, $id, $read_only;
493

    
494
	$privhtml = '<div class="table-responsive">';
495
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
496
	$privhtml .=		'<thead>';
497
	$privhtml .=			'<tr>';
498
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
499
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
500
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
501
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
502
	$privhtml .=			'</tr>';
503
	$privhtml .=		'</thead>';
504
	$privhtml .=		'<tbody>';
505

    
506
	$i = 0;
507
	$user_has_root_priv = false;
508

    
509
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
510
		$group = false;
511
		if ($priv['group']) {
512
			$group = $priv['group'];
513
		}
514

    
515
		$privhtml .=		'<tr>';
516
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
517
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
518
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
519
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
520
			$privhtml .=			' ' . gettext('(admin privilege)');
521
			$user_has_root_priv = true;
522
		}
523
		$privhtml .=			'</td>';
524
		$privhtml .=			'<td>';
525
		if (!$group && !$read_only) {
526
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
527
		}
528

    
529
		$privhtml .=			'</td>';
530
		$privhtml .=		'</tr>';
531

    
532
		if (!$group) {
533
			$i++;
534
		}
535
	}
536

    
537
	if ($user_has_root_priv) {
538
		$privhtml .=		'<tr>';
539
		$privhtml .=			'<td colspan="3">';
540
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
541
		$privhtml .=			'</td>';
542
		$privhtml .=			'<td>';
543
		$privhtml .=			'</td>';
544
		$privhtml .=		'</tr>';
545

    
546
	}
547

    
548
	$privhtml .=		'</tbody>';
549
	$privhtml .=	'</table>';
550
	$privhtml .= '</div>';
551

    
552
	$privhtml .= '<nav class="action-buttons">';
553
	if (!$read_only) {
554
		$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>';
555
	}
556
	$privhtml .= '</nav>';
557

    
558
	return($privhtml);
559
}
560

    
561
function build_cert_table() {
562
	global $a_user, $id, $read_only;
563

    
564
	$certhtml = '<div class="table-responsive">';
565
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
566
	$certhtml .=		'<thead>';
567
	$certhtml .=			'<tr>';
568
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
569
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
570
	$certhtml .=				'<th></th>';
571
	$certhtml .=			'</tr>';
572
	$certhtml .=		'</thead>';
573
	$certhtml .=		'<tbody>';
574

    
575
	$a_cert = $a_user[$id]['cert'];
576
	if (is_array($a_cert)) {
577
		$i = 0;
578
		foreach ($a_cert as $certref) {
579
			$cert = lookup_cert($certref);
580
			$ca = lookup_ca($cert['caref']);
581
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
582

    
583
			$certhtml .=	'<tr>';
584
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
585
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
586
			$certhtml .=		'<td>';
587
			if (!$read_only) {
588
				$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
589
				$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
590
			}
591
			$certhtml .=		'</td>';
592
			$certhtml .=	'</tr>';
593
			$i++;
594
		}
595

    
596
	}
597

    
598
	$certhtml .=		'</tbody>';
599
	$certhtml .=	'</table>';
600
	$certhtml .= '</div>';
601

    
602
	$certhtml .= '<nav class="action-buttons">';
603
	if (!$read_only) {
604
		$certhtml .=	'<a href="system_certmanager.php?act=new&amp;userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
605
	}
606
	$certhtml .= '</nav>';
607

    
608
	return($certhtml);
609
}
610

    
611
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
612
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
613

    
614
if ($act == "new" || $act == "edit" || $input_errors) {
615
	$pgtitle[] = gettext('Edit');
616
	$pglinks[] = "@self";
617
}
618

    
619
include("head.inc");
620

    
621
if ($delete_errors) {
622
	print_input_errors($delete_errors);
623
}
624

    
625
if ($input_errors) {
626
	print_input_errors($input_errors);
627
}
628

    
629
if ($savemsg) {
630
	print_info_box($savemsg, 'success');
631
}
632

    
633
$tab_array = array();
634
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
635
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
636
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
637
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
638
display_top_tabs($tab_array);
639

    
640
if (!($act == "new" || $act == "edit" || $input_errors)) {
641
?>
642
<form method="post">
643
<div class="panel panel-default">
644
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
645
	<div class="panel-body">
646
		<div class="table-responsive">
647
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
648
				<thead>
649
					<tr>
650
						<th>&nbsp;</th>
651
						<th><?=gettext("Username")?></th>
652
						<th><?=gettext("Full name")?></th>
653
						<th><?=gettext("Status")?></th>
654
						<th><?=gettext("Groups")?></th>
655
						<th><?=gettext("Actions")?></th>
656
					</tr>
657
				</thead>
658
				<tbody>
659
<?php
660
foreach ($a_user as $i => $userent):
661
	?>
662
					<tr>
663
						<td>
664
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
665
						</td>
666
						<td>
667
<?php
668
	if ($userent['scope'] != "user") {
669
		$usrimg = 'eye-open';
670
	} else {
671
		$usrimg = 'user';
672
	}
673
?>
674
							<i class="fa fa-<?=$usrimg?>"></i>
675
							<?=htmlspecialchars($userent['name'])?>
676
						</td>
677
						<td><?=htmlspecialchars($userent['descr'])?></td>
678
						<td><i class="fa fa-<?= (isset($userent['disabled'])) ? 'ban" title="' . gettext("Disabled") . '"' : 'check" title="' . gettext("Enabled") . '"' ; ?>><span style='display: none'><?= (isset($userent['disabled'])) ? gettext("Disabled") : gettext("Enabled") ; ?></span></i></td>
679
						<td><?=implode(",", local_user_get_groups($userent))?></td>
680
						<td>
681
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
682
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username']) && !$read_only): ?>
683
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>" usepost></a>
684
<?php endif; ?>
685
						</td>
686
					</tr>
687
<?php endforeach; ?>
688
				</tbody>
689
			</table>
690
		</div>
691
	</div>
692
</div>
693
<nav class="action-buttons">
694
	<?php if (!$read_only): ?>
695

    
696
	<a href="?act=new" class="btn btn-sm btn-success">
697
		<i class="fa fa-plus icon-embed-btn"></i>
698
		<?=gettext("Add")?>
699
	</a>
700

    
701
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
702
		<i class="fa fa-trash icon-embed-btn"></i>
703
		<?=gettext("Delete")?>
704
	</button>
705
	<?php endif; ?>
706

    
707
</nav>
708
</form>
709
<div class="infoblock">
710
<?php
711
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
712
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
713
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
714
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
715
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
716
	);
717

    
718
?></div>
719

    
720
<?php
721
	include("foot.inc");
722
	exit;
723
}
724

    
725
$form = new Form;
726

    
727
if ($act == "new" || $act == "edit" || $input_errors):
728

    
729
	$form->addGlobal(new Form_Input(
730
		'act',
731
		null,
732
		'hidden',
733
		''
734
	));
735

    
736
	$form->addGlobal(new Form_Input(
737
		'userid',
738
		null,
739
		'hidden',
740
		isset($id) ? $id:''
741
	));
742

    
743
	$form->addGlobal(new Form_Input(
744
		'privid',
745
		null,
746
		'hidden',
747
		''
748
	));
749

    
750
	$form->addGlobal(new Form_Input(
751
		'certid',
752
		null,
753
		'hidden',
754
		''
755
	));
756

    
757
	$ro = "";
758
	if ($pconfig['utype'] == "system") {
759
		$ro = "readonly";
760
	}
761

    
762
	$section = new Form_Section('User Properties');
763

    
764
	$section->addInput(new Form_StaticText(
765
		'Defined by',
766
		strtoupper($pconfig['utype'])
767
	));
768

    
769
	$form->addGlobal(new Form_Input(
770
		'utype',
771
		null,
772
		'hidden',
773
		$pconfig['utype']
774
	));
775

    
776
	$section->addInput(new Form_Checkbox(
777
		'disabled',
778
		'Disabled',
779
		'This user cannot login',
780
		$pconfig['disabled']
781
	));
782

    
783
	$section->addInput($input = new Form_Input(
784
		'usernamefld',
785
		'*Username',
786
		'text',
787
		$pconfig['usernamefld'],
788
		['autocomplete' => 'new-password']
789
	));
790

    
791
	if ($ro) {
792
		$input->setReadonly();
793
	}
794

    
795
	$form->addGlobal(new Form_Input(
796
		'oldusername',
797
		null,
798
		'hidden',
799
		$pconfig['usernamefld']
800
	));
801

    
802
	if ($act == "edit") {
803
		$pwd_required = "";
804
	} else {
805
		$pwd_required = "*";
806
	}
807

    
808
	$group = new Form_Group($pwd_required . 'Password');
809
	$group->add(new Form_Input(
810
		'passwordfld1',
811
		'Password',
812
		'password',
813
		null,
814
		['autocomplete' => 'new-password']
815
	));
816
	$group->add(new Form_Input(
817
		'passwordfld2',
818
		'Confirm Password',
819
		'password',
820
		null,
821
		['autocomplete' => 'new-password']
822
	));
823

    
824
	$section->add($group);
825

    
826
	$section->addInput($input = new Form_Input(
827
		'descr',
828
		'Full name',
829
		'text',
830
		htmlspecialchars($pconfig['descr'])
831
	))->setHelp('User\'s full name, for administrative information only');
832

    
833
	if ($ro) {
834
		$input->setDisabled();
835
	}
836

    
837
	$section->addInput(new Form_Input(
838
		'expires',
839
		'Expiration date',
840
		'text',
841
		$pconfig['expires']
842
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
843
		'the expiration date as MM/DD/YYYY');
844

    
845
	$section->addInput(new Form_Checkbox(
846
		'customsettings',
847
		'Custom Settings',
848
		'Use individual customized GUI options and dashboard layout for this user.',
849
		$pconfig['customsettings']
850
	));
851

    
852
	gen_user_settings_fields($section, $pconfig);
853

    
854
	// ==== Group membership ==================================================
855
	$group = new Form_Group('Group membership');
856

    
857
	// Make a list of all the groups configured on the system, and a list of
858
	// those which this user is a member of
859
	$systemGroups = array();
860
	$usersGroups = array();
861

    
862
	$usergid = [$pconfig['usernamefld']];
863

    
864
	foreach ($config['system']['group'] as $Ggroup) {
865
		if ($Ggroup['name'] != "all") {
866
			if (($act == 'edit' || $input_errors) && $Ggroup['member'] && in_array($a_user[$id]['uid'], $Ggroup['member'])) {
867
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
868
			} else {
869
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
870
			}
871
		}
872
	}
873

    
874
	$group->add(new Form_Select(
875
		'sysgroups',
876
		null,
877
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
878
		$systemGroups,
879
		true
880
	))->setHelp('Not member of');
881

    
882
	$group->add(new Form_Select(
883
		'groups',
884
		null,
885
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
886
		$usersGroups,
887
		true
888
	))->setHelp('Member of');
889

    
890
	$section->add($group);
891

    
892
	$group = new Form_Group('');
893

    
894
	$group->add(new Form_Button(
895
		'movetoenabled',
896
		'Move to "Member of" list',
897
		null,
898
		'fa-angle-double-right'
899
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
900

    
901
	$group->add(new Form_Button(
902
		'movetodisabled',
903
		'Move to "Not member of" list',
904
		null,
905
		'fa-angle-double-left'
906
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
907

    
908
	$group->setHelp('Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items.');
909
	$section->add($group);
910

    
911
	// ==== Button for adding user certificate ================================
912
	if ($act == 'new') {
913
		if (count($nonPrvCas) > 0) {
914
			$section->addInput(new Form_Checkbox(
915
				'showcert',
916
				'Certificate',
917
				'Click to create a user certificate',
918
				false
919
			));
920
		} else {
921
			$section->addInput(new Form_StaticText(
922
				'Certificate',
923
				gettext('No private CAs found. A private CA is required to create a new user certificate. ' .
924
					'Save the user first to import an external certificate.')
925
			));
926
		}
927
	}
928

    
929
	$form->add($section);
930

    
931
	// ==== Effective privileges section ======================================
932
	if (isset($pconfig['uid'])) {
933
		// We are going to build an HTML table and add it to an Input_StaticText. It may be ugly, but it
934
		// is the best way to make the display we need.
935

    
936
		$section = new Form_Section('Effective Privileges');
937

    
938
		$section->addInput(new Form_StaticText(
939
			null,
940
			build_priv_table()
941
		));
942

    
943
		$form->add($section);
944

    
945
		// ==== Certificate table section =====================================
946
		$section = new Form_Section('User Certificates');
947

    
948
		$section->addInput(new Form_StaticText(
949
			null,
950
			build_cert_table()
951
		));
952

    
953
		$form->add($section);
954
	}
955

    
956
	// ==== Add user certificate for a new user
957
	if (is_array($config['ca']) && count($config['ca']) > 0) {
958
		$section = new Form_Section('Create Certificate for User');
959
		$section->addClass('cert-options');
960

    
961
		if (!empty($nonPrvCas)) {
962
			$section->addInput(new Form_Input(
963
				'name',
964
				'Descriptive name',
965
				'text',
966
				$pconfig['name']
967
			));
968

    
969
			$section->addInput(new Form_Select(
970
				'caref',
971
				'Certificate authority',
972
				null,
973
				$nonPrvCas
974
			));
975

    
976
			$section->addInput(new Form_Select(
977
				'keylen',
978
				'Key length',
979
				2048,
980
				array(
981
					512 => '512 bits',
982
					1024 => '1024 bits',
983
					2048 => '2048 bits',
984
					3072 => '3072 bits',
985
					4096 => '4096 bits',
986
					7680 => '7680 bits',
987
					8192 => '8192 bits',
988
					15360 => '15360 bits',
989
					16384 => '16384 bits'
990
				)
991
			))->setHelp('The larger the key, the more security it offers, but larger keys take considerably more time to generate, ' .
992
				'and take slightly longer to validate leading to a slight slowdown in setting up new sessions (not always noticeable). ' .
993
				'As of 2016, 2048 bit is the minimum and most common selection and 4096 is the maximum in common use. ' .
994
				'For more information see %1$s.', '<a href="https://keylength.com">keylength.com</a>');
995

    
996
			$section->addInput(new Form_Input(
997
				'lifetime',
998
				'Lifetime',
999
				'number',
1000
				$pconfig['lifetime']
1001
			));
1002
		}
1003

    
1004
		$form->add($section);
1005
	}
1006

    
1007
endif;
1008
// ==== Paste a key for the new user
1009
$section = new Form_Section('Keys');
1010

    
1011
$section->addInput(new Form_Checkbox(
1012
	'showkey',
1013
	'Authorized keys',
1014
	'Click to paste an authorized key',
1015
	false
1016
));
1017

    
1018
$section->addInput(new Form_Textarea(
1019
	'authorizedkeys',
1020
	'Authorized SSH Keys',
1021
	$pconfig['authorizedkeys']
1022
))->setHelp('Enter authorized SSH keys for this user');
1023

    
1024
$section->addInput(new Form_Input(
1025
	'ipsecpsk',
1026
	'IPsec Pre-Shared Key',
1027
	'text',
1028
	$pconfig['ipsecpsk']
1029
));
1030

    
1031
$form->add($section);
1032

    
1033
print $form;
1034

    
1035
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
1036
?>
1037
<script type="text/javascript">
1038
//<![CDATA[
1039
events.push(function() {
1040

    
1041
	function setcustomoptions() {
1042
		var adv = $('#customsettings').prop('checked');
1043

    
1044
		hideInput('webguicss', !adv);
1045
		hideInput('webguifixedmenu', !adv);
1046
		hideInput('webguihostnamemenu', !adv);
1047
		hideInput('dashboardcolumns', !adv);
1048
		hideCheckbox('interfacessort', !adv);
1049
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
1050
		hideCheckbox('systemlogsfilterpanel', !adv);
1051
		hideCheckbox('systemlogsmanagelogpanel', !adv);
1052
		hideCheckbox('statusmonitoringsettingspanel', !adv);
1053
		hideCheckbox('webguileftcolumnhyper', !adv);
1054
		hideCheckbox('disablealiaspopupdetail', !adv);
1055
		hideCheckbox('pagenamefirst', !adv);
1056
	}
1057

    
1058
	// Handle displaying a warning message if a user-created theme is selected.
1059
	function setThemeWarning() {
1060
		if ($('#webguicss').val().startsWith("pfSense")) {
1061
			$('#csstxt').html("").addClass("text-default");
1062
		} else {
1063
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
1064
		}
1065
	}
1066

    
1067
	$('#webguicss').change(function() {
1068
		setThemeWarning();
1069
	});
1070

    
1071
	setThemeWarning();
1072

    
1073
	// On click . .
1074
	$('#customsettings').click(function () {
1075
		setcustomoptions();
1076
	});
1077

    
1078
	$("#movetodisabled").click(function() {
1079
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1080
	});
1081

    
1082
	$("#movetoenabled").click(function() {
1083
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1084
	});
1085

    
1086
	$("#showcert").click(function() {
1087
		hideClass('cert-options', !this.checked);
1088
	});
1089

    
1090
	$("#showkey").click(function() {
1091
		hideInput('authorizedkeys', false);
1092
		hideCheckbox('showkey', true);
1093
	});
1094

    
1095
	$('[id^=delcert]').click(function(event) {
1096
		if (confirm(event.target.title)) {
1097
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
1098
			$('#userid').val('<?=$id;?>');
1099
			$('#act').val('delcert');
1100
			$('form').submit();
1101
		}
1102
	});
1103

    
1104
	$('[id^=delprivid]').click(function(event) {
1105
		if (confirm(event.target.title)) {
1106
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
1107
			$('#userid').val('<?=$id;?>');
1108
			$('#act').val('delprivid');
1109
			$('form').submit();
1110
		}
1111
	});
1112

    
1113
	$('#expires').datepicker();
1114

    
1115
	// ---------- On initial page load ------------------------------------------------------------
1116

    
1117
	hideClass('cert-options', true);
1118
	//hideInput('authorizedkeys', true);
1119
	hideCheckbox('showkey', true);
1120
	setcustomoptions();
1121

    
1122
	// On submit mark all the user's groups as "selected"
1123
	$('form').submit(function() {
1124
		AllServers($('[name="groups[]"] option'), true);
1125
	});
1126

    
1127
});
1128
//]]>
1129
</script>
1130
<?php
1131
include('foot.inc');
1132
?>
(207-207/227)