honwen / aliyun-ddns-cli

ALiDDNS - Dynamic DNS CLI for [aliyun.com]
MIT License
413 stars 111 forks source link

maindomain and subdomain fix(or support?) #48

Closed CamberLoid closed 3 years ago

CamberLoid commented 3 years ago

发现原仓库的域名解析有Bug,没有对主域名/子域名的支持 因此加入了一些不太优雅写出来的另外几种方法 在本地编译通过并投入生产环境使用

由于本人没有Golang开发经验,因此本pr需要仓库作者修改或者指导

谢谢

honwen commented 3 years ago

any use example?

CamberLoid commented 3 years ago

For example a.b.example.tld the regex will consider b.example.tld as main domain but the true main domain is example.tld

honwen commented 3 years ago

please help check https://github.com/honwen/aliyun-ddns-cli/releases/tag/v2021-04-11

CamberLoid commented 3 years ago

Test failed. No support for tld like co.kr

Test code:

package main

import (
        "log"
        "fmt"
        "strings"

        "github.com/asaskevich/govalidator"
)

func splitDomain(fulldomain string) (rr, domain string) {
        wildCard := false
        if strings.HasPrefix(fulldomain, `*.`) {
                wildCard = true
                fulldomain = fulldomain[2:]
        }

        for len(fulldomain) > 0 && strings.HasSuffix(fulldomain, `.`) {
                fulldomain = fulldomain[:len(fulldomain)-1]
        }

        subs := strings.Split(fulldomain, `.`)
        if !govalidator.IsDNSName(fulldomain) || len(subs) < 2 {
                log.Fatal("Not a Vaild Domain")
        }

        rrSubs := subs[:len(subs)-2]
        domainSubs := subs[len(subs)-2:]

        if wildCard {
                rr = strings.Join(append([]string{`*`}, rrSubs...), `.`)
        } else {
                rr = strings.Join(rrSubs, `.`)
        }

        if len(rr) == 0 {
                rr = `@`
        }

        domain = strings.Join(domainSubs, `.`)
        // fmt.Println(rr, domain)
        return
}

func main() {
        a,b := splitDomain("ko.no.example.co.kr")
        fmt.Print(a)
        fmt.Print("\n")
        fmt.Print(b)
}

Example output:

camber@Camber-Windoge ~/test.go % ./test
ko.no.example
co.kr%

Expected output:

ko.no
example.co.kr

Test environment Windows Subsystem Linux / Ubuntu 21.10(Development branch) go version go1.16 linux/amd64

honwen commented 3 years ago

does AliCloud NS support example.co.kr as main domain?

honwen commented 3 years ago

try latest commit https://github.com/honwen/aliyun-ddns-cli/commit/76c09aedae8b0cd0ea2b8f43fe4e9819fc9626b8

honwen commented 3 years ago

please help check https://github.com/honwen/aliyun-ddns-cli/releases/tag/v2021-04-13

honwen commented 3 years ago

reopen a issues if meet any problem