Project

General

Profile

Download (5.13 KB) Statistics
| Branch: | Tag: | Revision:
1 6b07c15a Matthew Grooms
<?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
39
require("guiconfig.inc");
40
41
$pgtitle = array("System","User manager","Add privileges");
42
43
$userid = $_GET['userid'];
44
if (isset($_POST['userid']))
45
	$userid = $_POST['userid'];
46
47
admin_users_sort();
48
$a_user = & $config['system']['user'][$userid];
49
if (!is_array($a_user)) {
50
	pfSenseHeader("system_usermanager.php?id={$userid}");
51
	exit;
52
}
53
54
if (!is_array($a_user)) {
55
	pfSenseHeader("system_usermanager.php");
56
	exit;
57
}
58
59
if (!is_array($a_user['priv']))
60
	$a_user['priv'] = array();
61
62
if ($_POST) {
63
64
	unset($input_errors);
65
	$pconfig = $_POST;
66
67
	/* input validation */
68
	$reqdfields = explode(" ", "sysprivs");
69
	$reqdfieldsn = explode(",", "Selected priveleges");
70
71
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
72
73
	/* if this is an AJAX caller then handle via JSON */
74
	if(isAjax() && is_array($input_errors)) {
75
		input_errors2Ajax($input_errors);
76
		exit;
77
	}
78
79
	if (!$input_errors) {
80
81
		if (!is_array($pconfig['sysprivs']))
82
			$pconfig['sysprivs'] = array();
83
84
		if (!count($a_user['priv']))
85
			$a_user['priv'] = $pconfig['sysprivs'];
86
		else
87
			$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
88
89 659fa7f2 Matthew Grooms
		local_user_set($a_user);
90 6b07c15a Matthew Grooms
		$retval = write_config();
91
		$savemsg = get_std_save_message($retval);
92
93
		pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
94
		exit;
95
	}
96
}
97
98
/* if ajax is calling, give them an update message */
99
if(isAjax())
100
	print_info_box_np($savemsg);
101
102
include("head.inc");
103
?>
104
105
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
106
<?php include("fbegin.inc"); ?>
107
<script type="text/javascript">
108
<!--
109
110
<?php
111
112
if (is_array($priv_list)) {
113
	$id = 0;
114
115
	$jdescs = "var descs = new Array();\n";
116
	foreach($priv_list as $pname => $pdata) {
117
		if (in_array($pname, $a_user['priv']))
118
			continue;
119
		$desc = addslashes($pdata['descr']);
120
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
121
		$id++;
122
	}
123
124
	echo $jdescs;
125
}
126
127
?>
128
129
function update_description() {
130
	var index = document.iform.sysprivs.selectedIndex;
131
	document.getElementById("pdesc").innerHTML = descs[index];
132
}
133
134
//-->
135
</script>
136
<?php
137
	if ($input_errors)
138
		print_input_errors($input_errors);
139
	if ($savemsg)
140
		print_info_box($savemsg);
141
?>
142
	<form action="system_usermanager_addprivs.php" method="post" name="iform" id="iform">
143
		<div id="inputerrors"></div>
144
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
145
			<tr>
146
				<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
147
				<td width="78%" class="vtable">
148
					<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
149
						<?php
150
							foreach($priv_list as $pname => $pdata):
151
								if (in_array($pname, $a_user['priv']))
152
									continue;
153
						?>
154
						<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
155
						<?php endforeach; ?>
156
					</select>
157
					<br/>
158
					<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
159
				</td>
160
			</tr>
161
			<tr height="60">
162
				<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
163
				<td width="78%" valign="top" class="vtable" id="pdesc">
164
					<em>Select a privilege from the list above for a description</em>
165
				</td>
166
			</tr>
167
			<tr>
168
				<td width="22%" valign="top">&nbsp;</td>
169
				<td width="78%">
170
					<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
171
					<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
172
					<?php if (isset($userid)): ?>
173
					<input name="userid" type="hidden" value="<?=$userid;?>" />
174
					<?php endif; ?>
175
				</td>
176
			</tr>
177
		</table>
178
	</form>
179
<?php include("fend.inc"); ?>
180
</body>
181
</html>