Project

General

Profile

Download (16 KB) Statistics
| Branch: | Tag: | Revision:
1 d88c6a9f Scott Ullrich
<?php 
2 fab7ff44 Bill Marquette
/*
3 d88c6a9f Scott Ullrich
	$Id: system_groupmanager.php 
4
	part of m0n0wall (http://m0n0.ch/wall)
5
6 6b07c15a Matthew Grooms
	Copyright (C) 2008 Shrew Soft Inc.
7
	All rights reserved. 
8
9 d88c6a9f Scott Ullrich
	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 fab7ff44 Bill Marquette
*/
36 1d333258 Scott Ullrich
/*
37
	pfSense_MODULE:	auth
38
*/
39 fab7ff44 Bill Marquette
40 6b07c15a Matthew Grooms
##|+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 fab7ff44 Bill Marquette
47 3fa86ecd sullrich
require("guiconfig.inc");
48 d88c6a9f Scott Ullrich
49 bbf825ab Vinicius Coque
$pgtitle = array(gettext("System"), gettext("Group manager"));
50 fab7ff44 Bill Marquette
51 6b07c15a Matthew Grooms
if (!is_array($config['system']['group']))
52
	$config['system']['group'] = array();
53 d81c2ad1 Scott Ullrich
54 6b07c15a Matthew Grooms
$a_group = &$config['system']['group'];
55 d81c2ad1 Scott Ullrich
56 6b07c15a Matthew Grooms
$id = $_GET['id'];
57
if (isset($_POST['id']))
58
	$id = $_POST['id'];
59 d81c2ad1 Scott Ullrich
60 6b07c15a Matthew Grooms
if ($_GET['act'] == "delgroup") {
61 31b53653 Scott Ullrich
62 6b07c15a Matthew Grooms
	if (!$a_group[$_GET['id']]) {
63
		pfSenseHeader("system_groupmanager.php");
64
		exit;
65
	}
66 31b53653 Scott Ullrich
67 659fa7f2 Matthew Grooms
	local_group_del($a_group[$_GET['id']]);
68 6b07c15a Matthew Grooms
	$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 fab7ff44 Bill Marquette
}
74 d88c6a9f Scott Ullrich
75 6b07c15a Matthew Grooms
if ($_GET['act'] == "delpriv") {
76 fab7ff44 Bill Marquette
77 6b07c15a Matthew Grooms
	if (!$a_group[$_GET['id']]) {
78
		pfSenseHeader("system_groupmanager.php");
79
		exit;
80
	}
81 fab7ff44 Bill Marquette
82 6b07c15a Matthew Grooms
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_GET['privid']]]['name'];
83
	unset($a_group[$id]['priv'][$_GET['privid']]);
84
85 2ee08031 Erik Fonnesbeck
	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 d88c6a9f Scott Ullrich
	}
92 6b07c15a Matthew Grooms
93
	write_config();
94
	$_GET['act'] = "edit";
95
	$savemsg = gettext("Privilege")." {$privdeleted} ".
96
				gettext("successfully deleted")."<br/>";
97
}
98 45ee90ed Matthew Grooms
99
if($_GET['act']=="edit"){
100
	if (isset($id) && $a_group[$id]) {
101
		$pconfig['name'] = $a_group[$id]['name'];
102 6b07c15a Matthew Grooms
		$pconfig['gid'] = $a_group[$id]['gid'];
103
		$pconfig['gtype'] = $a_group[$id]['scope'];
104 45ee90ed Matthew Grooms
		$pconfig['description'] = $a_group[$id]['description'];
105 6b07c15a Matthew Grooms
		$pconfig['members'] = $a_group[$id]['member'];
106
		$pconfig['priv'] = $a_group[$id]['priv'];
107 45ee90ed Matthew Grooms
	}
108
}
109 6b07c15a Matthew Grooms
110 fab7ff44 Bill Marquette
if ($_POST) {
111
112 d88c6a9f Scott Ullrich
	unset($input_errors);
113
	$pconfig = $_POST;
114
115
	/* input validation */
116
	$reqdfields = explode(" ", "groupname");
117 b4fd804b Carlos Eduardo Ramos
	$reqdfieldsn = array(gettext("Group Name"));
118 d88c6a9f Scott Ullrich
	
119
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
120
	
121
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
122 bbf825ab Vinicius Coque
		$input_errors[] = gettext("The group name contains invalid characters.");
123 d88c6a9f Scott Ullrich
		
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 bbf825ab Vinicius Coque
				$input_errors[] = gettext("Another entry with the same group name already exists.");
129 d88c6a9f Scott Ullrich
				break;
130
			}
131
		}
132
	}
133
	
134
	if (!$input_errors) {
135 45ee90ed Matthew Grooms
		$group = array();
136 d88c6a9f Scott Ullrich
		if (isset($id) && $a_group[$id])
137
			$group = $a_group[$id];
138
		
139
		$group['name'] = $_POST['groupname'];
140
		$group['description'] = $_POST['description'];
141 45ee90ed Matthew Grooms
142 70d6b5c4 Ermal
		if (empty($_POST['members']))
143
			unset($group['member']);
144
		else if ($group['gid'] != 1998) // all group
145 6b07c15a Matthew Grooms
			$group['member'] = $_POST['members'];
146 45ee90ed Matthew Grooms
147 d88c6a9f Scott Ullrich
		if (isset($id) && $a_group[$id])
148
			$a_group[$id] = $group;
149 45ee90ed Matthew Grooms
		else {
150
			$group['gid'] = $config['system']['nextgid']++;
151 d88c6a9f Scott Ullrich
			$a_group[] = $group;
152 45ee90ed Matthew Grooms
		}
153
154 659fa7f2 Matthew Grooms
		local_group_set($group);
155 2a0e8512 jim-p
156
		/* Refresh users in this group since their privileges may have changed. */
157 5709072a jim-p
		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 2a0e8512 jim-p
		}
164
165 d88c6a9f Scott Ullrich
		write_config();
166
		
167
		header("Location: system_groupmanager.php");
168
		exit;
169
	}
170 fab7ff44 Bill Marquette
}
171
172
include("head.inc");
173
174
?>
175 45ee90ed Matthew Grooms
176
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
177 6b07c15a Matthew Grooms
<?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 fab7ff44 Bill Marquette
<?php
230 45ee90ed Matthew Grooms
	if ($input_errors)
231
		print_input_errors($input_errors);
232
	if ($savemsg)
233
		print_info_box($savemsg);
234 fab7ff44 Bill Marquette
?>
235 45ee90ed Matthew Grooms
<table width="100%" border="0" cellpadding="0" cellspacing="0">
236
	<tr>
237 e30001cf Matthew Grooms
		<td>
238 45ee90ed Matthew Grooms
			<?php 
239
				$tab_array = array();
240
				$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
241 6b07c15a Matthew Grooms
				$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
242 45ee90ed Matthew Grooms
				$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
243 d799787e Matthew Grooms
				$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
244 45ee90ed Matthew Grooms
				display_top_tabs($tab_array);
245
			?>
246
		</td>
247
	</tr>    
248
	<tr>
249 e30001cf Matthew Grooms
		<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 dd5bf424 Scott Ullrich
								<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
266 e30001cf Matthew Grooms
							</td>
267
						</tr>
268
						<tr> 
269 bbf825ab Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
270 e30001cf Matthew Grooms
							<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 bbf825ab Vinicius Coque
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
276 e30001cf Matthew Grooms
							<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 bbf825ab Vinicius Coque
								<?=gettext("Group description, for your own information only");?>
280 e30001cf Matthew Grooms
							</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 bbf825ab Vinicius Coque
											<strong><?=gettext("Not Members");?></strong><br/>
292 e30001cf Matthew Grooms
											<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 73815007 jim-p
														if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))
297 e30001cf Matthew Grooms
															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 bbf825ab Vinicius Coque
												<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 e30001cf Matthew Grooms
											</a>
311
											<br/><br/>
312
											<a href="javascript:move_selected('members','notmembers')">
313 bbf825ab Vinicius Coque
												<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 e30001cf Matthew Grooms
											</a>
315
										</td>
316
										<td align="center" width="50%">
317 bbf825ab Vinicius Coque
											<strong><?=gettext("Members");?></strong><br/>
318 e30001cf Matthew Grooms
											<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 cf74d3a8 bcyrill
														if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])))
323 e30001cf Matthew Grooms
															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 45ee90ed Matthew Grooms
338 e30001cf Matthew Grooms
						<?php endif; ?>
339 4d86a13d Scott Ullrich
						<?php if($_GET['act'] != "new"): ?>
340
						
341 e30001cf Matthew Grooms
						<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 33300c73 Scott Ullrich
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
361 e30001cf Matthew Grooms
										</td>
362
										<td valign="middle" nowrap class="list">
363 dd5bf424 Scott Ullrich
											<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 e30001cf Matthew Grooms
												<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 dd5bf424 Scott Ullrich
											<a href="system_groupmanager_addprivs.php?groupid=<?=htmlspecialchars($id)?>">
377 e30001cf Matthew Grooms
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" />
378
											</a>
379 4d86a13d Scott Ullrich
380 e30001cf Matthew Grooms
										</td>
381
									</tr>
382 4d86a13d Scott Ullrich
383 e30001cf Matthew Grooms
								</table>
384
							</td>
385
						</tr>
386 4d86a13d Scott Ullrich
						<?php endif; ?>
387 e30001cf Matthew Grooms
						<tr> 
388
							<td width="22%" valign="top">&nbsp;</td>
389
							<td width="78%"> 
390 6e707e77 Vinicius Coque
								<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>"> 
391 e30001cf Matthew Grooms
								<?php if (isset($id) && $a_group[$id]): ?>
392 dd5bf424 Scott Ullrich
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
393
								<input name="gid" type="hidden" value="<?=htmlspecialchars($pconfig['gid']);?>">
394 e30001cf Matthew Grooms
								<?php endif; ?>
395
							</td>
396
						</tr>
397
					</table>
398
				</form>
399
400
				<?php else: ?>
401
402 5b42a459 bcyrill
				<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 45ee90ed Matthew Grooms
				</table>
481
			
482 ee9933b6 Renato Botelho
				<?php endif; ?>
483 e30001cf Matthew Grooms
484
			</div>     
485 45ee90ed Matthew Grooms
		</td>
486
	</tr>
487
</table>
488
</body>
489 3e321df2 Ermal Luçi
<?php include("fend.inc"); ?>