mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-23 11:08:13 -05:00
b489f8f6f1
修复添加了服务后端中间件统一鉴权导致了一些后端鉴权不通过的问题
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
|
|
class Server
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$request->validate([
|
|
'token' => ['required','string',function ($attribute, $value, $fail) {
|
|
if ($value != admin_setting('server_token')) {
|
|
$fail("The $attribute is error.");
|
|
}
|
|
}],
|
|
'node_type' => [
|
|
'nullable',
|
|
'string',
|
|
'regex:/^(?i)(hysteria|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/',
|
|
function ($attribute, $value, $fail) {
|
|
// 将值转换为小写
|
|
request()->merge([$attribute => strtolower($value)]);
|
|
},
|
|
],
|
|
'node_id' => 'required'
|
|
]);
|
|
|
|
return $next($request);
|
|
}
|
|
}
|