Projet

Général

Profil

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

univnautes / usr / local / www / system_groupmanager.php @ b4e9a4da

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 = src_selbox.options.length;
214
	for (index = 0; index < count; index++) {
215
		if (src_selbox.options[index].selected) {
216
			option = document.createElement('option');
217
			option.text = src_selbox.options[index].text;
218
			option.value = src_selbox.options[index].value;
219
			dst_selbox.add(option, null);
220
		}
221
	}
222
}
223

    
224
function move_selected(srcid, dstid) {
225
	copy_selected(srcid, dstid);
226
	remove_selected(srcid);
227
}
228

    
229
function presubmit() {
230
	clear_selected('notmembers');
231
	setall_selected('members');
232
}
233

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

    
259
				<?php if($_GET['act']=="new" || $_GET['act']=="edit"): ?>
260

    
261
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
262
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
263
	                    <?php
264
	                        $ro = "";
265
	                        if ($pconfig['gtype'] == "system")
266
	                            $ro = "readonly=\"readonly\"";
267
	                    ?>
268
						<tr>
269
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
270
							<td width="78%" class="vtable">
271
								<strong><?=strtoupper($pconfig['gtype']);?></strong>
272
								<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
273
							</td>
274
						</tr>
275
						<tr> 
276
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
277
							<td width="78%" class="vtable"> 
278
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?> />
279
							</td>
280
						</tr>
281
						<tr> 
282
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
283
							<td width="78%" class="vtable"> 
284
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>" />
285
								<br />
286
								<?=gettext("Group description, for your own information only");?>
287
							</td>
288
						</tr>
289

    
290
						<?php if ($pconfig['gid'] != 1998): // all users group ?>
291

    
292
						<tr>
293
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
294
							<td width="78%" class="vtable" align="center">
295
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="membership">
296
									<tr>
297
										<td align="center" width="50%">
298
											<strong><?=gettext("Not Members");?></strong><br />
299
											<br />
300
												<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple">
301
												<?php
302
													$rowIndex = 0;
303
													foreach ($config['system']['user'] as $user):
304
														if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))
305
															continue;
306
														$rowIndex++;
307
												?>
308
												<option value="<?=$user['uid'];?>" <?=$selected;?>>
309
													<?=htmlspecialchars($user['name']);?>
310
												</option>
311
												<?php endforeach;
312
												if ($rowIndex == 0)
313
													echo "<option></option>";
314
												?>
315
											</select>
316
											<br />
317
										</td>
318
										<td>
319
											<br />
320
											<a href="javascript:move_selected('notmembers','members')">
321
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" />
322
											</a>
323
											<br /><br />
324
											<a href="javascript:move_selected('members','notmembers')">
325
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
326
											</a>
327
										</td>
328
										<td align="center" width="50%">
329
											<strong><?=gettext("Members");?></strong><br />
330
											<br />
331
											<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onchange="clear_selected('notmembers')" multiple="multiple">
332
												<?php
333
													$rowIndex = 0;
334
													foreach ($config['system']['user'] as $user):
335
														if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])))
336
															continue;
337
														$rowIndex++;
338
												?>
339
												<option value="<?=$user['uid'];?>">
340
													<?=htmlspecialchars($user['name']);?>
341
												</option>
342
												<?php endforeach;
343
												if ($rowIndex == 0)
344
													echo "<option></option>";
345
												?>
346
											</select>
347
											<br />
348
										</td>
349
									</tr>
350
								</table>
351
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
352
							</td>
353
						</tr>
354

    
355
						<?php endif; ?>
356
						<?php if($_GET['act'] != "new"): ?>
357
						
358
						<tr>
359
							<td width="22%" valign="top" class="vncell"><?=gettext("Assigned Privileges");?></td>
360
							<td width="78%" class="vtable">
361
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
362
									<tr>
363
										<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
364
										<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
365
										<td class="list"></td>
366
									</tr>
367
									<?php
368
										if(is_array($pconfig['priv'])):
369
											$i = 0;
370
											foreach ($pconfig['priv'] as $priv):
371
									?>
372
									<tr>
373
										<td class="listr">
374
											<?=htmlspecialchars($priv_list[$priv]['name']);?>
375
										</td>
376
										<td class="listbg">
377
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
378
										</td>
379
										<td valign="middle" class="list nowrap">
380
											<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?");?>')">
381
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
382
											</a>
383
										</td>
384
									</tr>
385
									<?php
386
											$i++;
387
	                      					endforeach;
388
										endif;
389
									?>
390
									<tr>
391
										<td class="list" colspan="2"></td>
392
										<td class="list">
393
											<a href="system_groupmanager_addprivs.php?groupid=<?=htmlspecialchars($id)?>">
394
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
395
											</a>
396

    
397
										</td>
398
									</tr>
399

    
400
								</table>
401
							</td>
402
						</tr>
403
						<?php endif; ?>
404
						<tr> 
405
							<td width="22%" valign="top">&nbsp;</td>
406
							<td width="78%"> 
407
								<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
408
								<?php if (isset($id) && $a_group[$id]): ?>
409
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
410
								<input name="gid" type="hidden" value="<?=htmlspecialchars($pconfig['gid']);?>" />
411
								<?php endif; ?>
412
							</td>
413
						</tr>
414
					</table>
415
				</form>
416

    
417
				<?php else: ?>
418

    
419
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
420
					<thead>
421
						<tr>
422
							<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
423
							<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
424
							<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
425
							<th width="10%" class="list"></th>
426
						</tr>
427
					</thead>
428
					<tfoot>
429
						<tr> 
430
							<td class="list" colspan="3"></td>
431
							<td class="list">
432
								<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" />
433
								</a>
434
							</td>
435
						</tr>
436
						<tr>
437
							<td colspan="3">
438
								<p>
439
									<?=gettext("Additional webConfigurator groups can be added here. 
440
									Group permissions can be assigned which are inherited by users who are members of the group.
441
									An icon that appears grey indicates that it is a system defined object.
442
									Some system object properties can be modified but they cannot be deleted.");?>
443
								</p>
444
							</td>
445
						</tr>
446
					</tfoot>
447
					<tbody>
448
						<?php
449
							$i = 0;
450
							foreach($a_group as $group):
451

    
452
								if($group['scope'] == "system")
453
									$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
454
								else
455
									$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
456
								$groupcount = count($group['member']);
457
								if ($group["name"] == "all")
458
									$groupcount = count($config['system']['user']);
459
						?>
460
						<tr ondblclick="document.location='system_groupmanager.php?act=edit&amp;id=<?=$i;?>'">
461
							<td class="listlr">
462
								<table border="0" cellpadding="0" cellspacing="0" summary="">
463
									<tr>
464
										<td align="left" valign="middle">
465
											<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
466
										</td>
467
										<td align="left" valign="middle">
468
											<?=htmlspecialchars($group['name']); ?>&nbsp;
469
										</td>
470
									</tr>
471
								</table>
472
							</td>
473
							<td class="listr">
474
								<?=htmlspecialchars($group['description']);?>&nbsp;
475
							</td>
476
							<td class="listbg">
477
								<?=$groupcount;?>
478
							</td>
479
							<td valign="middle" class="list nowrap">
480
								<a href="system_groupmanager.php?act=edit&amp;id=<?=$i;?>">
481
									<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0" alt="edit" />
482
								</a>
483
								&nbsp;
484
								<?php if($group['scope'] != "system"): ?>
485
								<a href="system_groupmanager.php?act=delgroup&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this group?"); ?>')">
486
									<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete group"); ?>" width="17" height="17" border="0" alt="delete" />
487
								</a>
488
								<?php endif; ?>
489
							</td>
490
						</tr>
491
						<?php
492
							$i++;
493
							endforeach;
494
						?>
495
					</tbody>
496
				</table>
497
			
498
				<?php endif; ?>
499

    
500
			</div>     
501
		</td>
502
	</tr>
503
</table>
504
<?php include("fend.inc"); ?>
505
</body>
506
</html>
(223-223/255)