Project

General

Profile

Download (31.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-2018 Rubicon Communications, LLC (Netgate)
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
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

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

    
36
require_once("certs.inc");
37
require_once("guiconfig.inc");
38
require_once("pfsense-utils.inc");
39

    
40
$logging_level = LOG_WARNING;
41
$logging_prefix = gettext("Local User Database");
42

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

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

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

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

    
84
if ($_POST['act'] == "deluser") {
85

    
86
	if (!isset($_POST['username']) || !isset($a_user[$id]) || ($_POST['username'] != $a_user[$id]['name'])) {
87
		pfSenseHeader("system_usermanager.php");
88
		exit;
89
	}
90

    
91
	if ($_POST['username'] == $_SESSION['Username']) {
92
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_POST['username']);
93
	} else {
94
		local_user_del($a_user[$id]);
95
		$userdeleted = $a_user[$id]['name'];
96
		unset($a_user[$id]);
97
		/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
98
		$a_user = array_values($a_user);
99
		$savemsg = sprintf(gettext("Successfully deleted user: %s"), $userdeleted);
100
		write_config($savemsg);
101
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
102
	}
103

    
104
} else if ($act == "new") {
105
	/*
106
	 * set this value cause the text field is read only
107
	 * and the user should not be able to mess with this
108
	 * setting.
109
	 */
110
	$pconfig['utype'] = "user";
111
	$pconfig['lifetime'] = 3650;
112

    
113
	$nonPrvCas = array();
114
	if (is_array($config['ca']) && count($config['ca']) > 0) {
115
		foreach ($config['ca'] as $ca) {
116
			if (!$ca['prv']) {
117
				continue;
118
			}
119

    
120
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
121
		}
122
	}
123

    
124
}
125

    
126
if (isset($_POST['dellall'])) {
127

    
128
	$del_users = $_POST['delete_check'];
129
	$deleted_users = array();
130

    
131
	if (!empty($del_users)) {
132
		foreach ($del_users as $userid) {
133
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
134
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
135
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
136
				} else {
137
					$deleted_users[] = $a_user[$userid]['name'];
138
					local_user_del($a_user[$userid]);
139
					unset($a_user[$userid]);
140
				}
141
			} else {
142
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
143
			}
144
		}
145

    
146
		if (count($deleted_users) > 0) {
147
			$savemsg = sprintf(gettext("Successfully deleted %s: %s"), (count($deleted_users) == 1) ? gettext("user") : gettext("users"), implode(', ', $deleted_users));
148
			/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
149
			$a_user = array_values($a_user);
150
			write_config($savemsg);
151
			syslog($logging_level, "{$logging_prefix}: {$savemsg}");
152
		}
153
	}
154
}
155

    
156
if ($_POST['act'] == "delcert") {
157

    
158
	if (!$a_user[$id]) {
159
		pfSenseHeader("system_usermanager.php");
160
		exit;
161
	}
162

    
163
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
164
	$certdeleted = $certdeleted['descr'];
165
	unset($a_user[$id]['cert'][$_POST['certid']]);
166
	$savemsg = sprintf(gettext("Removed certificate association \"%s\" from user %s"), $certdeleted, $a_user[$id]['name']);
167
	write_config($savemsg);
168
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
169
	$_POST['act'] = "edit";
170
}
171

    
172
if ($_POST['act'] == "delprivid") {
173
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
174
	unset($a_user[$id]['priv'][$_POST['privid']]);
175
	local_user_set($a_user[$id]);
176
	$savemsg = sprintf(gettext("Removed Privilege \"%s\" from user %s"), $privdeleted, $a_user[$id]['name']);
177
	write_config($savemsg);
178
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
179
	$_POST['act'] = "edit";
180
}
181

    
182
if ($_POST['save']) {
183
	unset($input_errors);
184
	$pconfig = $_POST;
185

    
186
	/* input validation */
187
	if (isset($id) && ($a_user[$id])) {
188
		$reqdfields = explode(" ", "usernamefld");
189
		$reqdfieldsn = array(gettext("Username"));
190
	} else {
191
		if (empty($_POST['name'])) {
192
			$reqdfields = explode(" ", "usernamefld passwordfld1");
193
			$reqdfieldsn = array(
194
				gettext("Username"),
195
				gettext("Password"));
196
		} else {
197
			$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
198
			$reqdfieldsn = array(
199
				gettext("Username"),
200
				gettext("Password"),
201
				gettext("Descriptive name"),
202
				gettext("Certificate authority"),
203
				gettext("Key length"),
204
				gettext("Lifetime"));
205
		}
206
	}
207

    
208
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
209

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

    
214
	if (strlen($_POST['usernamefld']) > 32) {
215
		$input_errors[] = gettext("The username is longer than 32 characters.");
216
	}
217

    
218
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
219
		$input_errors[] = gettext("The passwords do not match.");
220
	}
221

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

    
226
	/* Check the POSTed groups to ensure they are valid and exist */
227
	if (is_array($_POST['groups'])) {
228
		foreach ($_POST['groups'] as $newgroup) {
229
			if (empty(getGroupEntry($newgroup))) {
230
				$input_errors[] = gettext("One or more invalid groups was submitted.");
231
			}
232
		}
233
	}
234

    
235
	if (isset($id) && $a_user[$id]) {
236
		$oldusername = $a_user[$id]['name'];
237
	} else {
238
		$oldusername = "";
239
	}
240
	/* make sure this user name is unique */
241
	if (!$input_errors) {
242
		foreach ($a_user as $userent) {
243
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
244
				$input_errors[] = gettext("Another entry with the same username already exists.");
245
				break;
246
			}
247
		}
248
	}
249
	/* also make sure it is not reserved */
250
	if (!$input_errors) {
251
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
252
		foreach ($system_users as $s_user) {
253
			$ent = explode(":", $s_user);
254
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
255
				$input_errors[] = gettext("That username is reserved by the system.");
256
				break;
257
			}
258
		}
259
	}
260

    
261
	/*
262
	 * Check for a valid expiration date if one is set at all (valid means,
263
	 * DateTime puts out a time stamp so any DateTime compatible time
264
	 * format may be used. to keep it simple for the enduser, we only
265
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
266
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
267
	 * Otherwise such an entry would lead to an invalid expiration data.
268
	 */
269
	if ($_POST['expires']) {
270
		try {
271
			$expdate = new DateTime($_POST['expires']);
272
			//convert from any DateTime compatible date to MM/DD/YYYY
273
			$_POST['expires'] = $expdate->format("m/d/Y");
274
		} catch (Exception $ex) {
275
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
276
		}
277
	}
278

    
279
	if (!empty($_POST['name'])) {
280
		$ca = lookup_ca($_POST['caref']);
281
		if (!$ca) {
282
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
283
		}
284
	}
285
	validate_webguicss_field($input_errors, $_POST['webguicss']);
286
	validate_webguifixedmenu_field($input_errors, $_POST['webguifixedmenu']);
287
	validate_webguihostnamemenu_field($input_errors, $_POST['webguihostnamemenu']);
288
	validate_dashboardcolumns_field($input_errors, $_POST['dashboardcolumns']);
289

    
290
	if (!$input_errors) {
291

    
292
		$userent = array();
293
		if (isset($id) && $a_user[$id]) {
294
			$userent = $a_user[$id];
295
		}
296

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

    
299
		/* the user name was modified */
300
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
301
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
302
			local_user_del($userent);
303
		}
304

    
305
		/* the user password was modified */
306
		if ($_POST['passwordfld1']) {
307
			local_user_set_password($userent, $_POST['passwordfld1']);
308
		}
309

    
310
		/* only change description if sent */
311
		if (isset($_POST['descr'])) {
312
			$userent['descr'] = $_POST['descr'];
313
		}
314

    
315
		$userent['name'] = $_POST['usernamefld'];
316
		$userent['expires'] = $_POST['expires'];
317
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
318
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
319
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
320

    
321
		if ($_POST['disabled']) {
322
			$userent['disabled'] = true;
323
		} else {
324
			unset($userent['disabled']);
325
		}
326

    
327
		if ($_POST['customsettings']) {
328
			$userent['customsettings'] = true;
329
		} else {
330
			unset($userent['customsettings']);
331
		}
332

    
333
		if ($_POST['webguicss']) {
334
			$userent['webguicss'] = $_POST['webguicss'];
335
		} else {
336
			unset($userent['webguicss']);
337
		}
338

    
339
		if ($_POST['webguifixedmenu']) {
340
			$userent['webguifixedmenu'] = $_POST['webguifixedmenu'];
341
		} else {
342
			unset($userent['webguifixedmenu']);
343
		}
344

    
345
		if ($_POST['webguihostnamemenu']) {
346
			$userent['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
347
		} else {
348
			unset($userent['webguihostnamemenu']);
349
		}
350

    
351
		if ($_POST['interfacessort']) {
352
			$userent['interfacessort'] = true;
353
		} else {
354
			unset($userent['interfacessort']);
355
		}
356

    
357
		if ($_POST['dashboardavailablewidgetspanel']) {
358
			$userent['dashboardavailablewidgetspanel'] = true;
359
		} else {
360
			unset($userent['dashboardavailablewidgetspanel']);
361
		}
362

    
363
		if ($_POST['systemlogsfilterpanel']) {
364
			$userent['systemlogsfilterpanel'] = true;
365
		} else {
366
			unset($userent['systemlogsfilterpanel']);
367
		}
368

    
369
		if ($_POST['systemlogsmanagelogpanel']) {
370
			$userent['systemlogsmanagelogpanel'] = true;
371
		} else {
372
			unset($userent['systemlogsmanagelogpanel']);
373
		}
374

    
375
		if ($_POST['statusmonitoringsettingspanel']) {
376
			$userent['statusmonitoringsettingspanel'] = true;
377
		} else {
378
			unset($userent['statusmonitoringsettingspanel']);
379
		}
380

    
381
		if ($_POST['webguileftcolumnhyper']) {
382
			$userent['webguileftcolumnhyper'] = true;
383
		} else {
384
			unset($userent['webguileftcolumnhyper']);
385
		}
386

    
387
		if ($_POST['disablealiaspopupdetail']) {
388
			$userent['disablealiaspopupdetail'] = true;
389
		} else {
390
			unset($userent['disablealiaspopupdetail']);
391
		}
392

    
393
		if ($_POST['pagenamefirst']) {
394
			$userent['pagenamefirst'] = true;
395
		} else {
396
			unset($userent['pagenamefirst']);
397
		}
398

    
399
		if (isset($id) && $a_user[$id]) {
400
			$a_user[$id] = $userent;
401
		} else {
402
			if (!empty($_POST['name'])) {
403
				$cert = array();
404
				$cert['refid'] = uniqid();
405
				$userent['cert'] = array();
406

    
407
				$cert['descr'] = $_POST['name'];
408

    
409
				$subject = cert_get_subject_hash($ca['crt']);
410

    
411
				$dn = array();
412
				if (!empty($subject['C'])) {
413
					$dn['countryName'] = $subject['C'];
414
				}
415
				if (!empty($subject['ST'])) {
416
					$dn['stateOrProvinceName'] = $subject['ST'];
417
				}
418
				if (!empty($subject['L'])) {
419
					$dn['localityName'] = $subject['L'];
420
				}
421
				if (!empty($subject['O'])) {
422
					$dn['organizationName'] = $subject['O'];
423
				}
424
				if (!empty($subject['OU'])) {
425
					$dn['organizationalUnit'] = $subject['OU'];
426
				}
427
				$dn['commonName'] = $userent['name'];
428
				$cn_altname = cert_add_altname_type($userent['name']);
429
				if (!empty($cn_altname)) {
430
					$dn['subjectAltName'] = $cn_altname;
431
				}
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
		/* Sort it alphabetically */
458
		usort($config['system']['user'], function($a, $b) {
459
			return strcmp($a['name'], $b['name']);
460
		});
461

    
462
		local_user_set_groups($userent, $_POST['groups']);
463
		local_user_set($userent);
464
		$savemsg = sprintf(gettext("Successfully %s user %s"), (isset($id)) ? gettext("edited") : gettext("created"), $userent['name']);
465
		write_config($savemsg);
466
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
467
		if (is_dir("/etc/inc/privhooks")) {
468
			run_plugins("/etc/inc/privhooks");
469
		}
470

    
471
		pfSenseHeader("system_usermanager.php");
472
	}
473
}
474

    
475
function build_priv_table() {
476
	global $a_user, $id;
477

    
478
	$privhtml = '<div class="table-responsive">';
479
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
480
	$privhtml .=		'<thead>';
481
	$privhtml .=			'<tr>';
482
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
483
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
484
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
485
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
486
	$privhtml .=			'</tr>';
487
	$privhtml .=		'</thead>';
488
	$privhtml .=		'<tbody>';
489

    
490
	$i = 0;
491
	$user_has_root_priv = false;
492

    
493
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
494
		$group = false;
495
		if ($priv['group']) {
496
			$group = $priv['group'];
497
		}
498

    
499
		$privhtml .=		'<tr>';
500
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
501
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
502
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
503
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
504
			$privhtml .=			' ' . gettext('(admin privilege)');
505
			$user_has_root_priv = true;
506
		}
507
		$privhtml .=			'</td>';
508
		$privhtml .=			'<td>';
509
		if (!$group) {
510
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
511
		}
512

    
513
		$privhtml .=			'</td>';
514
		$privhtml .=		'</tr>';
515

    
516
		if (!$group) {
517
			$i++;
518
		}
519
	}
520

    
521
	if ($user_has_root_priv) {
522
		$privhtml .=		'<tr>';
523
		$privhtml .=			'<td colspan="3">';
524
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
525
		$privhtml .=			'</td>';
526
		$privhtml .=			'<td>';
527
		$privhtml .=			'</td>';
528
		$privhtml .=		'</tr>';
529

    
530
	}
531

    
532
	$privhtml .=		'</tbody>';
533
	$privhtml .=	'</table>';
534
	$privhtml .= '</div>';
535

    
536
	$privhtml .= '<nav class="action-buttons">';
537
	$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>';
538
	$privhtml .= '</nav>';
539

    
540
	return($privhtml);
541
}
542

    
543
function build_cert_table() {
544
	global $a_user, $id;
545

    
546
	$certhtml = '<div class="table-responsive">';
547
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
548
	$certhtml .=		'<thead>';
549
	$certhtml .=			'<tr>';
550
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
551
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
552
	$certhtml .=				'<th></th>';
553
	$certhtml .=			'</tr>';
554
	$certhtml .=		'</thead>';
555
	$certhtml .=		'<tbody>';
556

    
557
	$a_cert = $a_user[$id]['cert'];
558
	if (is_array($a_cert)) {
559
		$i = 0;
560
		foreach ($a_cert as $certref) {
561
			$cert = lookup_cert($certref);
562
			$ca = lookup_ca($cert['caref']);
563
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
564

    
565
			$certhtml .=	'<tr>';
566
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
567
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
568
			$certhtml .=		'<td>';
569
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
570
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
571
			$certhtml .=		'</td>';
572
			$certhtml .=	'</tr>';
573
			$i++;
574
		}
575

    
576
	}
577

    
578
	$certhtml .=		'</tbody>';
579
	$certhtml .=	'</table>';
580
	$certhtml .= '</div>';
581

    
582
	$certhtml .= '<nav class="action-buttons">';
583
	$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>';
584
	$certhtml .= '</nav>';
585

    
586
	return($certhtml);
587
}
588

    
589
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
590
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
591

    
592
if ($act == "new" || $act == "edit" || $input_errors) {
593
	$pgtitle[] = gettext('Edit');
594
	$pglinks[] = "@self";
595
}
596

    
597
include("head.inc");
598

    
599
if ($delete_errors) {
600
	print_input_errors($delete_errors);
601
}
602

    
603
if ($input_errors) {
604
	print_input_errors($input_errors);
605
}
606

    
607
if ($savemsg) {
608
	print_info_box($savemsg, 'success');
609
}
610

    
611
$tab_array = array();
612
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
613
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
614
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
615
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
616
display_top_tabs($tab_array);
617

    
618
if (!($act == "new" || $act == "edit" || $input_errors)) {
619
?>
620
<form method="post">
621
<div class="panel panel-default">
622
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
623
	<div class="panel-body">
624
		<div class="table-responsive">
625
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
626
				<thead>
627
					<tr>
628
						<th>&nbsp;</th>
629
						<th><?=gettext("Username")?></th>
630
						<th><?=gettext("Full name")?></th>
631
						<th><?=gettext("Status")?></th>
632
						<th><?=gettext("Groups")?></th>
633
						<th><?=gettext("Actions")?></th>
634
					</tr>
635
				</thead>
636
				<tbody>
637
<?php
638
foreach ($a_user as $i => $userent):
639
	?>
640
					<tr>
641
						<td>
642
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
643
						</td>
644
						<td>
645
<?php
646
	if ($userent['scope'] != "user") {
647
		$usrimg = 'eye-open';
648
	} else {
649
		$usrimg = 'user';
650
	}
651
?>
652
							<i class="fa fa-<?=$usrimg?>"></i>
653
							<?=htmlspecialchars($userent['name'])?>
654
						</td>
655
						<td><?=htmlspecialchars($userent['descr'])?></td>
656
						<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>
657
						<td><?=implode(",", local_user_get_groups($userent))?></td>
658
						<td>
659
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
660
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
661
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>" usepost></a>
662
<?php endif; ?>
663
						</td>
664
					</tr>
665
<?php endforeach; ?>
666
				</tbody>
667
			</table>
668
		</div>
669
	</div>
670
</div>
671
<nav class="action-buttons">
672
	<a href="?act=new" class="btn btn-sm btn-success">
673
		<i class="fa fa-plus icon-embed-btn"></i>
674
		<?=gettext("Add")?>
675
	</a>
676

    
677
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
678
		<i class="fa fa-trash icon-embed-btn"></i>
679
		<?=gettext("Delete")?>
680
	</button>
681

    
682
</nav>
683
</form>
684
<div class="infoblock">
685
<?php
686
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
687
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
688
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
689
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
690
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
691
	);
692

    
693
?></div>
694

    
695
<?php
696
	include("foot.inc");
697
	exit;
698
}
699

    
700
$form = new Form;
701

    
702
if ($act == "new" || $act == "edit" || $input_errors):
703

    
704
	$form->addGlobal(new Form_Input(
705
		'act',
706
		null,
707
		'hidden',
708
		''
709
	));
710

    
711
	$form->addGlobal(new Form_Input(
712
		'userid',
713
		null,
714
		'hidden',
715
		isset($id) ? $id:''
716
	));
717

    
718
	$form->addGlobal(new Form_Input(
719
		'privid',
720
		null,
721
		'hidden',
722
		''
723
	));
724

    
725
	$form->addGlobal(new Form_Input(
726
		'certid',
727
		null,
728
		'hidden',
729
		''
730
	));
731

    
732
	$ro = "";
733
	if ($pconfig['utype'] == "system") {
734
		$ro = "readonly";
735
	}
736

    
737
	$section = new Form_Section('User Properties');
738

    
739
	$section->addInput(new Form_StaticText(
740
		'Defined by',
741
		strtoupper($pconfig['utype'])
742
	));
743

    
744
	$form->addGlobal(new Form_Input(
745
		'utype',
746
		null,
747
		'hidden',
748
		$pconfig['utype']
749
	));
750

    
751
	$section->addInput(new Form_Checkbox(
752
		'disabled',
753
		'Disabled',
754
		'This user cannot login',
755
		$pconfig['disabled']
756
	));
757

    
758
	$section->addInput($input = new Form_Input(
759
		'usernamefld',
760
		'*Username',
761
		'text',
762
		$pconfig['usernamefld']
763
	));
764

    
765
	if ($ro) {
766
		$input->setReadonly();
767
	}
768

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

    
776
	if ($act == "edit") {
777
		$pwd_required = "";
778
	} else {
779
		$pwd_required = "*";
780
	}
781

    
782
	$group = new Form_Group($pwd_required . 'Password');
783
	$group->add(new Form_Input(
784
		'passwordfld1',
785
		'Password',
786
		'password'
787
	));
788
	$group->add(new Form_Input(
789
		'passwordfld2',
790
		'Confirm Password',
791
		'password'
792
	));
793

    
794
	$section->add($group);
795

    
796
	$section->addInput($input = new Form_Input(
797
		'descr',
798
		'Full name',
799
		'text',
800
		htmlspecialchars($pconfig['descr'])
801
	))->setHelp('User\'s full name, for administrative information only');
802

    
803
	if ($ro) {
804
		$input->setDisabled();
805
	}
806

    
807
	$section->addInput(new Form_Input(
808
		'expires',
809
		'Expiration date',
810
		'text',
811
		$pconfig['expires']
812
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
813
		'the expiration date as MM/DD/YYYY');
814

    
815
	$section->addInput(new Form_Checkbox(
816
		'customsettings',
817
		'Custom Settings',
818
		'Use individual customized GUI options and dashboard layout for this user.',
819
		$pconfig['customsettings']
820
	));
821

    
822
	gen_user_settings_fields($section, $pconfig);
823

    
824
	// ==== Group membership ==================================================
825
	$group = new Form_Group('Group membership');
826

    
827
	// Make a list of all the groups configured on the system, and a list of
828
	// those which this user is a member of
829
	$systemGroups = array();
830
	$usersGroups = array();
831

    
832
	$usergid = [$pconfig['usernamefld']];
833

    
834
	foreach ($config['system']['group'] as $Ggroup) {
835
		if ($Ggroup['name'] != "all") {
836
			if (($act == 'edit' || $input_errors) && $Ggroup['member'] && in_array($a_user[$id]['uid'], $Ggroup['member'])) {
837
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
838
			} else {
839
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
840
			}
841
		}
842
	}
843

    
844
	$group->add(new Form_Select(
845
		'sysgroups',
846
		null,
847
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
848
		$systemGroups,
849
		true
850
	))->setHelp('Not member of');
851

    
852
	$group->add(new Form_Select(
853
		'groups',
854
		null,
855
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
856
		$usersGroups,
857
		true
858
	))->setHelp('Member of');
859

    
860
	$section->add($group);
861

    
862
	$group = new Form_Group('');
863

    
864
	$group->add(new Form_Button(
865
		'movetoenabled',
866
		'Move to "Member of" list',
867
		null,
868
		'fa-angle-double-right'
869
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
870

    
871
	$group->add(new Form_Button(
872
		'movetodisabled',
873
		'Move to "Not member of" list',
874
		null,
875
		'fa-angle-double-left'
876
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
877

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

    
881
	// ==== Button for adding user certificate ================================
882
	if ($act == 'new') {
883
		if (count($nonPrvCas) > 0) {
884
			$section->addInput(new Form_Checkbox(
885
				'showcert',
886
				'Certificate',
887
				'Click to create a user certificate',
888
				false
889
			));
890
		} else {
891
			$section->addInput(new Form_StaticText(
892
				'Certificate',
893
				gettext('No private CAs found. A private CA is required to create a new user certificate. ' .
894
					'Save the user first to import an external certificate.')
895
			));
896
		}
897
	}
898

    
899
	$form->add($section);
900

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

    
906
		$section = new Form_Section('Effective Privileges');
907

    
908
		$section->addInput(new Form_StaticText(
909
			null,
910
			build_priv_table()
911
		));
912

    
913
		$form->add($section);
914

    
915
		// ==== Certificate table section =====================================
916
		$section = new Form_Section('User Certificates');
917

    
918
		$section->addInput(new Form_StaticText(
919
			null,
920
			build_cert_table()
921
		));
922

    
923
		$form->add($section);
924
	}
925

    
926
	// ==== Add user certificate for a new user
927
	if (is_array($config['ca']) && count($config['ca']) > 0) {
928
		$section = new Form_Section('Create Certificate for User');
929
		$section->addClass('cert-options');
930

    
931
		if (!empty($nonPrvCas)) {
932
			$section->addInput(new Form_Input(
933
				'name',
934
				'Descriptive name',
935
				'text',
936
				$pconfig['name']
937
			));
938

    
939
			$section->addInput(new Form_Select(
940
				'caref',
941
				'Certificate authority',
942
				null,
943
				$nonPrvCas
944
			));
945

    
946
			$section->addInput(new Form_Select(
947
				'keylen',
948
				'Key length',
949
				2048,
950
				array(
951
					512 => '512 bits',
952
					1024 => '1024 bits',
953
					2048 => '2048 bits',
954
					3072 => '3072 bits',
955
					4096 => '4096 bits',
956
					7680 => '7680 bits',
957
					8192 => '8192 bits',
958
					15360 => '15360 bits',
959
					16384 => '16384 bits'
960
				)
961
			))->setHelp('The larger the key, the more security it offers, but larger keys take considerably more time to generate, ' .
962
				'and take slightly longer to validate leading to a slight slowdown in setting up new sessions (not always noticeable). ' .
963
				'As of 2016, 2048 bit is the minimum and most common selection and 4096 is the maximum in common use. ' .
964
				'For more information see %1$s.', '<a href="https://keylength.com">keylength.com</a>');
965

    
966
			$section->addInput(new Form_Input(
967
				'lifetime',
968
				'Lifetime',
969
				'number',
970
				$pconfig['lifetime']
971
			));
972
		}
973

    
974
		$form->add($section);
975
	}
976

    
977
endif;
978
// ==== Paste a key for the new user
979
$section = new Form_Section('Keys');
980

    
981
$section->addInput(new Form_Checkbox(
982
	'showkey',
983
	'Authorized keys',
984
	'Click to paste an authorized key',
985
	false
986
));
987

    
988
$section->addInput(new Form_Textarea(
989
	'authorizedkeys',
990
	'Authorized SSH Keys',
991
	$pconfig['authorizedkeys']
992
))->setHelp('Enter authorized SSH keys for this user');
993

    
994
$section->addInput(new Form_Input(
995
	'ipsecpsk',
996
	'IPsec Pre-Shared Key',
997
	'text',
998
	$pconfig['ipsecpsk']
999
));
1000

    
1001
$form->add($section);
1002

    
1003
print $form;
1004

    
1005
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
1006
?>
1007
<script type="text/javascript">
1008
//<![CDATA[
1009
events.push(function() {
1010

    
1011
	function setcustomoptions() {
1012
		var adv = $('#customsettings').prop('checked');
1013

    
1014
		hideInput('webguicss', !adv);
1015
		hideInput('webguifixedmenu', !adv);
1016
		hideInput('webguihostnamemenu', !adv);
1017
		hideInput('dashboardcolumns', !adv);
1018
		hideCheckbox('interfacessort', !adv);
1019
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
1020
		hideCheckbox('systemlogsfilterpanel', !adv);
1021
		hideCheckbox('systemlogsmanagelogpanel', !adv);
1022
		hideCheckbox('statusmonitoringsettingspanel', !adv);
1023
		hideCheckbox('webguileftcolumnhyper', !adv);
1024
		hideCheckbox('disablealiaspopupdetail', !adv);
1025
		hideCheckbox('pagenamefirst', !adv);
1026
	}
1027

    
1028
	// Handle displaying a warning message if a user-created theme is selected.
1029
	function setThemeWarning() {
1030
		if ($('#webguicss').val().startsWith("pfSense")) {
1031
			$('#csstxt').html("").addClass("text-default");
1032
		} else {
1033
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
1034
		}
1035
	}
1036

    
1037
	$('#webguicss').change(function() {
1038
		setThemeWarning();
1039
	});
1040

    
1041
	setThemeWarning();
1042

    
1043
	// On click . .
1044
	$('#customsettings').click(function () {
1045
		setcustomoptions();
1046
	});
1047

    
1048
	$("#movetodisabled").click(function() {
1049
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1050
	});
1051

    
1052
	$("#movetoenabled").click(function() {
1053
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1054
	});
1055

    
1056
	$("#showcert").click(function() {
1057
		hideClass('cert-options', !this.checked);
1058
	});
1059

    
1060
	$("#showkey").click(function() {
1061
		hideInput('authorizedkeys', false);
1062
		hideCheckbox('showkey', true);
1063
	});
1064

    
1065
	$('[id^=delcert]').click(function(event) {
1066
		if (confirm(event.target.title)) {
1067
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
1068
			$('#userid').val('<?=$id;?>');
1069
			$('#act').val('delcert');
1070
			$('form').submit();
1071
		}
1072
	});
1073

    
1074
	$('[id^=delprivid]').click(function(event) {
1075
		if (confirm(event.target.title)) {
1076
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
1077
			$('#userid').val('<?=$id;?>');
1078
			$('#act').val('delprivid');
1079
			$('form').submit();
1080
		}
1081
	});
1082

    
1083
	$('#expires').datepicker();
1084

    
1085
	// ---------- On initial page load ------------------------------------------------------------
1086

    
1087
	hideClass('cert-options', true);
1088
	//hideInput('authorizedkeys', true);
1089
	hideCheckbox('showkey', true);
1090
	setcustomoptions();
1091

    
1092
	// On submit mark all the user's groups as "selected"
1093
	$('form').submit(function() {
1094
		AllServers($('[name="groups[]"] option'), true);
1095
	});
1096

    
1097
});
1098
//]]>
1099
</script>
1100
<?php
1101
include('foot.inc');
1102
?>
(214-214/234)