1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_usermanager_addprivs.php
|
5
|
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
All rights reserved.
|
8
|
|
9
|
Copyright (C) 2006 Daniel S. Haischt.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
/*
|
34
|
pfSense_MODULE: auth
|
35
|
*/
|
36
|
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-system-usermanager-addprivs
|
39
|
##|*NAME=System: User Manager: Add Privileges page
|
40
|
##|*DESCR=Allow access to the 'System: User Manager: Add Privileges' page.
|
41
|
##|*MATCH=system_usermanager_addprivs.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
function admusercmp($a, $b) {
|
45
|
return strcasecmp($a['name'], $b['name']);
|
46
|
}
|
47
|
|
48
|
require("guiconfig.inc");
|
49
|
|
50
|
$pgtitle = array("System","User manager","Add privileges");
|
51
|
|
52
|
if (is_numericint($_GET['userid']))
|
53
|
$userid = $_GET['userid'];
|
54
|
|
55
|
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
|
56
|
$userid = $_POST['userid'];
|
57
|
|
58
|
if (!isset($config['system']['user'][$userid]) && !is_array($config['system']['user'][$userid])) {
|
59
|
pfSenseHeader("system_usermanager.php");
|
60
|
exit;
|
61
|
}
|
62
|
|
63
|
$a_user = & $config['system']['user'][$userid];
|
64
|
|
65
|
if (!is_array($a_user['priv']))
|
66
|
$a_user['priv'] = array();
|
67
|
|
68
|
if ($_POST) {
|
69
|
conf_mount_rw();
|
70
|
|
71
|
unset($input_errors);
|
72
|
$pconfig = $_POST;
|
73
|
|
74
|
/* input validation */
|
75
|
$reqdfields = explode(" ", "sysprivs");
|
76
|
$reqdfieldsn = array(gettext("Selected privileges"));
|
77
|
|
78
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
79
|
|
80
|
/* if this is an AJAX caller then handle via JSON */
|
81
|
if(isAjax() && is_array($input_errors)) {
|
82
|
input_errors2Ajax($input_errors);
|
83
|
exit;
|
84
|
}
|
85
|
|
86
|
if (!$input_errors) {
|
87
|
|
88
|
if (!is_array($pconfig['sysprivs']))
|
89
|
$pconfig['sysprivs'] = array();
|
90
|
|
91
|
if (!count($a_user['priv']))
|
92
|
$a_user['priv'] = $pconfig['sysprivs'];
|
93
|
else
|
94
|
$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
|
95
|
|
96
|
$a_user['priv'] = sort_user_privs($a_user['priv']);
|
97
|
local_user_set($a_user);
|
98
|
$retval = write_config();
|
99
|
$savemsg = get_std_save_message($retval);
|
100
|
conf_mount_ro();
|
101
|
|
102
|
post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
|
103
|
|
104
|
exit;
|
105
|
}
|
106
|
|
107
|
conf_mount_ro();
|
108
|
}
|
109
|
|
110
|
function build_priv_list() {
|
111
|
global $priv_list, $a_user;
|
112
|
|
113
|
$list = array();
|
114
|
|
115
|
foreach($priv_list as $pname => $pdata) {
|
116
|
if (in_array($pname, $a_user['priv']))
|
117
|
continue;
|
118
|
|
119
|
$list[$pname] = $pdata['name'];
|
120
|
}
|
121
|
|
122
|
return($list);
|
123
|
}
|
124
|
|
125
|
/* if ajax is calling, give them an update message */
|
126
|
if(isAjax())
|
127
|
print_info_box_np($savemsg);
|
128
|
|
129
|
include("head.inc");
|
130
|
|
131
|
if ($input_errors)
|
132
|
print_input_errors($input_errors);
|
133
|
|
134
|
if ($savemsg)
|
135
|
print_info_box($savemsg, 'success');
|
136
|
|
137
|
$tab_array = array();
|
138
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
139
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
140
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
141
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
142
|
display_top_tabs($tab_array);
|
143
|
|
144
|
require('classes/Form.class.php');
|
145
|
|
146
|
$form = new Form();
|
147
|
|
148
|
$section = new Form_Section('User privileges');
|
149
|
|
150
|
$section->addInput(new Form_Select(
|
151
|
'sysprivs',
|
152
|
'System',
|
153
|
null,
|
154
|
build_priv_list(),
|
155
|
true
|
156
|
))->addClass('multiselect')->setHelp('Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items');
|
157
|
|
158
|
if (isset($userid)) {
|
159
|
$section->addInput(new Form_Input(
|
160
|
'userid',
|
161
|
null,
|
162
|
'hidden',
|
163
|
$userid
|
164
|
));
|
165
|
}
|
166
|
|
167
|
$form->add($section);
|
168
|
|
169
|
print($form);
|
170
|
?>
|
171
|
|
172
|
<div class="panel panel-body alert-info" id="pdesc">Select a privilege from the list above for a description"</div>
|
173
|
|
174
|
<script>
|
175
|
//<![CDATA[
|
176
|
events.push(function(){
|
177
|
|
178
|
<?php
|
179
|
|
180
|
// Build a list of privilege descriptions
|
181
|
if (is_array($priv_list)) {
|
182
|
$id = 0;
|
183
|
|
184
|
$jdescs = "var descs = new Array();\n";
|
185
|
foreach($priv_list as $pname => $pdata) {
|
186
|
if (in_array($pname, $a_user['priv']))
|
187
|
continue;
|
188
|
$desc = addslashes(preg_replace("/pfSense/i", $g['product_name'], $pdata['descr']));
|
189
|
$jdescs .= "descs[{$id}] = '{$desc}';\n";
|
190
|
$id++;
|
191
|
}
|
192
|
|
193
|
echo $jdescs;
|
194
|
}
|
195
|
|
196
|
?>
|
197
|
// Set the number of options to display
|
198
|
$('.multiselect').attr("size","20");
|
199
|
|
200
|
// When the 'sysprivs" selector is clicked, we display a description
|
201
|
$('.multiselect').click(function() {
|
202
|
$('#pdesc').html(descs[$(this).children('option:selected').index()]);
|
203
|
});
|
204
|
});
|
205
|
//]]>
|
206
|
</script>
|
207
|
|
208
|
<?php include("foot.inc");
|