Projet

Général

Profil

Télécharger (33,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_usermanager.php @ 1a6769a6

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
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
57
	$id = $_POST['userid'];
58

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

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

    
64
if (isset($_SERVER['HTTP_REFERER']))
65
	$referer = $_SERVER['HTTP_REFERER'];
66
else
67
	$referer = '/system_usermanager.php';
68

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

    
82
if ($_POST['act'] == "deluser") {
83

    
84
	if (!$a_user[$id]) {
85
		pfSenseHeader("system_usermanager.php");
86
		exit;
87
	}
88

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

    
100
	if (!$a_user[$id]) {
101
		pfSenseHeader("system_usermanager.php");
102
		exit;
103
	}
104

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

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

    
120
	$cert =& lookup_cert($a_user[$id]['cert'][$_POST['certid']]);
121

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

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

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

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

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

    
145
	header("Content-Type: application/octet-stream");
146
	header("Content-Disposition: attachment; filename={$exp_name}");
147
	header("Content-Length: $exp_size");
148
	echo $exp_data;
149
	exit;
150
}
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} ".
164
				gettext("association removed.")."<br />";
165
}
166
else if ($_POST['act'] == "new") {
167
	/*
168
	 * set this value cause the text field is read only
169
	 * and the user should not be able to mess with this
170
	 * setting.
171
	 */
172
	$pconfig['utype'] = "user";
173
	$pconfig['lifetime'] = 3650;
174
}
175

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

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

    
202
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
203

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

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

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

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

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

    
256
	if (!empty($_POST['name'])) {
257
		$ca = lookup_ca($_POST['caref']);
258
		if (!$ca)
259
			$input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
260
	}
261

    
262
	/* if this is an AJAX caller then handle via JSON */
263
	if (isAjax() && is_array($input_errors)) {
264
		input_errors2Ajax($input_errors);
265
		exit;
266
	}
267

    
268
	if (!$input_errors) {
269
		conf_mount_rw();
270
		$userent = array();
271
		if (isset($id) && $a_user[$id])
272
			$userent = $a_user[$id];
273

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

    
276
		/* the user name was modified */
277
		if ($_POST['usernamefld'] <> $_POST['oldusername']) {
278
			$_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
279
			local_user_del($userent);
280
		}
281

    
282
		/* the user password was mofified */
283
		if ($_POST['passwordfld1'])
284
			local_user_set_password($userent, $_POST['passwordfld1']);
285

    
286
		$userent['name'] = $_POST['usernamefld'];
287
		$userent['descr'] = $_POST['descr'];
288
		$userent['expires'] = $_POST['expires'];
289
		$userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
290
		$userent['ipsecpsk'] = $_POST['ipsecpsk'];
291

    
292
		if($_POST['disabled'])
293
			$userent['disabled'] = true;
294
		else
295
			unset($userent['disabled']);
296

    
297
		if (isset($id) && $a_user[$id])
298
			$a_user[$id] = $userent;
299
		else {
300
			if (!empty($_POST['name'])) {
301
				$cert = array();
302
				$cert['refid'] = uniqid();
303
				$userent['cert'] = array();
304

    
305
				$cert['descr'] = $_POST['name'];
306

    
307
				$subject = cert_get_subject_array($ca['crt']);
308

    
309
				$dn = array(
310
					'countryName' => $subject[0]['v'],
311
					'stateOrProvinceName' => $subject[1]['v'],
312
					'localityName' => $subject[2]['v'],
313
					'organizationName' => $subject[3]['v'],
314
					'emailAddress' => $subject[4]['v'],
315
					'commonName' => $userent['name']);
316

    
317
				cert_create($cert, $_POST['caref'], $_POST['keylen'],
318
					(int)$_POST['lifetime'], $dn);
319

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

    
336
			$a_user[] = $userent;
337
		}
338

    
339
		local_user_set_groups($userent,$_POST['groups']);
340
		local_user_set($userent);
341
		write_config();
342

    
343
		if(is_dir("/etc/inc/privhooks"))
344
			run_plugins("/etc/inc/privhooks");
345

    
346
		conf_mount_ro();
347

    
348
		pfSenseHeader("system_usermanager.php");
349
	}
350
}
351

    
352
$closehead = false;
353
include("head.inc");
354
?>
355

    
356
<link rel="stylesheet" type="text/css" href="/javascript/jquery-ui-timepicker-addon/css/jquery-ui-timepicker-addon.css" />
357
<link rel="stylesheet" type="text/css" href="/javascript/jquery/jquery-ui.custom.css" />
358

    
359
<script type="text/javascript">
360
//<![CDATA[
361
	jQuery(function() {
362
		jQuery( "#expires" ).datepicker( { dateFormat: 'mm/dd/yy', changeYear: true, yearRange: "+0:+100" } );
363
	});
364
//]]>
365
</script>
366
</head>
367

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

    
371
<script type="text/javascript">
372
//<![CDATA[
373

    
374
function setall_selected(id) {
375
	selbox = document.getElementById(id);
376
	count = selbox.options.length;
377
	for (index = 0; index<count; index++)
378
		selbox.options[index].selected = true;
379
}
380

    
381
function clear_selected(id) {
382
	selbox = document.getElementById(id);
383
	count = selbox.options.length;
384
	for (index = 0; index<count; index++)
385
		selbox.options[index].selected = false;
386
}
387

    
388
function remove_selected(id) {
389
	selbox = document.getElementById(id);
390
	index = selbox.options.length - 1;
391
	for (; index >= 0; index--)
392
		if (selbox.options[index].selected)
393
			selbox.remove(index);
394
}
395

    
396
function copy_selected(srcid, dstid) {
397
	src_selbox = document.getElementById(srcid);
398
	dst_selbox = document.getElementById(dstid);
399
	count = dst_selbox.options.length;
400
	for (index = count - 1; index >= 0; index--) {
401
		if (dst_selbox.options[index].value == '') {
402
			dst_selbox.remove(index);
403
		}
404
	}
405
	count = src_selbox.options.length;
406
	for (index = 0; index < count; index++) {
407
		if (src_selbox.options[index].selected) {
408
			option = document.createElement('option');
409
			option.text = src_selbox.options[index].text;
410
			option.value = src_selbox.options[index].value;
411
			dst_selbox.add(option, null);
412
		}
413
	}
414
}
415

    
416
function move_selected(srcid, dstid) {
417
	copy_selected(srcid, dstid);
418
	remove_selected(srcid);
419
}
420

    
421
function presubmit() {
422
	clear_selected('notgroups');
423
	setall_selected('groups');
424
}
425

    
426
function usercertClicked(obj) {
427
	if (obj.checked) {
428
		document.getElementById("usercertchck").style.display="none";
429
		document.getElementById("usercert").style.display="";
430
	} else {
431
		document.getElementById("usercert").style.display="none";
432
		document.getElementById("usercertchck").style.display="";
433
	}
434
}
435

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

    
733
<?php
734
					else:
735
						if (is_array($config['ca']) && count($config['ca']) > 0):
736
							$i = 0;
737
							foreach( $config['ca'] as $ca) {
738
								if (!$ca['prv'])
739
									continue;
740
								$i++;
741
							}
742
?>
743

    
744
						<tr id="usercertchck">
745
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
746
							<td width="78%" class="vtable">
747
							<input type="checkbox" onclick="javascript:usercertClicked(this)" /> <?=gettext("Click to create a user certificate."); ?>
748
							</td>
749
						</tr>
750

    
751
<?php
752
							if ($i > 0):
753
?>
754
						<tr id="usercert" style="display:none">
755
							<td width="22%" valign="top" class="vncell"><?=gettext("Certificate");?></td>
756
							<td width="78%" class="vtable">
757
								<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="certificate">
758
									<tr>
759
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
760
										<td width="78%" class="vtable">
761
											<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
762
										</td>
763
									</tr>
764
									<tr>
765
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
766
										<td width="78%" class="vtable">
767
											<select name='caref' id='caref' class="formselect" onchange='internalca_change()'>
768
<?php
769
											$rowIndex = 0;
770
											foreach( $config['ca'] as $ca):
771
												if (!$ca['prv'])
772
													continue;
773
												$rowIndex++;
774
?>
775
												<option value="<?=$ca['refid'];?>"><?=$ca['descr'];?></option>
776
<?php
777
											endforeach;
778
											if ($rowIndex == 0)
779
												echo "<option></option>";
780
?>
781
											</select>
782
										</td>
783
									</tr>
784
									<tr>
785
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
786
										<td width="78%" class="vtable">
787
											<select name='keylen' class="formselect">
788
<?php
789
											$cert_keylens = array( "2048", "512", "1024", "4096");
790
											foreach( $cert_keylens as $len):
791
?>
792
												<option value="<?=$len;?>"><?=$len;?></option>
793
<?php
794
											endforeach;
795
											if (!count($cert_keylens))
796
												echo "<option></option>";
797
?>
798
											</select>
799
											bits
800
										</td>
801
									</tr>
802
									<tr>
803
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
804
										<td width="78%" class="vtable">
805
											<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>" />days
806
										</td>
807
									</tr>
808
								</table>
809
							</td>
810
						</tr>
811
<?php
812
							endif;
813
						endif;
814
					endif;
815
?>
816
						<tr id="sshkeychck" <?php if(!empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
817
							<td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
818
							<td width="78%" class="vtable">
819
								<input type="checkbox" onclick="javascript:sshkeyClicked(this)" /> <?=gettext("Click to paste an authorized key."); ?>
820
							</td>
821
						</tr>
822
						<tr id="sshkey" <?php if(empty($pconfig['authorizedkeys'])) echo 'style="display:none"'; ?>>
823
							<td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
824
							<td width="78%" class="vtable">
825
								<script type="text/javascript">
826
								//<![CDATA[
827
								window.onload=function(){
828
									document.getElementById("authorizedkeys").wrap='off';
829
								}
830
								//]]>
831
								</script>
832
								<textarea name="authorizedkeys" cols="65" rows="7" id="authorizedkeys" class="formfld_cert"><?=htmlspecialchars($pconfig['authorizedkeys']);?></textarea>
833
								<br />
834
								<?=gettext("Paste an authorized keys file here.");?>
835
							</td>
836
						</tr>
837
						<tr id="ipsecpskrow">
838
							<td width="22%" valign="top" class="vncell"><?=gettext("IPsec Pre-Shared Key");?></td>
839
							<td width="78%" class="vtable">
840
								<input name="ipsecpsk" type="text" class="formfld unknown" id="ipsecpsk" size="65" value="<?=htmlspecialchars($pconfig['ipsecpsk']);?>" />
841
							</td>
842
						</tr>
843
						<tr>
844
							<td width="22%" valign="top">&nbsp;</td>
845
							<td width="78%">
846
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
847
								<input type="button" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
848
								<?php if (isset($id) && $a_user[$id]): ?>
849
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
850
								<?php endif;?>
851
							</td>
852
						</tr>
853
					</table>
854
				</form>
855
<?php
856
			else:
857
?>
858
				<form action="system_usermanager.php" method="post" name="iform2" id="iform2">
859
					<input type="hidden" id="act" name="act" value="" />
860
					<input type="hidden" id="userid" name="userid" value="<?=(isset($id) ? $id : '');?>" />
861
					<input type="hidden" id="privid" name="privid" value="" />
862
					<input type="hidden" id="certid" name="certid" value="" />
863
					<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
864
						<thead>
865
							<tr>
866
								<th width="25%" class="listhdrr"><?=gettext("Username"); ?></th>
867
								<th width="25%" class="listhdrr"><?=gettext("Full name"); ?></th>
868
								<th width="5%" class="listhdrr"><?=gettext("Disabled"); ?></th>
869
								<th width="25%" class="listhdrr"><?=gettext("Groups"); ?></th>
870
								<th width="10%" class="list"></th>
871
							</tr>
872
						</thead>
873
						<tfoot>
874
							<tr>
875
								<td class="list" colspan="4"></td>
876
								<td class="list">
877
									<input type="image" name="addcert" width="17" height="17" border="0"
878
										src="/themes/<?=$g['theme'];?>/images/icons/icon_plus.gif"
879
										onclick="document.getElementById('act').value='<?php echo "new";?>';"
880
										title="<?=gettext("add user");?>" />
881
								</td>
882
							</tr>
883
							<tr>
884
								<td colspan="4">
885
									<p>
886
										<?=gettext("Additional users can be added here. User permissions for accessing " .
887
										"the webConfigurator can be assigned directly or inherited from group memberships. " .
888
										"An icon that appears grey indicates that it is a system defined object. " .
889
										"Some system object properties can be modified but they cannot be deleted."); ?>
890
										<br /><br />
891
										<?=gettext("Accounts created here are also used for other parts of the system " .
892
										"such as OpenVPN, IPsec, and Captive Portal.");?>
893
									</p>
894
								</td>
895
							</tr>
896
						</tfoot>
897
						<tbody>
898
<?php
899
						$i = 0;
900
						foreach($a_user as $userent):
901
?>
902
								<tr ondblclick="document.getElementById('act').value='<?php echo "edit";?>';
903
									document.getElementById('userid').value='<?=$i;?>';
904
									document.iform2.submit();">
905
								<td class="listlr">
906
									<table border="0" cellpadding="0" cellspacing="0" summary="icons">
907
										<tr>
908
											<td align="left" valign="middle">
909
<?php
910
												if($userent['scope'] != "user")
911
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user-grey.png";
912
												else
913
													$usrimg = "/themes/{$g['theme']}/images/icons/icon_system-user.png";
914
?>
915
												<img src="<?=$usrimg;?>" alt="<?=gettext("User"); ?>" title="<?=gettext("User"); ?>" border="0" height="16" width="16" />
916
											</td>
917
											<td align="left" valign="middle">
918
												<?=htmlspecialchars($userent['name']);?>
919
											</td>
920
										</tr>
921
									</table>
922
								</td>
923
								<td class="listr"><?=htmlspecialchars($userent['descr']);?>&nbsp;</td>
924
								<td class="listr"><?php if(isset($userent['disabled'])) echo "*"; ?></td>
925
								<td class="listbg">
926
									<?=implode(",",local_user_get_groups($userent));?>
927
									&nbsp;
928
								</td>
929
								<td valign="middle" class="list nowrap">
930
									<input type="image" name="edituser[]" width="17" height="17" border="0"
931
										src="/themes/<?=$g['theme'];?>/images/icons/icon_e.gif"
932
										onclick="document.getElementById('userid').value='<?=$i;?>';
933
											document.getElementById('act').value='<?php echo "edit";?>';"
934
										title="<?=gettext("edit user");?>" />
935
<?php
936
								if($userent['scope'] != "system"):
937
?>
938
									&nbsp;
939
									<input type="image" name="deluser[]" width="17" height="17" border="0"
940
										src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
941
										onclick="document.getElementById('userid').value='<?=$i;?>';
942
											document.getElementById('act').value='<?php echo "deluser";?>';
943
											return confirm('<?=gettext("Do you really want to delete this user?");?>');"
944
										title="<?=gettext("delete user");?>" />
945
<?php
946
								endif;
947
?>
948
								</td>
949
							</tr>
950
<?php
951
							$i++;
952
						endforeach;
953
?>
954
						</tbody>
955
					</table>
956
				</form>
957
<?php
958
			endif;
959
?>
960
			</div>
961
		</td>
962
	</tr>
963
</table>
964
<?php include("fend.inc");?>
965
</body>
966
</html>
(229-229/256)