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
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_hash($ca['crt']);
413

    
414
				$dn = array();
415
				if (!empty($subject['C'])) {
416
					$dn['countryName'] = $subject['C'];
417
				}
418
				if (!empty($subject['ST'])) {
419
					$dn['stateOrProvinceName'] = $subject['ST'];
420
				}
421
				if (!empty($subject['L'])) {
422
					$dn['localityName'] = $subject['L'];
423
				}
424
				if (!empty($subject['O'])) {
425
					$dn['organizationName'] = $subject['O'];
426
				}
427
				if (!empty($subject['OU'])) {
428
					$dn['organizationalUnit'] = $subject['OU'];
429
				}
430
				$dn['commonName'] = $userent['name'];
431
				$cn_altname = cert_add_altname_type($userent['name']);
432
				if (!empty($cn_altname)) {
433
					$dn['subjectAltName'] = $cn_altname;
434
				}
435

    
436
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
437
					(int)$_POST['lifetime'], $dn);
438

    
439
				if (!is_array($config['cert'])) {
440
					$config['cert'] = array();
441
				}
442
				$config['cert'][] = $cert;
443
				$userent['cert'][] = $cert['refid'];
444
			}
445
			$userent['uid'] = $config['system']['nextuid']++;
446
			/* Add the user to All Users group. */
447
			foreach ($config['system']['group'] as $gidx => $group) {
448
				if ($group['name'] == "all") {
449
					if (!is_array($config['system']['group'][$gidx]['member'])) {
450
						$config['system']['group'][$gidx]['member'] = array();
451
					}
452
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
453
					break;
454
				}
455
			}
456

    
457
			$a_user[] = $userent;
458
		}
459

    
460
		/* Sort it alphabetically */
461
		usort($config['system']['user'], function($a, $b) {
462
			return strcmp($a['name'], $b['name']);
463
		});
464

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

    
474
		pfSenseHeader("system_usermanager.php");
475
	}
476
}
477

    
478
function build_priv_table() {
479
	global $a_user, $id;
480

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

    
493
	$i = 0;
494
	$user_has_root_priv = false;
495

    
496
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
497
		$group = false;
498
		if ($priv['group']) {
499
			$group = $priv['group'];
500
		}
501

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

    
516
		$privhtml .=			'</td>';
517
		$privhtml .=		'</tr>';
518

    
519
		if (!$group) {
520
			$i++;
521
		}
522
	}
523

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

    
533
	}
534

    
535
	$privhtml .=		'</tbody>';
536
	$privhtml .=	'</table>';
537
	$privhtml .= '</div>';
538

    
539
	$privhtml .= '<nav class="action-buttons">';
540
	$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>';
541
	$privhtml .= '</nav>';
542

    
543
	return($privhtml);
544
}
545

    
546
function build_cert_table() {
547
	global $a_user, $id;
548

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

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

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

    
579
	}
580

    
581
	$certhtml .=		'</tbody>';
582
	$certhtml .=	'</table>';
583
	$certhtml .= '</div>';
584

    
585
	$certhtml .= '<nav class="action-buttons">';
586
	$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>';
587
	$certhtml .= '</nav>';
588

    
589
	return($certhtml);
590
}
591

    
592
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
593
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
594

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

    
600
include("head.inc");
601

    
602
if ($delete_errors) {
603
	print_input_errors($delete_errors);
604
}
605

    
606
if ($input_errors) {
607
	print_input_errors($input_errors);
608
}
609

    
610
if ($savemsg) {
611
	print_info_box($savemsg, 'success');
612
}
613

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

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

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

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

    
696
?></div>
697

    
698
<?php
699
	include("foot.inc");
700
	exit;
701
}
702

    
703
$form = new Form;
704

    
705
if ($act == "new" || $act == "edit" || $input_errors):
706

    
707
	$form->addGlobal(new Form_Input(
708
		'act',
709
		null,
710
		'hidden',
711
		''
712
	));
713

    
714
	$form->addGlobal(new Form_Input(
715
		'userid',
716
		null,
717
		'hidden',
718
		isset($id) ? $id:''
719
	));
720

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

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

    
735
	$ro = "";
736
	if ($pconfig['utype'] == "system") {
737
		$ro = "readonly";
738
	}
739

    
740
	$section = new Form_Section('User Properties');
741

    
742
	$section->addInput(new Form_StaticText(
743
		'Defined by',
744
		strtoupper($pconfig['utype'])
745
	));
746

    
747
	$form->addGlobal(new Form_Input(
748
		'utype',
749
		null,
750
		'hidden',
751
		$pconfig['utype']
752
	));
753

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

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

    
768
	if ($ro) {
769
		$input->setReadonly();
770
	}
771

    
772
	$form->addGlobal(new Form_Input(
773
		'oldusername',
774
		null,
775
		'hidden',
776
		$pconfig['usernamefld']
777
	));
778

    
779
	if ($act == "edit") {
780
		$pwd_required = "";
781
	} else {
782
		$pwd_required = "*";
783
	}
784

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

    
797
	$section->add($group);
798

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

    
806
	if ($ro) {
807
		$input->setDisabled();
808
	}
809

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

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

    
825
	gen_user_settings_fields($section, $pconfig);
826

    
827
	// ==== Group membership ==================================================
828
	$group = new Form_Group('Group membership');
829

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

    
835
	$usergid = [$pconfig['usernamefld']];
836

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

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

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

    
863
	$section->add($group);
864

    
865
	$group = new Form_Group('');
866

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

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

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

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

    
902
	$form->add($section);
903

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

    
909
		$section = new Form_Section('Effective Privileges');
910

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

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

    
918
		// ==== Certificate table section =====================================
919
		$section = new Form_Section('User Certificates');
920

    
921
		$section->addInput(new Form_StaticText(
922
			null,
923
			build_cert_table()
924
		));
925

    
926
		$form->add($section);
927
	}
928

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

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

    
942
			$section->addInput(new Form_Select(
943
				'caref',
944
				'Certificate authority',
945
				null,
946
				$nonPrvCas
947
			));
948

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

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

    
977
		$form->add($section);
978
	}
979

    
980
endif;
981
// ==== Paste a key for the new user
982
$section = new Form_Section('Keys');
983

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

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

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

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

    
1006
print $form;
1007

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

    
1014
	function setcustomoptions() {
1015
		var adv = $('#customsettings').prop('checked');
1016

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

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

    
1040
	$('#webguicss').change(function() {
1041
		setThemeWarning();
1042
	});
1043

    
1044
	setThemeWarning();
1045

    
1046
	// On click . .
1047
	$('#customsettings').click(function () {
1048
		setcustomoptions();
1049
	});
1050

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

    
1055
	$("#movetoenabled").click(function() {
1056
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1057
	});
1058

    
1059
	$("#showcert").click(function() {
1060
		hideClass('cert-options', !this.checked);
1061
	});
1062

    
1063
	$("#showkey").click(function() {
1064
		hideInput('authorizedkeys', false);
1065
		hideCheckbox('showkey', true);
1066
	});
1067

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

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

    
1086
	$('#expires').datepicker();
1087

    
1088
	// ---------- On initial page load ------------------------------------------------------------
1089

    
1090
	hideClass('cert-options', true);
1091
	//hideInput('authorizedkeys', true);
1092
	hideCheckbox('showkey', true);
1093
	setcustomoptions();
1094

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

    
1100
});
1101
//]]>
1102
</script>
1103
<?php
1104
include('foot.inc');
1105
?>
(214-214/234)