2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Providers;
|
|
|
|
|
2021-10-23 19:17:16 +00:00
|
|
|
use Illuminate\Http\Request;
|
2022-05-22 18:10:01 +00:00
|
|
|
use Pterodactyl\Models\Database;
|
2016-09-03 21:09:00 +00:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2021-10-23 19:17:16 +00:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
2022-05-21 20:58:04 +00:00
|
|
|
use Pterodactyl\Http\Middleware\TrimStrings;
|
2022-05-22 21:23:48 +00:00
|
|
|
use Pterodactyl\Http\Middleware\AdminAuthenticate;
|
2022-05-22 22:16:47 +00:00
|
|
|
use Pterodactyl\Http\Middleware\RequireTwoFactorAuthentication;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
|
|
|
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
|
|
{
|
2022-05-21 20:58:04 +00:00
|
|
|
protected const FILE_PATH_REGEX = '/^\/api\/client\/servers\/([a-z0-9-]{36})\/files(\/?$|\/(.)*$)/i';
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
/**
|
2021-10-23 19:17:16 +00:00
|
|
|
* Define your route model bindings, pattern filters, etc.
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
2021-10-23 19:17:16 +00:00
|
|
|
public function boot()
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2021-10-23 19:17:16 +00:00
|
|
|
$this->configureRateLimiting();
|
|
|
|
|
2022-05-21 20:58:04 +00:00
|
|
|
// Disable trimming string values when requesting file information — it isn't helpful
|
|
|
|
// and messes up the ability to actually open a directory that ends with a space.
|
|
|
|
TrimStrings::skipWhen(function (Request $request) {
|
|
|
|
return preg_match(self::FILE_PATH_REGEX, $request->getPathInfo()) === 1;
|
|
|
|
});
|
|
|
|
|
2022-05-22 18:10:01 +00:00
|
|
|
// This is needed to make use of the "resolveRouteBinding" functionality in the
|
|
|
|
// model. Without it you'll never trigger that logic flow thus resulting in a 404
|
|
|
|
// error because we request databases with a HashID, and not with a normal ID.
|
|
|
|
Route::model('database', Database::class);
|
|
|
|
|
2021-10-23 19:17:16 +00:00
|
|
|
$this->routes(function () {
|
2022-05-22 21:23:48 +00:00
|
|
|
Route::middleware('web')->group(function () {
|
2022-05-22 22:16:47 +00:00
|
|
|
Route::middleware(['auth.session', RequireTwoFactorAuthentication::class])
|
|
|
|
->group(base_path('routes/base.php'));
|
|
|
|
|
|
|
|
Route::middleware(['auth.session', RequireTwoFactorAuthentication::class, AdminAuthenticate::class])
|
|
|
|
->prefix('/admin')
|
|
|
|
->group(base_path('routes/admin.php'));
|
|
|
|
|
2022-05-14 19:51:05 +00:00
|
|
|
Route::middleware('guest')->prefix('/auth')->group(base_path('routes/auth.php'));
|
|
|
|
});
|
|
|
|
|
2022-05-22 22:16:47 +00:00
|
|
|
Route::middleware(['api', RequireTwoFactorAuthentication::class])->group(function () {
|
2022-05-14 19:51:05 +00:00
|
|
|
Route::middleware(['application-api', 'throttle:api.application'])
|
|
|
|
->prefix('/api/application')
|
2022-05-22 18:10:01 +00:00
|
|
|
->scopeBindings()
|
2022-05-14 19:51:05 +00:00
|
|
|
->group(base_path('routes/api-application.php'));
|
|
|
|
|
|
|
|
Route::middleware(['client-api', 'throttle:api.client'])
|
|
|
|
->prefix('/api/client')
|
2022-05-22 18:10:01 +00:00
|
|
|
->scopeBindings()
|
2022-05-14 19:51:05 +00:00
|
|
|
->group(base_path('routes/api-client.php'));
|
|
|
|
});
|
|
|
|
|
2022-05-22 18:10:01 +00:00
|
|
|
Route::middleware('daemon')
|
|
|
|
->prefix('/api/remote')
|
|
|
|
->scopeBindings()
|
2021-10-23 19:17:16 +00:00
|
|
|
->group(base_path('routes/api-remote.php'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure the rate limiters for the application.
|
|
|
|
*/
|
|
|
|
protected function configureRateLimiting()
|
|
|
|
{
|
|
|
|
// Authentication rate limiting. For login and checkpoint endpoints we'll apply
|
|
|
|
// a limit of 10 requests per minute, for the forgot password endpoint apply a
|
|
|
|
// limit of two per minute for the requester so that there is less ability to
|
|
|
|
// trigger email spam.
|
|
|
|
RateLimiter::for('authentication', function (Request $request) {
|
|
|
|
if ($request->route()->named('auth.post.forgot-password')) {
|
|
|
|
return Limit::perMinute(2)->by($request->ip());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Limit::perMinute(10);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Configure the throttles for both the application and client APIs below.
|
|
|
|
// This is configurable per-instance in "config/http.php". By default this
|
|
|
|
// limiter will be tied to the specific request user, and falls back to the
|
|
|
|
// request IP if there is no request user present for the key.
|
|
|
|
//
|
|
|
|
// This means that an authenticated API user cannot use IP switching to get
|
|
|
|
// around the limits.
|
|
|
|
RateLimiter::for('api.client', function (Request $request) {
|
|
|
|
$key = optional($request->user())->uuid ?: $request->ip();
|
|
|
|
|
|
|
|
return Limit::perMinutes(
|
|
|
|
config('http.rate_limit.client_period'),
|
|
|
|
config('http.rate_limit.client')
|
|
|
|
)->by($key);
|
|
|
|
});
|
|
|
|
|
|
|
|
RateLimiter::for('api.application', function (Request $request) {
|
|
|
|
$key = optional($request->user())->uuid ?: $request->ip();
|
|
|
|
|
|
|
|
return Limit::perMinutes(
|
|
|
|
config('http.rate_limit.application_period'),
|
|
|
|
config('http.rate_limit.application')
|
|
|
|
)->by($key);
|
|
|
|
});
|
2017-04-02 01:01:10 +00:00
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|