forked from ChristianBeer/ProFTPd-Admin
-
Notifications
You must be signed in to change notification settings - Fork 11
/
add_group.php
113 lines (105 loc) · 4.84 KB
/
add_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
<?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 <[email protected]>
* @copyright Christian Beer <[email protected]>
* @copyright Ricardo Padilha <[email protected]>
*
*/
global $cfg;
include_once ("configs/config.php");
include_once ("includes/Session.php");
include_once ("includes/AdminClass.php");
$ac = new AdminClass($cfg);
$field_gid = $cfg['field_gid'];
$field_groupname = $cfg['field_groupname'];
$field_members = $cfg['field_members'];
$errors = array();
if (!empty($_REQUEST["action"]) && $_REQUEST["action"] == "create") {
/* group name validation */
if (empty($_REQUEST[$field_groupname])
|| !preg_match($cfg['groupname_regex'], $_REQUEST[$field_groupname])
|| strlen($_REQUEST[$field_groupname]) > $cfg['max_groupname_length']) {
array_push($errors, 'Invalid group name; group name must contain only letters, numbers, hyphens, and underscores with a maximum of '.$cfg['max_groupname_length'].' characters.');
}
/* group name uniqueness validation */
if ($ac->check_groupname($_REQUEST[$field_groupname])) {
array_push($errors, 'Name already exists; name must be unique.');
}
/* gid validation */
if (empty($_REQUEST[$field_gid]) || !$ac->is_valid_id($_REQUEST[$field_gid])) {
array_push($errors, 'Invalid GID; GID must be a positive integer.');
}
if ($cfg['max_gid'] != -1 && $cfg['min_gid'] != -1) {
if ($_REQUEST[$field_gid] > $cfg['max_gid'] || $_REQUEST[$field_gid] < $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_gid] > $cfg['max_gid']) {
array_push($errors, 'Invalid GID; GID must be at most ' . $cfg['max_gid'] . '.');
} else if ($cfg['min_gid'] != -1 && $_REQUEST[$field_gid] < $cfg['min_gid']) {
array_push($errors, 'Invalid GID; GID must be at least ' . $cfg['min_gid'] . '.');
}
/* gid uniqueness validation */
if ($ac->check_gid($_REQUEST[$field_gid])) {
array_push($errors, 'GID already exists; GID must be unique.');
}
/* data validation passed */
if (count($errors) == 0) {
$groupdata = array($field_groupname => $_REQUEST[$field_groupname],
$field_gid => $_REQUEST[$field_gid],
$field_members => '');
if ($ac->add_group($groupdata)) {
$infomsg = 'Group "'.$_REQUEST[$cfg['field_groupname']].'" created successfully.';
} else {
$errormsg = 'Group "'.$_REQUEST[$cfg['field_groupname']].'" creation failed; check log files.';
}
} else {
$errormsg = implode($errors, "<br />\n");
}
}
include ("includes/header.php");
?>
<?php include ("includes/messages.php"); ?>
<div class="col-xs-12 col-sm-8 col-md-6 center">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Add group</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<form role="form" class="form-horizontal" method="post" data-toggle="validator">
<!-- Group name -->
<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']; ?>" placeholder="Enter a group name" maxlength="<?php echo $cfg['max_groupname_length']; ?>" pattern="<?php echo substr($cfg['groupname_regex'], 2, -3); ?>" required>
<p class="help-block"><small>Only letters, numbers, hyphens, and underscores. Maximum <?php echo $cfg['max_groupname_length']; ?> characters.</small></p>
</div>
</div>
<!-- GID -->
<div class="form-group">
<label for="<?php echo $cfg['field_gid']; ?>" class="col-sm-4 control-label">GID</label>
<div class="col-sm-8">
<input type="number" class="form-control" id="<?php echo $field_gid; ?>" name="<?php echo $field_gid; ?>" placeholder="Enter the 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">
<a class="btn btn-default" href="groups.php">« View groups</a>
<button type="submit" class="btn btn-primary pull-right" name="action" value="create">Create group</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include ("includes/footer.php"); ?>