Project

General

Profile

Download (6.94 KB) Statistics
| Branch: | Tag: | Revision:
1 6b07c15a Matthew Grooms
<?php
2
/* $Id$ */
3
/*
4
	system_groupmanager_addprivs.php
5
6 29aef6c4 Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
7 6b07c15a Matthew Grooms
	Copyright (C) 2006 Daniel S. Haischt.
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	auth
33
*/
34 6b07c15a Matthew Grooms
35
##|+PRIV
36
##|*IDENT=page-system-groupmanager-addprivs
37
##|*NAME=System: Group Manager: Add Privileges page
38
##|*DESCR=Allow access to the 'System: Group Manager: Add Privileges' page.
39
##|*MATCH=system_groupmanager_addprivs.php*
40
##|-PRIV
41
42 4504a769 Ermal Lu?i
function cpusercmp($a, $b) {
43
	return strcasecmp($a['name'], $b['name']);
44
}
45
46 0d64af59 Ermal Lu?i
function admin_groups_sort() {
47 4504a769 Ermal Lu?i
        global $config;
48 0d64af59 Ermal Lu?i
49
        if (!is_array($config['system']['group']))
50
                return;
51
52
        usort($config['system']['group'], "cpusercmp");
53
}
54 6b07c15a Matthew Grooms
55
require("guiconfig.inc");
56
57 c3c68a70 Vinicius Coque
$pgtitle = array(gettext("System"),gettext("Group manager"),gettext("Add privileges"));
58 6b07c15a Matthew Grooms
59 e41ec584 Renato Botelho
if (is_numericint($_GET['groupid']))
60
	$groupid = $_GET['groupid'];
61
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
62 6b07c15a Matthew Grooms
	$groupid = $_POST['groupid'];
63
64
$a_group = & $config['system']['group'][$groupid];
65
66
if (!is_array($a_group)) {
67
	pfSenseHeader("system_groupmanager.php?id={$groupid}");
68
	exit;
69
}
70
71
if (!is_array($a_group['priv']))
72
	$a_group['priv'] = array();
73
74
if ($_POST) {
75
76
	unset($input_errors);
77
	$pconfig = $_POST;
78
79
	/* input validation */
80
	$reqdfields = explode(" ", "sysprivs");
81 76d49f20 Renato Botelho
	$reqdfieldsn = array(gettext("Selected priveleges"));
82 6b07c15a Matthew Grooms
83 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
84 6b07c15a Matthew Grooms
85
	/* if this is an AJAX caller then handle via JSON */
86
	if(isAjax() && is_array($input_errors)) {
87
		input_errors2Ajax($input_errors);
88
		exit;
89
	}
90
91
	if (!$input_errors) {
92
93
		if (!is_array($pconfig['sysprivs']))
94
			$pconfig['sysprivs'] = array();
95
96
		if (!count($a_group['priv']))
97
			$a_group['priv'] = $pconfig['sysprivs'];
98
		else
99
			$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
100
101 2ee08031 Erik Fonnesbeck
		if (is_array($a_group['member'])) {
102
			foreach ($a_group['member'] as $uid) {
103
				$user = getUserEntryByUID($uid);
104
				if ($user)
105
					local_user_set($user);
106
			}
107 6b07c15a Matthew Grooms
		}
108
109 0d64af59 Ermal Lu?i
		admin_groups_sort();
110
111 6b07c15a Matthew Grooms
		$retval = write_config();
112
		$savemsg = get_std_save_message($retval);
113
114 b3733e10 Colin Fleming
		pfSenseHeader("system_groupmanager.php?act=edit&amp;id={$groupid}");
115 6b07c15a Matthew Grooms
		exit;
116
	}
117
}
118
119
/* if ajax is calling, give them an update message */
120
if(isAjax())
121
	print_info_box_np($savemsg);
122
123
include("head.inc");
124
?>
125
126
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
127
<?php include("fbegin.inc"); ?>
128
<script type="text/javascript">
129 8b60b40f Colin Fleming
//<![CDATA[
130 6b07c15a Matthew Grooms
131
<?php
132
133
if (is_array($priv_list)) {
134
	$id = 0;
135
136
	$jdescs = "var descs = new Array();\n";
137
	foreach($priv_list as $pname => $pdata) {
138
		if (in_array($pname, $a_group['priv']))
139
			continue;
140
		$desc = addslashes($pdata['descr']);
141
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
142
		$id++;
143
	}
144
145
	echo $jdescs;
146
}
147
148
?>
149
150
function update_description() {
151
	var index = document.iform.sysprivs.selectedIndex;
152
	document.getElementById("pdesc").innerHTML = descs[index];
153
}
154
155 8b60b40f Colin Fleming
//]]>
156 6b07c15a Matthew Grooms
</script>
157
<?php
158
	if ($input_errors)
159
		print_input_errors($input_errors);
160
	if ($savemsg)
161
		print_info_box($savemsg);
162
?>
163 8b60b40f Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager add priveleges">
164 e30001cf Matthew Grooms
	<tr>
165
		<td>
166
		<?php
167
			$tab_array = array();
168
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
169
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
170
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
171
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
172
			display_top_tabs($tab_array);
173
		?>
174
		</td>
175
	</tr>
176
	<tr>
177
		<td id="mainarea">
178
			<div class="tabcont">
179
				<form action="system_groupmanager_addprivs.php" method="post" name="iform" id="iform">
180 8b60b40f Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
181 e30001cf Matthew Grooms
						<tr>
182
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
183
							<td width="78%" class="vtable">
184 f1a73dbf sullrich
								<table>
185
									<tr><td>
186 8b60b40f Colin Fleming
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35">
187 e30001cf Matthew Grooms
									<?php
188
										foreach($priv_list as $pname => $pdata):
189
											if (in_array($pname, $a_group['priv']))
190
												continue;
191
									?>
192
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
193
									<?php endforeach; ?>
194
								</select>
195 8cd558b6 ayvis
								<br />
196 e30001cf Matthew Grooms
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
197 f1a73dbf sullrich
								</td><td>
198
								<a href='#'onClick="selectAll();">Select all</a>
199
								<script type="text/javascript">
200 8b60b40f Colin Fleming
								//<![CDATA[
201 f1a73dbf sullrich
									function selectAll() {
202 300e2c0b Vinicius Coque
										var options = jQuery('select#sysprivs option');
203 f1a73dbf sullrich
										var len = options.length;
204
										for (var i = 0; i < len; i++) {
205
										    options[i].selected = true;
206
										}
207
									}
208
									selectAll();
209 8b60b40f Colin Fleming
								//]]>									
210 f1a73dbf sullrich
								</script>
211 8cd558b6 ayvis
								<br />
212 f1a73dbf sullrich
								</td>
213
								</tr>
214
								</table>
215 e30001cf Matthew Grooms
							</td>
216
						</tr>
217
						<tr height="60">
218
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
219
							<td width="78%" valign="top" class="vtable" id="pdesc">
220 c3c68a70 Vinicius Coque
								<em><?=gettext("Select a privilege from the list above for a description");?></em>
221 e30001cf Matthew Grooms
							</td>
222
						</tr>
223
						<tr>
224
							<td width="22%" valign="top">&nbsp;</td>
225
							<td width="78%">
226
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
227
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
228
								<?php if (isset($groupid)): ?>
229 e41ec584 Renato Botelho
								<input name="groupid" type="hidden" value="<?=htmlspecialchars($groupid);?>" />
230 e30001cf Matthew Grooms
								<?php endif; ?>
231
							</td>
232
						</tr>
233
					</table>
234
				</form>
235
			</div>
236
		</td>
237
	</tr>
238
</table>
239 6b07c15a Matthew Grooms
<?php include("fend.inc"); ?>
240
</body>
241
</html>