Project

General

Profile

Download (6.1 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
##|+PRIV
32
##|*IDENT=page-system-usermanager-addprivs
33
##|*NAME=System: User Manager: Add Privileges page
34
##|*DESCR=Allow access to the 'System: User Manager: Add Privileges' page.
35
##|*MATCH=system_usermanager_addprivs.php*
36
##|-PRIV
37

    
38
function admusercmp($a, $b) {
39
	return strcasecmp($a['name'], $b['name']);
40
}
41

    
42
function admin_users_sort() {
43
        global $g, $config;
44

    
45
        if (!is_array($config['system']['user']))
46
                return;
47

    
48
        usort($config['system']['user'], "admusercmp");
49
}
50

    
51
require("guiconfig.inc");
52

    
53
$pgtitle = array("System","User manager","Add privileges");
54

    
55
$userid = $_GET['userid'];
56
if (isset($_POST['userid']))
57
	$userid = $_POST['userid'];
58

    
59
admin_users_sort();
60
$a_user = & $config['system']['user'][$userid];
61
if (!is_array($a_user)) {
62
	pfSenseHeader("system_usermanager.php?id={$userid}");
63
	exit;
64
}
65

    
66
if (!is_array($a_user)) {
67
	pfSenseHeader("system_usermanager.php");
68
	exit;
69
}
70

    
71
if (!is_array($a_user['priv']))
72
	$a_user['priv'] = array();
73

    
74
if ($_POST) {
75
	conf_mount_rw();
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = explode(" ", "sysprivs");
82
	$reqdfieldsn = explode(",", "Selected priveleges");
83

    
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85

    
86
	/* if this is an AJAX caller then handle via JSON */
87
	if(isAjax() && is_array($input_errors)) {
88
		input_errors2Ajax($input_errors);
89
		exit;
90
	}
91

    
92
	if (!$input_errors) {
93

    
94
		if (!is_array($pconfig['sysprivs']))
95
			$pconfig['sysprivs'] = array();
96

    
97
		if (!count($a_user['priv']))
98
			$a_user['priv'] = $pconfig['sysprivs'];
99
		else
100
			$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
101

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

    
115
/* if ajax is calling, give them an update message */
116
if(isAjax())
117
	print_info_box_np($savemsg);
118

    
119
include("head.inc");
120
?>
121

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

    
127
<?php
128

    
129
if (is_array($priv_list)) {
130
	$id = 0;
131

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

    
141
	echo $jdescs;
142
}
143

    
144
?>
145

    
146
function update_description() {
147
	var index = document.iform.sysprivs.selectedIndex;
148
	document.getElementById("pdesc").innerHTML = descs[index];
149
}
150

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