1 |
6b07c15a
|
Matthew Grooms
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
system_usermanager_addprivs.php
|
5 |
|
|
|
6 |
|
|
Copyright (C) 2006 Daniel S. Haischt.
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, 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 the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
|
|
*/
|
30 |
1d333258
|
Scott Ullrich
|
/*
|
31 |
|
|
pfSense_MODULE: auth
|
32 |
|
|
*/
|
33 |
6b07c15a
|
Matthew Grooms
|
|
34 |
|
|
##|+PRIV
|
35 |
|
|
##|*IDENT=page-system-usermanager-addprivs
|
36 |
|
|
##|*NAME=System: User Manager: Add Privileges page
|
37 |
|
|
##|*DESCR=Allow access to the 'System: User Manager: Add Privileges' page.
|
38 |
|
|
##|*MATCH=system_usermanager_addprivs.php*
|
39 |
|
|
##|-PRIV
|
40 |
|
|
|
41 |
4504a769
|
Ermal Lu?i
|
function admusercmp($a, $b) {
|
42 |
|
|
return strcasecmp($a['name'], $b['name']);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
0d64af59
|
Ermal Lu?i
|
function admin_users_sort() {
|
46 |
|
|
global $g, $config;
|
47 |
|
|
|
48 |
|
|
if (!is_array($config['system']['user']))
|
49 |
|
|
return;
|
50 |
|
|
|
51 |
4504a769
|
Ermal Lu?i
|
usort($config['system']['user'], "admusercmp");
|
52 |
0d64af59
|
Ermal Lu?i
|
}
|
53 |
6b07c15a
|
Matthew Grooms
|
|
54 |
|
|
require("guiconfig.inc");
|
55 |
|
|
|
56 |
|
|
$pgtitle = array("System","User manager","Add privileges");
|
57 |
|
|
|
58 |
|
|
$userid = $_GET['userid'];
|
59 |
|
|
if (isset($_POST['userid']))
|
60 |
|
|
$userid = $_POST['userid'];
|
61 |
|
|
|
62 |
|
|
$a_user = & $config['system']['user'][$userid];
|
63 |
|
|
if (!is_array($a_user)) {
|
64 |
|
|
pfSenseHeader("system_usermanager.php?id={$userid}");
|
65 |
|
|
exit;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
if (!is_array($a_user)) {
|
69 |
|
|
pfSenseHeader("system_usermanager.php");
|
70 |
|
|
exit;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
if (!is_array($a_user['priv']))
|
74 |
|
|
$a_user['priv'] = array();
|
75 |
|
|
|
76 |
|
|
if ($_POST) {
|
77 |
dff1a09d
|
Scott Ullrich
|
conf_mount_rw();
|
78 |
6b07c15a
|
Matthew Grooms
|
|
79 |
|
|
unset($input_errors);
|
80 |
|
|
$pconfig = $_POST;
|
81 |
|
|
|
82 |
|
|
/* input validation */
|
83 |
|
|
$reqdfields = explode(" ", "sysprivs");
|
84 |
|
|
$reqdfieldsn = explode(",", "Selected priveleges");
|
85 |
|
|
|
86 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
87 |
|
|
|
88 |
|
|
/* if this is an AJAX caller then handle via JSON */
|
89 |
|
|
if(isAjax() && is_array($input_errors)) {
|
90 |
|
|
input_errors2Ajax($input_errors);
|
91 |
|
|
exit;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
if (!$input_errors) {
|
95 |
|
|
|
96 |
|
|
if (!is_array($pconfig['sysprivs']))
|
97 |
|
|
$pconfig['sysprivs'] = array();
|
98 |
|
|
|
99 |
|
|
if (!count($a_user['priv']))
|
100 |
|
|
$a_user['priv'] = $pconfig['sysprivs'];
|
101 |
|
|
else
|
102 |
|
|
$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
|
103 |
|
|
|
104 |
0d64af59
|
Ermal Lu?i
|
admin_users_sort();
|
105 |
659fa7f2
|
Matthew Grooms
|
local_user_set($a_user);
|
106 |
6b07c15a
|
Matthew Grooms
|
$retval = write_config();
|
107 |
|
|
$savemsg = get_std_save_message($retval);
|
108 |
dff1a09d
|
Scott Ullrich
|
conf_mount_ro();
|
109 |
|
|
|
110 |
6b07c15a
|
Matthew Grooms
|
pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
|
111 |
dff1a09d
|
Scott Ullrich
|
|
112 |
6b07c15a
|
Matthew Grooms
|
exit;
|
113 |
|
|
}
|
114 |
dff1a09d
|
Scott Ullrich
|
conf_mount_ro();
|
115 |
6b07c15a
|
Matthew Grooms
|
}
|
116 |
|
|
|
117 |
|
|
/* if ajax is calling, give them an update message */
|
118 |
|
|
if(isAjax())
|
119 |
|
|
print_info_box_np($savemsg);
|
120 |
|
|
|
121 |
|
|
include("head.inc");
|
122 |
|
|
?>
|
123 |
|
|
|
124 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
125 |
|
|
<?php include("fbegin.inc"); ?>
|
126 |
|
|
<script type="text/javascript">
|
127 |
|
|
<!--
|
128 |
|
|
|
129 |
|
|
<?php
|
130 |
|
|
|
131 |
|
|
if (is_array($priv_list)) {
|
132 |
|
|
$id = 0;
|
133 |
|
|
|
134 |
|
|
$jdescs = "var descs = new Array();\n";
|
135 |
|
|
foreach($priv_list as $pname => $pdata) {
|
136 |
|
|
if (in_array($pname, $a_user['priv']))
|
137 |
|
|
continue;
|
138 |
|
|
$desc = addslashes($pdata['descr']);
|
139 |
|
|
$jdescs .= "descs[{$id}] = '{$desc}';\n";
|
140 |
|
|
$id++;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
echo $jdescs;
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
?>
|
147 |
|
|
|
148 |
|
|
function update_description() {
|
149 |
|
|
var index = document.iform.sysprivs.selectedIndex;
|
150 |
|
|
document.getElementById("pdesc").innerHTML = descs[index];
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
//-->
|
154 |
|
|
</script>
|
155 |
|
|
<?php
|
156 |
|
|
if ($input_errors)
|
157 |
|
|
print_input_errors($input_errors);
|
158 |
|
|
if ($savemsg)
|
159 |
|
|
print_info_box($savemsg);
|
160 |
|
|
?>
|
161 |
e30001cf
|
Matthew Grooms
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
162 |
|
|
<tr>
|
163 |
|
|
<td>
|
164 |
|
|
<?php
|
165 |
|
|
$tab_array = array();
|
166 |
|
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
167 |
|
|
$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
|
168 |
|
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
169 |
|
|
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
|
170 |
|
|
display_top_tabs($tab_array);
|
171 |
|
|
?>
|
172 |
|
|
</td>
|
173 |
|
|
</tr>
|
174 |
|
|
<tr>
|
175 |
|
|
<td id="mainarea">
|
176 |
|
|
<div class="tabcont">
|
177 |
|
|
<form action="system_usermanager_addprivs.php" method="post" name="iform" id="iform">
|
178 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
179 |
|
|
<tr>
|
180 |
|
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
|
181 |
|
|
<td width="78%" class="vtable">
|
182 |
|
|
<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
|
183 |
|
|
<?php
|
184 |
|
|
foreach($priv_list as $pname => $pdata):
|
185 |
|
|
if (in_array($pname, $a_user['priv']))
|
186 |
|
|
continue;
|
187 |
|
|
?>
|
188 |
|
|
<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
|
189 |
|
|
<?php endforeach; ?>
|
190 |
|
|
</select>
|
191 |
|
|
<br/>
|
192 |
|
|
<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
|
193 |
|
|
</td>
|
194 |
|
|
</tr>
|
195 |
|
|
<tr height="60">
|
196 |
|
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
197 |
|
|
<td width="78%" valign="top" class="vtable" id="pdesc">
|
198 |
|
|
<em>Select a privilege from the list above for a description</em>
|
199 |
|
|
</td>
|
200 |
|
|
</tr>
|
201 |
|
|
<tr>
|
202 |
|
|
<td width="22%" valign="top"> </td>
|
203 |
|
|
<td width="78%">
|
204 |
|
|
<input id="submitt" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
205 |
|
|
<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
|
206 |
|
|
<?php if (isset($userid)): ?>
|
207 |
|
|
<input name="userid" type="hidden" value="<?=$userid;?>" />
|
208 |
|
|
<?php endif; ?>
|
209 |
|
|
</td>
|
210 |
|
|
</tr>
|
211 |
|
|
</table>
|
212 |
|
|
</form>
|
213 |
|
|
</div>
|
214 |
|
|
</td>
|
215 |
|
|
</tr>
|
216 |
|
|
</table>
|
217 |
6b07c15a
|
Matthew Grooms
|
<?php include("fend.inc"); ?>
|
218 |
|
|
</body>
|
219 |
|
|
</html>
|