commit a06f35db9974cfc0214643625fa0bd4e188b6363 Author: Hamza Zakaria Date: Tue Mar 17 14:02:56 2026 +0100 First diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..342ae49 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +APP_NAME = DDNSUpdater +BIN_DIR = bin +VERSION = 0.1.0 + +all: build run + +build: + @if not exist $(BIN_DIR) mkdir $(BIN_DIR) + go build -ldflags "-s -w -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe . + +run: + go run . + +clean: + @if exist $(BIN_DIR) rmdir /s /q $(BIN_DIR) + +windows: + @if not exist $(BIN_DIR) mkdir $(BIN_DIR) + set GOOS=windows&& set GOARCH=amd64&& go build -o $(BIN_DIR)\$(APP_NAME).exe . + +tidy: + go mod tidy + +fmt: + go fmt ./... diff --git a/bin/DDNSUpdater.exe b/bin/DDNSUpdater.exe new file mode 100644 index 0000000..1c1302f Binary files /dev/null and b/bin/DDNSUpdater.exe differ diff --git a/config.json b/config.json new file mode 100644 index 0000000..d98571c --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "url": "https://triztech.pro/cpanelwebcall/TOKEN", + "interval_minutes": 300 +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..70dd311 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module triztech/hamza-zakaria/DDNSUpdater + +go 1.25.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..96ee82a --- /dev/null +++ b/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "os" + "time" +) + +type Config struct { + URL string `json:"url"` + IntervalMins int `json:"interval_minutes"` +} + +// read config.json +func loadConfig(path string) (*Config, error) { + file, err := ioutil.ReadFile(path) + if err != nil { + return nil, err + } + var cfg Config + err = json.Unmarshal(file, &cfg) + if err != nil { + return nil, err + } + return &cfg, nil +} + +func updateDDNS(url string) { + resp, err := http.Get(url) + if err != nil { + fmt.Println("Error calling DDNS URL:", err) + return + } + defer resp.Body.Close() + + if resp.StatusCode == http.StatusOK { + fmt.Println(time.Now(), "DDNS updated successfully") + } else { + fmt.Println(time.Now(), "Failed to update DDNS, status code:", resp.StatusCode) + } +} + +func main() { + cfg, err := loadConfig("config.json") + if err != nil { + fmt.Println("Failed to load config:", err) + os.Exit(1) + } + + ticker := time.NewTicker(time.Duration(cfg.IntervalMins) * time.Minute) + defer ticker.Stop() + + // run immediately once + updateDDNS(cfg.URL) + + for range ticker.C { + updateDDNS(cfg.URL) + } +}