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("priv.defs.inc");
48
require("priv.inc");
49
require("guiconfig.inc");
50

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

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

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

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

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

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

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

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

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

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

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

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

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

    
110
if ($_POST) {
111

    
112
	unset($input_errors);
113
	$pconfig = $_POST;
114

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

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

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

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

    
160
include("head.inc");
161

    
162
?>
163

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

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

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

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

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

    
205
function move_selected(srcid, dstid) {
206
	copy_selected(srcid, dstid);
207
	remove_selected(srcid);
208
}
209

    
210
function presubmit() {
211
	clear_selected('notmembers');
212
	setall_selected('members');
213
}
214

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

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

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

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

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

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

    
368
										</td>
369
									</tr>
370

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

    
388
				<?php else: ?>
389

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

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

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