Project

General

Profile

Download (19.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	$Id: system_groupmanager.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	part of pfSense
6

    
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	All rights reserved.
9

    
10
	Copyright (C) 2008 Shrew Soft Inc.
11
	All rights reserved.
12

    
13
	Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
14
	All rights reserved.
15

    
16
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
17
	All rights reserved.
18

    
19
	Redistribution and use in source and binary forms, with or without
20
	modification, are permitted provided that the following conditions are met:
21

    
22
	1. Redistributions of source code must retain the above copyright notice,
23
	   this list of conditions and the following disclaimer.
24

    
25
	2. Redistributions in binary form must reproduce the above copyright
26
	   notice, this list of conditions and the following disclaimer in the
27
	   documentation and/or other materials provided with the distribution.
28

    
29
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
30
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
31
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
33
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
	POSSIBILITY OF SUCH DAMAGE.
39
*/
40
/*
41
	pfSense_MODULE:	auth
42
*/
43

    
44
##|+PRIV
45
##|*IDENT=page-system-groupmanager
46
##|*NAME=System: Group manager page
47
##|*DESCR=Allow access to the 'System: Group manager' page.
48
##|*MATCH=system_groupmanager.php*
49
##|-PRIV
50

    
51
require("guiconfig.inc");
52

    
53
$pgtitle = array(gettext("System"), gettext("Group manager"));
54

    
55
if (!is_array($config['system']['group']))
56
	$config['system']['group'] = array();
57

    
58
$a_group = &$config['system']['group'];
59

    
60
unset($id);
61
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
62
	$id = $_POST['groupid'];
63

    
64
$act = (isset($_POST['act']) ? $_POST['act'] : '');
65

    
66
if ($act == "delgroup") {
67

    
68
	if (!isset($id) || !isset($_POST['groupname']) || !isset($a_group[$id]) || ($_POST['groupname'] != $a_group[$id]['name'])) {
69
		pfSenseHeader("system_groupmanager.php");
70
		exit;
71
	}
72

    
73
	conf_mount_rw();
74
	local_group_del($a_group[$id]);
75
	conf_mount_ro();
76
	$groupdeleted = $a_group[$id]['name'];
77
	unset($a_group[$id]);
78
	write_config();
79
	$savemsg = gettext("Group")." {$groupdeleted} ".
80
		gettext("successfully deleted")."<br />";
81
}
82

    
83
if ($act == "delpriv") {
84

    
85
	if (!isset($id) || !isset($a_group[$id])) {
86
		pfSenseHeader("system_groupmanager.php");
87
		exit;
88
	}
89

    
90
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_POST['privid']]]['name'];
91
	unset($a_group[$id]['priv'][$_POST['privid']]);
92

    
93
	if (is_array($a_group[$id]['member'])) {
94
		foreach ($a_group[$id]['member'] as $uid) {
95
			$user = getUserEntryByUID($uid);
96
			if ($user)
97
				local_user_set($user);
98
		}
99
	}
100

    
101
	write_config();
102
	$act = "edit";
103
	$savemsg = gettext("Privilege")." {$privdeleted} ".
104
				gettext("successfully deleted")."<br />";
105
}
106

    
107
if ($act == "edit") {
108
	if (isset($id) && isset($a_group[$id])) {
109
		$pconfig['name'] = $a_group[$id]['name'];
110
		$pconfig['gid'] = $a_group[$id]['gid'];
111
		$pconfig['gtype'] = $a_group[$id]['scope'];
112
		$pconfig['description'] = $a_group[$id]['description'];
113
		$pconfig['members'] = $a_group[$id]['member'];
114
		$pconfig['priv'] = $a_group[$id]['priv'];
115
	}
116
}
117

    
118
if(isset($_POST['dellall_x'])) {
119

    
120
	$del_groups = $_POST['delete_check'];
121

    
122
	if(!empty($del_groups)) {
123
		foreach($del_groups as $groupid) {
124
			if(isset($a_group[$groupid]) && $a_group[$groupid]['scope'] != "system") {
125
				conf_mount_rw();
126
				local_group_del($a_group[$groupid]);
127
				conf_mount_ro();
128
				unset($a_group[$groupid]);
129
			}
130
		}
131
		$savemsg = gettext("Selected groups removed successfully!");
132
		write_config($savemsg);
133
	}
134
}
135

    
136
if (isset($_POST['save'])) {
137

    
138
	unset($input_errors);
139
	$pconfig = $_POST;
140

    
141
	/* input validation */
142
	$reqdfields = explode(" ", "groupname");
143
	$reqdfieldsn = array(gettext("Group Name"));
144

    
145
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
146

    
147
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
148
		$input_errors[] = gettext("The group name contains invalid characters.");
149

    
150
	if (strlen($_POST['groupname']) > 16)
151
		$input_errors[] = gettext("The group name is longer than 16 characters.");
152

    
153
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
154
		/* make sure there are no dupes */
155
		foreach ($a_group as $group) {
156
			if ($group['name'] == $_POST['groupname']) {
157
				$input_errors[] = gettext("Another entry with the same group name already exists.");
158
				break;
159
			}
160
		}
161
	}
162

    
163
	if (!$input_errors) {
164
		$group = array();
165
		if (isset($id) && $a_group[$id])
166
			$group = $a_group[$id];
167

    
168
		$group['name'] = $_POST['groupname'];
169
		$group['description'] = $_POST['description'];
170

    
171
		if (empty($_POST['members']))
172
			unset($group['member']);
173
		else if ($group['gid'] != 1998) // all group
174
			$group['member'] = $_POST['members'];
175

    
176
		if (isset($id) && $a_group[$id])
177
			$a_group[$id] = $group;
178
		else {
179
			$group['gid'] = $config['system']['nextgid']++;
180
			$a_group[] = $group;
181
		}
182

    
183
		conf_mount_rw();
184
		local_group_set($group);
185
		conf_mount_ro();
186

    
187
		/* Refresh users in this group since their privileges may have changed. */
188
		if (is_array($group['member'])) {
189
			$a_user = &$config['system']['user'];
190
			foreach ($a_user as & $user) {
191
				if (in_array($user['uid'], $group['member']))
192
					local_user_set($user);
193
			}
194
		}
195

    
196
		write_config();
197

    
198
		header("Location: system_groupmanager.php");
199
		exit;
200
	}
201
}
202

    
203
include("head.inc");
204

    
205
?>
206

    
207
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
208
<?php include("fbegin.inc"); ?>
209
<script type="text/javascript" src="/javascript/row_toggle.js"></script>
210
<script type="text/javascript">
211
//<![CDATA[
212

    
213
function setall_selected(id) {
214
	selbox = document.getElementById(id);
215
	count = selbox.options.length;
216
	for (index = 0; index<count; index++)
217
		selbox.options[index].selected = true;
218
}
219

    
220
function delete_empty(id) {
221
	selbox = document.getElementById(id);
222
	count = selbox.options.length;
223
	for (index = 0; index<count; index++)
224
		if (selbox.options[index].value == '')
225
			selbox.remove(index);
226
}
227

    
228
function clear_selected(id) {
229
	selbox = document.getElementById(id);
230
	count = selbox.options.length;
231
	for (index = 0; index<count; index++)
232
		selbox.options[index].selected = false;
233
}
234

    
235
function remove_selected(id) {
236
	selbox = document.getElementById(id);
237
	index = selbox.options.length - 1;
238
	for (; index >= 0; index--)
239
		if (selbox.options[index].selected)
240
			selbox.remove(index);
241
}
242

    
243
function copy_selected(srcid, dstid) {
244
	src_selbox = document.getElementById(srcid);
245
	dst_selbox = document.getElementById(dstid);
246
	count = dst_selbox.options.length;
247
	for (index = count - 1; index >= 0; index--) {
248
		if (dst_selbox.options[index].value == '') {
249
			dst_selbox.remove(index);
250
		}
251
	}
252
	count = src_selbox.options.length;
253
	for (index = 0; index < count; index++) {
254
		if (src_selbox.options[index].selected) {
255
			option = document.createElement('option');
256
			option.text = src_selbox.options[index].text;
257
			option.value = src_selbox.options[index].value;
258
			dst_selbox.add(option, null);
259
		}
260
	}
261
}
262

    
263
function move_selected(srcid, dstid) {
264
	copy_selected(srcid, dstid);
265
	remove_selected(srcid);
266
}
267

    
268
function presubmit() {
269
	delete_empty('members');
270
	delete_empty('notmembers');
271
	clear_selected('notmembers');
272
	setall_selected('members');
273
}
274

    
275
//]]>
276
</script>
277
<?php
278
	if ($input_errors)
279
		print_input_errors($input_errors);
280
	if ($savemsg)
281
		print_info_box($savemsg);
282
?>
283
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager">
284
	<tr>
285
		<td>
286
<?php
287
			$tab_array = array();
288
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
289
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
290
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
291
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
292
			display_top_tabs($tab_array);
293
?>
294
		</td>
295
	</tr>
296
	<tr>
297
		<td id="mainarea">
298
			<div class="tabcont">
299

    
300
<?php
301
			if($act == "new" || $act == "edit"):
302
?>
303
				<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
304
					<input type="hidden" id="act" name="act" value="" />
305
					<input type="hidden" id="groupid" name="groupid" value="<?=(isset($id) ? $id : '');?>" />
306
					<input type="hidden" id="privid" name="privid" value="" />
307
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
308
<?php
309
						$ro = "";
310
						if ($pconfig['gtype'] == "system")
311
							$ro = "readonly=\"readonly\"";
312
?>
313
						<tr>
314
							<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
315
							<td width="78%" class="vtable">
316
								<strong><?=strtoupper($pconfig['gtype']);?></strong>
317
								<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
318
							</td>
319
						</tr>
320
						<tr>
321
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
322
							<td width="78%" class="vtable">
323
								<input name="groupname" type="text" class="formfld group" id="groupname" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?> />
324
							</td>
325
						</tr>
326
						<tr>
327
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
328
							<td width="78%" class="vtable">
329
								<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>" />
330
								<br />
331
								<?=gettext("Group description, for your own information only");?>
332
							</td>
333
						</tr>
334
<?php
335
					if ($pconfig['gid'] != 1998): // all users group
336
?>
337
						<tr>
338
							<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
339
							<td width="78%" class="vtable" align="center">
340
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="membership">
341
									<tr>
342
										<td align="center" width="50%">
343
											<strong><?=gettext("Not Members");?></strong><br />
344
											<br />
345
												<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple">
346
<?php
347
											$rowIndex = 0;
348
											foreach ($config['system']['user'] as $user):
349
												if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))
350
													continue;
351
												$rowIndex++;
352
?>
353
												<option value="<?=$user['uid'];?>" <?=$selected;?>>
354
													<?=htmlspecialchars($user['name']);?>
355
												</option>
356
<?php
357
											endforeach;
358
											if ($rowIndex == 0)
359
												echo "<option></option>";
360
?>
361
											</select>
362
											<br />
363
										</td>
364
										<td>
365
											<br />
366
											<a href="javascript:move_selected('notmembers','members')">
367
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" />
368
											</a>
369
											<br /><br />
370
											<a href="javascript:move_selected('members','notmembers')">
371
												<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
372
											</a>
373
										</td>
374
										<td align="center" width="50%">
375
											<strong><?=gettext("Members");?></strong><br />
376
											<br />
377
											<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onchange="clear_selected('notmembers')" multiple="multiple">
378
<?php
379
											$rowIndex = 0;
380
											foreach ($config['system']['user'] as $user):
381
												if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])))
382
													continue;
383
												$rowIndex++;
384
?>
385
												<option value="<?=$user['uid'];?>">
386
													<?=htmlspecialchars($user['name']);?>
387
												</option>
388
<?php
389
											endforeach;
390
											if ($rowIndex == 0)
391
												echo "<option></option>";
392
?>
393
											</select>
394
											<br />
395
										</td>
396
									</tr>
397
								</table>
398
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
399
							</td>
400
						</tr>
401
<?php
402
					endif;
403
					if ($act != "new"):
404
?>
405
						<tr>
406
							<td width="22%" valign="top" class="vncell"><?=gettext("Assigned Privileges");?></td>
407
							<td width="78%" class="vtable">
408
								<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
409
									<tr>
410
										<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
411
										<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
412
										<td class="list"></td>
413
									</tr>
414
<?php
415
							if(is_array($pconfig['priv'])):
416
								$i = 0;
417
								foreach ($pconfig['priv'] as $priv):
418
?>
419
									<tr>
420
										<td class="listr">
421
											<?=htmlspecialchars($priv_list[$priv]['name']);?>
422
										</td>
423
										<td class="listbg">
424
											<?=htmlspecialchars($priv_list[$priv]['descr']);?>
425
										</td>
426
										<td valign="middle" class="list nowrap">
427
											<input type="image" name="delpriv[]" width="17" height="17" border="0"
428
												src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
429
												onclick="document.getElementById('privid').value='<?=$i;?>';
430
													document.getElementById('groupid').value='<?=$id;?>';
431
													document.getElementById('act').value='<?php echo "delpriv";?>';
432
													return confirm('<?=gettext("Do you really want to delete this privilege?");?>');"
433
												title="<?=gettext("delete privilege");?>" />
434
										</td>
435
									</tr>
436
<?php
437
									$i++;
438
								endforeach;
439
							endif;
440
?>
441
									<tr>
442
										<td class="list" colspan="2"></td>
443
										<td class="list">
444
											<a href="system_groupmanager_addprivs.php?groupid=<?=htmlspecialchars($id)?>">
445
												<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
446
											</a>
447

    
448
										</td>
449
									</tr>
450

    
451
								</table>
452
							</td>
453
						</tr>
454
<?php
455
					endif;
456
?>
457
						<tr>
458
							<td width="22%" valign="top">&nbsp;</td>
459
							<td width="78%">
460
								<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
461
								<input type="button" value="<?=gettext("Cancel");?>" onclick="window.location.href='/system_groupmanager.php'" />
462
								<?php if (isset($id) && $a_group[$id]): ?>
463
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
464
								<input name="gid" type="hidden" value="<?=htmlspecialchars($pconfig['gid']);?>" />
465
								<?php endif; ?>
466
							</td>
467
						</tr>
468
					</table>
469
				</form>
470
<?php
471
			else:
472
?>
473
				<form action="system_groupmanager.php" method="post" name="iform2" id="iform2">
474
					<input type="hidden" id="act" name="act" value="" />
475
					<input type="hidden" id="groupid" name="groupid" value="<?=(isset($id) ? $id : '');?>" />
476
					<input type="hidden" id="groupname" name="groupname" value="" />
477
					<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
478
						<thead>
479
							<tr>
480
								<th width="5%" class="list">&nbsp;</th>
481
								<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
482
								<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
483
								<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
484
								<th width="10%" class="list"></th>
485
							</tr>
486
						</thead>
487
						<tfoot>
488
							<tr>
489
								<td class="list" colspan="4"></td>
490
								<td class="list">
491
									<input type="image" name="addcert" width="17" height="17" border="0"
492
										src="/themes/<?=$g['theme'];?>/images/icons/icon_plus.gif"
493
										onclick="document.getElementById('act').value='<?php echo "new";?>';"
494
										title="<?=gettext("add group");?>" />
495
									<input type="image" src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" name="dellall" title="<?=gettext('Delete selected groups')?>" onClick="return confirm('<?=gettext("Do you really want to delete selected groups?");?>')" />
496
								</td>
497
							</tr>
498
							<tr>
499
								<td colspan="4">
500
									<p>
501
										<?=gettext("Additional webConfigurator groups can be added here.
502
										Group permissions can be assigned which are inherited by users who are members of the group.
503
										An icon that appears grey indicates that it is a system defined object.
504
										Some system object properties can be modified but they cannot be deleted.");?>
505
									</p>
506
								</td>
507
							</tr>
508
						</tfoot>
509
						<tbody>
510
<?php
511
						$i = 0;
512
						foreach($a_group as $group):
513
							if($group['scope'] == "system")
514
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
515
							else
516
								$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
517
							$groupcount = count($group['member']);
518
							if ($group["name"] == "all")
519
								$groupcount = count($config['system']['user']);
520
?>
521
							<tr ondblclick="document.getElementById('act').value='<?php echo "edit";?>';
522
								document.getElementById('groupid').value='<?=$i;?>';
523
								document.iform2.submit();" id="fr<?=$i?>">
524
								<td class="list" id="frd<?=$i?>">
525
								<?php if($group['scope'] != "system") : ?>
526
									<input type="checkbox" id="frc<?=$i?>" onclick="fr_bgcolor(<?=$i?>)" name="delete_check[]" value="<?=$i?>" />
527
								<?php endif; ?>
528
								</td>
529
								<td class="listlr" id="frd<?=$i?>" onclick="fr_toggle(<?=$i?>)">
530
									<table border="0" cellpadding="0" cellspacing="0" summary="">
531
										<tr>
532
											<td align="left" valign="middle">
533
												<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
534
											</td>
535
											<td align="left" valign="middle">
536
												<?=htmlspecialchars($group['name']); ?>&nbsp;
537
											</td>
538
										</tr>
539
									</table>
540
								</td>
541
								<td class="listr" id="frd<?=$i?>" onclick="fr_toggle(<?=$i?>)">
542
									<?=htmlspecialchars($group['description']);?>&nbsp;
543
								</td>
544
								<td class="listbg" onclick="fr_toggle(<?=$i?>)">
545
									<?=$groupcount;?>
546
								</td>
547
								<td valign="middle" class="list nowrap">
548
									<input type="image" name="editgroup[]" width="17" height="17" border="0"
549
										src="/themes/<?=$g['theme'];?>/images/icons/icon_e.gif"
550
										onclick="document.getElementById('groupid').value='<?=$i;?>';
551
											document.getElementById('act').value='<?php echo "edit";?>';"
552
										title="<?=gettext("edit group");?>" />
553
									&nbsp;
554
<?php
555
								if($group['scope'] != "system"):
556
?>
557
									<input type="image" name="delgroup[]" width="17" height="17" border="0"
558
										src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif"
559
										onclick="document.getElementById('groupid').value='<?=$i;?>';
560
											document.getElementById('groupname').value='<?=$group['name'];?>';
561
											document.getElementById('act').value='<?php echo "delgroup";?>';
562
											return confirm('<?=gettext("Do you really want to delete this group?");?>');"
563
										title="<?=gettext("delete group");?>" />
564
<?php
565
								endif;
566
?>
567
								</td>
568
							</tr>
569
<?php
570
							$i++;
571
						endforeach;
572
?>
573
						</tbody>
574
					</table>
575
				</form>
576
<?php
577
			endif;
578
?>
579
			</div>
580
		</td>
581
	</tr>
582
</table>
583
<?php include("fend.inc"); ?>
584
</body>
585
</html>
(224-224/256)