Project

General

Profile

Download (15.2 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
##|+PRIV
38
##|*IDENT=page-system-groupmanager
39
##|*NAME=System: Group manager page
40
##|*DESCR=Allow access to the 'System: Group manager' page.
41
##|*MATCH=system_groupmanager.php*
42
##|-PRIV
43

    
44

    
45
require("guiconfig.inc");
46

    
47
$pgtitle = array("System", "Group manager");
48

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

    
52
admin_groups_sort();
53
$a_group = &$config['system']['group'];
54

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

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

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

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

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

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

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

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

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

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

    
107
if ($_POST) {
108

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

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

    
139
		if ($group['gid'] != 1998) // all group
140
			$group['member'] = $_POST['members'];
141

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

    
149
		local_group_set($group);
150
		write_config();
151
		
152
		header("Location: system_groupmanager.php");
153
		exit;
154
	}
155
}
156

    
157
include("head.inc");
158

    
159
?>
160

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

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

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

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

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

    
202
function move_selected(srcid, dstid) {
203
	copy_selected(srcid, dstid);
204
	remove_selected(srcid);
205
}
206

    
207
function presubmit() {
208
	clear_selected('notmembers');
209
	setall_selected('members');
210
}
211

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

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

    
242
			<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
243
			<script type="text/javascript">
244
				function checkall() {
245
					var el = document.getElementById('iform');
246
					for (var i = 0; i < el.elements.length; i++)
247
						el.elements[i].checked = true;
248
				}
249
				function checknone() {
250
					var el = document.getElementById('iform');
251
					for (var i = 0; i < el.elements.length; i++)
252
						el.elements[i].checked = false;
253
				}
254
			</script>
255
			<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
256
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
257
                    <?php
258
                        $ro = "";
259
                        if ($pconfig['gtype'] == "system")
260
                            $ro = "readonly = \"readonly\"";
261
                    ?>
262
					<tr>
263
						<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
264
						<td width="78%" class="vtable">
265
							<strong><?=strtoupper($pconfig['gtype']);?></strong>
266
							<input name="gtype" type="hidden" value="<?=$pconfig['gtype']?>"/>
267
						</td>
268
					</tr>
269
					<tr> 
270
						<td width="22%" valign="top" class="vncellreq">Group name</td>
271
						<td width="78%" class="vtable"> 
272
							<input name="groupname" type="text" class="formfld group" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?>> 
273
						</td>
274
					</tr>
275
					<tr> 
276
						<td width="22%" valign="top" class="vncell">Description</td>
277
						<td width="78%" class="vtable"> 
278
							<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
279
							<br>
280
							Group description, for your own information only
281
						</td>
282
					</tr>
283

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

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

    
339
					<?php endif; ?>
340

    
341
					<tr>
342
						<td width="22%" valign="top" class="vncell"><?=gettext("Effective 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
										<font color="#FFFFFF">
361
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
362
										</font>
363
									</td>
364
									<td valign="middle" nowrap class="list">
365
										<a href="system_groupmanager.php?act=delpriv&id=<?=$id?>&privid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this privilege?");?>')">
366
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" />
367
										</a>
368
									</td>
369
								</tr>
370
								<?php
371
										$i++;
372
                      					endforeach;
373
									endif;
374
								?>
375
								<tr>
376
									<td class="list" colspan="2"></td>
377
									<td class="list">
378
										<a href="system_groupmanager_addprivs.php?groupid=<?=$id?>">
379
											<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" />
380
										</a>
381
									</td>
382
								</tr>
383
							</table>
384
						</td>
385
					</tr>
386
					<tr> 
387
						<td width="22%" valign="top">&nbsp;</td>
388
						<td width="78%"> 
389
							<input name="save" type="submit" class="formbtn" value="Save"> 
390
							<?php if (isset($id) && $a_group[$id]): ?>
391
							<input name="id" type="hidden" value="<?=$id;?>">
392
							<input name="gid" type="hidden" value="<?=$pconfig['gid'];?>">
393
							<?php endif; ?>
394
						</td>
395
					</tr>
396
				</table>
397
			</form>
398

    
399
			<?php else: ?>
400

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

    
412
						if($group['scope'] == "system")
413
							$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
414
						else
415
							$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
416
				?>
417
				<tr>
418
					<td class="listlr">
419
						<table border="0" cellpadding="0" cellspacing="0">
420
							<tr>
421
								<td align="left" valign="center">
422
									<img src="<?=$grpimg;?>" alt="User" title="User" border="0" height="16" width="16" />
423
								</td>
424
								</td>
425
								<td align="left" valign="middle">
426
									<?=htmlspecialchars($group['name']); ?>&nbsp;
427
								</td>
428
							</tr>
429
						</table>
430
					</td>
431
					<td class="listr">
432
						<?=htmlspecialchars($group['description']);?>&nbsp;
433
					</td>
434
					<td class="listbg">
435
						<font color="white">
436
							<?=count($group['member'])?>
437
						</font>
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="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('Do you really want to delete this group?')">
446
							<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="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="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
							<?=gettext("Group permissions can be assinged which will be inherited by users.");?>
467
							<?=gettext("An icon that appears grey indicates that it is a system defined object.");?>
468
							<?=gettext("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
		</td>
477
	</tr>
478
</table>
479
</body>
480
<?php include("fend.inc"); ?>
(175-175/214)