Project

General

Profile

Download (30.2 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

    
415
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
416
					(int)$_POST['lifetime'], $dn);
417

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

    
436
			$a_user[] = $userent;
437
		}
438

    
439
		/* 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. */
440
		local_user_set_groups($userent, $_POST['groups']);
441
		local_user_set($userent);
442
		/* 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. */
443
		local_user_set_groups($userent, $_POST['groups']);
444
		write_config();
445

    
446
		if (is_dir("/etc/inc/privhooks")) {
447
			run_plugins("/etc/inc/privhooks");
448
		}
449

    
450

    
451
		pfSenseHeader("system_usermanager.php");
452
	}
453
}
454

    
455
function build_priv_table() {
456
	global $a_user, $id;
457

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

    
470
	$i = 0;
471
	$user_has_root_priv = false;
472

    
473
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
474
		$group = false;
475
		if ($priv['group']) {
476
			$group = $priv['group'];
477
		}
478

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

    
493
		$privhtml .=			'</td>';
494
		$privhtml .=		'</tr>';
495

    
496
		if (!$group) {
497
			$i++;
498
		}
499
	}
500

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

    
510
	}
511

    
512
	$privhtml .=		'</tbody>';
513
	$privhtml .=	'</table>';
514
	$privhtml .= '</div>';
515

    
516
	$privhtml .= '<nav class="action-buttons">';
517
	$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>';
518
	$privhtml .= '</nav>';
519

    
520
	return($privhtml);
521
}
522

    
523
function build_cert_table() {
524
	global $a_user, $id;
525

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

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

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

    
556
	}
557

    
558
	$certhtml .=		'</tbody>';
559
	$certhtml .=	'</table>';
560
	$certhtml .= '</div>';
561

    
562
	$certhtml .= '<nav class="action-buttons">';
563
	$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>';
564
	$certhtml .= '</nav>';
565

    
566
	return($certhtml);
567
}
568

    
569
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
570
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
571

    
572
if ($act == "new" || $act == "edit" || $input_errors) {
573
	$pgtitle[] = gettext('Edit');
574
	$pglinks[] = "@self";
575
}
576

    
577
include("head.inc");
578

    
579
if ($delete_errors) {
580
	print_input_errors($delete_errors);
581
}
582

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

    
587
if ($savemsg) {
588
	print_info_box($savemsg, 'success');
589
}
590

    
591
$tab_array = array();
592
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
593
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
594
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
595
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
596
display_top_tabs($tab_array);
597

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

    
657
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
658
		<i class="fa fa-trash icon-embed-btn"></i>
659
		<?=gettext("Delete")?>
660
	</button>
661

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

    
673
?></div>
674

    
675
<?php
676
	include("foot.inc");
677
	exit;
678
}
679

    
680
$form = new Form;
681

    
682
if ($act == "new" || $act == "edit" || $input_errors):
683

    
684
	$form->addGlobal(new Form_Input(
685
		'act',
686
		null,
687
		'hidden',
688
		''
689
	));
690

    
691
	$form->addGlobal(new Form_Input(
692
		'userid',
693
		null,
694
		'hidden',
695
		isset($id) ? $id:''
696
	));
697

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

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

    
712
	$ro = "";
713
	if ($pconfig['utype'] == "system") {
714
		$ro = "readonly";
715
	}
716

    
717
	$section = new Form_Section('User Properties');
718

    
719
	$section->addInput(new Form_StaticText(
720
		'Defined by',
721
		strtoupper($pconfig['utype'])
722
	));
723

    
724
	$form->addGlobal(new Form_Input(
725
		'utype',
726
		null,
727
		'hidden',
728
		$pconfig['utype']
729
	));
730

    
731
	$section->addInput(new Form_Checkbox(
732
		'disabled',
733
		'Disabled',
734
		'This user cannot login',
735
		$pconfig['disabled']
736
	));
737

    
738
	$section->addInput($input = new Form_Input(
739
		'usernamefld',
740
		'*Username',
741
		'text',
742
		$pconfig['usernamefld']
743
	));
744

    
745
	if ($ro) {
746
		$input->setReadonly();
747
	}
748

    
749
	$form->addGlobal(new Form_Input(
750
		'oldusername',
751
		null,
752
		'hidden',
753
		$pconfig['usernamefld']
754
	));
755

    
756
	if ($act == "edit") {
757
		$pwd_required = "";
758
	} else {
759
		$pwd_required = "*";
760
	}
761

    
762
	$group = new Form_Group($pwd_required . 'Password');
763
	$group->add(new Form_Input(
764
		'passwordfld1',
765
		'Password',
766
		'password'
767
	));
768
	$group->add(new Form_Input(
769
		'passwordfld2',
770
		'Confirm Password',
771
		'password'
772
	));
773

    
774
	$section->add($group);
775

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

    
783
	if ($ro) {
784
		$input->setDisabled();
785
	}
786

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

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

    
802
	gen_user_settings_fields($section, $pconfig);
803

    
804
	// ==== Group membership ==================================================
805
	$group = new Form_Group('Group membership');
806

    
807
	// Make a list of all the groups configured on the system, and a list of
808
	// those which this user is a member of
809
	$systemGroups = array();
810
	$usersGroups = array();
811

    
812
	$usergid = [$pconfig['usernamefld']];
813

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

    
824
	$group->add(new Form_Select(
825
		'sysgroups',
826
		null,
827
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
828
		$systemGroups,
829
		true
830
	))->setHelp('Not member of');
831

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

    
840
	$section->add($group);
841

    
842
	$group = new Form_Group('');
843

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

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

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

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

    
879
	$form->add($section);
880

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

    
886
		$section = new Form_Section('Effective Privileges');
887

    
888
		$section->addInput(new Form_StaticText(
889
			null,
890
			build_priv_table()
891
		));
892

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

    
895
		// ==== Certificate table section =====================================
896
		$section = new Form_Section('User Certificates');
897

    
898
		$section->addInput(new Form_StaticText(
899
			null,
900
			build_cert_table()
901
		));
902

    
903
		$form->add($section);
904
	}
905

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

    
911
		if (!empty($nonPrvCas)) {
912
			$section->addInput(new Form_Input(
913
				'name',
914
				'Descriptive name',
915
				'text',
916
				$pconfig['name']
917
			));
918

    
919
			$section->addInput(new Form_Select(
920
				'caref',
921
				'Certificate authority',
922
				null,
923
				$nonPrvCas
924
			));
925

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

    
946
			$section->addInput(new Form_Input(
947
				'lifetime',
948
				'Lifetime',
949
				'number',
950
				$pconfig['lifetime']
951
			));
952
		}
953

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

    
957
endif;
958
// ==== Paste a key for the new user
959
$section = new Form_Section('Keys');
960

    
961
$section->addInput(new Form_Checkbox(
962
	'showkey',
963
	'Authorized keys',
964
	'Click to paste an authorized key',
965
	false
966
));
967

    
968
$section->addInput(new Form_Textarea(
969
	'authorizedkeys',
970
	'Authorized SSH Keys',
971
	$pconfig['authorizedkeys']
972
))->setHelp('Enter authorized SSH keys for this user');
973

    
974
$section->addInput(new Form_Input(
975
	'ipsecpsk',
976
	'IPsec Pre-Shared Key',
977
	'text',
978
	$pconfig['ipsecpsk']
979
));
980

    
981
$form->add($section);
982

    
983
print $form;
984

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

    
991
	function setcustomoptions() {
992
		var adv = $('#customsettings').prop('checked');
993

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

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

    
1017
	$('#webguicss').change(function() {
1018
		setThemeWarning();
1019
	});
1020

    
1021
	setThemeWarning();
1022

    
1023
	// On click . .
1024
	$('#customsettings').click(function () {
1025
		setcustomoptions();
1026
	});
1027

    
1028
	$("#movetodisabled").click(function() {
1029
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1030
	});
1031

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

    
1036
	$("#showcert").click(function() {
1037
		hideClass('cert-options', !this.checked);
1038
	});
1039

    
1040
	$("#showkey").click(function() {
1041
		hideInput('authorizedkeys', false);
1042
		hideCheckbox('showkey', true);
1043
	});
1044

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

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

    
1063
	$('#expires').datepicker();
1064

    
1065
	// ---------- On initial page load ------------------------------------------------------------
1066

    
1067
	hideClass('cert-options', true);
1068
	//hideInput('authorizedkeys', true);
1069
	hideCheckbox('showkey', true);
1070
	setcustomoptions();
1071

    
1072
	// On submit mark all the user's groups as "selected"
1073
	$('form').submit(function() {
1074
		AllServers($('[name="groups[]"] option'), true);
1075
	});
1076

    
1077
});
1078
//]]>
1079
</script>
1080
<?php
1081
include('foot.inc');
1082
?>
(205-205/224)