Project

General

Profile

Download (30.4 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
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
		write_config();
98
		$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
99
	}
100

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

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

    
117
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
118
		}
119
	}
120

    
121
}
122

    
123
if (isset($_POST['dellall'])) {
124

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

    
130
	if (!empty($del_users)) {
131
		foreach ($del_users as $userid) {
132
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
133
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
134
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
135
				} else {
136
					$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
137
					$comma = ", ";
138
					$deleted_count++;
139
					local_user_del($a_user[$userid]);
140
					unset($a_user[$userid]);
141
				}
142
			} else {
143
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
144
			}
145
		}
146

    
147
		if ($deleted_count > 0) {
148
			if ($deleted_count == 1) {
149
				$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
150
			} else {
151
				$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
152
			}
153
			write_config($savemsg);
154
		}
155
	}
156
}
157

    
158
if ($_POST['act'] == "delcert") {
159

    
160
	if (!$a_user[$id]) {
161
		pfSenseHeader("system_usermanager.php");
162
		exit;
163
	}
164

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

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

    
182
if ($_POST['save']) {
183
	unset($input_errors);
184
	$pconfig = $_POST;
185

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

    
208
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
209

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

    
214
	if (strlen($_POST['usernamefld']) > 16) {
215
		$input_errors[] = gettext("The username is longer than 16 characters.");
216
	}
217

    
218
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
219
		$input_errors[] = gettext("The passwords do not match.");
220
	}
221

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

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

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

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

    
279
	if (!empty($_POST['name'])) {
280
		$ca = lookup_ca($_POST['caref']);
281
		if (!$ca) {
282
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
283
		}
284
	}
285

    
286
	if (!$input_errors) {
287

    
288
		$userent = array();
289
		if (isset($id) && $a_user[$id]) {
290
			$userent = $a_user[$id];
291
		}
292

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

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

    
301
		/* the user password was modified */
302
		if ($_POST['passwordfld1']) {
303
			local_user_set_password($userent, $_POST['passwordfld1']);
304
		}
305

    
306
		/* only change description if sent */
307
		if (isset($_POST['descr'])) {
308
			$userent['descr'] = $_POST['descr'];
309
		}
310

    
311
		$userent['name'] = $_POST['usernamefld'];
312
		$userent['expires'] = $_POST['expires'];
313
		$userent['dashboardcolumns'] = $_POST['dashboardcolumns'];
314
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
315
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
316

    
317
		if ($_POST['disabled']) {
318
			$userent['disabled'] = true;
319
		} else {
320
			unset($userent['disabled']);
321
		}
322

    
323
		if ($_POST['customsettings']) {
324
			$userent['customsettings'] = true;
325
		} else {
326
			unset($userent['customsettings']);
327
		}
328

    
329
		if ($_POST['webguicss']) {
330
			$userent['webguicss'] = $_POST['webguicss'];
331
		} else {
332
			unset($userent['webguicss']);
333
		}
334

    
335
		if ($_POST['webguifixedmenu']) {
336
			$userent['webguifixedmenu'] = $_POST['webguifixedmenu'];
337
		} else {
338
			unset($userent['webguifixedmenu']);
339
		}
340

    
341
		if ($_POST['webguihostnamemenu']) {
342
			$userent['webguihostnamemenu'] = $_POST['webguihostnamemenu'];
343
		} else {
344
			unset($userent['webguihostnamemenu']);
345
		}
346

    
347
		if ($_POST['interfacessort']) {
348
			$userent['interfacessort'] = true;
349
		} else {
350
			unset($userent['interfacessort']);
351
		}
352

    
353
		if ($_POST['dashboardavailablewidgetspanel']) {
354
			$userent['dashboardavailablewidgetspanel'] = true;
355
		} else {
356
			unset($userent['dashboardavailablewidgetspanel']);
357
		}
358

    
359
		if ($_POST['systemlogsfilterpanel']) {
360
			$userent['systemlogsfilterpanel'] = true;
361
		} else {
362
			unset($userent['systemlogsfilterpanel']);
363
		}
364

    
365
		if ($_POST['systemlogsmanagelogpanel']) {
366
			$userent['systemlogsmanagelogpanel'] = true;
367
		} else {
368
			unset($userent['systemlogsmanagelogpanel']);
369
		}
370

    
371
		if ($_POST['statusmonitoringsettingspanel']) {
372
			$userent['statusmonitoringsettingspanel'] = true;
373
		} else {
374
			unset($userent['statusmonitoringsettingspanel']);
375
		}
376

    
377
		if ($_POST['webguileftcolumnhyper']) {
378
			$userent['webguileftcolumnhyper'] = true;
379
		} else {
380
			unset($userent['webguileftcolumnhyper']);
381
		}
382

    
383
		if ($_POST['disablealiaspopupdetail']) {
384
			$userent['disablealiaspopupdetail'] = true;
385
		} else {
386
			unset($userent['disablealiaspopupdetail']);
387
		}
388

    
389
		if ($_POST['pagenamefirst']) {
390
			$userent['pagenamefirst'] = true;
391
		} else {
392
			unset($userent['pagenamefirst']);
393
		}
394

    
395
		if (isset($id) && $a_user[$id]) {
396
			$a_user[$id] = $userent;
397
		} else {
398
			if (!empty($_POST['name'])) {
399
				$cert = array();
400
				$cert['refid'] = uniqid();
401
				$userent['cert'] = array();
402

    
403
				$cert['descr'] = $_POST['name'];
404

    
405
				$subject = cert_get_subject_array($ca['crt']);
406

    
407
				$dn = array(
408
					'countryName' => $subject[0]['v'],
409
					'stateOrProvinceName' => $subject[1]['v'],
410
					'localityName' => $subject[2]['v'],
411
					'organizationName' => $subject[3]['v'],
412
					'emailAddress' => $subject[4]['v'],
413
					'commonName' => $userent['name']);
414
				$altnames_tmp = array(cert_add_altname_type($userent['name']));
415
				if (!empty($altnames_tmp)) {
416
					$dn['subjectAltName'] = implode(",", $altnames_tmp);
417
				}
418

    
419
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
420
					(int)$_POST['lifetime'], $dn);
421

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

    
440
			$a_user[] = $userent;
441
		}
442

    
443
		/* 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. */
444
		local_user_set_groups($userent, $_POST['groups']);
445
		local_user_set($userent);
446
		/* 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. */
447
		local_user_set_groups($userent, $_POST['groups']);
448
		write_config();
449

    
450
		if (is_dir("/etc/inc/privhooks")) {
451
			run_plugins("/etc/inc/privhooks");
452
		}
453

    
454

    
455
		pfSenseHeader("system_usermanager.php");
456
	}
457
}
458

    
459
function build_priv_table() {
460
	global $a_user, $id;
461

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

    
474
	$i = 0;
475
	$user_has_root_priv = false;
476

    
477
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
478
		$group = false;
479
		if ($priv['group']) {
480
			$group = $priv['group'];
481
		}
482

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

    
497
		$privhtml .=			'</td>';
498
		$privhtml .=		'</tr>';
499

    
500
		if (!$group) {
501
			$i++;
502
		}
503
	}
504

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

    
514
	}
515

    
516
	$privhtml .=		'</tbody>';
517
	$privhtml .=	'</table>';
518
	$privhtml .= '</div>';
519

    
520
	$privhtml .= '<nav class="action-buttons">';
521
	$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>';
522
	$privhtml .= '</nav>';
523

    
524
	return($privhtml);
525
}
526

    
527
function build_cert_table() {
528
	global $a_user, $id;
529

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

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

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

    
560
	}
561

    
562
	$certhtml .=		'</tbody>';
563
	$certhtml .=	'</table>';
564
	$certhtml .= '</div>';
565

    
566
	$certhtml .= '<nav class="action-buttons">';
567
	$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>';
568
	$certhtml .= '</nav>';
569

    
570
	return($certhtml);
571
}
572

    
573
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
574
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
575

    
576
if ($act == "new" || $act == "edit" || $input_errors) {
577
	$pgtitle[] = gettext('Edit');
578
	$pglinks[] = "@self";
579
}
580

    
581
include("head.inc");
582

    
583
if ($delete_errors) {
584
	print_input_errors($delete_errors);
585
}
586

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

    
591
if ($savemsg) {
592
	print_info_box($savemsg, 'success');
593
}
594

    
595
$tab_array = array();
596
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
597
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
598
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
599
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
600
display_top_tabs($tab_array);
601

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

    
661
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
662
		<i class="fa fa-trash icon-embed-btn"></i>
663
		<?=gettext("Delete")?>
664
	</button>
665

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

    
677
?></div>
678

    
679
<?php
680
	include("foot.inc");
681
	exit;
682
}
683

    
684
$form = new Form;
685

    
686
if ($act == "new" || $act == "edit" || $input_errors):
687

    
688
	$form->addGlobal(new Form_Input(
689
		'act',
690
		null,
691
		'hidden',
692
		''
693
	));
694

    
695
	$form->addGlobal(new Form_Input(
696
		'userid',
697
		null,
698
		'hidden',
699
		isset($id) ? $id:''
700
	));
701

    
702
	$form->addGlobal(new Form_Input(
703
		'privid',
704
		null,
705
		'hidden',
706
		''
707
	));
708

    
709
	$form->addGlobal(new Form_Input(
710
		'certid',
711
		null,
712
		'hidden',
713
		''
714
	));
715

    
716
	$ro = "";
717
	if ($pconfig['utype'] == "system") {
718
		$ro = "readonly";
719
	}
720

    
721
	$section = new Form_Section('User Properties');
722

    
723
	$section->addInput(new Form_StaticText(
724
		'Defined by',
725
		strtoupper($pconfig['utype'])
726
	));
727

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

    
735
	$section->addInput(new Form_Checkbox(
736
		'disabled',
737
		'Disabled',
738
		'This user cannot login',
739
		$pconfig['disabled']
740
	));
741

    
742
	$section->addInput($input = new Form_Input(
743
		'usernamefld',
744
		'*Username',
745
		'text',
746
		$pconfig['usernamefld']
747
	));
748

    
749
	if ($ro) {
750
		$input->setReadonly();
751
	}
752

    
753
	$form->addGlobal(new Form_Input(
754
		'oldusername',
755
		null,
756
		'hidden',
757
		$pconfig['usernamefld']
758
	));
759

    
760
	if ($act == "edit") {
761
		$pwd_required = "";
762
	} else {
763
		$pwd_required = "*";
764
	}
765

    
766
	$group = new Form_Group($pwd_required . 'Password');
767
	$group->add(new Form_Input(
768
		'passwordfld1',
769
		'Password',
770
		'password'
771
	));
772
	$group->add(new Form_Input(
773
		'passwordfld2',
774
		'Confirm Password',
775
		'password'
776
	));
777

    
778
	$section->add($group);
779

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

    
787
	if ($ro) {
788
		$input->setDisabled();
789
	}
790

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

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

    
806
	gen_user_settings_fields($section, $pconfig);
807

    
808
	// ==== Group membership ==================================================
809
	$group = new Form_Group('Group membership');
810

    
811
	// Make a list of all the groups configured on the system, and a list of
812
	// those which this user is a member of
813
	$systemGroups = array();
814
	$usersGroups = array();
815

    
816
	$usergid = [$pconfig['usernamefld']];
817

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

    
828
	$group->add(new Form_Select(
829
		'sysgroups',
830
		null,
831
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
832
		$systemGroups,
833
		true
834
	))->setHelp('Not member of');
835

    
836
	$group->add(new Form_Select(
837
		'groups',
838
		null,
839
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
840
		$usersGroups,
841
		true
842
	))->setHelp('Member of');
843

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

    
846
	$group = new Form_Group('');
847

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

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

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

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

    
883
	$form->add($section);
884

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

    
890
		$section = new Form_Section('Effective Privileges');
891

    
892
		$section->addInput(new Form_StaticText(
893
			null,
894
			build_priv_table()
895
		));
896

    
897
		$form->add($section);
898

    
899
		// ==== Certificate table section =====================================
900
		$section = new Form_Section('User Certificates');
901

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

    
907
		$form->add($section);
908
	}
909

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

    
915
		if (!empty($nonPrvCas)) {
916
			$section->addInput(new Form_Input(
917
				'name',
918
				'Descriptive name',
919
				'text',
920
				$pconfig['name']
921
			));
922

    
923
			$section->addInput(new Form_Select(
924
				'caref',
925
				'Certificate authority',
926
				null,
927
				$nonPrvCas
928
			));
929

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

    
950
			$section->addInput(new Form_Input(
951
				'lifetime',
952
				'Lifetime',
953
				'number',
954
				$pconfig['lifetime']
955
			));
956
		}
957

    
958
		$form->add($section);
959
	}
960

    
961
endif;
962
// ==== Paste a key for the new user
963
$section = new Form_Section('Keys');
964

    
965
$section->addInput(new Form_Checkbox(
966
	'showkey',
967
	'Authorized keys',
968
	'Click to paste an authorized key',
969
	false
970
));
971

    
972
$section->addInput(new Form_Textarea(
973
	'authorizedkeys',
974
	'Authorized SSH Keys',
975
	$pconfig['authorizedkeys']
976
))->setHelp('Enter authorized SSH keys for this user');
977

    
978
$section->addInput(new Form_Input(
979
	'ipsecpsk',
980
	'IPsec Pre-Shared Key',
981
	'text',
982
	$pconfig['ipsecpsk']
983
));
984

    
985
$form->add($section);
986

    
987
print $form;
988

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

    
995
	function setcustomoptions() {
996
		var adv = $('#customsettings').prop('checked');
997

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

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

    
1021
	$('#webguicss').change(function() {
1022
		setThemeWarning();
1023
	});
1024

    
1025
	setThemeWarning();
1026

    
1027
	// On click . .
1028
	$('#customsettings').click(function () {
1029
		setcustomoptions();
1030
	});
1031

    
1032
	$("#movetodisabled").click(function() {
1033
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1034
	});
1035

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

    
1040
	$("#showcert").click(function() {
1041
		hideClass('cert-options', !this.checked);
1042
	});
1043

    
1044
	$("#showkey").click(function() {
1045
		hideInput('authorizedkeys', false);
1046
		hideCheckbox('showkey', true);
1047
	});
1048

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

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

    
1067
	$('#expires').datepicker();
1068

    
1069
	// ---------- On initial page load ------------------------------------------------------------
1070

    
1071
	hideClass('cert-options', true);
1072
	//hideInput('authorizedkeys', true);
1073
	hideCheckbox('showkey', true);
1074
	setcustomoptions();
1075

    
1076
	// On submit mark all the user's groups as "selected"
1077
	$('form').submit(function() {
1078
		AllServers($('[name="groups[]"] option'), true);
1079
	});
1080

    
1081
});
1082
//]]>
1083
</script>
1084
<?php
1085
include('foot.inc');
1086
?>
(209-209/228)