Project

General

Profile

Download (15.1 KB) Statistics
| Branch: | Tag: | Revision:
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
	local_group_del($a_group[$_GET['id']]);
68
	$groupdeleted = $a_group[$_GET['id']]['name'];
69
	unset($a_group[$_GET['id']]);
70
	write_config();
71
	$savemsg = gettext("Group")." {$groupdeleted} ".
72
				gettext("successfully deleted")."<br/>";
73
}
74

    
75
if ($_GET['act'] == "delpriv") {
76

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

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

    
85
	foreach ($a_group[$id]['member'] as $uid) {
86
		$user = getUserEntryByUID($uid);
87
		if ($user)
88
			local_user_set($user);
89
	}
90

    
91
	write_config();
92
	$_GET['act'] = "edit";
93
	$savemsg = gettext("Privilege")." {$privdeleted} ".
94
				gettext("successfully deleted")."<br/>";
95
}
96

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

    
108
if ($_POST) {
109

    
110
	unset($input_errors);
111
	$pconfig = $_POST;
112

    
113
	/* input validation */
114
	$reqdfields = explode(" ", "groupname");
115
	$reqdfieldsn = array(gettext("Group Name"));
116
	
117
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
118
	
119
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
120
		$input_errors[] = gettext("The group name contains invalid characters.");
121
		
122
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
123
		/* make sure there are no dupes */
124
		foreach ($a_group as $group) {
125
			if ($group['name'] == $_POST['groupname']) {
126
				$input_errors[] = gettext("Another entry with the same group name already exists.");
127
				break;
128
			}
129
		}
130
	}
131
	
132
	if (!$input_errors) {
133
		$group = array();
134
		if (isset($id) && $a_group[$id])
135
			$group = $a_group[$id];
136
		
137
		$group['name'] = $_POST['groupname'];
138
		$group['description'] = $_POST['description'];
139

    
140
		if ($group['gid'] != 1998) // all group
141
			$group['member'] = $_POST['members'];
142

    
143
		if (isset($id) && $a_group[$id])
144
			$a_group[$id] = $group;
145
		else {
146
			$group['gid'] = $config['system']['nextgid']++;
147
			$a_group[] = $group;
148
		}
149

    
150
		local_group_set($group);
151
		write_config();
152
		
153
		header("Location: system_groupmanager.php");
154
		exit;
155
	}
156
}
157

    
158
include("head.inc");
159

    
160
?>
161

    
162
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
163
<?php include("fbegin.inc"); ?>
164
<script language="JavaScript">
165
<!--
166

    
167
function setall_selected(id) {
168
	selbox = document.getElementById(id);
169
	count = selbox.options.length;
170
	for (index = 0; index<count; index++)
171
		selbox.options[index].selected = true;
172
}
173

    
174
function clear_selected(id) {
175
	selbox = document.getElementById(id);
176
	count = selbox.options.length;
177
	for (index = 0; index<count; index++)
178
		selbox.options[index].selected = false;
179
}
180

    
181
function remove_selected(id) {
182
	selbox = document.getElementById(id);
183
	index = selbox.options.length - 1;
184
	for (; index >= 0; index--)
185
		if (selbox.options[index].selected)
186
			selbox.remove(index);
187
}
188

    
189
function copy_selected(srcid, dstid) {
190
	src_selbox = document.getElementById(srcid);
191
	dst_selbox = document.getElementById(dstid);
192
	count = src_selbox.options.length;
193
	for (index = 0; index < count; index++) {
194
		if (src_selbox.options[index].selected) {
195
			option = document.createElement('option');
196
			option.text = src_selbox.options[index].text;
197
			option.value = src_selbox.options[index].value;
198
			dst_selbox.add(option, null);
199
		}
200
	}
201
}
202

    
203
function move_selected(srcid, dstid) {
204
	copy_selected(srcid, dstid);
205
	remove_selected(srcid);
206
}
207

    
208
function presubmit() {
209
	clear_selected('notmembers');
210
	setall_selected('members');
211
}
212

    
213
//-->
214
</script>
215
<?php
216
	if ($input_errors)
217
		print_input_errors($input_errors);
218
	if ($savemsg)
219
		print_info_box($savemsg);
220
?>
221
<table width="100%" border="0" cellpadding="0" cellspacing="0">
222
	<tr>
223
		<td>
224
			<?php 
225
				$tab_array = array();
226
				$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
227
				$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
228
				$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
229
				$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
230
				display_top_tabs($tab_array);
231
			?>
232
		</td>
233
	</tr>    
234
	<tr>
235
		<td id="mainarea">
236
			<div class="tabcont">
237

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

    
240
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
241
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
242
	                    <?php
243
	                        $ro = "";
244
	                        if ($pconfig['gtype'] == "system")
245
	                            $ro = "readonly = \"readonly\"";
246
	                    ?>
247
						<tr>
248
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
249
							<td width="78%" class="vtable">
250
								<strong><?=strtoupper($pconfig['gtype']);?></strong>
251
								<input name="gtype" type="hidden" value="<?=$pconfig['gtype']?>"/>
252
							</td>
253
						</tr>
254
						<tr> 
255
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
256
							<td width="78%" class="vtable"> 
257
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?>> 
258
							</td>
259
						</tr>
260
						<tr> 
261
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
262
							<td width="78%" class="vtable"> 
263
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
264
								<br>
265
								<?=gettext("Group description, for your own information only");?>
266
							</td>
267
						</tr>
268

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

    
271
						<tr>
272
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
273
							<td width="78%" class="vtable" align="center">
274
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
275
									<tr>
276
										<td align="center" width="50%">
277
											<strong><?=gettext("Not Members");?></strong><br/>
278
											<br/>
279
												<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onChange="clear_selected('members')" multiple>
280
												<?php
281
													foreach ($config['system']['user'] as $user):
282
														if (in_array($user['uid'],$pconfig['members']))
283
															continue;
284
												?>
285
												<option value="<?=$user['uid'];?>" <?=$selected;?>>
286
													<?=htmlspecialchars($user['name']);?>
287
												</option>
288
												<?php endforeach; ?>
289
											</select>
290
											<br/>
291
										</td>
292
										<td>
293
											<br/>
294
											<a href="javascript:move_selected('notmembers','members')">
295
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" />
296
											</a>
297
											<br/><br/>
298
											<a href="javascript:move_selected('members','notmembers')">
299
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
300
											</a>
301
										</td>
302
										<td align="center" width="50%">
303
											<strong><?=gettext("Members");?></strong><br/>
304
											<br/>
305
											<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onChange="clear_selected('notmembers')" multiple>
306
												<?php
307
													foreach ($config['system']['user'] as $user):
308
														if (!in_array($user['uid'],$pconfig['members']))
309
															continue;
310
												?>
311
												<option value="<?=$user['uid'];?>">
312
													<?=htmlspecialchars($user['name']);?>
313
												</option>
314
												<?php endforeach; ?>
315
											</select>
316
											<br/>
317
										</td>
318
									</tr>
319
								</table>
320
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
321
							</td>
322
						</tr>
323

    
324
						<?php endif; ?>
325
						<?php if($_GET['act'] != "new"): ?>
326
						
327
						<tr>
328
							<td width="22%" valign="top" class="vncell"><?=gettext("Assigned Privileges");?></td>
329
							<td width="78%" class="vtable">
330
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
331
									<tr>
332
										<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
333
										<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
334
										<td class="list"></td>
335
									</tr>
336
									<?php
337
										if(is_array($pconfig['priv'])):
338
											$i = 0;
339
											foreach ($pconfig['priv'] as $priv):
340
									?>
341
									<tr>
342
										<td class="listr">
343
											<?=htmlspecialchars($priv_list[$priv]['name']);?>
344
										</td>
345
										<td class="listbg">
346
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
347
										</td>
348
										<td valign="middle" nowrap class="list">
349
											<a href="system_groupmanager.php?act=delpriv&id=<?=$id?>&privid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this privilege?");?>')">
350
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" />
351
											</a>
352
										</td>
353
									</tr>
354
									<?php
355
											$i++;
356
	                      					endforeach;
357
										endif;
358
									?>
359
									<tr>
360
										<td class="list" colspan="2"></td>
361
										<td class="list">
362
											<a href="system_groupmanager_addprivs.php?groupid=<?=$id?>">
363
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" />
364
											</a>
365

    
366
										</td>
367
									</tr>
368

    
369
								</table>
370
							</td>
371
						</tr>
372
						<?php endif; ?>
373
						<tr> 
374
							<td width="22%" valign="top">&nbsp;</td>
375
							<td width="78%"> 
376
								<input name="save" type="submit" class="formbtn" value="Save"> 
377
								<?php if (isset($id) && $a_group[$id]): ?>
378
								<input name="id" type="hidden" value="<?=$id;?>">
379
								<input name="gid" type="hidden" value="<?=$pconfig['gid'];?>">
380
								<?php endif; ?>
381
							</td>
382
						</tr>
383
					</table>
384
				</form>
385

    
386
				<?php else: ?>
387

    
388
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
389
					<tr>
390
						<td width="25%" class="listhdrr"><?=gettext("Group name");?></td>
391
						<td width="25%" class="listhdrr"><?=gettext("Description");?></td>
392
						<td width="30%" class="listhdrr"><?=gettext("Member Count");?></td>
393
						<td width="10%" class="list"></td>
394
					</tr>
395
					<?php
396
						$i = 0;
397
						foreach($a_group as $group):
398

    
399
							if($group['scope'] == "system")
400
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
401
							else
402
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
403
					?>
404
					<tr>
405
						<td class="listlr">
406
							<table border="0" cellpadding="0" cellspacing="0">
407
								<tr>
408
									<td align="left" valign="center">
409
										<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
410
									</td>
411
									</td>
412
									<td align="left" valign="middle">
413
										<?=htmlspecialchars($group['name']); ?>&nbsp;
414
									</td>
415
								</tr>
416
							</table>
417
						</td>
418
						<td class="listr">
419
							<?=htmlspecialchars($group['description']);?>&nbsp;
420
						</td>
421
						<td class="listbg">
422
							<?=count($group['member'])?>
423
						</td>
424
						<td valign="middle" nowrap class="list">
425
							<a href="system_groupmanager.php?act=edit&id=<?=$i;?>">
426
								<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0">
427
							</a>
428
							&nbsp;
429
							<?php if($group['scope'] != "system"): ?>
430
							<a href="system_groupmanager.php?act=delgroup&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this group?')">
431
								<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="delete group" width="17" height="17" border="0">
432
							</a>
433
							<?php endif; ?>
434
						</td>
435
					</tr>
436
					<?php
437
						$i++;
438
						endforeach;
439
					?>
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">
444
							</a>
445
						</td>
446
					</tr>
447
					<tr>
448
						<td colspan="3">
449
							<p>
450
								<?=gettext("Additional webConfigurator groups can be added here.");?>
451
								<?=gettext("Group permissions can be assigned which are inherited by users who are members of the group.");?>
452
								<?=gettext("An icon that appears grey indicates that it is a system defined object.");?>
453
								<?=gettext("Some system object properties can be modified but they cannot be deleted.");?>
454
							</p>
455
						</td>
456
					</tr>
457
				</table>
458
			
459
				<? endif; ?>
460

    
461
			</div>     
462
		</td>
463
	</tr>
464
</table>
465
</body>
466
<?php include("fend.inc"); ?>
(186-186/216)