forked from ChristianBeer/ProFTPd-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_group.php
206 lines (197 loc) · 8.85 KB
/
edit_group.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* This file is part of ProFTPd Admin
*
* @package ProFTPd-Admin
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
*
* @copyright Lex Brugman <lex_brugman@users.sourceforge.net>
* @copyright Christian Beer <djangofett@gmx.net>
* @copyright Ricardo Padilha <ricardo@droboports.com>
*
*/
include_once ("configs/config.php");
include_once ("includes/AdminClass.php");
global $cfg;
$ac = new AdminClass($cfg);
$field_gid = $cfg['field_gid'];
$field_newgid = "new_".$cfg['field_gid'];
$field_groupname = $cfg['field_groupname'];
$field_members = $cfg['field_members'];
$field_id = $cfg['field_id'];
$field_uid = $cfg['field_uid'];
$field_disabled = $cfg['field_disabled'];
if (empty($_REQUEST[$field_gid])) {
header("Location: groups.php");
die();
}
$gid = $_REQUEST[$field_gid];
if (!$ac->is_valid_id($gid)) {
$errormsg = 'Invalid GID; must be a positive integer.';
} else {
$group = $ac->get_group_by_gid($gid);
if (!is_array($group)) {
$errormsg = 'Group does not exist; cannot find GID '.$gid.' in the database.';
} else {
$groupname = $group[$field_groupname];
$members = $group[$field_members];
$users_main = $ac->get_users_by_gid($gid);
$users_add = $ac->get_add_users_by_gid($gid);
}
}
if (empty($errormsg) && !empty($_REQUEST["action"]) && $_REQUEST["action"] == "update") {
$errors = array();
/* gid validation */
if (empty($_REQUEST[$field_newgid])
|| !$ac->is_valid_id($_REQUEST[$field_newgid])) {
array_push($errors, 'Invalid GID; GID must be a positive integer.');
}
/* gid uniqueness validation */
if (empty($errormsg) && $ac->check_gid($_REQUEST[$field_newgid])) {
array_push($errors, 'GID already exists; GID must be unique.');
}
/* gid range validation */
if ($cfg['max_gid'] != -1 && $cfg['min_gid'] != -1) {
if ($_REQUEST[$field_newgid] > $cfg['max_gid'] || $_REQUEST[$field_newgid] < $cfg['min_gid']) {
array_push($errors, 'Invalid GID; GID must be between ' . $cfg['min_gid'] . ' and ' . $cfg['max_gid'] . '.');
}
} else if ($cfg['max_gid'] != -1 && $_REQUEST[$field_newgid] > $cfg['max_gid']) {
array_push($errors, 'Invalid GID; GID must be at most ' . $cfg['max_gid'] . '.');
} else if ($cfg['min_gid'] != -1 && $_REQUEST[$field_newgid] < $cfg['min_gid']) {
array_push($errors, 'Invalid GID; GID must be at least ' . $cfg['min_gid'] . '.');
}
if (count($errors) == 0) {
/* data validation passed */
$newgid = $_REQUEST[$field_newgid];
if ($ac->update_group($gid, $newgid)) {
$infomsg = 'Group database updated successfully.';
/* update data */
$gid = $newgid;
$users_main = $ac->get_users_by_gid($gid);
$users_add = $ac->get_add_users_by_gid($gid);
} else {
$errormsg = 'Group update failed; check log files.';
}
} else {
$errormsg = implode($errors, "<br />\n");
}
}
include ("includes/header.php");
?>
<?php include ("includes/messages.php"); ?>
<?php if (is_array($group)) { ?>
<!-- Users panel -->
<div class="col-xs-12 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a data-toggle="collapse" href="#groupmembership" aria-expanded="true" aria-controls="groupmembership">Group membership</a>
</h3>
</div>
<div class="panel-body collapse in" id="groupmembership" aria-expanded="true">
<div class="col-sm-12">
<!-- Main users table -->
<h4>Main users</h4>
<?php if (!$users_main) { ?>
<p>Currently there are no users with this group as their main group.</p>
<?php } else { ?>
<table class="table table-striped table-condensed sortable">
<thead>
<th>UID</th>
<th><span class="glyphicon glyphicon-user" aria-hidden="true" title="User"></th>
<th><span class="glyphicon glyphicon-lock" aria-hidden="true" title="Suspended"></th>
<th data-defaultsort="disabled"></th>
</thead>
<tbody>
<?php reset($users_main); foreach ($users_main as $u_id => $u_userid) {
$user = $ac->get_user_by_id($u_id); ?>
<tr>
<td class="pull-middle"><?php echo $user[$field_uid]; ?></td>
<td class="pull-middle"><?php echo $u_userid; ?></td>
<td class="pull-middle"><?php echo ($user[$field_disabled] ? 'Yes' : 'No'); ?></td>
<td class="pull-middle">
<div class="btn-toolbar pull-right" role="toolbar">
<a class="btn-group" role="group" href="edit_user.php?action=show&<?php echo $field_id; ?>=<?php echo $u_id; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a class="btn-group" role="group" href="remove_user.php?action=remove&<?php echo $field_id; ?>=<?php echo $u_id; ?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<!-- Additional users table -->
<h4>Additional users</h4>
<?php if (!$users_add) { ?>
<p>Currently there are no users with this group in their additional groups.</p>
<?php } else { ?>
<table class="table table-striped table-condensed sortable">
<thead>
<th>UID</th>
<th><span class="glyphicon glyphicon-user" aria-hidden="true" title="User"></th>
<th><span class="glyphicon glyphicon-lock" aria-hidden="true" title="Suspended"></th>
<th data-defaultsort="disabled"></th>
</thead>
<tbody>
<?php reset($users_add); foreach ($users_add as $u_id => $u_userid) {
$user = $ac->get_user_by_id($u_id); ?>
<tr>
<td class="pull-middle"><?php echo $user[$field_uid]; ?></td>
<td class="pull-middle"><?php echo $u_userid; ?></td>
<td class="pull-middle"><?php echo ($user[$field_disabled] ? 'Yes' : 'No'); ?></td>
<td class="pull-middle">
<div class="btn-toolbar pull-right" role="toolbar">
<a class="btn-group" role="group" href="edit_user.php?action=show&<?php echo $field_id; ?>=<?php echo $u_id; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a class="btn-group" role="group" href="remove_user.php?action=remove&<?php echo $field_id; ?>=<?php echo $u_id; ?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</div>
</div>
</div>
</div>
<!-- Edit panel -->
<div class="col-xs-12 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a data-toggle="collapse" href="#groupprops" aria-expanded="true" aria-controls="groupprops">Group properties</a>
</h3>
</div>
<div class="panel-body collapse in" id="groupprops" aria-expanded="true">
<div class="col-sm-12">
<form role="form" class="form-horizontal" method="post" data-toggle="validator">
<!-- Group name (readonly) -->
<div class="form-group">
<label for="<?php echo $cfg['field_groupname']; ?>" class="col-sm-4 control-label">Group name</label>
<div class="controls col-sm-8">
<input type="text" class="form-control" id="<?php echo $cfg['field_groupname']; ?>" name="<?php echo $cfg['field_groupname']; ?>" value="<?php echo $groupname; ?>" readonly />
</div>
</div>
<!-- GID -->
<div class="form-group">
<label for="<?php echo $cfg['field_gid']; ?>" class="col-sm-4 control-label">New GID</label>
<div class="col-sm-8">
<input type="number" class="form-control" id="new_<?php echo $cfg['field_gid']; ?>" name="new_<?php echo $cfg['field_gid']; ?>" value="<?php echo $gid; ?>" placeholder="Enter the new GID" min="1" required />
<p class="help-block"><small>Positive integer.</small></p>
</div>
</div>
<!-- Actions -->
<div class="form-group">
<div class="col-sm-12">
<input type="hidden" name="<?php echo $field_gid; ?>" value="<?php echo $gid; ?>" />
<a class="btn btn-danger" href="remove_group.php?action=remove&<?php echo $field_gid; ?>=<?php echo $gid; ?>">Remove group</a>
<button type="submit" class="btn btn-primary pull-right" role="group" name="action" value="update">Update group</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
<?php include ("includes/footer.php"); ?>