Project

General

Profile

Download (8.36 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	$Id: system_groupmanager.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	part of pfSense
6

    
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	All rights reserved.
9

    
10
	Copyright (C) 2008 Shrew Soft Inc.
11
	All rights reserved.
12

    
13
	Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
14
	All rights reserved.
15

    
16
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
17
	All rights reserved.
18

    
19
	Redistribution and use in source and binary forms, with or without
20
	modification, are permitted provided that the following conditions are met:
21

    
22
	1. Redistributions of source code must retain the above copyright notice,
23
	   this list of conditions and the following disclaimer.
24

    
25
	2. Redistributions in binary form must reproduce the above copyright
26
	   notice, this list of conditions and the following disclaimer in the
27
	   documentation and/or other materials provided with the distribution.
28

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

    
44
##|+PRIV
45
##|*IDENT=page-system-groupmanager
46
##|*NAME=System: Group manager page
47
##|*DESCR=Allow access to the 'System: Group manager' page.
48
##|*MATCH=system_groupmanager.php*
49
##|-PRIV
50

    
51
require("guiconfig.inc");
52

    
53
$pgtitle = array(gettext("System"), gettext("Group manager"));
54

    
55
if (!is_array($config['system']['group']))
56
	$config['system']['group'] = array();
57

    
58
$a_group = &$config['system']['group'];
59

    
60
unset($id);
61
if (isset($_POST['groupid']) && is_numericint($_POST['groupid']))
62
	$id = $_POST['groupid'];
63
elseif (isset($_GET['groupid']) && is_numericint($_GET['groupid']))
64
	$id = $_GET['groupid'];
65

    
66
if ($_POST['act'] == "delgroup") {
67

    
68
	if (!isset($id) || !isset($_POST['groupname']) || !isset($a_group[$id]) || ($_POST['groupname'] != $a_group[$id]['name'])) {
69
		pfSenseHeader("system_groupmanager.php");
70
		exit;
71
	}
72

    
73
	conf_mount_rw();
74
	local_group_del($a_group[$id]);
75
	conf_mount_ro();
76
	$groupdeleted = $a_group[$id]['name'];
77
	unset($a_group[$id]);
78
	write_config();
79
	$savemsg = gettext("Group")." {$groupdeleted} ".
80
		gettext("successfully deleted")."<br />";
81
}
82

    
83
if ($_GET['act'] == "edit") {
84
	// This used to be a separate act=delpriv
85
	if (isset($a_group[$id]) && !empty($_POST['delpriv'])) {
86
		foreach ($_POST['delpriv'] as $i)
87
			unset($a_group[$id]['priv'][ $i ]);
88

    
89
		if (is_array($a_group[$id]['member'])) {
90
			foreach ($a_group[$id]['member'] as $uid) {
91
				$user = getUserEntryByUID($uid);
92
				if ($user)
93
					local_user_set($user);
94
			}
95
		}
96

    
97
		write_config();
98
	}
99

    
100
	if (isset($id) && isset($a_group[$id])) {
101
		$pconfig['name'] = $a_group[$id]['name'];
102
		$pconfig['gid'] = $a_group[$id]['gid'];
103
		$pconfig['gtype'] = $a_group[$id]['scope'];
104
		$pconfig['description'] = $a_group[$id]['description'];
105
		$pconfig['members'] = $a_group[$id]['member'];
106
		$pconfig['priv'] = $a_group[$id]['priv'];
107
	}
108
}
109

    
110
if (isset($_POST['save'])) {
111
	unset($input_errors);
112
	$pconfig = $_POST;
113

    
114
	/* input validation */
115
	$reqdfields = explode(" ", "groupname");
116
	$reqdfieldsn = array(gettext("Group Name"));
117

    
118
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
119

    
120
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
121
		$input_errors[] = gettext("The group name contains invalid characters.");
122

    
123
	if (strlen($_POST['groupname']) > 16)
124
		$input_errors[] = gettext("The group name is longer than 16 characters.");
125

    
126
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
127
		/* make sure there are no dupes */
128
		foreach ($a_group as $group) {
129
			if ($group['name'] == $_POST['groupname']) {
130
				$input_errors[] = gettext("Another entry with the same group name already exists.");
131
				break;
132
			}
133
		}
134
	}
135

    
136
	if (!$input_errors) {
137
		$group = array();
138
		if (isset($id) && $a_group[$id])
139
			$group = $a_group[$id];
140

    
141
		$group['name'] = $_POST['groupname'];
142
		$group['description'] = $_POST['description'];
143

    
144
		if (empty($_POST['members']))
145
			unset($group['member']);
146
		else if ($group['gid'] != 1998) // all group
147
			$group['member'] = $_POST['members'];
148

    
149
		if (isset($id) && $a_group[$id])
150
			$a_group[$id] = $group;
151
		else {
152
			$group['gid'] = $config['system']['nextgid']++;
153
			$a_group[] = $group;
154
		}
155

    
156
		conf_mount_rw();
157
		local_group_set($group);
158
		conf_mount_ro();
159

    
160
		/* Refresh users in this group since their privileges may have changed. */
161
		if (is_array($group['member'])) {
162
			$a_user = &$config['system']['user'];
163
			foreach ($a_user as & $user) {
164
				if (in_array($user['uid'], $group['member']))
165
					local_user_set($user);
166
			}
167
		}
168

    
169
		write_config();
170

    
171
		header("Location: system_groupmanager.php");
172
		exit;
173
	}
174
}
175

    
176
include("head.inc");
177

    
178
if ($input_errors)
179
	print_input_errors($input_errors);
180
if ($savemsg)
181
	print_info_box($savemsg);
182

    
183
$tab_array = array();
184
$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
185
$tab_array[] = array(gettext("Groups"), true, "system_groupmanager.php");
186
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
187
$tab_array[] = array(gettext("Servers"), false, "system_authservers.php");
188
display_top_tabs($tab_array);
189

    
190
if (!($_GET['act'] == "new" || $_GET['act'] == "edit"))
191
{
192
?>
193
<table class="table">
194
	<thead>
195
		<tr>
196
			<th><?=gettext("Group name")?></th>
197
			<th><?=gettext("Description")?></th>
198
			<th><?=gettext("Member Count")?></th>
199
			<th></th>
200
		</tr>
201
	</thead>
202
	<tbody>
203
<?php
204
	foreach($a_group as $i => $group):
205
		if ($group["name"] == "all")
206
			$groupcount = count($config['system']['user']);
207
		else
208
			$groupcount = count($group['member']);
209
?>
210
		<tr>
211
			<td>
212
				<?=htmlspecialchars($group['name'])?>
213
			</td>
214
			<td>
215
				<?=htmlspecialchars($group['description'])?>
216
			</td>
217
			<td>
218
				<?=$groupcount?>
219
			</td>
220
			<td>
221
				<a href="?act=edit&amp;groupid=<?=$i?>" class="btn btn-xs btn-primary">edit</a>
222
				<?php if($group['scope'] != "system"): ?>
223
					<a href="?act=delgroup&amp;groupid=<?=$i?>&amp;groupname=<?=$group['name']?>" class="btn btn-xs btn-danger">delete</a>
224
				<?php endif;?>
225
			</td>
226
		</tr>
227
<?php
228
	endforeach;
229
?>
230
		</tbody>
231
	</table>
232

    
233
	<a href="?act=new" class="btn btn-success">add new</a>
234
<?php
235
	include('foot.inc');
236
	exit;
237
}
238

    
239
require('classes/Form.class.php');
240
$form = new Form;
241
$form->setAction('system_groupmanager.php?act=edit');
242
$form->addGlobal(new Form_Input(
243
	'groupid',
244
	null,
245
	'hidden',
246
	$id
247
));
248

    
249
if (isset($id) && $a_group[$id]){
250
	$form->addGlobal(new Form_Input(
251
		'id',
252
		null,
253
		'hidden',
254
		$id
255
	));
256

    
257
	$form->addGlobal(new Form_Input(
258
		'gid',
259
		null,
260
		'hidden',
261
		$pconfig['gid']
262
	));
263
}
264

    
265
$section = new Form_Section('Group properties');
266

    
267
if ($_GET['act'] != "new")
268
{
269
	$section->addInput(new Form_StaticText(
270
		'Defined by',
271
		strtoupper($pconfig['gtype'])
272
	));
273
}
274

    
275
$section->addInput($input = new Form_Input(
276
	'groupname',
277
	'Group name',
278
	'text',
279
	$pconfig['name']
280
));
281

    
282
if ($pconfig['gtype'] == "system")
283
	$input->setReadonly();
284

    
285
$section->addInput(new Form_Input(
286
	'description',
287
	'Description',
288
	'text',
289
	$pconfig['description']
290
))->setHelp('Group description, for your own information only');
291

    
292
$form->add($section);
293
if ($pconfig['gid'] != 1998) // all users group
294
{
295
	$section = new Form_Section('Group Memberships');
296

    
297
	$allUsers = array_map(function($u){ return $u['name']; }, $config['system']['user']);
298
	$section->addInput(new Form_Select(
299
		'members',
300
		'Members',
301
		$pconfig['members'],
302
		$allUsers,
303
		true
304
	))->setHelp('Hold down CTRL (pc)/COMMAND (mac) key to select');
305

    
306
	$form->add($section);
307
}
308

    
309
if ($_GET['act'] != "new")
310
{
311
	$section = new Form_Section('Assigned Privileges');
312

    
313
	foreach ((array)$pconfig['priv'] as $i => $priv)
314
	{
315
		// We reverse name and action for readability of longer names
316
		$group = new Form_Group('Revoke privilege');
317

    
318
		$group->add(new Form_Checkbox(
319
			'delpriv[]',
320
			null,
321
			$priv_list[ $priv ]['name'],
322
			false,
323
			$i
324
		));
325

    
326
		$section->add($group);
327
	}
328

    
329
	$section->addInput(new Form_StaticText(
330
		null,
331
		new Form_Button(null, 'grant more privileges', 'system_groupmanager_addprivs.php?groupid='. $id)
332
	));
333

    
334
	$form->add($section);
335
}
336

    
337
print $form;
338

    
339
include('foot.inc');
(222-222/253)