Project

General

Profile

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