Project

General

Profile

Download (29.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * system_usermanager.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2008 Shrew Soft Inc.
8
 * Copyright (c) 2005 Paul Taylor <paultaylor@winn-dixie.com>
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-system-usermanager
30
##|*NAME=System: User Manager
31
##|*DESCR=Allow access to the 'System: User Manager' page.
32
##|*WARN=standard-warning-root
33
##|*MATCH=system_usermanager.php*
34
##|-PRIV
35

    
36
require_once("certs.inc");
37
require_once("guiconfig.inc");
38

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

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

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

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

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

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

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

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

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

    
110
if (isset($_POST['dellall'])) {
111

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

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

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

    
145
if ($_POST['act'] == "delcert") {
146

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

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

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

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

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

    
195
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
196

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

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

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

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

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

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

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

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

    
273
	if (!$input_errors) {
274

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
382
		if (isset($id) && $a_user[$id]) {
383
			$a_user[$id] = $userent;
384
		} else {
385
			if (!empty($_POST['name'])) {
386
				$cert = array();
387
				$cert['refid'] = uniqid();
388
				$userent['cert'] = array();
389

    
390
				$cert['descr'] = $_POST['name'];
391

    
392
				$subject = cert_get_subject_array($ca['crt']);
393

    
394
				$dn = array(
395
					'countryName' => $subject[0]['v'],
396
					'stateOrProvinceName' => $subject[1]['v'],
397
					'localityName' => $subject[2]['v'],
398
					'organizationName' => $subject[3]['v'],
399
					'emailAddress' => $subject[4]['v'],
400
					'commonName' => $userent['name']);
401

    
402
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
403
					(int)$_POST['lifetime'], $dn);
404

    
405
				if (!is_array($config['cert'])) {
406
					$config['cert'] = array();
407
				}
408
				$config['cert'][] = $cert;
409
				$userent['cert'][] = $cert['refid'];
410
			}
411
			$userent['uid'] = $config['system']['nextuid']++;
412
			/* Add the user to All Users group. */
413
			foreach ($config['system']['group'] as $gidx => $group) {
414
				if ($group['name'] == "all") {
415
					if (!is_array($config['system']['group'][$gidx]['member'])) {
416
						$config['system']['group'][$gidx]['member'] = array();
417
					}
418
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
419
					break;
420
				}
421
			}
422

    
423
			$a_user[] = $userent;
424
		}
425

    
426
		/* 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. */
427
		local_user_set_groups($userent, $_POST['groups']);
428
		local_user_set($userent);
429
		/* 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. */
430
		local_user_set_groups($userent, $_POST['groups']);
431
		write_config();
432

    
433
		if (is_dir("/etc/inc/privhooks")) {
434
			run_plugins("/etc/inc/privhooks");
435
		}
436

    
437

    
438
		pfSenseHeader("system_usermanager.php");
439
	}
440
}
441

    
442
function build_priv_table() {
443
	global $a_user, $id;
444

    
445
	$privhtml = '<div class="table-responsive">';
446
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
447
	$privhtml .=		'<thead>';
448
	$privhtml .=			'<tr>';
449
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
450
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
451
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
452
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
453
	$privhtml .=			'</tr>';
454
	$privhtml .=		'</thead>';
455
	$privhtml .=		'<tbody>';
456

    
457
	$i = 0;
458
	$user_has_root_priv = false;
459

    
460
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
461
		$group = false;
462
		if ($priv['group']) {
463
			$group = $priv['group'];
464
		}
465

    
466
		$privhtml .=		'<tr>';
467
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
468
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
469
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
470
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
471
			$privhtml .=			' ' . gettext('(admin privilege)');
472
			$user_has_root_priv = true;
473
		}
474
		$privhtml .=			'</td>';
475
		$privhtml .=			'<td>';
476
		if (!$group) {
477
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
478
		}
479

    
480
		$privhtml .=			'</td>';
481
		$privhtml .=		'</tr>';
482

    
483
		if (!$group) {
484
			$i++;
485
		}
486
	}
487

    
488
	if ($user_has_root_priv) {
489
		$privhtml .=		'<tr>';
490
		$privhtml .=			'<td colspan="3">';
491
		$privhtml .=				'<b>' . gettext('Security notice: This user effectively has administrator-level access') . '</b>';
492
		$privhtml .=			'</td>';
493
		$privhtml .=			'<td>';
494
		$privhtml .=			'</td>';
495
		$privhtml .=		'</tr>';
496

    
497
	}
498

    
499
	$privhtml .=		'</tbody>';
500
	$privhtml .=	'</table>';
501
	$privhtml .= '</div>';
502

    
503
	$privhtml .= '<nav class="action-buttons">';
504
	$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>';
505
	$privhtml .= '</nav>';
506

    
507
	return($privhtml);
508
}
509

    
510
function build_cert_table() {
511
	global $a_user, $id;
512

    
513
	$certhtml = '<div class="table-responsive">';
514
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
515
	$certhtml .=		'<thead>';
516
	$certhtml .=			'<tr>';
517
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
518
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
519
	$certhtml .=				'<th></th>';
520
	$certhtml .=			'</tr>';
521
	$certhtml .=		'</thead>';
522
	$certhtml .=		'<tbody>';
523

    
524
	$a_cert = $a_user[$id]['cert'];
525
	if (is_array($a_cert)) {
526
		$i = 0;
527
		foreach ($a_cert as $certref) {
528
			$cert = lookup_cert($certref);
529
			$ca = lookup_ca($cert['caref']);
530
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
531

    
532
			$certhtml .=	'<tr>';
533
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
534
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
535
			$certhtml .=		'<td>';
536
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
537
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
538
			$certhtml .=		'</td>';
539
			$certhtml .=	'</tr>';
540
			$i++;
541
		}
542

    
543
	}
544

    
545
	$certhtml .=		'</tbody>';
546
	$certhtml .=	'</table>';
547
	$certhtml .= '</div>';
548

    
549
	$certhtml .= '<nav class="action-buttons">';
550
	$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>';
551
	$certhtml .= '</nav>';
552

    
553
	return($certhtml);
554
}
555

    
556
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
557
$pglinks = array("", "system_usermanager.php", "system_usermanager.php");
558

    
559
if ($act == "new" || $act == "edit" || $input_errors) {
560
	$pgtitle[] = gettext('Edit');
561
	$pglinks[] = "@self";
562
}
563

    
564
include("head.inc");
565

    
566
if ($delete_errors) {
567
	print_input_errors($delete_errors);
568
}
569

    
570
if ($input_errors) {
571
	print_input_errors($input_errors);
572
}
573

    
574
if ($savemsg) {
575
	print_info_box($savemsg, 'success');
576
}
577

    
578
$tab_array = array();
579
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
580
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
581
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
582
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
583
display_top_tabs($tab_array);
584

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

    
644
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
645
		<i class="fa fa-trash icon-embed-btn"></i>
646
		<?=gettext("Delete")?>
647
	</button>
648

    
649
</nav>
650
</form>
651
<div class="infoblock">
652
<?php
653
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
654
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
655
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
656
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
657
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
658
	);
659

    
660
?></div>
661

    
662
<?php
663
	include("foot.inc");
664
	exit;
665
}
666

    
667
$form = new Form;
668

    
669
if ($act == "new" || $act == "edit" || $input_errors):
670

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

    
678
	$form->addGlobal(new Form_Input(
679
		'userid',
680
		null,
681
		'hidden',
682
		isset($id) ? $id:''
683
	));
684

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

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

    
699
	$ro = "";
700
	if ($pconfig['utype'] == "system") {
701
		$ro = "readonly";
702
	}
703

    
704
	$section = new Form_Section('User Properties');
705

    
706
	$section->addInput(new Form_StaticText(
707
		'Defined by',
708
		strtoupper($pconfig['utype'])
709
	));
710

    
711
	$form->addGlobal(new Form_Input(
712
		'utype',
713
		null,
714
		'hidden',
715
		$pconfig['utype']
716
	));
717

    
718
	$section->addInput(new Form_Checkbox(
719
		'disabled',
720
		'Disabled',
721
		'This user cannot login',
722
		$pconfig['disabled']
723
	));
724

    
725
	$section->addInput($input = new Form_Input(
726
		'usernamefld',
727
		'*Username',
728
		'text',
729
		$pconfig['usernamefld']
730
	));
731

    
732
	if ($ro) {
733
		$input->setReadonly();
734
	}
735

    
736
	$form->addGlobal(new Form_Input(
737
		'oldusername',
738
		null,
739
		'hidden',
740
		$pconfig['usernamefld']
741
	));
742

    
743
	if ($act == "edit") {
744
		$pwd_required = "";
745
	} else {
746
		$pwd_required = "*";
747
	}
748

    
749
	$group = new Form_Group($pwd_required . 'Password');
750
	$group->add(new Form_Input(
751
		'passwordfld1',
752
		'Password',
753
		'password'
754
	));
755
	$group->add(new Form_Input(
756
		'passwordfld2',
757
		'Confirm Password',
758
		'password'
759
	));
760

    
761
	$section->add($group);
762

    
763
	$section->addInput($input = new Form_Input(
764
		'descr',
765
		'Full name',
766
		'text',
767
		htmlspecialchars($pconfig['descr'])
768
	))->setHelp('User\'s full name, for administrative information only');
769

    
770
	if ($ro) {
771
		$input->setDisabled();
772
	}
773

    
774
	$section->addInput(new Form_Input(
775
		'expires',
776
		'Expiration date',
777
		'text',
778
		$pconfig['expires']
779
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
780
		'the expiration date as MM/DD/YYYY');
781

    
782
	$section->addInput(new Form_Checkbox(
783
		'customsettings',
784
		'Custom Settings',
785
		'Use individual customized GUI options and dashboard layout for this user.',
786
		$pconfig['customsettings']
787
	));
788

    
789
	gen_user_settings_fields($section, $pconfig);
790

    
791
	// ==== Group membership ==================================================
792
	$group = new Form_Group('Group membership');
793

    
794
	// Make a list of all the groups configured on the system, and a list of
795
	// those which this user is a member of
796
	$systemGroups = array();
797
	$usersGroups = array();
798

    
799
	$usergid = [$pconfig['usernamefld']];
800

    
801
	foreach ($config['system']['group'] as $Ggroup) {
802
		if ($Ggroup['name'] != "all") {
803
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
804
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
805
			} else {
806
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
807
			}
808
		}
809
	}
810

    
811
	$group->add(new Form_Select(
812
		'sysgroups',
813
		null,
814
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
815
		$systemGroups,
816
		true
817
	))->setHelp('Not member of');
818

    
819
	$group->add(new Form_Select(
820
		'groups',
821
		null,
822
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
823
		$usersGroups,
824
		true
825
	))->setHelp('Member of');
826

    
827
	$section->add($group);
828

    
829
	$group = new Form_Group('');
830

    
831
	$group->add(new Form_Button(
832
		'movetoenabled',
833
		'Move to "Member of" list',
834
		null,
835
		'fa-angle-double-right'
836
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
837

    
838
	$group->add(new Form_Button(
839
		'movetodisabled',
840
		'Move to "Not member of" list',
841
		null,
842
		'fa-angle-double-left'
843
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
844

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

    
848
	// ==== Button for adding user certificate ================================
849
	if ($act == 'new') {
850
		$section->addInput(new Form_Checkbox(
851
			'showcert',
852
			'Certificate',
853
			'Click to create a user certificate',
854
			false
855
		));
856
	}
857

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

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

    
865
		$section = new Form_Section('Effective Privileges');
866

    
867
		$section->addInput(new Form_StaticText(
868
			null,
869
			build_priv_table()
870
		));
871

    
872
		$form->add($section);
873

    
874
		// ==== Certificate table section =====================================
875
		$section = new Form_Section('User Certificates');
876

    
877
		$section->addInput(new Form_StaticText(
878
			null,
879
			build_cert_table()
880
		));
881

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

    
885
	// ==== Add user certificate for a new user
886
	if (is_array($config['ca']) && count($config['ca']) > 0) {
887
		$section = new Form_Section('Create Certificate for User');
888
		$section->addClass('cert-options');
889

    
890
		$nonPrvCas = array();
891
		foreach ($config['ca'] as $ca) {
892
			if (!$ca['prv']) {
893
				continue;
894
			}
895

    
896
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
897
		}
898

    
899
		if (!empty($nonPrvCas)) {
900
			$section->addInput(new Form_Input(
901
				'name',
902
				'Descriptive name',
903
				'text',
904
				$pconfig['name']
905
			));
906

    
907
			$section->addInput(new Form_Select(
908
				'caref',
909
				'Certificate authority',
910
				null,
911
				$nonPrvCas
912
			));
913

    
914
			$section->addInput(new Form_Select(
915
				'keylen',
916
				'Key length',
917
				2048,
918
				array(
919
					512 => '512 bits',
920
					1024 => '1024 bits',
921
					2048 => '2048 bits',
922
					3072 => '3072 bits',
923
					4096 => '4096 bits',
924
					7680 => '7680 bits',
925
					8192 => '8192 bits',
926
					15360 => '15360 bits',
927
					16384 => '16384 bits'
928
				)
929
			))->setHelp('The larger the key, the more security it offers, but larger keys take considerably more time to generate, ' .
930
				'and take slightly longer to validate leading to a slight slowdown in setting up new sessions (not always noticeable). ' .
931
				'As of 2016, 2048 bit is the minimum and most common selection and 4096 is the maximum in common use. ' .
932
				'For more information see %1$s.', '<a href="https://keylength.com">keylength.com</a>');
933

    
934
			$section->addInput(new Form_Input(
935
				'lifetime',
936
				'Lifetime',
937
				'number',
938
				$pconfig['lifetime']
939
			));
940
		}
941

    
942
		$form->add($section);
943
	}
944

    
945
endif;
946
// ==== Paste a key for the new user
947
$section = new Form_Section('Keys');
948

    
949
$section->addInput(new Form_Checkbox(
950
	'showkey',
951
	'Authorized keys',
952
	'Click to paste an authorized key',
953
	false
954
));
955

    
956
$section->addInput(new Form_Textarea(
957
	'authorizedkeys',
958
	'Authorized SSH Keys',
959
	$pconfig['authorizedkeys']
960
))->setHelp('Enter authorized SSH keys for this user');
961

    
962
$section->addInput(new Form_Input(
963
	'ipsecpsk',
964
	'IPsec Pre-Shared Key',
965
	'text',
966
	$pconfig['ipsecpsk']
967
));
968

    
969
$form->add($section);
970

    
971
print $form;
972

    
973
$csswarning = sprintf(gettext("%sUser-created themes are unsupported, use at your own risk."), "<br />");
974
?>
975
<script type="text/javascript">
976
//<![CDATA[
977
events.push(function() {
978

    
979
	function setcustomoptions() {
980
		var adv = $('#customsettings').prop('checked');
981

    
982
		hideInput('webguicss', !adv);
983
		hideInput('webguifixedmenu', !adv);
984
		hideInput('webguihostnamemenu', !adv);
985
		hideInput('dashboardcolumns', !adv);
986
		hideCheckbox('interfacessort', !adv);
987
		hideCheckbox('dashboardavailablewidgetspanel', !adv);
988
		hideCheckbox('systemlogsfilterpanel', !adv);
989
		hideCheckbox('systemlogsmanagelogpanel', !adv);
990
		hideCheckbox('statusmonitoringsettingspanel', !adv);
991
		hideCheckbox('webguileftcolumnhyper', !adv);
992
		hideCheckbox('disablealiaspopupdetail', !adv);
993
		hideCheckbox('pagenamefirst', !adv);
994
	}
995

    
996
	// Handle displaying a warning message if a user-created theme is selected.
997
	function setThemeWarning() {
998
		if ($('#webguicss').val().startsWith("pfSense")) {
999
			$('#csstxt').html("").addClass("text-default");
1000
		} else {
1001
			$('#csstxt').html("<?=$csswarning?>").addClass("text-danger");
1002
		}
1003
	}
1004

    
1005
	$('#webguicss').change(function() {
1006
		setThemeWarning();
1007
	});
1008

    
1009
	setThemeWarning();
1010

    
1011
	// On click . .
1012
	$('#customsettings').click(function () {
1013
		setcustomoptions();
1014
	});
1015

    
1016
	$("#movetodisabled").click(function() {
1017
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
1018
	});
1019

    
1020
	$("#movetoenabled").click(function() {
1021
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
1022
	});
1023

    
1024
	$("#showcert").click(function() {
1025
		hideClass('cert-options', !this.checked);
1026
	});
1027

    
1028
	$("#showkey").click(function() {
1029
		hideInput('authorizedkeys', false);
1030
		hideCheckbox('showkey', true);
1031
	});
1032

    
1033
	$('[id^=delcert]').click(function(event) {
1034
		if (confirm(event.target.title)) {
1035
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
1036
			$('#userid').val('<?=$id;?>');
1037
			$('#act').val('delcert');
1038
			$('form').submit();
1039
		}
1040
	});
1041

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

    
1051
	$('#expires').datepicker();
1052

    
1053
	// ---------- On initial page load ------------------------------------------------------------
1054

    
1055
	hideClass('cert-options', true);
1056
	//hideInput('authorizedkeys', true);
1057
	hideCheckbox('showkey', true);
1058
	setcustomoptions();
1059

    
1060
	// On submit mark all the user's groups as "selected"
1061
	$('form').submit(function() {
1062
		AllServers($('[name="groups[]"] option'), true);
1063
	});
1064

    
1065
});
1066
//]]>
1067
</script>
1068
<?php
1069
include('foot.inc');
1070
?>
(204-204/223)