diff --git a/README.md b/README.md index 595caec..86c092c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ If your server do not have static IP, i.e. When Public IP of your server / route * Copy the Dynamic DNS password which is generated after enabling Dynamic DNS. Keep it safe and handy. -* Add a record of type `A + Dynamic DNS` with required host name. +* Add a record of type `A + Dynamic DNS` with required host name(s). * Install docker on server. @@ -37,7 +37,7 @@ docker run --name server.example.com -d --restart unless-stopped -e NC_HOST='ser ``` Here, -`NC_HOST` is host name added in Namecheap record. +`NC_HOST` are the host name(s) added in the Namecheap record, seperated by a comma. `NC_DOMAIN` is your domain name. diff --git a/logger.go b/logger.go index 6911288..ce9084f 100644 --- a/logger.go +++ b/logger.go @@ -12,7 +12,7 @@ const ( WarningLog string = "WARN" ) -func DDNSLogger(logType, host, domain, message string) { +func DDNSLogger(logType, hosts, domain, message string) { var ( StdoutInfoLogger *log.Logger @@ -25,12 +25,12 @@ func DDNSLogger(logType, host, domain, message string) { StdoutErrorLogger = log.New(os.Stdout, "ERROR ", log.Ldate|log.Ltime) if logType == "INFO" { - StdoutInfoLogger.Println(host+"."+domain, message) + StdoutInfoLogger.Println(hosts+"."+domain, message) } else if logType == "WARN" { - StdoutWarningLogger.Println(host+"."+domain, message) + StdoutWarningLogger.Println(hosts+"."+domain, message) } else if logType == "ERROR" { - StdoutErrorLogger.Println(host+"."+domain, message) + StdoutErrorLogger.Println(hosts+"."+domain, message) } else { - fmt.Println(host+"."+domain, message) + fmt.Println(hosts+"."+domain, message) } } diff --git a/main.go b/main.go index b0fce75..6251b7f 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "strings" ) func main() { @@ -11,11 +12,11 @@ func main() { fmt.Println("Git Repo:", gitrepo) domain := flag.String("domain", "", "Domain name e.g. example.com") - host := flag.String("host", "", "Subdomain or hostname e.g. www") + hosts := flag.String("host", "", "Subdomain or hostname e.g. www") password := flag.String("password", "", "Dynamic DNS Password from Namecheap") flag.Parse() - if *domain == "" || *host == "" || *password == "" { + if *domain == "" || *hosts == "" || *password == "" { fmt.Println("ERROR domain, host and Dynamic DDNS password are mandatory") fmt.Printf("\nUsage of %s:\n", os.Args[1]) flag.PrintDefaults() @@ -24,15 +25,18 @@ func main() { pubIp, err := getPubIP() if err != nil { - DDNSLogger(ErrorLog, *host, *domain, err.Error()) + DDNSLogger(ErrorLog, *hosts, *domain, err.Error()) } else { - if err = setDNSRecord(*host, *domain, *password, pubIp); err != nil { - DDNSLogger(ErrorLog, *host, *domain, err.Error()) - DDNSLogger(WarningLog, *host, *domain, "Ignoring above error. If this is not right, Re-run the process after fixing the error") - } else { - DDNSLogger(InformationLog, *host, *domain, "Record updated. "+pubIp) + DDNSLogger(InformationLog, *hosts, *domain, "Updating all hosts.") + for _, host := range strings.Split(*hosts, ",") { + if err = setDNSRecord(host, *domain, *password, pubIp); err != nil { + DDNSLogger(ErrorLog, *hosts, *domain, err.Error()) + DDNSLogger(WarningLog, *hosts, *domain, "Above error occured while updating host " + host + ", ignoring. If this is not right, Re-run the process after fixing the error") + } else { + DDNSLogger(InformationLog, *hosts, *domain, "Record for " + host + " updated. "+pubIp) + } } } - updateRecord(*domain, *host, *password) + updateRecord(*domain, *hosts, *password) }