Project

General

Profile

Download (6.27 KB) Statistics
| Branch: | Tag: | Revision:
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
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
55
	$userid = $_POST['userid'];
56

    
57
if (!isset($config['system']['user'][$userid]) && !is_array($config['system']['user'][$userid])) {
58
	pfSenseHeader("system_usermanager.php");
59
	exit;
60
}
61

    
62
$a_user = & $config['system']['user'][$userid];
63

    
64
if (!is_array($a_user['priv']))
65
	$a_user['priv'] = array();
66

    
67
if ($_POST) {
68
	conf_mount_rw();
69

    
70
	unset($input_errors);
71
	$pconfig = $_POST;
72

    
73
	/* input validation */
74
	$reqdfields = explode(" ", "sysprivs");
75
	$reqdfieldsn = array(gettext("Selected privileges"));
76

    
77
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
78

    
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
		$a_user['priv'] = sort_user_privs($a_user['priv']);
96
		local_user_set($a_user);
97
		$retval = write_config();
98
		$savemsg = get_std_save_message($retval);
99
		conf_mount_ro();
100
		
101
		post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid));
102
		
103
		exit;
104
	}
105
	conf_mount_ro();
106
}
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
//<![CDATA[
119

    
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
		$desc = addslashes(preg_replace("/pfSense/i", $g['product_name'], $pdata['descr']));
130
		$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
//]]>
145
</script>
146
<?php
147
	if ($input_errors)
148
		print_input_errors($input_errors);
149
	if ($savemsg)
150
		print_info_box($savemsg);
151
?>
152
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="user manager add privileges">
153
	<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
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
170
						<tr>
171
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
172
							<td width="78%" class="vtable">
173
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35">
174
									<?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
								<br />
183
								<?=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
								<em><?=gettext("Select a privilege from the list above for a description"); ?></em>
190
							</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
								<input name="userid" type="hidden" value="<?=htmlspecialchars($userid);?>" />
199
								<?php endif; ?>
200
							</td>
201
						</tr>
202
					</table>
203
				</form>
204
			</div>
205
		</td>
206
	</tr>
207
</table>
208
<?php include("fend.inc"); ?>
209
</body>
210
</html>
(230-230/256)