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
	if(is_array($_POST['groups'])) {
218
		foreach ($_POST['groups'] as $newgroup) {
219
			if (empty(getGroupEntry($newgroup))) {
220
				$input_errors[] = gettext("One or more invalid groups was submitted.");
221
			}
222
		}
223
	}
224

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

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

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

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

    
282
	if (!$input_errors) {
283

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

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

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

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

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

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

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

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

    
327
				$cert['descr'] = $_POST['name'];
328

    
329
				$subject = cert_get_subject_array($ca['crt']);
330

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

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

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

    
360
			$a_user[] = $userent;
361
		}
362

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

    
370
		if (is_dir("/etc/inc/privhooks")) {
371
			run_plugins("/etc/inc/privhooks");
372
		}
373

    
374
		conf_mount_ro();
375

    
376
		pfSenseHeader("system_usermanager.php");
377
	}
378
}
379

    
380
function build_priv_table() {
381
	global $a_user, $id;
382

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

    
395
	$i = 0;
396

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

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

    
412
		$privhtml .=			'</td>';
413
		$privhtml .=		'</tr>';
414

    
415
		if (!$group) {
416
			$i++;
417
		}
418
	}
419

    
420
	$privhtml .=		'</tbody>';
421
	$privhtml .=	'</table>';
422
	$privhtml .= '</div>';
423

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

    
428
	return($privhtml);
429
}
430

    
431
function build_cert_table() {
432
	global $a_user, $id;
433

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

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

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

    
464
	}
465

    
466
	$certhtml .=		'</tbody>';
467
	$certhtml .=	'</table>';
468
	$certhtml .= '</div>';
469

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

    
474
	return($certhtml);
475
}
476

    
477
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
478

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

    
484
if ($input_errors) {
485
	print_input_errors($input_errors);
486
}
487

    
488
if ($savemsg) {
489
	print_info_box($savemsg, 'success');
490
}
491

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

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

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

    
577
$form = new Form;
578

    
579
if ($act == "new" || $act == "edit" || $input_errors):
580

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

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

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

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

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

    
614
	$section = new Form_Section('User Properties');
615

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

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

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

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

    
642
	if ($ro) {
643
		$input->setReadonly();
644
	}
645

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

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

    
665
	$section->add($group);
666

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

    
674
	if ($ro) {
675
		$input->setDisabled();
676
	}
677

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

    
686
	// ==== Group membership ==================================================
687
	$group = new Form_Group('Group membership');
688

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

    
694
	$usergid = [$pconfig['usernamefld']];
695

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

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

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

    
722
	$section->add($group);
723

    
724
	$group = new Form_Group('');
725

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

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

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

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

    
753
	$form->add($section);
754

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

    
760
		$section = new Form_Section('Effective Privileges');
761

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

    
767
		$form->add($section);
768

    
769
		// ==== Certificate table section =====================================
770
		$section = new Form_Section('User Certificates');
771

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

    
777
		$form->add($section);
778
	}
779

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

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

    
791
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
792
		}
793

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

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

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

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

    
829
		$form->add($section);
830
	}
831

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

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

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

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

    
856
$form->add($section);
857

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

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

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

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

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

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

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

    
900

    
901
	// ---------- On initial page load ------------------------------------------------------------
902

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

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