-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
39 lines (33 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"flag"
"fmt"
"os"
)
func main() {
fmt.Println("Namecheap Dynamic DNS client Version", version)
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")
password := flag.String("password", "", "Dynamic DNS Password from Namecheap")
// iPCacheTimeOutSeconds := flag.Int("ip-cache-timeout", 86400, "IP cache timeout in seconds.")
flag.Parse()
if *domain == "" || *host == "" || *password == "" {
fmt.Println("ERROR domain, host and Dynamic DDNS password are mandatory")
fmt.Printf("\nUsage of %s:\n", os.Args[1])
flag.PrintDefaults()
os.Exit(1)
}
pubIp, err := getPubIP()
if err != nil {
DDNSLogger(ErrorLog, *host, *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)
}
}
updateRecord(*domain, *host, *password)
}