Project

General

Profile

Download (4.44 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_groupmanager_addprivs.php
5

    
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2006 Daniel S. Haischt.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	auth
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-system-groupmanager-addprivs
37
##|*NAME=System: Group Manager: Add Privileges page
38
##|*DESCR=Allow access to the 'System: Group Manager: Add Privileges' page.
39
##|*MATCH=system_groupmanager_addprivs.php*
40
##|-PRIV
41

    
42
function cpusercmp($a, $b) {
43
	return strcasecmp($a['name'], $b['name']);
44
}
45

    
46
function admin_groups_sort() {
47
	global $config;
48

    
49
	if (!is_array($config['system']['group'])) {
50
		return;
51
	}
52

    
53
	usort($config['system']['group'], "cpusercmp");
54
}
55

    
56
require("guiconfig.inc");
57

    
58
$pgtitle = array(gettext("System"), gettext("Group manager"), gettext("Add privileges"));
59

    
60
if (is_numericint($_GET['groupid'])) {
61
	$groupid = $_GET['groupid'];
62
}
63
if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) {
64
	$groupid = $_POST['groupid'];
65
}
66

    
67
$a_group = & $config['system']['group'][$groupid];
68

    
69
if (!is_array($a_group)) {
70
	pfSenseHeader("system_groupmanager.php?id={$groupid}");
71
	exit;
72
}
73

    
74
if (!is_array($a_group['priv'])) {
75
	$a_group['priv'] = array();
76
}
77

    
78
if ($_POST) {
79

    
80
	unset($input_errors);
81
	$pconfig = $_POST;
82

    
83
	/* input validation */
84
	$reqdfields = explode(" ", "sysprivs");
85
	$reqdfieldsn = array(gettext("Selected privileges"));
86

    
87
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88

    
89
	/* if this is an AJAX caller then handle via JSON */
90
	if (isAjax() && is_array($input_errors)) {
91
		input_errors2Ajax($input_errors);
92
		exit;
93
	}
94

    
95
	if (!$input_errors) {
96

    
97
		if (!is_array($pconfig['sysprivs'])) {
98
			$pconfig['sysprivs'] = array();
99
		}
100

    
101
		if (!count($a_group['priv'])) {
102
			$a_group['priv'] = $pconfig['sysprivs'];
103
		} else {
104
			$a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']);
105
		}
106

    
107
		if (is_array($a_group['member'])) {
108
			foreach ($a_group['member'] as $uid) {
109
				$user = getUserEntryByUID($uid);
110
				if ($user) {
111
					local_user_set($user);
112
				}
113
			}
114
		}
115

    
116
		admin_groups_sort();
117

    
118
		$retval = write_config();
119
		$savemsg = get_std_save_message($retval);
120

    
121
		pfSenseHeader("system_groupmanager.php?act=edit&groupid={$groupid}");
122
		exit;
123
	}
124
}
125

    
126
/* if ajax is calling, give them an update message */
127
if (isAjax()) {
128
	print_info_box_np($savemsg);
129
}
130

    
131
include("head.inc");
132

    
133
if ($input_errors)
134
	print_input_errors($input_errors);
135
if ($savemsg)
136
	print_info_box($savemsg);
137

    
138
$tab_array = array();
139
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
140
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
141
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
142
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
143
display_top_tabs($tab_array);
144

    
145
require('classes/Form.class.php');
146
$form = new Form;
147
if (isset($groupid))
148
{
149
	$form->addGlobal(new Form_Input(
150
		'groupid',
151
		null,
152
		'hidden',
153
		$groupid
154
	));
155
}
156

    
157
$section = new Form_Section('Add privileges for '. $a_group['name']);
158

    
159
$priv_list = array_map(function($p){ return $p['name']; }, $priv_list);
160
asort($priv_list);
161

    
162
$section->addInput(new Form_Select(
163
	'sysprivs',
164
	'Assigned privileges',
165
	$a_group['priv'],
166
	$priv_list,
167
	true
168
))->setHelp('Hold down CTRL (pc)/COMMAND (mac) key to select');
169

    
170
$form->add($section);
171

    
172
print $form;
173

    
174
include('foot.inc');
(208-208/238)