Skip to content

Commit 4e3123e

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 0a59f96 commit 4e3123e

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

configuration.example.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174

175175
// If automatic groups mode is disabled, then you have to manually add the allowed groups into $allowed_groups down below:
176176
// If enabled, then any groups you are a memberof will automatically be added in using the template below.
177-
$auto_groups_mode = false;
177+
$auto_groups_mode = true;
178178

179179
$auto_groups_mode_virtual_folder_template = [
180180
[
@@ -190,6 +190,14 @@
190190
]
191191
];
192192

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

functions.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ function createResponseObject($connectionName, $username, $groups = []) {
138138
$user_output_objects,
139139
$allowed_groups,
140140
$auto_groups_mode,
141-
$auto_groups_mode_virtual_folder_template;
141+
$auto_groups_mode_virtual_folder_template,
142+
$allowed_group_prefixes;
142143

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

@@ -172,17 +173,32 @@ function createResponseObject($connectionName, $username, $groups = []) {
172173
if (!empty($groups)) {
173174
if ($auto_groups_mode) {
174175
foreach($groups as $group) {
175-
if (isset($auto_groups_mode_virtual_folder_template)) {
176-
foreach($auto_groups_mode_virtual_folder_template as $virtual_group_folder) {
177176

178-
$virtual_group_folder['name'] = str_replace('#GROUP#', $group, $virtual_group_folder['name']);
179-
$virtual_group_folder['mapped_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['mapped_path']);
180-
$virtual_group_folder['virtual_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['virtual_path']);
177+
$allowed = true;
181178

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

184-
// Defaulting to open permissions on the virtual group folder:
185-
$output['permissions'][$virtual_group_folder['virtual_path']] = ["*"];
193+
$virtual_group_folder['name'] = str_replace('#GROUP#', $group, $virtual_group_folder['name']);
194+
$virtual_group_folder['mapped_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['mapped_path']);
195+
$virtual_group_folder['virtual_path'] = str_replace('#GROUP#', $group, $virtual_group_folder['virtual_path']);
196+
197+
$output['virtual_folders'][] = $virtual_group_folder;
198+
199+
// Defaulting to open permissions on the virtual group folder:
200+
$output['permissions'][$virtual_group_folder['virtual_path']] = ["*"];
201+
}
186202
}
187203
}
188204
}

0 commit comments

Comments
 (0)