Project

General

Profile

Download (6.09 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
31
##|+PRIV
32
##|*IDENT=page-system-groupmanager-addprivs
33
##|*NAME=System: Group Manager: Add Privileges page
34
##|*DESCR=Allow access to the 'System: Group Manager: Add Privileges' page.
35
##|*MATCH=system_groupmanager_addprivs.php*
36
##|-PRIV
37
38 4504a769 Ermal Lu?i
function cpusercmp($a, $b) {
39
	return strcasecmp($a['name'], $b['name']);
40
}
41
42 0d64af59 Ermal Lu?i
function admin_groups_sort() {
43 4504a769 Ermal Lu?i
        global $config;
44 0d64af59 Ermal Lu?i
45
        if (!is_array($config['system']['group']))
46
                return;
47
48
        usort($config['system']['group'], "cpusercmp");
49
}
50 6b07c15a Matthew Grooms
51
require("guiconfig.inc");
52
53
$pgtitle = array("System","Group manager","Add privileges");
54
55
$groupid = $_GET['groupid'];
56
if (isset($_POST['groupid']))
57
	$groupid = $_POST['groupid'];
58
59
admin_groups_sort();
60
$a_group = & $config['system']['group'][$groupid];
61
62
if (!is_array($a_group)) {
63
	pfSenseHeader("system_groupmanager.php?id={$groupid}");
64
	exit;
65
}
66
67
if (!is_array($a_group['priv']))
68
	$a_group['priv'] = array();
69
70
if ($_POST) {
71
72
	unset($input_errors);
73
	$pconfig = $_POST;
74
75
	/* input validation */
76
	$reqdfields = explode(" ", "sysprivs");
77
	$reqdfieldsn = explode(",", "Selected priveleges");
78
79
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
80
81
	/* if this is an AJAX caller then handle via JSON */
82
	if(isAjax() && is_array($input_errors)) {
83
		input_errors2Ajax($input_errors);
84
		exit;
85
	}
86
87
	if (!$input_errors) {
88
89
		if (!is_array($pconfig['sysprivs']))
90
			$pconfig['sysprivs'] = array();
91
92
		if (!count($a_group['priv']))
93
			$a_group['priv'] = $pconfig['sysprivs'];
94
		else
95
			$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
96
97
		foreach ($a_group['member'] as $uid) {
98
			$user = getUserEntryByUID($uid);
99
			if ($user)
100 659fa7f2 Matthew Grooms
				local_user_set($user);
101 6b07c15a Matthew Grooms
		}
102
103 0d64af59 Ermal Lu?i
		admin_groups_sort();
104
105 6b07c15a Matthew Grooms
		$retval = write_config();
106
		$savemsg = get_std_save_message($retval);
107
108
		pfSenseHeader("system_groupmanager.php?act=edit&id={$groupid}");
109
		exit;
110
	}
111
}
112
113
/* if ajax is calling, give them an update message */
114
if(isAjax())
115
	print_info_box_np($savemsg);
116
117
include("head.inc");
118
?>
119
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
121
<?php include("fbegin.inc"); ?>
122
<script type="text/javascript">
123
<!--
124
125
<?php
126
127
if (is_array($priv_list)) {
128
	$id = 0;
129
130
	$jdescs = "var descs = new Array();\n";
131
	foreach($priv_list as $pname => $pdata) {
132
		if (in_array($pname, $a_group['priv']))
133
			continue;
134
		$desc = addslashes($pdata['descr']);
135
		$jdescs .= "descs[{$id}] = '{$desc}';\n";
136
		$id++;
137
	}
138
139
	echo $jdescs;
140
}
141
142
?>
143
144
function update_description() {
145
	var index = document.iform.sysprivs.selectedIndex;
146
	document.getElementById("pdesc").innerHTML = descs[index];
147
}
148
149
//-->
150
</script>
151
<?php
152
	if ($input_errors)
153
		print_input_errors($input_errors);
154
	if ($savemsg)
155
		print_info_box($savemsg);
156
?>
157 e30001cf Matthew Grooms
<table width="100%" border="0" cellpadding="0" cellspacing="0">
158
	<tr>
159
		<td>
160
		<?php
161
			$tab_array = array();
162
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
163
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
164
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
165
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
166
			display_top_tabs($tab_array);
167
		?>
168
		</td>
169
	</tr>
170
	<tr>
171
		<td id="mainarea">
172
			<div class="tabcont">
173
				<form action="system_groupmanager_addprivs.php" method="post" name="iform" id="iform">
174
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
175
						<tr>
176
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
177
							<td width="78%" class="vtable">
178
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
179
									<?php
180
										foreach($priv_list as $pname => $pdata):
181
											if (in_array($pname, $a_group['priv']))
182
												continue;
183
									?>
184
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
185
									<?php endforeach; ?>
186
								</select>
187
								<br/>
188
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
189
							</td>
190
						</tr>
191
						<tr height="60">
192
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
193
							<td width="78%" valign="top" class="vtable" id="pdesc">
194
								<em>Select a privilege from the list above for a description</em>
195
							</td>
196
						</tr>
197
						<tr>
198
							<td width="22%" valign="top">&nbsp;</td>
199
							<td width="78%">
200
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
201
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
202
								<?php if (isset($groupid)): ?>
203
								<input name="groupid" type="hidden" value="<?=$groupid;?>" />
204
								<?php endif; ?>
205
							</td>
206
						</tr>
207
					</table>
208
				</form>
209
			</div>
210
		</td>
211
	</tr>
212
</table>
213 6b07c15a Matthew Grooms
<?php include("fend.inc"); ?>
214
</body>
215
</html>