diff --git a/app/Components/IP.php b/app/Components/IP.php index bc5a7e9e..8bb35260 100644 --- a/app/Components/IP.php +++ b/app/Components/IP.php @@ -41,7 +41,7 @@ class IP return $response->json(); } - Log::warning('解析IPv6异常:'.$ip); + Log::warning('api.ip.sb解析'.$ip.'异常: '.$response->body()); return false; } diff --git a/app/Http/Controllers/Admin/NodeController.php b/app/Http/Controllers/Admin/NodeController.php index 0a0c41a8..d10ffa74 100644 --- a/app/Http/Controllers/Admin/NodeController.php +++ b/app/Http/Controllers/Admin/NodeController.php @@ -135,6 +135,7 @@ class NodeController extends Controller 'is_subscribe' => $info['is_subscribe'], 'is_ddns' => $info['is_ddns'], 'relay_node_id' => $info['relay_node_id'], + 'port' => $info['port'], 'push_port' => $info['push_port'], 'detection_type' => $info['detection_type'], 'sort' => $info['sort'], diff --git a/app/Http/Requests/Admin/NodeRequest.php b/app/Http/Requests/Admin/NodeRequest.php index 2ddf0b4f..43f0ff12 100644 --- a/app/Http/Requests/Admin/NodeRequest.php +++ b/app/Http/Requests/Admin/NodeRequest.php @@ -12,8 +12,8 @@ class NodeRequest extends FormRequest 'is_ddns' => 'required|boolean', 'name' => 'required|string', 'server' => 'required_if:is_ddns,1|nullable|ends_with:'.implode(',', config('domains')), - 'ip' => 'required_if:is_ddns,0|nullable|ipv4', - 'ipv6' => 'nullable|ipv6', + 'ip' => 'required_if:is_ddns,0|nullable', + 'ipv6' => 'nullable', 'push_port' => 'numeric|between:1,65535|different:port', 'traffic_rate' => 'required|numeric|min:0', 'level' => 'required|numeric|exists:level,level', diff --git a/app/Models/Node.php b/app/Models/Node.php index bfadeb3d..02f36ee2 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Components\IP; +use Arr; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -100,7 +101,7 @@ class Node extends Model { $ip = $this->ips(); if ($ip !== []) { - $data = IP::IPSB($ip[0]); + $data = IP::IPSB($ip[0]); // 复数IP都以第一个为准 if ($data) { self::withoutEvents(function () use ($data) { @@ -139,53 +140,63 @@ class Node extends Model 'group' => sysConfig('website_name'), 'udp' => $this->is_udp, ]; - switch ($this->type) { - case 0: - $config = array_merge($config, [ - 'type' => 'shadowsocks', - 'passwd' => $user->passwd, - ], $this->profile); - if ($this->port) { - $config['port'] = $this->port; - } else { - $config['port'] = $user->port; - } - break; - case 2: - $config = array_merge($config, [ - 'type' => 'v2ray', - 'port' => $this->port, - 'uuid' => $user->vmess_id, - ], $this->profile); - break; - case 3: - $config = array_merge($config, [ - 'type' => 'trojan', - 'port' => $this->port, - 'passwd' => $user->passwd, - 'sni' => $this->relay_node_id ? $this->server : '', - ], $this->profile); - break; - case 1: - case 4: - $config = array_merge($config, [ - 'type' => 'shadowsocksr', - ], $this->profile); - if ($this->profile['passwd'] && $this->port) { - //单端口使用中转的端口 - $config['port'] = $this->port; - $config['protocol_param'] = $user->port.':'.$user->passwd; - } else { - $config['port'] = $user->port; - $config['passwd'] = $user->passwd; - if ($this->type === 1) { - $config['method'] = $user->method; - $config['protocol'] = $user->protocol; - $config['obfs'] = $user->obfs; - } - } - break; + if ($this->relay_node_id) { + $parentConfig = $this->relayNode->getConfig($user); + $config = array_merge($config, Arr::except($parentConfig, ['id', 'name', 'host', 'group', 'udp'])); + if ($parentConfig['type'] === 'trojan') { + $config['sni'] = $parentConfig['host']; + } + $config['port'] = $this->port; + } else { + switch ($this->type) { + case 0: + $config = array_merge($config, [ + 'type' => 'shadowsocks', + 'passwd' => $user->passwd, + ], $this->profile); + if ($this->port) { + $config['port'] = $this->port; + } else { + $config['port'] = $user->port; + } + break; + case 2: + $config = array_merge($config, [ + 'type' => 'v2ray', + 'port' => $this->port, + 'uuid' => $user->vmess_id, + ], $this->profile); + break; + case 3: + $config = array_merge($config, [ + 'type' => 'trojan', + 'port' => $this->port, + 'passwd' => $user->passwd, + 'sni' => '', + ], $this->profile); + break; + case 1: + case 4: + $config = array_merge($config, [ + 'type' => 'shadowsocksr', + ], $this->profile); + if ($this->profile['passwd'] && $this->port) { + //单端口使用中转的端口 + $config['port'] = $this->port; + $config['protocol_param'] = $user->port.':'.$user->passwd; + } else { + $config['port'] = $user->port; + $config['passwd'] = $user->passwd; + if ($this->type === 1) { + $config['method'] = $user->method; + $config['protocol'] = $user->protocol; + $config['obfs'] = $user->obfs; + } + } + + break; + } } return $config; diff --git a/resources/views/admin/node/info.blade.php b/resources/views/admin/node/info.blade.php index a26c2c37..22f1fb7a 100644 --- a/resources/views/admin/node/info.blade.php +++ b/resources/views/admin/node/info.blade.php @@ -146,196 +146,6 @@