Project

General

Profile

Download (25.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	system_usermanager.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2008 Shrew Soft Inc.
8
 *	Copyright (c)  2005 Paul Taylor <paultaylor@winn-dixie.com>
9
 *
10
 *	Some or all of this file is based on the m0n0wall project which is
11
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
12
 *
13
 *	Redistribution and use in source and binary forms, with or without modification,
14
 *	are permitted provided that the following conditions are met:
15
 *
16
 *	1. Redistributions of source code must retain the above copyright notice,
17
 *		this list of conditions and the following disclaimer.
18
 *
19
 *	2. Redistributions in binary form must reproduce the above copyright
20
 *		notice, this list of conditions and the following disclaimer in
21
 *		the documentation and/or other materials provided with the
22
 *		distribution.
23
 *
24
 *	3. All advertising materials mentioning features or use of this software
25
 *		must display the following acknowledgment:
26
 *		"This product includes software developed by the pfSense Project
27
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
28
 *
29
 *	4. The names "pfSense" and "pfSense Project" must not be used to
30
 *		 endorse or promote products derived from this software without
31
 *		 prior written permission. For written permission, please contact
32
 *		 coreteam@pfsense.org.
33
 *
34
 *	5. Products derived from this software may not be called "pfSense"
35
 *		nor may "pfSense" appear in their names without prior written
36
 *		permission of the Electric Sheep Fencing, LLC.
37
 *
38
 *	6. Redistributions of any form whatsoever must retain the following
39
 *		acknowledgment:
40
 *
41
 *	"This product includes software developed by the pfSense Project
42
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
56
 *
57
 *	====================================================================
58
 *
59
 */
60

    
61
##|+PRIV
62
##|*IDENT=page-system-usermanager
63
##|*NAME=System: User Manager
64
##|*DESCR=Allow access to the 'System: User Manager' page.
65
##|*MATCH=system_usermanager.php*
66
##|-PRIV
67

    
68
require("certs.inc");
69
require("guiconfig.inc");
70

    
71
// start admin user code
72
if (isset($_POST['userid']) && is_numericint($_POST['userid'])) {
73
	$id = $_POST['userid'];
74
}
75

    
76
if (isset($_GET['userid']) && is_numericint($_GET['userid'])) {
77
	$id = $_GET['userid'];
78
}
79

    
80
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
81
	$config['system']['user'] = array();
82
}
83

    
84
$a_user = &$config['system']['user'];
85
$act = $_GET['act'];
86

    
87
if (isset($_SERVER['HTTP_REFERER'])) {
88
	$referer = $_SERVER['HTTP_REFERER'];
89
} else {
90
	$referer = '/system_usermanager.php';
91
}
92

    
93
if (isset($id) && $a_user[$id]) {
94
	$pconfig['usernamefld'] = $a_user[$id]['name'];
95
	$pconfig['descr'] = $a_user[$id]['descr'];
96
	$pconfig['expires'] = $a_user[$id]['expires'];
97
	$pconfig['groups'] = local_user_get_groups($a_user[$id]);
98
	$pconfig['utype'] = $a_user[$id]['scope'];
99
	$pconfig['uid'] = $a_user[$id]['uid'];
100
	$pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
101
	$pconfig['priv'] = $a_user[$id]['priv'];
102
	$pconfig['ipsecpsk'] = $a_user[$id]['ipsecpsk'];
103
	$pconfig['disabled'] = isset($a_user[$id]['disabled']);
104
}
105

    
106
if ($_GET['act'] == "deluser") {
107

    
108
	if (!isset($_GET['username']) || !isset($a_user[$id]) || ($_GET['username'] != $a_user[$id]['name'])) {
109
		pfSenseHeader("system_usermanager.php");
110
		exit;
111
	}
112

    
113
	conf_mount_rw();
114
	local_user_del($a_user[$id]);
115
	conf_mount_ro();
116
	$userdeleted = $a_user[$id]['name'];
117
	unset($a_user[$id]);
118
	write_config();
119
	$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
120
} else if ($act == "new") {
121
	/*
122
	 * set this value cause the text field is read only
123
	 * and the user should not be able to mess with this
124
	 * setting.
125
	 */
126
	$pconfig['utype'] = "user";
127
	$pconfig['lifetime'] = 3650;
128
}
129

    
130
if (isset($_POST['dellall'])) {
131

    
132
	$del_users = $_POST['delete_check'];
133

    
134
	if (!empty($del_users)) {
135
		foreach ($del_users as $userid) {
136
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
137
				conf_mount_rw();
138
				local_user_del($a_user[$userid]);
139
 			    conf_mount_ro();
140
				unset($a_user[$userid]);
141
			}
142
		}
143
		$savemsg = gettext("Selected users removed successfully.");
144
		write_config($savemsg);
145
	}
146
}
147

    
148
if ($_POST['act'] == "delcert") {
149

    
150
	if (!$a_user[$id]) {
151
		pfSenseHeader("system_usermanager.php");
152
		exit;
153
	}
154

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

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

    
172
if ($_POST['save']) {
173
	unset($input_errors);
174
	$pconfig = $_POST;
175

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

    
198
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
199

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

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

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

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

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

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

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

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

    
274
	/* if this is an AJAX caller then handle via JSON */
275
	if (isAjax() && is_array($input_errors)) {
276
		input_errors2Ajax($input_errors);
277
		exit;
278
	}
279

    
280
	if (!$input_errors) {
281

    
282
		conf_mount_rw();
283
		$userent = array();
284
		if (isset($id) && $a_user[$id]) {
285
			$userent = $a_user[$id];
286
		}
287

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

    
290
		/* the user name was modified */
291
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
292
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
293
			local_user_del($userent);
294
		}
295

    
296
		/* the user password was modified */
297
		if ($_POST['passwordfld1']) {
298
			local_user_set_password($userent, $_POST['passwordfld1']);
299
		}
300

    
301
		/* only change description if sent */
302
		if (isset($_POST['descr'])) {
303
			$userent['descr'] = $_POST['descr'];
304
		}
305

    
306
		$userent['name'] = $_POST['usernamefld'];
307
		$userent['expires'] = $_POST['expires'];
308
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
309
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
310

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

    
317
		if (isset($id) && $a_user[$id]) {
318
			$a_user[$id] = $userent;
319
		} else {
320
			if (!empty($_POST['name'])) {
321
				$cert = array();
322
				$cert['refid'] = uniqid();
323
				$userent['cert'] = array();
324

    
325
				$cert['descr'] = $_POST['name'];
326

    
327
				$subject = cert_get_subject_array($ca['crt']);
328

    
329
				$dn = array(
330
					'countryName' => $subject[0]['v'],
331
					'stateOrProvinceName' => $subject[1]['v'],
332
					'localityName' => $subject[2]['v'],
333
					'organizationName' => $subject[3]['v'],
334
					'emailAddress' => $subject[4]['v'],
335
					'commonName' => $userent['name']);
336

    
337
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
338
					(int)$_POST['lifetime'], $dn);
339

    
340
				if (!is_array($config['cert'])) {
341
					$config['cert'] = array();
342
				}
343
				$config['cert'][] = $cert;
344
				$userent['cert'][] = $cert['refid'];
345
			}
346
			$userent['uid'] = $config['system']['nextuid']++;
347
			/* Add the user to All Users group. */
348
			foreach ($config['system']['group'] as $gidx => $group) {
349
				if ($group['name'] == "all") {
350
					if (!is_array($config['system']['group'][$gidx]['member'])) {
351
						$config['system']['group'][$gidx]['member'] = array();
352
					}
353
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
354
					break;
355
				}
356
			}
357

    
358
			$a_user[] = $userent;
359
		}
360

    
361
		/* 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. */
362
		local_user_set_groups($userent, $_POST['groups']);
363
		local_user_set($userent);
364
		/* 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. */
365
		local_user_set_groups($userent, $_POST['groups']);
366
		write_config();
367

    
368
		if (is_dir("/etc/inc/privhooks")) {
369
			run_plugins("/etc/inc/privhooks");
370
		}
371

    
372
		conf_mount_ro();
373

    
374
		pfSenseHeader("system_usermanager.php");
375
	}
376
}
377

    
378
function build_priv_table() {
379
	global $a_user, $id;
380

    
381
	$privhtml = '<div class="table-responsive">';
382
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
383
	$privhtml .=		'<thead>';
384
	$privhtml .=			'<tr>';
385
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
386
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
387
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
388
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
389
	$privhtml .=			'</tr>';
390
	$privhtml .=		'</thead>';
391
	$privhtml .=		'<tbody>';
392

    
393
	$i = 0;
394

    
395
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
396
		$group = false;
397
		if ($priv['group']) {
398
			$group = $priv['group'];
399
		}
400

    
401
		$privhtml .=		'<tr>';
402
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
403
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
404
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']) . '</td>';
405
		$privhtml .=			'<td>';
406
		if (!$group) {
407
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
408
		}
409

    
410
		$privhtml .=			'</td>';
411
		$privhtml .=		'</tr>';
412

    
413
		if (!$group) {
414
			$i++;
415
		}
416
	}
417

    
418
	$privhtml .=		'</tbody>';
419
	$privhtml .=	'</table>';
420
	$privhtml .= '</div>';
421

    
422
	$privhtml .= '<nav class="action-buttons">';
423
	$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>';
424
	$privhtml .= '</nav>';
425

    
426
	return($privhtml);
427
}
428

    
429
function build_cert_table() {
430
	global $a_user, $id;
431

    
432
	$certhtml = '<div class="table-responsive">';
433
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
434
	$certhtml .=		'<thead>';
435
	$certhtml .=			'<tr>';
436
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
437
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
438
	$certhtml .=				'<th></th>';
439
	$certhtml .=			'</tr>';
440
	$certhtml .=		'</thead>';
441
	$certhtml .=		'<tbody>';
442

    
443
	$a_cert = $a_user[$id]['cert'];
444
	if (is_array($a_cert)) {
445
		$i = 0;
446
		foreach ($a_cert as $certref) {
447
			$cert = lookup_cert($certref);
448
			$ca = lookup_ca($cert['caref']);
449
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
450

    
451
			$certhtml .=	'<tr>';
452
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
453
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
454
			$certhtml .=		'<td>';
455
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
456
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
457
			$certhtml .=		'</td>';
458
			$certhtml .=	'</tr>';
459
			$i++;
460
		}
461

    
462
	}
463

    
464
	$certhtml .=		'</tbody>';
465
	$certhtml .=	'</table>';
466
	$certhtml .= '</div>';
467

    
468
	$certhtml .= '<nav class="action-buttons">';
469
	$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>';
470
	$certhtml .= '</nav>';
471

    
472
	return($certhtml);
473
}
474

    
475
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
476

    
477
if ($act == "new" || $act == "edit" || $input_errors) {
478
	$pgtitle[] = gettext('Edit');
479
}
480
include("head.inc");
481

    
482
if ($input_errors) {
483
	print_input_errors($input_errors);
484
}
485

    
486
if ($savemsg) {
487
	print_info_box($savemsg, 'success');
488
}
489

    
490
$tab_array = array();
491
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
492
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
493
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
494
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
495
display_top_tabs($tab_array);
496

    
497
if (!($act == "new" || $act == "edit" || $input_errors)) {
498
?>
499
<form method="post">
500
<div class="panel panel-default">
501
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
502
	<div class="panel-body">
503
		<div class="table-responsive">
504
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
505
				<thead>
506
					<tr>
507
						<th>&nbsp;</th>
508
						<th><?=gettext("Username")?></th>
509
						<th><?=gettext("Full name")?></th>
510
						<th><?=gettext("Disabled")?></th>
511
						<th><?=gettext("Groups")?></th>
512
						<th><?=gettext("Actions")?></th>
513
					</tr>
514
				</thead>
515
				<tbody>
516
<?php
517
foreach ($a_user as $i => $userent):
518
	?>
519
					<tr>
520
						<td>
521
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=($userent['scope'] == "system" ? 'disabled' : '')?>/>
522
						</td>
523
						<td>
524
<?php
525
	if ($userent['scope'] != "user") {
526
		$usrimg = 'eye-open';
527
	} else {
528
		$usrimg = 'user';
529
	}
530
?>
531
							<i class="fa fa-<?=$usrimg?>"></i>
532
							<?=htmlspecialchars($userent['name'])?>
533
						</td>
534
						<td><?=htmlspecialchars($userent['descr'])?></td>
535
						<td><?php if (isset($userent['disabled'])) echo "*"?></td>
536
						<td><?=implode(",", local_user_get_groups($userent))?></td>
537
						<td>
538
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
539
<?php if ($userent['scope'] != "system"): ?>
540
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>"></a>
541
<?php endif; ?>
542
						</td>
543
					</tr>
544
<?php endforeach; ?>
545
				</tbody>
546
			</table>
547
		</div>
548
	</div>
549
</div>
550
<nav class="action-buttons">
551
	<a href="?act=new" class="btn btn-sm btn-success">
552
		<i class="fa fa-plus icon-embed-btn"></i>
553
		<?=gettext("Add")?>
554
	</a>
555

    
556
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
557
		<i class="fa fa-trash icon-embed-btn"></i>
558
		<?=gettext("Delete")?>
559
	</button>
560
</nav>
561
</form>
562
<div class="infoblock">
563
<?php
564
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
565
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
566
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
567
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
568
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
569
	);
570
?></div><?php
571
	include("foot.inc");
572
	exit;
573
}
574

    
575
$form = new Form;
576

    
577
if ($act == "new" || $act == "edit" || $input_errors):
578

    
579
	$form->addGlobal(new Form_Input(
580
		'act',
581
		null,
582
		'hidden',
583
		''
584
	));
585

    
586
	$form->addGlobal(new Form_Input(
587
		'userid',
588
		null,
589
		'hidden',
590
		isset($id) ? $id:''
591
	));
592

    
593
	$form->addGlobal(new Form_Input(
594
		'privid',
595
		null,
596
		'hidden',
597
		''
598
	));
599

    
600
	$form->addGlobal(new Form_Input(
601
		'certid',
602
		null,
603
		'hidden',
604
		''
605
	));
606

    
607
	$ro = "";
608
	if ($pconfig['utype'] == "system") {
609
		$ro = "readonly";
610
	}
611

    
612
	$section = new Form_Section('User Properties');
613

    
614
	$section->addInput(new Form_StaticText(
615
		'Defined by',
616
		strtoupper($pconfig['utype'])
617
	));
618

    
619
	$form->addGlobal(new Form_Input(
620
		'utype',
621
		null,
622
		'hidden',
623
		$pconfig['utype']
624
	));
625

    
626
	$section->addInput(new Form_Checkbox(
627
		'disabled',
628
		'Disabled',
629
		'This user cannot login',
630
		$pconfig['disabled']
631
	));
632

    
633
	$section->addInput($input = new Form_Input(
634
		'usernamefld',
635
		'Username',
636
		'text',
637
		$pconfig['usernamefld']
638
	));
639

    
640
	if ($ro) {
641
		$input->setReadonly();
642
	}
643

    
644
	$form->addGlobal(new Form_Input(
645
		'oldusername',
646
		null,
647
		'hidden',
648
		$pconfig['usernamefld']
649
	));
650

    
651
	$group = new Form_Group('Password');
652
	$group->add(new Form_Input(
653
		'passwordfld1',
654
		'Password',
655
		'password'
656
	));
657
	$group->add(new Form_Input(
658
		'passwordfld2',
659
		'Confirm Password',
660
		'password'
661
	));
662

    
663
	$section->add($group);
664

    
665
	$section->addInput($input = new Form_Input(
666
		'descr',
667
		'Full name',
668
		'text',
669
		htmlspecialchars($pconfig['descr'])
670
	))->setHelp('User\'s full name, for administrative information only');
671

    
672
	if ($ro) {
673
		$input->setDisabled();
674
	}
675

    
676
	$section->addInput(new Form_Input(
677
		'expires',
678
		'Expiration date',
679
		'date',
680
		$pconfig['expires']
681
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
682
		'the expiration date');
683

    
684
	// ==== Group membership ==================================================
685
	$group = new Form_Group('Group membership');
686

    
687
	// Make a list of all the groups configured on the system, and a list of
688
	// those which this user is a member of
689
	$systemGroups = array();
690
	$usersGroups = array();
691

    
692
	$usergid = [$pconfig['usernamefld']];
693

    
694
	foreach ($config['system']['group'] as $Ggroup) {
695
		if ($Ggroup['name'] != "all") {
696
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
697
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
698
			} else {
699
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
700
			}
701
		}
702
	}
703

    
704
	$group->add(new Form_Select(
705
		'sysgroups',
706
		null,
707
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
708
		$systemGroups,
709
		true
710
	))->setHelp('Not member of');
711

    
712
	$group->add(new Form_Select(
713
		'groups',
714
		null,
715
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
716
		$usersGroups,
717
		true
718
	))->setHelp('Member of');
719

    
720
	$section->add($group);
721

    
722
	$group = new Form_Group('');
723

    
724
	$group->add(new Form_Button(
725
		'movetoenabled',
726
		'Move to "Member of" list',
727
		null,
728
		'fa-angle-double-right'
729
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
730

    
731
	$group->add(new Form_Button(
732
		'movetodisabled',
733
		'Move to "Not member of" list',
734
		null,
735
		'fa-angle-double-left'
736
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
737

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

    
741
	// ==== Button for adding user certificate ================================
742
	if ($act == 'new') {
743
		$section->addInput(new Form_Checkbox(
744
			'showcert',
745
			'Certificate',
746
			'Click to create a user certificate',
747
			false
748
		));
749
	}
750

    
751
	$form->add($section);
752

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

    
758
		$section = new Form_Section('Effective Privileges');
759

    
760
		$section->addInput(new Form_StaticText(
761
			null,
762
			build_priv_table()
763
		));
764

    
765
		$form->add($section);
766

    
767
		// ==== Certificate table section =====================================
768
		$section = new Form_Section('User Certificates');
769

    
770
		$section->addInput(new Form_StaticText(
771
			null,
772
			build_cert_table()
773
		));
774

    
775
		$form->add($section);
776
	}
777

    
778
	// ==== Add user certificate for a new user
779
	if (is_array($config['ca']) && count($config['ca']) > 0) {
780
		$section = new Form_Section('Create Certificate for User');
781
		$section->addClass('cert-options');
782

    
783
		$nonPrvCas = array();
784
		foreach($config['ca'] as $ca) {
785
			if (!$ca['prv']) {
786
				continue;
787
			}
788

    
789
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
790
		}
791

    
792
		if (!empty($nonPrvCas)) {
793
			$section->addInput(new Form_Input(
794
				'name',
795
				'Descriptive name',
796
				'text',
797
				$pconfig['name']
798
			));
799

    
800
			$section->addInput(new Form_Select(
801
				'caref',
802
				'Certificate authority',
803
				null,
804
				$nonPrvCas
805
			));
806

    
807
			$section->addInput(new Form_Select(
808
				'keylen',
809
				'Key length',
810
				2048,
811
				array(
812
					512 => '512 bits',
813
					1024 => '1024 bits',
814
					2048 => '2048 bits',
815
					4096 => '4096 bits',
816
				)
817
			));
818

    
819
			$section->addInput(new Form_Input(
820
				'lifetime',
821
				'Lifetime',
822
				'number',
823
				$pconfig['lifetime']
824
			));
825
		}
826

    
827
		$form->add($section);
828
	}
829

    
830
endif;
831
// ==== Paste a key for the new user
832
$section = new Form_Section('Keys');
833

    
834
$section->addInput(new Form_Checkbox(
835
	'showkey',
836
	'Authorized keys',
837
	'Click to paste an authorized key',
838
	false
839
));
840

    
841
$section->addInput(new Form_Textarea(
842
	'authorizedkeys',
843
	'Authorized SSH Keys',
844
	$pconfig['authorizedkeys']
845
))->setHelp('Enter authorized SSH keys for this user');
846

    
847
$section->addInput(new Form_Input(
848
	'ipsecpsk',
849
	'IPsec Pre-Shared Key',
850
	'text',
851
	$pconfig['ipsecpsk']
852
));
853

    
854
$form->add($section);
855

    
856
print $form;
857
?>
858
<script type="text/javascript">
859
//<![CDATA[
860
events.push(function() {
861

    
862
	// On click . .
863
	$("#movetodisabled").click(function() {
864
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
865
	});
866

    
867
	$("#movetoenabled").click(function() {
868
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
869
	});
870

    
871
	$("#showcert").click(function() {
872
		hideClass('cert-options', !this.checked);
873
	});
874

    
875
	$("#showkey").click(function() {
876
		hideInput('authorizedkeys', false);
877
		hideCheckbox('showkey', true);
878
	});
879

    
880
	$('[id^=delcert]').click(function(event) {
881
		if (confirm(event.target.title)) {
882
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
883
			$('#userid').val('<?=$id;?>');
884
			$('#act').val('delcert');
885
			$('form').submit();
886
		}
887
	});
888

    
889
	$('[id^=delprivid]').click(function(event) {
890
		if (confirm(event.target.title)) {
891
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
892
			$('#userid').val('<?=$id;?>');
893
			$('#act').val('delprivid');
894
			$('form').submit();
895
		}
896
	});
897

    
898
	$('#expires').datepicker();
899

    
900
	// ---------- On initial page load ------------------------------------------------------------
901

    
902
	hideClass('cert-options', true);
903
	//hideInput('authorizedkeys', true);
904
	hideCheckbox('showkey', true);
905

    
906
	// On submit mark all the user's groups as "selected"
907
	$('form').submit(function() {
908
		AllServers($('[name="groups[]"] option'), true);
909
	});
910
});
911
//]]>
912
</script>
913
<?php
914
include('foot.inc');
915
?>
(207-207/226)