2024-04-03 09:05:12 +00:00
|
|
|
package models
|
|
|
|
|
2024-04-09 03:36:34 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
2024-04-03 09:05:12 +00:00
|
|
|
|
2024-04-19 04:47:00 +00:00
|
|
|
// Domain domain data structure
|
2024-04-03 09:05:12 +00:00
|
|
|
type Domain struct {
|
2024-04-19 01:44:37 +00:00
|
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
2024-04-03 09:05:12 +00:00
|
|
|
DomainName string `gorm:"unique,not null,size:255" json:"domain_name"`
|
|
|
|
|
2024-04-11 02:51:50 +00:00
|
|
|
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"`
|
2024-04-19 01:44:37 +00:00
|
|
|
RefreshInterval uint32 `gorm:"type:uint;not null;default:86400" json:"refresh_interval"`
|
|
|
|
RetryInterval uint32 `gorm:"type:uint;not null;default:7200" json:"retry_interval"`
|
|
|
|
ExpiryPeriod uint32 `gorm:"type:uint;not null;default:3600000" json:"expiry_period"`
|
|
|
|
NegativeTtl uint32 `gorm:"type:uint;not null;default:86400" json:"negative_ttl"`
|
2024-04-03 09:05:12 +00:00
|
|
|
}
|
|
|
|
|
2024-04-11 03:41:33 +00:00
|
|
|
func (d *Domain) EmailSOAForamt() string {
|
2024-04-08 23:58:27 +00:00
|
|
|
s := strings.Split(d.AdminEmail, "@")
|
|
|
|
s[0] = strings.Replace(s[0], ".", "\\", -1)
|
2024-04-10 06:56:15 +00:00
|
|
|
if !strings.HasSuffix(s[1], ".") {
|
|
|
|
s[1] = fmt.Sprintf("%s.", s[1])
|
|
|
|
}
|
2024-04-08 23:58:27 +00:00
|
|
|
return strings.Join(s, ".")
|
2024-04-03 09:05:12 +00:00
|
|
|
}
|
2024-04-09 03:36:34 +00:00
|
|
|
|
2024-04-11 03:41:33 +00:00
|
|
|
func (d *Domain) WithDotEnd() string {
|
2024-04-09 03:36:34 +00:00
|
|
|
if strings.HasSuffix(d.DomainName, ".") {
|
|
|
|
return d.DomainName
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf("%s.", d.DomainName)
|
|
|
|
}
|
|
|
|
}
|
2024-04-09 13:16:19 +00:00
|
|
|
|
2024-04-13 02:14:45 +00:00
|
|
|
func (d *Domain) GenerateSOA() SOARecord {
|
2024-04-10 06:56:15 +00:00
|
|
|
var ns string
|
|
|
|
if !strings.HasSuffix(d.MainDNS, ".") {
|
|
|
|
ns = fmt.Sprintf("%s.", d.MainDNS)
|
|
|
|
} else {
|
|
|
|
ns = d.MainDNS
|
|
|
|
}
|
2024-04-13 02:14:45 +00:00
|
|
|
r := SOARecord{}
|
|
|
|
r.Ns = ns
|
|
|
|
r.MBox = d.EmailSOAForamt()
|
|
|
|
r.Refresh = d.RefreshInterval
|
|
|
|
r.Retry = d.RetryInterval
|
|
|
|
r.Expire = d.ExpiryPeriod
|
|
|
|
r.MinTtl = d.NegativeTtl
|
|
|
|
return r
|
2024-04-09 13:16:19 +00:00
|
|
|
}
|
2024-04-11 02:51:50 +00:00
|
|
|
|
2024-04-19 01:44:37 +00:00
|
|
|
func (d *Domain) GetValue() Domain {
|
|
|
|
return *d
|
|
|
|
}
|
|
|
|
|
2024-04-11 02:51:50 +00:00
|
|
|
type IDomain interface {
|
|
|
|
EmailSOAForamt() string
|
|
|
|
WithDotEnd() string
|
2024-04-13 02:14:45 +00:00
|
|
|
GenerateSOA() SOARecord
|
2024-04-19 01:44:37 +00:00
|
|
|
GetValue() Domain
|
2024-04-11 02:51:50 +00:00
|
|
|
}
|