Browse Source

视频内外网访问逻辑修改

任敬轩 10 months ago
parent
commit
cd4c3ac013
1 changed files with 33 additions and 1 deletions
  1. 33 1
      Modules/Admin/Http/Controllers/LoginController.php

+ 33 - 1
Modules/Admin/Http/Controllers/LoginController.php

@@ -39,7 +39,39 @@ class LoginController extends Controller
             return redirect('/admin');
             return redirect('/admin');
         }
         }
 
 
-//         return view('admin::login');
+        // 获取当前访问者的 IP 地址
+        $ipAddress = $_SERVER['REMOTE_ADDR'];
+
+        // 定义私有 IP 段
+        $privateRanges = [
+            ['10.0.0.0', '10.255.255.255'],
+            ['172.16.0.0', '172.31.255.255'],
+            ['192.168.0.0', '192.168.255.255']
+        ];
+
+        $ipInPrivateRange = false;
+
+        // 判断 IP 是否在任何一个私有 IP 段内
+        foreach ($privateRanges as $range) {
+            if ($this->isIpInRange($ipAddress, $range[0], $range[1])) {
+                $ipInPrivateRange = true;
+                break;
+            }
+        }
+
+        if (!$ipInPrivateRange) {
+            http_response_code(404);
+            exit;
+        }
+
+        return view('admin::login');
+    }
+
+    function isIpInRange($ip, $rangeStart, $rangeEnd) {
+        $ipLong = ip2long($ip);
+        $startLong = ip2long($rangeStart);
+        $endLong = ip2long($rangeEnd);
+        return ($ipLong >= $startLong && $ipLong <= $endLong);
     }
     }
 
 
     //登录动作
     //登录动作