Project

General

Profile

Download (31.2 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
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
49
	$config['system']['user'] = array();
50
}
51

    
52
$a_user = &$config['system']['user'];
53
$act = $_REQUEST['act'];
54

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

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

    
87
if ($_POST['act'] == "deluser") {
88

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

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

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

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

    
123
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
124
		}
125
	}
126

    
127
}
128

    
129
if (isset($_POST['dellall'])) {
130

    
131
	$del_users = $_POST['delete_check'];
132
	$deleted_users = array();
133

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

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

    
159
if ($_POST['act'] == "delcert") {
160

    
161
	if (!$a_user[$id]) {
162
		pfSenseHeader("system_usermanager.php");
163
		exit;
164
	}
165

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

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

    
185
if ($_POST['save']) {
186
	unset($input_errors);
187
	$pconfig = $_POST;
188

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

    
211
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
212

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

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

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

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

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

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

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

    
282
	if (!empty($_POST['name'])) {
283
		$ca = lookup_ca($_POST['caref']);
284
		if (!$ca) {
285
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
286
		}
287
	}
288

    
289
	if (!$input_errors) {
290

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
408
				$subject = cert_get_subject_array($ca['crt']);
409

    
410
				$dn = array(
411
					'countryName' => $subject[0]['v'],
412
					'stateOrProvinceName' => $subject[1]['v'],
413
					'localityName' => $subject[2]['v'],
414
					'organizationName' => $subject[3]['v'],
415
					'emailAddress' => $subject[4]['v'],
416
					'commonName' => $userent['name']);
417
				$cn_altname = cert_add_altname_type($userent['name']);
418
				if (!empty($cn_altname)) {
419
					$dn['subjectAltName'] = $cn_altname;
420
				}
421

    
422
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
423
					(int)$_POST['lifetime'], $dn);
424

    
425
				if (!is_array($config['cert'])) {
426
					$config['cert'] = array();
427
				}
428
				$config['cert'][] = $cert;
429
				$userent['cert'][] = $cert['refid'];
430
			}
431
			$userent['uid'] = $config['system']['nextuid']++;
432
			/* Add the user to All Users group. */
433
			foreach ($config['system']['group'] as $gidx => $group) {
434
				if ($group['name'] == "all") {
435
					if (!is_array($config['system']['group'][$gidx]['member'])) {
436
						$config['system']['group'][$gidx]['member'] = array();
437
					}
438
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
439
					break;
440
				}
441
			}
442

    
443
			$a_user[] = $userent;
444
		}
445

    
446
		/* Sort it alphabetically */
447
		usort($config['system']['user'], function($a, $b) {
448
			return strcmp($a['name'], $b['name']);
449
		});
450

    
451
		/* 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. */
452
		local_user_set_groups($userent, $_POST['groups']);
453
		local_user_set($userent);
454
		/* 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. */
455
		local_user_set_groups($userent, $_POST['groups']);
456
		$savemsg = sprintf(gettext("Successfully %s user %s"), (isset($id)) ? gettext("edited") : gettext("created"), $userent['name']);
457
		write_config($savemsg);
458
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
459
		if (is_dir("/etc/inc/privhooks")) {
460
			run_plugins("/etc/inc/privhooks");
461
		}
462

    
463
		pfSenseHeader("system_usermanager.php");
464
	}
465
}
466

    
467
function build_priv_table() {
468
	global $a_user, $id;
469

    
470
	$privhtml = '<div class="table-responsive">';
471
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
472
	$privhtml .=		'<thead>';
473
	$privhtml .=			'<tr>';
474
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
475
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
476
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
477
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
478
	$privhtml .=			'</tr>';
479
	$privhtml .=		'</thead>';
480
	$privhtml .=		'<tbody>';
481

    
482
	$i = 0;
483
	$user_has_root_priv = false;
484

    
485
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
486
		$group = false;
487
		if ($priv['group']) {
488
			$group = $priv['group'];
489
		}
490

    
491
		$privhtml .=		'<tr>';
492
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
493
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
494
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
495
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
496
			$privhtml .=			' ' . gettext('(admin privilege)');
497
			$user_has_root_priv = true;
498
		}
499
		$privhtml .=			'</td>';
500
		$privhtml .=			'<td>';
501
		if (!$group) {
502
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
503
		}
504

    
505
		$privhtml .=			'</td>';
506
		$privhtml .=		'</tr>';
507

    
508
		if (!$group) {
509
			$i++;
510
		}
511
	}
512

    
513
	if ($user_has_root_priv) {
514
		$privhtml .=		'<tr>';
515
		$privhtml .=			'<td colspan="3">';
516
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
517
		$privhtml .=			'</td>';
518
		$privhtml .=			'<td>';
519
		$privhtml .=			'</td>';
520
		$privhtml .=		'</tr>';
521

    
522
	}
523

    
524
	$privhtml .=		'</tbody>';
525
	$privhtml .=	'</table>';
526
	$privhtml .= '</div>';
527

    
528
	$privhtml .= '<nav class="action-buttons">';
529
	$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>';
530
	$privhtml .= '</nav>';
531

    
532
	return($privhtml);
533
}
534

    
535
function build_cert_table() {
536
	global $a_user, $id;
537

    
538
	$certhtml = '<div class="table-responsive">';
539
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
540
	$certhtml .=		'<thead>';
541
	$certhtml .=			'<tr>';
542
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
543
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
544
	$certhtml .=				'<th></th>';
545
	$certhtml .=			'</tr>';
546
	$certhtml .=		'</thead>';
547
	$certhtml .=		'<tbody>';
548

    
549
	$a_cert = $a_user[$id]['cert'];
550
	if (is_array($a_cert)) {
551
		$i = 0;
552
		foreach ($a_cert as $certref) {
553
			$cert = lookup_cert($certref);
554
			$ca = lookup_ca($cert['caref']);
555
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
556

    
557
			$certhtml .=	'<tr>';
558
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
559
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
560
			$certhtml .=		'<td>';
561
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
562
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
563
			$certhtml .=		'</td>';
564
			$certhtml .=	'</tr>';
565
			$i++;
566
		}
567

    
568
	}
569

    
570
	$certhtml .=		'</tbody>';
571
	$certhtml .=	'</table>';
572
	$certhtml .= '</div>';
573

    
574
	$certhtml .= '<nav class="action-buttons">';
575
	$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>';
576
	$certhtml .= '</nav>';
577

    
578
	return($certhtml);
579
}
580

    
581
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
582
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
583

    
584
if ($act == "new" || $act == "edit" || $input_errors) {
585
	$pgtitle[] = gettext('Edit');
586
	$pglinks[] = "@self";
587
}
588

    
589
include("head.inc");
590

    
591
if ($delete_errors) {
592
	print_input_errors($delete_errors);
593
}
594

    
595
if ($input_errors) {
596
	print_input_errors($input_errors);
597
}
598

    
599
if ($savemsg) {
600
	print_info_box($savemsg, 'success');
601
}
602

    
603
$tab_array = array();
604
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
605
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
606
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
607
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
608
display_top_tabs($tab_array);
609

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

    
669
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
670
		<i class="fa fa-trash icon-embed-btn"></i>
671
		<?=gettext("Delete")?>
672
	</button>
673

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

    
685
?></div>
686

    
687
<?php
688
	include("foot.inc");
689
	exit;
690
}
691

    
692
$form = new Form;
693

    
694
if ($act == "new" || $act == "edit" || $input_errors):
695

    
696
	$form->addGlobal(new Form_Input(
697
		'act',
698
		null,
699
		'hidden',
700
		''
701
	));
702

    
703
	$form->addGlobal(new Form_Input(
704
		'userid',
705
		null,
706
		'hidden',
707
		isset($id) ? $id:''
708
	));
709

    
710
	$form->addGlobal(new Form_Input(
711
		'privid',
712
		null,
713
		'hidden',
714
		''
715
	));
716

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

    
724
	$ro = "";
725
	if ($pconfig['utype'] == "system") {
726
		$ro = "readonly";
727
	}
728

    
729
	$section = new Form_Section('User Properties');
730

    
731
	$section->addInput(new Form_StaticText(
732
		'Defined by',
733
		strtoupper($pconfig['utype'])
734
	));
735

    
736
	$form->addGlobal(new Form_Input(
737
		'utype',
738
		null,
739
		'hidden',
740
		$pconfig['utype']
741
	));
742

    
743
	$section->addInput(new Form_Checkbox(
744
		'disabled',
745
		'Disabled',
746
		'This user cannot login',
747
		$pconfig['disabled']
748
	));
749

    
750
	$section->addInput($input = new Form_Input(
751
		'usernamefld',
752
		'*Username',
753
		'text',
754
		$pconfig['usernamefld']
755
	));
756

    
757
	if ($ro) {
758
		$input->setReadonly();
759
	}
760

    
761
	$form->addGlobal(new Form_Input(
762
		'oldusername',
763
		null,
764
		'hidden',
765
		$pconfig['usernamefld']
766
	));
767

    
768
	if ($act == "edit") {
769
		$pwd_required = "";
770
	} else {
771
		$pwd_required = "*";
772
	}
773

    
774
	$group = new Form_Group($pwd_required . 'Password');
775
	$group->add(new Form_Input(
776
		'passwordfld1',
777
		'Password',
778
		'password'
779
	));
780
	$group->add(new Form_Input(
781
		'passwordfld2',
782
		'Confirm Password',
783
		'password'
784
	));
785

    
786
	$section->add($group);
787

    
788
	$section->addInput($input = new Form_Input(
789
		'descr',
790
		'Full name',
791
		'text',
792
		htmlspecialchars($pconfig['descr'])
793
	))->setHelp('User\'s full name, for administrative information only');
794

    
795
	if ($ro) {
796
		$input->setDisabled();
797
	}
798

    
799
	$section->addInput(new Form_Input(
800
		'expires',
801
		'Expiration date',
802
		'text',
803
		$pconfig['expires']
804
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
805
		'the expiration date as MM/DD/YYYY');
806

    
807
	$section->addInput(new Form_Checkbox(
808
		'customsettings',
809
		'Custom Settings',
810
		'Use individual customized GUI options and dashboard layout for this user.',
811
		$pconfig['customsettings']
812
	));
813

    
814
	gen_user_settings_fields($section, $pconfig);
815

    
816
	// ==== Group membership ==================================================
817
	$group = new Form_Group('Group membership');
818

    
819
	// Make a list of all the groups configured on the system, and a list of
820
	// those which this user is a member of
821
	$systemGroups = array();
822
	$usersGroups = array();
823

    
824
	$usergid = [$pconfig['usernamefld']];
825

    
826
	foreach ($config['system']['group'] as $Ggroup) {
827
		if ($Ggroup['name'] != "all") {
828
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
829
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
830
			} else {
831
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
832
			}
833
		}
834
	}
835

    
836
	$group->add(new Form_Select(
837
		'sysgroups',
838
		null,
839
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
840
		$systemGroups,
841
		true
842
	))->setHelp('Not member of');
843

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

    
852
	$section->add($group);
853

    
854
	$group = new Form_Group('');
855

    
856
	$group->add(new Form_Button(
857
		'movetoenabled',
858
		'Move to "Member of" list',
859
		null,
860
		'fa-angle-double-right'
861
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
862

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

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

    
873
	// ==== Button for adding user certificate ================================
874
	if ($act == 'new') {
875
		if (count($nonPrvCas) > 0) {
876
			$section->addInput(new Form_Checkbox(
877
				'showcert',
878
				'Certificate',
879
				'Click to create a user certificate',
880
				false
881
			));
882
		} else {
883
			$section->addInput(new Form_StaticText(
884
				'Certificate',
885
				gettext('No private CAs found. A private CA is required to create a new user certificate. ' .
886
					'Save the user first to import an external certificate.')
887
			));
888
		}
889
	}
890

    
891
	$form->add($section);
892

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

    
898
		$section = new Form_Section('Effective Privileges');
899

    
900
		$section->addInput(new Form_StaticText(
901
			null,
902
			build_priv_table()
903
		));
904

    
905
		$form->add($section);
906

    
907
		// ==== Certificate table section =====================================
908
		$section = new Form_Section('User Certificates');
909

    
910
		$section->addInput(new Form_StaticText(
911
			null,
912
			build_cert_table()
913
		));
914

    
915
		$form->add($section);
916
	}
917

    
918
	// ==== Add user certificate for a new user
919
	if (is_array($config['ca']) && count($config['ca']) > 0) {
920
		$section = new Form_Section('Create Certificate for User');
921
		$section->addClass('cert-options');
922

    
923
		if (!empty($nonPrvCas)) {
924
			$section->addInput(new Form_Input(
925
				'name',
926
				'Descriptive name',
927
				'text',
928
				$pconfig['name']
929
			));
930

    
931
			$section->addInput(new Form_Select(
932
				'caref',
933
				'Certificate authority',
934
				null,
935
				$nonPrvCas
936
			));
937

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

    
958
			$section->addInput(new Form_Input(
959
				'lifetime',
960
				'Lifetime',
961
				'number',
962
				$pconfig['lifetime']
963
			));
964
		}
965

    
966
		$form->add($section);
967
	}
968

    
969
endif;
970
// ==== Paste a key for the new user
971
$section = new Form_Section('Keys');
972

    
973
$section->addInput(new Form_Checkbox(
974
	'showkey',
975
	'Authorized keys',
976
	'Click to paste an authorized key',
977
	false
978
));
979

    
980
$section->addInput(new Form_Textarea(
981
	'authorizedkeys',
982
	'Authorized SSH Keys',
983
	$pconfig['authorizedkeys']
984
))->setHelp('Enter authorized SSH keys for this user');
985

    
986
$section->addInput(new Form_Input(
987
	'ipsecpsk',
988
	'IPsec Pre-Shared Key',
989
	'text',
990
	$pconfig['ipsecpsk']
991
));
992

    
993
$form->add($section);
994

    
995
print $form;
996

    
997
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
998
?>
999
<script type="text/javascript">
1000
//<![CDATA[
1001
events.push(function() {
1002

    
1003
	function setcustomoptions() {
1004
		var adv = $('#customsettings').prop('checked');
1005

    
1006
		hideInput('webguicss', !adv);
1007
		hideInput('webguifixedmenu', !adv);
1008
		hideInput('webguihostnamemenu', !adv);
1009
		hideInput('dashboardcolumns', !adv);
1010
		hideCheckbox('interfacessort', !adv);
1011
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
1012
		hideCheckbox('systemlogsfilterpanel', !adv);
1013
		hideCheckbox('systemlogsmanagelogpanel', !adv);
1014
		hideCheckbox('statusmonitoringsettingspanel', !adv);
1015
		hideCheckbox('webguileftcolumnhyper', !adv);
1016
		hideCheckbox('disablealiaspopupdetail', !adv);
1017
		hideCheckbox('pagenamefirst', !adv);
1018
	}
1019

    
1020
	// Handle displaying a warning message if a user-created theme is selected.
1021
	function setThemeWarning() {
1022
		if ($('#webguicss').val().startsWith("pfSense")) {
1023
			$('#csstxt').html("").addClass("text-default");
1024
		} else {
1025
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
1026
		}
1027
	}
1028

    
1029
	$('#webguicss').change(function() {
1030
		setThemeWarning();
1031
	});
1032

    
1033
	setThemeWarning();
1034

    
1035
	// On click . .
1036
	$('#customsettings').click(function () {
1037
		setcustomoptions();
1038
	});
1039

    
1040
	$("#movetodisabled").click(function() {
1041
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1042
	});
1043

    
1044
	$("#movetoenabled").click(function() {
1045
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1046
	});
1047

    
1048
	$("#showcert").click(function() {
1049
		hideClass('cert-options', !this.checked);
1050
	});
1051

    
1052
	$("#showkey").click(function() {
1053
		hideInput('authorizedkeys', false);
1054
		hideCheckbox('showkey', true);
1055
	});
1056

    
1057
	$('[id^=delcert]').click(function(event) {
1058
		if (confirm(event.target.title)) {
1059
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
1060
			$('#userid').val('<?=$id;?>');
1061
			$('#act').val('delcert');
1062
			$('form').submit();
1063
		}
1064
	});
1065

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

    
1075
	$('#expires').datepicker();
1076

    
1077
	// ---------- On initial page load ------------------------------------------------------------
1078

    
1079
	hideClass('cert-options', true);
1080
	//hideInput('authorizedkeys', true);
1081
	hideCheckbox('showkey', true);
1082
	setcustomoptions();
1083

    
1084
	// On submit mark all the user's groups as "selected"
1085
	$('form').submit(function() {
1086
		AllServers($('[name="groups[]"] option'), true);
1087
	});
1088

    
1089
});
1090
//]]>
1091
</script>
1092
<?php
1093
include('foot.inc');
1094
?>
(212-212/232)