Project

General

Profile

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

    
7
    Copyright (C) 2008 Shrew Soft Inc.
8
    All rights reserved.
9

    
10
    Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
11
    All rights reserved.
12

    
13
    Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
14
    All rights reserved.
15

    
16
    Redistribution and use in source and binary forms, with or without
17
    modification, are permitted provided that the following conditions are met:
18

    
19
    1. Redistributions of source code must retain the above copyright notice,
20
       this list of conditions and the following disclaimer.
21

    
22
    2. Redistributions in binary form must reproduce the above copyright
23
       notice, this list of conditions and the following disclaimer in the
24
       documentation and/or other materials provided with the distribution.
25

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

    
42
##|+PRIV
43
##|*IDENT=page-system-usermanager
44
##|*NAME=System: User Manager page
45
##|*DESCR=Allow access to the 'System: User Manager' page.
46
##|*MATCH=system_usermanager.php*
47
##|-PRIV
48

    
49
require("certs.inc");
50
require("guiconfig.inc");
51

    
52

    
53
// start admin user code
54
$pgtitle = array(gettext("System"),gettext("User Manager"));
55

    
56
$id = $_GET['id'];
57
if (isset($_POST['id']))
58
	$id = $_POST['id'];
59

    
60
if (!is_array($config['system']['user']))
61
	$config['system']['user'] = array();
62

    
63
$a_user = &$config['system']['user'];
64

    
65
if (isset($id) && $a_user[$id]) {
66
	$pconfig['usernamefld'] = $a_user[$id]['name'];
67
	$pconfig['descr'] = $a_user[$id]['descr'];
68
	$pconfig['expires'] = $a_user[$id]['expires'];
69
	$pconfig['groups'] = local_user_get_groups($a_user[$id]);
70
	$pconfig['utype'] = $a_user[$id]['scope'];
71
	$pconfig['uid'] = $a_user[$id]['uid'];
72
	$pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
73
	$pconfig['priv'] = $a_user[$id]['priv'];
74
	$pconfig['ipsecpsk'] = $a_user[$id]['ipsecpsk'];
75
	$pconfig['disabled'] = isset($a_user[$id]['disabled']);
76
}
77

    
78
if ($_GET['act'] == "deluser") {
79

    
80
	if (!$a_user[$id]) {
81
		pfSenseHeader("system_usermanager.php");
82
		exit;
83
	}
84

    
85
	local_user_del($a_user[$id]);
86
	$userdeleted = $a_user[$id]['name'];
87
	unset($a_user[$id]);
88
	write_config();
89
	$savemsg = gettext("User")." {$userdeleted} ".
90
				gettext("successfully deleted")."<br/>";
91
}
92
else if ($_GET['act'] == "delpriv") {
93

    
94
	if (!$a_user[$id]) {
95
		pfSenseHeader("system_usermanager.php");
96
		exit;
97
	}
98

    
99
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_GET['privid']]]['name'];
100
	unset($a_user[$id]['priv'][$_GET['privid']]);
101
	local_user_set($a_user[$id]);
102
	write_config();
103
	$_GET['act'] = "edit";
104
	$savemsg = gettext("Privilege")." {$privdeleted} ".
105
				gettext("successfully deleted")."<br/>";
106
}
107
else if ($_GET['act'] == "expcert") {
108

    
109
	if (!$a_user[$id]) {
110
		pfSenseHeader("system_usermanager.php");
111
		exit;
112
	}
113

    
114
	$cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]);
115

    
116
	$exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.crt");
117
	$exp_data = base64_decode($cert['crt']);
118
	$exp_size = strlen($exp_data);
119

    
120
	header("Content-Type: application/octet-stream");
121
	header("Content-Disposition: attachment; filename={$exp_name}");
122
	header("Content-Length: $exp_size");
123
	echo $exp_data;
124
	exit;
125
}
126
else if ($_GET['act'] == "expckey") {
127

    
128
	if (!$a_user[$id]) {
129
		pfSenseHeader("system_usermanager.php");
130
		exit;
131
	}
132

    
133
	$cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]);
134

    
135
	$exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.key");
136
	$exp_data = base64_decode($cert['prv']);
137
	$exp_size = strlen($exp_data);
138

    
139
	header("Content-Type: application/octet-stream");
140
	header("Content-Disposition: attachment; filename={$exp_name}");
141
	header("Content-Length: $exp_size");
142
	echo $exp_data;
143
	exit;
144
}
145
else if ($_GET['act'] == "delcert") {
146

    
147
	if (!$a_user[$id]) {
148
		pfSenseHeader("system_usermanager.php");
149
		exit;
150
	}
151

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

    
170
if ($_POST) {
171
	unset($input_errors);
172
	$pconfig = $_POST;
173

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

    
196
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
197

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

    
201
	if (strlen($_POST['usernamefld']) > 16)
202
		$input_errors[] = gettext("The username is longer than 16 characters.");
203

    
204
	if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2']))
205
		$input_errors[] = gettext("The passwords do not match.");
206

    
207
	if (isset($id) && $a_user[$id])
208
		$oldusername = $a_user[$id]['name'];
209
	else
210
		$oldusername = "";
211
	/* make sure this user name is unique */
212
	if (!$input_errors) {
213
		foreach ($a_user as $userent) {
214
			if ($userent['name'] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
215
				$input_errors[] = gettext("Another entry with the same username already exists.");
216
				break;
217
			}
218
		}
219
	}
220
	/* also make sure it is not reserved */
221
	if (!$input_errors) {
222
		$system_users = explode("\n", file_get_contents("/etc/passwd"));
223
		foreach ($system_users as $s_user) {
224
			$ent = explode(":", $s_user);
225
			if ($ent[0] == $_POST['usernamefld'] && $oldusername != $_POST['usernamefld']) {
226
				$input_errors[] = gettext("That username is reserved by the system.");
227
				break;
228
			}
229
		}
230
	}
231

    
232
	/*
233
	 * Check for a valid expirationdate if one is set at all (valid means,
234
	 * DateTime puts out a time stamp so any DateTime compatible time
235
	 * format may be used. to keep it simple for the enduser, we only
236
	 * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
237
	 * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
238
	 * Otherwhise such an entry would lead to an invalid expiration data.
239
	 */
240
	if ($_POST['expires']){
241
		try {
242
			$expdate = new DateTime($_POST['expires']);
243
			//convert from any DateTime compatible date to MM/DD/YYYY
244
			$_POST['expires'] = $expdate->format("m/d/Y");
245
		} catch ( Exception $ex ) {
246
			$input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
247
		}
248
	}
249

    
250
	if (!empty($_POST['name'])) {
251
		$ca = lookup_ca($_POST['caref']);
252
       		if (!$ca)
253
               		$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
254
	}
255

    
256
	/* if this is an AJAX caller then handle via JSON */
257
	if (isAjax() && is_array($input_errors)) {
258
		input_errors2Ajax($input_errors);
259
		exit;
260
	}
261

    
262
	if (!$input_errors) {
263
		conf_mount_rw();
264
		$userent = array();
265
		if (isset($id) && $a_user[$id])
266
			$userent = $a_user[$id];
267

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

    
270
		/* the user name was modified */
271
		if ($_POST['usernamefld'] <> $_POST['oldusername']) {
272
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
273
			local_user_del($userent);
274
		}
275

    
276
		/* the user password was mofified */
277
		if ($_POST['passwordfld1'])
278
			local_user_set_password($userent, $_POST['passwordfld1']);
279

    
280
		$userent['name'] = $_POST['usernamefld'];
281
		$userent['descr'] = $_POST['descr'];
282
		$userent['expires'] = $_POST['expires'];
283
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
284
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
285

    
286
		if($_POST['disabled'])
287
			$userent['disabled'] = true;
288
		else
289
			unset($userent['disabled']);
290

    
291
		if (isset($id) && $a_user[$id])
292
			$a_user[$id] = $userent;
293
		else {
294
			if (!empty($_POST['name'])) {
295
				$cert = array();
296
				$cert['refid'] = uniqid();
297
                       		$userent['cert'] = array();
298

    
299
				$cert['descr'] = $_POST['name'];
300

    
301
               			$subject = cert_get_subject_array($ca['crt']);
302

    
303
               			$dn = array(
304
                       			'countryName' => $subject[0]['v'],
305
                       			'stateOrProvinceName' => $subject[1]['v'],
306
                       			'localityName' => $subject[2]['v'],
307
                       			'organizationName' => $subject[3]['v'],
308
                       			'emailAddress' => $subject[4]['v'],
309
                       			'commonName' => $userent['name']);
310

    
311
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
312
					(int)$_POST['lifetime'], $dn);
313

    
314
				if (!is_array($config['cert']))
315
					$config['cert'] = array();
316
				$config['cert'][] = $cert;
317
				$userent['cert'][] = $cert['refid'];
318
			}
319
			$userent['uid'] = $config['system']['nextuid']++;
320
			/* Add the user to All Users group. */
321
			foreach ($config['system']['group'] as $gidx => $group) {
322
				if ($group['name'] == "all") {
323
					if (!is_array($config['system']['group'][$gidx]['member']))
324
						$config['system']['group'][$gidx]['member'] = array();
325
					$config['system']['group'][$gidx]['member'][] = $userent['uid'];
326
					break;
327
				}
328
			}
329

    
330
			$a_user[] = $userent;
331
		}
332

    
333
		local_user_set_groups($userent,$_POST['groups']);
334
		local_user_set($userent);
335
		write_config();
336

    
337
		if(is_dir("/etc/inc/privhooks"))
338
			run_plugins("/etc/inc/privhooks");
339

    
340
		conf_mount_ro();
341

    
342
		pfSenseHeader("system_usermanager.php");
343
	}
344
}
345

    
346
include("head.inc");
347
?>
348

    
349
<link rel="stylesheet" type="text/css" href="/javascript/jquery-ui-timepicker-addon/css/jquery-ui-timepicker-addon.css" />
350
<link rel="stylesheet" type="text/css" href="/javascript/jquery/jquery-ui.custom.css" />
351

    
352
<script>
353
	jQuery(function() {
354
		jQuery( "#expires" ).datepicker( { dateFormat: 'mm/dd/yy', changeYear: true, yearRange: "+0:+100" } );
355
	});
356
</script>
357

    
358
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
359
<?php include("fbegin.inc"); ?>
360

    
361
<script type="text/javascript">
362
//<![CDATA[
363

    
364
function setall_selected(id) {
365
	selbox = document.getElementById(id);
366
	count = selbox.options.length;
367
	for (index = 0; index<count; index++)
368
		selbox.options[index].selected = true;
369
}
370

    
371
function clear_selected(id) {
372
	selbox = document.getElementById(id);
373
	count = selbox.options.length;
374
	for (index = 0; index<count; index++)
375
		selbox.options[index].selected = false;
376
}
377

    
378
function remove_selected(id) {
379
	selbox = document.getElementById(id);
380
	index = selbox.options.length - 1;
381
	for (; index >= 0; index--)
382
		if (selbox.options[index].selected)
383
			selbox.remove(index);
384
}
385

    
386
function copy_selected(srcid, dstid) {
387
	src_selbox = document.getElementById(srcid);
388
	dst_selbox = document.getElementById(dstid);
389
	count = src_selbox.options.length;
390
	for (index = 0; index < count; index++) {
391
		if (src_selbox.options[index].selected) {
392
			option = document.createElement('option');
393
			option.text = src_selbox.options[index].text;
394
			option.value = src_selbox.options[index].value;
395
			dst_selbox.add(option, null);
396
		}
397
	}
398
}
399

    
400
function move_selected(srcid, dstid) {
401
	copy_selected(srcid, dstid);
402
	remove_selected(srcid);
403
}
404

    
405
function presubmit() {
406
	clear_selected('notgroups');
407
	setall_selected('groups');
408
}
409

    
410
function usercertClicked(obj) {
411
	if (obj.checked) {
412
		document.getElementById("usercertchck").style.display="none";
413
		document.getElementById("usercert").style.display="";
414
	} else {
415
		document.getElementById("usercert").style.display="none";
416
		document.getElementById("usercertchck").style.display="";
417
	}
418
}
419

    
420
function sshkeyClicked(obj) {
421
        if (obj.checked) {
422
                document.getElementById("sshkeychck").style.display="none";
423
                document.getElementById("sshkey").style.display="";
424
        } else {
425
                document.getElementById("sshkey").style.display="none";
426
                document.getElementById("sshkeychck").style.display="";
427
        }
428
}
429
//]]>
430
</script>
431
<?php
432
	if ($input_errors)
433
		print_input_errors($input_errors);
434
	if ($savemsg)
435
		print_info_box($savemsg);
436
?>
437
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="user manager">
438
	<tr>
439
		<td>
440
		<?php
441
			$tab_array = array();
442
			$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
443
			$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
444
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
445
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
446
			display_top_tabs($tab_array);
447
		?>
448
		</td>
449
	</tr>
450
	<tr>
451
		<td id="mainarea">
452
			<div class="tabcont">
453

    
454
				<?php if ($_GET['act'] == "new" || $_GET['act'] == "edit" || $input_errors): ?>
455

    
456
				<form action="system_usermanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
457
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
458
						<?php
459
							$ro = "";
460
							if ($pconfig['utype'] == "system")
461
								$ro = "readonly=\"readonly\"";
462
						?>
463
	                    <tr>
464
	                        <td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
465
	                        <td width="78%" class="vtable">
466
	                            <strong><?=strtoupper(htmlspecialchars($pconfig['utype']));?></strong>
467
								<input name="utype" type="hidden" value="<?=htmlspecialchars($pconfig['utype'])?>" />
468
	                        </td>
469
	                    </tr>
470
						<tr>
471
							<td width="22%" valign="top" class="vncell"><?=gettext("Disabled");?></td>
472
							<td width="78%" class="vtable">
473
								<input name="disabled" type="checkbox" id="disabled" <?php if($pconfig['disabled']) echo "checked=\"checked\""; ?> />
474
							</td>
475
						</tr>
476
						<tr>
477
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
478
							<td width="78%" class="vtable">
479
								<input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" <?=$ro;?> />
480
								<input name="oldusername" type="hidden" id="oldusername" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" />
481
							</td>
482
						</tr>
483
						<tr>
484
							<td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td>
485
							<td width="78%" class="vtable">
486
								<input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" value="" />
487
							</td>
488
						</tr>
489
						<tr>
490
							<td width="78%" class="vtable">
491
								<input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;<?= gettext("(confirmation)"); ?>
492
							</td>
493
						</tr>
494
						<tr>
495
							<td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td>
496
							<td width="78%" class="vtable">
497
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>" <?=$ro;?> />
498
								<br/>
499
								<?=gettext("User's full name, for your own information only");?>
500
							</td>
501
						</tr>
502
						<tr>
503
							<td width="22%" valign="top" class="vncell"><?=gettext("Expiration date"); ?></td>
504
							<td width="78%" class="vtable">
505
								<input name="expires" type="text" class="formfld unknown" id="expires" size="10" value="<?=htmlspecialchars($pconfig['expires']);?>" />
506
								<br/>
507
								<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></td>
508
						</tr>
509
						<tr>
510
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
511
							<td width="78%" class="vtable" align="center">
512
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="group membership">
513
									<tr>
514
										<td align="center" width="50%">
515
											<strong><?=gettext("Not Member Of"); ?></strong><br/>
516
											<br/>
517
											<select size="10" style="width: 75%" name="notgroups[]" class="formselect" id="notgroups" onchange="clear_selected('groups')" multiple="multiple">
518
												<?php
519
													foreach ($config['system']['group'] as $group):
520
														if ($group['gid'] == 1998) /* all users group */
521
															continue;
522
														if (is_array($pconfig['groups']) && in_array($group['name'],$pconfig['groups']))
523
															continue;
524
												?>
525
												<option value="<?=$group['name'];?>" <?=$selected;?>>
526
													<?=htmlspecialchars($group['name']);?>
527
												</option>
528
												<?php endforeach; ?>
529
											</select>
530
											<br/>
531
										</td>
532
										<td>
533
											<br/>
534
											<a href="javascript:move_selected('notgroups','groups')">
535
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Groups"); ?>" alt="<?=gettext("Add Groups"); ?>" width="17" height="17" border="0" />
536
											</a>
537
											<br/><br/>
538
											<a href="javascript:move_selected('groups','notgroups')">
539
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Groups"); ?>" alt="<?=gettext("Remove Groups"); ?>" width="17" height="17" border="0" />
540
											</a>
541
										</td>
542
										<td align="center" width="50%">
543
											<strong><?=gettext("Member Of"); ?></strong><br/>
544
											<br/>
545
											<select size="10" style="width: 75%" name="groups[]" class="formselect" id="groups" onchange="clear_selected('nogroups')" multiple="multiple">
546
												<?php
547
												if (is_array($pconfig['groups'])) {
548
													foreach ($config['system']['group'] as $group):
549
														if ($group['gid'] == 1998) /* all users group */
550
															continue;
551
														if (!in_array($group['name'],$pconfig['groups']))
552
															continue;
553
												?>
554
												<option value="<?=$group['name'];?>">
555
													<?=htmlspecialchars($group['name']);?>
556
												</option>
557
												<?php endforeach;
558
												} ?>
559
											</select>
560
											<br/>
561
										</td>
562
									</tr>
563
								</table>
564
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
565
							</td>
566
						</tr>
567

    
568
						<?php if (isset($pconfig['uid'])): ?>
569

    
570
						<tr>
571
							<td width="22%" valign="top" class="vncell"><?=gettext("Effective Privileges");?></td>
572
							<td width="78%" class="vtable">
573
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
574
									<tr>
575
										<td width="20%" class="listhdrr"><?=gettext("Inherited From");?></td>
576
										<td width="30%" class="listhdrr"><?=gettext("Name");?></td>
577
										<td width="40%" class="listhdrr"><?=gettext("Description");?></td>
578
										<td class="list"></td>
579
									</tr>
580
									<?php
581

    
582
										$privdesc = get_user_privdesc($a_user[$id]);
583
										if(is_array($privdesc)):
584
											$i = 0;
585
											foreach ($privdesc as $priv):
586
											$group = false;
587
											if ($priv['group'])
588
												$group = $priv['group'];
589
									?>
590
									<tr>
591
										<td class="listlr"><?=$group;?></td>
592
										<td class="listr">
593
											<?=htmlspecialchars($priv['name']);?>
594
										</td>
595
										<td class="listbg">
596
												<?=htmlspecialchars($priv['descr']);?>
597
										</td>
598
										<td valign="middle" class="list nowrap">
599
											<?php if (!$group): ?>
600
											<a href="system_usermanager.php?act=delpriv&amp;id=<?=$id?>&privid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this privilege?");?>')">
601
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
602
											</a>
603
											<?php endif; ?>
604
										</td>
605
									</tr>
606
									<?php
607
											/* can only delete user priv indexes */
608
											if (!$group)
609
												$i++;
610
											endforeach;
611
										endif;
612
									?>
613
									<tr>
614
										<td class="list" colspan="3"></td>
615
										<td class="list">
616
											<a href="system_usermanager_addprivs.php?userid=<?=$id?>">
617
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
618
											</a>
619
										</td>
620
									</tr>
621
								</table>
622
							</td>
623
						</tr>
624
						<tr>
625
							<td width="22%" valign="top" class="vncell"><?=gettext("User Certificates");?></td>
626
							<td width="78%" class="vtable">
627
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="certificates">
628
									<tr>
629
										<td width="45%" class="listhdrr"><?=gettext("Name");?></td>
630
										<td width="45%" class="listhdrr"><?=gettext("CA");?></td>
631
										<td class="list"></td>
632
									</tr>
633
									<?php
634

    
635
										$a_cert = $a_user[$id]['cert'];
636
										if(is_array($a_cert)):
637
											$i = 0;
638
											foreach ($a_cert as $certref):
639
												$cert = lookup_cert($certref);
640
												$ca = lookup_ca($cert['caref']);
641
									?>
642
									<tr>
643
										<td class="listlr">
644
											<?=htmlspecialchars($cert['descr']);?>
645
											<?php if (is_cert_revoked($cert)): ?>
646
											(<b>Revoked</b>)
647
											<?php endif; ?>
648
										</td>
649
										<td class="listr">
650
											<?=htmlspecialchars($ca['descr']);?>
651
										</td>
652
										<td valign="middle" class="list nowrap">
653
											<a href="system_usermanager.php?act=expckey&id=<?=$id;?>&amp;certid=<?=$i;?>">
654
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export private key"); ?>" alt="<?=gettext("export private key"); ?>" width="17" height="17" border="0" />
655
											</a>
656
											<a href="system_usermanager.php?act=expcert&id=<?=$id;?>&amp;certid=<?=$i;?>">
657
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert"); ?>" alt="<?=gettext("export cert"); ?>" width="17" height="17" border="0" />
658
											</a>
659
											<a href="system_usermanager.php?act=delcert&id=<?=$id?>&amp;certid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to remove this certificate association?") .'\n'. gettext("(Certificate will not be deleted)");?>')">
660
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="<?=gettext("delete cert");?>" />
661
											</a>
662
										</td>
663
									</tr>
664
									<?php
665
												$i++;
666
											endforeach;
667
										endif;
668
									?>
669
									<tr>
670
										<td class="list" colspan="2"></td>
671
										<td class="list">
672
											<a href="system_certmanager.php?act=new&amp;userid=<?=$id?>">
673
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
674
											</a>
675
										</td>
676
									</tr>
677
								</table>
678
							</td>
679
						</tr>
680

    
681
						<?php else : ?>
682
						<?php 	if (is_array($config['ca']) && count($config['ca']) > 0): ?>
683
						<?php		$i = 0; foreach( $config['ca'] as $ca) {
684
                                                                        	if (!$ca['prv'])
685
                                                                                	continue;
686
										$i++;
687
									}
688
						?>
689

    
690
						<tr id="usercertchck">
691
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
692
                                                	<td width="78%" class="vtable">
693
							<input type="checkbox" onclick="javascript:usercertClicked(this)" /> <?=gettext("Click to create a user certificate."); ?>
694
							</td>
695
						</tr>
696

    
697
						<?php		if ($i > 0): ?>
698

    
699
						<tr id="usercert" name="usercert" style="display:none">
700
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
701
                                                	<td width="78%" class="vtable">
702
							<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="certificate">
703
							<tr>
704
                                                        	<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
705
                                                        	<td width="78%" class="vtable">
706
									<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
707
                                                        	</td>
708
                                                	</tr>
709
                                                	<tr>
710
                                                        	<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
711
                                                        	<td width="78%" class="vtable">
712
                                                                	<select name='caref' id='caref' class="formselect" onchange='internalca_change()'>
713
                                                                <?php
714
                                                                        foreach( $config['ca'] as $ca):
715
                                                                        if (!$ca['prv'])
716
                                                                                continue;
717
                                                                ?>
718
                                                                        <option value="<?=$ca['refid'];?>"><?=$ca['descr'];?></option>
719
                                                                <?php endforeach; ?>
720
                                                                	</select>
721
                                                        	</td>
722
                                                	</tr>
723
                                                	<tr>
724
                                                        	<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
725
                                                        	<td width="78%" class="vtable">
726
                                                                	<select name='keylen' class="formselect">
727
                                                                <?php
728
									$cert_keylens = array( "2048", "512", "1024", "4096");
729
                                                                        foreach( $cert_keylens as $len):
730
                                                                ?>
731
                                                                        <option value="<?=$len;?>"><?=$len;?></option>
732
                                                                <?php endforeach; ?>
733
                                                                	</select>
734
                                                                	bits
735
                                                        	</td>
736
                                                	</tr>
737
							<tr>
738
                                                        	<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
739
                                                        	<td width="78%" class="vtable">
740
                                                                	<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />days
741
                                                        	</td>
742
                                                	</tr>
743
						</table>
744
							</td>
745
						</tr>
746

    
747
						<?php 	endif; endif; ?>
748
						<?php endif; ?>
749

    
750
						<tr id="sshkeychck" <?php if(!empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
751
                                                        <td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
752
                                                        <td width="78%" class="vtable">
753
                                                        <input type="checkbox" onclick="javascript:sshkeyClicked(this)" /> <?=gettext("Click to paste an authorized key."); ?>
754
                                                        </td>
755
                                                </tr>
756
						<tr id="sshkey" <?php if(empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
757
							<td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
758
							<td width="78%" class="vtable">
759
								<textarea name="authorizedkeys" cols="65" rows="7" id="authorizedkeys" class="formfld_cert" wrap="off"><?=htmlspecialchars($pconfig['authorizedkeys']);?></textarea>
760
								<br/>
761
								<?=gettext("Paste an authorized keys file here.");?>
762
							</td>
763
						</tr>
764
						<tr id="ipsecpskrow">
765
							<td width="22%" valign="top" class="vncell"><?=gettext("IPsec Pre-Shared Key");?></td>
766
							<td width="78%" class="vtable">
767
								<input name="ipsecpsk" type="text" class="formfld unknown" id="ipsecpsk" size="65" value="<?=htmlspecialchars($pconfig['ipsecpsk']);?>" />
768
							</td>
769
						</tr>
770
						<tr>
771
							<td width="22%" valign="top">&nbsp;</td>
772
							<td width="78%">
773
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
774
								<?php if (isset($id) && $a_user[$id]): ?>
775
								<input name="id" type="hidden" value="<?=$id;?>" />
776
								<?php endif;?>
777
							</td>
778
						</tr>
779
					</table>
780
				</form>
781

    
782
				<?php else: ?>
783

    
784
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
785
					<thead>
786
						<tr>
787
							<th width="25%" class="listhdrr"><?=gettext("Username"); ?></th>
788
							<th width="25%" class="listhdrr"><?=gettext("Full name"); ?></th>
789
							<th width="5%" class="listhdrr"><?=gettext("Disabled"); ?></th>
790
							<th width="25%" class="listhdrr"><?=gettext("Groups"); ?></th>
791
							<th width="10%" class="list"></th>
792
						</tr>
793
					</thead>
794
					<tfoot>
795
						<tr>
796
							<td class="list" colspan="4"></td>
797
							<td class="list">
798
								<a href="system_usermanager.php?act=new">
799
									<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add user"); ?>" alt="<?=gettext("add user"); ?>" width="17" height="17" border="0" />
800
								</a>
801
							</td>
802
						</tr>
803
						<tr>
804
							<td colspan="4">
805
								<p>
806
									<?=gettext("Additional users can be added here. User permissions for accessing " .
807
									"the webConfigurator can be assigned directly or inherited from group memberships. " .
808
									"An icon that appears grey indicates that it is a system defined object. " .
809
									"Some system object properties can be modified but they cannot be deleted."); ?>
810
									<br/><br/>
811
									<?=gettext("Accounts created here are also used for other parts of the system " .
812
									"such as OpenVPN, IPsec, and Captive Portal.");?>
813
								</p>
814
							</td>
815
						</tr>
816
					</tfoot>
817
					<tbody>
818
						<?php
819
							$i = 0;
820
							foreach($a_user as $userent):
821
						?>
822
						<tr ondblclick="document.location='system_usermanager.php?act=edit&amp;id=<?=$i;?>'">
823
							<td class="listlr">
824
								<table border="0" cellpadding="0" cellspacing="0" summary="icons">
825
									<tr>
826
										<td align="left" valign="middle">
827
											<?php
828
												if($userent['scope'] != "user")
829
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user-grey.png";
830
												else
831
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user.png";
832
											?>
833
											<img src="<?=$usrimg;?>" alt="<?=gettext("User"); ?>" title="<?=gettext("User"); ?>" border="0" height="16" width="16" />
834
										</td>
835
										<td align="left" valign="middle">
836
											<?=htmlspecialchars($userent['name']);?>
837
										</td>
838
									</tr>
839
								</table>
840
							</td>
841
							<td class="listr"><?=htmlspecialchars($userent['descr']);?>&nbsp;</td>
842
							<td class="listr"><?php if(isset($userent['disabled'])) echo "*"; ?></td>
843
							<td class="listbg">
844
									<?=implode(",",local_user_get_groups($userent));?>
845
								&nbsp;
846
							</td>
847
							<td valign="middle" class="list nowrap">
848
								<a href="system_usermanager.php?act=edit&amp;id=<?=$i;?>">
849
									<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit user"); ?>" alt="<?=gettext("edit user"); ?>" width="17" height="17" border="0" />
850
								</a>
851
								<?php if($userent['scope'] != "system"): ?>
852
								&nbsp;
853
								<a href="system_usermanager.php?act=deluser&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this User?");?>')">
854
									<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete user"); ?>" alt="<?=gettext("delete user"); ?>" width="17" height="17" border="0" />
855
								</a>
856
								<?php endif; ?>
857
							</td>
858
						</tr>
859
						<?php
860
								$i++;
861
							endforeach;
862
						?>
863
					</tbody>
864
				</table>
865

    
866
				<?php endif; ?>
867

    
868
			</div>
869
		</td>
870
	</tr>
871
</table>
872
<?php include("fend.inc");?>
873
</body>
874
</html>
875

    
(220-220/246)