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