Compare commits

...

2 Commits

Author SHA1 Message Date
f5730d2691 update using 2023-09-21 17:09:25 -04:00
3f5d108177 add MX record 2023-09-21 17:07:58 -04:00
2 changed files with 21 additions and 6 deletions

View File

@ -5,6 +5,10 @@ CLI tool to manage cloudflare DNS records
### Using go ### Using go
```bash ```bash
go install go.balki.me/cloudflare-dns-cli@latest go install go.balki.me/cloudflare-dns-cli@latest
# Or run directly
go run go.balki.me/cloudflare-dns-cli@latest
``` ```
### Using docker ### Using docker
```bash ```bash
@ -14,7 +18,7 @@ CLI tool to manage cloudflare DNS records
## Features ## Features
1. Add/Modify `A`, `AAAA`, `CNAME` records 1. Add/Modify `A`, `AAAA`, `CNAME`, `MX` records
2. List/Delete records 2. List/Delete records
3. Save all records in JSON format 3. Save all records in JSON format
@ -30,6 +34,7 @@ Usage of cloudflare-dns-cli:
Domain name, e.g. example.com. env var: DOMAIN Domain name, e.g. example.com. env var: DOMAIN
-i value -i value
IP address (default 127.0.0.1) IP address (default 127.0.0.1)
-m Set mx record with cname value
-o string -o string
Path to save all records as json, e.g. ./records.json Path to save all records as json, e.g. ./records.json
-s string -s string

10
main.go
View File

@ -23,6 +23,7 @@ var (
sub = "<UNSET>" sub = "<UNSET>"
path string path string
del = false del = false
mx = false
) )
func genRecord() (libdns.Record, error) { func genRecord() (libdns.Record, error) {
@ -30,11 +31,19 @@ func genRecord() (libdns.Record, error) {
ipv6 := ip.To16() ipv6 := ip.To16()
switch { switch {
case cname != "": case cname != "":
if mx {
return libdns.Record{
Type: "MX",
Name: sub,
Value: cname,
}, nil
} else {
return libdns.Record{ return libdns.Record{
Type: "CNAME", Type: "CNAME",
Name: sub, Name: sub,
Value: cname, Value: cname,
}, nil }, nil
}
case ipv4 != nil: case ipv4 != nil:
return libdns.Record{ return libdns.Record{
Type: "A", Type: "A",
@ -101,6 +110,7 @@ func main() {
flag.StringVar(&cname, "c", cname, "CNAME target") flag.StringVar(&cname, "c", cname, "CNAME target")
flag.StringVar(&path, "o", path, "Path to save all records as json, e.g. ./records.json") flag.StringVar(&path, "o", path, "Path to save all records as json, e.g. ./records.json")
flag.BoolVar(&del, "x", del, "Delete records of subdomain") flag.BoolVar(&del, "x", del, "Delete records of subdomain")
flag.BoolVar(&mx, "m", mx, "Set mx record with cname value")
flag.Parse() flag.Parse()
provider := cloudflare.Provider{APIToken: token} provider := cloudflare.Provider{APIToken: token}