Project

General

Profile

Download (5.22 KB) Statistics
| Branch: | Tag: | Revision:
1 6b07c15a Matthew Grooms
<?php
2
/* $Id$ */
3
/*
4
	system_usermanager_addprivs.php
5
6 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 29aef6c4 Jim Thompson
	All rights reserved.
8
9 6b07c15a Matthew Grooms
	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 1d333258 Scott Ullrich
/*
34 aa3c6f56 sbeaver
	pfSense_MODULE: auth
35 1d333258 Scott Ullrich
*/
36 6b07c15a Matthew Grooms
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 4504a769 Ermal Lu?i
function admusercmp($a, $b) {
45
	return strcasecmp($a['name'], $b['name']);
46
}
47
48 6b07c15a Matthew Grooms
require("guiconfig.inc");
49
50
$pgtitle = array("System","User manager","Add privileges");
51
52 e41ec584 Renato Botelho
if (is_numericint($_GET['userid']))
53
	$userid = $_GET['userid'];
54 aa3c6f56 sbeaver
55 e41ec584 Renato Botelho
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
56 6b07c15a Matthew Grooms
	$userid = $_POST['userid'];
57
58 1a6769a6 Renato Botelho
if (!isset($config['system']['user'][$userid]) && !is_array($config['system']['user'][$userid])) {
59 6b07c15a Matthew Grooms
	pfSenseHeader("system_usermanager.php");
60
	exit;
61
}
62
63 1a6769a6 Renato Botelho
$a_user = & $config['system']['user'][$userid];
64
65 6b07c15a Matthew Grooms
if (!is_array($a_user['priv']))
66
	$a_user['priv'] = array();
67
68
if ($_POST) {
69 dff1a09d Scott Ullrich
	conf_mount_rw();
70 6b07c15a Matthew Grooms
71
	unset($input_errors);
72
	$pconfig = $_POST;
73
74
	/* input validation */
75
	$reqdfields = explode(" ", "sysprivs");
76 e30050b6 Phil Davis
	$reqdfieldsn = array(gettext("Selected privileges"));
77 6b07c15a Matthew Grooms
78 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
79 6b07c15a Matthew Grooms
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 3f109700 jim-p
		$a_user['priv'] = sort_user_privs($a_user['priv']);
97 659fa7f2 Matthew Grooms
		local_user_set($a_user);
98 6b07c15a Matthew Grooms
		$retval = write_config();
99
		$savemsg = get_std_save_message($retval);
100 dff1a09d Scott Ullrich
		conf_mount_ro();
101 aa3c6f56 sbeaver
102 1a6769a6 Renato Botelho
		post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
103 aa3c6f56 sbeaver
104 6b07c15a Matthew Grooms
		exit;
105
	}
106 aa3c6f56 sbeaver
107 dff1a09d Scott Ullrich
	conf_mount_ro();
108 6b07c15a Matthew Grooms
}
109
110 aa3c6f56 sbeaver
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 6b07c15a Matthew Grooms
/* 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 aa3c6f56 sbeaver
if ($input_errors)
132
	print_input_errors($input_errors);
133 6b07c15a Matthew Grooms
134 aa3c6f56 sbeaver
if ($savemsg)
135
	print_info_box($savemsg, 'success');
136 6b07c15a Matthew Grooms
137 aa3c6f56 sbeaver
$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 6b07c15a Matthew Grooms
144 aa3c6f56 sbeaver
require('classes/Form.class.php');
145
146
$form = new Form();
147
148
$section = new Form_Section('User privileges');
149 6b07c15a Matthew Grooms
150 aa3c6f56 sbeaver
$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 6b07c15a Matthew Grooms
}
166
167 aa3c6f56 sbeaver
$form->add($section);
168
169
print($form);
170 6b07c15a Matthew Grooms
?>
171
172 aa3c6f56 sbeaver
<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 6b07c15a Matthew Grooms
178
<?php
179 aa3c6f56 sbeaver
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 6b07c15a Matthew Grooms
?>
197 aa3c6f56 sbeaver
	// 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");