Project

General

Profile

Download (14.8 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
require("priv.defs.inc");
49

    
50
$pgtitle = array("System", "Group manager");
51

    
52
if (!is_array($config['system']['group']))
53
	$config['system']['group'] = array();
54

    
55
$a_group = &$config['system']['group'];
56

    
57
$id = $_GET['id'];
58
if (isset($_POST['id']))
59
	$id = $_POST['id'];
60

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

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

    
68
	local_group_del($a_group[$_GET['id']]);
69
	$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
}
75

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

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

    
83
	$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
			local_user_set($user);
90
	}
91

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

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

    
109
if ($_POST) {
110

    
111
	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
		$group = array();
135
		if (isset($id) && $a_group[$id])
136
			$group = $a_group[$id];
137
		
138
		$group['name'] = $_POST['groupname'];
139
		$group['description'] = $_POST['description'];
140

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

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

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

    
159
include("head.inc");
160

    
161
?>
162

    
163
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
164
<?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
<?php
217
	if ($input_errors)
218
		print_input_errors($input_errors);
219
	if ($savemsg)
220
		print_info_box($savemsg);
221
?>
222
<table width="100%" border="0" cellpadding="0" cellspacing="0">
223
	<tr>
224
		<td>
225
			<?php 
226
				$tab_array = array();
227
				$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
228
				$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
229
				$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
230
				$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
231
				display_top_tabs($tab_array);
232
			?>
233
		</td>
234
	</tr>    
235
	<tr>
236
		<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

    
325
						<?php endif; ?>
326
						<?php if($_GET['act'] != "new"): ?>
327
						
328
						<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
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
348
										</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

    
367
										</td>
368
									</tr>
369

    
370
								</table>
371
							</td>
372
						</tr>
373
						<?php endif; ?>
374
						<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
					<tr>
391
						<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
					</tr>
396
					<?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
					<tr>
406
						<td class="listlr">
407
							<table border="0" cellpadding="0" cellspacing="0">
408
								<tr>
409
									<td align="left" valign="center">
410
										<img src="<?=$grpimg;?>" alt="User" title="User" border="0" height="16" width="16" />
411
									</td>
412
									</td>
413
									<td align="left" valign="middle">
414
										<?=htmlspecialchars($group['name']); ?>&nbsp;
415
									</td>
416
								</tr>
417
							</table>
418
						</td>
419
						<td class="listr">
420
							<?=htmlspecialchars($group['description']);?>&nbsp;
421
						</td>
422
						<td class="listbg">
423
							<?=count($group['member'])?>
424
						</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
						</td>
436
					</tr>
437
					<?php
438
						$i++;
439
						endforeach;
440
					?>
441
					<tr> 
442
						<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
						</td>
457
					</tr>
458
				</table>
459
			
460
				<? endif; ?>
461

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