Browse Source

Add 针对多IP,geo信息查询与连通性检测的支持

兔姬桑 4 years ago
parent
commit
d6805bff7e

+ 11 - 17
app/Console/Commands/NodeStatusDetection.php

@@ -81,24 +81,18 @@ class NodeStatusDetection extends Command
             }
             $node_id = (int) $node->id;
             // 使用DDNS的node先通过gethostbyname获取ipv4地址
-            if ($node->is_ddns) {
-                $ip = gethostbyname($node->server);
-                if (strcmp($ip, $node->server) !== 0) {
-                    $node->ip = $ip;
-                } else {
-                    Log::warning('【节点阻断检测】检测'.$node->server.'时,IP获取失败'.$ip.' | '.$node->server);
-                }
-            }
-            if ($node->detection_type !== 1) {
-                $icmpCheck = (new NetworkDetection)->networkCheck($node->ip, true);
-                if ($icmpCheck !== false && $icmpCheck !== '通讯正常') {
-                    $data[$node_id]['icmp'] = $icmpCheck;
+            foreach ($node->ips() as $ip) {
+                if ($node->detection_type !== 1) {
+                    $icmpCheck = (new NetworkDetection)->networkCheck($ip, true);
+                    if ($icmpCheck !== false && $icmpCheck !== '通讯正常') {
+                        $data[$node_id][$ip]['icmp'] = $icmpCheck;
+                    }
                 }
-            }
-            if ($node->detection_type !== 2) {
-                $tcpCheck = (new NetworkDetection)->networkCheck($node->ip, false, $node->single ? $node->port : 22);
-                if ($tcpCheck !== false && $tcpCheck !== '通讯正常') {
-                    $data[$node_id]['tcp'] = $tcpCheck;
+                if ($node->detection_type !== 2) {
+                    $tcpCheck = (new NetworkDetection)->networkCheck($ip, false, $node->single ? $node->port : 22);
+                    if ($tcpCheck !== false && $tcpCheck !== '通讯正常') {
+                        $data[$node_id][$ip]['tcp'] = $tcpCheck;
+                    }
                 }
             }
 

+ 1 - 1
app/Http/Controllers/PaymentController.php

@@ -30,7 +30,7 @@ class PaymentController extends Controller
 
     public static function notify(Request $request): void
     {
-        self::$method = $request->query('method');
+        self::$method = $request->query('method') ?: $request->input('method');
 
         Log::info(self::$method.'回调接口[POST]:'.self::$method.var_export($request->all(), true));
         self::getClient()->notify($request);

+ 23 - 10
app/Models/Node.php

@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
 use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Database\Eloquent\Relations\HasOne;
+use Log;
 
 /**
  * 节点配置信息.
@@ -72,9 +73,18 @@ class Node extends Model
         return $this->hasOne(NodeAuth::class);
     }
 
-    public function ips(int $type = 4)
+    public function ips(int $type = 4): array
     {
-        $ip = $type === 4 ? $this->attributes['ip'] : $this->attributes['ipv6'];
+        // 使用DDNS的node先通过gethostbyname获取ip地址
+        if ($this->attributes['is_ddns']) { // When ddns is enable, only domain can be used to check the ip
+            $ip = gethostbyname($this->attributes['server']);
+            if (strcmp($ip, $this->attributes['server']) === 0) {
+                Log::warning('获取 【'.$this->attributes['server'].'】 IP失败'.$ip);
+                $ip = '';
+            }
+        } else {
+            $ip = $type === 4 ? $this->attributes['ip'] : $this->attributes['ipv6']; // check the multiple existing of ip
+        }
 
         return array_map('trim', explode(',', $ip));
     }
@@ -94,19 +104,22 @@ class Node extends Model
             ->get();
     }
 
-    public function refresh_geo()
+    public function refresh_geo(): bool
     {
-        $data = IP::IPSB($this->is_ddns ? gethostbyname($this->server) : $this->ip);
+        $ip = $this->ips();
+        if ($ip !== []) {
+            $data = IP::IPSB($ip[0]);
 
-        if ($data) {
-            self::withoutEvents(function () use ($data) {
-                $this->update(['geo' => $data['latitude'].','.$data['longitude']]);
-            });
+            if ($data) {
+                self::withoutEvents(function () use ($data) {
+                    $this->update(['geo' => $data['latitude'].','.$data['longitude']]);
+                });
 
-            return 1;
+                return true;
+            }
         }
 
-        return 0;
+        return false;
     }
 
     public function config(User $user)

+ 5 - 3
app/Notifications/NodeBlocked.php

@@ -33,11 +33,13 @@ class NodeBlocked extends Notification implements ShouldQueue
 
     private function markdownMessage()
     {
-        $content = '| '.trans('user.attribute.node').' | ICMP | TCP'." |\r\n| ------ | :------: | :------: |\r\n";
+        $content = '| '.trans('user.attribute.node').' | IP | ICMP | TCP'." |\r\n| ------ | :------: | :------: |\r\n";
         $tail = '';
         foreach ($this->data as $node) {
-            if (Arr::hasAny($node, ['icmp', 'tcp'])) {
-                $content .= "| {$node['name']} | ".($node['icmp'] ?? '✔️').' | '.($node['tcp'] ?? '✔️')." |\r\n";
+            $case = $node;
+            Arr::forget($case, ['message', 'name']);
+            foreach ($case as $ip => $info) {
+                $content .= "| {$node['name']} | {$ip} | ".($info['icmp'] ?? '✔️').' | '.($info['tcp'] ?? '✔️')." |\r\n";
             }
             if (Arr::hasAny($node, ['message'])) {
                 $tail .= "- {$node['name']}: {$node['message']}\r\n";

File diff suppressed because it is too large
+ 102 - 418
composer.lock


+ 1 - 1
resources/views/user/components/help/clients/android.blade.php

@@ -1,5 +1,5 @@
 <ol>
-    <li><a href="clients/ShadowsocksRR-3.5.1.1.apk" target="_blank">点击此处</a>下载客户端并启动</li>
+    <li><a href="https://github.com/shadowsocksrr/shadowsocksr-android/releases/download/3.5.3/shadowsocksr-android-3.5.3.apk" target="_blank">点击此处</a>下载客户端并启动</li>
     <li> 单击左上角的shadowsocksR进入配置文件页,点击右下角的“+”号,点击“添加/升级SSR订阅”,完整复制本页上方“订阅服务”处地址,填入订阅信息并保存</li>
     <li> 选中任意一个节点,返回软件首页</li>
     <li> 在软件首页处找到“路由”选项,并将其改为“绕过局域网及中国大陆地址”</li>

+ 4 - 5
resources/views/user/components/help/clients/game.blade.php

@@ -1,7 +1,6 @@
 <ol>
-    <li><a href="clients/SSTap-beta-setup-1.0.9.7.zip" target="_blank">点击此处</a>下载客户端并安装</li>
-    <li> 打开 SSTap,选择 <i class="fa fa-cog"></i> -&gt; SSR订阅 -&gt; SSR订阅管理,添加订阅地址</li>
-    <li> 添加完成后,再次选择 <i class="fa fa-cog"></i> - SSR订阅 - 手动更新SSR订阅,即可同步节点列表。</li>
-    <li> 在代理模式中选择游戏或「不代理中国IP」,点击「连接」即可加速。</li>
-    <li> 需要注意的是,一旦连接成功,客户端会自动缩小到任务栏,可在设置中关闭。</li>
+    <li><a href="https://github.com/netchx/netch/releases/download/1.8.5/Netch.7z" target="_blank">点击此处</a>下载客户端并安装</li>
+    <li> 打开 Netch,设置 <i class="fa fa-cog"></i> -&gt; 订阅 -&gt; ,添加订阅地址</li>
+    <li> 添加完成后,从订阅链接更新服务器。</li>
+    <li> 在代理模式中选择游戏或「不代理局域网和中国IP」,点击「连接」即可加速。</li>
 </ol>

Some files were not shown because too many files changed in this diff