Project

General

Profile

Download (6.16 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
31
	pfSense_MODULE:	auth
32
*/
33

    
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
function admusercmp($a, $b) {
42
	return strcasecmp($a['name'], $b['name']);
43
}
44

    
45
function admin_users_sort() {
46
        global $g, $config;
47

    
48
        if (!is_array($config['system']['user']))
49
                return;
50

    
51
        usort($config['system']['user'], "admusercmp");
52
}
53

    
54
require("guiconfig.inc");
55
require("priv.defs.inc");
56
require("priv.inc");
57

    
58
$pgtitle = array("System","User manager","Add privileges");
59

    
60
$userid = $_GET['userid'];
61
if (isset($_POST['userid']))
62
	$userid = $_POST['userid'];
63

    
64
$a_user = & $config['system']['user'][$userid];
65
if (!is_array($a_user)) {
66
	pfSenseHeader("system_usermanager.php?id={$userid}");
67
	exit;
68
}
69

    
70
if (!is_array($a_user)) {
71
	pfSenseHeader("system_usermanager.php");
72
	exit;
73
}
74

    
75
if (!is_array($a_user['priv']))
76
	$a_user['priv'] = array();
77

    
78
if ($_POST) {
79
	conf_mount_rw();
80

    
81
	unset($input_errors);
82
	$pconfig = $_POST;
83

    
84
	/* input validation */
85
	$reqdfields = explode(" ", "sysprivs");
86
	$reqdfieldsn = explode(",", "Selected priveleges");
87

    
88
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
89

    
90
	/* if this is an AJAX caller then handle via JSON */
91
	if(isAjax() && is_array($input_errors)) {
92
		input_errors2Ajax($input_errors);
93
		exit;
94
	}
95

    
96
	if (!$input_errors) {
97

    
98
		if (!is_array($pconfig['sysprivs']))
99
			$pconfig['sysprivs'] = array();
100

    
101
		if (!count($a_user['priv']))
102
			$a_user['priv'] = $pconfig['sysprivs'];
103
		else
104
			$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
105

    
106
		admin_users_sort();
107
		local_user_set($a_user);
108
		$retval = write_config();
109
		$savemsg = get_std_save_message($retval);
110
		conf_mount_ro();
111
		
112
		pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
113
		
114
		exit;
115
	}
116
	conf_mount_ro();
117
}
118

    
119
/* if ajax is calling, give them an update message */
120
if(isAjax())
121
	print_info_box_np($savemsg);
122

    
123
include("head.inc");
124
?>
125

    
126
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
127
<?php include("fbegin.inc"); ?>
128
<script type="text/javascript">
129
<!--
130

    
131
<?php
132

    
133
if (is_array($priv_list)) {
134
	$id = 0;
135

    
136
	$jdescs = "var descs = new Array();\n";
137
	foreach($priv_list as $pname => $pdata) {
138
		if (in_array($pname, $a_user['priv']))
139
			continue;
140
		$desc = addslashes($pdata['descr']);
141
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
142
		$id++;
143
	}
144

    
145
	echo $jdescs;
146
}
147

    
148
?>
149

    
150
function update_description() {
151
	var index = document.iform.sysprivs.selectedIndex;
152
	document.getElementById("pdesc").innerHTML = descs[index];
153
}
154

    
155
//-->
156
</script>
157
<?php
158
	if ($input_errors)
159
		print_input_errors($input_errors);
160
	if ($savemsg)
161
		print_info_box($savemsg);
162
?>
163
<table width="100%" border="0" cellpadding="0" cellspacing="0">
164
	<tr>
165
		<td>
166
		<?php
167
			$tab_array = array();
168
			$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
169
			$tab_array[] = array(gettext("Groups"), false, "system_groupmanager.php");
170
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
171
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
172
			display_top_tabs($tab_array);
173
		?>
174
		</td>
175
	</tr>
176
	<tr>
177
		<td id="mainarea">
178
			<div class="tabcont">
179
				<form action="system_usermanager_addprivs.php" method="post" name="iform" id="iform">
180
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
181
						<tr>
182
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
183
							<td width="78%" class="vtable">
184
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
185
									<?php
186
										foreach($priv_list as $pname => $pdata):
187
											if (in_array($pname, $a_user['priv']))
188
												continue;
189
									?>
190
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
191
									<?php endforeach; ?>
192
								</select>
193
								<br/>
194
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
195
							</td>
196
						</tr>
197
						<tr height="60">
198
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
199
							<td width="78%" valign="top" class="vtable" id="pdesc">
200
								<em>Select a privilege from the list above for a description</em>
201
							</td>
202
						</tr>
203
						<tr>
204
							<td width="22%" valign="top">&nbsp;</td>
205
							<td width="78%">
206
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
207
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
208
								<?php if (isset($userid)): ?>
209
								<input name="userid" type="hidden" value="<?=$userid;?>" />
210
								<?php endif; ?>
211
							</td>
212
						</tr>
213
					</table>
214
				</form>
215
			</div>
216
		</td>
217
	</tr>
218
</table>
219
<?php include("fend.inc"); ?>
220
</body>
221
</html>
(194-194/218)