Project

General

Profile

Download (30.6 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
// start admin user code
41
if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
42
	$id = $_REQUEST['userid'];
43
}
44

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

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

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

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

    
84
if ($_POST['act'] == "deluser") {
85

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

    
91
	if ($_POST['username'] == $_SESSION['Username']) {
92
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_POST['username']);
93
	} else {
94
		local_user_del($a_user[$id]);
95
		$userdeleted = $a_user[$id]['name'];
96
		unset($a_user[$id]);
97
		/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
98
		$a_user = array_values($a_user);
99
		write_config();
100
		$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
101
	}
102

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

    
112
	$nonPrvCas = array();
113
	if (is_array($config['ca']) && count($config['ca']) > 0) {
114
		foreach ($config['ca'] as $ca) {
115
			if (!$ca['prv']) {
116
				continue;
117
			}
118

    
119
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
120
		}
121
	}
122

    
123
}
124

    
125
if (isset($_POST['dellall'])) {
126

    
127
	$del_users = $_POST['delete_check'];
128
	$deleted_users = "";
129
	$deleted_count = 0;
130
	$comma = "";
131

    
132
	if (!empty($del_users)) {
133
		foreach ($del_users as $userid) {
134
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
135
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
136
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
137
				} else {
138
					$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
139
					$comma = ", ";
140
					$deleted_count++;
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 ($deleted_count > 0) {
150
			if ($deleted_count == 1) {
151
				$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
152
			} else {
153
				$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
154
			}
155
			/* Reindex the array to avoid operating on an incorrect index https://redmine.pfsense.org/issues/7733 */
156
			$a_user = array_values($a_user);
157
			write_config($savemsg);
158
		}
159
	}
160
}
161

    
162
if ($_POST['act'] == "delcert") {
163

    
164
	if (!$a_user[$id]) {
165
		pfSenseHeader("system_usermanager.php");
166
		exit;
167
	}
168

    
169
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
170
	$certdeleted = $certdeleted['descr'];
171
	unset($a_user[$id]['cert'][$_POST['certid']]);
172
	write_config();
173
	$_POST['act'] = "edit";
174
	$savemsg = sprintf(gettext("Certificate %s association removed."), $certdeleted);
175
}
176

    
177
if ($_POST['act'] == "delprivid") {
178
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
179
	unset($a_user[$id]['priv'][$_POST['privid']]);
180
	local_user_set($a_user[$id]);
181
	write_config();
182
	$_POST['act'] = "edit";
183
	$savemsg = sprintf(gettext("Privilege %s removed."), $privdeleted);
184
}
185

    
186
if ($_POST['save']) {
187
	unset($input_errors);
188
	$pconfig = $_POST;
189

    
190
	/* input validation */
191
	if (isset($id) && ($a_user[$id])) {
192
		$reqdfields = explode(" ", "usernamefld");
193
		$reqdfieldsn = array(gettext("Username"));
194
	} else {
195
		if (empty($_POST['name'])) {
196
			$reqdfields = explode(" ", "usernamefld passwordfld1");
197
			$reqdfieldsn = array(
198
				gettext("Username"),
199
				gettext("Password"));
200
		} else {
201
			$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
202
			$reqdfieldsn = array(
203
				gettext("Username"),
204
				gettext("Password"),
205
				gettext("Descriptive name"),
206
				gettext("Certificate authority"),
207
				gettext("Key length"),
208
				gettext("Lifetime"));
209
		}
210
	}
211

    
212
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
213

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

    
218
	if (strlen($_POST['usernamefld']) > 32) {
219
		$input_errors[] = gettext("The username is longer than 32 characters.");
220
	}
221

    
222
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
223
		$input_errors[] = gettext("The passwords do not match.");
224
	}
225

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

    
230
	/* Check the POSTed groups to ensure they are valid and exist */
231
	if (is_array($_POST['groups'])) {
232
		foreach ($_POST['groups'] as $newgroup) {
233
			if (empty(getGroupEntry($newgroup))) {
234
				$input_errors[] = gettext("One or more invalid groups was submitted.");
235
			}
236
		}
237
	}
238

    
239
	if (isset($id) && $a_user[$id]) {
240
		$oldusername = $a_user[$id]['name'];
241
	} else {
242
		$oldusername = "";
243
	}
244
	/* make sure this user name is unique */
245
	if (!$input_errors) {
246
		foreach ($a_user as $userent) {
247
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
248
				$input_errors[] = gettext("Another entry with the same username already exists.");
249
				break;
250
			}
251
		}
252
	}
253
	/* also make sure it is not reserved */
254
	if (!$input_errors) {
255
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
256
		foreach ($system_users as $s_user) {
257
			$ent = explode(":", $s_user);
258
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
259
				$input_errors[] = gettext("That username is reserved by the system.");
260
				break;
261
			}
262
		}
263
	}
264

    
265
	/*
266
	 * Check for a valid expiration date if one is set at all (valid means,
267
	 * DateTime puts out a time stamp so any DateTime compatible time
268
	 * format may be used. to keep it simple for the enduser, we only
269
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
270
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
271
	 * Otherwise such an entry would lead to an invalid expiration data.
272
	 */
273
	if ($_POST['expires']) {
274
		try {
275
			$expdate = new DateTime($_POST['expires']);
276
			//convert from any DateTime compatible date to MM/DD/YYYY
277
			$_POST['expires'] = $expdate->format("m/d/Y");
278
		} catch (Exception $ex) {
279
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
280
		}
281
	}
282

    
283
	if (!empty($_POST['name'])) {
284
		$ca = lookup_ca($_POST['caref']);
285
		if (!$ca) {
286
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
287
		}
288
	}
289

    
290
	if (!$input_errors) {
291

    
292
		$userent = array();
293
		if (isset($id) && $a_user[$id]) {
294
			$userent = $a_user[$id];
295
		}
296

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

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

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

    
310
		/* only change description if sent */
311
		if (isset($_POST['descr'])) {
312
			$userent['descr'] = $_POST['descr'];
313
		}
314

    
315
		$userent['name'] = $_POST['usernamefld'];
316
		$userent['expires'] = $_POST['expires'];
317
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
318
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
319
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
320

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

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

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

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

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

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

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

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

    
369
		if ($_POST['systemlogsmanagelogpanel']) {
370
			$userent['systemlogsmanagelogpanel'] = true;
371
		} else {
372
			unset($userent['systemlogsmanagelogpanel']);
373
		}
374

    
375
		if ($_POST['statusmonitoringsettingspanel']) {
376
			$userent['statusmonitoringsettingspanel'] = true;
377
		} else {
378
			unset($userent['statusmonitoringsettingspanel']);
379
		}
380

    
381
		if ($_POST['webguileftcolumnhyper']) {
382
			$userent['webguileftcolumnhyper'] = true;
383
		} else {
384
			unset($userent['webguileftcolumnhyper']);
385
		}
386

    
387
		if ($_POST['disablealiaspopupdetail']) {
388
			$userent['disablealiaspopupdetail'] = true;
389
		} else {
390
			unset($userent['disablealiaspopupdetail']);
391
		}
392

    
393
		if ($_POST['pagenamefirst']) {
394
			$userent['pagenamefirst'] = true;
395
		} else {
396
			unset($userent['pagenamefirst']);
397
		}
398

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

    
407
				$cert['descr'] = $_POST['name'];
408

    
409
				$subject = cert_get_subject_array($ca['crt']);
410

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

    
423
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
424
					(int)$_POST['lifetime'], $dn);
425

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

    
444
			$a_user[] = $userent;
445
		}
446

    
447
		/* 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. */
448
		local_user_set_groups($userent, $_POST['groups']);
449
		local_user_set($userent);
450
		/* 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. */
451
		local_user_set_groups($userent, $_POST['groups']);
452
		write_config();
453

    
454
		if (is_dir("/etc/inc/privhooks")) {
455
			run_plugins("/etc/inc/privhooks");
456
		}
457

    
458

    
459
		pfSenseHeader("system_usermanager.php");
460
	}
461
}
462

    
463
function build_priv_table() {
464
	global $a_user, $id;
465

    
466
	$privhtml = '<div class="table-responsive">';
467
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
468
	$privhtml .=		'<thead>';
469
	$privhtml .=			'<tr>';
470
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
471
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
472
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
473
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
474
	$privhtml .=			'</tr>';
475
	$privhtml .=		'</thead>';
476
	$privhtml .=		'<tbody>';
477

    
478
	$i = 0;
479
	$user_has_root_priv = false;
480

    
481
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
482
		$group = false;
483
		if ($priv['group']) {
484
			$group = $priv['group'];
485
		}
486

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

    
501
		$privhtml .=			'</td>';
502
		$privhtml .=		'</tr>';
503

    
504
		if (!$group) {
505
			$i++;
506
		}
507
	}
508

    
509
	if ($user_has_root_priv) {
510
		$privhtml .=		'<tr>';
511
		$privhtml .=			'<td colspan="3">';
512
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
513
		$privhtml .=			'</td>';
514
		$privhtml .=			'<td>';
515
		$privhtml .=			'</td>';
516
		$privhtml .=		'</tr>';
517

    
518
	}
519

    
520
	$privhtml .=		'</tbody>';
521
	$privhtml .=	'</table>';
522
	$privhtml .= '</div>';
523

    
524
	$privhtml .= '<nav class="action-buttons">';
525
	$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>';
526
	$privhtml .= '</nav>';
527

    
528
	return($privhtml);
529
}
530

    
531
function build_cert_table() {
532
	global $a_user, $id;
533

    
534
	$certhtml = '<div class="table-responsive">';
535
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
536
	$certhtml .=		'<thead>';
537
	$certhtml .=			'<tr>';
538
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
539
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
540
	$certhtml .=				'<th></th>';
541
	$certhtml .=			'</tr>';
542
	$certhtml .=		'</thead>';
543
	$certhtml .=		'<tbody>';
544

    
545
	$a_cert = $a_user[$id]['cert'];
546
	if (is_array($a_cert)) {
547
		$i = 0;
548
		foreach ($a_cert as $certref) {
549
			$cert = lookup_cert($certref);
550
			$ca = lookup_ca($cert['caref']);
551
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
552

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

    
564
	}
565

    
566
	$certhtml .=		'</tbody>';
567
	$certhtml .=	'</table>';
568
	$certhtml .= '</div>';
569

    
570
	$certhtml .= '<nav class="action-buttons">';
571
	$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>';
572
	$certhtml .= '</nav>';
573

    
574
	return($certhtml);
575
}
576

    
577
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
578
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
579

    
580
if ($act == "new" || $act == "edit" || $input_errors) {
581
	$pgtitle[] = gettext('Edit');
582
	$pglinks[] = "@self";
583
}
584

    
585
include("head.inc");
586

    
587
if ($delete_errors) {
588
	print_input_errors($delete_errors);
589
}
590

    
591
if ($input_errors) {
592
	print_input_errors($input_errors);
593
}
594

    
595
if ($savemsg) {
596
	print_info_box($savemsg, 'success');
597
}
598

    
599
$tab_array = array();
600
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
601
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
602
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
603
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
604
display_top_tabs($tab_array);
605

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

    
665
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
666
		<i class="fa fa-trash icon-embed-btn"></i>
667
		<?=gettext("Delete")?>
668
	</button>
669

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

    
681
?></div>
682

    
683
<?php
684
	include("foot.inc");
685
	exit;
686
}
687

    
688
$form = new Form;
689

    
690
if ($act == "new" || $act == "edit" || $input_errors):
691

    
692
	$form->addGlobal(new Form_Input(
693
		'act',
694
		null,
695
		'hidden',
696
		''
697
	));
698

    
699
	$form->addGlobal(new Form_Input(
700
		'userid',
701
		null,
702
		'hidden',
703
		isset($id) ? $id:''
704
	));
705

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

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

    
720
	$ro = "";
721
	if ($pconfig['utype'] == "system") {
722
		$ro = "readonly";
723
	}
724

    
725
	$section = new Form_Section('User Properties');
726

    
727
	$section->addInput(new Form_StaticText(
728
		'Defined by',
729
		strtoupper($pconfig['utype'])
730
	));
731

    
732
	$form->addGlobal(new Form_Input(
733
		'utype',
734
		null,
735
		'hidden',
736
		$pconfig['utype']
737
	));
738

    
739
	$section->addInput(new Form_Checkbox(
740
		'disabled',
741
		'Disabled',
742
		'This user cannot login',
743
		$pconfig['disabled']
744
	));
745

    
746
	$section->addInput($input = new Form_Input(
747
		'usernamefld',
748
		'*Username',
749
		'text',
750
		$pconfig['usernamefld']
751
	));
752

    
753
	if ($ro) {
754
		$input->setReadonly();
755
	}
756

    
757
	$form->addGlobal(new Form_Input(
758
		'oldusername',
759
		null,
760
		'hidden',
761
		$pconfig['usernamefld']
762
	));
763

    
764
	if ($act == "edit") {
765
		$pwd_required = "";
766
	} else {
767
		$pwd_required = "*";
768
	}
769

    
770
	$group = new Form_Group($pwd_required . 'Password');
771
	$group->add(new Form_Input(
772
		'passwordfld1',
773
		'Password',
774
		'password'
775
	));
776
	$group->add(new Form_Input(
777
		'passwordfld2',
778
		'Confirm Password',
779
		'password'
780
	));
781

    
782
	$section->add($group);
783

    
784
	$section->addInput($input = new Form_Input(
785
		'descr',
786
		'Full name',
787
		'text',
788
		htmlspecialchars($pconfig['descr'])
789
	))->setHelp('User\'s full name, for administrative information only');
790

    
791
	if ($ro) {
792
		$input->setDisabled();
793
	}
794

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

    
803
	$section->addInput(new Form_Checkbox(
804
		'customsettings',
805
		'Custom Settings',
806
		'Use individual customized GUI options and dashboard layout for this user.',
807
		$pconfig['customsettings']
808
	));
809

    
810
	gen_user_settings_fields($section, $pconfig);
811

    
812
	// ==== Group membership ==================================================
813
	$group = new Form_Group('Group membership');
814

    
815
	// Make a list of all the groups configured on the system, and a list of
816
	// those which this user is a member of
817
	$systemGroups = array();
818
	$usersGroups = array();
819

    
820
	$usergid = [$pconfig['usernamefld']];
821

    
822
	foreach ($config['system']['group'] as $Ggroup) {
823
		if ($Ggroup['name'] != "all") {
824
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
825
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
826
			} else {
827
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
828
			}
829
		}
830
	}
831

    
832
	$group->add(new Form_Select(
833
		'sysgroups',
834
		null,
835
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
836
		$systemGroups,
837
		true
838
	))->setHelp('Not member of');
839

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

    
848
	$section->add($group);
849

    
850
	$group = new Form_Group('');
851

    
852
	$group->add(new Form_Button(
853
		'movetoenabled',
854
		'Move to "Member of" list',
855
		null,
856
		'fa-angle-double-right'
857
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
858

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

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

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

    
887
	$form->add($section);
888

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

    
894
		$section = new Form_Section('Effective Privileges');
895

    
896
		$section->addInput(new Form_StaticText(
897
			null,
898
			build_priv_table()
899
		));
900

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

    
903
		// ==== Certificate table section =====================================
904
		$section = new Form_Section('User Certificates');
905

    
906
		$section->addInput(new Form_StaticText(
907
			null,
908
			build_cert_table()
909
		));
910

    
911
		$form->add($section);
912
	}
913

    
914
	// ==== Add user certificate for a new user
915
	if (is_array($config['ca']) && count($config['ca']) > 0) {
916
		$section = new Form_Section('Create Certificate for User');
917
		$section->addClass('cert-options');
918

    
919
		if (!empty($nonPrvCas)) {
920
			$section->addInput(new Form_Input(
921
				'name',
922
				'Descriptive name',
923
				'text',
924
				$pconfig['name']
925
			));
926

    
927
			$section->addInput(new Form_Select(
928
				'caref',
929
				'Certificate authority',
930
				null,
931
				$nonPrvCas
932
			));
933

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

    
954
			$section->addInput(new Form_Input(
955
				'lifetime',
956
				'Lifetime',
957
				'number',
958
				$pconfig['lifetime']
959
			));
960
		}
961

    
962
		$form->add($section);
963
	}
964

    
965
endif;
966
// ==== Paste a key for the new user
967
$section = new Form_Section('Keys');
968

    
969
$section->addInput(new Form_Checkbox(
970
	'showkey',
971
	'Authorized keys',
972
	'Click to paste an authorized key',
973
	false
974
));
975

    
976
$section->addInput(new Form_Textarea(
977
	'authorizedkeys',
978
	'Authorized SSH Keys',
979
	$pconfig['authorizedkeys']
980
))->setHelp('Enter authorized SSH keys for this user');
981

    
982
$section->addInput(new Form_Input(
983
	'ipsecpsk',
984
	'IPsec Pre-Shared Key',
985
	'text',
986
	$pconfig['ipsecpsk']
987
));
988

    
989
$form->add($section);
990

    
991
print $form;
992

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

    
999
	function setcustomoptions() {
1000
		var adv = $('#customsettings').prop('checked');
1001

    
1002
		hideInput('webguicss', !adv);
1003
		hideInput('webguifixedmenu', !adv);
1004
		hideInput('webguihostnamemenu', !adv);
1005
		hideInput('dashboardcolumns', !adv);
1006
		hideCheckbox('interfacessort', !adv);
1007
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
1008
		hideCheckbox('systemlogsfilterpanel', !adv);
1009
		hideCheckbox('systemlogsmanagelogpanel', !adv);
1010
		hideCheckbox('statusmonitoringsettingspanel', !adv);
1011
		hideCheckbox('webguileftcolumnhyper', !adv);
1012
		hideCheckbox('disablealiaspopupdetail', !adv);
1013
		hideCheckbox('pagenamefirst', !adv);
1014
	}
1015

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

    
1025
	$('#webguicss').change(function() {
1026
		setThemeWarning();
1027
	});
1028

    
1029
	setThemeWarning();
1030

    
1031
	// On click . .
1032
	$('#customsettings').click(function () {
1033
		setcustomoptions();
1034
	});
1035

    
1036
	$("#movetodisabled").click(function() {
1037
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1038
	});
1039

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

    
1044
	$("#showcert").click(function() {
1045
		hideClass('cert-options', !this.checked);
1046
	});
1047

    
1048
	$("#showkey").click(function() {
1049
		hideInput('authorizedkeys', false);
1050
		hideCheckbox('showkey', true);
1051
	});
1052

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

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

    
1071
	$('#expires').datepicker();
1072

    
1073
	// ---------- On initial page load ------------------------------------------------------------
1074

    
1075
	hideClass('cert-options', true);
1076
	//hideInput('authorizedkeys', true);
1077
	hideCheckbox('showkey', true);
1078
	setcustomoptions();
1079

    
1080
	// On submit mark all the user's groups as "selected"
1081
	$('form').submit(function() {
1082
		AllServers($('[name="groups[]"] option'), true);
1083
	});
1084

    
1085
});
1086
//]]>
1087
</script>
1088
<?php
1089
include('foot.inc');
1090
?>
(212-212/232)