Squashed commit of the following:

commit a394259f0a
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 19 15:10:08 2024 +0800

    done

commit af9d966376
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 19 13:52:33 2024 +0800

    debug done.

commit 47335ca5e9
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 19 12:47:00 2024 +0800

    swagger done

commit 34fb2a478b
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 19 10:05:19 2024 +0800

    stage 2, not completed

commit 88b2255f8b
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 19 09:44:37 2024 +0800

    test stage 1

commit b583720223
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 15 21:53:09 2024 +0800

    Squashed commit of the following:

    commit 1e92328a0fc570fe9419ad5dbaaef77f7dc9ad2e
    Author: Sense T <me@sense-t.eu.org>
    Date:   Mon Apr 15 21:52:44 2024 +0800

        yes, react it!

    commit 09fffff6139b4cecb81cb1444139f225e95e8917
    Author: Sense T <me@sense-t.eu.org>
    Date:   Mon Apr 15 17:33:26 2024 +0800

        actions to be done

    commit 1611b0b338cfd965d15f43fb10308bc56015895f
    Author: Sense T <me@sense-t.eu.org>
    Date:   Mon Apr 15 15:22:08 2024 +0800

        modal needed.

    commit 88453e7382618fb6774ff1cc4c0f7045d4dfcf46
    Author: Sense T <me@sense-t.eu.org>
    Date:   Mon Apr 15 10:52:13 2024 +0800

        Domain View done

    commit 8cedca27c79ca2ba69c8777dfcb6019799875e31
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sun Apr 14 21:24:14 2024 +0800

        domain delete modal done

    commit 60cd00c0cad0774bae5b57bcfc4723a29d28d221
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sun Apr 14 07:55:11 2024 +0800

        1

    commit 285853e988db6e6a6371135869da0129fd73afd7
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sat Apr 13 17:29:43 2024 +0800

        eslint

    commit 8f0ffbf744fd85a612daacd7bd6cbc45d58907d3
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sat Apr 13 17:20:50 2024 +0800

        f

    commit 9762b632225f185d83388e58d93ed49f62fe6b3f
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sat Apr 13 17:08:37 2024 +0800

        views, components to be done

    commit 321e5255f2b1e705844179dd910d5f5a1ae58298
    Author: Sense T <me@sense-t.eu.org>
    Date:   Sat Apr 13 14:29:04 2024 +0800

        prepare for react

commit 3305d8d618
Author: Sense T <me@sense-t.eu.org>
Date:   Sat Apr 13 10:30:02 2024 +0800

    swagger to be done

commit 2c754e7eec
Author: Sense T <me@sense-t.eu.org>
Date:   Sat Apr 13 10:14:45 2024 +0800

    validate 'em !

commit 7b529ad8f6
Author: Sense T <me@sense-t.eu.org>
Date:   Sat Apr 13 09:22:27 2024 +0800

    try to avoid nil point panic

commit 0012a697cb
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 12 22:26:35 2024 +0800

    fix some bug

commit a098d3056c
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 12 20:03:34 2024 +0800

    web debug done

commit 01765c4e7f
Author: Sense T <me@sense-t.eu.org>
Date:   Fri Apr 12 15:16:52 2024 +0800

    all tsx used, no vue SFC

commit 731504ae82
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 22:05:58 2024 +0800

    tsx used - stage 2

commit b669a3e68e
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 16:18:11 2024 +0800

    use tsx for compoents stage 1

commit 2ab1b0bf1b
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 12:10:57 2024 +0800

    rr validation

commit 58c66fc3a8
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 11:41:33 2024 +0800

    stage 1

commit 7a5fcf1972
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 10:51:50 2024 +0800

    long options supported

commit c3b80093d2
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 10:51:33 2024 +0800

    for develop use

commit 7f52707323
Author: Sense T <me@sense-t.eu.org>
Date:   Thu Apr 11 10:51:24 2024 +0800

    fix typo

commit 9cc2696bbe
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 16:53:03 2024 +0800

    record data validate done

commit 5e2ae637a0
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 14:56:15 2024 +0800

    end with dot.

commit ed4fee935d
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 13:41:32 2024 +0800

    content safety

commit 29f75938bb
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 13:24:01 2024 +0800

    cmd is ok

commit 9465bb885d
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 11:00:47 2024 +0800

    web done

commit 65bf461d44
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 10 11:00:38 2024 +0800

    use tokei for stat

commit 61395ab61b
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 21:53:12 2024 +0800

    errors handler

commit 9752e7d9ae
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 21:16:19 2024 +0800

    model with generics done

commit 7dd3af3707
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 16:28:18 2024 +0800

    use DAO

commit 2369734230
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 13:06:31 2024 +0800

    dao for future

commit e18781ba25
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 11:36:34 2024 +0800

    DotEnd

commit 613ef7fdd9
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 10:16:06 2024 +0800

    record should endwith .

commit c93e8107dc
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 10:06:47 2024 +0800

    update regexp

commit 84e9961f4b
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 08:30:32 2024 +0800

    error log

commit db77b0fdb2
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 08:25:25 2024 +0800

    no console log

commit 0c197820a0
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 08:25:01 2024 +0800

    use flags for validate

commit 33c9050653
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 07:58:27 2024 +0800

    SOA Email Format

commit fb9c78efed
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 00:19:03 2024 +0800

    no debug

commit 1a7bf83cb9
Author: Sense T <me@sense-t.eu.org>
Date:   Tue Apr 9 00:18:18 2024 +0800

    1

commit e72de14797
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 17:30:25 2024 +0800

    last modal

commit e884840b7d
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 15:56:03 2024 +0800

    add

commit 36b0384319
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 15:02:55 2024 +0800

    delete domain modal done

commit 753e950fae
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 13:49:11 2024 +0800

    add domainRemovemodal

commit 69613f9b6e
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 13:32:01 2024 +0800

    modal needed for edit

commit 8c0b79066f
Author: Sense T <me@sense-t.eu.org>
Date:   Mon Apr 8 09:37:32 2024 +0800

    base UI

commit a67b2d7724
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 21:07:20 2024 +0800

    route update

commit 5a266e9e6c
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 14:36:55 2024 +0800

    ui base data struct

commit 3449df913c
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 13:08:45 2024 +0800

    web store for dev

commit 156bf651dd
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 13:08:30 2024 +0800

    store friendly

commit d90e949472
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 10:08:02 2024 +0800

    base code update

commit 0a20b5a670
Author: Sense T <me@sense-t.eu.org>
Date:   Sun Apr 7 10:07:26 2024 +0800

    metrics

commit bdd4866c10
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 3 22:37:15 2024 +0800

    all api done

commit 8a8ea59b71
Author: Sense T <me@sense-t.eu.org>
Date:   Wed Apr 3 17:05:12 2024 +0800

    1
This commit is contained in:
Sense T
2024-04-19 15:16:24 +08:00
parent 94a126086e
commit 021ec9c8f6
72 changed files with 11469 additions and 89 deletions

65
models/domain.go Normal file
View File

@@ -0,0 +1,65 @@
package models
import (
"fmt"
"strings"
)
// Domain domain data structure
type Domain struct {
ID uint `gorm:"primaryKey" json:"id"`
DomainName string `gorm:"unique,not null,size:255" json:"domain_name"`
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:"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"`
}
func (d *Domain) EmailSOAForamt() string {
s := strings.Split(d.AdminEmail, "@")
s[0] = strings.Replace(s[0], ".", "\\", -1)
if !strings.HasSuffix(s[1], ".") {
s[1] = fmt.Sprintf("%s.", s[1])
}
return strings.Join(s, ".")
}
func (d *Domain) WithDotEnd() string {
if strings.HasSuffix(d.DomainName, ".") {
return d.DomainName
} else {
return fmt.Sprintf("%s.", d.DomainName)
}
}
func (d *Domain) GenerateSOA() SOARecord {
var ns string
if !strings.HasSuffix(d.MainDNS, ".") {
ns = fmt.Sprintf("%s.", d.MainDNS)
} else {
ns = d.MainDNS
}
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
}
func (d *Domain) GetValue() Domain {
return *d
}
type IDomain interface {
EmailSOAForamt() string
WithDotEnd() string
GenerateSOA() SOARecord
GetValue() Domain
}

82
models/record.go Normal file
View File

@@ -0,0 +1,82 @@
package models
import (
"encoding/json"
"errors"
"strings"
)
var ErrorZoneNotEndWithDot = errors.New("zone should end with '.'")
const (
RecordTypeA = "A"
RecordTypeAAAA = "AAAA"
RecordTypeCNAME = "CNAME"
RecordTypeSOA = "SOA"
RecordTypeTXT = "TXT"
RecordTypeNS = "NS"
RecordTypeMX = "MX"
RecordTypeCAA = "CAA"
RecordTypeSRV = "SRV"
)
type recordContentTypes interface {
ARecord | AAAARecord | CNAMERecord | CAARecord | NSRecord | MXRecord | SOARecord | SRVRecord | TXTRecord | RecordContentDefault
}
// Record dns records for coredns mysql plugin
type Record[T recordContentTypes] struct {
ID uint `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"`
// see https://github.com/cloud66-oss/coredns_mysql/blob/main/types.go for content
Content T `gorm:"serializer:json;type:text" json:"content"`
RecordType string `gorm:"not null;size:255" json:"record_type"`
}
func (*Record[T]) TableName() string {
return "coredns_records"
}
func (r *Record[T]) CheckZone() error {
if !strings.HasSuffix(r.Zone, ".") {
return ErrorZoneNotEndWithDot
}
return nil
}
func (r *Record[T]) WithOutDotTail() string {
return strings.TrimRight(r.Zone, ".")
}
func (r *Record[T]) ToEntity() IRecord {
return r
}
func (r *Record[T]) FromEntity(entity any) error {
b, err := json.Marshal(entity)
if err != nil {
return err
}
return json.Unmarshal(b, r)
}
func (r *Record[T]) GetType() string {
return r.RecordType
}
func (r *Record[T]) GetValue() IRecord {
return r.ToEntity()
}
type IRecord interface {
TableName() string
CheckZone() error
WithOutDotTail() string
ToEntity() IRecord
FromEntity(any) error
GetType() string
GetValue() IRecord
}

142
models/record_types.go Normal file
View File

@@ -0,0 +1,142 @@
package models
import (
"errors"
"regexp"
"strings"
dns "github.com/cloud66-oss/coredns_mysql"
)
var (
ErrInvalidIPv4 = errors.New("not a valid ipv4 address")
ErrInvalidIPv6 = errors.New("not a valid ipv6 address")
ErrEmptyTXT = errors.New("txt record should not empty")
ErrNoDotSuffix = errors.New("should end with dot")
ErrBadEmailFormat = errors.New("email here should have no '@'")
ErrBadCAATag = errors.New("caa tag should not empty")
ErrBadCAAValue = errors.New("caa value should not empty")
ErrInvalidType = errors.New("invalid type")
)
type ARecord struct {
dns.ARecord
}
func (r ARecord) Validate() error {
ok := regexp.MustCompile("^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])[.]){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$").MatchString(r.Ip.String())
if !ok {
return ErrInvalidIPv4
}
return nil
}
type AAAARecord struct {
dns.AAAARecord
}
func (r AAAARecord) Validate() error {
ok := regexp.MustCompile("^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])[.]){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])[.]){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$").MatchString(r.Ip.String())
if !ok {
return ErrInvalidIPv6
}
return nil
}
type TXTRecord struct {
dns.TXTRecord
}
func (r TXTRecord) Validate() error {
if r.Text == "" {
return ErrEmptyTXT
}
return nil
}
type CNAMERecord struct {
dns.CNAMERecord
}
func (r CNAMERecord) Validate() error {
if !strings.HasSuffix(r.Host, ".") {
return ErrNoDotSuffix
}
return nil
}
type NSRecord struct {
dns.NSRecord
}
func (r NSRecord) Validate() error {
if !strings.HasSuffix(r.Host, ".") {
return ErrNoDotSuffix
}
return nil
}
type MXRecord struct {
dns.MXRecord
}
func (r MXRecord) Validate() error {
if !strings.HasSuffix(r.Host, ".") {
return ErrNoDotSuffix
}
return nil
}
type SRVRecord struct {
dns.SRVRecord
}
func (r SRVRecord) Validate() error {
if !strings.HasPrefix(r.Target, ".") {
return ErrNoDotSuffix
}
return nil
}
type SOARecord struct {
dns.SOARecord
}
func (r SOARecord) Validate() error {
if !strings.HasSuffix(r.Ns, ".") {
return ErrNoDotSuffix
}
if strings.Contains(r.MBox, "@") {
return ErrBadEmailFormat
}
return nil
}
type CAARecord struct {
dns.CAARecord
}
func (r CAARecord) Validate() error {
if r.Tag == "" {
return ErrBadCAATag
}
if r.Value == "" {
return ErrBadCAAValue
}
return nil
}
type RecordContentDefault map[string]any
func (r RecordContentDefault) Validate() error {
return ErrInvalidType
}
type IRecordType interface {
Validate() error
}

31
models/settings.go Normal file
View File

@@ -0,0 +1,31 @@
package models
import (
"fmt"
)
const (
SettingsKeyAdminUsername = "admin.username"
SettingsKeyAdminPassword = "admin.password"
SettingsKeyDNSServer = "dns.servers"
)
// Settings settings for this app
type Settings struct {
ID uint `gorm:"primaryKey"`
Key string `gorm:"unique;not null;size:255"`
Value string `gorm:"not null;size:255"`
}
func (s *Settings) String() string {
return fmt.Sprintf("%s: %s", s.Key, s.Value)
}
func (s *Settings) GetValue() Settings {
return *s
}
type ISettings interface {
String() string
GetValue() Settings
}