Project

General

Profile

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

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

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

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

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

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

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

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

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

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

    
523
	}
524

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

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

    
533
	return($privhtml);
534
}
535

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

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

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

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

    
569
	}
570

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

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

    
579
	return($certhtml);
580
}
581

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

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

    
590
include("head.inc");
591

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

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

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

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

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

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

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

    
686
?></div>
687

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

    
693
$form = new Form;
694

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
815
	gen_user_settings_fields($section, $pconfig);
816

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
996
print $form;
997

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

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

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

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

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

    
1034
	setThemeWarning();
1035

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

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

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

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

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

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

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

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

    
1078
	// ---------- On initial page load ------------------------------------------------------------
1079

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

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

    
1090
});
1091
//]]>
1092
</script>
1093
<?php
1094
include('foot.inc');
1095
?>
(214-214/234)