diff --git a/README.md b/README.md index 9083bef3f..3cfff3a1b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Light container updating DNS A and/or AAAA records periodically for multiple DNS ## Features - Updates periodically A records for different DNS providers: + - Aliyun - Cloudflare - DD24 - DDNSS.de @@ -148,6 +149,7 @@ Start by having the following content in *config.json*, or in your `CONFIG` envi For each setting, you need to fill in parameters. Check the documentation for your DNS provider: +- [Aliyun](https://github.com/qdm12/ddns-updater/blob/master/docs/aliyun.md) - [Cloudflare](https://github.com/qdm12/ddns-updater/blob/master/docs/cloudflare.md) - [DDNSS.de](https://github.com/qdm12/ddns-updater/blob/master/docs/ddnss.de.md) - [DigitalOcean](https://github.com/qdm12/ddns-updater/blob/master/docs/digitalocean.md) diff --git a/docs/aliyun.md b/docs/aliyun.md new file mode 100644 index 000000000..a054b6ab1 --- /dev/null +++ b/docs/aliyun.md @@ -0,0 +1,35 @@ +# Aliyun + +## Configuration + +### Example + +```json +{ + "settings": [ + { + "provider": "aliyun", + "domain": "domain.com", + "host": "@", + "access_key_id": "your access_key_id", + "access_secret": "your access_secret", + "region": "your region", + "ip_version": "ipv4" + } + ] +} +``` + +### Compulsory parameters + +- `"domain"` +- `"host"` is your host and can be a subdomain or `"@"` +- `"access_key_id"` +- `"access_secret"` + +### Optional parameters + +- `"ip_version"` can be `ipv4` (A records) or `ipv6` (AAAA records), defaults to `ipv4 or ipv6` +- `"region"` is your region, which defaults to `cn-hangzhou` if not set. + +## Domain setup diff --git a/go.mod b/go.mod index 96d1303aa..5a7403e1f 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/qdm12/ddns-updater go 1.17 require ( + github.com/aliyun/alibaba-cloud-sdk-go v1.61.1280 github.com/breml/rootcerts v0.1.0 github.com/containrrr/shoutrrr v0.5.1 github.com/go-chi/chi v1.5.4 @@ -18,8 +19,12 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.12.0 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect + github.com/json-iterator/go v1.1.9 // indirect github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.12 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nxadm/tail v1.4.6 // indirect github.com/onsi/ginkgo v1.14.2 // indirect github.com/onsi/gomega v1.10.1 // indirect @@ -29,7 +34,8 @@ require ( golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect golang.org/x/text v0.3.3 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 4ef3ba1d3..d64bcded6 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/agnivade/wasmbrowsertest v0.3.1/go.mod h1:zQt6ZTdl338xxRaMW395qccVE2eQm0SjC/SDz0mPWQI= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1280 h1:2NvK2j7P4yuxBp2hoJ1UMpmrYY+na8M/0+IP60vdiww= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1280/go.mod h1:9CMdKNL3ynIGPpfTcdwTvIm8SGuAZYYC4jFVSSvE1YQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -61,6 +63,7 @@ github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6Wezm github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -90,6 +93,7 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20190908185732-236ed259b199/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -101,8 +105,13 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jarcoal/httpmock v1.0.4 h1:jp+dy/+nonJE4g4xbVtl9QdrUNbn6/3hDT5R4nDIZnA= github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -142,7 +151,10 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.2.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= @@ -188,7 +200,9 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -328,6 +342,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= +gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -338,8 +354,9 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gosrc.io/xmpp v0.5.1/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY= gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/gotestsum v0.3.5/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY= diff --git a/internal/settings/constants/providers.go b/internal/settings/constants/providers.go index 1867f1023..b47121f10 100644 --- a/internal/settings/constants/providers.go +++ b/internal/settings/constants/providers.go @@ -4,6 +4,7 @@ import "github.com/qdm12/ddns-updater/internal/models" // All possible provider values. const ( + Aliyun models.Provider = "aliyun" Cloudflare models.Provider = "cloudflare" Dd24 models.Provider = "dd24" DdnssDe models.Provider = "ddnss" @@ -38,6 +39,7 @@ const ( func ProviderChoices() []models.Provider { return []models.Provider{ + Aliyun, Cloudflare, Dd24, DdnssDe, diff --git a/internal/settings/errors/validation.go b/internal/settings/errors/validation.go index 78b9385b9..37d3f07b8 100644 --- a/internal/settings/errors/validation.go +++ b/internal/settings/errors/validation.go @@ -13,6 +13,8 @@ var ( ErrEmptyApiSecret = errors.New("empty API secret") ErrEmptySecret = errors.New("empty secret") ErrEmptyToken = errors.New("empty token") + ErrEmptyAccessKeyId = errors.New("empty access key id") + ErrEmptyAccessKeySecret = errors.New("empty key secret") ErrEmptyTTL = errors.New("TTL is not set") ErrEmptyUsername = errors.New("empty username") ErrEmptyZoneIdentifier = errors.New("empty zone identifier") diff --git a/internal/settings/providers/aliyun/provider.go b/internal/settings/providers/aliyun/provider.go new file mode 100644 index 000000000..bcf91b833 --- /dev/null +++ b/internal/settings/providers/aliyun/provider.go @@ -0,0 +1,139 @@ +package aliyun + +import ( + "context" + "encoding/json" + "fmt" + "net" + "net/http" + "strings" + + "github.com/aliyun/alibaba-cloud-sdk-go/services/alidns" + "github.com/qdm12/ddns-updater/internal/models" + "github.com/qdm12/ddns-updater/internal/settings/constants" + "github.com/qdm12/ddns-updater/internal/settings/errors" + "github.com/qdm12/ddns-updater/internal/settings/utils" + "github.com/qdm12/ddns-updater/pkg/publicip/ipversion" +) + +type provider struct { + domain string + host string + ipVersion ipversion.IPVersion + accessKeyId string + accessSecret string + region string +} + +func New(data json.RawMessage, domain, host string, + ipVersion ipversion.IPVersion) (p *provider, err error) { + extraSettings := struct { + AccessKeyId string `json:"access_key_id"` + AccessSecret string `json:"access_secret"` + Region string `json:"region"` + }{} + if err := json.Unmarshal(data, &extraSettings); err != nil { + return nil, err + } + p = &provider{ + domain: domain, + host: host, + ipVersion: ipVersion, + accessKeyId: extraSettings.AccessKeyId, + accessSecret: extraSettings.AccessSecret, + region: "cn-hangzhou", + } + if extraSettings.Region != "" { + p.region = extraSettings.Region + } + if err := p.isValid(); err != nil { + return nil, err + } + return p, nil +} + +func (p *provider) isValid() error { + switch { + case p.accessKeyId == "": + return errors.ErrEmptyAccessKeyId + case p.accessSecret == "": + return errors.ErrEmptyAccessKeySecret + } + return nil +} + +func (p *provider) String() string { + return utils.ToString(p.domain, p.host, constants.Aliyun, p.ipVersion) +} + +func (p *provider) Domain() string { + return p.domain +} + +func (p *provider) Host() string { + return p.host +} + +func (p *provider) IPVersion() ipversion.IPVersion { + return p.ipVersion +} + +func (p *provider) Proxied() bool { + return false +} + +func (p *provider) BuildDomainName() string { + return utils.BuildDomainName(p.host, p.domain) +} + +func (p *provider) HTML() models.HTMLRow { + return models.HTMLRow{ + Domain: models.HTML(fmt.Sprintf("%s", p.BuildDomainName(), p.BuildDomainName())), + Host: models.HTML(p.Host()), + Provider: "Aliyun", + IPVersion: models.HTML(p.ipVersion.String()), + } +} + +func (p *provider) Update(ctx context.Context, _ *http.Client, ip net.IP) (newIP net.IP, err error) { + recordType := constants.A + if ip.To4() == nil { + recordType = constants.AAAA + } + + client, err := alidns.NewClientWithAccessKey(p.region, p.accessKeyId, p.accessSecret) + if err != nil { + return nil, err + } + + listRequest := alidns.CreateDescribeDomainRecordsRequest() + listRequest.Scheme = "https" + + listRequest.DomainName = p.domain + listRequest.RRKeyWord = p.host + resp, err := client.DescribeDomainRecords(listRequest) + if err != nil { + return nil, err + } + recordID := "" + for _, record := range resp.DomainRecords.Record { + if strings.EqualFold(record.RR, p.host) { + recordID = record.RecordId + break + } + } + if recordID == "" { + return nil, errors.ErrRecordNotFound + } + + request := alidns.CreateUpdateDomainRecordRequest() + request.Scheme = "https" + + request.Value = ip.String() + request.Type = recordType + request.RR = p.host + request.RecordId = recordID + + _, err = client.UpdateDomainRecord(request) + return ip, err +} diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 3ef5b9d64..db7f7ebf0 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -11,6 +11,7 @@ import ( "github.com/qdm12/ddns-updater/internal/models" "github.com/qdm12/ddns-updater/internal/regex" "github.com/qdm12/ddns-updater/internal/settings/constants" + "github.com/qdm12/ddns-updater/internal/settings/providers/aliyun" "github.com/qdm12/ddns-updater/internal/settings/providers/cloudflare" "github.com/qdm12/ddns-updater/internal/settings/providers/dd24" "github.com/qdm12/ddns-updater/internal/settings/providers/ddnss" @@ -62,6 +63,8 @@ func New(provider models.Provider, data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion, matcher regex.Matcher) ( settings Settings, err error) { switch provider { + case constants.Aliyun: + return aliyun.New(data, domain, host, ipVersion) case constants.Cloudflare: return cloudflare.New(data, domain, host, ipVersion, matcher) case constants.Dd24: