Project

General

Profile

Download (6.88 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / system_groupmanager_addprivs.php @ a1b66bec

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

    
56
$pgtitle = array(gettext("System"),gettext("Group manager"),gettext("Add privileges"));
57

    
58
if (is_numericint($_GET['groupid']))
59
	$groupid = $_GET['groupid'];
60
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
61
	$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
	$reqdfieldsn = array(gettext("Selected priveleges"));
81

    
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
		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
		}
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&amp;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
//<![CDATA[
129

    
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
//]]>
155
</script>
156
<?php
157
	if ($input_errors)
158
		print_input_errors($input_errors);
159
	if ($savemsg)
160
		print_info_box($savemsg);
161
?>
162
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager add priveleges">
163
	<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
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
180
						<tr>
181
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
182
							<td width="78%" class="vtable">
183
								<table>
184
									<tr><td>
185
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35">
186
									<?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
								</td><td>
197
								<a href='#'onClick="selectAll();">Select all</a>
198
								<script type="text/javascript">
199
								//<![CDATA[
200
									function selectAll() {
201
										var options = jQuery('select#sysprivs option');
202
										var len = options.length;
203
										for (var i = 0; i < len; i++) {
204
										    options[i].selected = true;
205
										}
206
									}
207
									selectAll();
208
								//]]>									
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><?=gettext("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="<?=htmlspecialchars($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>
(225-225/256)