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
|
conf_mount_rw();
|
68
|
local_group_del($a_group[$_GET['id']]);
|
69
|
conf_mount_ro();
|
70
|
$groupdeleted = $a_group[$_GET['id']]['name'];
|
71
|
unset($a_group[$_GET['id']]);
|
72
|
write_config();
|
73
|
$savemsg = gettext("Group")." {$groupdeleted} ".
|
74
|
gettext("successfully deleted")."<br />";
|
75
|
}
|
76
|
|
77
|
if ($_GET['act'] == "delpriv") {
|
78
|
|
79
|
if (!$a_group[$_GET['id']]) {
|
80
|
pfSenseHeader("system_groupmanager.php");
|
81
|
exit;
|
82
|
}
|
83
|
|
84
|
$privdeleted = $priv_list[$a_group[$id]['priv'][$_GET['privid']]]['name'];
|
85
|
unset($a_group[$id]['priv'][$_GET['privid']]);
|
86
|
|
87
|
if (is_array($a_group[$id]['member'])) {
|
88
|
foreach ($a_group[$id]['member'] as $uid) {
|
89
|
$user = getUserEntryByUID($uid);
|
90
|
if ($user)
|
91
|
local_user_set($user);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
write_config();
|
96
|
$_GET['act'] = "edit";
|
97
|
$savemsg = gettext("Privilege")." {$privdeleted} ".
|
98
|
gettext("successfully deleted")."<br />";
|
99
|
}
|
100
|
|
101
|
if($_GET['act']=="edit"){
|
102
|
if (isset($id) && $a_group[$id]) {
|
103
|
$pconfig['name'] = $a_group[$id]['name'];
|
104
|
$pconfig['gid'] = $a_group[$id]['gid'];
|
105
|
$pconfig['gtype'] = $a_group[$id]['scope'];
|
106
|
$pconfig['description'] = $a_group[$id]['description'];
|
107
|
$pconfig['members'] = $a_group[$id]['member'];
|
108
|
$pconfig['priv'] = $a_group[$id]['priv'];
|
109
|
}
|
110
|
}
|
111
|
|
112
|
if ($_POST) {
|
113
|
|
114
|
unset($input_errors);
|
115
|
$pconfig = $_POST;
|
116
|
|
117
|
/* input validation */
|
118
|
$reqdfields = explode(" ", "groupname");
|
119
|
$reqdfieldsn = array(gettext("Group Name"));
|
120
|
|
121
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
122
|
|
123
|
if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
|
124
|
$input_errors[] = gettext("The group name contains invalid characters.");
|
125
|
|
126
|
if (strlen($_POST['groupname']) > 16)
|
127
|
$input_errors[] = gettext("The group name is longer than 16 characters.");
|
128
|
|
129
|
if (!$input_errors && !(isset($id) && $a_group[$id])) {
|
130
|
/* make sure there are no dupes */
|
131
|
foreach ($a_group as $group) {
|
132
|
if ($group['name'] == $_POST['groupname']) {
|
133
|
$input_errors[] = gettext("Another entry with the same group name already exists.");
|
134
|
break;
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if (!$input_errors) {
|
140
|
$group = array();
|
141
|
if (isset($id) && $a_group[$id])
|
142
|
$group = $a_group[$id];
|
143
|
|
144
|
$group['name'] = $_POST['groupname'];
|
145
|
$group['description'] = $_POST['description'];
|
146
|
|
147
|
if (empty($_POST['members']))
|
148
|
unset($group['member']);
|
149
|
else if ($group['gid'] != 1998) // all group
|
150
|
$group['member'] = $_POST['members'];
|
151
|
|
152
|
if (isset($id) && $a_group[$id])
|
153
|
$a_group[$id] = $group;
|
154
|
else {
|
155
|
$group['gid'] = $config['system']['nextgid']++;
|
156
|
$a_group[] = $group;
|
157
|
}
|
158
|
|
159
|
conf_mount_rw();
|
160
|
local_group_set($group);
|
161
|
conf_mount_ro();
|
162
|
|
163
|
/* Refresh users in this group since their privileges may have changed. */
|
164
|
if (is_array($group['member'])) {
|
165
|
$a_user = &$config['system']['user'];
|
166
|
foreach ($a_user as & $user) {
|
167
|
if (in_array($user['uid'], $group['member']))
|
168
|
local_user_set($user);
|
169
|
}
|
170
|
}
|
171
|
|
172
|
write_config();
|
173
|
|
174
|
header("Location: system_groupmanager.php");
|
175
|
exit;
|
176
|
}
|
177
|
}
|
178
|
|
179
|
include("head.inc");
|
180
|
|
181
|
?>
|
182
|
|
183
|
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
|
184
|
<?php include("fbegin.inc"); ?>
|
185
|
<script type="text/javascript">
|
186
|
//<![CDATA[
|
187
|
|
188
|
function setall_selected(id) {
|
189
|
selbox = document.getElementById(id);
|
190
|
count = selbox.options.length;
|
191
|
for (index = 0; index<count; index++)
|
192
|
selbox.options[index].selected = true;
|
193
|
}
|
194
|
|
195
|
function clear_selected(id) {
|
196
|
selbox = document.getElementById(id);
|
197
|
count = selbox.options.length;
|
198
|
for (index = 0; index<count; index++)
|
199
|
selbox.options[index].selected = false;
|
200
|
}
|
201
|
|
202
|
function remove_selected(id) {
|
203
|
selbox = document.getElementById(id);
|
204
|
index = selbox.options.length - 1;
|
205
|
for (; index >= 0; index--)
|
206
|
if (selbox.options[index].selected)
|
207
|
selbox.remove(index);
|
208
|
}
|
209
|
|
210
|
function copy_selected(srcid, dstid) {
|
211
|
src_selbox = document.getElementById(srcid);
|
212
|
dst_selbox = document.getElementById(dstid);
|
213
|
count = src_selbox.options.length;
|
214
|
for (index = 0; index < count; index++) {
|
215
|
if (src_selbox.options[index].selected) {
|
216
|
option = document.createElement('option');
|
217
|
option.text = src_selbox.options[index].text;
|
218
|
option.value = src_selbox.options[index].value;
|
219
|
dst_selbox.add(option, null);
|
220
|
}
|
221
|
}
|
222
|
}
|
223
|
|
224
|
function move_selected(srcid, dstid) {
|
225
|
copy_selected(srcid, dstid);
|
226
|
remove_selected(srcid);
|
227
|
}
|
228
|
|
229
|
function presubmit() {
|
230
|
clear_selected('notmembers');
|
231
|
setall_selected('members');
|
232
|
}
|
233
|
|
234
|
//]]>
|
235
|
</script>
|
236
|
<?php
|
237
|
if ($input_errors)
|
238
|
print_input_errors($input_errors);
|
239
|
if ($savemsg)
|
240
|
print_info_box($savemsg);
|
241
|
?>
|
242
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager">
|
243
|
<tr>
|
244
|
<td>
|
245
|
<?php
|
246
|
$tab_array = array();
|
247
|
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
|
248
|
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
|
249
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
250
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
251
|
display_top_tabs($tab_array);
|
252
|
?>
|
253
|
</td>
|
254
|
</tr>
|
255
|
<tr>
|
256
|
<td id="mainarea">
|
257
|
<div class="tabcont">
|
258
|
|
259
|
<?php if($_GET['act']=="new" || $_GET['act']=="edit"): ?>
|
260
|
|
261
|
<form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()">
|
262
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
263
|
<?php
|
264
|
$ro = "";
|
265
|
if ($pconfig['gtype'] == "system")
|
266
|
$ro = "readonly=\"readonly\"";
|
267
|
?>
|
268
|
<tr>
|
269
|
<td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td>
|
270
|
<td width="78%" class="vtable">
|
271
|
<strong><?=strtoupper($pconfig['gtype']);?></strong>
|
272
|
<input name="gtype" type="hidden" value="<?=htmlspecialchars($pconfig['gtype'])?>"/>
|
273
|
</td>
|
274
|
</tr>
|
275
|
<tr>
|
276
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Group name");?></td>
|
277
|
<td width="78%" class="vtable">
|
278
|
<input name="groupname" type="text" class="formfld group" id="groupname" size="20" maxlength="16" value="<?=htmlspecialchars($pconfig['name']);?>" <?=$ro;?> />
|
279
|
</td>
|
280
|
</tr>
|
281
|
<tr>
|
282
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
283
|
<td width="78%" class="vtable">
|
284
|
<input name="description" type="text" class="formfld unknown" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>" />
|
285
|
<br />
|
286
|
<?=gettext("Group description, for your own information only");?>
|
287
|
</td>
|
288
|
</tr>
|
289
|
|
290
|
<?php if ($pconfig['gid'] != 1998): // all users group ?>
|
291
|
|
292
|
<tr>
|
293
|
<td width="22%" valign="top" class="vncell"><?=gettext("Group Memberships");?></td>
|
294
|
<td width="78%" class="vtable" align="center">
|
295
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="membership">
|
296
|
<tr>
|
297
|
<td align="center" width="50%">
|
298
|
<strong><?=gettext("Not Members");?></strong><br />
|
299
|
<br />
|
300
|
<select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple">
|
301
|
<?php
|
302
|
foreach ($config['system']['user'] as $user):
|
303
|
if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))
|
304
|
continue;
|
305
|
?>
|
306
|
<option value="<?=$user['uid'];?>" <?=$selected;?>>
|
307
|
<?=htmlspecialchars($user['name']);?>
|
308
|
</option>
|
309
|
<?php endforeach; ?>
|
310
|
</select>
|
311
|
<br />
|
312
|
</td>
|
313
|
<td>
|
314
|
<br />
|
315
|
<a href="javascript:move_selected('notmembers','members')">
|
316
|
<img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" />
|
317
|
</a>
|
318
|
<br /><br />
|
319
|
<a href="javascript:move_selected('members','notmembers')">
|
320
|
<img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" />
|
321
|
</a>
|
322
|
</td>
|
323
|
<td align="center" width="50%">
|
324
|
<strong><?=gettext("Members");?></strong><br />
|
325
|
<br />
|
326
|
<select size="10" style="width: 75%" name="members[]" class="formselect" id="members" onchange="clear_selected('notmembers')" multiple="multiple">
|
327
|
<?php
|
328
|
foreach ($config['system']['user'] as $user):
|
329
|
if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])))
|
330
|
continue;
|
331
|
?>
|
332
|
<option value="<?=$user['uid'];?>">
|
333
|
<?=htmlspecialchars($user['name']);?>
|
334
|
</option>
|
335
|
<?php endforeach; ?>
|
336
|
</select>
|
337
|
<br />
|
338
|
</td>
|
339
|
</tr>
|
340
|
</table>
|
341
|
<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
|
342
|
</td>
|
343
|
</tr>
|
344
|
|
345
|
<?php endif; ?>
|
346
|
<?php if($_GET['act'] != "new"): ?>
|
347
|
|
348
|
<tr>
|
349
|
<td width="22%" valign="top" class="vncell"><?=gettext("Assigned Privileges");?></td>
|
350
|
<td width="78%" class="vtable">
|
351
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="privileges">
|
352
|
<tr>
|
353
|
<td width="40%" class="listhdrr"><?=gettext("Name");?></td>
|
354
|
<td width="60%" class="listhdrr"><?=gettext("Description");?></td>
|
355
|
<td class="list"></td>
|
356
|
</tr>
|
357
|
<?php
|
358
|
if(is_array($pconfig['priv'])):
|
359
|
$i = 0;
|
360
|
foreach ($pconfig['priv'] as $priv):
|
361
|
?>
|
362
|
<tr>
|
363
|
<td class="listr">
|
364
|
<?=htmlspecialchars($priv_list[$priv]['name']);?>
|
365
|
</td>
|
366
|
<td class="listbg">
|
367
|
<?=htmlspecialchars($priv_list[$priv]['descr']);?>
|
368
|
</td>
|
369
|
<td valign="middle" class="list nowrap">
|
370
|
<a href="system_groupmanager.php?act=delpriv&id=<?=htmlspecialchars($id)?>&privid=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this privilege?");?>')">
|
371
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" />
|
372
|
</a>
|
373
|
</td>
|
374
|
</tr>
|
375
|
<?php
|
376
|
$i++;
|
377
|
endforeach;
|
378
|
endif;
|
379
|
?>
|
380
|
<tr>
|
381
|
<td class="list" colspan="2"></td>
|
382
|
<td class="list">
|
383
|
<a href="system_groupmanager_addprivs.php?groupid=<?=htmlspecialchars($id)?>">
|
384
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" />
|
385
|
</a>
|
386
|
|
387
|
</td>
|
388
|
</tr>
|
389
|
|
390
|
</table>
|
391
|
</td>
|
392
|
</tr>
|
393
|
<?php endif; ?>
|
394
|
<tr>
|
395
|
<td width="22%" valign="top"> </td>
|
396
|
<td width="78%">
|
397
|
<input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
398
|
<?php if (isset($id) && $a_group[$id]): ?>
|
399
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
400
|
<input name="gid" type="hidden" value="<?=htmlspecialchars($pconfig['gid']);?>" />
|
401
|
<?php endif; ?>
|
402
|
</td>
|
403
|
</tr>
|
404
|
</table>
|
405
|
</form>
|
406
|
|
407
|
<?php else: ?>
|
408
|
|
409
|
<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
|
410
|
<thead>
|
411
|
<tr>
|
412
|
<th width="25%" class="listhdrr"><?=gettext("Group name");?></th>
|
413
|
<th width="25%" class="listhdrr"><?=gettext("Description");?></th>
|
414
|
<th width="30%" class="listhdrr"><?=gettext("Member Count");?></th>
|
415
|
<th width="10%" class="list"></th>
|
416
|
</tr>
|
417
|
</thead>
|
418
|
<tfoot>
|
419
|
<tr>
|
420
|
<td class="list" colspan="3"></td>
|
421
|
<td class="list">
|
422
|
<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" />
|
423
|
</a>
|
424
|
</td>
|
425
|
</tr>
|
426
|
<tr>
|
427
|
<td colspan="3">
|
428
|
<p>
|
429
|
<?=gettext("Additional webConfigurator groups can be added here.
|
430
|
Group permissions can be assigned which are inherited by users who are members of the group.
|
431
|
An icon that appears grey indicates that it is a system defined object.
|
432
|
Some system object properties can be modified but they cannot be deleted.");?>
|
433
|
</p>
|
434
|
</td>
|
435
|
</tr>
|
436
|
</tfoot>
|
437
|
<tbody>
|
438
|
<?php
|
439
|
$i = 0;
|
440
|
foreach($a_group as $group):
|
441
|
|
442
|
if($group['scope'] == "system")
|
443
|
$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png";
|
444
|
else
|
445
|
$grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png";
|
446
|
$groupcount = count($group['member']);
|
447
|
if ($group["name"] == "all")
|
448
|
$groupcount = count($config['system']['user']);
|
449
|
?>
|
450
|
<tr ondblclick="document.location='system_groupmanager.php?act=edit&id=<?=$i;?>'">
|
451
|
<td class="listlr">
|
452
|
<table border="0" cellpadding="0" cellspacing="0" summary="">
|
453
|
<tr>
|
454
|
<td align="left" valign="middle">
|
455
|
<img src="<?=$grpimg;?>" alt="<?=gettext("User");?>" title="<?=gettext("User");?>" border="0" height="16" width="16" />
|
456
|
</td>
|
457
|
<td align="left" valign="middle">
|
458
|
<?=htmlspecialchars($group['name']); ?>
|
459
|
</td>
|
460
|
</tr>
|
461
|
</table>
|
462
|
</td>
|
463
|
<td class="listr">
|
464
|
<?=htmlspecialchars($group['description']);?>
|
465
|
</td>
|
466
|
<td class="listbg">
|
467
|
<?=$groupcount;?>
|
468
|
</td>
|
469
|
<td valign="middle" class="list nowrap">
|
470
|
<a href="system_groupmanager.php?act=edit&id=<?=$i;?>">
|
471
|
<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0" alt="edit" />
|
472
|
</a>
|
473
|
|
474
|
<?php if($group['scope'] != "system"): ?>
|
475
|
<a href="system_groupmanager.php?act=delgroup&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this group?"); ?>')">
|
476
|
<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete group"); ?>" width="17" height="17" border="0" alt="delete" />
|
477
|
</a>
|
478
|
<?php endif; ?>
|
479
|
</td>
|
480
|
</tr>
|
481
|
<?php
|
482
|
$i++;
|
483
|
endforeach;
|
484
|
?>
|
485
|
</tbody>
|
486
|
</table>
|
487
|
|
488
|
<?php endif; ?>
|
489
|
|
490
|
</div>
|
491
|
</td>
|
492
|
</tr>
|
493
|
</table>
|
494
|
<?php include("fend.inc"); ?>
|
495
|
</body>
|
496
|
</html>
|