Project

General

Profile

Download (14.6 KB) Statistics
| Branch: | Tag: | Revision:
1 4c291f4c Renato Botelho
<?php
2 fab7ff44 Bill Marquette
/*
3 c5d81585 Renato Botelho
 * system_groupmanager.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 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 c5d81585 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 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18 f74457df Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 f74457df Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26 f74457df Stephen Beaver
 */
27 fab7ff44 Bill Marquette
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-system-groupmanager
30 48157a04 Phil Davis
##|*NAME=System: Group Manager
31
##|*DESCR=Allow access to the 'System: Group Manager' page.
32 57188e47 Phil Davis
##|*WARN=standard-warning-root
33 6b07c15a Matthew Grooms
##|*MATCH=system_groupmanager.php*
34
##|-PRIV
35 fab7ff44 Bill Marquette
36 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
37 15c74b5b doktornotor
require_once("pfsense-utils.inc");
38 d88c6a9f Scott Ullrich
39 3fa6d462 jim-p
$logging_level = LOG_WARNING;
40
$logging_prefix = gettext("Local User Database");
41
42 ea0dd417 jim-p
init_config_arr(array('system', 'group'));
43 6b07c15a Matthew Grooms
$a_group = &$config['system']['group'];
44 d81c2ad1 Scott Ullrich
45 7ea27b0d Renato Botelho
unset($id);
46 4611e283 Steve Beaver
$id = $_REQUEST['groupid'];
47
$act = (isset($_REQUEST['act']) ? $_REQUEST['act'] : '');
48 31b53653 Scott Ullrich
49 06683083 Stephen Beaver
function cpusercmp($a, $b) {
50
	return strcasecmp($a['name'], $b['name']);
51
}
52 23d09a2e Stephen Beaver
53 06683083 Stephen Beaver
function admin_groups_sort() {
54
	global $a_group;
55
56
	if (!is_array($a_group)) {
57
		return;
58
	}
59
60
	usort($a_group, "cpusercmp");
61
}
62
63 4611e283 Steve Beaver
if ($_POST['act'] == "delgroup") {
64 7ea27b0d Renato Botelho
65 449cac24 Renato Botelho
	if (!isset($id) || !isset($_REQUEST['groupname']) ||
66
	    !isset($a_group[$id]) ||
67
	    ($_REQUEST['groupname'] != $a_group[$id]['name'])) {
68 6b07c15a Matthew Grooms
		pfSenseHeader("system_groupmanager.php");
69
		exit;
70
	}
71 31b53653 Scott Ullrich
72 7ea27b0d Renato Botelho
	local_group_del($a_group[$id]);
73
	$groupdeleted = $a_group[$id]['name'];
74
	unset($a_group[$id]);
75 449cac24 Renato Botelho
	/*
76
	 * Reindex the array to avoid operating on an incorrect index
77
	 * https://redmine.pfsense.org/issues/7733
78
	 */
79 92c27793 jim-p
	$a_group = array_values($a_group);
80 3fa6d462 jim-p
81 449cac24 Renato Botelho
	$savemsg = sprintf(gettext("Successfully deleted group: %s"),
82
	    $groupdeleted);
83 3fa6d462 jim-p
	write_config($savemsg);
84
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
85 fab7ff44 Bill Marquette
}
86 d88c6a9f Scott Ullrich
87 4611e283 Steve Beaver
if ($_POST['act'] == "delpriv") {
88 6b07c15a Matthew Grooms
89 7ea27b0d Renato Botelho
	if (!isset($id) || !isset($a_group[$id])) {
90 6b07c15a Matthew Grooms
		pfSenseHeader("system_groupmanager.php");
91
		exit;
92
	}
93 fab7ff44 Bill Marquette
94 449cac24 Renato Botelho
	$privdeleted =
95
	    $priv_list[$a_group[$id]['priv'][$_REQUEST['privid']]]['name'];
96 4611e283 Steve Beaver
	unset($a_group[$id]['priv'][$_REQUEST['privid']]);
97 6b07c15a Matthew Grooms
98 2ee08031 Erik Fonnesbeck
	if (is_array($a_group[$id]['member'])) {
99
		foreach ($a_group[$id]['member'] as $uid) {
100
			$user = getUserEntryByUID($uid);
101 e0c7b2fe Phil Davis
			if ($user) {
102 2ee08031 Erik Fonnesbeck
				local_user_set($user);
103 64600f94 Sjon Hortensius
			}
104 2ee08031 Erik Fonnesbeck
		}
105 64600f94 Sjon Hortensius
	}
106 45ee90ed Matthew Grooms
107 449cac24 Renato Botelho
	$savemsg = sprintf(gettext("Removed Privilege \"%s\" from group %s"),
108
	    $privdeleted, $a_group[$id]['name']);
109 3fa6d462 jim-p
	write_config($savemsg);
110
	syslog($logging_level, "{$logging_prefix}: {$savemsg}");
111
112 7ea27b0d Renato Botelho
	$act = "edit";
113 6b07c15a Matthew Grooms
}
114 45ee90ed Matthew Grooms
115 7ea27b0d Renato Botelho
if ($act == "edit") {
116
	if (isset($id) && isset($a_group[$id])) {
117 45ee90ed Matthew Grooms
		$pconfig['name'] = $a_group[$id]['name'];
118 6b07c15a Matthew Grooms
		$pconfig['gid'] = $a_group[$id]['gid'];
119 449cac24 Renato Botelho
		$pconfig['gtype'] = empty($a_group[$id]['scope'])
120
		    ? "local" : $a_group[$id]['scope'];
121 45ee90ed Matthew Grooms
		$pconfig['description'] = $a_group[$id]['description'];
122 6b07c15a Matthew Grooms
		$pconfig['members'] = $a_group[$id]['member'];
123
		$pconfig['priv'] = $a_group[$id]['priv'];
124 45ee90ed Matthew Grooms
	}
125
}
126 6b07c15a Matthew Grooms
127 20231404 Steve Beaver
if (isset($_POST['dellall_x'])) {
128 c0c5b8cc bruno
129 20231404 Steve Beaver
	$del_groups = $_POST['delete_check'];
130 3fa6d462 jim-p
	$deleted_groups = array();
131 c0c5b8cc bruno
132 e0c7b2fe Phil Davis
	if (!empty($del_groups)) {
133
		foreach ($del_groups as $groupid) {
134 449cac24 Renato Botelho
			if (isset($a_group[$groupid]) &&
135
			    $a_group[$groupid]['scope'] != "system") {
136 3fa6d462 jim-p
				$deleted_groups[] = $a_group[$groupid]['name'];
137 c0c5b8cc bruno
				local_group_del($a_group[$groupid]);
138
				unset($a_group[$groupid]);
139
			}
140
		}
141 3fa6d462 jim-p
142 449cac24 Renato Botelho
		$savemsg = sprintf(gettext("Successfully deleted %s: %s"),
143
		    (count($deleted_groups) == 1)
144
		    ? gettext("group") : gettext("groups"),
145
		    implode(', ', $deleted_groups));
146
		/*
147
		 * Reindex the array to avoid operating on an incorrect index
148
		 * https://redmine.pfsense.org/issues/7733
149
		 */
150 92c27793 jim-p
		$a_group = array_values($a_group);
151 c0c5b8cc bruno
		write_config($savemsg);
152 3fa6d462 jim-p
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
153 c0c5b8cc bruno
	}
154
}
155
156 7ea27b0d Renato Botelho
if (isset($_POST['save'])) {
157 d88c6a9f Scott Ullrich
	unset($input_errors);
158
	$pconfig = $_POST;
159
160
	/* input validation */
161
	$reqdfields = explode(" ", "groupname");
162 b4fd804b Carlos Eduardo Ramos
	$reqdfieldsn = array(gettext("Group Name"));
163 4c291f4c Renato Botelho
164 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
165 4c291f4c Renato Botelho
166 d7689b2c Stephen Beaver
	if ($_POST['gtype'] != "remote") {
167 79ed8ce0 Stephen Beaver
		if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['groupname'])) {
168 449cac24 Renato Botelho
			$input_errors[] = sprintf(gettext(
169
			    "The (%s) group name contains invalid characters."),
170
			    $_POST['gtype']);
171 79ed8ce0 Stephen Beaver
		}
172
	} else {
173
		if (preg_match("/[^a-zA-Z0-9\.\- _]/", $_POST['groupname'])) {
174 449cac24 Renato Botelho
			$input_errors[] = sprintf(gettext(
175
			    "The (%s) group name contains invalid characters."),
176
			    $_POST['gtype']);
177 79ed8ce0 Stephen Beaver
		}
178 e0c7b2fe Phil Davis
	}
179 4c291f4c Renato Botelho
180 e0c7b2fe Phil Davis
	if (strlen($_POST['groupname']) > 16) {
181 449cac24 Renato Botelho
		$input_errors[] = gettext(
182
		    "The group name is longer than 16 characters.");
183 e0c7b2fe Phil Davis
	}
184 4c291f4c Renato Botelho
185 5bef2407 jim-p
	/* Check the POSTed members to ensure they are valid and exist */
186 9d3e8723 Phil Davis
	if (is_array($_POST['members'])) {
187 9f472202 NewEraCracker
		foreach ($_POST['members'] as $newmember) {
188 449cac24 Renato Botelho
			if (!is_numeric($newmember) ||
189
			    empty(getUserEntryByUID($newmember))) {
190
				$input_errors[] = gettext("One or more " .
191
				    "invalid group members was submitted.");
192 9f472202 NewEraCracker
			}
193 5bef2407 jim-p
		}
194
	}
195
196 d88c6a9f Scott Ullrich
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
197
		/* make sure there are no dupes */
198
		foreach ($a_group as $group) {
199
			if ($group['name'] == $_POST['groupname']) {
200 449cac24 Renato Botelho
				$input_errors[] = gettext("Another entry " .
201
				    "with the same group name already exists.");
202 d88c6a9f Scott Ullrich
				break;
203
			}
204
		}
205
	}
206 4c291f4c Renato Botelho
207 d88c6a9f Scott Ullrich
	if (!$input_errors) {
208 45ee90ed Matthew Grooms
		$group = array();
209 e0c7b2fe Phil Davis
		if (isset($id) && $a_group[$id]) {
210 d88c6a9f Scott Ullrich
			$group = $a_group[$id];
211 e0c7b2fe Phil Davis
		}
212 4c291f4c Renato Botelho
213 d88c6a9f Scott Ullrich
		$group['name'] = $_POST['groupname'];
214
		$group['description'] = $_POST['description'];
215 79ed8ce0 Stephen Beaver
		$group['scope'] = $_POST['gtype'];
216 45ee90ed Matthew Grooms
217 e0c7b2fe Phil Davis
		if (empty($_POST['members'])) {
218 70d6b5c4 Ermal
			unset($group['member']);
219 e0c7b2fe Phil Davis
		} else if ($group['gid'] != 1998) { // all group
220 6b07c15a Matthew Grooms
			$group['member'] = $_POST['members'];
221 e0c7b2fe Phil Davis
		}
222 45ee90ed Matthew Grooms
223 e0c7b2fe Phil Davis
		if (isset($id) && $a_group[$id]) {
224 d88c6a9f Scott Ullrich
			$a_group[$id] = $group;
225 e0c7b2fe Phil Davis
		} else {
226 45ee90ed Matthew Grooms
			$group['gid'] = $config['system']['nextgid']++;
227 d88c6a9f Scott Ullrich
			$a_group[] = $group;
228 45ee90ed Matthew Grooms
		}
229
230 06683083 Stephen Beaver
		admin_groups_sort();
231
232 659fa7f2 Matthew Grooms
		local_group_set($group);
233 2a0e8512 jim-p
234 449cac24 Renato Botelho
		/*
235
		 * Refresh users in this group since their privileges may have
236
		 * changed.
237
		 */
238 5709072a jim-p
		if (is_array($group['member'])) {
239 ea0dd417 jim-p
			init_config_arr(array('system', 'user'));
240 5709072a jim-p
			$a_user = &$config['system']['user'];
241
			foreach ($a_user as & $user) {
242 e0c7b2fe Phil Davis
				if (in_array($user['uid'], $group['member'])) {
243 5709072a jim-p
					local_user_set($user);
244 e0c7b2fe Phil Davis
				}
245 5709072a jim-p
			}
246 2a0e8512 jim-p
		}
247
248 dc3bc1f8 Renato Botelho
		/* Sort it alphabetically */
249
		usort($config['system']['group'], function($a, $b) {
250
			return strcmp($a['name'], $b['name']);
251
		});
252
253 449cac24 Renato Botelho
		$savemsg = sprintf(gettext("Successfully %s group %s"),
254
		    (strlen($id) > 0) ? gettext("edited") : gettext("created"),
255
		    $group['name']);
256 3fa6d462 jim-p
		write_config($savemsg);
257
		syslog($logging_level, "{$logging_prefix}: {$savemsg}");
258 4c291f4c Renato Botelho
259 d88c6a9f Scott Ullrich
		header("Location: system_groupmanager.php");
260
		exit;
261
	}
262 23d09a2e Stephen Beaver
263
	$pconfig['name'] = $_POST['groupname'];
264 fab7ff44 Bill Marquette
}
265
266 2f1e91e4 Stephen Beaver
function build_priv_table() {
267
	global $a_group, $id;
268
269
	$privhtml = '<div class="table-responsive">';
270
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
271
	$privhtml .=		'<thead>';
272 70da45c9 NOYB
	$privhtml .=			'<tr>';
273
	$privhtml .=				'<th>' . gettext('Name') . '</th>';
274
	$privhtml .=				'<th>' . gettext('Description') . '</th>';
275
	$privhtml .=				'<th>' . gettext('Action') . '</th>';
276
	$privhtml .=			'</tr>';
277 2f1e91e4 Stephen Beaver
	$privhtml .=		'</thead>';
278
	$privhtml .=		'<tbody>';
279
280 57188e47 Phil Davis
	$user_has_root_priv = false;
281
282 2f1e91e4 Stephen Beaver
	foreach (get_user_privdesc($a_group[$id]) as $i => $priv) {
283
		$privhtml .=		'<tr>';
284
		$privhtml .=			'<td>' . htmlspecialchars($priv['name']) . '</td>';
285 57188e47 Phil Davis
		$privhtml .=			'<td>' . htmlspecialchars($priv['descr']);
286
		if (isset($priv['warn']) && ($priv['warn'] == 'standard-warning-root')) {
287 21312954 Phil Davis
			$privhtml .=			' ' . gettext('(admin privilege)');
288 57188e47 Phil Davis
			$user_has_root_priv = true;
289
		}
290
		$privhtml .=			'</td>';
291 20231404 Steve Beaver
		$privhtml .=			'<td><a class="fa fa-trash" title="' . gettext('Delete Privilege') . '"	href="system_groupmanager.php?act=delpriv&amp;groupid=' . $id . '&amp;privid=' . $i . '" usepost></a></td>';
292 2f1e91e4 Stephen Beaver
		$privhtml .=		'</tr>';
293 d61309a0 Phil Davis
294 2f1e91e4 Stephen Beaver
	}
295
296 57188e47 Phil Davis
	if ($user_has_root_priv) {
297
		$privhtml .=		'<tr>';
298
		$privhtml .=			'<td colspan="2">';
299 9187d6f7 Phil Davis
		$privhtml .=				'<b>' . gettext('Security notice: Users in this group effectively have administrator-level access') . '</b>';
300 57188e47 Phil Davis
		$privhtml .=			'</td>';
301
		$privhtml .=			'<td>';
302
		$privhtml .=			'</td>';
303
		$privhtml .=		'</tr>';
304 20231404 Steve Beaver
305 57188e47 Phil Davis
	}
306
307 2f1e91e4 Stephen Beaver
	$privhtml .=		'</tbody>';
308
	$privhtml .=	'</table>';
309
	$privhtml .= '</div>';
310
311
	$privhtml .= '<nav class="action-buttons">';
312 4611e283 Steve Beaver
	$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>';
313 2f1e91e4 Stephen Beaver
	$privhtml .= '</nav>';
314
315
	return($privhtml);
316
}
317
318 8f1ab2a4 k-paulius
$pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Groups"));
319 edcd7535 Phil Davis
$pglinks = array("", "system_usermanager.php", "system_groupmanager.php");
320 8f1ab2a4 k-paulius
321
if ($act == "new" || $act == "edit") {
322
	$pgtitle[] = gettext('Edit');
323 edcd7535 Phil Davis
	$pglinks[] = "@self";
324 8f1ab2a4 k-paulius
}
325 23d09a2e Stephen Beaver
326 fab7ff44 Bill Marquette
include("head.inc");
327
328 d61309a0 Phil Davis
if ($input_errors) {
329 64600f94 Sjon Hortensius
	print_input_errors($input_errors);
330 d61309a0 Phil Davis
}
331 23d09a2e Stephen Beaver
332 d61309a0 Phil Davis
if ($savemsg) {
333 f78bbe16 Phil Davis
	print_info_box($savemsg, 'success');
334 d61309a0 Phil Davis
}
335 64600f94 Sjon Hortensius
336
$tab_array = array();
337
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
338
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
339
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
340 2d1f33d9 k-paulius
$tab_array[] = array(gettext("Authentication Servers"), false, "system_authservers.php");
341 64600f94 Sjon Hortensius
display_top_tabs($tab_array);
342
343 4611e283 Steve Beaver
if (!($act == "new" || $act == "edit")) {
344 64600f94 Sjon Hortensius
?>
345 060ed238 Stephen Beaver
<div class="panel panel-default">
346
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Groups')?></h2></div>
347
	<div class="panel-body">
348
		<div class="table-responsive">
349 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
350 060ed238 Stephen Beaver
				<thead>
351
					<tr>
352
						<th><?=gettext("Group name")?></th>
353
						<th><?=gettext("Description")?></th>
354
						<th><?=gettext("Member Count")?></th>
355
						<th><?=gettext("Actions")?></th>
356
					</tr>
357
				</thead>
358
				<tbody>
359 64600f94 Sjon Hortensius
<?php
360 d61309a0 Phil Davis
	foreach ($a_group as $i => $group):
361
		if ($group["name"] == "all") {
362 64600f94 Sjon Hortensius
			$groupcount = count($config['system']['user']);
363 19028049 Renato Botelho
		} elseif (is_array($group['member'])) {
364 64600f94 Sjon Hortensius
			$groupcount = count($group['member']);
365 19028049 Renato Botelho
		} else {
366
			$groupcount = 0;
367 d61309a0 Phil Davis
		}
368 64600f94 Sjon Hortensius
?>
369 060ed238 Stephen Beaver
					<tr>
370
						<td>
371
							<?=htmlspecialchars($group['name'])?>
372
						</td>
373
						<td>
374
							<?=htmlspecialchars($group['description'])?>
375
						</td>
376
						<td>
377
							<?=$groupcount?>
378
						</td>
379
						<td>
380 4611e283 Steve Beaver
							<a class="fa fa-pencil" title="<?=gettext("Edit group"); ?>" href="?act=edit&amp;groupid=<?=$i?>"></a>
381 060ed238 Stephen Beaver
							<?php if ($group['scope'] != "system"): ?>
382 20231404 Steve Beaver
								<a class="fa fa-trash"	title="<?=gettext("Delete group")?>" href="?act=delgroup&amp;groupid=<?=$i?>&amp;groupname=<?=$group['name']?>" usepost></a>
383 060ed238 Stephen Beaver
							<?php endif;?>
384
						</td>
385
					</tr>
386 64600f94 Sjon Hortensius
<?php
387
	endforeach;
388 fab7ff44 Bill Marquette
?>
389 060ed238 Stephen Beaver
				</tbody>
390
			</table>
391
		</div>
392 94404d94 Sander van Leeuwen
	</div>
393 060ed238 Stephen Beaver
</div>
394
395
<nav class="action-buttons">
396 4611e283 Steve Beaver
	<a href="?act=new" class="btn btn-success btn-sm">
397 060ed238 Stephen Beaver
		<i class="fa fa-plus icon-embed-btn"></i>
398
		<?=gettext("Add")?>
399
	</a>
400
</nav>
401 64600f94 Sjon Hortensius
<?php
402
	include('foot.inc');
403
	exit;
404 6b07c15a Matthew Grooms
}
405
406 64600f94 Sjon Hortensius
$form = new Form;
407
$form->setAction('system_groupmanager.php?act=edit');
408
$form->addGlobal(new Form_Input(
409
	'groupid',
410
	null,
411
	'hidden',
412
	$id
413
));
414
415 9d3e8723 Phil Davis
if (isset($id) && $a_group[$id]) {
416 64600f94 Sjon Hortensius
	$form->addGlobal(new Form_Input(
417
		'id',
418
		null,
419
		'hidden',
420
		$id
421
	));
422
423
	$form->addGlobal(new Form_Input(
424
		'gid',
425
		null,
426
		'hidden',
427
		$pconfig['gid']
428
	));
429 61dec0b0 Renato Botelho
}
430
431 5f88f964 k-paulius
$section = new Form_Section('Group Properties');
432 82833610 Stephen Beaver
433 e6acc2ee Sjon Hortensius
$section->addInput($input = new Form_Input(
434 64600f94 Sjon Hortensius
	'groupname',
435 153c3aa6 Phil Davis
	'*Group name',
436 64600f94 Sjon Hortensius
	'text',
437
	$pconfig['name']
438
));
439
440 d61309a0 Phil Davis
if ($pconfig['gtype'] == "system") {
441 1192840b Sjon Hortensius
	$input->setReadonly();
442 79ed8ce0 Stephen Beaver
443
	$section->addInput(new Form_Input(
444
		'gtype',
445 153c3aa6 Phil Davis
		'*Scope',
446 79ed8ce0 Stephen Beaver
		'text',
447
		$pconfig['gtype']
448
	))->setReadonly();
449
} else {
450
	$section->addInput(new Form_Select(
451
		'gtype',
452 153c3aa6 Phil Davis
		'*Scope',
453 79ed8ce0 Stephen Beaver
		$pconfig['gtype'],
454 82833610 Stephen Beaver
		["local" => gettext("Local"), "remote" => gettext("Remote")]
455 449cac24 Renato Botelho
	))->setHelp("<span class=\"text-danger\">Warning: Changing this " .
456
	    "setting may affect the local groups file, in which case a " .
457
	    "reboot may be required for the changes to take effect.</span>");
458 d61309a0 Phil Davis
}
459 e6acc2ee Sjon Hortensius
460 64600f94 Sjon Hortensius
$section->addInput(new Form_Input(
461
	'description',
462
	'Description',
463
	'text',
464
	$pconfig['description']
465 89140b63 NOYB
))->setHelp('Group description, for administrative information only');
466 64600f94 Sjon Hortensius
467
$form->add($section);
468 d61309a0 Phil Davis
469 449cac24 Renato Botelho
/* all users group */
470
if ($pconfig['gid'] != 1998) {
471
	/* Group membership */
472 2f1e91e4 Stephen Beaver
	$group = new Form_Group('Group membership');
473
474 449cac24 Renato Botelho
	/*
475
	 * Make a list of all the groups configured on the system, and a list of
476
	 * those which this user is a member of
477
	 */
478 2f1e91e4 Stephen Beaver
	$systemGroups = array();
479
	$usersGroups = array();
480
481
	foreach ($config['system']['user'] as $user) {
482 449cac24 Renato Botelho
		if (is_array($pconfig['members']) && in_array($user['uid'],
483
		    $pconfig['members'])) {
484
			/* Add it to the user's list */
485
			$usersGroups[ $user['uid'] ] = $user['name'];
486 d61309a0 Phil Davis
		} else {
487 449cac24 Renato Botelho
			/* Add it to the 'not a member of' list */
488
			$systemGroups[ $user['uid'] ] = $user['name'];
489 d61309a0 Phil Davis
		}
490 2f1e91e4 Stephen Beaver
	}
491
492
	$group->add(new Form_Select(
493
		'notmembers',
494
		null,
495 449cac24 Renato Botelho
		array_combine((array)$pconfig['groups'],
496
		    (array)$pconfig['groups']),
497 2f1e91e4 Stephen Beaver
		$systemGroups,
498
		true
499 6ef8f2e9 heper
	))->setHelp('Not members');
500 64600f94 Sjon Hortensius
501 2f1e91e4 Stephen Beaver
	$group->add(new Form_Select(
502 64600f94 Sjon Hortensius
		'members',
503 2f1e91e4 Stephen Beaver
		null,
504 449cac24 Renato Botelho
		array_combine((array)$pconfig['groups'],
505
		    (array)$pconfig['groups']),
506 2f1e91e4 Stephen Beaver
		$usersGroups,
507 64600f94 Sjon Hortensius
		true
508 6ef8f2e9 heper
	))->setHelp('Members');
509 2f1e91e4 Stephen Beaver
510
	$section->add($group);
511
512
	$group = new Form_Group('');
513
514
	$group->add(new Form_Button(
515
		'movetoenabled',
516 faab522f Renato Botelho
		'Move to "Members"',
517 37676f4e jim-p
		null,
518
		'fa-angle-double-right'
519 449cac24 Renato Botelho
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass(
520
	    'btn-info btn-sm');
521 2f1e91e4 Stephen Beaver
522
	$group->add(new Form_Button(
523
		'movetodisabled',
524 faab522f Renato Botelho
		'Move to "Not members',
525 37676f4e jim-p
		null,
526
		'fa-angle-double-left'
527 449cac24 Renato Botelho
	))->setAttribute('type','button')->removeClass('btn-primary')->addClass(
528
	    'btn-info btn-sm');
529 2f1e91e4 Stephen Beaver
530 449cac24 Renato Botelho
	$group->setHelp(
531
	    'Hold down CTRL (PC)/COMMAND (Mac) key to select multiple items.');
532 2f1e91e4 Stephen Beaver
	$section->add($group);
533 64600f94 Sjon Hortensius
534 6b07c15a Matthew Grooms
}
535
536 7af38087 jim-p
if (isset($pconfig['gid'])) {
537 64600f94 Sjon Hortensius
	$section = new Form_Section('Assigned Privileges');
538
539
	$section->addInput(new Form_StaticText(
540
		null,
541 2f1e91e4 Stephen Beaver
		build_priv_table()
542 64600f94 Sjon Hortensius
	));
543 6b07c15a Matthew Grooms
544 2f1e91e4 Stephen Beaver
545 64600f94 Sjon Hortensius
	$form->add($section);
546 6b07c15a Matthew Grooms
}
547
548 64600f94 Sjon Hortensius
print $form;
549 2f1e91e4 Stephen Beaver
?>
550 8fd9052f Colin Fleming
<script type="text/javascript">
551 2f1e91e4 Stephen Beaver
//<![CDATA[
552 d61309a0 Phil Davis
events.push(function() {
553 2f1e91e4 Stephen Beaver
554
	// On click . .
555
	$("#movetodisabled").click(function() {
556 449cac24 Renato Botelho
		moveOptions($('[name="members[]"] option'),
557
		    $('[name="notmembers[]"]'));
558 2f1e91e4 Stephen Beaver
	});
559
560
	$("#movetoenabled").click(function() {
561 449cac24 Renato Botelho
		moveOptions($('[name="notmembers[]"] option'),
562
		    $('[name="members[]"]'));
563 2f1e91e4 Stephen Beaver
	});
564
565
	// On submit mark all the user's groups as "selected"
566 d61309a0 Phil Davis
	$('form').submit(function() {
567 2f1e91e4 Stephen Beaver
		AllServers($('[name="members[]"] option'), true);
568
	});
569
});
570
//]]>
571
</script>
572
<?php
573 854fa106 heper
include('foot.inc');