Pārlūkot izejas kodu

Files update & small tweaks

兔姬桑 2 gadi atpakaļ
vecāks
revīzija
04e0fd6b30

+ 15 - 25
app/Components/IP.php

@@ -14,8 +14,7 @@ use MaxMind\Db\Reader\InvalidDatabaseException;
 
 class IP
 {
-    // 获取IP地址信息
-    public static function getIPInfo($ip)
+    public static function getIPInfo($ip) // 获取IP地址信息
     {
         // IPv6 推荐使用ip.sb
         if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
@@ -32,8 +31,7 @@ class IP
         return $ipInfo;
     }
 
-    // 通过api.ip.sb查询IP地址的详细信息
-    public static function IPSB($ip)
+    public static function IPSB($ip) // 通过api.ip.sb查询IP地址的详细信息
     {
         try {
             $response = Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'])->timeout(15)->post('https://api.ip.sb/geoip/'.$ip);
@@ -52,8 +50,7 @@ class IP
         }
     }
 
-    // 通过ip2Region查询IP地址的详细信息 ← 聚合 淘宝IP库,GeoIP,纯真IP库
-    public static function ip2Region(string $ip)
+    public static function ip2Region(string $ip) // 通过ip2Region查询IP地址的详细信息 ← 聚合 淘宝IP库,GeoIP,纯真IP库
     {
         $ipInfo = false;
         try {
@@ -78,10 +75,9 @@ class IP
         return $ipInfo;
     }
 
-    // 通过ip2Location查询IP地址的详细信息
-    public static function ip2Location(string $ip)
+    public static function ip2Location(string $ip) // 通过ip2Location查询IP地址的详细信息
     {
-        $filePath = database_path('IP2LOCATION-LITE-DB3.IPV6.BIN');
+        $filePath = database_path('IP2LOCATION-LITE-DB3.IPV6.BIN'); // 来源: https://lite.ip2location.com/database-download IP-COUNTRY-REGION-CITY的BIN
         try {
             $location = (new Database($filePath, Database::FILE_IO))
                 ->lookup($ip, [Database::CITY_NAME, Database::REGION_NAME, Database::COUNTRY_NAME]);
@@ -98,10 +94,9 @@ class IP
         return false;
     }
 
-    // 通过IPIP查询IP地址的详细信息
-    public static function IPIP(string $ip): array
+    public static function IPIP(string $ip): array // 通过IPIP查询IP地址的详细信息
     {
-        $filePath = database_path('ipip.ipdb');
+        $filePath = database_path('ipipfree.ipdb'); // 来源: https://www.ipip.net/free_download/
         $location = (new City($filePath))->findMap($ip, 'CN');
 
         return [
@@ -111,8 +106,7 @@ class IP
         ];
     }
 
-    // 通过IPIP在线查询IP地址的详细信息
-    public static function IPIPOnline(string $ip)
+    public static function IPIPOnline(string $ip) // 通过IPIP在线查询IP地址的详细信息
     { // https://freeapi.ipip.net
         $response = Http::timeout(15)->get('https://freeapi.ipip.net/'.$ip);
 
@@ -134,8 +128,7 @@ class IP
         return false;
     }
 
-    // 通过ip.taobao.com查询IP地址的详细信息
-    public static function TaoBao(string $ip)
+    public static function TaoBao(string $ip) // 通过ip.taobao.com查询IP地址的详细信息
     {
         // 依据 https://ip.taobao.com/instructions 开发
         $response = Http::timeout(15)->post('https://ip.taobao.com/outGetIpInfo?ip='.$ip.'&accessKey=alibaba-inc');
@@ -159,8 +152,7 @@ class IP
         return false;
     }
 
-    // 通过api.map.baidu.com查询IP地址的详细信息
-    public static function Baidu(string $ip)
+    public static function Baidu(string $ip) // 通过api.map.baidu.com查询IP地址的详细信息
     {
         if (! config('services.baidu.app_ak')) {
             Log::error('【百度IP库】AK信息缺失');
@@ -189,16 +181,15 @@ class IP
         return false;
     }
 
-    // 通过GeoIP2查询IP地址的详细信息
-    public static function GeoIP2(string $ip)
+    public static function GeoIP2(string $ip) // 通过GeoIP2查询IP地址的详细信息
     {
-        $filePath = database_path('maxmind.mmdb');
+        $filePath = database_path('GeoLite2-City.mmdb'); // 来源:https://github.com/PrxyHunter/GeoLite2/releases
         try {
             $location = (new Reader($filePath))->city($ip);
 
             return [
-                'country'  => $location->country->names['zh-CN'],
-                'province' => '',
+                'country'  => $location->country->name ?? '',
+                'province' => $location->mostSpecificSubdivision->name ?? '',
                 'city'     => $location->city->name ?? '',
             ];
         } catch (AddressNotFoundException $e) {
@@ -210,8 +201,7 @@ class IP
         return false;
     }
 
-    // 获取访客真实IP
-    public static function getClientIP()
+    public static function getClientIP() // 获取访客真实IP
     {
         /*
          * 访问时用localhost访问的,读出来的是“::1”是正常情况

+ 1 - 1
app/Http/Controllers/Admin/TicketController.php

@@ -56,7 +56,7 @@ class TicketController extends Controller
         return view('admin.ticket.reply', [
             'ticket'    => $ticket,
             'user'      => $ticket->user,
-            'replyList' => $ticket->reply()->with('ticket:id,status', 'admin:id,username', 'user:id,username')->oldest()->get(),
+            'replyList' => $ticket->reply()->with('ticket:id,status', 'admin:id,username,qq', 'user:id,username,qq')->oldest()->get(),
         ]);
     }
 

+ 2 - 2
app/Http/Controllers/Admin/UserController.php

@@ -92,7 +92,7 @@ class UserController extends Controller
         $data['vmess_id'] = $data['uuid'] ?? Str::uuid();
         Arr::forget($data, 'uuid');
         $data['transfer_enable'] *= GB;
-        $data['expired_at'] = $data['expired_at'] ?? date('Y-m-d', strtotime('365 days'));
+        $data['expired_at'] = $data['expired_at'] ?? date('Y-m-d', strtotime('next year'));
         $data['remark'] = str_replace(['atob', 'eval'], '', $data['remark']);
         $data['reg_ip'] = IP::getClientIp();
         $data['reset_time'] = $data['reset_time'] > date('Y-m-d') ? $data['reset_time'] : null;
@@ -217,7 +217,7 @@ class UserController extends Controller
         Arr::forget($data, ['roles', 'uuid', 'password']);
         $data['transfer_enable'] *= GB;
         $data['enable'] = $data['status'] < 0 ? 0 : $data['enable'];
-        $data['expired_at'] = $data['expired_at'] ?? date('Y-m-d', strtotime('365 days'));
+        $data['expired_at'] = $data['expired_at'] ?? date('Y-m-d', strtotime('next year'));
         $data['remark'] = str_replace(['atob', 'eval'], '', $data['remark']);
 
         // 只有超级管理员才能赋予超级管理员

+ 3 - 1
app/Http/Controllers/AuthController.php

@@ -137,9 +137,11 @@ class AuthController extends Controller
     }
 
     // 退出
-    public function logout(): RedirectResponse
+    public function logout(Request $request): RedirectResponse
     {
         Auth::logout();
+        $request->session()->invalidate();
+        $request->session()->regenerateToken();
 
         return Redirect::route('login');
     }

+ 8 - 4
app/helpers.php

@@ -88,9 +88,9 @@ if (! function_exists('filterEmoji')) {
 
 // 获取系统设置
 if (! function_exists('sysConfig')) {
-    function sysConfig($key = false)
+    function sysConfig($key = false, $default = null)
     {
-        return $key ? config('settings.'.$key) : config('settings');
+        return $key ? config('settings.'.$key, $default) : config('settings');
     }
 }
 
@@ -98,7 +98,9 @@ if (! function_exists('sysConfig')) {
 if (! function_exists('string_encrypt')) {
     function string_encrypt(string $data): string
     {
-        return base64url_encode(openssl_encrypt($data, 'aes-128-ctr', hash('sha256', config('app.key')), OPENSSL_RAW_DATA, substr(sha1(config('app.key')), 0, 16)));
+        $key = config('app.key');
+
+        return base64url_encode(openssl_encrypt($data, 'aes-128-ctr', hash('sha256', $key), OPENSSL_RAW_DATA, substr(sha1($key), 0, 16)));
     }
 }
 
@@ -106,7 +108,9 @@ if (! function_exists('string_encrypt')) {
 if (! function_exists('string_decrypt')) {
     function string_decrypt(string $data): string
     {
-        return openssl_decrypt(base64url_decode($data), 'aes-128-ctr', hash('sha256', config('app.key')), OPENSSL_RAW_DATA, substr(sha1(config('app.key')), 0, 16));
+        $key = config('app.key');
+
+        return openssl_decrypt(base64url_decode($data), 'aes-128-ctr', hash('sha256', $key), OPENSSL_RAW_DATA, substr(sha1($key), 0, 16));
     }
 }
 

BIN
database/maxmind.mmdb → database/GeoLite2-City.mmdb


BIN
database/IP2LOCATION-LITE-DB3.IPV6.BIN


+ 0 - 0
database/ipip.ipdb → database/ipipfree.ipdb