├── .github ├── dependabot.yml └── workflows │ ├── go.tidy.yml │ └── build-cmd.yml ├── models ├── basic.go ├── dnspod.go ├── cloudflare.go └── cloudxns.go ├── .gitignore ├── go.mod ├── cmd ├── ddnsclient │ ├── main_test.go │ ├── basic.go │ ├── app.conf.sample │ ├── cloudflare.go │ ├── cloudxns.go │ ├── dnspod.go │ └── main.go ├── cfipchange │ └── main.go └── cname │ └── main.go ├── README.md ├── go.sum ├── .travis.yml └── LICENSE /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /models/basic.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type BasicAuthConfigurationItem struct { 4 | UserName string `json:"username"` 5 | Password string `json:"password"` 6 | Url string `json:"url"` 7 | Internal bool `json:",omitempty"` 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/missdeer/ddnsclient 2 | 3 | go 1.23.0 4 | 5 | toolchain go1.23.7 6 | 7 | require github.com/cloudflare/cloudflare-go v0.115.0 8 | 9 | require ( 10 | github.com/goccy/go-json v0.10.5 // indirect 11 | github.com/google/go-cmp v0.6.0 // indirect 12 | github.com/google/go-querystring v1.1.0 // indirect 13 | golang.org/x/net v0.38.0 // indirect 14 | golang.org/x/text v0.23.0 // indirect 15 | golang.org/x/time v0.9.0 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /cmd/ddnsclient/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "testing" 6 | ) 7 | 8 | func TestGetCurrentExternalIP(t *testing.T) { 9 | insecureSkipVerify = false 10 | ifconfigURL = "https://ifconfig.minidump.info" 11 | ip, err := getCurrentExternalIP(true) 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | log.Println(ip) 16 | ip, err = getCurrentExternalIP(false) 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | log.Println(ip) 21 | } 22 | -------------------------------------------------------------------------------- /cmd/ddnsclient/basic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net/http" 7 | ) 8 | 9 | func basicAuthorizeHttpRequest(user string, password string, requestUrl string) error { 10 | client := &http.Client{} 11 | req, err := http.NewRequest("GET", requestUrl, nil) 12 | req.SetBasicAuth(user, password) 13 | resp, err := client.Do(req) 14 | if err != nil { 15 | fmt.Printf("request %s failed\n", requestUrl) 16 | return err 17 | } 18 | defer resp.Body.Close() 19 | _, err = ioutil.ReadAll(resp.Body) 20 | if err != nil { 21 | fmt.Printf("reading response failed\n") 22 | return err 23 | } 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /models/dnspod.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type DnspodConfigurationItem struct { 4 | TokenId string `json:"id"` 5 | Token string `json:"token"` 6 | UserName string `json:"username"` 7 | Password string `json:"password"` 8 | Domain string `json:"domain"` 9 | SubDomain string `json:"sub_domain"` 10 | Internal bool `json:",omitempty"` 11 | } 12 | 13 | type DnspodDomainItem struct { 14 | Id int `json:"id"` 15 | Name string `json:"name"` 16 | } 17 | 18 | type DnspodDomainList struct { 19 | Domains []DnspodDomainItem `json:"domains"` 20 | } 21 | 22 | type DnspodRecordItem struct { 23 | Id string `json:"id"` 24 | Name string `json:"name"` 25 | } 26 | 27 | type DnspodRecordList struct { 28 | Records []DnspodRecordItem `json:"records"` 29 | } 30 | -------------------------------------------------------------------------------- /models/cloudflare.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type CloudflareConfigurationItem struct { 4 | UserName string `json:"username"` 5 | Token string `json:"token"` 6 | Domain string `json:"domain"` 7 | SubDomain string `json:"sub_domain"` 8 | Internal bool `json:",omitempty"` 9 | } 10 | 11 | type CloudflareRecordItem struct { 12 | Id string `json:"rec_id"` 13 | DisplayName string `json:"display_name"` 14 | Type string `json:"type"` 15 | } 16 | 17 | type CloudflareRecords struct { 18 | Objs []CloudflareRecordItem `json:"objs"` 19 | } 20 | 21 | type CloudflareResponse struct { 22 | Recs CloudflareRecords `json:"recs"` 23 | } 24 | 25 | type CloudflareRecordList struct { 26 | Response CloudflareResponse `json:"response"` 27 | } 28 | 29 | type CloudflareNewRecords struct { 30 | Obj CloudflareRecordItem `json:"obj"` 31 | } 32 | 33 | type CloudflareNewRecordResponse struct { 34 | Rec CloudflareNewRecords `json:"rec"` 35 | } 36 | 37 | type CloudflareNewRecordResponseBody struct { 38 | Response CloudflareNewRecordResponse `json:"response"` 39 | } 40 | -------------------------------------------------------------------------------- /cmd/ddnsclient/app.conf.sample: -------------------------------------------------------------------------------- 1 | { 2 | "basic": [ 3 | { 4 | "username": "xxxx", 5 | "password": "ppaassss", 6 | "url": "http://ddns.oray.com/ph/update?hostname=xxxx.vicp.net" 7 | }, 8 | { 9 | "username": "xxxx", 10 | "password": "ppaassss", 11 | "url": "http://members.3322.net/dyndns/update?system=dyndns&hostname=xxxx.f3322.net" 12 | } 13 | ], 14 | "dnspod": [ 15 | { 16 | "id": "xxxx", 17 | "token": "ppaassss", 18 | "domain": "domain.com", 19 | "sub_domain": "subdomain" 20 | }, 21 | { 22 | "username": "xxxx", 23 | "password": "ppaassss", 24 | "domain": "domain.com", 25 | "sub_domain": "subdomain" 26 | } 27 | ], 28 | "cloudflare": [ 29 | { 30 | "username": "xxxx@domain.com", 31 | "token": "ppaassss", 32 | "domain": "domain.com", 33 | "sub_domain": "subdomain" 34 | } 35 | ], 36 | "cloudxns": [ 37 | { 38 | "apikey": "xxxxxxxxxx", 39 | "secretkey": "yyyyyyyyyy", 40 | "domain": "domain.com", 41 | "sub_domain": "subdomain" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /.github/workflows/go.tidy.yml: -------------------------------------------------------------------------------- 1 | name: go tidy 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | paths: 8 | - '.github/workflows/go.tidy.yml' 9 | - 'go.mod' 10 | - 'go.sum' 11 | 12 | jobs: 13 | fix: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - 17 | name: Checkout 18 | uses: actions/checkout@v2 19 | - 20 | name: Tidy 21 | run: | 22 | rm -f go.sum 23 | cd cmd/ddnsclient 24 | go mod tidy 25 | - 26 | name: Set up Git 27 | env: 28 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 29 | run: | 30 | git config user.name "auto-go-mod-tidy[bot]" 31 | git config user.email "auto-go-mod-tidy[bot]@users.noreply.github.com" 32 | git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git 33 | - 34 | name: Commit and push changes 35 | run: | 36 | git add . 37 | if output=$(git status --porcelain) && [ ! -z "$output" ]; then 38 | git commit -m 'auto go mod tidy' 39 | git push 40 | fi 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddnsclient 2 | update ddns A record 3 | 4 | [![Build Status](https://secure.travis-ci.org/missdeer/ddnsclient.png)](https://travis-ci.org/missdeer/ddnsclient) [![GitHub release](https://img.shields.io/github/release/missdeer/ddnsclient.svg?maxAge=2592000)](https://github.com/missdeer/ddnsclient/releases) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/missdeer/ddnsclient/master/LICENSE) 5 | 6 | 7 | Support: 8 | ---- 9 | - basic http authorization services, such as pubyum.com, oray.com and so on 10 | - [DNSPod](https://dnspod.cn) 11 | - [CloudFlare](https://www.cloudflare.com) 12 | - [CloudXNS](https://www.cloudxns.net) 13 | 14 | Get prebuilt binary: 15 | ---- 16 | 17 | Click this button to download the binary for your platform: [![GitHub release](https://img.shields.io/github/release/missdeer/ddnsclient.svg?maxAge=2592000)](https://github.com/missdeer/ddnsclient/releases) 18 | 19 | Build: 20 | ---- 21 | 22 | ```bash 23 | go get github.com/missdeer/ddnsclient/cmd/ddnsclient 24 | ``` 25 | 26 | Usage: 27 | ---- 28 | - rename app.conf.sample to app.conf 29 | - modify app.conf as you like 30 | - run command: `./ddnsclient` 31 | - or specify a special configuration file path on commandline: `./ddnsclient -config /some/special/path/myapp.conf` 32 | - or specify a service URL to get current external IP: `./ddnsclient -ifconfig https://if.yii.li` 33 | - or specify a flag to ignore ifconfig service's SSL certificate verification: `./ddnsclient -insecureSkipVerify` 34 | 35 | Attention: 36 | ---- 37 | Currently, ddnsclient util depends on [https://if.yii.li](https://github.com/missdeer/ddnsclient/blob/master/cmd/ddnsclient/main.go#L37) service to get the device public internet IP, if you want to setup your own service to archive this goal, please visit [ifconfig project site](https://github.com/missdeer/ifconfig) for more information. 38 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/cloudflare/cloudflare-go v0.115.0 h1:84/dxeeXweCc0PN5Cto44iTA8AkG1fyT11yPO5ZB7sM= 2 | github.com/cloudflare/cloudflare-go v0.115.0/go.mod h1:Ds6urDwn/TF2uIU24mu7H91xkKP8gSAHxQ44DSZgVmU= 3 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 4 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= 6 | github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= 7 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 8 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 9 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 10 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= 11 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= 12 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 13 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 14 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 15 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 16 | golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= 17 | golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= 18 | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= 19 | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= 20 | golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= 21 | golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 22 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 23 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 24 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 25 | -------------------------------------------------------------------------------- /cmd/ddnsclient/cloudflare.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "time" 8 | 9 | "github.com/cloudflare/cloudflare-go" 10 | ) 11 | 12 | func cloudflareRequest(user string, token string, domain string, subDomain string, isInternal bool) error { 13 | // Construct a new API object 14 | api, err := cloudflare.New(token, user) 15 | if err != nil { 16 | log.Fatal(err) 17 | return err 18 | } 19 | 20 | ctx := context.Background() 21 | // Fetch user details on the account 22 | u, err := api.UserDetails(ctx) 23 | if err != nil { 24 | log.Fatal(err) 25 | return err 26 | } 27 | // Print user details 28 | fmt.Println("Cloudflare user information:", u) 29 | 30 | // Fetch the zone ID 31 | id, err := api.ZoneIDByName(domain) // Assuming example.com exists in your Cloudflare account already 32 | if err != nil { 33 | log.Fatal(err) 34 | return err 35 | } 36 | 37 | // Fetch zone details 38 | zone, err := api.ZoneDetails(ctx, id) 39 | if err != nil { 40 | log.Fatal(err) 41 | return err 42 | } 43 | // Print zone details 44 | fmt.Println("Cloudflare zone detail:", zone) 45 | 46 | // Fetch all records for a zone 47 | recs, err := api.DNSRecords(ctx, id, cloudflare.DNSRecord{Type: "A", Name: subDomain + "." + domain}) 48 | if err != nil { 49 | log.Fatal(err) 50 | return err 51 | } 52 | 53 | newIP := currentExternalIPv4 54 | if isInternal { 55 | newIP = currentInternalIPv4 56 | } 57 | r := cloudflare.DNSRecord{ 58 | Type: "A", 59 | Name: subDomain + "." + domain, 60 | Content: newIP, 61 | ZoneID: id, 62 | } 63 | if len(recs) == 0 { 64 | // insert a new record 65 | _, err = api.CreateDNSRecord(ctx, id, r) 66 | if err != nil { 67 | fmt.Println(err) 68 | return err 69 | } else { 70 | fmt.Printf("[%v] A record created to cloudflare: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 71 | } 72 | } else { 73 | // update 74 | err = api.UpdateDNSRecord(ctx, id, recs[0].ID, r) 75 | if err != nil { 76 | fmt.Println(err) 77 | return err 78 | } else { 79 | fmt.Printf("[%v] A record updated to cloudflare: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 80 | } 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /models/cloudxns.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type CloudXNSConfigurationItem struct { 4 | APIKey string `json:"apikey"` 5 | SecretKey string `json:"secretkey"` 6 | Domain string `json:"domain"` 7 | SubDomain string `json:"sub_domain"` 8 | Internal bool `json:",omitempty"` 9 | } 10 | 11 | type CloudXNSDomainItem struct { 12 | Id int `json:"id,string"` 13 | Domain string `json:"domain"` 14 | Status string `json:"status"` 15 | AuditStatus string `json:"audit_status"` 16 | TakeOverStatus string `json:"take_over_status"` 17 | Level int `json:"level,string"` 18 | CreateTime string `json:"create_time"` 19 | UpdateTime string `json:"update_time"` 20 | TTL int `json:"ttl,string"` 21 | } 22 | 23 | type CloudXNSDomainList struct { 24 | Code int `json:"code"` 25 | Message string `json:"message"` 26 | Total int `json:"total,string"` 27 | Data []CloudXNSDomainItem `json:"data"` 28 | } 29 | 30 | type CloudXNSHostRecordItem struct { 31 | Id int `json:"id,string"` 32 | Host string `json:"host"` 33 | RecordNum int `json:"record_num,string"` 34 | DomainName string `json:"domain_name"` 35 | } 36 | 37 | type CloudXNSHostRecordList struct { 38 | Code int `json:"code"` 39 | Message string `json:"message"` 40 | Total int `json:"total,string"` 41 | Data []CloudXNSHostRecordItem `json:"hosts"` 42 | } 43 | 44 | type CloudXNSResolveItem struct { 45 | RecordId int `json:"record_id,string"` 46 | HostId int `json:"host_id,string"` 47 | Host string `json:"host"` 48 | LineZh string `json:"line_zh"` 49 | LineEn string `json:"line_en"` 50 | LineId int `json:"line_id,string"` 51 | MX interface{} `json:"mx"` 52 | Value string `json:"value"` 53 | Type string `json:"type"` 54 | Status string `json:"status"` 55 | CreateTime string `json:"create_time"` 56 | UpdateTime string `json:"update_time"` 57 | } 58 | 59 | type CloudXNSResolveList struct { 60 | Code int `json:"code"` 61 | Message string `json:"message"` 62 | Total int `json:"total"` 63 | Data []CloudXNSResolveItem `json:"data"` 64 | } 65 | -------------------------------------------------------------------------------- /cmd/cfipchange/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | 10 | "github.com/cloudflare/cloudflare-go" 11 | ) 12 | 13 | var ( 14 | cmd string 15 | cfKey string 16 | cfEmail string 17 | recordName string 18 | recordContent string 19 | recordType string 20 | recordContentFrom string 21 | recordContentTo string 22 | ) 23 | 24 | func listRecord(api *cloudflare.API) { 25 | ctx := context.Background() 26 | zones, err := api.ListZones(ctx) 27 | if err != nil { 28 | log.Fatal(err) 29 | } 30 | 31 | for _, zone := range zones { 32 | records, err := api.DNSRecords(ctx, zone.ID, cloudflare.DNSRecord{}) 33 | if err != nil { 34 | log.Println("getting dns records failed for ", zone.Host, err) 35 | continue 36 | } 37 | for _, record := range records { 38 | if record.Type == "A" { 39 | fmt.Printf("record %s => %s\n", record.Name, record.Content) 40 | } 41 | } 42 | } 43 | } 44 | 45 | func modifyRecord(api *cloudflare.API, rrType string, name string, content string) { 46 | ctx := context.Background() 47 | zones, err := api.ListZones(ctx) 48 | if err != nil { 49 | log.Fatal(err) 50 | } 51 | 52 | for _, zone := range zones { 53 | records, err := api.DNSRecords(ctx, zone.ID, cloudflare.DNSRecord{}) 54 | if err != nil { 55 | log.Println("getting dns records failed for ", zone.Host, err) 56 | continue 57 | } 58 | for _, record := range records { 59 | if record.Name == name && (rrType == "" || record.Type == rrType) { 60 | old := record.Content 61 | record.Content = content 62 | if err = api.UpdateDNSRecord(ctx, zone.ID, record.ID, record); err != nil { 63 | log.Println("update dns record failed", err) 64 | } else { 65 | log.Printf("dns record %s.%s updated from %s to %s\n", record.Name, zone.Host, old, content) 66 | } 67 | return 68 | } 69 | } 70 | } 71 | } 72 | 73 | func changeSpecifiedRecords(api *cloudflare.API, rrType string, from string, to string) { 74 | ctx := context.Background() 75 | zones, err := api.ListZones(ctx) 76 | if err != nil { 77 | log.Fatal(err) 78 | } 79 | 80 | for _, zone := range zones { 81 | records, err := api.DNSRecords(ctx, zone.ID, cloudflare.DNSRecord{}) 82 | if err != nil { 83 | log.Println("getting dns records failed for ", zone.Host, err) 84 | continue 85 | } 86 | for _, record := range records { 87 | if record.Content == from && (rrType == "" || record.Type == rrType) { 88 | record.Content = to 89 | if err = api.UpdateDNSRecord(ctx, zone.ID, record.ID, record); err != nil { 90 | log.Println("update dns record failed", err) 91 | } else { 92 | log.Printf("dns record %s.%s updated from %s to %s\n", record.Name, zone.Host, from, to) 93 | } 94 | } 95 | } 96 | } 97 | } 98 | 99 | func main() { 100 | cfKey = os.Getenv("CF_API_KEY") 101 | cfEmail = os.Getenv("CF_API_EMAIL") 102 | 103 | flag.StringVar(&cfKey, "key", cfKey, "Cloudflare API key") 104 | flag.StringVar(&cfEmail, "email", cfEmail, "Cloudflare account email") 105 | flag.StringVar(&cmd, "cmd", "list", "command: list, modify, change") 106 | flag.StringVar(&recordName, "name", "", "record name to be modified") 107 | flag.StringVar(&recordContent, "content", "", "record content modified to") 108 | flag.StringVar(&recordType, "type", "A", "record type to be modified or changed") 109 | flag.StringVar(&recordContentFrom, "from", "", "record content to be changed from") 110 | flag.StringVar(&recordContentTo, "to", "", "record content to be changed to") 111 | flag.Parse() 112 | 113 | api, err := cloudflare.New(cfKey, cfEmail) 114 | if err != nil { 115 | log.Fatal(err) 116 | } 117 | 118 | switch cmd { 119 | case "list": 120 | listRecord(api) 121 | case "modify": 122 | modifyRecord(api, recordType, recordName, recordContent) 123 | case "change": 124 | changeSpecifiedRecords(api, recordType, recordContentFrom, recordContentTo) 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /.github/workflows/build-cmd.yml: -------------------------------------------------------------------------------- 1 | name: build-cmd 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: Build 7 | runs-on: macos-latest 8 | strategy: 9 | matrix: 10 | cmd: [ddnsclient, cname, cfipchange] 11 | steps: 12 | 13 | - name: Set up Go 1.17 14 | uses: actions/setup-go@v2 15 | with: 16 | go-version: 1.17 17 | id: go 18 | 19 | - name: Check out code into the Go module directory 20 | uses: actions/checkout@v2 21 | with: 22 | ref: master 23 | 24 | - name: Build 25 | run: | 26 | cd cmd/${{ matrix.cmd }} 27 | env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../../linux-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 28 | env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o ../../linux-arm-7/${{ matrix.cmd }} -ldflags="-s -w" . 29 | env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ../../darwin-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 30 | env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ../../darwin-arm64/${{ matrix.cmd }} -ldflags="-s -w" . 31 | mkdir -p ../../darwin-universal && lipo -create -output ../../darwin-universal/${{ matrix.cmd }} ../../darwin-arm64/${{ matrix.cmd }} ../../darwin-amd64/${{ matrix.cmd }} 32 | env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ../../windows-amd64/${{ matrix.cmd }}.exe -ldflags="-s -w" . 33 | env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o ../../freebsd-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 34 | env CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -o ../../openbsd-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 35 | env CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -o ../../netbsd-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 36 | env CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -o ../../dragonfly-amd64/${{ matrix.cmd }} -ldflags="-s -w" . 37 | cd ../.. 38 | env GOPATH=$PWD/gopath go get -u github.com/missdeer/cicdutil 39 | 40 | - name: Upload artifact ${{ matrix.cmd }}-linux-amd64 41 | uses: actions/upload-artifact@v1.0.0 42 | with: 43 | # Artifact name 44 | name: ${{ matrix.cmd }}-linux-amd64 45 | # Directory containing files to upload 46 | path: linux-amd64 47 | 48 | - name: Upload artifact ${{ matrix.cmd }}-linux-arm-7 49 | uses: actions/upload-artifact@v1.0.0 50 | with: 51 | # Artifact name 52 | name: ${{ matrix.cmd }}-linux-arm-7 53 | # Directory containing files to upload 54 | path: linux-arm-7 55 | 56 | - name: Upload artifact ${{ matrix.cmd }}-darwin-universal 57 | uses: actions/upload-artifact@v1.0.0 58 | with: 59 | # Artifact name 60 | name: ${{ matrix.cmd }}-darwin-universal 61 | # Directory containing files to upload 62 | path: darwin-universal 63 | 64 | - name: Upload artifact ${{ matrix.cmd }}-dragonfly-amd64 65 | uses: actions/upload-artifact@v1.0.0 66 | with: 67 | # Artifact name 68 | name: ${{ matrix.cmd }}-dragonfly-amd64 69 | # Directory containing files to upload 70 | path: dragonfly-amd64 71 | 72 | - name: Upload artifact ${{ matrix.cmd }}-openbsd-amd64 73 | uses: actions/upload-artifact@v1.0.0 74 | with: 75 | # Artifact name 76 | name: ${{ matrix.cmd }}-openbsd-amd64 77 | # Directory containing files to upload 78 | path: openbsd-amd64 79 | 80 | - name: Upload artifact ${{ matrix.cmd }}-netbsd-amd64 81 | uses: actions/upload-artifact@v1.0.0 82 | with: 83 | # Artifact name 84 | name: ${{ matrix.cmd }}-netbsd-amd64 85 | # Directory containing files to upload 86 | path: netbsd-amd64 87 | 88 | - name: Upload artifact ${{ matrix.cmd }}-freebsd-amd64 89 | uses: actions/upload-artifact@v1.0.0 90 | with: 91 | # Artifact name 92 | name: ${{ matrix.cmd }}-freebsd-amd64 93 | # Directory containing files to upload 94 | path: freebsd-amd64 95 | 96 | - name: Upload artifact ${{ matrix.cmd }}-windows-amd64 97 | uses: actions/upload-artifact@v1.0.0 98 | with: 99 | # Artifact name 100 | name: ${{ matrix.cmd }}-windows-amd64 101 | # Directory containing files to upload 102 | path: windows-amd64 103 | 104 | - name: Remove old artifacts 105 | run: | 106 | gopath/bin/cicdutil -p github -u missdeer -t ${{ secrets.GH_TOKEN }} -r ${{ matrix.cmd }} -k 0 -a delete 107 | -------------------------------------------------------------------------------- /cmd/cname/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "strings" 11 | "time" 12 | 13 | "github.com/missdeer/ddnsclient/models" 14 | ) 15 | 16 | var ( 17 | token string 18 | user string 19 | domain string 20 | suffix string 21 | prefixList string 22 | maxCount int 23 | ) 24 | 25 | func cloudflareCNAME(subDomain string) error { 26 | // get domain all records 27 | cloudflareAPIUrl := "https://www.cloudflare.com/api_json.html" 28 | client := &http.Client{} 29 | resp, err := client.PostForm(cloudflareAPIUrl, url.Values{ 30 | "a": {"rec_load_all"}, 31 | "tkn": {token}, 32 | "email": {user}, 33 | "z": {domain}, 34 | }) 35 | if err != nil { 36 | fmt.Println("request cloudflare all records failed.", err) 37 | return err 38 | } 39 | defer resp.Body.Close() 40 | 41 | body, err := ioutil.ReadAll(resp.Body) 42 | if err != nil { 43 | fmt.Println("reading cloudflare all records failed.", err) 44 | return err 45 | } 46 | 47 | recordList := new(models.CloudflareRecordList) 48 | if err = json.Unmarshal(body, &recordList); err != nil { 49 | fmt.Printf("unmarshalling cloudflare all records %s failed, %v\n", string(body), err) 50 | return err 51 | } 52 | 53 | // insert or update 54 | foundRecord := false 55 | var recordId string 56 | for _, v := range recordList.Response.Recs.Objs { 57 | if v.Type == "CNAME" && v.DisplayName == subDomain { 58 | recordId = v.Id 59 | foundRecord = true 60 | break 61 | } 62 | } 63 | if foundRecord == false { 64 | // insert a new record 65 | resp, err := client.PostForm(cloudflareAPIUrl, url.Values{ 66 | "a": {"rec_new"}, 67 | "tkn": {token}, 68 | "email": {user}, 69 | "z": {domain}, 70 | "ttl": {"1"}, 71 | "type": {"CNAME"}, 72 | "name": {subDomain}, 73 | "content": {fmt.Sprintf("%s.%s", subDomain, suffix)}, 74 | }) 75 | if err != nil { 76 | fmt.Println("request cloudflare new record failed.", err) 77 | return err 78 | } 79 | 80 | defer resp.Body.Close() 81 | 82 | body, err := ioutil.ReadAll(resp.Body) 83 | if err != nil { 84 | fmt.Println("reading cloudflare new record failed.", err) 85 | return err 86 | } 87 | // extract the new record id 88 | respBody := new(models.CloudflareNewRecordResponseBody) 89 | if err = json.Unmarshal(body, respBody); err != nil { 90 | fmt.Println("unmarshalling cloudflare new record response body failed.", err) 91 | return err 92 | } 93 | recordId = respBody.Response.Rec.Obj.Id 94 | fmt.Printf("[%v] CNAME record inserted into cloudflare: %s.%s => %s.%s\n", time.Now(), subDomain, domain, subDomain, suffix) 95 | return nil 96 | } 97 | // update the record 98 | resp, err = client.PostForm(cloudflareAPIUrl, url.Values{ 99 | "a": {"rec_edit"}, 100 | "tkn": {token}, 101 | "email": {user}, 102 | "z": {domain}, 103 | "type": {"CNAME"}, 104 | "service_mode": {"0"}, 105 | "ttl": {"1"}, 106 | "id": {recordId}, 107 | "name": {subDomain}, 108 | "content": {fmt.Sprintf("%s.%s", subDomain, suffix)}, 109 | }) 110 | if err != nil { 111 | fmt.Println("request cloudflare records edit failed", err) 112 | return err 113 | } 114 | defer resp.Body.Close() 115 | 116 | body, err = ioutil.ReadAll(resp.Body) 117 | if err != nil { 118 | fmt.Println("reading cloudflare record edit response failed.", err) 119 | return err 120 | } 121 | fmt.Printf("[%v] CNAME record update into cloudflare: %s.%s => %s.%s\n", time.Now(), subDomain, domain, subDomain, suffix) 122 | return nil 123 | } 124 | 125 | func main() { 126 | flag.StringVar(&domain, "domain", "", "your domain, such as xxx.com") 127 | flag.StringVar(&suffix, "suffix", "", "target domain, such as zzz.moe") 128 | flag.StringVar(&token, "token", "", "your cloudflare token") 129 | flag.StringVar(&user, "user", "", "your cloudflare user account") 130 | flag.StringVar(&prefixList, "prefix", "cn,kr,eu,tw,us,sg,jp,ru,hk", "prefix list") 131 | flag.IntVar(&maxCount, "max", 9, "max count") 132 | flag.Parse() 133 | 134 | if len(domain) == 0 || len(suffix) == 0 || len(token) == 0 || len(user) == 0 { 135 | flag.Usage() 136 | return 137 | } 138 | 139 | prefixes := strings.Split(prefixList, ",") 140 | for _, prefix := range prefixes { 141 | for i := 0; i <= maxCount; i++ { 142 | subDomain := fmt.Sprintf("%s-%x", prefix, i) 143 | cloudflareCNAME(subDomain) 144 | } 145 | } 146 | fmt.Println("Done!") 147 | } 148 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - tip 4 | env: 5 | global: 6 | - GITHUB_REPO: missdeer/ddnsclient 7 | - GIT_NAME: missdeer 8 | - GIT_EMAIL: missdeer@dfordsoft.com 9 | deploy: 10 | provider: releases 11 | api_key: 12 | secure: aPwmvkYdVaSg8WNZNaBNX4bAcqmr7B/tGSbbMa8T39PCPhKdZv9/aZQ06oOhMEp6ZQb4J0lWHgu7Rs659bGX5rzft8WxqLtRa8m1rEoNvDAFauFTjCNzcjwYGakykTRa/U+jhebLD8lyAY4WT9WwLLZNSLc4g5fPTTRr67GgB+E= 13 | file: 14 | - ddnsclient-darwin-amd64.tar.gz 15 | - ddnsclient-dragonflybsd-amd64.tar.gz 16 | - ddnsclient-freebsd-amd64.tar.gz 17 | - ddnsclient-freebsd-arm.tar.gz 18 | - ddnsclient-freebsd-x86.tar.gz 19 | - ddnsclient-linux-amd64.tar.gz 20 | - ddnsclient-linux-arm64.tar.gz 21 | - ddnsclient-linux-armv6.tar.gz 22 | - ddnsclient-linux-armv7.tar.gz 23 | - ddnsclient-linux-mips64.tar.gz 24 | - ddnsclient-linux-mips64le.tar.gz 25 | - ddnsclient-linux-mips.tar.gz 26 | - ddnsclient-linux-mipsle.tar.gz 27 | - ddnsclient-linux-ppc64.tar.gz 28 | - ddnsclient-linux-ppc64le.tar.gz 29 | - ddnsclient-linux-x86.tar.gz 30 | - ddnsclient-netbsd-amd64.tar.gz 31 | - ddnsclient-netbsd-arm.tar.gz 32 | - ddnsclient-netbsd-x86.tar.gz 33 | - ddnsclient-openbsd-amd64.tar.gz 34 | - ddnsclient-openbsd-x86.tar.gz 35 | - ddnsclient-solaris-amd64.tar.gz 36 | - ddnsclient-windows-amd64.tar.gz 37 | - ddnsclient-windows-x86.tar.gz 38 | on: 39 | repo: missdeer/ddnsclient 40 | tags: true 41 | skip_cleanup: true 42 | 43 | script: 44 | - pwd && ls -l && cd cmd/ddnsclient 45 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 46 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=386 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-x86.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 47 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm GOARM=5 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-armv5.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 48 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm GOARM=6 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-armv6.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 49 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm GOARM=7 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-armv7.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 50 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm64 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-arm64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 51 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=ppc64 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-ppc64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 52 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=ppc64le GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-ppc64le.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 53 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=mips64 GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-mips64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 54 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=mips64le GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-mips64le.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 55 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=mips GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-mips.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 56 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=mipsle GOOS=linux go build -ldflags="-s -w" && tar czvf ddnsclient-linux-mipsle.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 57 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=darwin go build && tar czvf ddnsclient-darwin-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 58 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=windows go build && tar czvf ddnsclient-windows-amd64.tar.gz app.conf.sample ddnsclient.exe && cp ./*.tar.gz ../ 59 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=386 GOOS=windows go build && tar czvf ddnsclient-windows-x86.tar.gz app.conf.sample ddnsclient.exe && cp ./*.tar.gz ../ 60 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=freebsd go build && tar czvf ddnsclient-freebsd-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 61 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=386 GOOS=freebsd go build && tar czvf ddnsclient-freebsd-x86.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 62 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm GOOS=freebsd go build && tar czvf ddnsclient-freebsd-arm.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 63 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=openbsd go build && tar czvf ddnsclient-openbsd-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 64 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=386 GOOS=openbsd go build && tar czvf ddnsclient-openbsd-x86.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 65 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=netbsd go build && tar czvf ddnsclient-netbsd-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 66 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=386 GOOS=netbsd go build && tar czvf ddnsclient-netbsd-x86.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 67 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=arm GOOS=netbsd go build && tar czvf ddnsclient-netbsd-arm.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 68 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=dragonfly go build && tar czvf ddnsclient-dragonflybsd-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 69 | - env GOPATH=$GOPATH:$PWD/../.. GOARCH=amd64 GOOS=solaris go build && tar czvf ddnsclient-solaris-amd64.tar.gz app.conf.sample ddnsclient && cp ./*.tar.gz ../ 70 | - cd .. && pwd && ls -l 71 | -------------------------------------------------------------------------------- /cmd/ddnsclient/cloudxns.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "crypto/md5" 6 | "encoding/hex" 7 | "encoding/json" 8 | "errors" 9 | "fmt" 10 | "io/ioutil" 11 | "net/http" 12 | "time" 13 | 14 | "github.com/missdeer/ddnsclient/models" 15 | ) 16 | 17 | func cloudxnsFindDomain(apiKey string, secretKey string, domain string) int { 18 | client := &http.Client{} 19 | // get domain list 20 | cloudxnsAPIUrl := "https://www.cloudxns.net/api2/domain" 21 | req, err := http.NewRequest("GET", cloudxnsAPIUrl, nil) 22 | req.Header.Set("API-KEY", apiKey) 23 | apiRequestDate := time.Now().String() 24 | req.Header.Add("API-REQUEST-DATE", apiRequestDate) 25 | sum := md5.Sum([]byte(apiKey + cloudxnsAPIUrl + apiRequestDate + secretKey)) 26 | req.Header.Add("API-HMAC", hex.EncodeToString(sum[:])) 27 | resp, err := client.Do(req) 28 | if err != nil { 29 | fmt.Println("Getting CloudXNS domain list failed", err) 30 | return -1 31 | } 32 | defer resp.Body.Close() 33 | 34 | body, err := ioutil.ReadAll(resp.Body) 35 | if err != nil { 36 | fmt.Printf("reading cloudflare all domain list failed\n") 37 | return -1 38 | } 39 | 40 | recordList := new(models.CloudXNSDomainList) 41 | if err = json.Unmarshal(body, &recordList); err != nil { 42 | fmt.Printf("unmarshalling CloudXNS all domain list %s failed: %v\n", string(body), err) 43 | return -1 44 | } 45 | 46 | docoratedDomain := domain + "." 47 | for _, v := range recordList.Data { 48 | if v.Domain == docoratedDomain { 49 | return v.Id 50 | } 51 | } 52 | return -1 53 | } 54 | 55 | func cloudxnsFindHostRecord(apiKey string, secretKey string, domainId int, subDomain string) int { 56 | client := &http.Client{} 57 | // get host record list 58 | cloudxnsAPIUrl := fmt.Sprintf("https://www.cloudxns.net/api2/host/%d?offset=0&row_num=2000", domainId) 59 | req, err := http.NewRequest("GET", cloudxnsAPIUrl, nil) 60 | req.Header.Set("API-KEY", apiKey) 61 | apiRequestDate := time.Now().String() 62 | req.Header.Add("API-REQUEST-DATE", apiRequestDate) 63 | sum := md5.Sum([]byte(apiKey + cloudxnsAPIUrl + apiRequestDate + secretKey)) 64 | req.Header.Add("API-HMAC", hex.EncodeToString(sum[:])) 65 | resp, err := client.Do(req) 66 | if err != nil { 67 | fmt.Println("Getting CloudXNS host record list failed", err) 68 | return -1 69 | } 70 | defer resp.Body.Close() 71 | 72 | body, err := ioutil.ReadAll(resp.Body) 73 | if err != nil { 74 | fmt.Printf("reading CloudXNS all host records failed\n") 75 | return -1 76 | } 77 | 78 | recordList := new(models.CloudXNSHostRecordList) 79 | if err = json.Unmarshal(body, &recordList); err != nil { 80 | fmt.Printf("unmarshalling CloudXNS all records %s failed\n", string(body)) 81 | return -1 82 | } 83 | 84 | for _, v := range recordList.Data { 85 | if v.Host == subDomain { 86 | return v.Id 87 | } 88 | } 89 | 90 | return -1 91 | } 92 | 93 | func cloudxnsRequest(apiKey string, secretKey string, domain string, subDomain string, isInternal bool) error { 94 | // find the domain 95 | domainId := cloudxnsFindDomain(apiKey, secretKey, domain) 96 | if domainId == -1 { 97 | fmt.Println("can't find domain in list", domain) 98 | return errors.New("domain not exists") 99 | } 100 | // find the host 101 | hostRecordId := cloudxnsFindHostRecord(apiKey, secretKey, domainId, subDomain) 102 | if hostRecordId == -1 { 103 | fmt.Println("can't find host record in list", subDomain) 104 | return errors.New("host record not exists") 105 | } 106 | // find the resolve record 107 | client := &http.Client{} 108 | 109 | // get resolve record list 110 | cloudxnsAPIUrl := fmt.Sprintf("https://www.cloudxns.net/api2/record/%d?host_id=%d&offset=0&row_num=2000", domainId, hostRecordId) 111 | req, err := http.NewRequest("GET", cloudxnsAPIUrl, nil) 112 | req.Header.Set("API-KEY", apiKey) 113 | apiRequestDate := time.Now().String() 114 | req.Header.Add("API-REQUEST-DATE", apiRequestDate) 115 | sum := md5.Sum([]byte(apiKey + cloudxnsAPIUrl + apiRequestDate + secretKey)) 116 | req.Header.Add("API-HMAC", hex.EncodeToString(sum[:])) 117 | resp, err := client.Do(req) 118 | if err != nil { 119 | fmt.Println("Getting CloudXNS resolve record list failed", err) 120 | return err 121 | } 122 | defer resp.Body.Close() 123 | 124 | body, err := ioutil.ReadAll(resp.Body) 125 | if err != nil { 126 | fmt.Printf("reading cloudflare all resolve records failed\n") 127 | return err 128 | } 129 | 130 | recordList := new(models.CloudXNSResolveList) 131 | if err = json.Unmarshal(body, &recordList); err != nil { 132 | fmt.Printf("unmarshalling CloudXNS all resolve records %s failed: %v\n", string(body), err) 133 | return err 134 | } 135 | 136 | // insert or update 137 | foundRecord := false 138 | var recordId int 139 | var lineId int 140 | if len(recordList.Data) > 0 { 141 | foundRecord = true 142 | recordId = recordList.Data[0].RecordId 143 | lineId = recordList.Data[0].LineId 144 | } 145 | 146 | newIP := currentExternalIPv4 147 | if isInternal { 148 | newIP = currentInternalIPv4 149 | } 150 | postValues := make(map[string]interface{}) 151 | if foundRecord { 152 | // update 153 | postValues["domain_id"] = domainId 154 | postValues["host"] = subDomain 155 | postValues["value"] = newIP 156 | p, err := json.Marshal(postValues) 157 | if err != nil { 158 | fmt.Println("marshal update body failed", err) 159 | return err 160 | } 161 | 162 | cloudxnsAPIUrl := fmt.Sprintf("https://www.cloudxns.net/api2/record/%d", recordId) 163 | req, err := http.NewRequest("PUT", cloudxnsAPIUrl, bytes.NewReader(p)) 164 | req.Header.Set("API-KEY", apiKey) 165 | apiRequestDate := time.Now().String() 166 | req.Header.Add("API-REQUEST-DATE", apiRequestDate) 167 | sum := md5.Sum([]byte(apiKey + cloudxnsAPIUrl + string(p) + apiRequestDate + secretKey)) 168 | req.Header.Add("API-HMAC", hex.EncodeToString(sum[:])) 169 | resp, err := client.Do(req) 170 | if err != nil { 171 | fmt.Printf("[%v] Updating CloudXNS resolve item failed: %v", time.Now(), err) 172 | return err 173 | } 174 | defer resp.Body.Close() 175 | fmt.Printf("A record updated to cloudXNS: %s.%s => %s\n", subDomain, domain, currentExternalIPv4) 176 | } else { 177 | // insert 178 | postValues["domain_id"] = fmt.Sprintf("%d", domainId) 179 | postValues["host"] = subDomain 180 | postValues["value"] = newIP 181 | postValues["type"] = "A" 182 | postValues["line_id"] = fmt.Sprintf("%d", lineId) 183 | p, err := json.Marshal(postValues) 184 | if err != nil { 185 | fmt.Println("marshal update body failed", err) 186 | return err 187 | } 188 | cloudxnsAPIUrl := "https://www.cloudxns.net/api2/record" 189 | req, err := http.NewRequest("POST", cloudxnsAPIUrl, bytes.NewReader(p)) 190 | req.Header.Set("API-KEY", apiKey) 191 | apiRequestDate := time.Now().String() 192 | req.Header.Add("API-REQUEST-DATE", apiRequestDate) 193 | sum := md5.Sum([]byte(apiKey + cloudxnsAPIUrl + string(p) + apiRequestDate + secretKey)) 194 | req.Header.Add("API-HMAC", hex.EncodeToString(sum[:])) 195 | resp, err := client.Do(req) 196 | if err != nil { 197 | fmt.Printf("[%v] inserting CloudXNS resolve item failed: %v", time.Now(), err) 198 | return err 199 | } 200 | defer resp.Body.Close() 201 | fmt.Printf("A record inserted to cloudXNS: %s.%s => %s\n", subDomain, domain, newIP) 202 | } 203 | return nil 204 | } 205 | -------------------------------------------------------------------------------- /cmd/ddnsclient/dnspod.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "strconv" 11 | "time" 12 | 13 | "github.com/missdeer/ddnsclient/models" 14 | ) 15 | 16 | var ( 17 | dnspodDomainList = &models.DnspodDomainList{} 18 | ) 19 | 20 | func dnspodRequestByToken(id string, token string, domain string, subDomain string, isInternal bool) error { 21 | needDomainList := false 22 | if len(dnspodDomainList.Domains) == 0 { 23 | needDomainList = true 24 | } 25 | var domainId int = 0 26 | if needDomainList == false { 27 | needDomainList = true 28 | for _, v := range dnspodDomainList.Domains { 29 | if v.Name == domain { 30 | needDomainList = false 31 | domainId = v.Id 32 | break 33 | } 34 | } 35 | } 36 | 37 | client := &http.Client{} 38 | if needDomainList { 39 | // get domainn id first 40 | domainListUrl := "https://dnsapi.cn/Domain.List" 41 | resp, err := client.PostForm(domainListUrl, url.Values{ 42 | "login_token": {id + "," + token}, 43 | "format": {"json"}, 44 | }) 45 | if err != nil { 46 | fmt.Printf("request domain list failed\n") 47 | return err 48 | } 49 | defer resp.Body.Close() 50 | 51 | body, err := ioutil.ReadAll(resp.Body) 52 | if err != nil { 53 | fmt.Printf("reading domain list failed\n") 54 | return err 55 | } 56 | 57 | if err = json.Unmarshal(body, &dnspodDomainList); err != nil { 58 | fmt.Printf("unmarshalling domain list %s failed\n", string(body)) 59 | return err 60 | } 61 | } 62 | foundDomain := false 63 | for _, v := range dnspodDomainList.Domains { 64 | if v.Name == domain { 65 | foundDomain = true 66 | domainId = v.Id 67 | break 68 | } 69 | } 70 | 71 | if foundDomain == false { 72 | fmt.Printf("domain %s doesn't exists\n", domain) 73 | return errors.New("domain not found") 74 | } 75 | 76 | // check record list 77 | recordListUrl := "https://dnsapi.cn/Record.List" 78 | resp, err := client.PostForm(recordListUrl, url.Values{ 79 | "login_token": {id + "," + token}, 80 | "format": {"json"}, 81 | "domain_id": {strconv.Itoa(domainId)}, 82 | }) 83 | if err != nil { 84 | fmt.Printf("request record list failed\n") 85 | return err 86 | } 87 | defer resp.Body.Close() 88 | 89 | body, err := ioutil.ReadAll(resp.Body) 90 | if err != nil { 91 | fmt.Printf("reading record list failed\n") 92 | return err 93 | } 94 | 95 | recordList := new(models.DnspodRecordList) 96 | if err = json.Unmarshal(body, recordList); err != nil { 97 | fmt.Printf("unmarshalling record list %s failed\n", string(body)) 98 | fmt.Println(err) 99 | return err 100 | } 101 | foundRecord := false 102 | var recordID string 103 | for _, v := range recordList.Records { 104 | if v.Name == subDomain { 105 | foundRecord = true 106 | recordID = v.Id 107 | break 108 | } 109 | } 110 | 111 | newIP := currentExternalIPv4 112 | if isInternal { 113 | newIP = currentInternalIPv4 114 | } 115 | if foundRecord == false { 116 | // if the sub domain doesn't exist, add one 117 | addRecordURL := "https://dnsapi.cn/Record.Create" 118 | resp, err := client.PostForm(addRecordURL, url.Values{ 119 | "login_token": {id + "," + token}, 120 | "format": {"json"}, 121 | "domain_id": {strconv.Itoa(domainId)}, 122 | "sub_domain": {subDomain}, 123 | "record_type": {"A"}, 124 | "record_line": {"默认"}, 125 | "value": {newIP}, 126 | }) 127 | if err != nil { 128 | fmt.Printf("request record insert failed\n") 129 | return err 130 | } 131 | defer resp.Body.Close() 132 | 133 | if _, err = ioutil.ReadAll(resp.Body); err != nil { 134 | fmt.Printf("reading record insert response failed\n") 135 | return err 136 | } 137 | 138 | fmt.Printf("[%v] A record inserted into DNSPOD: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 139 | } else { 140 | // otherwise just update it 141 | modifyRecordURL := "https://dnsapi.cn/Record.Modify" 142 | resp, err := client.PostForm(modifyRecordURL, url.Values{ 143 | "login_token": {id + "," + token}, 144 | "format": {"json"}, 145 | "record_id": {recordID}, 146 | "domain_id": {strconv.Itoa(domainId)}, 147 | "sub_domain": {subDomain}, 148 | "record_type": {"A"}, 149 | "record_line": {"默认"}, 150 | "value": {newIP}, 151 | }) 152 | if err != nil { 153 | fmt.Printf("request record modify failed\n") 154 | return err 155 | } 156 | defer resp.Body.Close() 157 | 158 | if _, err = ioutil.ReadAll(resp.Body); err != nil { 159 | fmt.Printf("reading record modify response failed\n") 160 | return err 161 | } 162 | fmt.Printf("[%v] A record updated to DNSPOD: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 163 | } 164 | 165 | return nil 166 | } 167 | 168 | func dnspodRequest(user string, password string, domain string, subDomain string, isInternal bool) error { 169 | needDomainList := false 170 | if len(dnspodDomainList.Domains) == 0 { 171 | needDomainList = true 172 | } 173 | var domainId int = 0 174 | if needDomainList == false { 175 | needDomainList = true 176 | for _, v := range dnspodDomainList.Domains { 177 | if v.Name == domain { 178 | needDomainList = false 179 | domainId = v.Id 180 | break 181 | } 182 | } 183 | } 184 | 185 | client := &http.Client{} 186 | if needDomainList { 187 | // get domainn id first 188 | domainListUrl := "https://dnsapi.cn/Domain.List" 189 | resp, err := client.PostForm(domainListUrl, url.Values{ 190 | "login_email": {user}, 191 | "login_password": {password}, 192 | "format": {"json"}, 193 | }) 194 | if err != nil { 195 | fmt.Printf("request domain list failed\n") 196 | return err 197 | } 198 | defer resp.Body.Close() 199 | 200 | body, err := ioutil.ReadAll(resp.Body) 201 | if err != nil { 202 | fmt.Printf("reading domain list failed\n") 203 | return err 204 | } 205 | 206 | if err = json.Unmarshal(body, &dnspodDomainList); err != nil { 207 | fmt.Printf("unmarshalling domain list %s failed\n", string(body)) 208 | return err 209 | } 210 | } 211 | foundDomain := false 212 | for _, v := range dnspodDomainList.Domains { 213 | if v.Name == domain { 214 | foundDomain = true 215 | domainId = v.Id 216 | break 217 | } 218 | } 219 | 220 | if foundDomain == false { 221 | fmt.Printf("domain %s doesn't exists\n", domain) 222 | return errors.New("domain not found") 223 | } 224 | 225 | // check record list 226 | recordListUrl := "https://dnsapi.cn/Record.List" 227 | resp, err := client.PostForm(recordListUrl, url.Values{ 228 | "login_email": {user}, 229 | "login_password": {password}, 230 | "format": {"json"}, 231 | "domain_id": {strconv.Itoa(domainId)}, 232 | }) 233 | if err != nil { 234 | fmt.Printf("request record list failed\n") 235 | return err 236 | } 237 | defer resp.Body.Close() 238 | 239 | body, err := ioutil.ReadAll(resp.Body) 240 | if err != nil { 241 | fmt.Printf("reading record list failed\n") 242 | return err 243 | } 244 | 245 | recordList := new(models.DnspodRecordList) 246 | if err = json.Unmarshal(body, recordList); err != nil { 247 | fmt.Printf("unmarshalling record list %s failed\n", string(body)) 248 | fmt.Println(err) 249 | return err 250 | } 251 | foundRecord := false 252 | var recordID string 253 | for _, v := range recordList.Records { 254 | if v.Name == subDomain { 255 | foundRecord = true 256 | recordID = v.Id 257 | break 258 | } 259 | } 260 | 261 | newIP := currentExternalIPv4 262 | if isInternal { 263 | newIP = currentInternalIPv4 264 | } 265 | if foundRecord == false { 266 | // if the sub domain doesn't exist, add one 267 | addRecordURL := "https://dnsapi.cn/Record.Create" 268 | resp, err := client.PostForm(addRecordURL, url.Values{ 269 | "login_email": {user}, 270 | "login_password": {password}, 271 | "format": {"json"}, 272 | "domain_id": {strconv.Itoa(domainId)}, 273 | "sub_domain": {subDomain}, 274 | "record_type": {"A"}, 275 | "record_line": {"默认"}, 276 | "value": {newIP}, 277 | }) 278 | if err != nil { 279 | fmt.Printf("request record insert failed\n") 280 | return err 281 | } 282 | defer resp.Body.Close() 283 | 284 | if _, err = ioutil.ReadAll(resp.Body); err != nil { 285 | fmt.Printf("reading record insert response failed\n") 286 | return err 287 | } 288 | 289 | fmt.Printf("[%v] A record inserted into DNSPOD: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 290 | } else { 291 | // otherwise just update it 292 | modifyRecordURL := "https://dnsapi.cn/Record.Modify" 293 | resp, err := client.PostForm(modifyRecordURL, url.Values{ 294 | "login_email": {user}, 295 | "login_password": {password}, 296 | "format": {"json"}, 297 | "record_id": {recordID}, 298 | "domain_id": {strconv.Itoa(domainId)}, 299 | "sub_domain": {subDomain}, 300 | "record_type": {"A"}, 301 | "record_line": {"默认"}, 302 | "value": {newIP}, 303 | }) 304 | if err != nil { 305 | fmt.Printf("request record modify failed\n") 306 | return err 307 | } 308 | defer resp.Body.Close() 309 | 310 | if _, err = ioutil.ReadAll(resp.Body); err != nil { 311 | fmt.Printf("reading record modify response failed\n") 312 | return err 313 | } 314 | fmt.Printf("[%v] A record updated to DNSPOD: %s.%s => %s\n", time.Now(), subDomain, domain, newIP) 315 | } 316 | 317 | return nil 318 | } 319 | -------------------------------------------------------------------------------- /cmd/ddnsclient/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "encoding/json" 7 | "errors" 8 | "flag" 9 | "fmt" 10 | "io/ioutil" 11 | "log" 12 | "net" 13 | "net/http" 14 | "net/url" 15 | "os" 16 | "regexp" 17 | "strings" 18 | "time" 19 | 20 | "github.com/missdeer/ddnsclient/models" 21 | ) 22 | 23 | type Setting struct { 24 | BasicAuthItems []models.BasicAuthConfigurationItem `json:"basic"` 25 | DnspodItems []models.DnspodConfigurationItem `json:"dnspod"` 26 | CloudflareItems []models.CloudflareConfigurationItem `json:"cloudflare"` 27 | CloudXNSItems []models.CloudXNSConfigurationItem `json:"cloudxns"` 28 | } 29 | 30 | var ( 31 | insecureSkipVerify bool 32 | ifconfigURL string 33 | currentExternalIPv4 string 34 | currentExternalIPv6 string 35 | currentInternalIPv4 string 36 | currentInternalIPv6 string 37 | lastExternalIPv4 string 38 | lastExternalIPv6 string 39 | lastInternalIPv4 string 40 | lastInternalIPv6 string 41 | networkStack string 42 | ) 43 | 44 | func getCurrentInternalIPs(ipv4 bool) ([]string, error) { 45 | var ips []string 46 | addrs, err := net.InterfaceAddrs() 47 | if err != nil { 48 | fmt.Println(err) 49 | return nil, err 50 | } 51 | for _, address := range addrs { 52 | if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { 53 | if (ipv4 && ipnet.IP.To4() != nil) || (!ipv4 && ipnet.IP.To16() != nil) { 54 | ips = append(ips, ipnet.IP.String()) 55 | } 56 | } 57 | } 58 | 59 | return ips, nil 60 | } 61 | 62 | func getCurrentExternalIP(ipv4 bool) (string, error) { 63 | parse, err := url.Parse(ifconfigURL) 64 | if err != nil { 65 | log.Println("can't parse ifconfig URL", err) 66 | return "", err 67 | } 68 | ips, err := net.LookupIP(parse.Host) 69 | if err != nil { 70 | log.Println("can't lookup IP", err) 71 | return "", err 72 | } 73 | var targetURL string 74 | for _, ip := range ips { 75 | if ipv4 == true && ip.To4() != nil { 76 | if parse.Port() != "" { 77 | targetURL = fmt.Sprintf("%s:%s", ip.To4().String(), parse.Port()) 78 | } else { 79 | if parse.Scheme == "http" { 80 | targetURL = fmt.Sprintf("%s:80", ip.To4().String()) 81 | } else { 82 | targetURL = fmt.Sprintf("%s:443", ip.To4().String()) 83 | } 84 | } 85 | break 86 | } 87 | if ipv4 == false && ip.To16() != nil { 88 | if parse.Port() != "" { 89 | targetURL = fmt.Sprintf("[%s]:%s", ip.To16().String(), parse.Port()) 90 | } else { 91 | if parse.Scheme == "http" { 92 | targetURL = fmt.Sprintf("[%s]:80", ip.To16().String()) 93 | } else { 94 | targetURL = fmt.Sprintf("[%s]:443", ip.To16().String()) 95 | } 96 | } 97 | break 98 | } 99 | } 100 | req, err := http.NewRequest("GET", ifconfigURL, nil) 101 | if err != nil { 102 | fmt.Println("create request to ifconfig failed", err) 103 | return "", err 104 | } 105 | req.Header.Set("User-Agent", "curl/7.41.0") 106 | 107 | client := &http.Client{ 108 | Transport: &http.Transport{ 109 | TLSClientConfig: &tls.Config{ 110 | InsecureSkipVerify: insecureSkipVerify, 111 | }, 112 | DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { 113 | if strings.HasPrefix(addr, parse.Host) { 114 | addr = targetURL 115 | } 116 | dialer := &net.Dialer{ 117 | Timeout: 30 * time.Second, 118 | KeepAlive: 30 * time.Second, 119 | } 120 | return dialer.DialContext(ctx, network, addr) 121 | }, 122 | }, 123 | } 124 | resp, err := client.Do(req) 125 | if err != nil { 126 | fmt.Printf("request %s failed", ifconfigURL) 127 | return "", err 128 | } 129 | defer resp.Body.Close() 130 | 131 | body, err := ioutil.ReadAll(resp.Body) 132 | if err != nil { 133 | fmt.Printf("reading ifconfig response failed\n") 134 | return "", err 135 | } 136 | 137 | for i := len(body); i > 0 && (body[i-1] < '0' || body[i-1] > '9'); i = len(body) { 138 | body = body[:i-1] 139 | } 140 | 141 | if matched, err := regexp.Match(`^((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])$`, body); err == nil && matched == true { 142 | return string(body), nil 143 | } 144 | 145 | if matched, err := regexp.Match(`^(([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]))$`, body); err == nil && matched == true { 146 | return string(body), nil 147 | } 148 | 149 | return "", errors.New("invalid IP address: " + string(body)) 150 | } 151 | 152 | func updateDDNS(setting *Setting) { 153 | var err error 154 | if networkStack == "ipv4" || networkStack == "dual" { 155 | currentExternalIPv4, err = getCurrentExternalIP(true) 156 | if err != nil { 157 | fmt.Println(err) 158 | return 159 | } 160 | currentInternalIPsV4, e := getCurrentInternalIPs(true) 161 | if e != nil { 162 | fmt.Println(err) 163 | return 164 | } 165 | currentInternalIPv4 = currentInternalIPsV4[0] 166 | } 167 | 168 | if networkStack == "ipv6" || networkStack == "dual" { 169 | currentExternalIPv6, err = getCurrentExternalIP(false) 170 | if err != nil { 171 | fmt.Println(err) 172 | return 173 | } 174 | currentInternalIPsV6, e := getCurrentInternalIPs(false) 175 | if e != nil { 176 | fmt.Println(err) 177 | return 178 | } 179 | currentInternalIPv6 = currentInternalIPsV6[0] 180 | } 181 | log.Println("current external ip:", currentExternalIPv4, currentExternalIPv6) 182 | log.Println("current internal ip:", currentInternalIPv4, currentInternalIPv6) 183 | basicAuth := func(v models.BasicAuthConfigurationItem) { 184 | for { 185 | if err := basicAuthorizeHttpRequest(v.UserName, v.Password, v.Url); err == nil { 186 | break 187 | } 188 | time.Sleep(1 * time.Minute) 189 | } 190 | } 191 | 192 | dnspod := func(v models.DnspodConfigurationItem) { 193 | for { 194 | if len(v.Token) != 0 && len(v.TokenId) != 0 { 195 | if err := dnspodRequestByToken(v.TokenId, v.Token, v.Domain, v.SubDomain, v.Internal); err == nil { 196 | break 197 | } 198 | } else if len(v.UserName) != 0 && len(v.Password) != 0 { 199 | if err := dnspodRequest(v.UserName, v.Password, v.Domain, v.SubDomain, v.Internal); err == nil { 200 | break 201 | } 202 | } 203 | time.Sleep(1 * time.Minute) 204 | } 205 | } 206 | 207 | cloudflare := func(v models.CloudflareConfigurationItem) { 208 | for { 209 | if err := cloudflareRequest(v.UserName, v.Token, v.Domain, v.SubDomain, v.Internal); err == nil { 210 | break 211 | } 212 | time.Sleep(1 * time.Minute) 213 | } 214 | } 215 | 216 | cloudxns := func(v models.CloudXNSConfigurationItem) { 217 | for { 218 | if err := cloudxnsRequest(v.APIKey, v.SecretKey, v.Domain, v.SubDomain, v.Internal); err == nil { 219 | break 220 | } 221 | time.Sleep(1 * time.Minute) 222 | } 223 | } 224 | if ((networkStack == "ipv4" || networkStack == "dual") && (len(currentExternalIPv4) != 0 && lastExternalIPv4 != currentExternalIPv4) || (len(currentInternalIPv4) != 0 && lastInternalIPv4 != currentInternalIPv4)) || 225 | ((networkStack == "ipv6" || networkStack == "dual") && (len(currentExternalIPv6) != 0 && lastExternalIPv6 != currentExternalIPv6) || (len(currentInternalIPv6) != 0 && lastInternalIPv6 != currentInternalIPv6)) { 226 | for _, v := range setting.BasicAuthItems { 227 | go basicAuth(v) 228 | } 229 | 230 | for _, v := range setting.DnspodItems { 231 | go dnspod(v) 232 | } 233 | 234 | for _, v := range setting.CloudflareItems { 235 | go cloudflare(v) 236 | } 237 | 238 | for _, v := range setting.CloudXNSItems { 239 | go cloudxns(v) 240 | } 241 | if (networkStack == "ipv4" || networkStack == "dual") && len(currentExternalIPv4) != 0 { 242 | lastExternalIPv4 = currentExternalIPv4 243 | } 244 | if (networkStack == "ipv4" || networkStack == "dual") && len(currentInternalIPv4) != 0 { 245 | lastInternalIPv4 = currentInternalIPv4 246 | } 247 | if (networkStack == "ipv6" || networkStack == "dual") && len(currentExternalIPv6) != 0 { 248 | lastExternalIPv6 = currentExternalIPv6 249 | } 250 | if (networkStack == "ipv6" || networkStack == "dual") && len(currentInternalIPv6) != 0 { 251 | lastInternalIPv6 = currentInternalIPv6 252 | } 253 | } 254 | } 255 | 256 | var conf string 257 | 258 | func main() { 259 | flag.BoolVar(&insecureSkipVerify, "insecureSkipVerify", false, "if true, TLS accepts any certificate") 260 | flag.StringVar(&ifconfigURL, "ifconfig", "https://ifconfig.minidump.info", "set ifconfig URL") 261 | flag.StringVar(&conf, "config", "app.conf", "set application config") 262 | flag.StringVar(&networkStack, "stack", "ipv4", "set network stack, available values: ipv4, ipv6, dual") 263 | var interval string 264 | flag.StringVar(&interval, "interval", "1m", "set update interval, available values: 1m, 5m, 10m, 30m, 1h, 2h, 6h, 12h, 1d") 265 | var singleShot bool 266 | flag.BoolVar(&singleShot, "singleShot", false, "if true, update once and exit") 267 | flag.Parse() 268 | 269 | fmt.Println("Dynamic DNS client") 270 | appConf, err := os.Open(conf) 271 | if err != nil { 272 | fmt.Println("opening app.conf failed:", err) 273 | return 274 | } 275 | 276 | defer func() { 277 | appConf.Close() 278 | }() 279 | 280 | b, err := ioutil.ReadAll(appConf) 281 | if err != nil { 282 | fmt.Println("reading app.conf failed:", err) 283 | return 284 | } 285 | setting := new(Setting) 286 | err = json.Unmarshal(b, &setting) 287 | if err != nil { 288 | fmt.Println("unmarshalling app.conf failed:", err) 289 | return 290 | } 291 | 292 | updateDDNS(setting) 293 | if !singleShot { 294 | duration, err := time.ParseDuration(interval) 295 | if err != nil { 296 | log.Fatal(err) 297 | } 298 | timer := time.NewTicker(duration) // every 1 minute 299 | for { 300 | select { 301 | case <-timer.C: 302 | go updateDDNS(setting) 303 | } 304 | } 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------