Project

General

Profile

Download (15.6 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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
108
if ($_POST) {
109

    
110
	unset($input_errors);
111
	$pconfig = $_POST;
112

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

    
140
		if (empty($_POST['members']))
141
			unset($group['member']);
142
		else 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

    
154
		/* Refresh users in this group since their privileges may have changed. */
155
		if (is_array($group['member'])) {
156
			$a_user = &$config['system']['user'];
157
			foreach ($a_user as & $user) {
158
				if (in_array($user['uid'], $group['member']))
159
					local_user_set($user);
160
			}
161
		}
162

    
163
		write_config();
164
		
165
		header("Location: system_groupmanager.php");
166
		exit;
167
	}
168
}
169

    
170
include("head.inc");
171

    
172
?>
173

    
174
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
175
<?php include("fbegin.inc"); ?>
176
<script language="JavaScript">
177
<!--
178

    
179
function setall_selected(id) {
180
	selbox = document.getElementById(id);
181
	count = selbox.options.length;
182
	for (index = 0; index<count; index++)
183
		selbox.options[index].selected = true;
184
}
185

    
186
function clear_selected(id) {
187
	selbox = document.getElementById(id);
188
	count = selbox.options.length;
189
	for (index = 0; index<count; index++)
190
		selbox.options[index].selected = false;
191
}
192

    
193
function remove_selected(id) {
194
	selbox = document.getElementById(id);
195
	index = selbox.options.length - 1;
196
	for (; index >= 0; index--)
197
		if (selbox.options[index].selected)
198
			selbox.remove(index);
199
}
200

    
201
function copy_selected(srcid, dstid) {
202
	src_selbox = document.getElementById(srcid);
203
	dst_selbox = document.getElementById(dstid);
204
	count = src_selbox.options.length;
205
	for (index = 0; index < count; index++) {
206
		if (src_selbox.options[index].selected) {
207
			option = document.createElement('option');
208
			option.text = src_selbox.options[index].text;
209
			option.value = src_selbox.options[index].value;
210
			dst_selbox.add(option, null);
211
		}
212
	}
213
}
214

    
215
function move_selected(srcid, dstid) {
216
	copy_selected(srcid, dstid);
217
	remove_selected(srcid);
218
}
219

    
220
function presubmit() {
221
	clear_selected('notmembers');
222
	setall_selected('members');
223
}
224

    
225
//-->
226
</script>
227
<?php
228
	if ($input_errors)
229
		print_input_errors($input_errors);
230
	if ($savemsg)
231
		print_info_box($savemsg);
232
?>
233
<table width="100%" border="0" cellpadding="0" cellspacing="0">
234
	<tr>
235
		<td>
236
			<?php 
237
				$tab_array = array();
238
				$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
239
				$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
240
				$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
241
				$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
242
				display_top_tabs($tab_array);
243
			?>
244
		</td>
245
	</tr>    
246
	<tr>
247
		<td id="mainarea">
248
			<div class="tabcont">
249

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

    
252
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
253
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
254
	                    <?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
						<tr> 
267
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
268
							<td width="78%" class="vtable"> 
269
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?>> 
270
							</td>
271
						</tr>
272
						<tr> 
273
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
274
							<td width="78%" class="vtable"> 
275
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
276
								<br>
277
								<?=gettext("Group description, for your own information only");?>
278
							</td>
279
						</tr>
280

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

    
283
						<tr>
284
							<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><?=gettext("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_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("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_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
312
											</a>
313
										</td>
314
										<td align="center" width="50%">
315
											<strong><?=gettext("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
							</td>
334
						</tr>
335

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

    
378
										</td>
379
									</tr>
380

    
381
								</table>
382
							</td>
383
						</tr>
384
						<?php endif; ?>
385
						<tr> 
386
							<td width="22%" valign="top">&nbsp;</td>
387
							<td width="78%"> 
388
								<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>"> 
389
								<?php if (isset($id) && $a_group[$id]): ?>
390
								<input name="id" type="hidden" value="<?=$id;?>">
391
								<input name="gid" type="hidden" value="<?=$pconfig['gid'];?>">
392
								<?php endif; ?>
393
							</td>
394
						</tr>
395
					</table>
396
				</form>
397

    
398
				<?php else: ?>
399

    
400
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
401
					<tr>
402
						<td width="25%" class="listhdrr"><?=gettext("Group name");?></td>
403
						<td width="25%" class="listhdrr"><?=gettext("Description");?></td>
404
						<td width="30%" class="listhdrr"><?=gettext("Member Count");?></td>
405
						<td width="10%" class="list"></td>
406
					</tr>
407
					<?php
408
						$i = 0;
409
						foreach($a_group as $group):
410

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

    
476
			</div>     
477
		</td>
478
	</tr>
479
</table>
480
</body>
481
<?php include("fend.inc"); ?>
(190-190/222)