Project

General

Profile

Download (6.72 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
31
	pfSense_MODULE:	auth
32
*/
33

    
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
function cpusercmp($a, $b) {
42
	return strcasecmp($a['name'], $b['name']);
43
}
44

    
45
function admin_groups_sort() {
46
        global $config;
47

    
48
        if (!is_array($config['system']['group']))
49
                return;
50

    
51
        usort($config['system']['group'], "cpusercmp");
52
}
53

    
54
require("guiconfig.inc");
55
require("priv.defs.inc");
56
require("priv.inc");
57

    
58
$pgtitle = array("System","Group manager","Add privileges");
59

    
60
$groupid = $_GET['groupid'];
61
if (isset($_POST['groupid']))
62
	$groupid = $_POST['groupid'];
63

    
64
admin_groups_sort();
65
$a_group = & $config['system']['group'][$groupid];
66

    
67
if (!is_array($a_group)) {
68
	pfSenseHeader("system_groupmanager.php?id={$groupid}");
69
	exit;
70
}
71

    
72
if (!is_array($a_group['priv']))
73
	$a_group['priv'] = array();
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = explode(" ", "sysprivs");
82
	$reqdfieldsn = explode(",", "Selected priveleges");
83

    
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85

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

    
92
	if (!$input_errors) {
93

    
94
		if (!is_array($pconfig['sysprivs']))
95
			$pconfig['sysprivs'] = array();
96

    
97
		if (!count($a_group['priv']))
98
			$a_group['priv'] = $pconfig['sysprivs'];
99
		else
100
			$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
101

    
102
		foreach ($a_group['member'] as $uid) {
103
			$user = getUserEntryByUID($uid);
104
			if ($user)
105
				local_user_set($user);
106
		}
107

    
108
		admin_groups_sort();
109

    
110
		$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 src="/javascript/scriptaculous/prototype.js" type="text/javascript">
128
</script>
129
<script type="text/javascript">
130
<!--
131

    
132
<?php
133

    
134
if (is_array($priv_list)) {
135
	$id = 0;
136

    
137
	$jdescs = "var descs = new Array();\n";
138
	foreach($priv_list as $pname => $pdata) {
139
		if (in_array($pname, $a_group['priv']))
140
			continue;
141
		$desc = addslashes($pdata['descr']);
142
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
143
		$id++;
144
	}
145

    
146
	echo $jdescs;
147
}
148

    
149
?>
150

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

    
156
//-->
157
</script>
158
<?php
159
	if ($input_errors)
160
		print_input_errors($input_errors);
161
	if ($savemsg)
162
		print_info_box($savemsg);
163
?>
164
<table width="100%" border="0" cellpadding="0" cellspacing="0">
165
	<tr>
166
		<td>
167
		<?php
168
			$tab_array = array();
169
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
170
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
171
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
172
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
173
			display_top_tabs($tab_array);
174
		?>
175
		</td>
176
	</tr>
177
	<tr>
178
		<td id="mainarea">
179
			<div class="tabcont">
180
				<form action="system_groupmanager_addprivs.php" method="post" name="iform" id="iform">
181
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
182
						<tr>
183
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
184
							<td width="78%" class="vtable">
185
								<table>
186
									<tr><td>
187
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
188
									<?php
189
										foreach($priv_list as $pname => $pdata):
190
											if (in_array($pname, $a_group['priv']))
191
												continue;
192
									?>
193
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
194
									<?php endforeach; ?>
195
								</select>
196
								<br/>
197
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
198
								</td><td>
199
								<a href='#'onClick="selectAll();">Select all</a>
200
								<script type="text/javascript">
201
									function selectAll() {
202
										var options = $$('select#sysprivs option');
203
										var len = options.length;
204
										for (var i = 0; i < len; i++) {
205
										    options[i].selected = true;
206
										}
207
									}
208
									selectAll();
209
								</script>
210
								<br/>
211
								</td>
212
								</tr>
213
								</table>
214
							</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
								<em>Select a privilege from the list above for a description</em>
220
							</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
								<input name="groupid" type="hidden" value="<?=$groupid;?>" />
229
								<?php endif; ?>
230
							</td>
231
						</tr>
232
					</table>
233
				</form>
234
			</div>
235
		</td>
236
	</tr>
237
</table>
238
<?php include("fend.inc"); ?>
239
</body>
240
</html>
(189-189/218)