Project

General

Profile

Download (25.2 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
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
73

    
74
if (isset($_POST['userid']) && is_numericint($_POST['userid'])) {
75
	$id = $_POST['userid'];
76
}
77

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

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

    
86
$a_user = &$config['system']['user'];
87
$act = $_GET['act'];
88

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

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

    
108
if ($_GET['act'] == "deluser") {
109

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

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

    
132
if (isset($_POST['dellall'])) {
133

    
134
	$del_users = $_POST['delete_check'];
135

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

    
150
if ($_POST['act'] == "delcert") {
151

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

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

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

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

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

    
200
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
201

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

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

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

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

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

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

    
262
	if (!empty($_POST['name'])) {
263
		$ca = lookup_ca($_POST['caref']);
264
		if (!$ca) {
265
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
266
		}
267
	}
268

    
269
	/* if this is an AJAX caller then handle via JSON */
270
	if (isAjax() && is_array($input_errors)) {
271
		input_errors2Ajax($input_errors);
272
		exit;
273
	}
274

    
275
	if (!$input_errors) {
276

    
277
		conf_mount_rw();
278
		$userent = array();
279
		if (isset($id) && $a_user[$id]) {
280
			$userent = $a_user[$id];
281
		}
282

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

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

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

    
296
		/* only change description if sent */
297
		if (isset($_POST['descr'])) {
298
			$userent['descr'] = $_POST['descr'];
299
		}
300

    
301
		$userent['name'] = $_POST['usernamefld'];
302
		$userent['expires'] = $_POST['expires'];
303
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
304
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
305

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

    
312
		if (isset($id) && $a_user[$id]) {
313
			$a_user[$id] = $userent;
314
		} else {
315
			if (!empty($_POST['name'])) {
316
				$cert = array();
317
				$cert['refid'] = uniqid();
318
				$userent['cert'] = array();
319

    
320
				$cert['descr'] = $_POST['name'];
321

    
322
				$subject = cert_get_subject_array($ca['crt']);
323

    
324
				$dn = array(
325
					'countryName' => $subject[0]['v'],
326
					'stateOrProvinceName' => $subject[1]['v'],
327
					'localityName' => $subject[2]['v'],
328
					'organizationName' => $subject[3]['v'],
329
					'emailAddress' => $subject[4]['v'],
330
					'commonName' => $userent['name']);
331

    
332
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
333
					(int)$_POST['lifetime'], $dn);
334

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

    
353
			$a_user[] = $userent;
354
		}
355

    
356
		/* 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. */
357
		local_user_set_groups($userent, $_POST['groups']);
358
		local_user_set($userent);
359
		/* 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. */
360
		local_user_set_groups($userent, $_POST['groups']);
361
		write_config();
362

    
363
		if (is_dir("/etc/inc/privhooks")) {
364
			run_plugins("/etc/inc/privhooks");
365
		}
366

    
367
		conf_mount_ro();
368

    
369
		pfSenseHeader("system_usermanager.php");
370
	}
371
}
372

    
373
function build_priv_table() {
374
	global $a_user, $id;
375

    
376
	$privhtml = '<div class="table-responsive">';
377
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
378
	$privhtml .=		'<thead>';
379
	$privhtml .=			'<tr>';
380
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
381
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
382
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
383
	$privhtml .=			'</tr>';
384
	$privhtml .=		'</thead>';
385
	$privhtml .=		'<tbody>';
386

    
387
	$i = 0;
388

    
389
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
390
		$group = false;
391
		if ($priv['group']) {
392
			$group = $priv['group'];
393
		}
394

    
395
		$privhtml .=		'<tr>';
396
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
397
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
398
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']) . '</td>';
399
		$privhtml .=			'<td>';
400
		if (!$group) {
401
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a></td>';
402
		}
403

    
404
		$privhtml .=			'</td>';
405
		$privhtml .=		'</tr>';
406

    
407
		if (!$group) {
408
			$i++;
409
		}
410
	}
411

    
412
	$privhtml .=		'</tbody>';
413
	$privhtml .=	'</table>';
414
	$privhtml .= '</div>';
415

    
416
	$privhtml .= '<nav class="action-buttons">';
417
	$privhtml .=	'<a href="system_usermanager_addprivs.php?userid=' . $id . '" class="btn btn-success">' . gettext("Add") . '</a>';
418
	$privhtml .= '</nav>';
419

    
420
	return($privhtml);
421
}
422

    
423
function build_cert_table() {
424
	global $a_user, $id;
425

    
426
	$certhtml = '<div class="table-responsive">';
427
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
428
	$certhtml .=		'<thead>';
429
	$certhtml .=			'<tr>';
430
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
431
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
432
	$certhtml .=				'<th></th>';
433
	$certhtml .=			'</tr>';
434
	$certhtml .=		'</thead>';
435
	$certhtml .=		'<tbody>';
436

    
437
	$a_cert = $a_user[$id]['cert'];
438
	if (is_array($a_cert)) {
439
		$i = 0;
440
		foreach ($a_cert as $certref) {
441
			$cert = lookup_cert($certref);
442
			$ca = lookup_ca($cert['caref']);
443
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
444

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

    
456
	}
457

    
458
	$certhtml .=		'</tbody>';
459
	$certhtml .=	'</table>';
460
	$certhtml .= '</div>';
461

    
462
	$certhtml .= '<nav class="action-buttons">';
463
	$certhtml .=	'<a href="system_certmanager.php?act=new&amp;userid=' . $id . '" class="btn btn-success">' . gettext("Add") . '</a>';
464
	$certhtml .= '</nav>';
465

    
466
	return($certhtml);
467
}
468

    
469
include("head.inc");
470

    
471
if ($input_errors) {
472
	print_input_errors($input_errors);
473
}
474

    
475
if ($savemsg) {
476
	print_info_box($savemsg, 'success');
477
}
478

    
479
$tab_array = array();
480
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
481
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
482
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
483
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
484
display_top_tabs($tab_array);
485

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

    
545
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
546
		<i class="fa fa-trash icon-embed-btn"></i>
547
		<?=gettext("Delete")?>
548
	</button>
549
</nav>
550
</form>
551

    
552
<div class="infoblock">
553
	<?=print_info_box(gettext("Additional users can be added here. User permissions for accessing " .
554
	"the webConfigurator can be assigned directly or inherited from group memberships. " .
555
	"An icon that appears grey indicates that it is a system defined object. " .
556
	"Some system object properties can be modified but they cannot be deleted.") .
557
	'<br /><br />' .
558
	gettext("Accounts added here are also used for other parts of the system " .
559
	"such as OpenVPN, IPsec, and Captive Portal."), 'info', false)?>
560
</div>
561

    
562
<?php
563
	include("foot.inc");
564
	exit;
565
}
566

    
567
$form = new Form;
568

    
569
if ($act == "new" || $act == "edit" || $input_errors):
570

    
571
	$form->addGlobal(new Form_Input(
572
		'act',
573
		null,
574
		'hidden',
575
		''
576
	));
577

    
578
	$form->addGlobal(new Form_Input(
579
		'userid',
580
		null,
581
		'hidden',
582
		isset($id) ? $id:''
583
	));
584

    
585
	$form->addGlobal(new Form_Input(
586
		'privid',
587
		null,
588
		'hidden',
589
		''
590
	));
591

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

    
599
	$ro = "";
600
	if ($pconfig['utype'] == "system") {
601
		$ro = "readonly";
602
	}
603

    
604
	$section = new Form_Section('User Properties');
605

    
606
	$section->addInput(new Form_StaticText(
607
		'Defined by',
608
		strtoupper($pconfig['utype'])
609
	));
610

    
611
	$form->addGlobal(new Form_Input(
612
		'utype',
613
		null,
614
		'hidden',
615
		$pconfig['utype']
616
	));
617

    
618
	$section->addInput(new Form_Checkbox(
619
		'disabled',
620
		'Disabled',
621
		'This user cannot login',
622
		$pconfig['disabled']
623
	));
624

    
625
	$section->addInput($input = new Form_Input(
626
		'usernamefld',
627
		'Username',
628
		'text',
629
		$pconfig['usernamefld']
630
	));
631

    
632
	if ($ro) {
633
		$input->setReadonly();
634
	}
635

    
636
	$form->addGlobal(new Form_Input(
637
		'oldusername',
638
		null,
639
		'hidden',
640
		$pconfig['usernamefld']
641
	));
642

    
643
	$group = new Form_Group('Password');
644
	$group->add(new Form_Input(
645
		'passwordfld1',
646
		'Password',
647
		'password'
648
	));
649
	$group->add(new Form_Input(
650
		'passwordfld2',
651
		'Confirm Password',
652
		'password'
653
	));
654

    
655
	$section->add($group);
656

    
657
	$section->addInput($input = new Form_Input(
658
		'descr',
659
		'Full name',
660
		'text',
661
		htmlspecialchars($pconfig['descr'])
662
	))->setHelp('User\'s full name, for your own information only');
663

    
664
	if ($ro) {
665
		$input->setDisabled();
666
	}
667

    
668
	$section->addInput(new Form_Input(
669
		'expires',
670
		'Expiration date',
671
		'date',
672
		$pconfig['expires']
673
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
674
		'the expiration date');
675

    
676
	// ==== Group membership ==================================================
677
	$group = new Form_Group('Group membership');
678

    
679
	// Make a list of all the groups configured on the system, and a list of
680
	// those which this user is a member of
681
	$systemGroups = array();
682
	$usersGroups = array();
683

    
684
	$usergid = [$pconfig['usernamefld']];
685

    
686
	foreach ($config['system']['group'] as $Ggroup) {
687
		if ($Ggroup['name'] != "all") {
688
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
689
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
690
			} else {
691
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
692
			}
693
		}
694
	}
695

    
696
	$group->add(new Form_Select(
697
		'sysgroups',
698
		null,
699
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
700
		$systemGroups,
701
		true
702
	))->setHelp('Not member of');
703

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

    
712
	$section->add($group);
713

    
714
	$group = new Form_Group('');
715

    
716
	$group->add(new Form_Button(
717
		'movetoenabled',
718
		'Move to "Member of" list >'
719
	))->removeClass('btn-primary')->addClass('btn-default btn-sm');
720

    
721
	$group->add(new Form_Button(
722
		'movetodisabled',
723
		'< Move to "Not member of" list'
724
	))->removeClass('btn-primary')->addClass('btn-default btn-sm');
725

    
726
	$group->setHelp('Hold down CTRL (pc)/COMMAND (mac) key to select multiple items');
727
	$section->add($group);
728

    
729
	// ==== Button for adding user certificate ================================
730
	if ($act == 'new') {
731
		$section->addInput(new Form_Checkbox(
732
			'showcert',
733
			'Certificate',
734
			'Click to create a user certificate',
735
			false
736
		));
737
	}
738

    
739
	$form->add($section);
740

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

    
746
		$section = new Form_Section('Effective Privileges');
747

    
748
		$section->addInput(new Form_StaticText(
749
			null,
750
			build_priv_table()
751
		));
752

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

    
755
		// ==== Certificate table section =====================================
756
		$section = new Form_Section('User Certificates');
757

    
758
		$section->addInput(new Form_StaticText(
759
			null,
760
			build_cert_table()
761
		));
762

    
763
		$form->add($section);
764
	}
765

    
766
	// ==== Add user certificate for a new user
767
	if (is_array($config['ca']) && count($config['ca']) > 0) {
768
		$section = new Form_Section('Create Certificate for User');
769
		$section->addClass('cert-options');
770

    
771
		$nonPrvCas = array();
772
		foreach($config['ca'] as $ca) {
773
			if (!$ca['prv']) {
774
				continue;
775
			}
776

    
777
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
778
		}
779

    
780
		if (!empty($nonPrvCas)) {
781
			$section->addInput(new Form_Input(
782
				'name',
783
				'Descriptive name',
784
				'text',
785
				$pconfig['name']
786
			));
787

    
788
			$section->addInput(new Form_Select(
789
				'caref',
790
				'Certificate authority',
791
				null,
792
				$nonPrvCas
793
			));
794

    
795
			$section->addInput(new Form_Select(
796
				'keylen',
797
				'Key length',
798
				2048,
799
				array(
800
					512 => '512 bits',
801
					1024 => '1024 bits',
802
					2048 => '2049 bits',
803
					4096 => '4096 bits',
804
				)
805
			));
806

    
807
			$section->addInput(new Form_Input(
808
				'lifetime',
809
				'Lifetime',
810
				'number',
811
				$pconfig['lifetime']
812
			));
813
		}
814

    
815
		$form->add($section);
816
	}
817

    
818
endif;
819
// ==== Paste a key for the new user
820
$section = new Form_Section('Keys');
821

    
822
$section->addInput(new Form_Checkbox(
823
	'showkey',
824
	'Authorized keys',
825
	'Click to paste an authorized key',
826
	false
827
));
828

    
829
$section->addInput(new Form_Textarea(
830
	'authorizedkeys',
831
	'Authorized SSH Keys',
832
	$pconfig['authorizedkeys']
833
))->setHelp('Enter authorized SSH keys for this user');
834

    
835
$section->addInput(new Form_Input(
836
	'ipsecpsk',
837
	'IPsec Pre-Shared Key',
838
	'text',
839
	$pconfig['ipsecpsk']
840
));
841

    
842
$form->add($section);
843

    
844
print $form;
845
?>
846
<script type="text/javascript">
847
//<![CDATA[
848
events.push(function() {
849

    
850
	// Select every option in the specified multiselect
851
	function AllServers(id, selectAll) {
852
	   for (i = 0; i < id.length; i++)	   {
853
		   id.eq(i).prop('selected', selectAll);
854
	   }
855
	}
856

    
857
	// Move all selected options from one multiselect to another
858
	function moveOptions(From, To)	{
859
		var len = From.length;
860
		var option;
861

    
862
		if (len > 0) {
863
			for (i=0; i<len; i++) {
864
				if (From.eq(i).is(':selected')) {
865
					option = From.eq(i).val();
866
					value  = From.eq(i).text();
867
					To.append(new Option(value, option));
868
					From.eq(i).remove();
869
				}
870
			}
871
		}
872
	}
873

    
874
	// Make buttons plain buttons, not submit
875
	$("#movetodisabled").prop('type','button');
876
	$("#movetoenabled").prop('type','button');
877

    
878
	// On click . .
879
	$("#movetodisabled").click(function() {
880
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
881
	});
882

    
883
	$("#movetoenabled").click(function() {
884
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
885
	});
886

    
887
	$("#showcert").click(function() {
888
		hideClass('cert-options', !this.checked);
889
	});
890

    
891
	$("#showkey").click(function() {
892
		hideInput('authorizedkeys', false);
893
		hideCheckbox('showkey', true);
894
	});
895

    
896
	$('[id^=delcert]').click(function(event) {
897
		if (confirm(event.target.title)) {
898
			$('#certid').val(event.target.id.match(/\d+$/)[0]);
899
			$('#userid').val('<?=$id;?>');
900
			$('#act').val('delcert');
901
			$('form').submit();
902
		}
903
	});
904

    
905
	$('[id^=delprivid]').click(function(event) {
906
		if (confirm(event.target.title)) {
907
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
908
			$('#userid').val('<?=$id;?>');
909
			$('#act').val('delprivid');
910
			$('form').submit();
911
		}
912
	});
913

    
914

    
915
	// ---------- On initial page load ------------------------------------------------------------
916

    
917
	hideClass('cert-options', true);
918
	//hideInput('authorizedkeys', true);
919
	hideCheckbox('showkey', true);
920

    
921
	// On submit mark all the user's groups as "selected"
922
	$('form').submit(function() {
923
		AllServers($('[name="groups[]"] option'), true);
924
	});
925
});
926
//]]>
927
</script>
928
<?php
929
include('foot.inc');
930
?>
(208-208/229)