mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	support trojan and more optimization
This commit is contained in:
		| @@ -90,7 +90,8 @@ class DeepbworkController extends Controller | ||||
|                 $request->input('node_id'), | ||||
|                 $item['u'], | ||||
|                 $item['d'], | ||||
|                 $server->rate | ||||
|                 $server->rate, | ||||
|                 'vmess' | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -80,7 +80,8 @@ class PoseidonController extends Controller | ||||
|                 $request->input('node_id'), | ||||
|                 $item['u'], | ||||
|                 $item['d'], | ||||
|                 $server->rate | ||||
|                 $server->rate, | ||||
|                 'vmess' | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|   | ||||
							
								
								
									
										118
									
								
								app/Http/Controllers/Server/TrojanTidalabController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								app/Http/Controllers/Server/TrojanTidalabController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,118 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\Server; | ||||
|  | ||||
| use App\Services\ServerService; | ||||
| use App\Services\UserService; | ||||
| use App\Utils\CacheKey; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\User; | ||||
| use App\Models\ServerTrojan; | ||||
| use App\Models\ServerLog; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
|  | ||||
| class TrojanTidalabController extends Controller | ||||
| { | ||||
|     CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"sniffing":{"enabled": true,"destOverride": ["http","tls"]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"outboundDetour":[{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"rules":[{"inboundTag":"api","outboundTag":"api","type":"field"}]},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}'; | ||||
|  | ||||
|     public function __construct(Request $request) | ||||
|     { | ||||
|         $token = $request->input('token'); | ||||
|         if (empty($token)) { | ||||
|             abort(500, 'token is null'); | ||||
|         } | ||||
|         if ($token !== config('v2board.server_token')) { | ||||
|             abort(500, 'token is error'); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // 后端获取用户 | ||||
|     public function user(Request $request) | ||||
|     { | ||||
|         $nodeId = $request->input('node_id'); | ||||
|         $server = ServerTrojan::find($nodeId); | ||||
|         if (!$server) { | ||||
|             abort(500, 'fail'); | ||||
|         } | ||||
|         Cache::put(CacheKey::get('SERVER_LAST_CHECK_AT', $server->id), time(), 3600); | ||||
|         $serverService = new ServerService(); | ||||
|         $users = $serverService->getAvailableUsers(json_decode($server->group_id)); | ||||
|         $result = []; | ||||
|         foreach ($users as $user) { | ||||
|             $user->trojan_user = [ | ||||
|                 "password" => $user->uuid, | ||||
|             ]; | ||||
|             unset($user['uuid']); | ||||
|             unset($user['v2ray_alter_id']); | ||||
|             unset($user['v2ray_level']); | ||||
|             array_push($result, $user); | ||||
|         } | ||||
|         return response([ | ||||
|             'msg' => 'ok', | ||||
|             'data' => $result, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     // 后端提交数据 | ||||
|     public function submit(Request $request) | ||||
|     { | ||||
|         // Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input')); | ||||
|         $server = ServerTrojan::find($request->input('node_id')); | ||||
|         if (!$server) { | ||||
|             return response([ | ||||
|                 'ret' => 0, | ||||
|                 'msg' => 'server is not found' | ||||
|             ]); | ||||
|         } | ||||
|         $data = file_get_contents('php://input'); | ||||
|         $data = json_decode($data, true); | ||||
|         Cache::put(CacheKey::get('SERVER_ONLINE_USER', $server->id), count($data), 3600); | ||||
|         $serverService = new ServerService(); | ||||
|         $userService = new UserService(); | ||||
|         foreach ($data as $item) { | ||||
|             $u = $item['u'] * $server->rate; | ||||
|             $d = $item['d'] * $server->rate; | ||||
|             if (!$userService->trafficFetch($u, $d, $item['user_id'])) { | ||||
|                 return response([ | ||||
|                     'ret' => 0, | ||||
|                     'msg' => 'user fetch fail' | ||||
|                 ]); | ||||
|             } | ||||
|  | ||||
|             $serverService->log( | ||||
|                 $item['user_id'], | ||||
|                 $request->input('node_id'), | ||||
|                 $item['u'], | ||||
|                 $item['d'], | ||||
|                 $server->rate, | ||||
|                 'trojan' | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|         return response([ | ||||
|             'ret' => 1, | ||||
|             'msg' => 'ok' | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     // 后端获取配置 | ||||
|     public function config(Request $request) | ||||
|     { | ||||
|         $nodeId = $request->input('node_id'); | ||||
|         $localPort = $request->input('local_port'); | ||||
|         if (empty($nodeId) || empty($localPort)) { | ||||
|             abort(500, '参数错误'); | ||||
|         } | ||||
|         $serverService = new ServerService(); | ||||
|         try { | ||||
|             $json = $serverService->getConfig($nodeId, $localPort); | ||||
|         } catch (\Exception $e) { | ||||
|             abort(500, $e->getMessage()); | ||||
|         } | ||||
|  | ||||
|         die(json_encode($json, JSON_UNESCAPED_UNICODE)); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user