diff --git a/PushDXCluster.exe b/PushDXCluster.exe new file mode 100644 index 0000000..9c98839 Binary files /dev/null and b/PushDXCluster.exe differ diff --git a/config.yml b/config.yml index b1088a0..5768b85 100644 --- a/config.yml +++ b/config.yml @@ -3,5 +3,5 @@ gotify: token: ALaGS4MVMWTEMcP cluster: - host: dxc.nc7j.com:23 + host: arc.jg1vgx.net:7000 call: XV9Q \ No newline at end of file diff --git a/go.mod b/go.mod index 5475d55..757365c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module gitea.rouggy.com/PushDXCluster go 1.21.4 + +require gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..dd0bc19 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/main.go b/main.go index 9171ed2..a9dee33 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "encoding/json" + "flag" "fmt" "io" "log" @@ -33,6 +34,26 @@ type ClusterMessage struct { Time string } +func ParseFlags() (string, error) { + // String that contains the configured configuration path + var configPath string + + // Set up a CLI flag called "-config" to allow users + // to supply the configuration file + flag.StringVar(&configPath, "config", "./config.yml", "path to config file") + + // Actually parse the flags + flag.Parse() + + // Validate the path first + if err := ValidateConfigPath(configPath); err != nil { + return "", err + } + + // Return the configuration path + return configPath, nil +} + // Message structure for Gotify type GotifyMessage struct { Title string `json:"title"` @@ -57,7 +78,7 @@ func readDXExpeFile(filename string) string { } // Function to send message to Gotify -func sendToGotify(title string, sMess ClusterMessage, priority int) { +func sendToGotify(title string, sMess ClusterMessage, priority int, cfg Config) { message := fmt.Sprintf("DX: %s\nFrom: %s\nFreq: %s\nMode: %s\nReport: %s\nTime: %s", sMess.DX, sMess.From, sMess.Freq, sMess.Mode, sMess.Report, sMess.Time) @@ -73,13 +94,13 @@ func sendToGotify(title string, sMess ClusterMessage, priority int) { return } - req, err := http.NewRequest("POST", gotifyURL, bytes.NewBuffer(jsonData)) + req, err := http.NewRequest("POST", cfg.Gotify.URL, bytes.NewBuffer(jsonData)) if err != nil { log.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") - req.Header.Add("Authorization", "Bearer ALaGS4MVMWTEMcP") + req.Header.Add("Authorization", "Bearer "+cfg.Gotify.Token) client := &http.Client{} resp, err := client.Do(req) @@ -125,10 +146,22 @@ func SanitizeClusterMessage(message string) ClusterMessage { } func main() { + + // Generate our config based on the config supplied + // by the user in the flags + cfgPath, err := ParseFlags() + if err != nil { + log.Fatal(err) + } + cfg, err := NewConfig(cfgPath) + if err != nil { + log.Fatal(err) + } + fmt.Println("PushDXCluster v0.1") for { // Connect to the Telnet server - conn, err := net.Dial("tcp", "ve7cc.net:23") + conn, err := net.Dial("tcp", cfg.Cluster.Host) if err != nil { log.Printf("Failed to connect to Telnet server: %v", err) time.Sleep(5 * time.Second) // Wait before retrying @@ -187,7 +220,7 @@ func main() { sMess := SanitizeClusterMessage(message) log.Printf("Received message: %s", message) if sMess.DX != "" && sMess.From == "XV9Q" && strings.Contains(DX, sMess.DX) { - sendToGotify("Spot", sMess, 5) + sendToGotify("Spot", sMess, 5, *cfg) } } diff --git a/rsrc_windows_386.syso b/rsrc_windows_386.syso new file mode 100644 index 0000000..9530d70 Binary files /dev/null and b/rsrc_windows_386.syso differ diff --git a/rsrc_windows_amd64.syso b/rsrc_windows_amd64.syso new file mode 100644 index 0000000..76c7daa Binary files /dev/null and b/rsrc_windows_amd64.syso differ