Project

General

Profile

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