Project

General

Profile

Download (14.4 KB) Statistics
| Branch: | Tag: | Revision:
1 4c291f4c Renato Botelho
<?php
2 fab7ff44 Bill Marquette
/*
3 aaec5634 Renato Botelho
 * system_groupmanager.php
4 191cb31d Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * Copyright (c) 2005 Paul Taylor <paultaylor@winn-dixie.com>
8
 * Copyright (c) 2008 Shrew Soft Inc
9
 * All rights reserved.
10 f74457df Stephen Beaver
 *
11 aaec5634 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 f74457df Stephen Beaver
 *
15 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
16
 * modification, are permitted provided that the following conditions are met:
17 f74457df Stephen Beaver
 *
18 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
19
 *    this list of conditions and the following disclaimer.
20 f74457df Stephen Beaver
 *
21 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
22
 *    notice, this list of conditions and the following disclaimer in
23
 *    the documentation and/or other materials provided with the
24
 *    distribution.
25 f74457df Stephen Beaver
 *
26 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
27
 *    must display the following acknowledgment:
28
 *    "This product includes software developed by the pfSense Project
29
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
30 f74457df Stephen Beaver
 *
31 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
32
 *    endorse or promote products derived from this software without
33
 *    prior written permission. For written permission, please contact
34
 *    coreteam@pfsense.org.
35 f74457df Stephen Beaver
 *
36 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
37
 *    nor may "pfSense" appear in their names without prior written
38
 *    permission of the Electric Sheep Fencing, LLC.
39 f74457df Stephen Beaver
 *
40 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
41
 *    acknowledgment:
42 f74457df Stephen Beaver
 *
43 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
44
 * for use in the pfSense software distribution (http://www.pfsense.org/).
45 f74457df Stephen Beaver
 *
46 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
47
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
50
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
53
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
57
 * OF THE POSSIBILITY OF SUCH DAMAGE.
58 f74457df Stephen Beaver
 */
59 fab7ff44 Bill Marquette
60 6b07c15a Matthew Grooms
##|+PRIV
61
##|*IDENT=page-system-groupmanager
62 2025ba8c Phil Davis
##|*NAME=System: Group Manager
63
##|*DESCR=Allow access to the 'System: Group Manager' page.
64 6b07c15a Matthew Grooms
##|*MATCH=system_groupmanager.php*
65
##|-PRIV
66 fab7ff44 Bill Marquette
67 aceaf18c Phil Davis
require_once("guiconfig.inc");
68 d88c6a9f Scott Ullrich
69 e0c7b2fe Phil Davis
if (!is_array($config['system']['group'])) {
70 6b07c15a Matthew Grooms
	$config['system']['group'] = array();
71 e0c7b2fe Phil Davis
}
72 d81c2ad1 Scott Ullrich
73 6b07c15a Matthew Grooms
$a_group = &$config['system']['group'];
74 d81c2ad1 Scott Ullrich
75 7ea27b0d Renato Botelho
unset($id);
76 06683083 Stephen Beaver
77 e0c7b2fe Phil Davis
if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) {
78 7ea27b0d Renato Botelho
	$id = $_POST['groupid'];
79 e0c7b2fe Phil Davis
}
80 d81c2ad1 Scott Ullrich
81 2f1e91e4 Stephen Beaver
if (isset($_GET['groupid']) && is_numericint($_GET['groupid'])) {
82
	$id = $_GET['groupid'];
83
}
84
85
$act = (isset($_GET['act']) ? $_GET['act'] : '');
86 31b53653 Scott Ullrich
87 06683083 Stephen Beaver
function cpusercmp($a, $b) {
88
	return strcasecmp($a['name'], $b['name']);
89
}
90 23d09a2e Stephen Beaver
91 06683083 Stephen Beaver
function admin_groups_sort() {
92
	global $a_group;
93
94
	if (!is_array($a_group)) {
95
		return;
96
	}
97
98
	usort($a_group, "cpusercmp");
99
}
100
101 7ea27b0d Renato Botelho
if ($act == "delgroup") {
102
103 2f1e91e4 Stephen Beaver
	if (!isset($id) || !isset($_GET['groupname']) || !isset($a_group[$id]) || ($_GET['groupname'] != $a_group[$id]['name'])) {
104 6b07c15a Matthew Grooms
		pfSenseHeader("system_groupmanager.php");
105
		exit;
106
	}
107 31b53653 Scott Ullrich
108 920dbb26 Renato Botelho
	conf_mount_rw();
109 7ea27b0d Renato Botelho
	local_group_del($a_group[$id]);
110 920dbb26 Renato Botelho
	conf_mount_ro();
111 7ea27b0d Renato Botelho
	$groupdeleted = $a_group[$id]['name'];
112
	unset($a_group[$id]);
113 6b07c15a Matthew Grooms
	write_config();
114 8545adde k-paulius
	$savemsg = sprintf(gettext("Group %s successfully deleted."), $groupdeleted);
115 fab7ff44 Bill Marquette
}
116 d88c6a9f Scott Ullrich
117 7ea27b0d Renato Botelho
if ($act == "delpriv") {
118 6b07c15a Matthew Grooms
119 7ea27b0d Renato Botelho
	if (!isset($id) || !isset($a_group[$id])) {
120 6b07c15a Matthew Grooms
		pfSenseHeader("system_groupmanager.php");
121
		exit;
122
	}
123 fab7ff44 Bill Marquette
124 7ea27b0d Renato Botelho
	$privdeleted = $priv_list[$a_group[$id]['priv'][$_POST['privid']]]['name'];
125 2f1e91e4 Stephen Beaver
	unset($a_group[$id]['priv'][$_GET['privid']]);
126 6b07c15a Matthew Grooms
127 2ee08031 Erik Fonnesbeck
	if (is_array($a_group[$id]['member'])) {
128
		foreach ($a_group[$id]['member'] as $uid) {
129
			$user = getUserEntryByUID($uid);
130 e0c7b2fe Phil Davis
			if ($user) {
131 2ee08031 Erik Fonnesbeck
				local_user_set($user);
132 64600f94 Sjon Hortensius
			}
133 2ee08031 Erik Fonnesbeck
		}
134 64600f94 Sjon Hortensius
	}
135 45ee90ed Matthew Grooms
136 6b07c15a Matthew Grooms
	write_config();
137 7ea27b0d Renato Botelho
	$act = "edit";
138 8545adde k-paulius
	$savemsg = sprintf(gettext("Privilege %s successfully deleted."), $privdeleted);
139 6b07c15a Matthew Grooms
}
140 45ee90ed Matthew Grooms
141 7ea27b0d Renato Botelho
if ($act == "edit") {
142
	if (isset($id) && isset($a_group[$id])) {
143 45ee90ed Matthew Grooms
		$pconfig['name'] = $a_group[$id]['name'];
144 6b07c15a Matthew Grooms
		$pconfig['gid'] = $a_group[$id]['gid'];
145 79ed8ce0 Stephen Beaver
		$pconfig['gtype'] = empty($a_group[$id]['scope']) ? "local" : $a_group[$id]['scope'];
146 45ee90ed Matthew Grooms
		$pconfig['description'] = $a_group[$id]['description'];
147 6b07c15a Matthew Grooms
		$pconfig['members'] = $a_group[$id]['member'];
148
		$pconfig['priv'] = $a_group[$id]['priv'];
149 45ee90ed Matthew Grooms
	}
150
}
151 6b07c15a Matthew Grooms
152 2f1e91e4 Stephen Beaver
if (isset($_GET['dellall_x'])) {
153 c0c5b8cc bruno
154 2f1e91e4 Stephen Beaver
	$del_groups = $_GET['delete_check'];
155 c0c5b8cc bruno
156 e0c7b2fe Phil Davis
	if (!empty($del_groups)) {
157
		foreach ($del_groups as $groupid) {
158
			if (isset($a_group[$groupid]) && $a_group[$groupid]['scope'] != "system") {
159 c0c5b8cc bruno
				conf_mount_rw();
160
				local_group_del($a_group[$groupid]);
161
				conf_mount_ro();
162
				unset($a_group[$groupid]);
163
			}
164
		}
165 8545adde k-paulius
		$savemsg = gettext("Selected groups removed successfully.");
166 c0c5b8cc bruno
		write_config($savemsg);
167
	}
168
}
169
170 7ea27b0d Renato Botelho
if (isset($_POST['save'])) {
171 d88c6a9f Scott Ullrich
	unset($input_errors);
172
	$pconfig = $_POST;
173
174
	/* input validation */
175
	$reqdfields = explode(" ", "groupname");
176 b4fd804b Carlos Eduardo Ramos
	$reqdfieldsn = array(gettext("Group Name"));
177 4c291f4c Renato Botelho
178 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
179 4c291f4c Renato Botelho
180 d7689b2c Stephen Beaver
	if ($_POST['gtype'] != "remote") {
181 79ed8ce0 Stephen Beaver
		if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['groupname'])) {
182 d7689b2c Stephen Beaver
			$input_errors[] = sprintf(gettext("The (%s) group name contains invalid characters."), $_POST['gtype']);
183 79ed8ce0 Stephen Beaver
		}
184
	} else {
185
		if (preg_match("/[^a-zA-Z0-9\.\- _]/", $_POST['groupname'])) {
186 d7689b2c Stephen Beaver
			$input_errors[] = sprintf(gettext("The (%s) group name contains invalid characters."), $_POST['gtype']);
187 79ed8ce0 Stephen Beaver
		}
188 e0c7b2fe Phil Davis
	}
189 4c291f4c Renato Botelho
190 e0c7b2fe Phil Davis
	if (strlen($_POST['groupname']) > 16) {
191 3db408b3 PiBa-NL
		$input_errors[] = gettext("The group name is longer than 16 characters.");
192 e0c7b2fe Phil Davis
	}
193 4c291f4c Renato Botelho
194 9630ba1f jim-p
	/* Check the POSTed members to ensure they are valid and exist */
195 9488f42b Phil Davis
	if (is_array($_POST['members'])) {
196 0e5ebefd NewEraCracker
		foreach ($_POST['members'] as $newmember) {
197
			if (!is_numeric($newmember) || empty(getUserEntryByUID($newmember))) {
198
				$input_errors[] = gettext("One or more invalid group members was submitted.");
199
			}
200 9630ba1f jim-p
		}
201
	}
202
203 d88c6a9f Scott Ullrich
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
204
		/* make sure there are no dupes */
205
		foreach ($a_group as $group) {
206
			if ($group['name'] == $_POST['groupname']) {
207 bbf825ab Vinicius Coque
				$input_errors[] = gettext("Another entry with the same group name already exists.");
208 d88c6a9f Scott Ullrich
				break;
209
			}
210
		}
211
	}
212 4c291f4c Renato Botelho
213 d88c6a9f Scott Ullrich
	if (!$input_errors) {
214 45ee90ed Matthew Grooms
		$group = array();
215 e0c7b2fe Phil Davis
		if (isset($id) && $a_group[$id]) {
216 d88c6a9f Scott Ullrich
			$group = $a_group[$id];
217 e0c7b2fe Phil Davis
		}
218 4c291f4c Renato Botelho
219 d88c6a9f Scott Ullrich
		$group['name'] = $_POST['groupname'];
220
		$group['description'] = $_POST['description'];
221 79ed8ce0 Stephen Beaver
		$group['scope'] = $_POST['gtype'];
222 45ee90ed Matthew Grooms
223 e0c7b2fe Phil Davis
		if (empty($_POST['members'])) {
224 70d6b5c4 Ermal
			unset($group['member']);
225 e0c7b2fe Phil Davis
		} else if ($group['gid'] != 1998) { // all group
226 6b07c15a Matthew Grooms
			$group['member'] = $_POST['members'];
227 e0c7b2fe Phil Davis
		}
228 45ee90ed Matthew Grooms
229 e0c7b2fe Phil Davis
		if (isset($id) && $a_group[$id]) {
230 d88c6a9f Scott Ullrich
			$a_group[$id] = $group;
231 e0c7b2fe Phil Davis
		} else {
232 45ee90ed Matthew Grooms
			$group['gid'] = $config['system']['nextgid']++;
233 d88c6a9f Scott Ullrich
			$a_group[] = $group;
234 45ee90ed Matthew Grooms
		}
235
236 06683083 Stephen Beaver
		admin_groups_sort();
237
238 920dbb26 Renato Botelho
		conf_mount_rw();
239 659fa7f2 Matthew Grooms
		local_group_set($group);
240 920dbb26 Renato Botelho
		conf_mount_ro();
241 2a0e8512 jim-p
242
		/* Refresh users in this group since their privileges may have changed. */
243 5709072a jim-p
		if (is_array($group['member'])) {
244
			$a_user = &$config['system']['user'];
245
			foreach ($a_user as & $user) {
246 e0c7b2fe Phil Davis
				if (in_array($user['uid'], $group['member'])) {
247 5709072a jim-p
					local_user_set($user);
248 e0c7b2fe Phil Davis
				}
249 5709072a jim-p
			}
250 2a0e8512 jim-p
		}
251
252 d88c6a9f Scott Ullrich
		write_config();
253 4c291f4c Renato Botelho
254 d88c6a9f Scott Ullrich
		header("Location: system_groupmanager.php");
255
		exit;
256
	}
257 23d09a2e Stephen Beaver
258
	$pconfig['name'] = $_POST['groupname'];
259 fab7ff44 Bill Marquette
}
260
261 2f1e91e4 Stephen Beaver
function build_priv_table() {
262
	global $a_group, $id;
263
264
	$privhtml = '<div class="table-responsive">';
265
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
266
	$privhtml .=		'<thead>';
267 70da45c9 NOYB
	$privhtml .=			'<tr>';
268
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
269
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
270
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
271
	$privhtml .=			'</tr>';
272 2f1e91e4 Stephen Beaver
	$privhtml .=		'</thead>';
273
	$privhtml .=		'<tbody>';
274
275
	foreach (get_user_privdesc($a_group[$id]) as $i => $priv) {
276
		$privhtml .=		'<tr>';
277
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
278
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']) . '</td>';
279 ed10e389 Phil Davis
		$privhtml .=			'<td><a class="fa fa-trash" title="' . gettext('Delete Privilege') . '"	href="system_groupmanager.php?act=delpriv&amp;groupid=' . $id . '&amp;privid=' . $i . '"></a></td>';
280 2f1e91e4 Stephen Beaver
		$privhtml .=		'</tr>';
281 d61309a0 Phil Davis
282 2f1e91e4 Stephen Beaver
	}
283
284
	$privhtml .=		'</tbody>';
285
	$privhtml .=	'</table>';
286
	$privhtml .= '</div>';
287
288
	$privhtml .= '<nav class="action-buttons">';
289 37676f4e jim-p
	$privhtml .=	'<a href="system_groupmanager_addprivs.php?groupid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
290 2f1e91e4 Stephen Beaver
	$privhtml .= '</nav>';
291
292
	return($privhtml);
293
}
294
295 8f1ab2a4 k-paulius
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Groups"));
296 de02dc29 Phil Davis
$pglinks = array("", "system_usermanager.php", "system_groupmanager.php");
297 8f1ab2a4 k-paulius
298
if ($act == "new" || $act == "edit") {
299
	$pgtitle[] = gettext('Edit');
300 de02dc29 Phil Davis
	$pglinks[] = "@self";
301 8f1ab2a4 k-paulius
}
302 23d09a2e Stephen Beaver
303 fab7ff44 Bill Marquette
include("head.inc");
304
305 d61309a0 Phil Davis
if ($input_errors) {
306 64600f94 Sjon Hortensius
	print_input_errors($input_errors);
307 d61309a0 Phil Davis
}
308 23d09a2e Stephen Beaver
309 d61309a0 Phil Davis
if ($savemsg) {
310 f78bbe16 Phil Davis
	print_info_box($savemsg, 'success');
311 d61309a0 Phil Davis
}
312 64600f94 Sjon Hortensius
313
$tab_array = array();
314
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
315
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
316
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
317 2d1f33d9 k-paulius
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
318 64600f94 Sjon Hortensius
display_top_tabs($tab_array);
319
320 d61309a0 Phil Davis
if (!($_GET['act'] == "new" || $_GET['act'] == "edit")) {
321 64600f94 Sjon Hortensius
?>
322 060ed238 Stephen Beaver
<div class="panel panel-default">
323
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Groups')?></h2></div>
324
	<div class="panel-body">
325
		<div class="table-responsive">
326 91677170 PiBa-NL
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
327 060ed238 Stephen Beaver
				<thead>
328
					<tr>
329
						<th><?=gettext("Group name")?></th>
330
						<th><?=gettext("Description")?></th>
331
						<th><?=gettext("Member Count")?></th>
332
						<th><?=gettext("Actions")?></th>
333
					</tr>
334
				</thead>
335
				<tbody>
336 64600f94 Sjon Hortensius
<?php
337 d61309a0 Phil Davis
	foreach ($a_group as $i => $group):
338
		if ($group["name"] == "all") {
339 64600f94 Sjon Hortensius
			$groupcount = count($config['system']['user']);
340 d61309a0 Phil Davis
		} else {
341 64600f94 Sjon Hortensius
			$groupcount = count($group['member']);
342 d61309a0 Phil Davis
		}
343 64600f94 Sjon Hortensius
?>
344 060ed238 Stephen Beaver
					<tr>
345
						<td>
346
							<?=htmlspecialchars($group['name'])?>
347
						</td>
348
						<td>
349
							<?=htmlspecialchars($group['description'])?>
350
						</td>
351
						<td>
352
							<?=$groupcount?>
353
						</td>
354
						<td>
355
							<a class="fa fa-pencil" title="<?=gettext("Edit group"); ?>" href="?act=edit&amp;groupid=<?=$i?>"></a>
356
							<?php if ($group['scope'] != "system"): ?>
357
								<a class="fa fa-trash"	title="<?=gettext("Delete group")?>" href="?act=delgroup&amp;groupid=<?=$i?>&amp;groupname=<?=$group['name']?>"></a>
358
							<?php endif;?>
359
						</td>
360
					</tr>
361 64600f94 Sjon Hortensius
<?php
362
	endforeach;
363 fab7ff44 Bill Marquette
?>
364 060ed238 Stephen Beaver
				</tbody>
365
			</table>
366
		</div>
367 94404d94 Sander van Leeuwen
	</div>
368 060ed238 Stephen Beaver
</div>
369
370
<nav class="action-buttons">
371
	<a href="?act=new" class="btn btn-success btn-sm">
372
		<i class="fa fa-plus icon-embed-btn"></i>
373
		<?=gettext("Add")?>
374
	</a>
375
</nav>
376 64600f94 Sjon Hortensius
<?php
377
	include('foot.inc');
378
	exit;
379 6b07c15a Matthew Grooms
}
380
381 64600f94 Sjon Hortensius
$form = new Form;
382
$form->setAction('system_groupmanager.php?act=edit');
383
$form->addGlobal(new Form_Input(
384
	'groupid',
385
	null,
386
	'hidden',
387
	$id
388
));
389
390 9488f42b Phil Davis
if (isset($id) && $a_group[$id]) {
391 64600f94 Sjon Hortensius
	$form->addGlobal(new Form_Input(
392
		'id',
393
		null,
394
		'hidden',
395
		$id
396
	));
397
398
	$form->addGlobal(new Form_Input(
399
		'gid',
400
		null,
401
		'hidden',
402
		$pconfig['gid']
403
	));
404 61dec0b0 Renato Botelho
}
405
406 5f88f964 k-paulius
$section = new Form_Section('Group Properties');
407 82833610 Stephen Beaver
408 e6acc2ee Sjon Hortensius
$section->addInput($input = new Form_Input(
409 64600f94 Sjon Hortensius
	'groupname',
410 51685157 Phil Davis
	'*Group name',
411 64600f94 Sjon Hortensius
	'text',
412
	$pconfig['name']
413
));
414
415 d61309a0 Phil Davis
if ($pconfig['gtype'] == "system") {
416 1192840b Sjon Hortensius
	$input->setReadonly();
417 79ed8ce0 Stephen Beaver
418
	$section->addInput(new Form_Input(
419
		'gtype',
420 51685157 Phil Davis
		'*Scope',
421 79ed8ce0 Stephen Beaver
		'text',
422
		$pconfig['gtype']
423
	))->setReadonly();
424
} else {
425
	$section->addInput(new Form_Select(
426
		'gtype',
427 51685157 Phil Davis
		'*Scope',
428 79ed8ce0 Stephen Beaver
		$pconfig['gtype'],
429 82833610 Stephen Beaver
		["local" => gettext("Local"), "remote" => gettext("Remote")]
430 79ed8ce0 Stephen Beaver
	));
431 d61309a0 Phil Davis
}
432 e6acc2ee Sjon Hortensius
433 64600f94 Sjon Hortensius
$section->addInput(new Form_Input(
434
	'description',
435
	'Description',
436
	'text',
437
	$pconfig['description']
438 89140b63 NOYB
))->setHelp('Group description, for administrative information only');
439 64600f94 Sjon Hortensius
440 79ed8ce0 Stephen Beaver
441 64600f94 Sjon Hortensius
$form->add($section);
442 d61309a0 Phil Davis
if ($pconfig['gid'] != 1998) { // all users group
443
444 2f1e91e4 Stephen Beaver
	// ==== Group membership ==================================================
445
	$group = new Form_Group('Group membership');
446
447
	// Make a list of all the groups configured on the system, and a list of
448
	// those which this user is a member of
449
	$systemGroups = array();
450
	$usersGroups = array();
451
452
	foreach ($config['system']['user'] as $user) {
453 d61309a0 Phil Davis
		if (is_array($pconfig['members']) && in_array($user['uid'], $pconfig['members'])) {
454 2f1e91e4 Stephen Beaver
			$usersGroups[ $user['uid'] ] = $user['name'];	// Add it to the user's list
455 d61309a0 Phil Davis
		} else {
456 2f1e91e4 Stephen Beaver
			$systemGroups[ $user['uid'] ] = $user['name']; // Add it to the 'not a member of' list
457 d61309a0 Phil Davis
		}
458 2f1e91e4 Stephen Beaver
	}
459
460
	$group->add(new Form_Select(
461
		'notmembers',
462
		null,
463
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
464
		$systemGroups,
465
		true
466 6ef8f2e9 heper
	))->setHelp('Not members');
467 64600f94 Sjon Hortensius
468 2f1e91e4 Stephen Beaver
	$group->add(new Form_Select(
469 64600f94 Sjon Hortensius
		'members',
470 2f1e91e4 Stephen Beaver
		null,
471
		array_combine((array)$pconfig['groups'], (array)$pconfig['groups']),
472
		$usersGroups,
473 64600f94 Sjon Hortensius
		true
474 6ef8f2e9 heper
	))->setHelp('Members');
475 2f1e91e4 Stephen Beaver
476
	$section->add($group);
477
478
	$group = new Form_Group('');
479
480
	$group->add(new Form_Button(
481
		'movetoenabled',
482 faab522f Renato Botelho
		'Move to "Members"',
483 37676f4e jim-p
		null,
484
		'fa-angle-double-right'
485 347c0214 Phil Davis
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
486 2f1e91e4 Stephen Beaver
487
	$group->add(new Form_Button(
488
		'movetodisabled',
489 faab522f Renato Botelho
		'Move to "Not members',
490 37676f4e jim-p
		null,
491
		'fa-angle-double-left'
492 347c0214 Phil Davis
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-info btn-sm');
493 2f1e91e4 Stephen Beaver
494 48d321ca NewEraCracker
	$group->setHelp('Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items.');
495 2f1e91e4 Stephen Beaver
	$section->add($group);
496 64600f94 Sjon Hortensius
497 6b07c15a Matthew Grooms
}
498
499 d61309a0 Phil Davis
if ($_GET['act'] != "new") {
500 64600f94 Sjon Hortensius
	$section = new Form_Section('Assigned Privileges');
501
502
	$section->addInput(new Form_StaticText(
503
		null,
504 2f1e91e4 Stephen Beaver
		build_priv_table()
505 64600f94 Sjon Hortensius
	));
506 6b07c15a Matthew Grooms
507 2f1e91e4 Stephen Beaver
508 64600f94 Sjon Hortensius
	$form->add($section);
509 6b07c15a Matthew Grooms
}
510
511 64600f94 Sjon Hortensius
print $form;
512 2f1e91e4 Stephen Beaver
?>
513 8fd9052f Colin Fleming
<script type="text/javascript">
514 2f1e91e4 Stephen Beaver
//<![CDATA[
515 d61309a0 Phil Davis
events.push(function() {
516 2f1e91e4 Stephen Beaver
517
	// On click . .
518
	$("#movetodisabled").click(function() {
519
		moveOptions($('[name="members[]"] option'), $('[name="notmembers[]"]'));
520
	});
521
522
	$("#movetoenabled").click(function() {
523
		moveOptions($('[name="notmembers[]"] option'), $('[name="members[]"]'));
524
	});
525
526
	// On submit mark all the user's groups as "selected"
527 d61309a0 Phil Davis
	$('form').submit(function() {
528 2f1e91e4 Stephen Beaver
		AllServers($('[name="members[]"] option'), true);
529
	});
530
});
531
//]]>
532
</script>
533
<?php
534 854fa106 heper
include('foot.inc');