"use client" import { useEffect, useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { RefreshCw, Shield, AlertTriangle, CheckCircle } from "lucide-react" interface IpDebugInfo { ip: string isAllowed: boolean enableIpWhitelist: boolean allowedIps: string[] timestamp: string debug?: { allIpSources?: Record allFoundIps?: string[] isLocalDevelopment?: boolean localIp?: string | null environment?: string host?: string referer?: string userAgent?: string originalDetectedIp?: string finalDetectedIp?: string rawDetectedIp?: string ipDetectionMethod?: string } ipv6Info?: { isIPv6Mapped: boolean originalFormat: string ipv6Format: string hasIPv6Support: boolean } } export default function IpDebugPage() { const [ipInfo, setIpInfo] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchIpInfo = async () => { setLoading(true) setError(null) try { const response = await fetch('/api/ip') if (!response.ok) { throw new Error('無法獲取IP信息') } const data = await response.json() setIpInfo(data) } catch (error) { console.error("無法獲取IP信息:", error) setError("無法獲取IP信息") } finally { setLoading(false) } } useEffect(() => { fetchIpInfo() }, []) if (loading) { return (
載入中...
) } if (error || !ipInfo) { return (
錯誤

{error}

) } return (

IP 檢測調試

{/* 主要IP信息 */} {ipInfo.enableIpWhitelist && !ipInfo.isAllowed ? ( <> IP 被拒絕 ) : ( <> IP 檢測正常 )}

{ipInfo.ip}

{ipInfo.isAllowed ? "允許" : "拒絕"}
{ipInfo.enableIpWhitelist && (
已啟用
)}
{/* 詳細調試信息 */} {ipInfo.debug && ( 詳細調試信息

{ipInfo.debug.environment || '未知'}

{ipInfo.debug.ipDetectionMethod || '未知'}

{ipInfo.debug.allFoundIps && ipInfo.debug.allFoundIps.length > 0 && (
{ipInfo.debug.allFoundIps.map((ip, index) => (
{ip}
))}
)} {ipInfo.debug.allIpSources && (
{Object.entries(ipInfo.debug.allIpSources).map(([key, value]) => (
{key}: {value || 'null'}
))}
)}
)} {/* IPv6信息 */} {ipInfo.ipv6Info && ( IPv6 信息
{ipInfo.ipv6Info.isIPv6Mapped ? "是" : "否"}
{ipInfo.ipv6Info.hasIPv6Support ? "已啟用" : "未啟用"}
{ipInfo.ipv6Info.isIPv6Mapped && (

{ipInfo.ipv6Info.ipv6Format}

)}
)} {/* 允許的IP列表 */} {ipInfo.enableIpWhitelist && ipInfo.allowedIps.length > 0 && ( 允許的IP列表
{ipInfo.allowedIps.map((ip, index) => (
{ip === ipInfo.ip ? "當前" : ""} {ip}
))}
)} {/* 建議 */} 建議 {!ipInfo.enableIpWhitelist && (

⚠️ IP白名單功能未啟用。如果您的IP檢測正常,建議啟用白名單功能以提高安全性。

)} {ipInfo.enableIpWhitelist && !ipInfo.isAllowed && (

❌ 您的IP不在允許列表中。請聯繫管理員將您的IP添加到白名單。

)} {ipInfo.ip.startsWith('172.70.') && (

💡 檢測到Cloudflare代理IP。系統已優化處理此類代理IP,會嘗試獲取您的真實IP。

)}

✅ 如果IP檢測仍有問題,請檢查1Panel的反向代理配置,確保正確轉發客戶端IP頭部。

) }