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
|
|
59
|
$a_group = &$config['system']['group'];
|
60
|
|
61
|
unset($id);
|
62
|
if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) {
|
63
|
$id = $_POST['groupid'];
|
64
|
}
|
65
|
|
66
|
$act = (isset($_POST['act']) ? $_POST['act'] : '');
|
67
|
|
68
|
if ($act == "delgroup") {
|
69
|
|
70
|
if (!isset($id) || !isset($_POST['groupname']) || !isset($a_group[$id]) || ($_POST['groupname'] != $a_group[$id]['name'])) {
|
71
|
pfSenseHeader("system_groupmanager.php");
|
72
|
exit;
|
73
|
}
|
74
|
|
75
|
conf_mount_rw();
|
76
|
local_group_del($a_group[$id]);
|
77
|
conf_mount_ro();
|
78
|
$groupdeleted = $a_group[$id]['name'];
|
79
|
unset($a_group[$id]);
|
80
|
write_config();
|
81
|
$savemsg = gettext("Group") . " {$groupdeleted} " .
|
82
|
gettext("successfully deleted") . "<br />";
|
83
|
}
|
84
|
|
85
|
if ($act == "delpriv") {
|
86
|
|
87
|
if (!isset($id) || !isset($a_group[$id])) {
|
88
|
pfSenseHeader("system_groupmanager.php");
|
89
|
exit;
|
90
|
}
|
91
|
|
92
|
$privdeleted = $priv_list[$a_group[$id]['priv'][$_POST['privid']]]['name'];
|
93
|
unset($a_group[$id]['priv'][$_POST['privid']]);
|
94
|
|
95
|
if (is_array($a_group[$id]['member'])) {
|
96
|
foreach ($a_group[$id]['member'] as $uid) {
|
97
|
$user = getUserEntryByUID($uid);
|
98
|
if ($user) {
|
99
|
local_user_set($user);
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
write_config();
|
105
|
$act = "edit";
|
106
|
$savemsg = gettext("Privilege") . " {$privdeleted} " .
|
107
|
gettext("successfully deleted") . "<br />";
|
108
|
}
|
109
|
|
110
|
if ($act == "edit") {
|
111
|
if (isset($id) && isset($a_group[$id])) {
|
112
|
$pconfig['name'] = $a_group[$id]['name'];
|
113
|
$pconfig['gid'] = $a_group[$id]['gid'];
|
114
|
$pconfig['gtype'] = $a_group[$id]['scope'];
|
115
|
$pconfig['description'] = $a_group[$id]['description'];
|
116
|
$pconfig['members'] = $a_group[$id]['member'];
|
117
|
$pconfig['priv'] = $a_group[$id]['priv'];
|
118
|
}
|
119
|
}
|
120
|
|
121
|
if (isset($_POST['dellall_x'])) {
|
122
|
|
123
|
$del_groups = $_POST['delete_check'];
|
124
|
|
125
|
if (!empty($del_groups)) {
|
126
|
foreach ($del_groups as $groupid) {
|
127
|
if (isset($a_group[$groupid]) && $a_group[$groupid]['scope'] != "system") {
|
128
|
conf_mount_rw();
|
129
|
local_group_del($a_group[$groupid]);
|
130
|
conf_mount_ro();
|
131
|
unset($a_group[$groupid]);
|
132
|
}
|
133
|
}
|
134
|
$savemsg = gettext("Selected groups removed successfully!");
|
135
|
write_config($savemsg);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if (isset($_POST['save'])) {
|
140
|
unset($input_errors);
|
141
|
$pconfig = $_POST;
|
142
|
|
143
|
/* input validation */
|
144
|
$reqdfields = explode(" ", "groupname");
|
145
|
$reqdfieldsn = array(gettext("Group Name"));
|
146
|
|
147
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
148
|
|
149
|
if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname'])) {
|
150
|
$input_errors[] = gettext("The group name contains invalid characters.");
|
151
|
}
|
152
|
|
153
|
if (strlen($_POST['groupname']) > 16) {
|
154
|
$input_errors[] = gettext("The group name is longer than 16 characters.");
|
155
|
}
|
156
|
|
157
|
if (!$input_errors && !(isset($id) && $a_group[$id])) {
|
158
|
/* make sure there are no dupes */
|
159
|
foreach ($a_group as $group) {
|
160
|
if ($group['name'] == $_POST['groupname']) {
|
161
|
$input_errors[] = gettext("Another entry with the same group name already exists.");
|
162
|
break;
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
|
167
|
if (!$input_errors) {
|
168
|
$group = array();
|
169
|
if (isset($id) && $a_group[$id]) {
|
170
|
$group = $a_group[$id];
|
171
|
}
|
172
|
|
173
|
$group['name'] = $_POST['groupname'];
|
174
|
$group['description'] = $_POST['description'];
|
175
|
|
176
|
if (empty($_POST['members'])) {
|
177
|
unset($group['member']);
|
178
|
} else if ($group['gid'] != 1998) { // all group
|
179
|
$group['member'] = $_POST['members'];
|
180
|
}
|
181
|
|
182
|
if (isset($id) && $a_group[$id]) {
|
183
|
$a_group[$id] = $group;
|
184
|
} else {
|
185
|
$group['gid'] = $config['system']['nextgid']++;
|
186
|
$a_group[] = $group;
|
187
|
}
|
188
|
|
189
|
conf_mount_rw();
|
190
|
local_group_set($group);
|
191
|
conf_mount_ro();
|
192
|
|
193
|
/* Refresh users in this group since their privileges may have changed. */
|
194
|
if (is_array($group['member'])) {
|
195
|
$a_user = &$config['system']['user'];
|
196
|
foreach ($a_user as & $user) {
|
197
|
if (in_array($user['uid'], $group['member'])) {
|
198
|
local_user_set($user);
|
199
|
}
|
200
|
}
|
201
|
}
|
202
|
|
203
|
write_config();
|
204
|
|
205
|
header("Location: system_groupmanager.php");
|
206
|
exit;
|
207
|
}
|
208
|
}
|
209
|
|
210
|
include("head.inc");
|
211
|
|
212
|
if ($input_errors)
|
213
|
print_input_errors($input_errors);
|
214
|
if ($savemsg)
|
215
|
print_info_box($savemsg);
|
216
|
|
217
|
$tab_array = array();
|
218
|
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
|
219
|
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
|
220
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
221
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
222
|
display_top_tabs($tab_array);
|
223
|
|
224
|
if (!($_GET['act'] == "new" || $_GET['act'] == "edit"))
|
225
|
{
|
226
|
?>
|
227
|
<div class="table-responsive">
|
228
|
<table class="table table-striped table-hover">
|
229
|
<thead>
|
230
|
<tr>
|
231
|
<th><?=gettext("Group name")?></th>
|
232
|
<th><?=gettext("Description")?></th>
|
233
|
<th><?=gettext("Member Count")?></th>
|
234
|
<th></th>
|
235
|
</tr>
|
236
|
</thead>
|
237
|
<tbody>
|
238
|
<?php
|
239
|
foreach($a_group as $i => $group):
|
240
|
if ($group["name"] == "all")
|
241
|
$groupcount = count($config['system']['user']);
|
242
|
else
|
243
|
$groupcount = count($group['member']);
|
244
|
?>
|
245
|
<tr>
|
246
|
<td>
|
247
|
<?=htmlspecialchars($group['name'])?>
|
248
|
</td>
|
249
|
<td>
|
250
|
<?=htmlspecialchars($group['description'])?>
|
251
|
</td>
|
252
|
<td>
|
253
|
<?=$groupcount?>
|
254
|
</td>
|
255
|
<td>
|
256
|
<a href="?act=edit&groupid=<?=$i?>" class="btn btn-xs btn-primary">edit</a>
|
257
|
<?php if($group['scope'] != "system"): ?>
|
258
|
<a href="?act=delgroup&groupid=<?=$i?>&groupname=<?=$group['name']?>" class="btn btn-xs btn-danger">delete</a>
|
259
|
<?php endif;?>
|
260
|
</td>
|
261
|
</tr>
|
262
|
<?php
|
263
|
endforeach;
|
264
|
?>
|
265
|
</tbody>
|
266
|
</table>
|
267
|
</div>
|
268
|
|
269
|
<nav class="action-buttons">
|
270
|
<a href="?act=new" class="btn btn-success">add new</a>
|
271
|
</nav>
|
272
|
<?php
|
273
|
include('foot.inc');
|
274
|
exit;
|
275
|
}
|
276
|
|
277
|
require('classes/Form.class.php');
|
278
|
$form = new Form;
|
279
|
$form->setAction('system_groupmanager.php?act=edit');
|
280
|
$form->addGlobal(new Form_Input(
|
281
|
'groupid',
|
282
|
null,
|
283
|
'hidden',
|
284
|
$id
|
285
|
));
|
286
|
|
287
|
if (isset($id) && $a_group[$id]){
|
288
|
$form->addGlobal(new Form_Input(
|
289
|
'id',
|
290
|
null,
|
291
|
'hidden',
|
292
|
$id
|
293
|
));
|
294
|
|
295
|
$form->addGlobal(new Form_Input(
|
296
|
'gid',
|
297
|
null,
|
298
|
'hidden',
|
299
|
$pconfig['gid']
|
300
|
));
|
301
|
}
|
302
|
|
303
|
$section = new Form_Section('Group properties');
|
304
|
|
305
|
if ($_GET['act'] != "new")
|
306
|
{
|
307
|
$section->addInput(new Form_StaticText(
|
308
|
'Defined by',
|
309
|
strtoupper($pconfig['gtype'])
|
310
|
));
|
311
|
}
|
312
|
|
313
|
$section->addInput($input = new Form_Input(
|
314
|
'groupname',
|
315
|
'Group name',
|
316
|
'text',
|
317
|
$pconfig['name']
|
318
|
));
|
319
|
|
320
|
if ($pconfig['gtype'] == "system")
|
321
|
$input->setReadonly();
|
322
|
|
323
|
$section->addInput(new Form_Input(
|
324
|
'description',
|
325
|
'Description',
|
326
|
'text',
|
327
|
$pconfig['description']
|
328
|
))->setHelp('Group description, for your own information only');
|
329
|
|
330
|
$form->add($section);
|
331
|
if ($pconfig['gid'] != 1998) // all users group
|
332
|
{
|
333
|
$section = new Form_Section('Group Memberships');
|
334
|
|
335
|
$allUsers = array_map(function($u){ return $u['name']; }, $config['system']['user']);
|
336
|
$section->addInput(new Form_Select(
|
337
|
'members',
|
338
|
'Members',
|
339
|
$pconfig['members'],
|
340
|
$allUsers,
|
341
|
true
|
342
|
))->setHelp('Hold down CTRL (pc)/COMMAND (mac) key to select');
|
343
|
|
344
|
$form->add($section);
|
345
|
}
|
346
|
|
347
|
if ($_GET['act'] != "new")
|
348
|
{
|
349
|
$section = new Form_Section('Assigned Privileges');
|
350
|
|
351
|
foreach ((array)$pconfig['priv'] as $i => $priv)
|
352
|
{
|
353
|
// We reverse name and action for readability of longer names
|
354
|
$group = new Form_Group('Revoke privilege');
|
355
|
|
356
|
$group->add(new Form_Checkbox(
|
357
|
'delpriv[]',
|
358
|
null,
|
359
|
$priv_list[ $priv ]['name'],
|
360
|
false,
|
361
|
$i
|
362
|
));
|
363
|
|
364
|
$section->add($group);
|
365
|
}
|
366
|
|
367
|
$section->addInput(new Form_StaticText(
|
368
|
null,
|
369
|
new Form_Button(null, 'grant more privileges', 'system_groupmanager_addprivs.php?groupid='. $id)
|
370
|
));
|
371
|
|
372
|
$form->add($section);
|
373
|
}
|
374
|
|
375
|
print $form;
|
376
|
|
377
|
include('foot.inc');
|