Projet

Général

Profil

Télécharger (17,9 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_groupmanager.php @ 7ea27b0d

1
<?php
2
/*
3
	$Id: system_groupmanager.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

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

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

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

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

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

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

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

    
40
##|+PRIV
41
##|*IDENT=page-system-groupmanager
42
##|*NAME=System: Group manager page
43
##|*DESCR=Allow access to the 'System: Group manager' page.
44
##|*MATCH=system_groupmanager.php*
45
##|-PRIV
46

    
47
require("guiconfig.inc");
48

    
49
$pgtitle = array(gettext("System"), gettext("Group manager"));
50

    
51
if (!is_array($config['system']['group']))
52
	$config['system']['group'] = array();
53

    
54
$a_group = &$config['system']['group'];
55

    
56
unset($id);
57
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
58
	$id = $_POST['groupid'];
59

    
60
$act = (isset($_POST['act']) ? $_POST['act'] : '');
61

    
62
if ($act == "delgroup") {
63

    
64
	if (!isset($id) || !isset($_POST['groupname']) || !isset($a_group[$id]) || ($_POST['groupname'] != $a_group[$id]['name'])) {
65
		pfSenseHeader("system_groupmanager.php");
66
		exit;
67
	}
68

    
69
	conf_mount_rw();
70
	local_group_del($a_group[$id]);
71
	conf_mount_ro();
72
	$groupdeleted = $a_group[$id]['name'];
73
	unset($a_group[$id]);
74
	write_config();
75
	$savemsg = gettext("Group")." {$groupdeleted} ".
76
		gettext("successfully deleted")."<br />";
77
}
78

    
79
if ($act == "delpriv") {
80

    
81
	if (!isset($id) || !isset($a_group[$id])) {
82
		pfSenseHeader("system_groupmanager.php");
83
		exit;
84
	}
85

    
86
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_POST['privid']]]['name'];
87
	unset($a_group[$id]['priv'][$_POST['privid']]);
88

    
89
	if (is_array($a_group[$id]['member'])) {
90
		foreach ($a_group[$id]['member'] as $uid) {
91
			$user = getUserEntryByUID($uid);
92
			if ($user)
93
				local_user_set($user);
94
		}
95
	}
96

    
97
	write_config();
98
	$act = "edit";
99
	$savemsg = gettext("Privilege")." {$privdeleted} ".
100
				gettext("successfully deleted")."<br />";
101
}
102

    
103
if ($act == "edit") {
104
	if (isset($id) && isset($a_group[$id])) {
105
		$pconfig['name'] = $a_group[$id]['name'];
106
		$pconfig['gid'] = $a_group[$id]['gid'];
107
		$pconfig['gtype'] = $a_group[$id]['scope'];
108
		$pconfig['description'] = $a_group[$id]['description'];
109
		$pconfig['members'] = $a_group[$id]['member'];
110
		$pconfig['priv'] = $a_group[$id]['priv'];
111
	}
112
}
113

    
114
if (isset($_POST['save'])) {
115

    
116
	unset($input_errors);
117
	$pconfig = $_POST;
118

    
119
	/* input validation */
120
	$reqdfields = explode(" ", "groupname");
121
	$reqdfieldsn = array(gettext("Group Name"));
122

    
123
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
124

    
125
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
126
		$input_errors[] = gettext("The group name contains invalid characters.");
127

    
128
	if (strlen($_POST['groupname']) > 16)
129
		$input_errors[] = gettext("The group name is longer than 16 characters.");
130

    
131
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
132
		/* make sure there are no dupes */
133
		foreach ($a_group as $group) {
134
			if ($group['name'] == $_POST['groupname']) {
135
				$input_errors[] = gettext("Another entry with the same group name already exists.");
136
				break;
137
			}
138
		}
139
	}
140

    
141
	if (!$input_errors) {
142
		$group = array();
143
		if (isset($id) && $a_group[$id])
144
			$group = $a_group[$id];
145

    
146
		$group['name'] = $_POST['groupname'];
147
		$group['description'] = $_POST['description'];
148

    
149
		if (empty($_POST['members']))
150
			unset($group['member']);
151
		else if ($group['gid'] != 1998) // all group
152
			$group['member'] = $_POST['members'];
153

    
154
		if (isset($id) && $a_group[$id])
155
			$a_group[$id] = $group;
156
		else {
157
			$group['gid'] = $config['system']['nextgid']++;
158
			$a_group[] = $group;
159
		}
160

    
161
		conf_mount_rw();
162
		local_group_set($group);
163
		conf_mount_ro();
164

    
165
		/* Refresh users in this group since their privileges may have changed. */
166
		if (is_array($group['member'])) {
167
			$a_user = &$config['system']['user'];
168
			foreach ($a_user as & $user) {
169
				if (in_array($user['uid'], $group['member']))
170
					local_user_set($user);
171
			}
172
		}
173

    
174
		write_config();
175

    
176
		header("Location: system_groupmanager.php");
177
		exit;
178
	}
179
}
180

    
181
include("head.inc");
182

    
183
?>
184

    
185
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
186
<?php include("fbegin.inc"); ?>
187
<script type="text/javascript">
188
//<![CDATA[
189

    
190
function setall_selected(id) {
191
	selbox = document.getElementById(id);
192
	count = selbox.options.length;
193
	for (index = 0; index<count; index++)
194
		selbox.options[index].selected = true;
195
}
196

    
197
function clear_selected(id) {
198
	selbox = document.getElementById(id);
199
	count = selbox.options.length;
200
	for (index = 0; index<count; index++)
201
		selbox.options[index].selected = false;
202
}
203

    
204
function remove_selected(id) {
205
	selbox = document.getElementById(id);
206
	index = selbox.options.length - 1;
207
	for (; index >= 0; index--)
208
		if (selbox.options[index].selected)
209
			selbox.remove(index);
210
}
211

    
212
function copy_selected(srcid, dstid) {
213
	src_selbox = document.getElementById(srcid);
214
	dst_selbox = document.getElementById(dstid);
215
	count = dst_selbox.options.length;
216
	for (index = count - 1; index >= 0; index--) {
217
		if (dst_selbox.options[index].value == '') {
218
			dst_selbox.remove(index);
219
		}
220
	}
221
	count = src_selbox.options.length;
222
	for (index = 0; index < count; index++) {
223
		if (src_selbox.options[index].selected) {
224
			option = document.createElement('option');
225
			option.text = src_selbox.options[index].text;
226
			option.value = src_selbox.options[index].value;
227
			dst_selbox.add(option, null);
228
		}
229
	}
230
}
231

    
232
function move_selected(srcid, dstid) {
233
	copy_selected(srcid, dstid);
234
	remove_selected(srcid);
235
}
236

    
237
function presubmit() {
238
	clear_selected('notmembers');
239
	setall_selected('members');
240
}
241

    
242
//]]>
243
</script>
244
<?php
245
	if ($input_errors)
246
		print_input_errors($input_errors);
247
	if ($savemsg)
248
		print_info_box($savemsg);
249
?>
250
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager">
251
	<tr>
252
		<td>
253
<?php
254
			$tab_array = array();
255
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
256
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
257
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
258
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
259
			display_top_tabs($tab_array);
260
?>
261
		</td>
262
	</tr>
263
	<tr>
264
		<td id="mainarea">
265
			<div class="tabcont">
266

    
267
<?php
268
			if($act == "new" || $act == "edit"):
269
?>
270
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
271
					<input type="hidden" id="act" name="act" value="" />
272
					<input type="hidden" id="groupid" name="groupid" value="<?=(isset($id) ? $id : '');?>" />
273
					<input type="hidden" id="privid" name="privid" value="" />
274
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
275
<?php
276
						$ro = "";
277
						if ($pconfig['gtype'] == "system")
278
							$ro = "readonly=\"readonly\"";
279
?>
280
						<tr>
281
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
282
							<td width="78%" class="vtable">
283
								<strong><?=strtoupper($pconfig['gtype']);?></strong>
284
								<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
285
							</td>
286
						</tr>
287
						<tr>
288
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
289
							<td width="78%" class="vtable">
290
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?> />
291
							</td>
292
						</tr>
293
						<tr>
294
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
295
							<td width="78%" class="vtable">
296
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>" />
297
								<br />
298
								<?=gettext("Group description, for your own information only");?>
299
							</td>
300
						</tr>
301
<?php
302
					if ($pconfig['gid'] != 1998): // all users group
303
?>
304
						<tr>
305
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
306
							<td width="78%" class="vtable" align="center">
307
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="membership">
308
									<tr>
309
										<td align="center" width="50%">
310
											<strong><?=gettext("Not Members");?></strong><br />
311
											<br />
312
												<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple">
313
<?php
314
											$rowIndex = 0;
315
											foreach ($config['system']['user'] as $user):
316
												if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))
317
													continue;
318
												$rowIndex++;
319
?>
320
												<option value="<?=$user['uid'];?>" <?=$selected;?>>
321
													<?=htmlspecialchars($user['name']);?>
322
												</option>
323
<?php
324
											endforeach;
325
											if ($rowIndex == 0)
326
												echo "<option></option>";
327
?>
328
											</select>
329
											<br />
330
										</td>
331
										<td>
332
											<br />
333
											<a href="javascript:move_selected('notmembers','members')">
334
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" />
335
											</a>
336
											<br /><br />
337
											<a href="javascript:move_selected('members','notmembers')">
338
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
339
											</a>
340
										</td>
341
										<td align="center" width="50%">
342
											<strong><?=gettext("Members");?></strong><br />
343
											<br />
344
											<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onchange="clear_selected('notmembers')" multiple="multiple">
345
<?php
346
											$rowIndex = 0;
347
											foreach ($config['system']['user'] as $user):
348
												if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])))
349
													continue;
350
												$rowIndex++;
351
?>
352
												<option value="<?=$user['uid'];?>">
353
													<?=htmlspecialchars($user['name']);?>
354
												</option>
355
<?php
356
											endforeach;
357
											if ($rowIndex == 0)
358
												echo "<option></option>";
359
?>
360
											</select>
361
											<br />
362
										</td>
363
									</tr>
364
								</table>
365
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
366
							</td>
367
						</tr>
368
<?php
369
					endif;
370
					if ($act != "new"):
371
?>
372
						<tr>
373
							<td width="22%" valign="top" class="vncell"><?=gettext("Assigned Privileges");?></td>
374
							<td width="78%" class="vtable">
375
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
376
									<tr>
377
										<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
378
										<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
379
										<td class="list"></td>
380
									</tr>
381
<?php
382
							if(is_array($pconfig['priv'])):
383
								$i = 0;
384
								foreach ($pconfig['priv'] as $priv):
385
?>
386
									<tr>
387
										<td class="listr">
388
											<?=htmlspecialchars($priv_list[$priv]['name']);?>
389
										</td>
390
										<td class="listbg">
391
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
392
										</td>
393
										<td valign="middle" class="list nowrap">
394
											<input type="image" name="delpriv[]" width="17" height="17" border="0"
395
												src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
396
												onclick="document.getElementById('privid').value='<?=$i;?>';
397
													document.getElementById('groupid').value='<?=$id;?>';
398
													document.getElementById('act').value='<?php echo "delpriv";?>';
399
													return confirm('<?=gettext("Do you really want to delete this privilege?");?>');"
400
												title="<?=gettext("delete privilege");?>" />
401
										</td>
402
									</tr>
403
<?php
404
									$i++;
405
								endforeach;
406
							endif;
407
?>
408
									<tr>
409
										<td class="list" colspan="2"></td>
410
										<td class="list">
411
											<a href="system_groupmanager_addprivs.php?groupid=<?=htmlspecialchars($id)?>">
412
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
413
											</a>
414

    
415
										</td>
416
									</tr>
417

    
418
								</table>
419
							</td>
420
						</tr>
421
<?php
422
					endif;
423
?>
424
						<tr>
425
							<td width="22%" valign="top">&nbsp;</td>
426
							<td width="78%">
427
								<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
428
								<input type="button" value="<?=gettext("Cancel");?>" onclick="window.location.href='/system_groupmanager.php'" />
429
								<?php if (isset($id) && $a_group[$id]): ?>
430
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
431
								<input name="gid" type="hidden" value="<?=htmlspecialchars($pconfig['gid']);?>" />
432
								<?php endif; ?>
433
							</td>
434
						</tr>
435
					</table>
436
				</form>
437
<?php
438
			else:
439
?>
440
				<form action="system_groupmanager.php" method="post" name="iform2" id="iform2">
441
					<input type="hidden" id="act" name="act" value="" />
442
					<input type="hidden" id="groupid" name="groupid" value="<?=(isset($id) ? $id : '');?>" />
443
					<input type="hidden" id="groupname" name="groupname" value="" />
444
					<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
445
						<thead>
446
							<tr>
447
								<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
448
								<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
449
								<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
450
								<th width="10%" class="list"></th>
451
							</tr>
452
						</thead>
453
						<tfoot>
454
							<tr>
455
								<td class="list" colspan="3"></td>
456
								<td class="list">
457
									<input type="image" name="addcert" width="17" height="17" border="0"
458
										src="/themes/<?=$g['theme'];?>/images/icons/icon_plus.gif"
459
										onclick="document.getElementById('act').value='<?php echo "new";?>';"
460
										title="<?=gettext("add group");?>" />
461
								</td>
462
							</tr>
463
							<tr>
464
								<td colspan="3">
465
									<p>
466
										<?=gettext("Additional webConfigurator groups can be added here.
467
										Group permissions can be assigned which are inherited by users who are members of the group.
468
										An icon that appears grey indicates that it is a system defined object.
469
										Some system object properties can be modified but they cannot be deleted.");?>
470
									</p>
471
								</td>
472
							</tr>
473
						</tfoot>
474
						<tbody>
475
<?php
476
						$i = 0;
477
						foreach($a_group as $group):
478
							if($group['scope'] == "system")
479
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
480
							else
481
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
482
							$groupcount = count($group['member']);
483
							if ($group["name"] == "all")
484
								$groupcount = count($config['system']['user']);
485
?>
486
							<tr ondblclick="document.getElementById('act').value='<?php echo "edit";?>';
487
								document.getElementById('groupid').value='<?=$i;?>';
488
								document.iform2.submit();">
489
								<td class="listlr">
490
									<table border="0" cellpadding="0" cellspacing="0" summary="">
491
										<tr>
492
											<td align="left" valign="middle">
493
												<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
494
											</td>
495
											<td align="left" valign="middle">
496
												<?=htmlspecialchars($group['name']); ?>&nbsp;
497
											</td>
498
										</tr>
499
									</table>
500
								</td>
501
								<td class="listr">
502
									<?=htmlspecialchars($group['description']);?>&nbsp;
503
								</td>
504
								<td class="listbg">
505
									<?=$groupcount;?>
506
								</td>
507
								<td valign="middle" class="list nowrap">
508
									<input type="image" name="editgroup[]" width="17" height="17" border="0"
509
										src="/themes/<?=$g['theme'];?>/images/icons/icon_e.gif"
510
										onclick="document.getElementById('groupid').value='<?=$i;?>';
511
											document.getElementById('act').value='<?php echo "edit";?>';"
512
										title="<?=gettext("edit group");?>" />
513
									&nbsp;
514
<?php
515
								if($group['scope'] != "system"):
516
?>
517
									<input type="image" name="delgroup[]" width="17" height="17" border="0"
518
										src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
519
										onclick="document.getElementById('groupid').value='<?=$i;?>';
520
											document.getElementById('groupname').value='<?=$group['name'];?>';
521
											document.getElementById('act').value='<?php echo "delgroup";?>';
522
											return confirm('<?=gettext("Do you really want to delete this group?");?>');"
523
										title="<?=gettext("delete group");?>" />
524
<?php
525
								endif;
526
?>
527
								</td>
528
							</tr>
529
<?php
530
							$i++;
531
						endforeach;
532
?>
533
						</tbody>
534
					</table>
535
				</form>
536
<?php
537
			endif;
538
?>
539
			</div>
540
		</td>
541
	</tr>
542
</table>
543
<?php include("fend.inc"); ?>
544
</body>
545
</html>
(224-224/256)