'use client'; import { useState, useEffect } from 'react'; import { Settings as SettingsIcon, Plus, Trash2, Save, RefreshCw, Wifi, Clock } from 'lucide-react'; const Settings = () => { const [config, setConfig] = useState(null); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [currentIPs, setCurrentIPs] = useState({ ipv4: '', ipv6: '' }); const [checkingIP, setCheckingIP] = useState(false); const fetchConfig = async () => { try { const response = await fetch('/api/config'); const data = await response.json(); if (data.success) { setConfig(data.config); } } catch (error) { console.error('Error fetching config:', error); } setLoading(false); }; const fetchCurrentIPs = async () => { try { const response = await fetch('/api/ip/current'); const data = await response.json(); if (data.success && data.ips) { setCurrentIPs(data.ips); } } catch (error) { console.error('Error fetching current IPs:', error); } }; const checkIPs = async () => { setCheckingIP(true); try { const response = await fetch('/api/ip/current', { method: 'POST' }); const data = await response.json(); if (data.success) { setCurrentIPs(data.newIPs); } } catch (error) { console.error('Error checking IPs:', error); } setCheckingIP(false); }; useEffect(() => { // Initial data loading // eslint-disable-next-line react-hooks/set-state-in-effect fetchConfig(); fetchCurrentIPs(); }, []); const saveConfig = async () => { setSaving(true); try { const response = await fetch('/api/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) }); if (response.ok) { alert('Configuration saved successfully'); } } catch (error) { console.error('Error saving config:', error); alert('Error saving configuration'); } setSaving(false); }; const addAccount = () => { const newAccount = { id: `account${Date.now()}`, name: 'New Account', appKey: '', appSecret: '', consumerKey: '', endpoint: 'ovh-eu', domains: [] }; setConfig({ ...config, ovhAccounts: [...config.ovhAccounts, newAccount] }); }; const removeAccount = (accountId) => { if (!confirm('Are you sure you want to delete this account?')) return; setConfig({ ...config, ovhAccounts: config.ovhAccounts.filter(acc => acc.id !== accountId) }); }; const updateAccount = (accountId, field, value) => { setConfig({ ...config, ovhAccounts: config.ovhAccounts.map(acc => acc.id === accountId ? { ...acc, [field]: value } : acc ) }); }; const addDomain = (accountId) => { const domain = prompt('Enter the domain name:'); if (!domain) return; setConfig({ ...config, ovhAccounts: config.ovhAccounts.map(acc => acc.id === accountId ? { ...acc, domains: [...(acc.domains || []), domain] } : acc ) }); }; const removeDomainFromAccount = (accountId, domain) => { setConfig({ ...config, ovhAccounts: config.ovhAccounts.map(acc => acc.id === accountId ? { ...acc, domains: acc.domains.filter(d => d !== domain) } : acc ) }); }; const updateIPProvider = (providerId, field, value) => { setConfig({ ...config, ipProviders: config.ipProviders.map(provider => provider.id === providerId ? { ...provider, [field]: value } : provider ) }); }; const updateAutoUpdate = (field, value) => { setConfig({ ...config, autoUpdate: { ...config.autoUpdate, [field]: value } }); }; if (loading || !config) { return (
Cargando configuración...
Manage your OVH accounts and IP providers
IPv4
{currentIPs.ipv4 || 'No disponible'}
IPv6
{currentIPs.ipv6 || 'No disponible'}
Automatic updates will periodically check public IPs and update DNS records for the specified domains.