Skip to content

Commit 50cb361

Browse files
committed
Adding in allowed group prefixes functionality (allows you to enable auto mode for groups, but limit creation to just those groups with a matching prefix).
1 parent 78630b0 commit 50cb361

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

configuration.example.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@
191191
]
192192
];
193193

194+
// Used only when auto groups mode is enabled and will help prevent all your groups from being
195+
// added into SFTPGo since only groups with the prefixes defined here will be automatically added
196+
// with prefixes automatically removed when listed as a virtual folder (e.g. a group with name
197+
// "sftpgo-example" would simply become "example").
198+
$allowed_group_prefixes = [
199+
'sftpgo-'
200+
];
201+
194202
// List of groups where a virtual folder will be created and associated with any group members:
195203
$allowed_groups = [];
196204

functions.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ function createResponseObject($connectionName, $username, $groups = []) {
135135
$user_output_objects,
136136
$allowed_groups,
137137
$auto_groups_mode,
138-
$auto_groups_mode_virtual_folder_template;
138+
$auto_groups_mode_virtual_folder_template,
139+
$allowed_group_prefixes;
139140

140141
$userHomeDirectory = str_replace('#USERNAME#', $username, $home_directories[$connectionName]);
141142

@@ -169,17 +170,32 @@ function createResponseObject($connectionName, $username, $groups = []) {
169170
if (!empty($groups)) {
170171
if ($auto_groups_mode) {
171172
foreach($groups as $group) {
172-
if (isset($auto_groups_mode_virtual_folder_template)) {
173-
foreach($auto_groups_mode_virtual_folder_template as $virtual_group_folder) {
174173

175-
$virtual_group_folder['name'] = str_replace('#GROUP#', $group, $virtual_group_folder['name']);
176-
$virtual_group_folder['mapped_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['mapped_path']);
177-
$virtual_group_folder['virtual_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['virtual_path']);
174+
$allowed = true;
178175

179-
$output['virtual_folders'][] = $virtual_group_folder;
176+
if (!empty($allowed_group_prefixes)) {
177+
$allowed = false;
178+
foreach($allowed_group_prefixes as $allowed_group_prefix) {
179+
if (strpos($group, $allowed_group_prefix) === 0) {
180+
$allowed = true;
181+
$group = str_replace($allowed_group_prefix, '', $group);
182+
}
183+
}
184+
}
185+
186+
if ($allowed) {
187+
if (isset($auto_groups_mode_virtual_folder_template)) {
188+
foreach($auto_groups_mode_virtual_folder_template as $virtual_group_folder) {
180189

181-
// Defaulting to open permissions on the virtual group folder:
182-
$output['permissions'][$virtual_group_folder['virtual_path']] = ["*"];
190+
$virtual_group_folder['name'] = str_replace('#GROUP#', $group, $virtual_group_folder['name']);
191+
$virtual_group_folder['mapped_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['mapped_path']);
192+
$virtual_group_folder['virtual_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['virtual_path']);
193+
194+
$output['virtual_folders'][] = $virtual_group_folder;
195+
196+
// Defaulting to open permissions on the virtual group folder:
197+
$output['permissions'][$virtual_group_folder['virtual_path']] = ["*"];
198+
}
183199
}
184200
}
185201
}

0 commit comments

Comments
 (0)