Project

General

Profile

Download (6.12 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

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

    
58
$groupid = $_GET['groupid'];
59
if (isset($_POST['groupid']))
60
	$groupid = $_POST['groupid'];
61

    
62
admin_groups_sort();
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 = explode(",", "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
		foreach ($a_group['member'] as $uid) {
101
			$user = getUserEntryByUID($uid);
102
			if ($user)
103
				local_user_set($user);
104
		}
105

    
106
		admin_groups_sort();
107

    
108
		$retval = write_config();
109
		$savemsg = get_std_save_message($retval);
110

    
111
		pfSenseHeader("system_groupmanager.php?act=edit&id={$groupid}");
112
		exit;
113
	}
114
}
115

    
116
/* if ajax is calling, give them an update message */
117
if(isAjax())
118
	print_info_box_np($savemsg);
119

    
120
include("head.inc");
121
?>
122

    
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
124
<?php include("fbegin.inc"); ?>
125
<script type="text/javascript">
126
<!--
127

    
128
<?php
129

    
130
if (is_array($priv_list)) {
131
	$id = 0;
132

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

    
142
	echo $jdescs;
143
}
144

    
145
?>
146

    
147
function update_description() {
148
	var index = document.iform.sysprivs.selectedIndex;
149
	document.getElementById("pdesc").innerHTML = descs[index];
150
}
151

    
152
//-->
153
</script>
154
<?php
155
	if ($input_errors)
156
		print_input_errors($input_errors);
157
	if ($savemsg)
158
		print_info_box($savemsg);
159
?>
160
<table width="100%" border="0" cellpadding="0" cellspacing="0">
161
	<tr>
162
		<td>
163
		<?php
164
			$tab_array = array();
165
			$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
166
			$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
167
			$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
168
			$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
169
			display_top_tabs($tab_array);
170
		?>
171
		</td>
172
	</tr>
173
	<tr>
174
		<td id="mainarea">
175
			<div class="tabcont">
176
				<form action="system_groupmanager_addprivs.php" method="post" name="iform" id="iform">
177
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
178
						<tr>
179
							<td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
180
							<td width="78%" class="vtable">
181
								<select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple>
182
									<?php
183
										foreach($priv_list as $pname => $pdata):
184
											if (in_array($pname, $a_group['priv']))
185
												continue;
186
									?>
187
									<option value="<?=$pname;?>"><?=$pdata['name'];?></option>
188
									<?php endforeach; ?>
189
								</select>
190
								<br/>
191
								<?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
192
							</td>
193
						</tr>
194
						<tr height="60">
195
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
196
							<td width="78%" valign="top" class="vtable" id="pdesc">
197
								<em>Select a privilege from the list above for a description</em>
198
							</td>
199
						</tr>
200
						<tr>
201
							<td width="22%" valign="top">&nbsp;</td>
202
							<td width="78%">
203
								<input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
204
								<input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
205
								<?php if (isset($groupid)): ?>
206
								<input name="groupid" type="hidden" value="<?=$groupid;?>" />
207
								<?php endif; ?>
208
							</td>
209
						</tr>
210
					</table>
211
				</form>
212
			</div>
213
		</td>
214
	</tr>
215
</table>
216
<?php include("fend.inc"); ?>
217
</body>
218
</html>
(188-188/217)