2023-11-29 13:53:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class CaddyRequestMiddleware
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*/
|
|
|
|
public function handle(Request $request, Closure $next)
|
|
|
|
{
|
|
|
|
if (!config('custom-domains.enabled')) {
|
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
|
|
|
'message' => 'Custom domains not enabled',
|
|
|
|
], 401);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config('custom-domains.enabled') && !in_array($request->ip(), config('custom-domains.authorized_ips'))) {
|
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
2023-11-30 10:20:19 +00:00
|
|
|
'message' => 'Unauthorized IP',
|
2023-11-29 13:53:08 +00:00
|
|
|
], 401);
|
|
|
|
}
|
|
|
|
|
|
|
|
$secret = $request->route('secret');
|
|
|
|
if (config('custom-domains.caddy_secret') && (!$secret || $secret !== config('custom-domains.caddy_secret'))) {
|
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
|
|
|
'message' => 'Unauthorized',
|
|
|
|
], 401);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|