diff --git a/app/Http/Controllers/Admin/Server/V2rayController.php b/app/Http/Controllers/Admin/Server/V2rayController.php index 089a3cf2..3fbf3693 100644 --- a/app/Http/Controllers/Admin/Server/V2rayController.php +++ b/app/Http/Controllers/Admin/Server/V2rayController.php @@ -145,7 +145,7 @@ class V2rayController extends Controller public function viewConfig(Request $request) { $serverService = new ServerService(); - $config = $serverService->getConfig($request->input('node_id'), 23333); + $config = $serverService->getVmessConfig($request->input('node_id'), 23333); return response([ 'data' => $config ]); diff --git a/app/Http/Controllers/Admin/ServerController.php b/app/Http/Controllers/Admin/ServerController.php deleted file mode 100755 index aec1ca37..00000000 --- a/app/Http/Controllers/Admin/ServerController.php +++ /dev/null @@ -1,228 +0,0 @@ -get(); - for ($i = 0; $i < count($server); $i++) { - if (!empty($server[$i]['tags'])) { - $server[$i]['tags'] = json_decode($server[$i]['tags']); - } - $server[$i]['group_id'] = json_decode($server[$i]['group_id']); - $server[$i]['online'] = Cache::get(CacheKey::get('SERVER_ONLINE_USER', $server[$i]['parent_id'] ? $server[$i]['parent_id'] : $server[$i]['id'])); - if ($server[$i]['parent_id']) { - $server[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_LAST_CHECK_AT', $server[$i]['parent_id'])); - } else { - $server[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_LAST_CHECK_AT', $server[$i]['id'])); - } - } - return response([ - 'data' => $server - ]); - } - - public function save(ServerV2raySave $request) - { - $params = $request->only(array_keys(ServerV2raySave::RULES)); - $params['group_id'] = json_encode($params['group_id']); - if (isset($params['tags'])) { - $params['tags'] = json_encode($params['tags']); - } - - if (isset($params['dnsSettings'])) { - if (!is_object(json_decode($params['dnsSettings']))) { - abort(500, 'DNS规则配置格式不正确'); - } - } - - if (isset($params['ruleSettings'])) { - if (!is_object(json_decode($params['ruleSettings']))) { - abort(500, '审计规则配置格式不正确'); - } - } - - if (isset($params['networkSettings'])) { - if (!is_object(json_decode($params['networkSettings']))) { - abort(500, '传输协议配置格式不正确'); - } - } - - if (isset($params['tlsSettings'])) { - if (!is_object(json_decode($params['tlsSettings']))) { - abort(500, 'TLS配置格式不正确'); - } - } - - if ($request->input('id')) { - $server = Server::find($request->input('id')); - if (!$server) { - abort(500, '服务器不存在'); - } - try { - $server->update($params); - } catch (\Exception $e) { - abort(500, '保存失败'); - } - return response([ - 'data' => true - ]); - } - - if (!Server::create($params)) { - abort(500, '创建失败'); - } - - return response([ - 'data' => true - ]); - } - - public function groupFetch(Request $request) - { - if ($request->input('group_id')) { - return response([ - 'data' => [ServerGroup::find($request->input('group_id'))] - ]); - } - return response([ - 'data' => ServerGroup::get() - ]); - } - - public function groupSave(Request $request) - { - if (empty($request->input('name'))) { - abort(500, '组名不能为空'); - } - - if ($request->input('id')) { - $serverGroup = ServerGroup::find($request->input('id')); - } else { - $serverGroup = new ServerGroup(); - } - - $serverGroup->name = $request->input('name'); - return response([ - 'data' => $serverGroup->save() - ]); - } - - public function groupDrop(Request $request) - { - if ($request->input('id')) { - $serverGroup = ServerGroup::find($request->input('id')); - if (!$serverGroup) { - abort(500, '组不存在'); - } - } - - $servers = Server::all(); - foreach ($servers as $server) { - $groupId = json_decode($server->group_id); - if (in_array($request->input('id'), $groupId)) { - abort(500, '该组已被节点所使用,无法删除'); - } - } - - if (Plan::where('group_id', $request->input('id'))->first()) { - abort(500, '该组已被订阅所使用,无法删除'); - } - if (User::where('group_id', $request->input('id'))->first()) { - abort(500, '该组已被用户所使用,无法删除'); - } - return response([ - 'data' => $serverGroup->delete() - ]); - } - - public function drop(Request $request) - { - if ($request->input('id')) { - $server = Server::find($request->input('id')); - if (!$server) { - abort(500, '节点ID不存在'); - } - } - return response([ - 'data' => $server->delete() - ]); - } - - public function update(ServerV2rayUpdate $request) - { - $params = $request->only([ - 'show', - ]); - - $server = Server::find($request->input('id')); - - if (!$server) { - abort(500, '该服务器不存在'); - } - try { - $server->update($params); - } catch (\Exception $e) { - abort(500, '保存失败'); - } - - return response([ - 'data' => true - ]); - } - - public function copy(Request $request) - { - $server = Server::find($request->input('id')); - if (!$server) { - abort(500, '服务器不存在'); - } - if (!Server::create($server->toArray())) { - abort(500, '复制失败'); - } - - return response([ - 'data' => true - ]); - } - - public function viewConfig(Request $request) - { - $serverService = new ServerService(); - $config = $serverService->getConfig($request->input('node_id'), 23333); - return response([ - 'data' => $config - ]); - } - - public function sort(ServerV2raySort $request) - { - DB::beginTransaction(); - foreach ($request->input('server_ids') as $k => $v) { - if (!Server::find($v)->update(['sort' => $k + 1])) { - DB::rollBack(); - abort(500, '保存失败'); - } - } - DB::commit(); - return response([ - 'data' => true - ]); - } -} diff --git a/app/Http/Requests/Admin/ServerTrojanSave.php b/app/Http/Requests/Admin/ServerTrojanSave.php index dca18f62..fc272049 100644 --- a/app/Http/Requests/Admin/ServerTrojanSave.php +++ b/app/Http/Requests/Admin/ServerTrojanSave.php @@ -12,6 +12,7 @@ class ServerTrojanSave extends FormRequest 'group_id' => 'required|array', 'host' => 'required|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i', 'port' => 'required', + 'server_port' => 'required', 'tags' => 'nullable|array', 'rate' => 'required|numeric' ]; @@ -34,6 +35,7 @@ class ServerTrojanSave extends FormRequest 'host.required' => '节点地址不能为空', 'host.regex' => '节点地址必须为域名', 'port.required' => '连接端口不能为空', + 'server_port.required' => '后端服务端口不能为空', 'tags.array' => '标签格式不正确', 'rate.required' => '倍率不能为空', 'rate.numeric' => '倍率格式不正确' diff --git a/app/Http/Routes/AdminRoute.php b/app/Http/Routes/AdminRoute.php index 2d6fefc9..9e14afe8 100644 --- a/app/Http/Routes/AdminRoute.php +++ b/app/Http/Routes/AdminRoute.php @@ -23,9 +23,9 @@ class AdminRoute $router->post('/plan/update', 'Admin\\PlanController@update'); $router->post('/plan/sort', 'Admin\\PlanController@sort'); // Server - $router->get ('/server/group/fetch', 'Admin\\ServerController@groupFetch'); - $router->post('/server/group/save', 'Admin\\ServerController@groupSave'); - $router->post('/server/group/drop', 'Admin\\ServerController@groupDrop'); + $router->get ('/server/group/fetch', 'Admin\\Server\\GroupController@fetch'); + $router->post('/server/group/save', 'Admin\\Server\\GroupController@save'); + $router->post('/server/group/drop', 'Admin\\Server\\GroupController@drop'); $router->group([ 'prefix' => 'server/trojan' ], function ($router) { diff --git a/app/Services/ServerService.php b/app/Services/ServerService.php index 4a492924..b886b6d0 100644 --- a/app/Services/ServerService.php +++ b/app/Services/ServerService.php @@ -118,7 +118,7 @@ class ServerService } $json = json_decode(self::TROJAN_CONFIG); - $json->local_port = $server->port; + $json->local_port = $server->server_port; $json->ssl->sni = $server->host; $json->ssl->cert = "/root/.cert/{$server->host}.crt"; $json->ssl->key = "/root/.cert/{$server->host}.key"; diff --git a/database/install.sql b/database/install.sql index cac3e77d..c124ccaf 100644 --- a/database/install.sql +++ b/database/install.sql @@ -197,6 +197,7 @@ CREATE TABLE `v2_server_trojan` ( `rate` varchar(11) NOT NULL, `host` varchar(255) NOT NULL, `port` int(11) NOT NULL, + `server_port` int(11) NOT NULL, `show` tinyint(1) NOT NULL DEFAULT '0', `sort` int(11) DEFAULT NULL, `created_at` int(11) NOT NULL, @@ -282,4 +283,4 @@ CREATE TABLE `v2_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- 2020-06-13 10:43:44 +-- 2020-06-18 12:12:19 diff --git a/database/update.sql b/database/update.sql index 5cd4d5b7..76c26a2c 100644 --- a/database/update.sql +++ b/database/update.sql @@ -283,3 +283,6 @@ ADD `method` varchar(255) NOT NULL AFTER `rate`; ALTER TABLE `v2_coupon` ADD `limit_plan_ids` varchar(255) NULL AFTER `limit_use`; + +ALTER TABLE `v2_server_trojan` +ADD `server_port` int(11) NOT NULL AFTER `port`;