1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_groupmanager_addprivs.php
|
5
|
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
Copyright (C) 2006 Daniel S. Haischt.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
/*
|
32
|
pfSense_MODULE: auth
|
33
|
*/
|
34
|
|
35
|
##|+PRIV
|
36
|
##|*IDENT=page-system-groupmanager-addprivs
|
37
|
##|*NAME=System: Group Manager: Add Privileges page
|
38
|
##|*DESCR=Allow access to the 'System: Group Manager: Add Privileges' page.
|
39
|
##|*MATCH=system_groupmanager_addprivs.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
function cpusercmp($a, $b) {
|
43
|
return strcasecmp($a['name'], $b['name']);
|
44
|
}
|
45
|
|
46
|
function admin_groups_sort() {
|
47
|
global $config;
|
48
|
|
49
|
if (!is_array($config['system']['group']))
|
50
|
return;
|
51
|
|
52
|
usort($config['system']['group'], "cpusercmp");
|
53
|
}
|
54
|
|
55
|
require("guiconfig.inc");
|
56
|
|
57
|
$pgtitle = array(gettext("System"),gettext("Group manager"),gettext("Add privileges"));
|
58
|
|
59
|
if (is_numericint($_GET['groupid']))
|
60
|
$groupid = $_GET['groupid'];
|
61
|
elseif (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
|
62
|
$groupid = $_POST['groupid'];
|
63
|
|
64
|
$a_group = & $config['system']['group'][$groupid];
|
65
|
|
66
|
if (!is_array($a_group)) {
|
67
|
pfSenseHeader("system_groupmanager.php?id={$groupid}");
|
68
|
exit;
|
69
|
}
|
70
|
|
71
|
if (!is_array($a_group['priv']))
|
72
|
$a_group['priv'] = array();
|
73
|
|
74
|
if ($_POST) {
|
75
|
|
76
|
unset($input_errors);
|
77
|
$pconfig = $_POST;
|
78
|
|
79
|
/* input validation */
|
80
|
$reqdfields = explode(" ", "sysprivs");
|
81
|
$reqdfieldsn = array(gettext("Selected privileges"));
|
82
|
|
83
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
84
|
|
85
|
/* if this is an AJAX caller then handle via JSON */
|
86
|
if(isAjax() && is_array($input_errors)) {
|
87
|
input_errors2Ajax($input_errors);
|
88
|
exit;
|
89
|
}
|
90
|
|
91
|
if (!$input_errors) {
|
92
|
|
93
|
if (!is_array($pconfig['sysprivs']))
|
94
|
$pconfig['sysprivs'] = array();
|
95
|
|
96
|
if (!count($a_group['priv']))
|
97
|
$a_group['priv'] = $pconfig['sysprivs'];
|
98
|
else
|
99
|
$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
|
100
|
|
101
|
if (is_array($a_group['member'])) {
|
102
|
foreach ($a_group['member'] as $uid) {
|
103
|
$user = getUserEntryByUID($uid);
|
104
|
if ($user)
|
105
|
local_user_set($user);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
admin_groups_sort();
|
110
|
|
111
|
$retval = write_config();
|
112
|
$savemsg = get_std_save_message($retval);
|
113
|
|
114
|
pfSenseHeader("system_groupmanager.php?act=edit&groupid={$groupid}");
|
115
|
exit;
|
116
|
}
|
117
|
}
|
118
|
|
119
|
/* if ajax is calling, give them an update message */
|
120
|
if(isAjax())
|
121
|
print_info_box_np($savemsg);
|
122
|
|
123
|
include("head.inc");
|
124
|
|
125
|
if ($input_errors)
|
126
|
print_input_errors($input_errors);
|
127
|
if ($savemsg)
|
128
|
print_info_box($savemsg);
|
129
|
|
130
|
$tab_array = array();
|
131
|
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
|
132
|
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
|
133
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
134
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
135
|
display_top_tabs($tab_array);
|
136
|
|
137
|
require('classes/Form.class.php');
|
138
|
$form = new Form;
|
139
|
if (isset($groupid))
|
140
|
{
|
141
|
$form->addGlobal(new Form_Input(
|
142
|
'groupid',
|
143
|
null,
|
144
|
'hidden',
|
145
|
$groupid
|
146
|
));
|
147
|
}
|
148
|
|
149
|
$section = new Form_Section('Add privileges for '. $a_group['name']);
|
150
|
|
151
|
$priv_list = array_map(function($p){ return $p['name']; }, $priv_list);
|
152
|
asort($priv_list);
|
153
|
|
154
|
$section->addInput(new Form_Select(
|
155
|
'sysprivs',
|
156
|
'Assigned privileges',
|
157
|
$a_group['priv'],
|
158
|
$priv_list,
|
159
|
true
|
160
|
))->setHelp('Hold down CTRL (pc)/COMMAND (mac) key to select');
|
161
|
|
162
|
$form->add($section);
|
163
|
|
164
|
print $form;
|
165
|
|
166
|
include('foot.inc');
|