1
|
<?php
|
2
|
/*
|
3
|
system_usermanager_addprivs.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
* Copyright (c) 2006 Daniel S. Haischt.
|
8
|
*
|
9
|
* Redistribution and use in source and binary forms, with or without modification,
|
10
|
* are permitted provided that the following conditions are met:
|
11
|
*
|
12
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13
|
* this list of conditions and the following disclaimer.
|
14
|
*
|
15
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
* notice, this list of conditions and the following disclaimer in
|
17
|
* the documentation and/or other materials provided with the
|
18
|
* distribution.
|
19
|
*
|
20
|
* 3. All advertising materials mentioning features or use of this software
|
21
|
* must display the following acknowledgment:
|
22
|
* "This product includes software developed by the pfSense Project
|
23
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24
|
*
|
25
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26
|
* endorse or promote products derived from this software without
|
27
|
* prior written permission. For written permission, please contact
|
28
|
* coreteam@pfsense.org.
|
29
|
*
|
30
|
* 5. Products derived from this software may not be called "pfSense"
|
31
|
* nor may "pfSense" appear in their names without prior written
|
32
|
* permission of the Electric Sheep Fencing, LLC.
|
33
|
*
|
34
|
* 6. Redistributions of any form whatsoever must retain the following
|
35
|
* acknowledgment:
|
36
|
*
|
37
|
* "This product includes software developed by the pfSense Project
|
38
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39
|
*
|
40
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52
|
*
|
53
|
* ====================================================================
|
54
|
*
|
55
|
*/
|
56
|
|
57
|
##|+PRIV
|
58
|
##|*IDENT=page-system-usermanager-addprivs
|
59
|
##|*NAME=System: User Manager: Add Privileges
|
60
|
##|*DESCR=Allow access to the 'System: User Manager: Add Privileges' page.
|
61
|
##|*MATCH=system_usermanager_addprivs.php*
|
62
|
##|-PRIV
|
63
|
|
64
|
function admusercmp($a, $b) {
|
65
|
return strcasecmp($a['name'], $b['name']);
|
66
|
}
|
67
|
|
68
|
require("guiconfig.inc");
|
69
|
|
70
|
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Users"), gettext("Add Privileges"));
|
71
|
|
72
|
if (is_numericint($_GET['userid'])) {
|
73
|
$userid = $_GET['userid'];
|
74
|
}
|
75
|
|
76
|
if (isset($_POST['userid']) && is_numericint($_POST['userid'])) {
|
77
|
$userid = $_POST['userid'];
|
78
|
}
|
79
|
|
80
|
if (!isset($config['system']['user'][$userid]) && !is_array($config['system']['user'][$userid])) {
|
81
|
pfSenseHeader("system_usermanager.php");
|
82
|
exit;
|
83
|
}
|
84
|
|
85
|
$a_user = & $config['system']['user'][$userid];
|
86
|
|
87
|
if (!is_array($a_user['priv'])) {
|
88
|
$a_user['priv'] = array();
|
89
|
}
|
90
|
|
91
|
// Make a local copy and sort it
|
92
|
$spriv_list = $priv_list;
|
93
|
uasort($spriv_list, admusercmp);
|
94
|
|
95
|
if ($_POST) {
|
96
|
conf_mount_rw();
|
97
|
|
98
|
unset($input_errors);
|
99
|
$pconfig = $_POST;
|
100
|
|
101
|
/* input validation */
|
102
|
$reqdfields = explode(" ", "sysprivs");
|
103
|
$reqdfieldsn = array(gettext("Selected privileges"));
|
104
|
|
105
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
106
|
|
107
|
/* if this is an AJAX caller then handle via JSON */
|
108
|
if (isAjax() && is_array($input_errors)) {
|
109
|
input_errors2Ajax($input_errors);
|
110
|
exit;
|
111
|
}
|
112
|
|
113
|
if (!$input_errors) {
|
114
|
|
115
|
if (!is_array($pconfig['sysprivs'])) {
|
116
|
$pconfig['sysprivs'] = array();
|
117
|
}
|
118
|
|
119
|
if (!count($a_user['priv'])) {
|
120
|
$a_user['priv'] = $pconfig['sysprivs'];
|
121
|
} else {
|
122
|
$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
|
123
|
}
|
124
|
|
125
|
$a_user['priv'] = sort_user_privs($a_user['priv']);
|
126
|
local_user_set($a_user);
|
127
|
$retval = write_config();
|
128
|
$savemsg = get_std_save_message($retval);
|
129
|
conf_mount_ro();
|
130
|
|
131
|
post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
|
132
|
|
133
|
exit;
|
134
|
}
|
135
|
|
136
|
conf_mount_ro();
|
137
|
}
|
138
|
|
139
|
function build_priv_list() {
|
140
|
global $spriv_list, $a_user;
|
141
|
|
142
|
$list = array();
|
143
|
|
144
|
foreach ($spriv_list as $pname => $pdata) {
|
145
|
if (in_array($pname, $a_user['priv'])) {
|
146
|
continue;
|
147
|
}
|
148
|
|
149
|
$list[$pname] = $pdata['name'];
|
150
|
}
|
151
|
|
152
|
return($list);
|
153
|
}
|
154
|
|
155
|
/* if ajax is calling, give them an update message */
|
156
|
if (isAjax()) {
|
157
|
print_info_box($savemsg, 'success');
|
158
|
}
|
159
|
|
160
|
include("head.inc");
|
161
|
|
162
|
if ($input_errors) {
|
163
|
print_input_errors($input_errors);
|
164
|
}
|
165
|
|
166
|
if ($savemsg) {
|
167
|
print_info_box($savemsg, 'success');
|
168
|
}
|
169
|
|
170
|
$tab_array = array();
|
171
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
172
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
173
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
174
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
175
|
display_top_tabs($tab_array);
|
176
|
|
177
|
$form = new Form();
|
178
|
|
179
|
$section = new Form_Section('User privileges');
|
180
|
|
181
|
$section->addInput(new Form_Select(
|
182
|
'sysprivs',
|
183
|
'Assigned privileges',
|
184
|
null,
|
185
|
build_priv_list(),
|
186
|
true
|
187
|
))->addClass('multiselect')
|
188
|
->setHelp('Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items');
|
189
|
// ->setAttribute('style', 'height:400px;');
|
190
|
|
191
|
|
192
|
$section->addInput(new Form_Input(
|
193
|
'filtertxt',
|
194
|
'Filter',
|
195
|
'text',
|
196
|
null
|
197
|
))->setHelp('Show only the choices containing this term');
|
198
|
|
199
|
$btnfilter = new Form_Button(
|
200
|
'btnfilter',
|
201
|
'Filter',
|
202
|
null,
|
203
|
'fa-filter'
|
204
|
);
|
205
|
|
206
|
$btnfilter->addClass('btn btn-info');
|
207
|
|
208
|
$form->addGlobal($btnfilter);
|
209
|
|
210
|
$btnclear = new Form_Button(
|
211
|
'btnclear',
|
212
|
'Clear',
|
213
|
null,
|
214
|
'fa-times'
|
215
|
);
|
216
|
|
217
|
$btnclear->addClass('btn btn-warning');
|
218
|
|
219
|
$form->addGlobal($btnclear);
|
220
|
|
221
|
if (isset($userid)) {
|
222
|
$section->addInput(new Form_Input(
|
223
|
'userid',
|
224
|
null,
|
225
|
'hidden',
|
226
|
$userid
|
227
|
));
|
228
|
}
|
229
|
|
230
|
$form->add($section);
|
231
|
|
232
|
print($form);
|
233
|
?>
|
234
|
|
235
|
<div class="panel panel-body alert-info col-sm-10 col-sm-offset-2" id="pdesc">Select a privilege from the list above for a description</div>
|
236
|
|
237
|
<script type="text/javascript">
|
238
|
//<![CDATA[
|
239
|
events.push(function() {
|
240
|
|
241
|
<?php
|
242
|
|
243
|
// Build a list of privilege descriptions
|
244
|
if (is_array($spriv_list)) {
|
245
|
$id = 0;
|
246
|
|
247
|
$jdescs = "var descs = new Array();\n";
|
248
|
foreach ($spriv_list as $pname => $pdata) {
|
249
|
if (in_array($pname, $a_user['priv'])) {
|
250
|
continue;
|
251
|
}
|
252
|
$desc = addslashes(preg_replace("/pfSense/i", $g['product_name'], $pdata['descr']));
|
253
|
$jdescs .= "descs[{$id}] = '{$desc}';\n";
|
254
|
$id++;
|
255
|
}
|
256
|
|
257
|
echo $jdescs;
|
258
|
}
|
259
|
?>
|
260
|
// Set the number of options to display
|
261
|
$('.multiselect').attr("size","20");
|
262
|
|
263
|
// When the 'sysprivs" selector is clicked, we display a description
|
264
|
$('.multiselect').click(function() {
|
265
|
$('#pdesc').html('<span class="text-info">' + descs[$(this).children('option:selected').index()] + '</span>');
|
266
|
});
|
267
|
|
268
|
$('#btnfilter').prop('type', 'button');
|
269
|
|
270
|
$('#btnfilter').click(function() {
|
271
|
searchterm = $('#filtertxt').val().toLowerCase();
|
272
|
|
273
|
$(".multiselect > option").each(function() {
|
274
|
if (this.text.toLowerCase().indexOf(searchterm) > -1 ) {
|
275
|
$(this).show();
|
276
|
} else {
|
277
|
$(this).hide();
|
278
|
}
|
279
|
});
|
280
|
});
|
281
|
|
282
|
$('#btnclear').prop('type', 'button');
|
283
|
|
284
|
$('#btnclear').click(function() {
|
285
|
$(".multiselect > option").each(function() {
|
286
|
$(this).show();
|
287
|
});
|
288
|
});
|
289
|
|
290
|
$('#filtertxt').keypress(function(e) {
|
291
|
if(e.which == 13) {
|
292
|
e.preventDefault();
|
293
|
$('#btnfilter').trigger('click');
|
294
|
}
|
295
|
});
|
296
|
|
297
|
// On submit unhide all options (or else they will not submit)
|
298
|
$('form').submit(function() {
|
299
|
$(".multiselect > option").each(function() {
|
300
|
$(this).show();
|
301
|
});
|
302
|
});
|
303
|
});
|
304
|
//]]>
|
305
|
</script>
|
306
|
|
307
|
<?php include("foot.inc");
|