Project

General

Profile

Download (35.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_usermanager.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	part of pfSense
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Copyright (C) 2008 Shrew Soft Inc.
12
	All rights reserved.
13

    
14
	Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
15
	All rights reserved.
16

    
17
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
18
	All rights reserved.
19

    
20
	Redistribution and use in source and binary forms, with or without
21
	modification, are permitted provided that the following conditions are met:
22

    
23
	1. Redistributions of source code must retain the above copyright notice,
24
	   this list of conditions and the following disclaimer.
25

    
26
	2. Redistributions in binary form must reproduce the above copyright
27
	   notice, this list of conditions and the following disclaimer in the
28
	   documentation and/or other materials provided with the distribution.
29

    
30
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
32
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39
	POSSIBILITY OF SUCH DAMAGE.
40
*/
41
/*
42
	pfSense_BUILDER_BINARIES:
43
	pfSense_MODULE:	auth
44
*/
45

    
46
##|+PRIV
47
##|*IDENT=page-system-usermanager
48
##|*NAME=System: User Manager page
49
##|*DESCR=Allow access to the 'System: User Manager' page.
50
##|*MATCH=system_usermanager.php*
51
##|-PRIV
52

    
53
require("certs.inc");
54
require("guiconfig.inc");
55

    
56
// start admin user code
57
$pgtitle = array(gettext("System"), gettext("User Manager"));
58

    
59
if (isset($_POST['userid']) && is_numericint($_POST['userid'])) {
60
	$id = $_POST['userid'];
61
}
62

    
63
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
64
	$config['system']['user'] = array();
65
}
66

    
67
$a_user = &$config['system']['user'];
68

    
69
if (isset($_SERVER['HTTP_REFERER'])) {
70
	$referer = $_SERVER['HTTP_REFERER'];
71
} else {
72
	$referer = '/system_usermanager.php';
73
}
74

    
75
if (isset($id) && $a_user[$id]) {
76
	$pconfig['usernamefld'] = $a_user[$id]['name'];
77
	$pconfig['descr'] = $a_user[$id]['descr'];
78
	$pconfig['expires'] = $a_user[$id]['expires'];
79
	$pconfig['groups'] = local_user_get_groups($a_user[$id]);
80
	$pconfig['utype'] = $a_user[$id]['scope'];
81
	$pconfig['uid'] = $a_user[$id]['uid'];
82
	$pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
83
	$pconfig['priv'] = $a_user[$id]['priv'];
84
	$pconfig['ipsecpsk'] = $a_user[$id]['ipsecpsk'];
85
	$pconfig['disabled'] = isset($a_user[$id]['disabled']);
86
}
87

    
88
if ($_POST['act'] == "deluser") {
89

    
90
	if (!isset($_POST['username']) || !isset($a_user[$id]) || ($_POST['username'] != $a_user[$id]['name'])) {
91
		pfSenseHeader("system_usermanager.php");
92
		exit;
93
	}
94

    
95
	conf_mount_rw();
96
	local_user_del($a_user[$id]);
97
	conf_mount_ro();
98
	$userdeleted = $a_user[$id]['name'];
99
	unset($a_user[$id]);
100
	write_config();
101
	$savemsg = gettext("User") . " {$userdeleted} " . gettext("successfully deleted") . "<br />";
102
} else if ($_POST['act'] == "delpriv") {
103

    
104
	if (!$a_user[$id]) {
105
		pfSenseHeader("system_usermanager.php");
106
		exit;
107
	}
108

    
109
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
110
	unset($a_user[$id]['priv'][$_POST['privid']]);
111
	local_user_set($a_user[$id]);
112
	write_config();
113
	$_POST['act'] = "edit";
114
	$savemsg = gettext("Privilege") . " {$privdeleted} " . gettext("successfully deleted"). "<br />";
115
} else if ($_POST['act'] == "expcert") {
116

    
117
	if (!$a_user[$id]) {
118
		pfSenseHeader("system_usermanager.php");
119
		exit;
120
	}
121

    
122
	$cert =& lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
123

    
124
	$exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.crt");
125
	$exp_data = base64_decode($cert['crt']);
126
	$exp_size = strlen($exp_data);
127

    
128
	header("Content-Type: application/octet-stream");
129
	header("Content-Disposition: attachment; filename={$exp_name}");
130
	header("Content-Length: $exp_size");
131
	echo $exp_data;
132
	exit;
133
} else if ($_POST['act'] == "expckey") {
134

    
135
	if (!$a_user[$id]) {
136
		pfSenseHeader("system_usermanager.php");
137
		exit;
138
	}
139

    
140
	$cert =& lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
141

    
142
	$exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.key");
143
	$exp_data = base64_decode($cert['prv']);
144
	$exp_size = strlen($exp_data);
145

    
146
	header("Content-Type: application/octet-stream");
147
	header("Content-Disposition: attachment; filename={$exp_name}");
148
	header("Content-Length: $exp_size");
149
	echo $exp_data;
150
	exit;
151
} else if ($_POST['act'] == "delcert") {
152

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

    
158
	$certdeleted = lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
159
	$certdeleted = $certdeleted['descr'];
160
	unset($a_user[$id]['cert'][$_POST['certid']]);
161
	write_config();
162
	$_POST['act'] = "edit";
163
	$savemsg = gettext("Certificate") . " {$certdeleted} " . gettext("association removed.") . "<br />";
164
} else if ($_POST['act'] == "new") {
165
	/*
166
	 * set this value cause the text field is read only
167
	 * and the user should not be able to mess with this
168
	 * setting.
169
	 */
170
	$pconfig['utype'] = "user";
171
	$pconfig['lifetime'] = 3650;
172
}
173

    
174
if (isset($_POST['dellall_x'])) {
175

    
176
	$del_users = $_POST['delete_check'];
177

    
178
	if (!empty($del_users)) {
179
		foreach ($del_users as $userid) {
180
			if (isset($a_user[$userid]) && $a_user[$userid]['scope'] != "system") {
181
				conf_mount_rw();
182
				local_user_del($a_user[$userid]);
183
				conf_mount_ro();
184
				unset($a_user[$userid]);
185
			}
186
		}
187
		$savemsg = gettext("Selected users removed successfully!");
188
		write_config($savemsg);
189
	}
190
}
191

    
192
if ($_POST['save']) {
193
	unset($input_errors);
194
	$pconfig = $_POST;
195

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

    
218
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
219

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

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

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

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

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

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

    
280
	if (!empty($_POST['name'])) {
281
		$ca = lookup_ca($_POST['caref']);
282
		if (!$ca) {
283
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
284
		}
285
	}
286

    
287
	/* if this is an AJAX caller then handle via JSON */
288
	if (isAjax() && is_array($input_errors)) {
289
		input_errors2Ajax($input_errors);
290
		exit;
291
	}
292

    
293
	if (!$input_errors) {
294
		conf_mount_rw();
295
		$userent = array();
296
		if (isset($id) && $a_user[$id]) {
297
			$userent = $a_user[$id];
298
		}
299

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

    
302
		/* the user name was modified */
303
		if (!empty($_POST['oldusername']) && ($_POST['usernamefld'] <> $_POST['oldusername'])) {
304
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
305
			local_user_del($userent);
306
		}
307

    
308
		/* the user password was modified */
309
		if ($_POST['passwordfld1']) {
310
			local_user_set_password($userent, $_POST['passwordfld1']);
311
		}
312

    
313
		$userent['name'] = $_POST['usernamefld'];
314
		$userent['descr'] = $_POST['descr'];
315
		$userent['expires'] = $_POST['expires'];
316
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
317
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
318

    
319
		if ($_POST['disabled']) {
320
			$userent['disabled'] = true;
321
		} else {
322
			unset($userent['disabled']);
323
		}
324

    
325
		if (isset($id) && $a_user[$id]) {
326
			$a_user[$id] = $userent;
327
		} else {
328
			if (!empty($_POST['name'])) {
329
				$cert = array();
330
				$cert['refid'] = uniqid();
331
				$userent['cert'] = array();
332

    
333
				$cert['descr'] = $_POST['name'];
334

    
335
				$subject = cert_get_subject_array($ca['crt']);
336

    
337
				$dn = array(
338
					'countryName' => $subject[0]['v'],
339
					'stateOrProvinceName' => $subject[1]['v'],
340
					'localityName' => $subject[2]['v'],
341
					'organizationName' => $subject[3]['v'],
342
					'emailAddress' => $subject[4]['v'],
343
					'commonName' => $userent['name']);
344

    
345
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
346
					(int)$_POST['lifetime'], $dn);
347

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

    
366
			$a_user[] = $userent;
367
		}
368

    
369
		local_user_set($userent);
370
		local_user_set_groups($userent, $_POST['groups']);
371
		write_config();
372

    
373
		if (is_dir("/etc/inc/privhooks")) {
374
			run_plugins("/etc/inc/privhooks");
375
		}
376

    
377
		conf_mount_ro();
378

    
379
		pfSenseHeader("system_usermanager.php");
380
	}
381
}
382

    
383
$closehead = false;
384
include("head.inc");
385
?>
386

    
387
<link rel="stylesheet" type="text/css" href="/javascript/jquery-ui-timepicker-addon/css/jquery-ui-timepicker-addon.css" />
388
<link rel="stylesheet" type="text/css" href="/javascript/jquery/jquery-ui-1.11.1.css" />
389

    
390
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
391
<script type="text/javascript">
392
//<![CDATA[
393
	jQuery(function() {
394
		jQuery( "#expires" ).datepicker( { dateFormat: 'mm/dd/yy', changeYear: true, yearRange: "+0:+100" } );
395
	});
396
//]]>
397
</script>
398
</head>
399

    
400
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
401
<?php include("fbegin.inc"); ?>
402

    
403
<script type="text/javascript">
404
//<![CDATA[
405

    
406
function setall_selected(id) {
407
	selbox = document.getElementById(id);
408
	count = selbox.options.length;
409
	for (index = 0; index<count; index++) {
410
		selbox.options[index].selected = true;
411
	}
412
}
413

    
414
function delete_empty(id) {
415
	selbox = document.getElementById(id);
416
	count = selbox.options.length;
417
	for (index = 0; index<count; index++) {
418
		if (selbox.options[index].value == '') {
419
			selbox.remove(index);
420
		}
421
	}
422
}
423

    
424
function clear_selected(id) {
425
	selbox = document.getElementById(id);
426
	count = selbox.options.length;
427
	for (index = 0; index<count; index++) {
428
		selbox.options[index].selected = false;
429
	}
430
}
431

    
432
function remove_selected(id) {
433
	selbox = document.getElementById(id);
434
	index = selbox.options.length - 1;
435
	for (; index >= 0; index--) {
436
		if (selbox.options[index].selected) {
437
			selbox.remove(index);
438
		}
439
	}
440
}
441

    
442
function copy_selected(srcid, dstid) {
443
	src_selbox = document.getElementById(srcid);
444
	dst_selbox = document.getElementById(dstid);
445
	count = dst_selbox.options.length;
446
	for (index = count - 1; index >= 0; index--) {
447
		if (dst_selbox.options[index].value == '') {
448
			dst_selbox.remove(index);
449
		}
450
	}
451
	count = src_selbox.options.length;
452
	for (index = 0; index < count; index++) {
453
		if (src_selbox.options[index].selected) {
454
			option = document.createElement('option');
455
			option.text = src_selbox.options[index].text;
456
			option.value = src_selbox.options[index].value;
457
			dst_selbox.add(option, null);
458
		}
459
	}
460
}
461

    
462
function move_selected(srcid, dstid) {
463
	copy_selected(srcid, dstid);
464
	remove_selected(srcid);
465
}
466

    
467
function presubmit() {
468
	delete_empty('groups');
469
	delete_empty('notgroups');
470
	clear_selected('notgroups');
471
	setall_selected('groups');
472
}
473

    
474
function usercertClicked(obj) {
475
	if (obj.checked) {
476
		document.getElementById("usercertchck").style.display="none";
477
		document.getElementById("usercert").style.display="";
478
	} else {
479
		document.getElementById("usercert").style.display="none";
480
		document.getElementById("usercertchck").style.display="";
481
	}
482
}
483

    
484
function sshkeyClicked(obj) {
485
	if (obj.checked) {
486
		document.getElementById("sshkeychck").style.display="none";
487
		document.getElementById("sshkey").style.display="";
488
	} else {
489
		document.getElementById("sshkey").style.display="none";
490
		document.getElementById("sshkeychck").style.display="";
491
	}
492
}
493
//]]>
494
</script>
495
<?php
496
	if ($input_errors) {
497
		print_input_errors($input_errors);
498
	}
499
	if ($savemsg) {
500
		print_info_box($savemsg);
501
	}
502
?>
503
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="user manager">
504
	<tr>
505
		<td>
506
<?php
507
			$tab_array = array();
508
			$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
509
			$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
510
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
511
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
512
			display_top_tabs($tab_array);
513
?>
514
		</td>
515
	</tr>
516
	<tr>
517
		<td id="mainarea">
518
			<div class="tabcont">
519
<?php
520
			if ($_POST['act'] == "new" || $_POST['act'] == "edit" || $input_errors):
521
?>
522
				<form action="system_usermanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
523
					<input type="hidden" id="act" name="act" value="" />
524
					<input type="hidden" id="userid" name="userid" value="<?=(isset($id) ? $id : '');?>" />
525
					<input type="hidden" id="privid" name="privid" value="" />
526
					<input type="hidden" id="certid" name="certid" value="" />
527
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
528
<?php
529
						$ro = "";
530
						if ($pconfig['utype'] == "system") {
531
							$ro = "readonly=\"readonly\"";
532
						}
533
?>
534
						<tr>
535
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
536
							<td width="78%" class="vtable">
537
								<strong><?=strtoupper(htmlspecialchars($pconfig['utype']));?></strong>
538
								<input name="utype" type="hidden" value="<?=htmlspecialchars($pconfig['utype'])?>" />
539
							</td>
540
						</tr>
541
						<tr>
542
							<td width="22%" valign="top" class="vncell"><?=gettext("Disabled");?></td>
543
							<td width="78%" class="vtable">
544
								<input name="disabled" type="checkbox" id="disabled" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
545
							</td>
546
						</tr>
547
						<tr>
548
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
549
							<td width="78%" class="vtable">
550
								<input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" <?=$ro;?> />
551
								<input name="oldusername" type="hidden" id="oldusername" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" />
552
							</td>
553
						</tr>
554
						<tr>
555
							<td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td>
556
							<td width="78%" class="vtable">
557
								<input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" value="" />
558
							</td>
559
						</tr>
560
						<tr>
561
							<td width="78%" class="vtable">
562
								<input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;<?= gettext("(confirmation)"); ?>
563
							</td>
564
						</tr>
565
						<tr>
566
							<td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td>
567
							<td width="78%" class="vtable">
568
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>" <?=$ro;?> />
569
								<br />
570
								<?=gettext("User's full name, for your own information only");?>
571
							</td>
572
						</tr>
573
						<tr>
574
							<td width="22%" valign="top" class="vncell"><?=gettext("Expiration date"); ?></td>
575
							<td width="78%" class="vtable">
576
								<input name="expires" type="text" class="formfld unknown" id="expires" size="10" value="<?=htmlspecialchars($pconfig['expires']);?>" />
577
								<br />
578
								<span class="vexpl"><?=gettext("Leave blank if the account shouldn't expire, otherwise enter the expiration date in the following format: mm/dd/yyyy"); ?></span>
579
							</td>
580
						</tr>
581
						<tr>
582
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
583
							<td width="78%" class="vtable" align="center">
584
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="group membership">
585
									<tr>
586
										<td align="center" width="50%">
587
											<strong><?=gettext("Not Member Of"); ?></strong><br />
588
											<br />
589
											<select size="10" style="width: 75%" name="notgroups[]" class="formselect" id="notgroups" onchange="clear_selected('groups')" multiple="multiple">
590
<?php
591
												$rowIndex = 0;
592
												foreach ($config['system']['group'] as $group):
593
													if ($group['gid'] == 1998) { /* all users group */
594
														continue;
595
													}
596
													if (is_array($pconfig['groups']) && in_array($group['name'], $pconfig['groups'])) {
597
														continue;
598
													}
599
													$rowIndex++;
600
?>
601
												<option value="<?=$group['name'];?>" <?=$selected;?>>
602
													<?=htmlspecialchars($group['name']);?>
603
												</option>
604
<?php
605
												endforeach;
606
												if ($rowIndex == 0) {
607
													echo "<option></option>";
608
												}
609
?>
610
											</select>
611
											<br />
612
										</td>
613
										<td>
614
											<br />
615
											<a href="javascript:move_selected('notgroups', 'groups')">
616
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Groups"); ?>" alt="<?=gettext("Add Groups"); ?>" width="17" height="17" border="0" />
617
											</a>
618
											<br /><br />
619
											<a href="javascript:move_selected('groups', 'notgroups')">
620
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Groups"); ?>" alt="<?=gettext("Remove Groups"); ?>" width="17" height="17" border="0" />
621
											</a>
622
										</td>
623
										<td align="center" width="50%">
624
											<strong><?=gettext("Member Of"); ?></strong><br />
625
											<br />
626
											<select size="10" style="width: 75%" name="groups[]" class="formselect" id="groups" onchange="clear_selected('notgroups')" multiple="multiple">
627
<?php
628
												$rowIndex = 0;
629
												if (is_array($pconfig['groups'])):
630
													foreach ($config['system']['group'] as $group):
631
														if ($group['gid'] == 1998) { /* all users group */
632
															continue;
633
														}
634
														if (!in_array($group['name'], $pconfig['groups'])) {
635
															continue;
636
														}
637
														$rowIndex++;
638
?>
639
												<option value="<?=$group['name'];?>">
640
													<?=htmlspecialchars($group['name']);?>
641
												</option>
642
<?php
643
													endforeach;
644
												endif;
645
												if ($rowIndex == 0) {
646
													echo "<option></option>";
647
												}
648
?>
649
											</select>
650
											<br />
651
										</td>
652
									</tr>
653
								</table>
654
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
655
							</td>
656
						</tr>
657
<?php
658
					if (isset($pconfig['uid'])):
659
?>
660
						<tr>
661
							<td width="22%" valign="top" class="vncell"><?=gettext("Effective Privileges");?></td>
662
							<td width="78%" class="vtable">
663
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
664
									<tr>
665
										<td width="20%" class="listhdrr"><?=gettext("Inherited From");?></td>
666
										<td width="30%" class="listhdrr"><?=gettext("Name");?></td>
667
										<td width="40%" class="listhdrr"><?=gettext("Description");?></td>
668
										<td class="list"></td>
669
									</tr>
670
<?php
671
							$privdesc = get_user_privdesc($a_user[$id]);
672
							if (is_array($privdesc)):
673
								$i = 0;
674
								foreach ($privdesc as $priv):
675
									$group = false;
676
									if ($priv['group']) {
677
										$group = $priv['group'];
678
									}
679
?>
680
									<tr>
681
										<td class="listlr"><?=$group;?></td>
682
										<td class="listr">
683
											<?=htmlspecialchars($priv['name']);?>
684
										</td>
685
										<td class="listbg">
686
											<?=htmlspecialchars($priv['descr']);?>
687
										</td>
688
										<td valign="middle" class="list nowrap">
689
<?php
690
										if (!$group):
691
?>
692
											<input type="image" name="delpriv[]" width="17" height="17" border="0"
693
												src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
694
												onclick="document.getElementById('privid').value='<?=$i;?>';
695
													document.getElementById('userid').value='<?=$id;?>';
696
													document.getElementById('act').value='<?php echo "delpriv";?>';
697
													return confirm('<?=gettext("Do you really want to delete this privilege?");?>');"
698
												title="<?=gettext("delete privilege");?>" />
699
<?php
700
										endif;
701
?>
702
										</td>
703
									</tr>
704
<?php
705
										/* can only delete user priv indexes */
706
										if (!$group) {
707
											$i++;
708
										}
709
								endforeach;
710
							endif;
711
?>
712
									<tr>
713
										<td class="list" colspan="3"></td>
714
										<td class="list">
715
											<a href="system_usermanager_addprivs.php?userid=<?=$id?>">
716
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
717
											</a>
718
										</td>
719
									</tr>
720
								</table>
721
							</td>
722
						</tr>
723
						<tr>
724
							<td width="22%" valign="top" class="vncell"><?=gettext("User Certificates");?></td>
725
							<td width="78%" class="vtable">
726
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="certificates">
727
									<tr>
728
										<td width="45%" class="listhdrr"><?=gettext("Name");?></td>
729
										<td width="45%" class="listhdrr"><?=gettext("CA");?></td>
730
										<td class="list"></td>
731
									</tr>
732
<?php
733
							$a_cert = $a_user[$id]['cert'];
734
							if (is_array($a_cert)):
735
								$i = 0;
736
								foreach ($a_cert as $certref):
737
									$cert = lookup_cert($certref);
738
									$ca = lookup_ca($cert['caref']);
739
?>
740
									<tr>
741
										<td class="listlr">
742
											<?=htmlspecialchars($cert['descr']);?>
743
<?php
744
										if (is_cert_revoked($cert)):
745
?>
746
											(<b>Revoked</b>)
747
<?php
748
										endif;
749
?>
750
										</td>
751
										<td class="listr">
752
											<?=htmlspecialchars($ca['descr']);?>
753
										</td>
754
										<td valign="middle" class="list nowrap">
755
											<input type="image" name="expckey[]" width="17" height="17" border="0"
756
												src="/themes/<?=$g['theme'];?>/images/icons/icon_down.gif"
757
												onclick="document.getElementById('certid').value='<?=$i;?>';
758
													document.getElementById('userid').value='<?=$id;?>';
759
													document.getElementById('act').value='<?php echo "expckey";?>';"
760
												title="<?=gettext("export private key");?>" />
761
											<input type="image" name="expcert[]" width="17" height="17" border="0"
762
												src="/themes/<?=$g['theme'];?>/images/icons/icon_down.gif"
763
												onclick="document.getElementById('certid').value='<?=$i;?>';
764
													document.getElementById('userid').value='<?=$id;?>';
765
													document.getElementById('act').value='<?php echo "expcert";?>';"
766
												title="<?=gettext("export cert");?>" />
767
											<input type="image" name="delcert[]" width="17" height="17" border="0"
768
												src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
769
												onclick="document.getElementById('certid').value='<?=$i;?>';
770
													document.getElementById('userid').value='<?=$id;?>';
771
													document.getElementById('act').value='<?php echo "delcert";?>';
772
													return confirm('<?=gettext("Do you really want to remove this certificate association?") .'\n'. gettext("(Certificate will not be deleted)");?>')"
773
												title="<?=gettext("delete cert");?>" />
774
										</td>
775
									</tr>
776
<?php
777
									$i++;
778
								endforeach;
779
							endif;
780
?>
781
									<tr>
782
										<td class="list" colspan="2"></td>
783
										<td class="list">
784
											<a href="system_certmanager.php?act=new&amp;userid=<?=$id?>">
785
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
786
											</a>
787
										</td>
788
									</tr>
789
								</table>
790
							</td>
791
						</tr>
792

    
793
<?php
794
					else:
795
						if (is_array($config['ca']) && count($config['ca']) > 0):
796
							$i = 0;
797
							foreach ($config['ca'] as $ca) {
798
								if (!$ca['prv']) {
799
									continue;
800
								}
801
								$i++;
802
							}
803
?>
804

    
805
						<tr id="usercertchck">
806
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
807
							<td width="78%" class="vtable">
808
								<input type="checkbox" onclick="javascript:usercertClicked(this)" /> <?=gettext("Click to create a user certificate."); ?>
809
							</td>
810
						</tr>
811

    
812
<?php
813
							if ($i > 0):
814
?>
815
						<tr id="usercert" style="display:none">
816
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
817
							<td width="78%" class="vtable">
818
								<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="certificate">
819
									<tr>
820
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
821
										<td width="78%" class="vtable">
822
											<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
823
										</td>
824
									</tr>
825
									<tr>
826
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
827
										<td width="78%" class="vtable">
828
											<select name='caref' id='caref' class="formselect" onchange='internalca_change()'>
829
<?php
830
											$rowIndex = 0;
831
											foreach ($config['ca'] as $ca):
832
												if (!$ca['prv']) {
833
													continue;
834
												}
835
												$rowIndex++;
836
?>
837
												<option value="<?=$ca['refid'];?>"><?=htmlspecialchars($ca['descr']);?></option>
838
<?php
839
											endforeach;
840
											if ($rowIndex == 0) {
841
												echo "<option></option>";
842
											}
843
?>
844
											</select>
845
										</td>
846
									</tr>
847
									<tr>
848
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
849
										<td width="78%" class="vtable">
850
											<select name='keylen' class="formselect">
851
<?php
852
											$cert_keylens = array("2048", "512", "1024", "4096");
853
											foreach ($cert_keylens as $len):
854
?>
855
												<option value="<?=$len;?>"><?=$len;?></option>
856
<?php
857
											endforeach;
858
											if (!count($cert_keylens)) {
859
												echo "<option></option>";
860
											}
861
?>
862
											</select>
863
											bits
864
										</td>
865
									</tr>
866
									<tr>
867
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
868
										<td width="78%" class="vtable">
869
											<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />days
870
										</td>
871
									</tr>
872
								</table>
873
							</td>
874
						</tr>
875
<?php
876
							endif;
877
						endif;
878
					endif;
879
?>
880
						<tr id="sshkeychck" <?php if (!empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
881
							<td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
882
							<td width="78%" class="vtable">
883
								<input type="checkbox" onclick="javascript:sshkeyClicked(this)" /> <?=gettext("Click to paste an authorized key."); ?>
884
							</td>
885
						</tr>
886
						<tr id="sshkey" <?php if (empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
887
							<td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
888
							<td width="78%" class="vtable">
889
								<script type="text/javascript">
890
								//<![CDATA[
891
								window.onload=function() {
892
									document.getElementById("authorizedkeys").wrap='off';
893
								}
894
								//]]>
895
								</script>
896
								<textarea name="authorizedkeys" cols="65" rows="7" id="authorizedkeys" class="formfld_cert"><?=htmlspecialchars($pconfig['authorizedkeys']);?></textarea>
897
								<br />
898
								<?=gettext("Paste an authorized keys file here.");?>
899
							</td>
900
						</tr>
901
						<tr id="ipsecpskrow">
902
							<td width="22%" valign="top" class="vncell"><?=gettext("IPsec Pre-Shared Key");?></td>
903
							<td width="78%" class="vtable">
904
								<input name="ipsecpsk" type="text" class="formfld unknown" id="ipsecpsk" size="65" value="<?=htmlspecialchars($pconfig['ipsecpsk']);?>" />
905
							</td>
906
						</tr>
907
						<tr>
908
							<td width="22%" valign="top">&nbsp;</td>
909
							<td width="78%">
910
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
911
								<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
912
								<?php if (isset($id) && $a_user[$id]): ?>
913
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
914
								<?php endif;?>
915
							</td>
916
						</tr>
917
					</table>
918
				</form>
919
<?php
920
			else:
921
?>
922
				<form action="system_usermanager.php" method="post" name="iform2" id="iform2">
923
					<input type="hidden" id="act" name="act" value="" />
924
					<input type="hidden" id="userid" name="userid" value="<?=(isset($id) ? $id : '');?>" />
925
					<input type="hidden" id="username" name="username" value="" />
926
					<input type="hidden" id="privid" name="privid" value="" />
927
					<input type="hidden" id="certid" name="certid" value="" />
928
					<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
929
						<thead>
930
							<tr>
931
								<th width="5%" class="list">&nbsp;</th>
932
								<th width="25%" class="listhdrr"><?=gettext("Username"); ?></th>
933
								<th width="25%" class="listhdrr"><?=gettext("Full name"); ?></th>
934
								<th width="5%" class="listhdrr"><?=gettext("Disabled"); ?></th>
935
								<th width="25%" class="listhdrr"><?=gettext("Groups"); ?></th>
936
								<th width="10%" class="list"></th>
937
							</tr>
938
						</thead>
939
						<tfoot>
940
							<tr>
941
								<td class="list" colspan="5"></td>
942
								<td class="list">
943
									<input type="image" name="addcert" width="17" height="17" border="0"
944
										src="/themes/<?=$g['theme'];?>/images/icons/icon_plus.gif"
945
										onclick="document.getElementById('act').value='<?php echo "new";?>';"
946
										title="<?=gettext("add user");?>" />
947
									<input type="image" src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" name="dellall" title="<?=gettext('Delete selected users')?>" onClick="return confirm('<?=gettext("Do you really want to delete selected Users?");?>')" />
948
								</td>
949
							</tr>
950
							<tr>
951
								<td colspan="5">
952
									<p>
953
										<?=gettext("Additional users can be added here. User permissions for accessing " .
954
										"the webConfigurator can be assigned directly or inherited from group memberships. " .
955
										"An icon that appears grey indicates that it is a system defined object. " .
956
										"Some system object properties can be modified but they cannot be deleted."); ?>
957
										<br /><br />
958
										<?=gettext("Accounts created here are also used for other parts of the system " .
959
										"such as OpenVPN, IPsec, and Captive Portal.");?>
960
									</p>
961
								</td>
962
							</tr>
963
						</tfoot>
964
						<tbody>
965
<?php
966
						$i = 0;
967
						foreach ($a_user as $userent):
968
?>
969
								<tr ondblclick="document.getElementById('act').value='<?php echo "edit";?>';
970
									document.getElementById('userid').value='<?=$i;?>';
971
									document.iform2.submit();" id="fr<?=$i?>">
972
								<td class="list" id="frd<?=$i?>">
973
								<?php if ($userent['scope'] != "system") : ?>
974
									<input type="checkbox" id="frc<?=$i?>" onclick="fr_bgcolor(<?=$i?>)" name="delete_check[]" value="<?=$i?>" />
975
								<?php endif; ?>
976
								</td>
977
								<td class="listlr" id="frd<?=$i?>" onclick="fr_toggle('<?=$i;?>')">
978
									<table border="0" cellpadding="0" cellspacing="0" summary="icons">
979
										<tr>
980
											<td align="left" valign="middle">
981
<?php
982
												if ($userent['scope'] != "user") {
983
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user-grey.png";
984
												} else {
985
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user.png";
986
												}
987
?>
988
												<img src="<?=$usrimg;?>" alt="<?=gettext("User"); ?>" title="<?=gettext("User"); ?>" border="0" height="16" width="16" />
989
											</td>
990
											<td align="left" valign="middle">
991
												<?=htmlspecialchars($userent['name']);?>
992
											</td>
993
										</tr>
994
									</table>
995
								</td>
996
								<td class="listr" id="frd<?=$i?>" onclick="fr_toggle('<?=$i;?>')"><?=htmlspecialchars($userent['descr']);?>&nbsp;</td>
997
								<td class="listr" id="frd<?=$i?>" onclick="fr_toggle('<?=$i;?>')"><?php if (isset($userent['disabled'])) echo "*"; ?></td>
998
								<td class="listbg" onclick="fr_toggle('<?=$i;?>')">
999
									<?=implode(",", local_user_get_groups($userent));?>
1000
									&nbsp;
1001
								</td>
1002
								<td valign="middle" class="list nowrap">
1003
									<input type="image" name="edituser[]" width="17" height="17" border="0"
1004
										src="/themes/<?=$g['theme'];?>/images/icons/icon_e.gif"
1005
										onclick="document.getElementById('userid').value='<?=$i;?>';
1006
											document.getElementById('act').value='<?php echo "edit";?>';"
1007
										title="<?=gettext("edit user");?>" />
1008
<?php
1009
								if ($userent['scope'] != "system"):
1010
?>
1011
									&nbsp;
1012
									<input type="image" name="deluser[]" width="17" height="17" border="0"
1013
										src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
1014
										onclick="document.getElementById('userid').value='<?=$i;?>';
1015
											document.getElementById('username').value='<?=$userent['name'];?>';
1016
											document.getElementById('act').value='<?php echo "deluser";?>';
1017
											return confirm('<?=gettext("Do you really want to delete this user?");?>');"
1018
										title="<?=gettext("delete user");?>" />
1019
<?php
1020
								endif;
1021
?>
1022
								</td>
1023
							</tr>
1024
<?php
1025
							$i++;
1026
						endforeach;
1027
?>
1028
						</tbody>
1029
					</table>
1030
				</form>
1031
<?php
1032
			endif;
1033
?>
1034
			</div>
1035
		</td>
1036
	</tr>
1037
</table>
1038
<?php include("fend.inc");?>
1039
</body>
1040
</html>
(225-225/252)