package templates import "fmt" import "strings" type IndexProps struct { Title string IsConfigured bool CurrentIP string Config ConfigData Records []DNSRecord UpdateFreqs []UpdateFrequency } type ConfigData struct { ZoneID string Domain string UpdatePeriod string ApiToken string } type DNSRecord struct { ID string Type string Name string Content string TTL int Proxied bool CreatedOn string } type UpdateFrequency struct { Label string Value string } templ Index(props IndexProps) { @Layout(props.Title) {

{ props.Title }

Current IP: { props.CurrentIP }
if !props.IsConfigured { @ConfigWarning() } else { @ConfigStatus(props.Config) @DNSRecordsSection(props.Records, props.CurrentIP) } @ConfigModal(props.Config, props.UpdateFreqs) @RecordModal(props.Config.Domain)
} } templ ConfigWarning() {

Configuration Required

Please configure your Cloudflare API credentials to manage your DNS records.

} templ ConfigStatus(config ConfigData) {
Configuration
Domain: { config.Domain }
Zone ID: { config.ZoneID }
IP Update Schedule: { formatUpdateSchedule(config.UpdatePeriod) }
} templ DNSRecordsSection(records []DNSRecord, currentIP string) {
DNS Records
@DNSRecordsTable(records, currentIP)
} templ DNSRecordsTable(records []DNSRecord, currentIP string) {
if len(records) == 0 { } else { for _, record := range records { @DNSRecordRow(record, currentIP) } }
Type Name Content TTL Proxied Actions
No DNS records found
} templ DNSRecordRow(record DNSRecord, currentIP string) { { record.Type } { record.Name } { record.Content } if record.Type == "A" { if record.Content == currentIP { Current IP } else { Outdated IP } } if record.TTL == 1 { Auto } else { { fmt.Sprintf("%ds", record.TTL) } } if record.Proxied { } } // Helper function to format update schedule func formatUpdateSchedule(period string) string { switch period { case "*/1 * * * *": return "Every minute" case "*/5 * * * *": return "Every 5 minutes" case "*/30 * * * *": return "Every 30 minutes" case "0 * * * *": return "Hourly" case "0 */6 * * *": return "Every 6 hours" case "0 0 * * *": return "Daily" case "": return "Manual updates only" default: return period } } // Helper function to extract subdomain name func getRecordName(fullName, domain string) string { if fullName == domain { return "@" } if strings.HasSuffix(fullName, "."+domain) { return fullName[:len(fullName)-len(domain)-1] } return fullName }