Project

General

Profile

Download (26.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
	if ($_GET['username'] == $_SESSION['Username']) {
114
		$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $_GET['username']);
115
	} else {
116
		conf_mount_rw();
117
		local_user_del($a_user[$id]);
118
		conf_mount_ro();
119
		$userdeleted = $a_user[$id]['name'];
120
		unset($a_user[$id]);
121
		write_config();
122
		$savemsg = sprintf(gettext("User %s successfully deleted."), $userdeleted);
123
	}
124
} else if ($act == "new") {
125
	/*
126
	 * set this value cause the text field is read only
127
	 * and the user should not be able to mess with this
128
	 * setting.
129
	 */
130
	$pconfig['utype'] = "user";
131
	$pconfig['lifetime'] = 3650;
132
}
133

    
134
if (isset($_POST['dellall'])) {
135

    
136
	$del_users = $_POST['delete_check'];
137
	$deleted_users = "";
138
	$deleted_count = 0;
139
	$comma = "";
140

    
141
	if (!empty($del_users)) {
142
		foreach ($del_users as $userid) {
143
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
144
				if ($a_user[$userid]['name'] == $_SESSION['Username']) {
145
					$delete_errors[] = sprintf(gettext("Cannot delete user %s because you are currently logged in as that user."), $a_user[$userid]['name']);
146
				} else {
147
					conf_mount_rw();
148
					$deleted_users = $deleted_users . $comma . $a_user[$userid]['name'];
149
					$comma = ", ";
150
					$deleted_count++;
151
					local_user_del($a_user[$userid]);
152
					conf_mount_ro();
153
					unset($a_user[$userid]);
154
				}
155
			} else {
156
				$delete_errors[] = sprintf(gettext("Cannot delete user %s because it is a system user."), $a_user[$userid]['name']);
157
			}
158
		}
159

    
160
		if ($deleted_count > 0) {
161
			if ($deleted_count == 1) {
162
				$savemsg = sprintf(gettext("User %s successfully deleted."), $deleted_users);
163
			} else {
164
				$savemsg = sprintf(gettext("Users %s successfully deleted."), $deleted_users);
165
			}
166
			write_config($savemsg);
167
		}
168
	}
169
}
170

    
171
if ($_POST['act'] == "delcert") {
172

    
173
	if (!$a_user[$id]) {
174
		pfSenseHeader("system_usermanager.php");
175
		exit;
176
	}
177

    
178
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
179
	$certdeleted = $certdeleted['descr'];
180
	unset($a_user[$id]['cert'][$_POST['certid']]);
181
	write_config();
182
	$_POST['act'] = "edit";
183
	$savemsg = sprintf(gettext("Certificate %s association removed."), $certdeleted);
184
}
185

    
186
if ($_POST['act'] == "delprivid") {
187
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
188
	unset($a_user[$id]['priv'][$_POST['privid']]);
189
	local_user_set($a_user[$id]);
190
	write_config();
191
	$_POST['act'] = "edit";
192
	$savemsg = sprintf(gettext("Privilege %s removed."), $privdeleted);
193
}
194

    
195
if ($_POST['save']) {
196
	unset($input_errors);
197
	$pconfig = $_POST;
198

    
199
	/* input validation */
200
	if (isset($id) && ($a_user[$id])) {
201
		$reqdfields = explode(" ", "usernamefld");
202
		$reqdfieldsn = array(gettext("Username"));
203
	} else {
204
		if (empty($_POST['name'])) {
205
			$reqdfields = explode(" ", "usernamefld passwordfld1");
206
			$reqdfieldsn = array(
207
				gettext("Username"),
208
				gettext("Password"));
209
		} else {
210
			$reqdfields = explode(" ", "usernamefld passwordfld1 name caref keylen lifetime");
211
			$reqdfieldsn = array(
212
				gettext("Username"),
213
				gettext("Password"),
214
				gettext("Descriptive name"),
215
				gettext("Certificate authority"),
216
				gettext("Key length"),
217
				gettext("Lifetime"));
218
		}
219
	}
220

    
221
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
222

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

    
227
	if (strlen($_POST['usernamefld']) > 16) {
228
		$input_errors[] = gettext("The username is longer than 16 characters.");
229
	}
230

    
231
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2'])) {
232
		$input_errors[] = gettext("The passwords do not match.");
233
	}
234

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

    
239
	/* Check the POSTed groups to ensure they are valid and exist */
240
	foreach ($_POST['groups'] as $newgroup) {
241
		if (empty(getGroupEntry($newgroup))) {
242
			$input_errors[] = gettext("One or more invalid groups was submitted.");
243
		}
244
	}
245

    
246
	if (isset($id) && $a_user[$id]) {
247
		$oldusername = $a_user[$id]['name'];
248
	} else {
249
		$oldusername = "";
250
	}
251
	/* make sure this user name is unique */
252
	if (!$input_errors) {
253
		foreach ($a_user as $userent) {
254
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
255
				$input_errors[] = gettext("Another entry with the same username already exists.");
256
				break;
257
			}
258
		}
259
	}
260
	/* also make sure it is not reserved */
261
	if (!$input_errors) {
262
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
263
		foreach ($system_users as $s_user) {
264
			$ent = explode(":", $s_user);
265
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
266
				$input_errors[] = gettext("That username is reserved by the system.");
267
				break;
268
			}
269
		}
270
	}
271

    
272
	/*
273
	 * Check for a valid expiration date if one is set at all (valid means,
274
	 * DateTime puts out a time stamp so any DateTime compatible time
275
	 * format may be used. to keep it simple for the enduser, we only
276
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
277
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
278
	 * Otherwise such an entry would lead to an invalid expiration data.
279
	 */
280
	if ($_POST['expires']) {
281
		try {
282
			$expdate = new DateTime($_POST['expires']);
283
			//convert from any DateTime compatible date to MM/DD/YYYY
284
			$_POST['expires'] = $expdate->format("m/d/Y");
285
		} catch (Exception $ex) {
286
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
287
		}
288
	}
289

    
290
	if (!empty($_POST['name'])) {
291
		$ca = lookup_ca($_POST['caref']);
292
		if (!$ca) {
293
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
294
		}
295
	}
296

    
297
	/* if this is an AJAX caller then handle via JSON */
298
	if (isAjax() && is_array($input_errors)) {
299
		input_errors2Ajax($input_errors);
300
		exit;
301
	}
302

    
303
	if (!$input_errors) {
304

    
305
		conf_mount_rw();
306
		$userent = array();
307
		if (isset($id) && $a_user[$id]) {
308
			$userent = $a_user[$id];
309
		}
310

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

    
313
		/* the user name was modified */
314
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
315
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
316
			local_user_del($userent);
317
		}
318

    
319
		/* the user password was modified */
320
		if ($_POST['passwordfld1']) {
321
			local_user_set_password($userent, $_POST['passwordfld1']);
322
		}
323

    
324
		/* only change description if sent */
325
		if (isset($_POST['descr'])) {
326
			$userent['descr'] = $_POST['descr'];
327
		}
328

    
329
		$userent['name'] = $_POST['usernamefld'];
330
		$userent['expires'] = $_POST['expires'];
331
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
332
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
333

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

    
340
		if (isset($id) && $a_user[$id]) {
341
			$a_user[$id] = $userent;
342
		} else {
343
			if (!empty($_POST['name'])) {
344
				$cert = array();
345
				$cert['refid'] = uniqid();
346
				$userent['cert'] = array();
347

    
348
				$cert['descr'] = $_POST['name'];
349

    
350
				$subject = cert_get_subject_array($ca['crt']);
351

    
352
				$dn = array(
353
					'countryName' => $subject[0]['v'],
354
					'stateOrProvinceName' => $subject[1]['v'],
355
					'localityName' => $subject[2]['v'],
356
					'organizationName' => $subject[3]['v'],
357
					'emailAddress' => $subject[4]['v'],
358
					'commonName' => $userent['name']);
359

    
360
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
361
					(int)$_POST['lifetime'], $dn);
362

    
363
				if (!is_array($config['cert'])) {
364
					$config['cert'] = array();
365
				}
366
				$config['cert'][] = $cert;
367
				$userent['cert'][] = $cert['refid'];
368
			}
369
			$userent['uid'] = $config['system']['nextuid']++;
370
			/* Add the user to All Users group. */
371
			foreach ($config['system']['group'] as $gidx => $group) {
372
				if ($group['name'] == "all") {
373
					if (!is_array($config['system']['group'][$gidx]['member'])) {
374
						$config['system']['group'][$gidx]['member'] = array();
375
					}
376
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
377
					break;
378
				}
379
			}
380

    
381
			$a_user[] = $userent;
382
		}
383

    
384
		/* 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. */
385
		local_user_set_groups($userent, $_POST['groups']);
386
		local_user_set($userent);
387
		/* 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. */
388
		local_user_set_groups($userent, $_POST['groups']);
389
		write_config();
390

    
391
		if (is_dir("/etc/inc/privhooks")) {
392
			run_plugins("/etc/inc/privhooks");
393
		}
394

    
395
		conf_mount_ro();
396

    
397
		pfSenseHeader("system_usermanager.php");
398
	}
399
}
400

    
401
function build_priv_table() {
402
	global $a_user, $id;
403

    
404
	$privhtml = '<div class="table-responsive">';
405
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
406
	$privhtml .=		'<thead>';
407
	$privhtml .=			'<tr>';
408
	$privhtml .=				'<th>' . gettext('Inherited from') . '</th>';
409
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
410
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
411
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
412
	$privhtml .=			'</tr>';
413
	$privhtml .=		'</thead>';
414
	$privhtml .=		'<tbody>';
415

    
416
	$i = 0;
417

    
418
	foreach (get_user_privdesc($a_user[$id]) as $priv) {
419
		$group = false;
420
		if ($priv['group']) {
421
			$group = $priv['group'];
422
		}
423

    
424
		$privhtml .=		'<tr>';
425
		$privhtml .=			'<td>' . htmlspecialchars($priv['group']) . '</td>';
426
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
427
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']) . '</td>';
428
		$privhtml .=			'<td>';
429
		if (!$group) {
430
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
431
		}
432

    
433
		$privhtml .=			'</td>';
434
		$privhtml .=		'</tr>';
435

    
436
		if (!$group) {
437
			$i++;
438
		}
439
	}
440

    
441
	$privhtml .=		'</tbody>';
442
	$privhtml .=	'</table>';
443
	$privhtml .= '</div>';
444

    
445
	$privhtml .= '<nav class="action-buttons">';
446
	$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>';
447
	$privhtml .= '</nav>';
448

    
449
	return($privhtml);
450
}
451

    
452
function build_cert_table() {
453
	global $a_user, $id;
454

    
455
	$certhtml = '<div class="table-responsive">';
456
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
457
	$certhtml .=		'<thead>';
458
	$certhtml .=			'<tr>';
459
	$certhtml .=				'<th>' . gettext('Name') . '</th>';
460
	$certhtml .=				'<th>' . gettext('CA') . '</th>';
461
	$certhtml .=				'<th></th>';
462
	$certhtml .=			'</tr>';
463
	$certhtml .=		'</thead>';
464
	$certhtml .=		'<tbody>';
465

    
466
	$a_cert = $a_user[$id]['cert'];
467
	if (is_array($a_cert)) {
468
		$i = 0;
469
		foreach ($a_cert as $certref) {
470
			$cert = lookup_cert($certref);
471
			$ca = lookup_ca($cert['caref']);
472
			$revokedstr =	is_cert_revoked($cert) ? '<b> Revoked</b>':'';
473

    
474
			$certhtml .=	'<tr>';
475
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
476
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
477
			$certhtml .=		'<td>';
478
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
479
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
480
			$certhtml .=		'</td>';
481
			$certhtml .=	'</tr>';
482
			$i++;
483
		}
484

    
485
	}
486

    
487
	$certhtml .=		'</tbody>';
488
	$certhtml .=	'</table>';
489
	$certhtml .= '</div>';
490

    
491
	$certhtml .= '<nav class="action-buttons">';
492
	$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>';
493
	$certhtml .= '</nav>';
494

    
495
	return($certhtml);
496
}
497

    
498
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"));
499

    
500
if ($act == "new" || $act == "edit" || $input_errors) {
501
	$pgtitle[] = gettext('Edit');
502
}
503
include("head.inc");
504

    
505
if ($delete_errors) {
506
	print_input_errors($delete_errors);
507
}
508

    
509
if ($input_errors) {
510
	print_input_errors($input_errors);
511
}
512

    
513
if ($savemsg) {
514
	print_info_box($savemsg, 'success');
515
}
516

    
517
$tab_array = array();
518
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
519
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
520
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
521
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
522
display_top_tabs($tab_array);
523

    
524
if (!($act == "new" || $act == "edit" || $input_errors)) {
525
?>
526
<form method="post">
527
<div class="panel panel-default">
528
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Users')?></h2></div>
529
	<div class="panel-body">
530
		<div class="table-responsive">
531
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
532
				<thead>
533
					<tr>
534
						<th>&nbsp;</th>
535
						<th><?=gettext("Username")?></th>
536
						<th><?=gettext("Full name")?></th>
537
						<th><?=gettext("Disabled")?></th>
538
						<th><?=gettext("Groups")?></th>
539
						<th><?=gettext("Actions")?></th>
540
					</tr>
541
				</thead>
542
				<tbody>
543
<?php
544
foreach ($a_user as $i => $userent):
545
	?>
546
					<tr>
547
						<td>
548
							<input type="checkbox" id="frc<?=$i?>" name="delete_check[]" value="<?=$i?>" <?=((($userent['scope'] == "system") || ($userent['name'] == $_SESSION['Username'])) ? 'disabled' : '')?>/>
549
						</td>
550
						<td>
551
<?php
552
	if ($userent['scope'] != "user") {
553
		$usrimg = 'eye-open';
554
	} else {
555
		$usrimg = 'user';
556
	}
557
?>
558
							<i class="fa fa-<?=$usrimg?>"></i>
559
							<?=htmlspecialchars($userent['name'])?>
560
						</td>
561
						<td><?=htmlspecialchars($userent['descr'])?></td>
562
						<td><?php if (isset($userent['disabled'])) echo "*"?></td>
563
						<td><?=implode(",", local_user_get_groups($userent))?></td>
564
						<td>
565
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
566
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
567
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>"></a>
568
<?php endif; ?>
569
						</td>
570
					</tr>
571
<?php endforeach; ?>
572
				</tbody>
573
			</table>
574
		</div>
575
	</div>
576
</div>
577
<nav class="action-buttons">
578
	<a href="?act=new" class="btn btn-sm btn-success">
579
		<i class="fa fa-plus icon-embed-btn"></i>
580
		<?=gettext("Add")?>
581
	</a>
582

    
583
	<button type="submit" class="btn btn-sm btn-danger" name="dellall" value="dellall" title="<?=gettext('Delete selected users')?>">
584
		<i class="fa fa-trash icon-embed-btn"></i>
585
		<?=gettext("Delete")?>
586
	</button>
587
</nav>
588
</form>
589
<div class="infoblock">
590
<?php
591
	print_callout('<p>' . gettext("Additional users can be added here. User permissions for accessing " .
592
		"the webConfigurator can be assigned directly or inherited from group memberships. " .
593
		"Some system object properties can be modified but they cannot be deleted.") . '</p>' .
594
		'<p>' . gettext("Accounts added here are also used for other parts of the system " .
595
		"such as OpenVPN, IPsec, and Captive Portal.") . '</p>'
596
	);
597
?></div><?php
598
	include("foot.inc");
599
	exit;
600
}
601

    
602
$form = new Form;
603

    
604
if ($act == "new" || $act == "edit" || $input_errors):
605

    
606
	$form->addGlobal(new Form_Input(
607
		'act',
608
		null,
609
		'hidden',
610
		''
611
	));
612

    
613
	$form->addGlobal(new Form_Input(
614
		'userid',
615
		null,
616
		'hidden',
617
		isset($id) ? $id:''
618
	));
619

    
620
	$form->addGlobal(new Form_Input(
621
		'privid',
622
		null,
623
		'hidden',
624
		''
625
	));
626

    
627
	$form->addGlobal(new Form_Input(
628
		'certid',
629
		null,
630
		'hidden',
631
		''
632
	));
633

    
634
	$ro = "";
635
	if ($pconfig['utype'] == "system") {
636
		$ro = "readonly";
637
	}
638

    
639
	$section = new Form_Section('User Properties');
640

    
641
	$section->addInput(new Form_StaticText(
642
		'Defined by',
643
		strtoupper($pconfig['utype'])
644
	));
645

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

    
653
	$section->addInput(new Form_Checkbox(
654
		'disabled',
655
		'Disabled',
656
		'This user cannot login',
657
		$pconfig['disabled']
658
	));
659

    
660
	$section->addInput($input = new Form_Input(
661
		'usernamefld',
662
		'Username',
663
		'text',
664
		$pconfig['usernamefld']
665
	));
666

    
667
	if ($ro) {
668
		$input->setReadonly();
669
	}
670

    
671
	$form->addGlobal(new Form_Input(
672
		'oldusername',
673
		null,
674
		'hidden',
675
		$pconfig['usernamefld']
676
	));
677

    
678
	$group = new Form_Group('Password');
679
	$group->add(new Form_Input(
680
		'passwordfld1',
681
		'Password',
682
		'password'
683
	));
684
	$group->add(new Form_Input(
685
		'passwordfld2',
686
		'Confirm Password',
687
		'password'
688
	));
689

    
690
	$section->add($group);
691

    
692
	$section->addInput($input = new Form_Input(
693
		'descr',
694
		'Full name',
695
		'text',
696
		htmlspecialchars($pconfig['descr'])
697
	))->setHelp('User\'s full name, for administrative information only');
698

    
699
	if ($ro) {
700
		$input->setDisabled();
701
	}
702

    
703
	$section->addInput(new Form_Input(
704
		'expires',
705
		'Expiration date',
706
		'text',
707
		$pconfig['expires']
708
	))->setHelp('Leave blank if the account shouldn\'t expire, otherwise enter '.
709
		'the expiration date');
710

    
711
	// ==== Group membership ==================================================
712
	$group = new Form_Group('Group membership');
713

    
714
	// Make a list of all the groups configured on the system, and a list of
715
	// those which this user is a member of
716
	$systemGroups = array();
717
	$usersGroups = array();
718

    
719
	$usergid = [$pconfig['usernamefld']];
720

    
721
	foreach ($config['system']['group'] as $Ggroup) {
722
		if ($Ggroup['name'] != "all") {
723
			if (($act == 'edit') && $Ggroup['member'] && in_array($pconfig['uid'], $Ggroup['member'])) {
724
				$usersGroups[ $Ggroup['name'] ] = $Ggroup['name'];	// Add it to the user's list
725
			} else {
726
				$systemGroups[ $Ggroup['name'] ] = $Ggroup['name']; // Add it to the 'not a member of' list
727
			}
728
		}
729
	}
730

    
731
	$group->add(new Form_Select(
732
		'sysgroups',
733
		null,
734
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
735
		$systemGroups,
736
		true
737
	))->setHelp('Not member of');
738

    
739
	$group->add(new Form_Select(
740
		'groups',
741
		null,
742
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
743
		$usersGroups,
744
		true
745
	))->setHelp('Member of');
746

    
747
	$section->add($group);
748

    
749
	$group = new Form_Group('');
750

    
751
	$group->add(new Form_Button(
752
		'movetoenabled',
753
		'Move to "Member of" list',
754
		null,
755
		'fa-angle-double-right'
756
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
757

    
758
	$group->add(new Form_Button(
759
		'movetodisabled',
760
		'Move to "Not member of" list',
761
		null,
762
		'fa-angle-double-left'
763
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
764

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

    
768
	// ==== Button for adding user certificate ================================
769
	if ($act == 'new') {
770
		$section->addInput(new Form_Checkbox(
771
			'showcert',
772
			'Certificate',
773
			'Click to create a user certificate',
774
			false
775
		));
776
	}
777

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

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

    
785
		$section = new Form_Section('Effective Privileges');
786

    
787
		$section->addInput(new Form_StaticText(
788
			null,
789
			build_priv_table()
790
		));
791

    
792
		$form->add($section);
793

    
794
		// ==== Certificate table section =====================================
795
		$section = new Form_Section('User Certificates');
796

    
797
		$section->addInput(new Form_StaticText(
798
			null,
799
			build_cert_table()
800
		));
801

    
802
		$form->add($section);
803
	}
804

    
805
	// ==== Add user certificate for a new user
806
	if (is_array($config['ca']) && count($config['ca']) > 0) {
807
		$section = new Form_Section('Create Certificate for User');
808
		$section->addClass('cert-options');
809

    
810
		$nonPrvCas = array();
811
		foreach($config['ca'] as $ca) {
812
			if (!$ca['prv']) {
813
				continue;
814
			}
815

    
816
			$nonPrvCas[ $ca['refid'] ] = $ca['descr'];
817
		}
818

    
819
		if (!empty($nonPrvCas)) {
820
			$section->addInput(new Form_Input(
821
				'name',
822
				'Descriptive name',
823
				'text',
824
				$pconfig['name']
825
			));
826

    
827
			$section->addInput(new Form_Select(
828
				'caref',
829
				'Certificate authority',
830
				null,
831
				$nonPrvCas
832
			));
833

    
834
			$section->addInput(new Form_Select(
835
				'keylen',
836
				'Key length',
837
				2048,
838
				array(
839
					512 => '512 bits',
840
					1024 => '1024 bits',
841
					2048 => '2048 bits',
842
					4096 => '4096 bits',
843
				)
844
			));
845

    
846
			$section->addInput(new Form_Input(
847
				'lifetime',
848
				'Lifetime',
849
				'number',
850
				$pconfig['lifetime']
851
			));
852
		}
853

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

    
857
endif;
858
// ==== Paste a key for the new user
859
$section = new Form_Section('Keys');
860

    
861
$section->addInput(new Form_Checkbox(
862
	'showkey',
863
	'Authorized keys',
864
	'Click to paste an authorized key',
865
	false
866
));
867

    
868
$section->addInput(new Form_Textarea(
869
	'authorizedkeys',
870
	'Authorized SSH Keys',
871
	$pconfig['authorizedkeys']
872
))->setHelp('Enter authorized SSH keys for this user');
873

    
874
$section->addInput(new Form_Input(
875
	'ipsecpsk',
876
	'IPsec Pre-Shared Key',
877
	'text',
878
	$pconfig['ipsecpsk']
879
));
880

    
881
$form->add($section);
882

    
883
print $form;
884
?>
885
<script type="text/javascript">
886
//<![CDATA[
887
events.push(function() {
888

    
889
	// On click . .
890
	$("#movetodisabled").click(function() {
891
		moveOptions($('[name="groups[]"] option'), $('[name="sysgroups[]"]'));
892
	});
893

    
894
	$("#movetoenabled").click(function() {
895
		moveOptions($('[name="sysgroups[]"] option'), $('[name="groups[]"]'));
896
	});
897

    
898
	$("#showcert").click(function() {
899
		hideClass('cert-options', !this.checked);
900
	});
901

    
902
	$("#showkey").click(function() {
903
		hideInput('authorizedkeys', false);
904
		hideCheckbox('showkey', true);
905
	});
906

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

    
916
	$('[id^=delprivid]').click(function(event) {
917
		if (confirm(event.target.title)) {
918
			$('#privid').val(event.target.id.match(/\d+$/)[0]);
919
			$('#userid').val('<?=$id;?>');
920
			$('#act').val('delprivid');
921
			$('form').submit();
922
		}
923
	});
924

    
925
	$('#expires').datepicker();
926

    
927
	// ---------- On initial page load ------------------------------------------------------------
928

    
929
	hideClass('cert-options', true);
930
	//hideInput('authorizedkeys', true);
931
	hideCheckbox('showkey', true);
932

    
933
	// On submit mark all the user's groups as "selected"
934
	$('form').submit(function() {
935
		AllServers($('[name="groups[]"] option'), true);
936
	});
937
});
938
//]]>
939
</script>
940
<?php
941
include('foot.inc');
942
?>
(207-207/226)