Project

General

Profile

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

    
235
	<nav class="action-buttons">
236
		<a href="?act=new" class="btn btn-success">add new</a>
237
	</nav>
238
<?php
239
	include('foot.inc');
240
	exit;
241
}
242

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

    
253
if (isset($id) && $a_group[$id]){
254
	$form->addGlobal(new Form_Input(
255
		'id',
256
		null,
257
		'hidden',
258
		$id
259
	));
260

    
261
	$form->addGlobal(new Form_Input(
262
		'gid',
263
		null,
264
		'hidden',
265
		$pconfig['gid']
266
	));
267
}
268

    
269
$section = new Form_Section('Group properties');
270

    
271
if ($_GET['act'] != "new")
272
{
273
	$section->addInput(new Form_StaticText(
274
		'Defined by',
275
		strtoupper($pconfig['gtype'])
276
	));
277
}
278

    
279
$section->addInput($input = new Form_Input(
280
	'groupname',
281
	'Group name',
282
	'text',
283
	$pconfig['name']
284
));
285

    
286
if ($pconfig['gtype'] == "system")
287
	$input->setReadonly();
288

    
289
$section->addInput(new Form_Input(
290
	'description',
291
	'Description',
292
	'text',
293
	$pconfig['description']
294
))->setHelp('Group description, for your own information only');
295

    
296
$form->add($section);
297
if ($pconfig['gid'] != 1998) // all users group
298
{
299
	$section = new Form_Section('Group Memberships');
300

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

    
310
	$form->add($section);
311
}
312

    
313
if ($_GET['act'] != "new")
314
{
315
	$section = new Form_Section('Assigned Privileges');
316

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

    
322
		$group->add(new Form_Checkbox(
323
			'delpriv[]',
324
			null,
325
			$priv_list[ $priv ]['name'],
326
			false,
327
			$i
328
		));
329

    
330
		$section->add($group);
331
	}
332

    
333
	$section->addInput(new Form_StaticText(
334
		null,
335
		new Form_Button(null, 'grant more privileges', 'system_groupmanager_addprivs.php?groupid='. $id)
336
	));
337

    
338
	$form->add($section);
339
}
340

    
341
print $form;
342

    
343
include('foot.inc');
(210-210/241)