diff --git a/app/Http/Controllers/Admin/ServerController.php b/app/Http/Controllers/Admin/ServerController.php index 1de6debb..0a559581 100755 --- a/app/Http/Controllers/Admin/ServerController.php +++ b/app/Http/Controllers/Admin/ServerController.php @@ -35,25 +35,18 @@ class ServerController extends Controller public function save(ServerSave $request) { - $params = $request->only([ - 'show', - 'group_id', - 'parent_id', - 'name', - 'host', - 'port', - 'server_port', - 'tls', - 'tags', - 'rate', - 'network', - 'settings' - ]); + $params = $request->only(array_keys(ServerSave::RULES)); $params['group_id'] = json_encode($params['group_id']); if (isset($params['tags'])) { $params['tags'] = json_encode($params['tags']); } + if (isset($params['tls'])) { + if (!isset($params['tls_pem']) || !isset($params['tls_key'])) { + abort(500, '开启TLS必须填写TLS证书'); + } + } + if (isset($params['settings'])) { if (!is_object(json_decode($params['settings']))) { abort(500, '传输协议配置格式不正确'); diff --git a/app/Http/Requests/Admin/ServerSave.php b/app/Http/Requests/Admin/ServerSave.php index fd5bc614..e7d3a2fc 100755 --- a/app/Http/Requests/Admin/ServerSave.php +++ b/app/Http/Requests/Admin/ServerSave.php @@ -6,6 +6,21 @@ use Illuminate\Foundation\Http\FormRequest; class ServerSave extends FormRequest { + CONST RULES = [ + 'show' => '', + 'name' => 'required', + 'group_id' => 'required|array', + 'parent_id' => 'nullable|integer', + 'host' => 'required', + 'port' => 'required', + 'server_port' => 'required', + 'tls' => 'required', + 'tls_pem' => '', + 'tls_key' => '', + 'tags' => 'array', + 'rate' => 'required|numeric', + 'network' => 'required|in:tcp,kcp,ws,http,domainsocket,quic' + ]; /** * Get the validation rules that apply to the request. * @@ -13,18 +28,7 @@ class ServerSave extends FormRequest */ public function rules() { - return [ - 'name' => 'required', - 'group_id' => 'required|array', - 'parent_id' => 'nullable|integer', - 'host' => 'required', - 'port' => 'required', - 'server_port' => 'required', - 'tls' => 'required', - 'tags' => 'array', - 'rate' => 'required|numeric', - 'network' => 'required|in:tcp,kcp,ws,http,domainsocket,quic' - ]; + return self::RULES; } public function messages()