diff --git a/app/Http/Controllers/Admin/RuleController.php b/app/Http/Controllers/Admin/RuleController.php index e2cc591f..7a955aed 100644 --- a/app/Http/Controllers/Admin/RuleController.php +++ b/app/Http/Controllers/Admin/RuleController.php @@ -87,7 +87,7 @@ class RuleController extends Controller { foreach($RuleGroupList as $RuleGroup){ $rules = explode(',', $RuleGroup->rules); if(in_array($id, $rules)){ - $rules = implode(',', array_diff($rules, (array) $id)); + $rules = implode(',', array_diff($rules, [$id])); RuleGroup::query()->whereId($RuleGroup->id)->update(['rules' => $rules]); } } diff --git a/app/Http/Controllers/Api/WebApi/BaseController.php b/app/Http/Controllers/Api/WebApi/BaseController.php index a0077bee..e700514a 100644 --- a/app/Http/Controllers/Api/WebApi/BaseController.php +++ b/app/Http/Controllers/Api/WebApi/BaseController.php @@ -43,12 +43,7 @@ class BaseController { // 返回数据 public function returnData($message, $status = 'fail', $code = 400, $data = '', $addition = false) { - $data = [ - 'status' => $status, - 'code' => $code, - 'data' => $data, - 'message' => $message, - ]; + $data = ['status' => $status, 'code' => $code, 'data' => $data, 'message' => $message]; if($addition){ $data = array_merge($data, $addition); diff --git a/app/Http/Controllers/NodeController.php b/app/Http/Controllers/NodeController.php index 0a389e53..002c49ff 100644 --- a/app/Http/Controllers/NodeController.php +++ b/app/Http/Controllers/NodeController.php @@ -8,6 +8,8 @@ use App\Models\Country; use App\Models\Label; use App\Models\Level; use App\Models\NodeAuth; +use App\Models\NodeRule; +use App\Models\RuleGroup; use App\Models\SsNode; use App\Models\SsNodeInfo; use App\Models\SsNodeLabel; @@ -134,7 +136,7 @@ class NodeController extends Controller { $node->v2_method = $request->input('v2_method'); $node->v2_net = $request->input('v2_net'); $node->v2_type = $request->input('v2_type'); - $node->v2_host = $request->input('v2_host'); + $node->v2_host = $request->input('v2_host')?: ''; $node->v2_path = $request->input('v2_path'); $node->v2_tls = intval($request->input('v2_tls')); $node->tls_provider = $request->input('tls_provider'); @@ -282,7 +284,7 @@ class NodeController extends Controller { 'v2_method' => $request->input('v2_method'), 'v2_net' => $request->input('v2_net'), 'v2_type' => $request->input('v2_type'), - 'v2_host' => $request->input('v2_host'), + 'v2_host' => $request->input('v2_host')?: '', 'v2_path' => $request->input('v2_path'), 'v2_tls' => intval($request->input('v2_tls')), 'tls_provider' => $request->input('tls_provider') @@ -343,6 +345,16 @@ class NodeController extends Controller { UserTrafficDaily::query()->whereNodeId($id)->delete(); UserTrafficHourly::query()->whereNodeId($id)->delete(); UserTrafficLog::query()->whereNodeId($id)->delete(); + NodeAuth::query()->whereNodeId($id)->delete(); + NodeRule::query()->whereNodeId($id)->delete(); + $RuleGroupList = RuleGroup::query()->get(); + foreach($RuleGroupList as $RuleGroup){ + $nodes = explode(',', $RuleGroup->nodes); + if(in_array($id, $nodes)){ + $nodes = implode(',', array_diff($nodes, [$id])); + RuleGroup::query()->whereId($RuleGroup->id)->update(['nodes' => $nodes]); + } + } DB::commit(); diff --git a/app/Http/Middleware/WebApi.php b/app/Http/Middleware/WebApi.php index 82e89a8b..97742941 100644 --- a/app/Http/Middleware/WebApi.php +++ b/app/Http/Middleware/WebApi.php @@ -21,51 +21,31 @@ class WebApi { $key = $request->header('key'); $time = $request->header('timestamp'); - if($key === null){ // 未提供 key - return Response::json([ - "status" => "fail", - "code" => 404, - "data" => "", - "message" => "Your key is null" - ]); + if($key === null){// 未提供 key + return $this->returnData('Your key is null!'); }elseif($id === null){// 未提供 node - return Response::json([ - "status" => "fail", - "code" => 404, - "data" => "", - "message" => "Your Node Id is null" - ]); + return $this->returnData('Your Node Id is null!'); } $node = SsNode::query()->whereId($id)->first(); if(!$node){// node不存在 - return Response::json([ - "status" => "fail", - "code" => 404, - "data" => "", - "message" => "Unknown Node" - ]); + return $this->returnData('Unknown Node!'); } $nodeAuth = NodeAuth::query()->whereNodeId($id)->first(); if(!$nodeAuth || $key != $nodeAuth->key){// key不存在/不匹配 - return Response::json([ - "status" => "fail", - "code" => 404, - "data" => "", - "message" => "Token is invalid" - ]); + return $this->returnData('Token is invalid!'); } - if(abs($time - time()) >= 300){//时差超过5分钟 - return Response::json([ - "status" => "fail", - "code" => 404, - "data" => "", - "message" => "Please resynchronize the server time!" - ]); + if(abs($time - time()) >= 300){// 时差超过5分钟 + return $this->returnData('Please resynchronize the server time!'); } return $next($request); } + + // 返回数据 + public function returnData($message) { + return Response::json(['status' => 'fail', 'code' => 404, 'data' => '', 'message' => $message]); + } } diff --git a/resources/views/admin/node/nodeInfo.blade.php b/resources/views/admin/node/nodeInfo.blade.php index db3df5c1..b6acd245 100644 --- a/resources/views/admin/node/nodeInfo.blade.php +++ b/resources/views/admin/node/nodeInfo.blade.php @@ -163,7 +163,7 @@ @@ -171,7 +171,7 @@ @@ -183,7 +183,7 @@ @@ -241,7 +241,7 @@
- + @@ -451,7 +451,9 @@ $('#relay_server').val('{{$node->relay_server}}'); @endif @else - $('#v2_net').selectpicker('val', "tcp"); + $('#status').click(); + $('#is_udp').click(); + $('#is_subscribe').click(); v2_path.val('/' + string); @endisset }); @@ -576,6 +578,7 @@ break; case 2: $v2ray_setting.show(); + $('#v2_net').selectpicker('val', 'tcp'); break; case 3: $trojan_setting.show(); diff --git a/sql/db.sql b/sql/db.sql index 64a3cc8d..804882b0 100644 --- a/sql/db.sql +++ b/sql/db.sql @@ -147,9 +147,10 @@ CREATE TABLE `user` `d` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '已下载流量,单位字节', `t` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '最后使用时间', `ip` CHAR(128) DEFAULT NULL COMMENT '最后连接IP', - `enable` BIT NOT NULL DEFAULT 1 COMMENT '代理状态', + `enable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '代理状态', `method` VARCHAR(30) NOT NULL DEFAULT 'aes-256-cfb' COMMENT '加密方式', `protocol` VARCHAR(30) NOT NULL DEFAULT 'origin' COMMENT '协议', + `protocol_param` VARCHAR(255) DEFAULT NULL COMMENT '协议参数', `obfs` VARCHAR(30) NOT NULL DEFAULT 'plain' COMMENT '混淆', `speed_limit` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户限速,为0表示不限速,单位Byte', `wechat` VARCHAR(30) DEFAULT '' COMMENT '微信', @@ -177,7 +178,7 @@ CREATE TABLE `user` LOCK TABLES `user` WRITE; /*!40000 ALTER TABLE `user` DISABLE KEYS */; -INSERT INTO `user`(`id`, `username`, `email`, `password`, `port`, `passwd`, `uuid`, `transfer_enable`, `u`, `d`, `t`, `enable`, `method`, `protocol`, `obfs`, `wechat`, `qq`, `credit`, `enable_time`, `expire_time`, `remark`, `is_admin`, `reg_ip`, `status`, `created_at`, `updated_at`) +INSERT INTO `user`(`id`, `username`, `email`, `password`, `port`, `passwd`, `vmess_id`, `transfer_enable`, `u`, `d`, `t`, `enable`, `method`, `protocol`, `obfs`, `wechat`, `qq`, `credit`, `enable_time`, `expire_time`, `remark`, `is_admin`, `reg_ip`, `status`, `created_at`, `updated_at`) VALUES (1, '管理员', 'test@test.com', '$2y$10$ryMdx5ejvCSdjvZVZAPpOuxHrsAUY8FEINUATy6RCck6j9EeHhPfq', 10000, '@123', 'c6effafd-6046-7a84-376e-b0429751c304', 1099511627776, 0, 0, 0, 1, 'aes-256-cfb', 'origin', 'plain', '', '', 0.00, '2017-01-01', '2099-01-01', NULL, 1, '127.0.0.1', 1, Now(), Now()); /*!40000 ALTER TABLE `user` ENABLE KEYS */; diff --git a/sql/mod/20200605.sql b/sql/mod/20200605.sql deleted file mode 100644 index a88493d5..00000000 --- a/sql/mod/20200605.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `user` - CHANGE `enable` `enable` BIT NOT NULL DEFAULT 1 COMMENT '代理状态'; \ No newline at end of file diff --git a/sql/mod/20200624.sql b/sql/mod/20200624.sql index 17194c0a..87103fe3 100644 --- a/sql/mod/20200624.sql +++ b/sql/mod/20200624.sql @@ -1,3 +1,3 @@ ALTER TABLE `user` CHANGE `uuid` `vmess_id` VARCHAR(64) NOT NULL DEFAULT '', - ADD `protocol_param` varchar(255) DEFAULT '' COMMENT '协议参数'; \ No newline at end of file + ADD `protocol_param` varchar(255) DEFAULT '' COMMENT '协议参数' AFTER `protocol`; \ No newline at end of file diff --git a/sql/mod/20200707.sql b/sql/mod/20200707.sql new file mode 100644 index 00000000..b56fe5f0 --- /dev/null +++ b/sql/mod/20200707.sql @@ -0,0 +1,2 @@ +ALTER TABLE `user` + CHANGE `enable` `enable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '代理状态'; \ No newline at end of file