Project

General

Profile

Download (31.5 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
	validate_webguicss_field($input_errors, $_POST['webguicss']);
289
	validate_webguifixedmenu_field($input_errors, $_POST['webguifixedmenu']);
290
	validate_webguihostnamemenu_field($input_errors, $_POST['webguihostnamemenu']);
291
	validate_dashboardcolumns_field($input_errors, $_POST['dashboardcolumns']);
292

    
293
	if (!$input_errors) {
294

    
295
		$userent = array();
296
		if (isset($id) && $a_user[$id]) {
297
			$userent = $a_user[$id];
298
		}
299

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

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

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

    
313
		/* only change description if sent */
314
		if (isset($_POST['descr'])) {
315
			$userent['descr'] = $_POST['descr'];
316
		}
317

    
318
		$userent['name'] = $_POST['usernamefld'];
319
		$userent['expires'] = $_POST['expires'];
320
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
321
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
322
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
323

    
324
		if ($_POST['disabled']) {
325
			$userent['disabled'] = true;
326
		} else {
327
			unset($userent['disabled']);
328
		}
329

    
330
		if ($_POST['customsettings']) {
331
			$userent['customsettings'] = true;
332
		} else {
333
			unset($userent['customsettings']);
334
		}
335

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

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

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

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

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

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

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

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

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

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

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

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

    
410
				$cert['descr'] = $_POST['name'];
411

    
412
				$subject = cert_get_subject_array($ca['crt']);
413

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

    
426
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
427
					(int)$_POST['lifetime'], $dn);
428

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

    
447
			$a_user[] = $userent;
448
		}
449

    
450
		/* Sort it alphabetically */
451
		usort($config['system']['user'], function($a, $b) {
452
			return strcmp($a['name'], $b['name']);
453
		});
454

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

    
467
		pfSenseHeader("system_usermanager.php");
468
	}
469
}
470

    
471
function build_priv_table() {
472
	global $a_user, $id;
473

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

    
486
	$i = 0;
487
	$user_has_root_priv = false;
488

    
489
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
490
		$group = false;
491
		if ($priv['group']) {
492
			$group = $priv['group'];
493
		}
494

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

    
509
		$privhtml .=			'</td>';
510
		$privhtml .=		'</tr>';
511

    
512
		if (!$group) {
513
			$i++;
514
		}
515
	}
516

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

    
526
	}
527

    
528
	$privhtml .=		'</tbody>';
529
	$privhtml .=	'</table>';
530
	$privhtml .= '</div>';
531

    
532
	$privhtml .= '<nav class="action-buttons">';
533
	$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>';
534
	$privhtml .= '</nav>';
535

    
536
	return($privhtml);
537
}
538

    
539
function build_cert_table() {
540
	global $a_user, $id;
541

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

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

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

    
572
	}
573

    
574
	$certhtml .=		'</tbody>';
575
	$certhtml .=	'</table>';
576
	$certhtml .= '</div>';
577

    
578
	$certhtml .= '<nav class="action-buttons">';
579
	$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>';
580
	$certhtml .= '</nav>';
581

    
582
	return($certhtml);
583
}
584

    
585
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
586
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
587

    
588
if ($act == "new" || $act == "edit" || $input_errors) {
589
	$pgtitle[] = gettext('Edit');
590
	$pglinks[] = "@self";
591
}
592

    
593
include("head.inc");
594

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

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

    
603
if ($savemsg) {
604
	print_info_box($savemsg, 'success');
605
}
606

    
607
$tab_array = array();
608
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
609
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
610
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
611
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
612
display_top_tabs($tab_array);
613

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

    
673
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
674
		<i class="fa fa-trash icon-embed-btn"></i>
675
		<?=gettext("Delete")?>
676
	</button>
677

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

    
689
?></div>
690

    
691
<?php
692
	include("foot.inc");
693
	exit;
694
}
695

    
696
$form = new Form;
697

    
698
if ($act == "new" || $act == "edit" || $input_errors):
699

    
700
	$form->addGlobal(new Form_Input(
701
		'act',
702
		null,
703
		'hidden',
704
		''
705
	));
706

    
707
	$form->addGlobal(new Form_Input(
708
		'userid',
709
		null,
710
		'hidden',
711
		isset($id) ? $id:''
712
	));
713

    
714
	$form->addGlobal(new Form_Input(
715
		'privid',
716
		null,
717
		'hidden',
718
		''
719
	));
720

    
721
	$form->addGlobal(new Form_Input(
722
		'certid',
723
		null,
724
		'hidden',
725
		''
726
	));
727

    
728
	$ro = "";
729
	if ($pconfig['utype'] == "system") {
730
		$ro = "readonly";
731
	}
732

    
733
	$section = new Form_Section('User Properties');
734

    
735
	$section->addInput(new Form_StaticText(
736
		'Defined by',
737
		strtoupper($pconfig['utype'])
738
	));
739

    
740
	$form->addGlobal(new Form_Input(
741
		'utype',
742
		null,
743
		'hidden',
744
		$pconfig['utype']
745
	));
746

    
747
	$section->addInput(new Form_Checkbox(
748
		'disabled',
749
		'Disabled',
750
		'This user cannot login',
751
		$pconfig['disabled']
752
	));
753

    
754
	$section->addInput($input = new Form_Input(
755
		'usernamefld',
756
		'*Username',
757
		'text',
758
		$pconfig['usernamefld']
759
	));
760

    
761
	if ($ro) {
762
		$input->setReadonly();
763
	}
764

    
765
	$form->addGlobal(new Form_Input(
766
		'oldusername',
767
		null,
768
		'hidden',
769
		$pconfig['usernamefld']
770
	));
771

    
772
	if ($act == "edit") {
773
		$pwd_required = "";
774
	} else {
775
		$pwd_required = "*";
776
	}
777

    
778
	$group = new Form_Group($pwd_required . 'Password');
779
	$group->add(new Form_Input(
780
		'passwordfld1',
781
		'Password',
782
		'password'
783
	));
784
	$group->add(new Form_Input(
785
		'passwordfld2',
786
		'Confirm Password',
787
		'password'
788
	));
789

    
790
	$section->add($group);
791

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

    
799
	if ($ro) {
800
		$input->setDisabled();
801
	}
802

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

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

    
818
	gen_user_settings_fields($section, $pconfig);
819

    
820
	// ==== Group membership ==================================================
821
	$group = new Form_Group('Group membership');
822

    
823
	// Make a list of all the groups configured on the system, and a list of
824
	// those which this user is a member of
825
	$systemGroups = array();
826
	$usersGroups = array();
827

    
828
	$usergid = [$pconfig['usernamefld']];
829

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

    
840
	$group->add(new Form_Select(
841
		'sysgroups',
842
		null,
843
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
844
		$systemGroups,
845
		true
846
	))->setHelp('Not member of');
847

    
848
	$group->add(new Form_Select(
849
		'groups',
850
		null,
851
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
852
		$usersGroups,
853
		true
854
	))->setHelp('Member of');
855

    
856
	$section->add($group);
857

    
858
	$group = new Form_Group('');
859

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

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

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

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

    
895
	$form->add($section);
896

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

    
902
		$section = new Form_Section('Effective Privileges');
903

    
904
		$section->addInput(new Form_StaticText(
905
			null,
906
			build_priv_table()
907
		));
908

    
909
		$form->add($section);
910

    
911
		// ==== Certificate table section =====================================
912
		$section = new Form_Section('User Certificates');
913

    
914
		$section->addInput(new Form_StaticText(
915
			null,
916
			build_cert_table()
917
		));
918

    
919
		$form->add($section);
920
	}
921

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

    
927
		if (!empty($nonPrvCas)) {
928
			$section->addInput(new Form_Input(
929
				'name',
930
				'Descriptive name',
931
				'text',
932
				$pconfig['name']
933
			));
934

    
935
			$section->addInput(new Form_Select(
936
				'caref',
937
				'Certificate authority',
938
				null,
939
				$nonPrvCas
940
			));
941

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

    
962
			$section->addInput(new Form_Input(
963
				'lifetime',
964
				'Lifetime',
965
				'number',
966
				$pconfig['lifetime']
967
			));
968
		}
969

    
970
		$form->add($section);
971
	}
972

    
973
endif;
974
// ==== Paste a key for the new user
975
$section = new Form_Section('Keys');
976

    
977
$section->addInput(new Form_Checkbox(
978
	'showkey',
979
	'Authorized keys',
980
	'Click to paste an authorized key',
981
	false
982
));
983

    
984
$section->addInput(new Form_Textarea(
985
	'authorizedkeys',
986
	'Authorized SSH Keys',
987
	$pconfig['authorizedkeys']
988
))->setHelp('Enter authorized SSH keys for this user');
989

    
990
$section->addInput(new Form_Input(
991
	'ipsecpsk',
992
	'IPsec Pre-Shared Key',
993
	'text',
994
	$pconfig['ipsecpsk']
995
));
996

    
997
$form->add($section);
998

    
999
print $form;
1000

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

    
1007
	function setcustomoptions() {
1008
		var adv = $('#customsettings').prop('checked');
1009

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

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

    
1033
	$('#webguicss').change(function() {
1034
		setThemeWarning();
1035
	});
1036

    
1037
	setThemeWarning();
1038

    
1039
	// On click . .
1040
	$('#customsettings').click(function () {
1041
		setcustomoptions();
1042
	});
1043

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

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

    
1052
	$("#showcert").click(function() {
1053
		hideClass('cert-options', !this.checked);
1054
	});
1055

    
1056
	$("#showkey").click(function() {
1057
		hideInput('authorizedkeys', false);
1058
		hideCheckbox('showkey', true);
1059
	});
1060

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

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

    
1079
	$('#expires').datepicker();
1080

    
1081
	// ---------- On initial page load ------------------------------------------------------------
1082

    
1083
	hideClass('cert-options', true);
1084
	//hideInput('authorizedkeys', true);
1085
	hideCheckbox('showkey', true);
1086
	setcustomoptions();
1087

    
1088
	// On submit mark all the user's groups as "selected"
1089
	$('form').submit(function() {
1090
		AllServers($('[name="groups[]"] option'), true);
1091
	});
1092

    
1093
});
1094
//]]>
1095
</script>
1096
<?php
1097
include('foot.inc');
1098
?>
(211-211/231)