up
This commit is contained in:
parent
8d5d5ca34a
commit
54e087b2e1
BIN
PushDXCluster.exe
Normal file
BIN
PushDXCluster.exe
Normal file
Binary file not shown.
@ -3,5 +3,5 @@ gotify:
|
||||
token: ALaGS4MVMWTEMcP
|
||||
|
||||
cluster:
|
||||
host: dxc.nc7j.com:23
|
||||
host: arc.jg1vgx.net:7000
|
||||
call: XV9Q
|
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module gitea.rouggy.com/PushDXCluster
|
||||
|
||||
go 1.21.4
|
||||
|
||||
require gopkg.in/yaml.v2 v2.4.0
|
||||
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
43
main.go
43
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
rsrc_windows_386.syso
Normal file
BIN
rsrc_windows_386.syso
Normal file
Binary file not shown.
BIN
rsrc_windows_amd64.syso
Normal file
BIN
rsrc_windows_amd64.syso
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user