Skip to content

Commit 24f340c

Browse files
committed
Fix up SFTP endpoint
1 parent 2570b4e commit 24f340c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/Http/Controllers/Api/Remote/SftpController.php renamed to app/Http/Controllers/Api/Remote/SftpAuthenticationController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1313
use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest;
1414

15-
class SftpController extends Controller
15+
class SftpAuthenticationController extends Controller
1616
{
1717
use ThrottlesLogins;
1818

@@ -40,9 +40,12 @@ public function __construct(AuthenticateUsingPasswordService $authenticationServ
4040
*
4141
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
4242
*/
43-
public function index(SftpAuthenticationFormRequest $request): JsonResponse
43+
public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
4444
{
45+
// Reverse the string to avoid issues with usernames that contain periods.
4546
$parts = explode('.', strrev($request->input('username')), 2);
47+
48+
// Unreverse the strings after parsing them apart.
4649
$connection = [
4750
'username' => strrev(array_get($parts, 1)),
4851
'server' => strrev(array_get($parts, 0)),
@@ -86,6 +89,8 @@ public function index(SftpAuthenticationFormRequest $request): JsonResponse
8689
*/
8790
protected function throttleKey(Request $request)
8891
{
89-
return strtolower(array_get(explode('.', $request->input('username')), 0) . '|' . $request->ip());
92+
$username = explode('.', strrev($request->input('username', '')));
93+
94+
return strtolower(strrev($username[0] ?? '') . '|' . $request->ip());
9095
}
9196
}

routes/api-remote.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts');
1010
});
1111

12-
Route::group(['prefix' => '/sftp'], function () {
13-
Route::post('/', 'SftpController@index')->name('api.remote.sftp');
14-
});
15-
12+
// Routes for the Wings daemon.
13+
Route::post('/sftp/auth', 'SftpAuthenticationController');
1614
Route::group(['prefix' => '/servers/{uuid}'], function () {
1715
Route::get('/configuration', 'Servers\ServerConfigurationController');
1816
});

0 commit comments

Comments
 (0)