'use client'; import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Loader2, Database, CheckCircle, AlertTriangle } from 'lucide-react'; export default function SetIPPage() { const [clientIP, setClientIP] = useState('61-227-253-171'); const [loading, setLoading] = useState(false); const [message, setMessage] = useState(''); const [error, setError] = useState(''); // 設置客戶端 IP const setClientIP = async () => { if (!clientIP.trim()) { setError('請輸入客戶端 IP 地址'); return; } try { setLoading(true); const response = await fetch('/api/set-client-ip', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ clientIP: clientIP.trim() }), }); const data = await response.json(); if (data.success) { setMessage(data.message || '客戶端 IP 設置成功'); setError(''); } else { setError(data.error || '設置客戶端 IP 失敗'); } } catch (err) { setError('設置錯誤: ' + (err instanceof Error ? err.message : '未知錯誤')); } finally { setLoading(false); } }; // 快速設置你的 IP const setYourIP = () => { setClientIP('61-227-253-171'); }; // 測試清理功能 const testCleanup = async () => { try { setLoading(true); const response = await fetch('/api/ip-cleanup', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ action: 'cleanup-current' }), }); const data = await response.json(); if (data.success) { setMessage(`清理完成: ${data.message}`); setError(''); } else { setError(data.error || '清理失敗'); } } catch (err) { setError('清理錯誤: ' + (err instanceof Error ? err.message : '未知錯誤')); } finally { setLoading(false); } }; return (

設置客戶端 IP

手動設置你的真實 IP 地址,用於連線清理

{/* IP 設置 */} 設置客戶端 IP 輸入你的真實 IP 地址,系統將使用此 IP 來清理連線
setClientIP(e.target.value)} placeholder="例如: 61-227-253-171" className="flex-1" />
{/* 使用說明 */} 使用說明

你的 IP: 61-227-253-171(從資料庫連線列表中獲取)

設置 IP: 點擊「設置 IP」按鈕來設置你的客戶端 IP

測試清理: 點擊「測試清理」按鈕來清理你的 IP 連線

自動清理: 設置後,關閉頁面時會自動清理你的 IP 連線

{/* 訊息顯示 */} {message && ( {message} )} {error && ( {error} )}
); }