From 7f9ad68e1bc718d639a0cf31b99360390713eef8 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Mon, 10 Feb 2020 15:51:01 +0800 Subject: [PATCH] opt tls --- .../Controllers/Admin/ServerController.php | 21 +++++--------- app/Http/Requests/Admin/ServerSave.php | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 26 deletions(-) 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()