Project

General

Profile

Download (6.27 KB) Statistics
| Branch: | Tag: | Revision:
1 6b07c15a Matthew Grooms
<?php
2
/* $Id$ */
3
/*
4
	system_usermanager_addprivs.php
5
6 6317d31d 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
	pfSense_MODULE:	auth
35
*/
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
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
55 6b07c15a Matthew Grooms
	$userid = $_POST['userid'];
56
57 1a6769a6 Renato Botelho
if (!isset($config['system']['user'][$userid]) && !is_array($config['system']['user'][$userid])) {
58 6b07c15a Matthew Grooms
	pfSenseHeader("system_usermanager.php");
59
	exit;
60
}
61
62 1a6769a6 Renato Botelho
$a_user = & $config['system']['user'][$userid];
63
64 6b07c15a Matthew Grooms
if (!is_array($a_user['priv']))
65
	$a_user['priv'] = array();
66
67
if ($_POST) {
68 dff1a09d Scott Ullrich
	conf_mount_rw();
69 6b07c15a Matthew Grooms
70
	unset($input_errors);
71
	$pconfig = $_POST;
72
73
	/* input validation */
74
	$reqdfields = explode(" ", "sysprivs");
75 92936289 Carlos Eduardo Ramos
	$reqdfieldsn = array(gettext("Selected priveleges"));
76 6b07c15a Matthew Grooms
77 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
78 6b07c15a Matthew Grooms
79
	/* if this is an AJAX caller then handle via JSON */
80
	if(isAjax() && is_array($input_errors)) {
81
		input_errors2Ajax($input_errors);
82
		exit;
83
	}
84
85
	if (!$input_errors) {
86
87
		if (!is_array($pconfig['sysprivs']))
88
			$pconfig['sysprivs'] = array();
89
90
		if (!count($a_user['priv']))
91
			$a_user['priv'] = $pconfig['sysprivs'];
92
		else
93
			$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
94
95 3f109700 jim-p
		$a_user['priv'] = sort_user_privs($a_user['priv']);
96 659fa7f2 Matthew Grooms
		local_user_set($a_user);
97 6b07c15a Matthew Grooms
		$retval = write_config();
98
		$savemsg = get_std_save_message($retval);
99 dff1a09d Scott Ullrich
		conf_mount_ro();
100
		
101 1a6769a6 Renato Botelho
		post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
102 dff1a09d Scott Ullrich
		
103 6b07c15a Matthew Grooms
		exit;
104
	}
105 dff1a09d Scott Ullrich
	conf_mount_ro();
106 6b07c15a Matthew Grooms
}
107
108
/* if ajax is calling, give them an update message */
109
if(isAjax())
110
	print_info_box_np($savemsg);
111
112
include("head.inc");
113
?>
114
115
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
116
<?php include("fbegin.inc"); ?>
117
<script type="text/javascript">
118 8b60b40f Colin Fleming
//<![CDATA[
119 6b07c15a Matthew Grooms
120
<?php
121
122
if (is_array($priv_list)) {
123
	$id = 0;
124
125
	$jdescs = "var descs = new Array();\n";
126
	foreach($priv_list as $pname => $pdata) {
127
		if (in_array($pname, $a_user['priv']))
128
			continue;
129 e811fcbe Warren Baker
		$desc = addslashes(preg_replace("/pfSense/i", $g['product_name'], $pdata['descr']));
130 6b07c15a Matthew Grooms
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
131
		$id++;
132
	}
133
134
	echo $jdescs;
135
}
136
137
?>
138
139
function update_description() {
140
	var index = document.iform.sysprivs.selectedIndex;
141
	document.getElementById("pdesc").innerHTML = descs[index];
142
}
143
144 8b60b40f Colin Fleming
//]]>
145 6b07c15a Matthew Grooms
</script>
146
<?php
147
	if ($input_errors)
148
		print_input_errors($input_errors);
149
	if ($savemsg)
150
		print_info_box($savemsg);
151
?>
152 8b60b40f Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="user manager add priveleges">
153 e30001cf Matthew Grooms
	<tr>
154
		<td>
155
		<?php
156
			$tab_array = array();
157
			$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
158
			$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
159
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
160
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
161
			display_top_tabs($tab_array);
162
		?>
163
		</td>
164
	</tr>
165
	<tr>
166
		<td id="mainarea">
167
			<div class="tabcont">
168
				<form action="system_usermanager_addprivs.php" method="post" name="iform" id="iform">
169 8b60b40f Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
170 e30001cf Matthew Grooms
						<tr>
171
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
172
							<td width="78%" class="vtable">
173 8b60b40f Colin Fleming
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35">
174 e30001cf Matthew Grooms
									<?php
175
										foreach($priv_list as $pname => $pdata):
176
											if (in_array($pname, $a_user['priv']))
177
												continue;
178
									?>
179
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
180
									<?php endforeach; ?>
181
								</select>
182 8cd558b6 ayvis
								<br />
183 e30001cf Matthew Grooms
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
184
							</td>
185
						</tr>
186
						<tr height="60">
187
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
188
							<td width="78%" valign="top" class="vtable" id="pdesc">
189 92936289 Carlos Eduardo Ramos
								<em><?=gettext("Select a privilege from the list above for a description"); ?></em>
190 e30001cf Matthew Grooms
							</td>
191
						</tr>
192
						<tr>
193
							<td width="22%" valign="top">&nbsp;</td>
194
							<td width="78%">
195
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
196
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
197
								<?php if (isset($userid)): ?>
198 e41ec584 Renato Botelho
								<input name="userid" type="hidden" value="<?=htmlspecialchars($userid);?>" />
199 e30001cf Matthew Grooms
								<?php endif; ?>
200
							</td>
201
						</tr>
202
					</table>
203
				</form>
204
			</div>
205
		</td>
206
	</tr>
207
</table>
208 6b07c15a Matthew Grooms
<?php include("fend.inc"); ?>
209
</body>
210
</html>