Projet

Général

Profil

Télécharger (16,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_groupmanager.php @ 4c291f4c

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

    
60
if ($_GET['act'] == "delgroup") {
61

    
62
	if (!$a_group[$_GET['id']]) {
63
		pfSenseHeader("system_groupmanager.php");
64
		exit;
65
	}
66

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

    
77
if ($_GET['act'] == "delpriv") {
78

    
79
	if (!$a_group[$_GET['id']]) {
80
		pfSenseHeader("system_groupmanager.php");
81
		exit;
82
	}
83

    
84
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_GET['privid']]]['name'];
85
	unset($a_group[$id]['priv'][$_GET['privid']]);
86

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

    
95
	write_config();
96
	$_GET['act'] = "edit";
97
	$savemsg = gettext("Privilege")." {$privdeleted} ".
98
				gettext("successfully deleted")."<br />";
99
}
100

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

    
112
if ($_POST) {
113

    
114
	unset($input_errors);
115
	$pconfig = $_POST;
116

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

    
121
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
122

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

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

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

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

    
144
		$group['name'] = $_POST['groupname'];
145
		$group['description'] = $_POST['description'];
146

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

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

    
159
		conf_mount_rw();
160
		local_group_set($group);
161
		conf_mount_ro();
162

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

    
172
		write_config();
173

    
174
		header("Location: system_groupmanager.php");
175
		exit;
176
	}
177
}
178

    
179
include("head.inc");
180

    
181
?>
182

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

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

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

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

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

    
230
function move_selected(srcid, dstid) {
231
	copy_selected(srcid, dstid);
232
	remove_selected(srcid);
233
}
234

    
235
function presubmit() {
236
	clear_selected('notmembers');
237
	setall_selected('members');
238
}
239

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

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

    
406
										</td>
407
									</tr>
408

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