This commit is contained in:
Sense T
2024-04-03 17:05:12 +08:00
parent 94a126086e
commit 8a8ea59b71
53 changed files with 4905 additions and 1 deletions

22
models/domain.go Normal file
View File

@@ -0,0 +1,22 @@
package models
import "strings"
type Domain struct {
ID int `gorm:"primaryKey" json:"id"`
DomainName string `gorm:"unique,not null,size:255" json:"domain_name"`
//SOA Info
MainDNS string `gorm:"not null,size:255" json:"main_dns"`
AdminEmail string `gorm:"not null,size:255" json:"admin_email"`
SerialNumber int64 `gorm:"not null,default:1" json:"serial_number"`
RefreshInterval uint32 `gorm:"not null,size:255,default:\"86400\"" json:"refresh_interval"`
RetryInterval uint32 `gorm:"not null,size:255,default:\"7200\"" json:"retry_interval"`
ExpiryPeriod uint32 `gorm:"not null,size:255,default:\"3600000\"" json:"expiry_period"`
NegativeTtl uint32 `gorm:"not null,size:255,default:\"86400\"" json:"negative_ttl"`
}
func (d *Domain) EmailSOAForamt() string {
soa := strings.Replace(d.AdminEmail, ".", "\\", 1)
return strings.Replace(soa, "@", ".", 1)
}

56
models/record.go Normal file
View File

@@ -0,0 +1,56 @@
package models
import (
"fmt"
dns "github.com/cloud66-oss/coredns_mysql"
)
const (
RecordTypeA = "A"
RecordTypeAAAA = "AAAA"
RecordTypeCNAME = "CNAME"
RecordTypeSOA = "SOA"
RecordTypeTXT = "TXT"
RecordTypeNS = "NS"
RecordTypeMX = "MX"
RecordTypeCAA = "CAA"
RecordTypeSRV = "SRV"
)
type Record struct {
ID int `gorm:"primaryKey" json:"id"`
Zone string `gorm:"not null,size:255" json:"zone"`
Name string `gorm:"not null,size:255" json:"name"`
Ttl int `json:"ttl"`
Content any `gorm:"serializer:json,type:\"text\"" json:"content"`
RecordType string `gorm:"not null,size:255" json:"record_type"`
}
func (Record) TableName() string {
return "coredns_record"
}
type RecordContentTypes interface {
dns.ARecord | dns.AAAARecord | dns.CNAMERecord | dns.CAARecord | dns.NSRecord | dns.MXRecord | dns.SOARecord | dns.SRVRecord | dns.TXTRecord
}
type RecordWithType[T RecordContentTypes] struct {
Record
Content T `json:"content"`
}
func (r *RecordWithType[T]) ToRecord() *Record {
r.Record.Content = r.Content
return &r.Record
}
func (r *RecordWithType[T]) FromRecord(record *Record) error {
r.Record = *record
var ok bool
if r.Content, ok = record.Content.(T); !ok {
return fmt.Errorf("cannot convert record type")
}
return nil
}

15
models/settings.go Normal file
View File

@@ -0,0 +1,15 @@
package models
import "gorm.io/gorm"
const (
SettingsKeyAdminUsername = "admin.username"
SettingsKeyAdminPassword = "admin.password"
SettingsKeyDNSServer = "dns.servers"
)
type Settings struct {
gorm.Model
Key string `gorm:"unique,not null,size:255"`
Value string `gorm:"not null,size:255"`
}