Project

General

Profile

Download (16 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
	if (is_array($a_group[$id]['member'])) {
86
		foreach ($a_group[$id]['member'] as $uid) {
87
			$user = getUserEntryByUID($uid);
88
			if ($user)
89
				local_user_set($user);
90
		}
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 = array(gettext("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[] = gettext("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[] = gettext("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 (empty($_POST['members']))
143
			unset($group['member']);
144
		else if ($group['gid'] != 1998) // all group
145
			$group['member'] = $_POST['members'];
146

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

    
154
		local_group_set($group);
155

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

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

    
172
include("head.inc");
173

    
174
?>
175

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

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

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

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

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

    
217
function move_selected(srcid, dstid) {
218
	copy_selected(srcid, dstid);
219
	remove_selected(srcid);
220
}
221

    
222
function presubmit() {
223
	clear_selected('notmembers');
224
	setall_selected('members');
225
}
226

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

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

    
254
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
255
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
256
	                    <?php
257
	                        $ro = "";
258
	                        if ($pconfig['gtype'] == "system")
259
	                            $ro = "readonly = \"readonly\"";
260
	                    ?>
261
						<tr>
262
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
263
							<td width="78%" class="vtable">
264
								<strong><?=strtoupper($pconfig['gtype']);?></strong>
265
								<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
266
							</td>
267
						</tr>
268
						<tr> 
269
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
270
							<td width="78%" class="vtable"> 
271
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?>> 
272
							</td>
273
						</tr>
274
						<tr> 
275
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
276
							<td width="78%" class="vtable"> 
277
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
278
								<br>
279
								<?=gettext("Group description, for your own information only");?>
280
							</td>
281
						</tr>
282

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

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

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

    
380
										</td>
381
									</tr>
382

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

    
400
				<?php else: ?>
401

    
402
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
403
					<thead>
404
						<tr>
405
							<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
406
							<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
407
							<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
408
							<th width="10%" class="list"></th>
409
						</tr>
410
					</thead>
411
					<tbody>
412
						<?php
413
							$i = 0;
414
							foreach($a_group as $group):
415

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

    
484
			</div>     
485
		</td>
486
	</tr>
487
</table>
488
</body>
489
<?php include("fend.inc"); ?>
(218-218/249)