Compare commits

..

No commits in common. "54e087b2e1be5978a1744dedc3d3da965950cfb5" and "bf8a95bf2160a9b8e2f4a0757d925d58511a4605" have entirely different histories.

8 changed files with 6 additions and 92 deletions

Binary file not shown.

View File

@ -1,47 +0,0 @@
package main
import (
"fmt"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Gotify struct {
URL string `yaml:"url"`
Token string `yanl:"token"`
} `yaml:"gotify"`
Cluster struct {
Host string `yaml:"host"`
Call string `yaml:"call"`
} `yaml:"cluster"`
}
func NewConfig(configPath string) (*Config, error) {
config := &Config{}
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()
d := yaml.NewDecoder(file)
if err := d.Decode(&config); err != nil {
return nil, err
}
return config, nil
}
func ValidateConfigPath(path string) error {
s, err := os.Stat(path)
if err != nil {
return err
}
if s.IsDir() {
return fmt.Errorf("'%s' is a directory, not a normal file", path)
}
return nil
}

View File

@ -3,5 +3,5 @@ gotify:
token: ALaGS4MVMWTEMcP
cluster:
host: arc.jg1vgx.net:7000
host: dxc.nc7j.com:23
call: XV9Q

2
go.mod
View File

@ -1,5 +1,3 @@
module gitea.rouggy.com/PushDXCluster
go 1.21.4
require gopkg.in/yaml.v2 v2.4.0

4
go.sum
View File

@ -1,4 +0,0 @@
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=

43
main.go
View File

@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"log"
@ -34,26 +33,6 @@ 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"`
@ -78,7 +57,7 @@ func readDXExpeFile(filename string) string {
}
// Function to send message to Gotify
func sendToGotify(title string, sMess ClusterMessage, priority int, cfg Config) {
func sendToGotify(title string, sMess ClusterMessage, priority int) {
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)
@ -94,13 +73,13 @@ func sendToGotify(title string, sMess ClusterMessage, priority int, cfg Config)
return
}
req, err := http.NewRequest("POST", cfg.Gotify.URL, bytes.NewBuffer(jsonData))
req, err := http.NewRequest("POST", gotifyURL, 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 "+cfg.Gotify.Token)
req.Header.Add("Authorization", "Bearer ALaGS4MVMWTEMcP")
client := &http.Client{}
resp, err := client.Do(req)
@ -146,22 +125,10 @@ 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", cfg.Cluster.Host)
conn, err := net.Dial("tcp", "ve7cc.net:23")
if err != nil {
log.Printf("Failed to connect to Telnet server: %v", err)
time.Sleep(5 * time.Second) // Wait before retrying
@ -220,7 +187,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, *cfg)
sendToGotify("Spot", sMess, 5)
}
}

Binary file not shown.

Binary file not shown.