Project

General

Profile

Download (29.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-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($_POST['userid']) && is_numericint($_POST['userid'])) {
41
	$id = $_POST['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 = $_POST['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" usepost><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" usepost><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
include("head.inc");
550

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

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

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

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

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

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

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

    
645
?></div>
646

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

    
652
$form = new Form;
653

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
774
	gen_user_settings_fields($section, $pconfig);
775

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
956
print $form;
957

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

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

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

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

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

    
992
	setThemeWarning();
993

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

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

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

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

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

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

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

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

    
1036
	// ---------- On initial page load ------------------------------------------------------------
1037

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

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

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