Project

General

Profile

Download (6.88 KB) Statistics
| Branch: | Tag: | Revision:
1 6b07c15a Matthew Grooms
<?php
2
/* $Id$ */
3
/*
4
	system_groupmanager_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 1d333258 Scott Ullrich
/*
31
	pfSense_MODULE:	auth
32
*/
33 6b07c15a Matthew Grooms
34
##|+PRIV
35
##|*IDENT=page-system-groupmanager-addprivs
36
##|*NAME=System: Group Manager: Add Privileges page
37
##|*DESCR=Allow access to the 'System: Group Manager: Add Privileges' page.
38
##|*MATCH=system_groupmanager_addprivs.php*
39
##|-PRIV
40
41 4504a769 Ermal Lu?i
function cpusercmp($a, $b) {
42
	return strcasecmp($a['name'], $b['name']);
43
}
44
45 0d64af59 Ermal Lu?i
function admin_groups_sort() {
46 4504a769 Ermal Lu?i
        global $config;
47 0d64af59 Ermal Lu?i
48
        if (!is_array($config['system']['group']))
49
                return;
50
51
        usort($config['system']['group'], "cpusercmp");
52
}
53 6b07c15a Matthew Grooms
54
require("guiconfig.inc");
55
56 c3c68a70 Vinicius Coque
$pgtitle = array(gettext("System"),gettext("Group manager"),gettext("Add privileges"));
57 6b07c15a Matthew Grooms
58 0e6cf71b Renato Botelho
if (is_numericint($_GET['groupid']))
59
	$groupid = $_GET['groupid'];
60
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
61 6b07c15a Matthew Grooms
	$groupid = $_POST['groupid'];
62
63
$a_group = & $config['system']['group'][$groupid];
64
65
if (!is_array($a_group)) {
66
	pfSenseHeader("system_groupmanager.php?id={$groupid}");
67
	exit;
68
}
69
70
if (!is_array($a_group['priv']))
71
	$a_group['priv'] = array();
72
73
if ($_POST) {
74
75
	unset($input_errors);
76
	$pconfig = $_POST;
77
78
	/* input validation */
79
	$reqdfields = explode(" ", "sysprivs");
80 76d49f20 Renato Botelho
	$reqdfieldsn = array(gettext("Selected priveleges"));
81 6b07c15a Matthew Grooms
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83
84
	/* if this is an AJAX caller then handle via JSON */
85
	if(isAjax() && is_array($input_errors)) {
86
		input_errors2Ajax($input_errors);
87
		exit;
88
	}
89
90
	if (!$input_errors) {
91
92
		if (!is_array($pconfig['sysprivs']))
93
			$pconfig['sysprivs'] = array();
94
95
		if (!count($a_group['priv']))
96
			$a_group['priv'] = $pconfig['sysprivs'];
97
		else
98
			$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
99
100 2ee08031 Erik Fonnesbeck
		if (is_array($a_group['member'])) {
101
			foreach ($a_group['member'] as $uid) {
102
				$user = getUserEntryByUID($uid);
103
				if ($user)
104
					local_user_set($user);
105
			}
106 6b07c15a Matthew Grooms
		}
107
108 0d64af59 Ermal Lu?i
		admin_groups_sort();
109
110 6b07c15a Matthew Grooms
		$retval = write_config();
111
		$savemsg = get_std_save_message($retval);
112
113
		pfSenseHeader("system_groupmanager.php?act=edit&id={$groupid}");
114
		exit;
115
	}
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 8b60b40f Colin Fleming
//<![CDATA[
129 6b07c15a Matthew Grooms
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_group['priv']))
138
			continue;
139
		$desc = addslashes($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 8b60b40f Colin Fleming
//]]>
155 6b07c15a Matthew Grooms
</script>
156
<?php
157
	if ($input_errors)
158
		print_input_errors($input_errors);
159
	if ($savemsg)
160
		print_info_box($savemsg);
161
?>
162 8b60b40f Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager add priveleges">
163 e30001cf Matthew Grooms
	<tr>
164
		<td>
165
		<?php
166
			$tab_array = array();
167
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
168
			$tab_array[] = array(gettext("Groups"), true, "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_groupmanager_addprivs.php" method="post" name="iform" id="iform">
179 8b60b40f Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
180 e30001cf Matthew Grooms
						<tr>
181
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
182
							<td width="78%" class="vtable">
183 f1a73dbf sullrich
								<table>
184
									<tr><td>
185 8b60b40f Colin Fleming
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35">
186 e30001cf Matthew Grooms
									<?php
187
										foreach($priv_list as $pname => $pdata):
188
											if (in_array($pname, $a_group['priv']))
189
												continue;
190
									?>
191
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
192
									<?php endforeach; ?>
193
								</select>
194
								<br/>
195
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
196 f1a73dbf sullrich
								</td><td>
197
								<a href='#'onClick="selectAll();">Select all</a>
198
								<script type="text/javascript">
199 8b60b40f Colin Fleming
								//<![CDATA[
200 f1a73dbf sullrich
									function selectAll() {
201 300e2c0b Vinicius Coque
										var options = jQuery('select#sysprivs option');
202 f1a73dbf sullrich
										var len = options.length;
203
										for (var i = 0; i < len; i++) {
204
										    options[i].selected = true;
205
										}
206
									}
207
									selectAll();
208 8b60b40f Colin Fleming
								//]]>									
209 f1a73dbf sullrich
								</script>
210
								<br/>
211
								</td>
212
								</tr>
213
								</table>
214 e30001cf Matthew Grooms
							</td>
215
						</tr>
216
						<tr height="60">
217
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
218
							<td width="78%" valign="top" class="vtable" id="pdesc">
219 c3c68a70 Vinicius Coque
								<em><?=gettext("Select a privilege from the list above for a description");?></em>
220 e30001cf Matthew Grooms
							</td>
221
						</tr>
222
						<tr>
223
							<td width="22%" valign="top">&nbsp;</td>
224
							<td width="78%">
225
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
226
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
227
								<?php if (isset($groupid)): ?>
228 0e6cf71b Renato Botelho
								<input name="groupid" type="hidden" value="<?=htmlspecialchars($groupid);?>" />
229 e30001cf Matthew Grooms
								<?php endif; ?>
230
							</td>
231
						</tr>
232
					</table>
233
				</form>
234
			</div>
235
		</td>
236
	</tr>
237
</table>
238 6b07c15a Matthew Grooms
<?php include("fend.inc"); ?>
239
</body>
240
</html>