Browse Source

修复导致ssr后端读db错误的问题;修复删除节点导致授权页面报错的问题;文件补缺与简化

兔姬桑 4 years ago
parent
commit
8841ce91db

+ 1 - 1
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]);
 				}
 			}

+ 1 - 6
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);

+ 14 - 2
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();
 

+ 12 - 32
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]);
+	}
 }

+ 9 - 6
resources/views/admin/node/nodeInfo.blade.php

@@ -163,7 +163,7 @@
 											<label for="method" class="col-md-3 col-form-label">加密方式</label>
 											<select data-plugin="selectpicker" data-style="btn-outline btn-primary" class="col-md-5 form-control" name="method" id="method">
 												@foreach ($method_list as $method)
-													<option value="{{$method->name}}" @if($method->is_default) selected @endif>{{$method->name}}</option>
+													<option value="{{$method->name}}" @if(!isset($node) && $method->is_default) selected @endif>{{$method->name}}</option>
 												@endforeach
 											</select>
 										</div>
@@ -171,7 +171,7 @@
 											<label for="protocol" class="col-md-3 col-form-label">协议</label>
 											<select data-plugin="selectpicker" data-style="btn-outline btn-primary" class="col-md-5 form-control" name="protocol" id="protocol">
 												@foreach ($protocol_list as $protocol)
-													<option value="{{$protocol->name}}" @if($protocol->is_default) selected @endif>{{$protocol->name}}</option>
+													<option value="{{$protocol->name}}" @if(!isset($node) && $protocol->is_default) selected @endif>{{$protocol->name}}</option>
 												@endforeach
 											</select>
 										</div>
@@ -183,7 +183,7 @@
 											<label for="obfs" class="col-md-3 col-form-label">混淆</label>
 											<select data-plugin="selectpicker" data-style="btn-outline btn-primary" class="col-md-5 form-control" name="obfs" id="obfs">
 												@foreach ($obfs_list as $obfs)
-													<option value="{{$obfs->name}}" @if($obfs->is_default) selected @endif>{{$obfs->name}}</option>
+													<option value="{{$obfs->name}}" @if(!isset($node) && $obfs->is_default) selected @endif>{{$obfs->name}}</option>
 												@endforeach
 											</select>
 										</div>
@@ -241,7 +241,7 @@
 										<div class="form-group row">
 											<label for="v2_method" class="col-md-3 col-form-label">加密方式</label>
 											<select data-plugin="selectpicker" data-style="btn-outline btn-primary" class="col-md-5 form-control" id="v2_method">
-												<option value="auto" selected>auto</option>
+												<option value="auto">auto</option>
 												<option value="none">none</option>
 												<option value="aes-128-gcm">aes-128-gcm</option>
 												<option value="chacha20-poly1305">chacha20-poly1305</option>
@@ -263,7 +263,7 @@
 										<div class="form-group row v2_type">
 											<label for="v2_type" class="col-md-3 col-form-label">伪装类型</label>
 											<select data-plugin="selectpicker" data-style="btn-outline btn-primary" class="col-md-5 form-control" id="v2_type">
-												<option value="none" selected>无伪装</option>
+												<option value="none">无伪装</option>
 												<option value="http">HTTP数据流</option>
 												<optgroup id="type_option" label="">
 													<option value="srtp">视频通话数据 (SRTP)</option>
@@ -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();

+ 3 - 2
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 */;

+ 0 - 2
sql/mod/20200605.sql

@@ -1,2 +0,0 @@
-ALTER TABLE `user`
-    CHANGE `enable` `enable` BIT NOT NULL DEFAULT 1 COMMENT '代理状态';

+ 1 - 1
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 '协议参数';
+    ADD `protocol_param` varchar(255) DEFAULT '' COMMENT '协议参数' AFTER `protocol`;

+ 2 - 0
sql/mod/20200707.sql

@@ -0,0 +1,2 @@
+ALTER TABLE `user`
+    CHANGE `enable` `enable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '代理状态';