Project

General

Profile

Download (14.7 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
##|+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

    
44

    
45
require("guiconfig.inc");
46

    
47
$pgtitle = array("System", "Group manager");
48

    
49
if (!is_array($config['system']['group']))
50
	$config['system']['group'] = array();
51

    
52
$a_group = &$config['system']['group'];
53

    
54
$id = $_GET['id'];
55
if (isset($_POST['id']))
56
	$id = $_POST['id'];
57

    
58
if ($_GET['act'] == "delgroup") {
59

    
60
	if (!$a_group[$_GET['id']]) {
61
		pfSenseHeader("system_groupmanager.php");
62
		exit;
63
	}
64

    
65
	local_group_del($a_group[$_GET['id']]);
66
	$groupdeleted = $a_group[$_GET['id']]['name'];
67
	unset($a_group[$_GET['id']]);
68
	write_config();
69
	$savemsg = gettext("Group")." {$groupdeleted} ".
70
				gettext("successfully deleted")."<br/>";
71
}
72

    
73
if ($_GET['act'] == "delpriv") {
74

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

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

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

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

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

    
106
if ($_POST) {
107

    
108
	unset($input_errors);
109
	$pconfig = $_POST;
110

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

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

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

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

    
156
include("head.inc");
157

    
158
?>
159

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

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

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

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

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

    
201
function move_selected(srcid, dstid) {
202
	copy_selected(srcid, dstid);
203
	remove_selected(srcid);
204
}
205

    
206
function presubmit() {
207
	clear_selected('notmembers');
208
	setall_selected('members');
209
}
210

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

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

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

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

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

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

    
364
										</td>
365
									</tr>
366

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

    
384
				<?php else: ?>
385

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

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

    
459
			</div>     
460
		</td>
461
	</tr>
462
</table>
463
</body>
464
<?php include("fend.inc"); ?>
(188-188/218)