Project

General

Profile

Download (6.31 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

    
56
$pgtitle = array("System","User manager","Add privileges");
57

    
58
$userid = $_GET['userid'];
59
if (isset($_POST['userid']))
60
	$userid = $_POST['userid'];
61

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

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

    
73
if (!is_array($a_user['priv']))
74
	$a_user['priv'] = array();
75

    
76
if ($_POST) {
77
	conf_mount_rw();
78

    
79
	unset($input_errors);
80
	$pconfig = $_POST;
81

    
82
	/* input validation */
83
	$reqdfields = explode(" ", "sysprivs");
84
	$reqdfieldsn = array(gettext("Selected priveleges"));
85

    
86
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
87

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

    
94
	if (!$input_errors) {
95

    
96
		if (!is_array($pconfig['sysprivs']))
97
			$pconfig['sysprivs'] = array();
98

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

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

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

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

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

    
130
<?php
131

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

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

    
144
	echo $jdescs;
145
}
146

    
147
?>
148

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

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