Project

General

Profile

Download (16.3 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 (strlen($_POST['groupname']) > 16)
125
		$input_errors[] = gettext("The group name is longer than 16 characters.");
126
	
127
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
128
		/* make sure there are no dupes */
129
		foreach ($a_group as $group) {
130
			if ($group['name'] == $_POST['groupname']) {
131
				$input_errors[] = gettext("Another entry with the same group name already exists.");
132
				break;
133
			}
134
		}
135
	}
136
	
137
	if (!$input_errors) {
138
		$group = array();
139
		if (isset($id) && $a_group[$id])
140
			$group = $a_group[$id];
141
		
142
		$group['name'] = $_POST['groupname'];
143
		$group['description'] = $_POST['description'];
144

    
145
		if (empty($_POST['members']))
146
			unset($group['member']);
147
		else if ($group['gid'] != 1998) // all group
148
			$group['member'] = $_POST['members'];
149

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

    
157
		local_group_set($group);
158

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

    
168
		write_config();
169
		
170
		header("Location: system_groupmanager.php");
171
		exit;
172
	}
173
}
174

    
175
include("head.inc");
176

    
177
?>
178

    
179
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
180
<?php include("fbegin.inc"); ?>
181
<script type="text/javascript">
182
//<![CDATA[
183

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

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

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

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

    
220
function move_selected(srcid, dstid) {
221
	copy_selected(srcid, dstid);
222
	remove_selected(srcid);
223
}
224

    
225
function presubmit() {
226
	clear_selected('notmembers');
227
	setall_selected('members');
228
}
229

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

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

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

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

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

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

    
383
										</td>
384
									</tr>
385

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

    
403
				<?php else: ?>
404

    
405
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
406
					<thead>
407
						<tr>
408
							<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
409
							<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
410
							<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
411
							<th width="10%" class="list"></th>
412
						</tr>
413
					</thead>
414
					<tfoot>
415
						<tr> 
416
							<td class="list" colspan="3"></td>
417
							<td class="list">
418
								<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" alt="add" />
419
								</a>
420
							</td>
421
						</tr>
422
						<tr>
423
							<td colspan="3">
424
								<p>
425
									<?=gettext("Additional webConfigurator groups can be added here. 
426
									Group permissions can be assigned which are inherited by users who are members of the group.
427
									An icon that appears grey indicates that it is a system defined object.
428
									Some system object properties can be modified but they cannot be deleted.");?>
429
								</p>
430
							</td>
431
						</tr>
432
					</tfoot>
433
					<tbody>
434
						<?php
435
							$i = 0;
436
							foreach($a_group as $group):
437

    
438
								if($group['scope'] == "system")
439
									$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
440
								else
441
									$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
442
								$groupcount = count($group['member']);
443
								if ($group["name"] == "all")
444
									$groupcount = count($config['system']['user']);
445
						?>
446
						<tr ondblclick="document.location='system_groupmanager.php?act=edit&amp;id=<?=$i;?>'">
447
							<td class="listlr">
448
								<table border="0" cellpadding="0" cellspacing="0" summary="">
449
									<tr>
450
										<td align="left" valign="middle">
451
											<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
452
										</td>
453
										<td align="left" valign="middle">
454
											<?=htmlspecialchars($group['name']); ?>&nbsp;
455
										</td>
456
									</tr>
457
								</table>
458
							</td>
459
							<td class="listr">
460
								<?=htmlspecialchars($group['description']);?>&nbsp;
461
							</td>
462
							<td class="listbg">
463
								<?=$groupcount;?>
464
							</td>
465
							<td valign="middle" class="list nowrap">
466
								<a href="system_groupmanager.php?act=edit&amp;id=<?=$i;?>">
467
									<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0" alt="edit" />
468
								</a>
469
								&nbsp;
470
								<?php if($group['scope'] != "system"): ?>
471
								<a href="system_groupmanager.php?act=delgroup&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this group?"); ?>')">
472
									<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete group"); ?>" width="17" height="17" border="0" alt="delete" />
473
								</a>
474
								<?php endif; ?>
475
							</td>
476
						</tr>
477
						<?php
478
							$i++;
479
							endforeach;
480
						?>
481
					</tbody>
482
				</table>
483
			
484
				<?php endif; ?>
485

    
486
			</div>     
487
		</td>
488
	</tr>
489
</table>
490
<?php include("fend.inc"); ?>
491
</body>
492
</html>
(215-215/246)