Skip to content

Commit

Permalink
Merge pull request #8 from ruedigerp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ruedigerp authored Nov 22, 2024
2 parents 78536a9 + 8580514 commit fea54dc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# readme
# DNS-Manager

## Install

brew tap ruedigerp/dns-manager
brew install ruedigerp/dns-manager
3 changes: 2 additions & 1 deletion cmd/addRecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var addRecordCmd = &cobra.Command{
proxied, _ := cmd.Flags().GetBool("proxied")
zone, _ := cmd.Flags().GetString("zone")
serviceprovider, _ := cmd.Flags().GetString("serviceprovider")
comment, _ := cmd.Flags().GetString("comment")

if dnsapi.CheckEmpty(ip, "ip address", "-i|--ip 123.123.123.123") ||
dnsapi.CheckEmpty(domain, "domain", "-d|--domain test.domain.tld") {
Expand All @@ -44,7 +45,7 @@ var addRecordCmd = &cobra.Command{

} else {

dnsapi.AddRecord(zoneID, token, domain, rtype, ip, proxied)
dnsapi.AddRecord(zoneID, token, domain, rtype, ip, proxied, comment)

resp, recordID, err := dnsapi.GetRecordId(zoneID, token, domain)
if resp {
Expand Down
4 changes: 2 additions & 2 deletions cmd/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var batchCmd = &cobra.Command{

if dnsconfig.Batch.Provider == "cloudflare" {

dnsapi.AddRecord(zoneID, token, domain, dnsconfig.Batch.Rtype, dnsconfig.Batch.IP, dnsconfig.Batch.Proxied)
dnsapi.AddRecord(zoneID, token, domain, dnsconfig.Batch.Rtype, dnsconfig.Batch.IP, dnsconfig.Batch.Proxied, dnsconfig.Batch.Comment)

} else if dnsconfig.Batch.Provider == "bind" {

Expand Down Expand Up @@ -64,7 +64,7 @@ var batchCmd = &cobra.Command{

if dnsconfig.Batch.Provider == "cloudflare" {

dnsapi.UpdateRecord(zoneID, token, domain, dnsconfig.Batch.Rtype, dnsconfig.Batch.IP, dnsconfig.Batch.Proxied)
dnsapi.UpdateRecord(zoneID, token, domain, dnsconfig.Batch.Rtype, dnsconfig.Batch.IP, dnsconfig.Batch.Proxied, dnsconfig.Batch.Comment)

} else if dnsconfig.Batch.Provider == "bind" {

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ func init() {
rootCmd.PersistentFlags().BoolP("proxied", "p", false, "Record type (A,TXT,CNAME, ...)")
rootCmd.PersistentFlags().StringVarP(&config, "config", "c", "", "config.yaml")
rootCmd.PersistentFlags().StringP("serviceprovider", "s", "", "Service Provider (Cloudflare, bind)")
rootCmd.PersistentFlags().StringP("textcomment", "t", "", "Comment")

}
3 changes: 2 additions & 1 deletion cmd/updateRecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var updateRecordCmd = &cobra.Command{
proxied, _ := cmd.Flags().GetBool("proxied")
zone, _ := cmd.Flags().GetString("zone")
serviceprovider, _ := cmd.Flags().GetString("serviceprovider")
comment, _ := cmd.Flags().GetString("comment")

if dnsapi.CheckEmpty(ip, "ip address", "-i|--ip 123.123.123.123") ||
dnsapi.CheckEmpty(domain, "domain", "-d|--domain test.domain.tld") {
Expand All @@ -42,7 +43,7 @@ var updateRecordCmd = &cobra.Command{
zoneID := dnsconfig.Cloudflare.ZoneId
token := dnsconfig.Cloudflare.Token

dnsapi.UpdateRecord(zoneID, token, domain, rtype, ip, proxied)
dnsapi.UpdateRecord(zoneID, token, domain, rtype, ip, proxied, comment)

resp, recordID, err := dnsapi.GetRecordId(zoneID, token, domain)

Expand Down
6 changes: 4 additions & 2 deletions dnsapi/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
)

func AddRecord(zoneID string, token string, domain string, rtype string, ip string, proxied bool) (string, error) {
func AddRecord(zoneID string, token string, domain string, rtype string, ip string, proxied bool, comment string) (string, error) {

var msg = ""
url := fmt.Sprintf("https://api.cloudflare.com/client/v4/zones/%s/dns_records", zoneID)
Expand All @@ -19,6 +19,7 @@ func AddRecord(zoneID string, token string, domain string, rtype string, ip stri
Content: ip,
TTL: 1,
Proxied: proxied,
Comment: comment,
}

jsonData, err := json.Marshal(dnsRecord)
Expand Down Expand Up @@ -53,7 +54,7 @@ func AddRecord(zoneID string, token string, domain string, rtype string, ip stri
return msg, nil
}

func UpdateRecord(zoneID string, token string, domain string, rtype string, ip string, proxied bool) (string, error) {
func UpdateRecord(zoneID string, token string, domain string, rtype string, ip string, proxied bool, comment string) (string, error) {

exists, recordID, _ := GetRecordId(zoneID, token, domain)

Expand All @@ -68,6 +69,7 @@ func UpdateRecord(zoneID string, token string, domain string, rtype string, ip s
Content: ip,
TTL: 1,
Proxied: proxied,
Comment: comment,
}

jsonData, err := json.Marshal(dnsRecord)
Expand Down
2 changes: 2 additions & 0 deletions dnsapi/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DNSRecord struct {
Content string `json:"content"` // IP-Adresse oder Zielinhalt des Records
TTL int `json:"ttl"` // Time-To-Live in Sekunden (z.B. 1 für "Auto")
Proxied bool `json:"proxied"` // Ob der Record über Cloudflare geleitet werden soll
Comment string `json:"comment,omitempty"`
}

type Config struct {
Expand All @@ -44,5 +45,6 @@ type Config struct {
Proxied bool `yaml:"proxied"`
Rtype string `yaml:"rtype"`
Domains []string `yaml:"domains"`
Comment string `yaml:"comment"`
}
}

0 comments on commit fea54dc

Please sign in to comment.