Projet

Général

Profil

Télécharger (6,2 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_usermanager_addprivs.php @ b3733e10

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
require("guiconfig.inc");
46

    
47
$pgtitle = array("System","User manager","Add privileges");
48

    
49
if (is_numericint($_GET['userid']))
50
	$userid = $_GET['userid'];
51
if (isset($_POST['userid']) && is_numericint($_POST['userid']))
52
	$userid = $_POST['userid'];
53

    
54
$a_user = & $config['system']['user'][$userid];
55
if (!is_array($a_user)) {
56
	pfSenseHeader("system_usermanager.php?id={$userid}");
57
	exit;
58
}
59

    
60
if (!is_array($a_user)) {
61
	pfSenseHeader("system_usermanager.php");
62
	exit;
63
}
64

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

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

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

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

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

    
80
	/* if this is an AJAX caller then handle via JSON */
81
	if(isAjax() && is_array($input_errors)) {
82
		input_errors2Ajax($input_errors);
83
		exit;
84
	}
85

    
86
	if (!$input_errors) {
87

    
88
		if (!is_array($pconfig['sysprivs']))
89
			$pconfig['sysprivs'] = array();
90

    
91
		if (!count($a_user['priv']))
92
			$a_user['priv'] = $pconfig['sysprivs'];
93
		else
94
			$a_user['priv'] = array_merge($a_user['priv'], $pconfig['sysprivs']);
95

    
96
		$a_user['priv'] = sort_user_privs($a_user['priv']);
97
		local_user_set($a_user);
98
		$retval = write_config();
99
		$savemsg = get_std_save_message($retval);
100
		conf_mount_ro();
101
		
102
		pfSenseHeader("system_usermanager.php?act=edit&amp;id={$userid}");
103
		
104
		exit;
105
	}
106
	conf_mount_ro();
107
}
108

    
109
/* if ajax is calling, give them an update message */
110
if(isAjax())
111
	print_info_box_np($savemsg);
112

    
113
include("head.inc");
114
?>
115

    
116
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
117
<?php include("fbegin.inc"); ?>
118
<script type="text/javascript">
119
//<![CDATA[
120

    
121
<?php
122

    
123
if (is_array($priv_list)) {
124
	$id = 0;
125

    
126
	$jdescs = "var descs = new Array();\n";
127
	foreach($priv_list as $pname => $pdata) {
128
		if (in_array($pname, $a_user['priv']))
129
			continue;
130
		$desc = addslashes(preg_replace("/pfSense/i", $g['product_name'], $pdata['descr']));
131
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
132
		$id++;
133
	}
134

    
135
	echo $jdescs;
136
}
137

    
138
?>
139

    
140
function update_description() {
141
	var index = document.iform.sysprivs.selectedIndex;
142
	document.getElementById("pdesc").innerHTML = descs[index];
143
}
144

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