Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1 d88c6a9f Scott Ullrich
<?php 
2 fab7ff44 Bill Marquette
/*
3 d88c6a9f Scott Ullrich
	$Id: system_groupmanager.php 
4
	part of m0n0wall (http://m0n0.ch/wall)
5
6 6b07c15a Matthew Grooms
	Copyright (C) 2008 Shrew Soft Inc.
7
	All rights reserved. 
8
9 d88c6a9f Scott Ullrich
	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 fab7ff44 Bill Marquette
*/
36
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-system-groupmanager
39
##|*NAME=System: Group manager page
40
##|*DESCR=Allow access to the 'System: Group manager' page.
41
##|*MATCH=system_groupmanager.php*
42
##|-PRIV
43 fab7ff44 Bill Marquette
44
45 6b07c15a Matthew Grooms
require("guiconfig.inc");
46 d88c6a9f Scott Ullrich
47 6b07c15a Matthew Grooms
$pgtitle = array("System", "Group manager");
48 fab7ff44 Bill Marquette
49 6b07c15a Matthew Grooms
if (!is_array($config['system']['group']))
50
	$config['system']['group'] = array();
51 d81c2ad1 Scott Ullrich
52 6b07c15a Matthew Grooms
admin_groups_sort();
53
$a_group = &$config['system']['group'];
54 d81c2ad1 Scott Ullrich
55 6b07c15a Matthew Grooms
$id = $_GET['id'];
56
if (isset($_POST['id']))
57
	$id = $_POST['id'];
58 d81c2ad1 Scott Ullrich
59 6b07c15a Matthew Grooms
if ($_GET['act'] == "delgroup") {
60 31b53653 Scott Ullrich
61 6b07c15a Matthew Grooms
	if (!$a_group[$_GET['id']]) {
62
		pfSenseHeader("system_groupmanager.php");
63
		exit;
64
	}
65 31b53653 Scott Ullrich
66 659fa7f2 Matthew Grooms
	local_group_del($a_group[$_GET['id']]);
67 6b07c15a Matthew Grooms
	$groupdeleted = $a_group[$_GET['id']]['name'];
68
	unset($a_group[$_GET['id']]);
69
	write_config();
70
	$savemsg = gettext("Group")." {$groupdeleted} ".
71
				gettext("successfully deleted")."<br/>";
72 fab7ff44 Bill Marquette
}
73 d88c6a9f Scott Ullrich
74 6b07c15a Matthew Grooms
if ($_GET['act'] == "delpriv") {
75 fab7ff44 Bill Marquette
76 6b07c15a Matthew Grooms
	if (!$a_group[$_GET['id']]) {
77
		pfSenseHeader("system_groupmanager.php");
78
		exit;
79
	}
80 fab7ff44 Bill Marquette
81 6b07c15a Matthew Grooms
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_GET['privid']]]['name'];
82
	unset($a_group[$id]['priv'][$_GET['privid']]);
83
84
	foreach ($a_group[$id]['member'] as $uid) {
85
		$user = getUserEntryByUID($uid);
86
		if ($user)
87 659fa7f2 Matthew Grooms
			local_user_set($user);
88 d88c6a9f Scott Ullrich
	}
89 6b07c15a Matthew Grooms
90
	write_config();
91
	$_GET['act'] = "edit";
92
	$savemsg = gettext("Privilege")." {$privdeleted} ".
93
				gettext("successfully deleted")."<br/>";
94
}
95 45ee90ed Matthew Grooms
96
if($_GET['act']=="edit"){
97
	if (isset($id) && $a_group[$id]) {
98
		$pconfig['name'] = $a_group[$id]['name'];
99 6b07c15a Matthew Grooms
		$pconfig['gid'] = $a_group[$id]['gid'];
100
		$pconfig['gtype'] = $a_group[$id]['scope'];
101 45ee90ed Matthew Grooms
		$pconfig['description'] = $a_group[$id]['description'];
102 6b07c15a Matthew Grooms
		$pconfig['members'] = $a_group[$id]['member'];
103
		$pconfig['priv'] = $a_group[$id]['priv'];
104 45ee90ed Matthew Grooms
	}
105
}
106 6b07c15a Matthew Grooms
107 fab7ff44 Bill Marquette
if ($_POST) {
108
109 d88c6a9f Scott Ullrich
	unset($input_errors);
110
	$pconfig = $_POST;
111
112
	/* input validation */
113
	$reqdfields = explode(" ", "groupname");
114
	$reqdfieldsn = explode(",", "Group Name");
115
	
116
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
117
	
118
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
119
		$input_errors[] = "The group name contains invalid characters.";
120
		
121
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
122
		/* make sure there are no dupes */
123
		foreach ($a_group as $group) {
124
			if ($group['name'] == $_POST['groupname']) {
125
				$input_errors[] = "Another entry with the same group name already exists.";
126
				break;
127
			}
128
		}
129
	}
130
	
131
	if (!$input_errors) {
132 45ee90ed Matthew Grooms
		$group = array();
133 d88c6a9f Scott Ullrich
		if (isset($id) && $a_group[$id])
134
			$group = $a_group[$id];
135
		
136
		$group['name'] = $_POST['groupname'];
137
		$group['description'] = $_POST['description'];
138 45ee90ed Matthew Grooms
139 6b07c15a Matthew Grooms
		if ($group['gid'] != 1998) // all group
140
			$group['member'] = $_POST['members'];
141 45ee90ed Matthew Grooms
142 d88c6a9f Scott Ullrich
		if (isset($id) && $a_group[$id])
143
			$a_group[$id] = $group;
144 45ee90ed Matthew Grooms
		else {
145
			$group['gid'] = $config['system']['nextgid']++;
146 d88c6a9f Scott Ullrich
			$a_group[] = $group;
147 45ee90ed Matthew Grooms
		}
148
149 659fa7f2 Matthew Grooms
		local_group_set($group);
150 d88c6a9f Scott Ullrich
		write_config();
151
		
152
		header("Location: system_groupmanager.php");
153
		exit;
154
	}
155 fab7ff44 Bill Marquette
}
156
157
include("head.inc");
158
159
?>
160 45ee90ed Matthew Grooms
161
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
162 6b07c15a Matthew Grooms
<?php include("fbegin.inc"); ?>
163
<script language="JavaScript">
164
<!--
165
166
function setall_selected(id) {
167
	selbox = document.getElementById(id);
168
	count = selbox.options.length;
169
	for (index = 0; index<count; index++)
170
		selbox.options[index].selected = true;
171
}
172
173
function clear_selected(id) {
174
	selbox = document.getElementById(id);
175
	count = selbox.options.length;
176
	for (index = 0; index<count; index++)
177
		selbox.options[index].selected = false;
178
}
179
180
function remove_selected(id) {
181
	selbox = document.getElementById(id);
182
	index = selbox.options.length - 1;
183
	for (; index >= 0; index--)
184
		if (selbox.options[index].selected)
185
			selbox.remove(index);
186
}
187
188
function copy_selected(srcid, dstid) {
189
	src_selbox = document.getElementById(srcid);
190
	dst_selbox = document.getElementById(dstid);
191
	count = src_selbox.options.length;
192
	for (index = 0; index < count; index++) {
193
		if (src_selbox.options[index].selected) {
194
			option = document.createElement('option');
195
			option.text = src_selbox.options[index].text;
196
			option.value = src_selbox.options[index].value;
197
			dst_selbox.add(option, null);
198
		}
199
	}
200
}
201
202
function move_selected(srcid, dstid) {
203
	copy_selected(srcid, dstid);
204
	remove_selected(srcid);
205
}
206
207
function presubmit() {
208
	clear_selected('notmembers');
209
	setall_selected('members');
210
}
211
212
//-->
213
</script>
214 fab7ff44 Bill Marquette
<?php
215 45ee90ed Matthew Grooms
	if ($input_errors)
216
		print_input_errors($input_errors);
217
	if ($savemsg)
218
		print_info_box($savemsg);
219 fab7ff44 Bill Marquette
?>
220 45ee90ed Matthew Grooms
<table width="100%" border="0" cellpadding="0" cellspacing="0">
221
	<tr>
222
		<td class="tabnavtbl">
223
			<ul id="tabnav">
224
			<?php 
225
				$tab_array = array();
226
				$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
227 6b07c15a Matthew Grooms
				$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
228 45ee90ed Matthew Grooms
				$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
229
				display_top_tabs($tab_array);
230
			?>
231
			</ul>
232
		</td>
233
	</tr>    
234
	<tr>
235
		<td class="tabcont">
236
237
			<?php if($_GET['act']=="new" || $_GET['act']=="edit"): ?>
238
239
			<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
240
			<script type="text/javascript">
241
				function checkall() {
242
					var el = document.getElementById('iform');
243
					for (var i = 0; i < el.elements.length; i++)
244
						el.elements[i].checked = true;
245
				}
246
				function checknone() {
247
					var el = document.getElementById('iform');
248
					for (var i = 0; i < el.elements.length; i++)
249
						el.elements[i].checked = false;
250 951224f2 Scott Ullrich
				}
251 45ee90ed Matthew Grooms
			</script>
252 6b07c15a Matthew Grooms
			<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
253 45ee90ed Matthew Grooms
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
254 6b07c15a Matthew Grooms
                    <?php
255
                        $ro = "";
256
                        if ($pconfig['gtype'] == "system")
257
                            $ro = "readonly = \"readonly\"";
258
                    ?>
259
					<tr>
260
						<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
261
						<td width="78%" class="vtable">
262
							<strong><?=strtoupper($pconfig['gtype']);?></strong>
263
							<input name="gtype" type="hidden" value="<?=$pconfig['gtype']?>"/>
264
						</td>
265
					</tr>
266 45ee90ed Matthew Grooms
					<tr> 
267
						<td width="22%" valign="top" class="vncellreq">Group name</td>
268
						<td width="78%" class="vtable"> 
269 6b07c15a Matthew Grooms
							<input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?>> 
270 45ee90ed Matthew Grooms
						</td>
271
					</tr>
272
					<tr> 
273
						<td width="22%" valign="top" class="vncell">Description</td>
274
						<td width="78%" class="vtable"> 
275 6b07c15a Matthew Grooms
							<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
276 45ee90ed Matthew Grooms
							<br>
277
							Group description, for your own information only
278
						</td>
279
					</tr>
280 6b07c15a Matthew Grooms
281
					<?php if ($pconfig['gid'] != 1998): // all users group ?>
282
283 45ee90ed Matthew Grooms
					<tr>
284 6b07c15a Matthew Grooms
						<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
285
						<td width="78%" class="vtable" align="center">
286
							<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
287
								<tr>
288
									<td align="center" width="50%">
289
										<strong>Not Members</strong><br/>
290
										<br/>
291
											<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onChange="clear_selected('members')" multiple>
292
											<?php
293
												foreach ($config['system']['user'] as $user):
294
													if (in_array($user['uid'],$pconfig['members']))
295
														continue;
296
											?>
297
											<option value="<?=$user['uid'];?>" <?=$selected;?>>
298
												<?=htmlspecialchars($user['name']);?>
299
											</option>
300
											<?php endforeach; ?>
301
										</select>
302
										<br/>
303
									</td>
304
									<td>
305
										<br/>
306
										<a href="javascript:move_selected('notmembers','members')">
307
											<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="Add Members" alt="Add Members" width="17" height="17" border="0" />
308
										</a>
309
										<br/><br/>
310
										<a href="javascript:move_selected('members','notmembers')">
311
											<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="Remove Members" alt="Remove Members" width="17" height="17" border="0" />
312
										</a>
313
									</td>
314
									<td align="center" width="50%">
315
										<strong>Members</strong><br/>
316
										<br/>
317
										<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onChange="clear_selected('notmembers')" multiple>
318
											<?php
319
												foreach ($config['system']['user'] as $user):
320
													if (!in_array($user['uid'],$pconfig['members']))
321
														continue;
322
											?>
323
											<option value="<?=$user['uid'];?>">
324
												<?=htmlspecialchars($user['name']);?>
325
											</option>
326
											<?php endforeach; ?>
327
										</select>
328
										<br/>
329
									</td>
330
								</tr>
331
							</table>
332
							<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
333 45ee90ed Matthew Grooms
						</td>
334
					</tr>
335 6b07c15a Matthew Grooms
336
					<?php endif; ?>
337
338 45ee90ed Matthew Grooms
					<tr>
339 6b07c15a Matthew Grooms
						<td width="22%" valign="top" class="vncell"><?=gettext("Effective Privileges");?></td>
340
						<td width="78%" class="vtable">
341
							<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
342 45ee90ed Matthew Grooms
								<tr>
343 6b07c15a Matthew Grooms
									<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
344
									<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
345
									<td class="list"></td>
346
								</tr>
347
								<?php
348
									if(is_array($pconfig['priv'])):
349
										$i = 0;
350
										foreach ($pconfig['priv'] as $priv):
351
								?>
352
								<tr>
353
									<td class="listr">
354
										<?=htmlspecialchars($priv_list[$priv]['name']);?>
355
									</td>
356
									<td class="listbg">
357
										<font color="#FFFFFF">
358
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
359
										</font>
360
									</td>
361
									<td valign="middle" nowrap class="list">
362
										<a href="system_groupmanager.php?act=delpriv&id=<?=$id?>&privid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this privilege?");?>')">
363
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" />
364
										</a>
365
									</td>
366 45ee90ed Matthew Grooms
								</tr>
367 6b07c15a Matthew Grooms
								<?php
368
										$i++;
369
                      					endforeach;
370
									endif;
371 45ee90ed Matthew Grooms
								?>
372
								<tr>
373 6b07c15a Matthew Grooms
									<td class="list" colspan="2"></td>
374
									<td class="list">
375
										<a href="system_groupmanager_addprivs.php?groupid=<?=$id?>">
376
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" />
377
										</a>
378 45ee90ed Matthew Grooms
									</td>
379
								</tr>
380
							</table>
381
						</td>
382
					</tr>
383
					<tr> 
384
						<td width="22%" valign="top">&nbsp;</td>
385
						<td width="78%"> 
386
							<input name="save" type="submit" class="formbtn" value="Save"> 
387
							<?php if (isset($id) && $a_group[$id]): ?>
388
							<input name="id" type="hidden" value="<?=$id;?>">
389 6b07c15a Matthew Grooms
							<input name="gid" type="hidden" value="<?=$pconfig['gid'];?>">
390
							<?php endif; ?>
391 45ee90ed Matthew Grooms
						</td>
392
					</tr>
393
				</table>
394
			</form>
395
396
			<?php else: ?>
397
398
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
399
				<tr>
400
					<td width="25%" class="listhdrr">Group name</td>
401
					<td width="25%" class="listhdrr">Description</td>
402 6b07c15a Matthew Grooms
					<td width="30%" class="listhdrr">Member Count</td>
403 45ee90ed Matthew Grooms
					<td width="10%" class="list"></td>
404 d88c6a9f Scott Ullrich
				</tr>
405 45ee90ed Matthew Grooms
				<?php
406
					$i = 0;
407
					foreach($a_group as $group):
408 6b07c15a Matthew Grooms
409
						if($group['scope'] == "system")
410
							$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
411
						else
412
							$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
413 45ee90ed Matthew Grooms
				?>
414
				<tr>
415
					<td class="listlr">
416 6b07c15a Matthew Grooms
						<table border="0" cellpadding="0" cellspacing="0">
417
							<tr>
418
								<td align="left" valign="center">
419
									<img src="<?=$grpimg;?>" alt="User" title="User" border="0" height="16" width="16" />
420
								</td>
421
								</td>
422
								<td align="left" valign="middle">
423
									<?=htmlspecialchars($group['name']); ?>&nbsp;
424
								</td>
425
							</tr>
426
						</table>
427 45ee90ed Matthew Grooms
					</td>
428
					<td class="listr">
429
						<?=htmlspecialchars($group['description']);?>&nbsp;
430
					</td>
431
					<td class="listbg">
432
						<font color="white">
433 6b07c15a Matthew Grooms
							<?=count($group['member'])?>
434 45ee90ed Matthew Grooms
						</font>
435
					</td>
436
					<td valign="middle" nowrap class="list">
437
						<a href="system_groupmanager.php?act=edit&id=<?=$i;?>">
438
							<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="edit group" width="17" height="17" border="0">
439
						</a>
440
						&nbsp;
441 6b07c15a Matthew Grooms
						<?php if($group['scope'] != "system"): ?>
442
						<a href="system_groupmanager.php?act=delgroup&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this group?')">
443 45ee90ed Matthew Grooms
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="delete group" width="17" height="17" border="0">
444
						</a>
445 6b07c15a Matthew Grooms
						<?php endif; ?>
446 45ee90ed Matthew Grooms
					</td>
447
				</tr>
448
				<?php
449
					$i++;
450
					endforeach;
451
				?>
452
				<tr> 
453 6b07c15a Matthew Grooms
					<td class="list" colspan="3"></td>
454 45ee90ed Matthew Grooms
					<td class="list">
455
						<a href="system_groupmanager.php?act=new"><img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="add group" width="17" height="17" border="0">
456
						</a>
457
					</td>
458
				</tr>
459
				<tr>
460
					<td colspan="4">
461
						Additional webGui admin groups can be added here.
462
						Each group can be restricted to specific portions of the webGUI.
463
						Individually select the desired web pages each group may access.
464
						For example, a troubleshooting group could be created which has
465
						access only to selected Status and Diagnostics pages.
466
					</td>
467
				</tr>
468
			</table>
469
			
470
			<? endif; ?>
471 d88c6a9f Scott Ullrich
     
472 45ee90ed Matthew Grooms
		</td>
473
	</tr>
474
</table>
475
</body>
476 3e321df2 Ermal Luçi
<?php include("fend.inc"); ?>