Project

General

Profile

Download (29.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-2016 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

    
39
// start admin user code
40
if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
41
	$id = $_REQUEST['userid'];
42
}
43

    
44
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
45
	$config['system']['user'] = array();
46
}
47

    
48
$a_user = &$config['system']['user'];
49
$act = $_REQUEST['act'];
50

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

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

    
81
if ($_POST['act'] == "deluser") {
82

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

    
88
	if ($_POST['username'] == $_SESSION['Username']) {
89
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_POST['username']);
90
	} else {
91
		local_user_del($a_user[$id]);
92
		$userdeleted = $a_user[$id]['name'];
93
		unset($a_user[$id]);
94
		write_config();
95
		$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
96
	}
97

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

    
108
if (isset($_POST['dellall'])) {
109

    
110
	$del_users = $_POST['delete_check'];
111
	$deleted_users = "";
112
	$deleted_count = 0;
113
	$comma = "";
114

    
115
	if (!empty($del_users)) {
116
		foreach ($del_users as $userid) {
117
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
118
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
119
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
120
				} else {
121
					$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
122
					$comma = ", ";
123
					$deleted_count++;
124
					local_user_del($a_user[$userid]);
125
					unset($a_user[$userid]);
126
				}
127
			} else {
128
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
129
			}
130
		}
131

    
132
		if ($deleted_count > 0) {
133
			if ($deleted_count == 1) {
134
				$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
135
			} else {
136
				$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
137
			}
138
			write_config($savemsg);
139
		}
140
	}
141
}
142

    
143
if ($_POST['act'] == "delcert") {
144

    
145
	if (!$a_user[$id]) {
146
		pfSenseHeader("system_usermanager.php");
147
		exit;
148
	}
149

    
150
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
151
	$certdeleted = $certdeleted['descr'];
152
	unset($a_user[$id]['cert'][$_POST['certid']]);
153
	write_config();
154
	$_POST['act'] = "edit";
155
	$savemsg = sprintf(gettext("Certificate %s association removed."), $certdeleted);
156
}
157

    
158
if ($_POST['act'] == "delprivid") {
159
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
160
	unset($a_user[$id]['priv'][$_POST['privid']]);
161
	local_user_set($a_user[$id]);
162
	write_config();
163
	$_POST['act'] = "edit";
164
	$savemsg = sprintf(gettext("Privilege %s removed."), $privdeleted);
165
}
166

    
167
if ($_POST['save']) {
168
	unset($input_errors);
169
	$pconfig = $_POST;
170

    
171
	/* input validation */
172
	if (isset($id) && ($a_user[$id])) {
173
		$reqdfields = explode(" ", "usernamefld");
174
		$reqdfieldsn = array(gettext("Username"));
175
	} else {
176
		if (empty($_POST['name'])) {
177
			$reqdfields = explode(" ", "usernamefld passwordfld1");
178
			$reqdfieldsn = array(
179
				gettext("Username"),
180
				gettext("Password"));
181
		} else {
182
			$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
183
			$reqdfieldsn = array(
184
				gettext("Username"),
185
				gettext("Password"),
186
				gettext("Descriptive name"),
187
				gettext("Certificate authority"),
188
				gettext("Key length"),
189
				gettext("Lifetime"));
190
		}
191
	}
192

    
193
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
194

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

    
199
	if (strlen($_POST['usernamefld']) > 16) {
200
		$input_errors[] = gettext("The username is longer than 16 characters.");
201
	}
202

    
203
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
204
		$input_errors[] = gettext("The passwords do not match.");
205
	}
206

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

    
211
	/* Check the POSTed groups to ensure they are valid and exist */
212
	if (is_array($_POST['groups'])) {
213
		foreach ($_POST['groups'] as $newgroup) {
214
			if (empty(getGroupEntry($newgroup))) {
215
				$input_errors[] = gettext("One or more invalid groups was submitted.");
216
			}
217
		}
218
	}
219

    
220
	if (isset($id) && $a_user[$id]) {
221
		$oldusername = $a_user[$id]['name'];
222
	} else {
223
		$oldusername = "";
224
	}
225
	/* make sure this user name is unique */
226
	if (!$input_errors) {
227
		foreach ($a_user as $userent) {
228
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
229
				$input_errors[] = gettext("Another entry with the same username already exists.");
230
				break;
231
			}
232
		}
233
	}
234
	/* also make sure it is not reserved */
235
	if (!$input_errors) {
236
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
237
		foreach ($system_users as $s_user) {
238
			$ent = explode(":", $s_user);
239
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
240
				$input_errors[] = gettext("That username is reserved by the system.");
241
				break;
242
			}
243
		}
244
	}
245

    
246
	/*
247
	 * Check for a valid expiration date if one is set at all (valid means,
248
	 * DateTime puts out a time stamp so any DateTime compatible time
249
	 * format may be used. to keep it simple for the enduser, we only
250
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
251
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
252
	 * Otherwise such an entry would lead to an invalid expiration data.
253
	 */
254
	if ($_POST['expires']) {
255
		try {
256
			$expdate = new DateTime($_POST['expires']);
257
			//convert from any DateTime compatible date to MM/DD/YYYY
258
			$_POST['expires'] = $expdate->format("m/d/Y");
259
		} catch (Exception $ex) {
260
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
261
		}
262
	}
263

    
264
	if (!empty($_POST['name'])) {
265
		$ca = lookup_ca($_POST['caref']);
266
		if (!$ca) {
267
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
268
		}
269
	}
270

    
271
	if (!$input_errors) {
272

    
273
		$userent = array();
274
		if (isset($id) && $a_user[$id]) {
275
			$userent = $a_user[$id];
276
		}
277

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

    
280
		/* the user name was modified */
281
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
282
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
283
			local_user_del($userent);
284
		}
285

    
286
		/* the user password was modified */
287
		if ($_POST['passwordfld1']) {
288
			local_user_set_password($userent, $_POST['passwordfld1']);
289
		}
290

    
291
		/* only change description if sent */
292
		if (isset($_POST['descr'])) {
293
			$userent['descr'] = $_POST['descr'];
294
		}
295

    
296
		$userent['name'] = $_POST['usernamefld'];
297
		$userent['expires'] = $_POST['expires'];
298
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
299
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
300
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
301

    
302
		if ($_POST['disabled']) {
303
			$userent['disabled'] = true;
304
		} else {
305
			unset($userent['disabled']);
306
		}
307

    
308
		if ($_POST['customsettings']) {
309
			$userent['customsettings'] = true;
310
		} else {
311
			unset($userent['customsettings']);
312
		}
313

    
314
		if ($_POST['webguicss']) {
315
			$userent['webguicss'] = $_POST['webguicss'];
316
		} else {
317
			unset($userent['webguicss']);
318
		}
319

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

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

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

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

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

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

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

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

    
368
		if (isset($id) && $a_user[$id]) {
369
			$a_user[$id] = $userent;
370
		} else {
371
			if (!empty($_POST['name'])) {
372
				$cert = array();
373
				$cert['refid'] = uniqid();
374
				$userent['cert'] = array();
375

    
376
				$cert['descr'] = $_POST['name'];
377

    
378
				$subject = cert_get_subject_array($ca['crt']);
379

    
380
				$dn = array(
381
					'countryName' => $subject[0]['v'],
382
					'stateOrProvinceName' => $subject[1]['v'],
383
					'localityName' => $subject[2]['v'],
384
					'organizationName' => $subject[3]['v'],
385
					'emailAddress' => $subject[4]['v'],
386
					'commonName' => $userent['name']);
387

    
388
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
389
					(int)$_POST['lifetime'], $dn);
390

    
391
				if (!is_array($config['cert'])) {
392
					$config['cert'] = array();
393
				}
394
				$config['cert'][] = $cert;
395
				$userent['cert'][] = $cert['refid'];
396
			}
397
			$userent['uid'] = $config['system']['nextuid']++;
398
			/* Add the user to All Users group. */
399
			foreach ($config['system']['group'] as $gidx => $group) {
400
				if ($group['name'] == "all") {
401
					if (!is_array($config['system']['group'][$gidx]['member'])) {
402
						$config['system']['group'][$gidx]['member'] = array();
403
					}
404
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
405
					break;
406
				}
407
			}
408

    
409
			$a_user[] = $userent;
410
		}
411

    
412
		/* 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. */
413
		local_user_set_groups($userent, $_POST['groups']);
414
		local_user_set($userent);
415
		/* 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. */
416
		local_user_set_groups($userent, $_POST['groups']);
417
		write_config();
418

    
419
		if (is_dir("/etc/inc/privhooks")) {
420
			run_plugins("/etc/inc/privhooks");
421
		}
422

    
423

    
424
		pfSenseHeader("system_usermanager.php");
425
	}
426
}
427

    
428
function build_priv_table() {
429
	global $a_user, $id;
430

    
431
	$privhtml = '<div class="table-responsive">';
432
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
433
	$privhtml .=		'<thead>';
434
	$privhtml .=			'<tr>';
435
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
436
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
437
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
438
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
439
	$privhtml .=			'</tr>';
440
	$privhtml .=		'</thead>';
441
	$privhtml .=		'<tbody>';
442

    
443
	$i = 0;
444
	$user_has_root_priv = false;
445

    
446
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
447
		$group = false;
448
		if ($priv['group']) {
449
			$group = $priv['group'];
450
		}
451

    
452
		$privhtml .=		'<tr>';
453
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
454
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
455
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
456
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
457
			$privhtml .=			' ' . gettext('(admin privilege)');
458
			$user_has_root_priv = true;
459
		}
460
		$privhtml .=			'</td>';
461
		$privhtml .=			'<td>';
462
		if (!$group) {
463
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
464
		}
465

    
466
		$privhtml .=			'</td>';
467
		$privhtml .=		'</tr>';
468

    
469
		if (!$group) {
470
			$i++;
471
		}
472
	}
473

    
474
	if ($user_has_root_priv) {
475
		$privhtml .=		'<tr>';
476
		$privhtml .=			'<td colspan="3">';
477
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
478
		$privhtml .=			'</td>';
479
		$privhtml .=			'<td>';
480
		$privhtml .=			'</td>';
481
		$privhtml .=		'</tr>';
482

    
483
	}
484

    
485
	$privhtml .=		'</tbody>';
486
	$privhtml .=	'</table>';
487
	$privhtml .= '</div>';
488

    
489
	$privhtml .= '<nav class="action-buttons">';
490
	$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>';
491
	$privhtml .= '</nav>';
492

    
493
	return($privhtml);
494
}
495

    
496
function build_cert_table() {
497
	global $a_user, $id;
498

    
499
	$certhtml = '<div class="table-responsive">';
500
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
501
	$certhtml .=		'<thead>';
502
	$certhtml .=			'<tr>';
503
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
504
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
505
	$certhtml .=				'<th></th>';
506
	$certhtml .=			'</tr>';
507
	$certhtml .=		'</thead>';
508
	$certhtml .=		'<tbody>';
509

    
510
	$a_cert = $a_user[$id]['cert'];
511
	if (is_array($a_cert)) {
512
		$i = 0;
513
		foreach ($a_cert as $certref) {
514
			$cert = lookup_cert($certref);
515
			$ca = lookup_ca($cert['caref']);
516
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
517

    
518
			$certhtml .=	'<tr>';
519
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
520
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
521
			$certhtml .=		'<td>';
522
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
523
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
524
			$certhtml .=		'</td>';
525
			$certhtml .=	'</tr>';
526
			$i++;
527
		}
528

    
529
	}
530

    
531
	$certhtml .=		'</tbody>';
532
	$certhtml .=	'</table>';
533
	$certhtml .= '</div>';
534

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

    
539
	return($certhtml);
540
}
541

    
542
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
543
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
544

    
545
if ($act == "new" || $act == "edit" || $input_errors) {
546
	$pgtitle[] = gettext('Edit');
547
	$pglinks[] = "@self";
548
}
549

    
550
include("head.inc");
551

    
552
if ($delete_errors) {
553
	print_input_errors($delete_errors);
554
}
555

    
556
if ($input_errors) {
557
	print_input_errors($input_errors);
558
}
559

    
560
if ($savemsg) {
561
	print_info_box($savemsg, 'success');
562
}
563

    
564
$tab_array = array();
565
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
566
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
567
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
568
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
569
display_top_tabs($tab_array);
570

    
571
if (!($act == "new" || $act == "edit" || $input_errors)) {
572
?>
573
<form method="post">
574
<div class="panel panel-default">
575
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
576
	<div class="panel-body">
577
		<div class="table-responsive">
578
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
579
				<thead>
580
					<tr>
581
						<th>&nbsp;</th>
582
						<th><?=gettext("Username")?></th>
583
						<th><?=gettext("Full name")?></th>
584
						<th><?=gettext("Status")?></th>
585
						<th><?=gettext("Groups")?></th>
586
						<th><?=gettext("Actions")?></th>
587
					</tr>
588
				</thead>
589
				<tbody>
590
<?php
591
foreach ($a_user as $i => $userent):
592
	?>
593
					<tr>
594
						<td>
595
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
596
						</td>
597
						<td>
598
<?php
599
	if ($userent['scope'] != "user") {
600
		$usrimg = 'eye-open';
601
	} else {
602
		$usrimg = 'user';
603
	}
604
?>
605
							<i class="fa fa-<?=$usrimg?>"></i>
606
							<?=htmlspecialchars($userent['name'])?>
607
						</td>
608
						<td><?=htmlspecialchars($userent['descr'])?></td>
609
						<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>
610
						<td><?=implode(",", local_user_get_groups($userent))?></td>
611
						<td>
612
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
613
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
614
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>" usepost></a>
615
<?php endif; ?>
616
						</td>
617
					</tr>
618
<?php endforeach; ?>
619
				</tbody>
620
			</table>
621
		</div>
622
	</div>
623
</div>
624
<nav class="action-buttons">
625
	<a href="?act=new" class="btn btn-sm btn-success">
626
		<i class="fa fa-plus icon-embed-btn"></i>
627
		<?=gettext("Add")?>
628
	</a>
629

    
630
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
631
		<i class="fa fa-trash icon-embed-btn"></i>
632
		<?=gettext("Delete")?>
633
	</button>
634

    
635
</nav>
636
</form>
637
<div class="infoblock">
638
<?php
639
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
640
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
641
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
642
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
643
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
644
	);
645

    
646
?></div>
647

    
648
<?php
649
	include("foot.inc");
650
	exit;
651
}
652

    
653
$form = new Form;
654

    
655
if ($act == "new" || $act == "edit" || $input_errors):
656

    
657
	$form->addGlobal(new Form_Input(
658
		'act',
659
		null,
660
		'hidden',
661
		''
662
	));
663

    
664
	$form->addGlobal(new Form_Input(
665
		'userid',
666
		null,
667
		'hidden',
668
		isset($id) ? $id:''
669
	));
670

    
671
	$form->addGlobal(new Form_Input(
672
		'privid',
673
		null,
674
		'hidden',
675
		''
676
	));
677

    
678
	$form->addGlobal(new Form_Input(
679
		'certid',
680
		null,
681
		'hidden',
682
		''
683
	));
684

    
685
	$ro = "";
686
	if ($pconfig['utype'] == "system") {
687
		$ro = "readonly";
688
	}
689

    
690
	$section = new Form_Section('User Properties');
691

    
692
	$section->addInput(new Form_StaticText(
693
		'Defined by',
694
		strtoupper($pconfig['utype'])
695
	));
696

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

    
704
	$section->addInput(new Form_Checkbox(
705
		'disabled',
706
		'Disabled',
707
		'This user cannot login',
708
		$pconfig['disabled']
709
	));
710

    
711
	$section->addInput($input = new Form_Input(
712
		'usernamefld',
713
		'*Username',
714
		'text',
715
		$pconfig['usernamefld']
716
	));
717

    
718
	if ($ro) {
719
		$input->setReadonly();
720
	}
721

    
722
	$form->addGlobal(new Form_Input(
723
		'oldusername',
724
		null,
725
		'hidden',
726
		$pconfig['usernamefld']
727
	));
728

    
729
	if ($act == "edit") {
730
		$pwd_required = "";
731
	} else {
732
		$pwd_required = "*";
733
	}
734

    
735
	$group = new Form_Group($pwd_required . 'Password');
736
	$group->add(new Form_Input(
737
		'passwordfld1',
738
		'Password',
739
		'password'
740
	));
741
	$group->add(new Form_Input(
742
		'passwordfld2',
743
		'Confirm Password',
744
		'password'
745
	));
746

    
747
	$section->add($group);
748

    
749
	$section->addInput($input = new Form_Input(
750
		'descr',
751
		'Full name',
752
		'text',
753
		htmlspecialchars($pconfig['descr'])
754
	))->setHelp('User\'s full name, for administrative information only');
755

    
756
	if ($ro) {
757
		$input->setDisabled();
758
	}
759

    
760
	$section->addInput(new Form_Input(
761
		'expires',
762
		'Expiration date',
763
		'text',
764
		$pconfig['expires']
765
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
766
		'the expiration date as MM/DD/YYYY');
767

    
768
	$section->addInput(new Form_Checkbox(
769
		'customsettings',
770
		'Custom Settings',
771
		'Use individual customized GUI options and dashboard layout for this user.',
772
		$pconfig['customsettings']
773
	));
774

    
775
	gen_user_settings_fields($section, $pconfig);
776

    
777
	// ==== Group membership ==================================================
778
	$group = new Form_Group('Group membership');
779

    
780
	// Make a list of all the groups configured on the system, and a list of
781
	// those which this user is a member of
782
	$systemGroups = array();
783
	$usersGroups = array();
784

    
785
	$usergid = [$pconfig['usernamefld']];
786

    
787
	foreach ($config['system']['group'] as $Ggroup) {
788
		if ($Ggroup['name'] != "all") {
789
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
790
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
791
			} else {
792
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
793
			}
794
		}
795
	}
796

    
797
	$group->add(new Form_Select(
798
		'sysgroups',
799
		null,
800
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
801
		$systemGroups,
802
		true
803
	))->setHelp('Not member of');
804

    
805
	$group->add(new Form_Select(
806
		'groups',
807
		null,
808
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
809
		$usersGroups,
810
		true
811
	))->setHelp('Member of');
812

    
813
	$section->add($group);
814

    
815
	$group = new Form_Group('');
816

    
817
	$group->add(new Form_Button(
818
		'movetoenabled',
819
		'Move to "Member of" list',
820
		null,
821
		'fa-angle-double-right'
822
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
823

    
824
	$group->add(new Form_Button(
825
		'movetodisabled',
826
		'Move to "Not member of" list',
827
		null,
828
		'fa-angle-double-left'
829
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
830

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

    
834
	// ==== Button for adding user certificate ================================
835
	if ($act == 'new') {
836
		$section->addInput(new Form_Checkbox(
837
			'showcert',
838
			'Certificate',
839
			'Click to create a user certificate',
840
			false
841
		));
842
	}
843

    
844
	$form->add($section);
845

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

    
851
		$section = new Form_Section('Effective Privileges');
852

    
853
		$section->addInput(new Form_StaticText(
854
			null,
855
			build_priv_table()
856
		));
857

    
858
		$form->add($section);
859

    
860
		// ==== Certificate table section =====================================
861
		$section = new Form_Section('User Certificates');
862

    
863
		$section->addInput(new Form_StaticText(
864
			null,
865
			build_cert_table()
866
		));
867

    
868
		$form->add($section);
869
	}
870

    
871
	// ==== Add user certificate for a new user
872
	if (is_array($config['ca']) && count($config['ca']) > 0) {
873
		$section = new Form_Section('Create Certificate for User');
874
		$section->addClass('cert-options');
875

    
876
		$nonPrvCas = array();
877
		foreach ($config['ca'] as $ca) {
878
			if (!$ca['prv']) {
879
				continue;
880
			}
881

    
882
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
883
		}
884

    
885
		if (!empty($nonPrvCas)) {
886
			$section->addInput(new Form_Input(
887
				'name',
888
				'Descriptive name',
889
				'text',
890
				$pconfig['name']
891
			));
892

    
893
			$section->addInput(new Form_Select(
894
				'caref',
895
				'Certificate authority',
896
				null,
897
				$nonPrvCas
898
			));
899

    
900
			$section->addInput(new Form_Select(
901
				'keylen',
902
				'Key length',
903
				2048,
904
				array(
905
					512 => '512 bits',
906
					1024 => '1024 bits',
907
					2048 => '2048 bits',
908
					3072 => '3072 bits',
909
					4096 => '4096 bits',
910
					7680 => '7680 bits',
911
					8192 => '8192 bits',
912
					15360 => '15360 bits',
913
					16384 => '16384 bits'
914
				)
915
			))->setHelp('The larger the key, the more security it offers, but larger keys take considerably more time to generate, ' .
916
				'and take slightly longer to validate leading to a slight slowdown in setting up new sessions (not always noticeable). ' .
917
				'As of 2016, 2048 bit is the minimum and most common selection and 4096 is the maximum in common use. ' .
918
				'For more information see %1$s.', '<a href="https://keylength.com">keylength.com</a>');
919

    
920
			$section->addInput(new Form_Input(
921
				'lifetime',
922
				'Lifetime',
923
				'number',
924
				$pconfig['lifetime']
925
			));
926
		}
927

    
928
		$form->add($section);
929
	}
930

    
931
endif;
932
// ==== Paste a key for the new user
933
$section = new Form_Section('Keys');
934

    
935
$section->addInput(new Form_Checkbox(
936
	'showkey',
937
	'Authorized keys',
938
	'Click to paste an authorized key',
939
	false
940
));
941

    
942
$section->addInput(new Form_Textarea(
943
	'authorizedkeys',
944
	'Authorized SSH Keys',
945
	$pconfig['authorizedkeys']
946
))->setHelp('Enter authorized SSH keys for this user');
947

    
948
$section->addInput(new Form_Input(
949
	'ipsecpsk',
950
	'IPsec Pre-Shared Key',
951
	'text',
952
	$pconfig['ipsecpsk']
953
));
954

    
955
$form->add($section);
956

    
957
print $form;
958

    
959
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
960
?>
961
<script type="text/javascript">
962
//<![CDATA[
963
events.push(function() {
964

    
965
	function setcustomoptions() {
966
		var adv = $('#customsettings').prop('checked');
967

    
968
		hideInput('webguicss', !adv);
969
		hideInput('webguifixedmenu', !adv);
970
		hideInput('webguihostnamemenu', !adv);
971
		hideInput('dashboardcolumns', !adv);
972
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
973
		hideCheckbox('systemlogsfilterpanel', !adv);
974
		hideCheckbox('systemlogsmanagelogpanel', !adv);
975
		hideCheckbox('statusmonitoringsettingspanel', !adv);
976
		hideCheckbox('webguileftcolumnhyper', !adv);
977
		hideCheckbox('pagenamefirst', !adv);
978
	}
979

    
980
	// Handle displaying a warning message if a user-created theme is selected.
981
	function setThemeWarning() {
982
		if ($('#webguicss').val().startsWith("pfSense")) {
983
			$('#csstxt').html("").addClass("text-default");
984
		} else {
985
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
986
		}
987
	}
988

    
989
	$('#webguicss').change(function() {
990
		setThemeWarning();
991
	});
992

    
993
	setThemeWarning();
994

    
995
	// On click . .
996
	$('#customsettings').click(function () {
997
		setcustomoptions();
998
	});
999

    
1000
	$("#movetodisabled").click(function() {
1001
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1002
	});
1003

    
1004
	$("#movetoenabled").click(function() {
1005
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1006
	});
1007

    
1008
	$("#showcert").click(function() {
1009
		hideClass('cert-options', !this.checked);
1010
	});
1011

    
1012
	$("#showkey").click(function() {
1013
		hideInput('authorizedkeys', false);
1014
		hideCheckbox('showkey', true);
1015
	});
1016

    
1017
	$('[id^=delcert]').click(function(event) {
1018
		if (confirm(event.target.title)) {
1019
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
1020
			$('#userid').val('<?=$id;?>');
1021
			$('#act').val('delcert');
1022
			$('form').submit();
1023
		}
1024
	});
1025

    
1026
	$('[id^=delprivid]').click(function(event) {
1027
		if (confirm(event.target.title)) {
1028
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
1029
			$('#userid').val('<?=$id;?>');
1030
			$('#act').val('delprivid');
1031
			$('form').submit();
1032
		}
1033
	});
1034

    
1035
	$('#expires').datepicker();
1036

    
1037
	// ---------- On initial page load ------------------------------------------------------------
1038

    
1039
	hideClass('cert-options', true);
1040
	//hideInput('authorizedkeys', true);
1041
	hideCheckbox('showkey', true);
1042
	setcustomoptions();
1043

    
1044
	// On submit mark all the user's groups as "selected"
1045
	$('form').submit(function() {
1046
		AllServers($('[name="groups[]"] option'), true);
1047
	});
1048

    
1049
});
1050
//]]>
1051
</script>
1052
<?php
1053
include('foot.inc');
1054
?>
(204-204/223)