mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	Use ServerService
This commit is contained in:
		| @@ -89,72 +89,18 @@ class PoseidonController extends Controller | |||||||
|         if (empty($nodeId) || empty($localPort)) { |         if (empty($nodeId) || empty($localPort)) { | ||||||
|             return $this->error('invalid parameters', 400); |             return $this->error('invalid parameters', 400); | ||||||
|         } |         } | ||||||
|         $server = Server::find($nodeId); |  | ||||||
|         if (!$server) { |  | ||||||
|             return $this->error("server could not be found", 404); |  | ||||||
|         } |  | ||||||
|         $json = json_decode(self::SERVER_CONFIG); |  | ||||||
|         $json->inboundDetour[0]->port = (int)$localPort; |  | ||||||
|         $json->inbound->port = (int)$server->server_port; |  | ||||||
|         $json->inbound->streamSettings->network = $server->network; |  | ||||||
|         if ($server->settings) { |  | ||||||
|             switch ($server->network) { |  | ||||||
|                 case 'tcp': |  | ||||||
|                     $json->inbound->streamSettings->tcpSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|                 case 'kcp': |  | ||||||
|                     $json->inbound->streamSettings->kcpSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|                 case 'ws': |  | ||||||
|                     $json->inbound->streamSettings->wsSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|                 case 'http': |  | ||||||
|                     $json->inbound->streamSettings->httpSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|                 case 'domainsocket': |  | ||||||
|                     $json->inbound->streamSettings->dsSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|                 case 'quic': |  | ||||||
|                     $json->inbound->streamSettings->quicSettings = json_decode($server->settings); |  | ||||||
|                     break; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if ($server->rules) { |         $serverService = new ServerService(); | ||||||
|             $rules = json_decode($server->rules); |         try { | ||||||
|             // domain |             $json = $serverService->getConfig($nodeId, $localPort); | ||||||
|             if (isset($rules->domain) && !empty($rules->domain)) { |             $json->poseidon = [ | ||||||
|                 $domainObj = new \StdClass(); |               'license_key' => (string)config('v2board.server_license'), | ||||||
|                 $domainObj->type = 'field'; |  | ||||||
|                 $domainObj->domain = $rules->domain; |  | ||||||
|                 $domainObj->outboundTag = 'block'; |  | ||||||
|                 array_push($json->routing->rules, $domainObj); |  | ||||||
|             } |  | ||||||
|             // protocol |  | ||||||
|             if (isset($rules->protocol) && !empty($rules->protocol)) { |  | ||||||
|                 $protocolObj = new \StdClass(); |  | ||||||
|                 $protocolObj->type = 'field'; |  | ||||||
|                 $protocolObj->protocol = $rules->protocol; |  | ||||||
|                 $protocolObj->outboundTag = 'block'; |  | ||||||
|                 array_push($json->routing->rules, $protocolObj); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if ((int)$server->tls) { |  | ||||||
|             $json->inbound->streamSettings->security = 'tls'; |  | ||||||
|             $tls = (object)[ |  | ||||||
|                 'certificateFile' => '/home/v2ray.crt', |  | ||||||
|                 'keyFile' => '/home/v2ray.key' |  | ||||||
|             ]; |             ]; | ||||||
|             $json->inbound->streamSettings->tlsSettings = new \StdClass(); |  | ||||||
|             $json->inbound->streamSettings->tlsSettings->certificates[0] = $tls; |             return $this->success($json); | ||||||
|  |         } catch (\Exception $e) { | ||||||
|  |             return $this->error($e->getMessage(), 500); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $json->poseidon = [ |  | ||||||
|           'license_key' => (string)config('v2board.server_license'), |  | ||||||
|         ]; |  | ||||||
|  |  | ||||||
|         return $this->success($json); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected function verifyToken(Request $request) |     protected function verifyToken(Request $request) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user