Fix up SFTP endpoint

This commit is contained in:
Dane Everitt 2019-12-07 16:14:04 -08:00
parent 2570b4e2d0
commit 24f340c9a1
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 10 additions and 7 deletions

View file

@ -12,7 +12,7 @@ use Pterodactyl\Services\Sftp\AuthenticateUsingPasswordService;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest; use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest;
class SftpController extends Controller class SftpAuthenticationController extends Controller
{ {
use ThrottlesLogins; use ThrottlesLogins;
@ -40,9 +40,12 @@ class SftpController extends Controller
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/ */
public function index(SftpAuthenticationFormRequest $request): JsonResponse public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
{ {
// Reverse the string to avoid issues with usernames that contain periods.
$parts = explode('.', strrev($request->input('username')), 2); $parts = explode('.', strrev($request->input('username')), 2);
// Unreverse the strings after parsing them apart.
$connection = [ $connection = [
'username' => strrev(array_get($parts, 1)), 'username' => strrev(array_get($parts, 1)),
'server' => strrev(array_get($parts, 0)), 'server' => strrev(array_get($parts, 0)),
@ -86,6 +89,8 @@ class SftpController extends Controller
*/ */
protected function throttleKey(Request $request) protected function throttleKey(Request $request)
{ {
return strtolower(array_get(explode('.', $request->input('username')), 0) . '|' . $request->ip()); $username = explode('.', strrev($request->input('username', '')));
return strtolower(strrev($username[0] ?? '') . '|' . $request->ip());
} }
} }

View file

@ -9,10 +9,8 @@ Route::group(['prefix' => '/scripts'], function () {
Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts'); Route::get('/{uuid}', 'EggInstallController@index')->name('api.remote.scripts');
}); });
Route::group(['prefix' => '/sftp'], function () { // Routes for the Wings daemon.
Route::post('/', 'SftpController@index')->name('api.remote.sftp'); Route::post('/sftp/auth', 'SftpAuthenticationController');
});
Route::group(['prefix' => '/servers/{uuid}'], function () { Route::group(['prefix' => '/servers/{uuid}'], function () {
Route::get('/configuration', 'Servers\ServerConfigurationController'); Route::get('/configuration', 'Servers\ServerConfigurationController');
}); });