Compare commits
17 Commits
54e087b2e1
...
main
Author | SHA1 | Date | |
---|---|---|---|
115051d463 | |||
9a03f3d4c6 | |||
bd1b8da2f7 | |||
a394767832 | |||
f424633083 | |||
a39dadce1a | |||
2d392d8033 | |||
b680af776e | |||
6bb76d73a1 | |||
80a882c411 | |||
acde3434dd | |||
45a73d45b9 | |||
5bac8fd4d2 | |||
9e72764c2a | |||
6d8d69deeb | |||
0892078851 | |||
28e606c414 |
Binary file not shown.
@ -17,6 +17,10 @@ type Config struct {
|
||||
Host string `yaml:"host"`
|
||||
Call string `yaml:"call"`
|
||||
} `yaml:"cluster"`
|
||||
|
||||
Log struct {
|
||||
SQLitePath string `yaml:"sqlitePath"`
|
||||
} `yaml:"log"`
|
||||
}
|
||||
|
||||
func NewConfig(configPath string) (*Config, error) {
|
||||
|
@ -3,5 +3,8 @@ gotify:
|
||||
token: ALaGS4MVMWTEMcP
|
||||
|
||||
cluster:
|
||||
host: arc.jg1vgx.net:7000
|
||||
call: XV9Q
|
||||
host: dxc.k0xm.net:7300
|
||||
call: F4BPO
|
||||
|
||||
log:
|
||||
sqlitePath: "C:\\Perso\\Seafile\\Radio\\Logs\\Log4OM\\Vietnam.SQLite"
|
2
dx.txt
2
dx.txt
@ -1 +1 @@
|
||||
8P9CB ZC4GW TM5FI 3A/LB3LJ VP2V/W5GI VP9/AB2E 8Q7KR FT4GL 8Q7KB 5W1SA TF2MSN FW1JG CO8BLY PZ5RA OD5KU
|
||||
TF2MSN T32AZ DT0IP YN2RP KH8T 9J2AO XT2AW 6O3T 5H1WX 5H3MB CR3W A25AO 5W1SA
|
107
main.go
107
main.go
@ -16,13 +16,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
telnetAddress = "dxc.nc7j.com:23" // Remplace par l'adresse et le port de ton serveur Telnet
|
||||
gotifyURL = "https://gotify.rouggy.com/message" // Remplace par l'URL de ton serveur Gotify
|
||||
gotifyToken = "ALaGS4MVMWTEMcP" // Remplace par le token de ton application Gotify
|
||||
identificationMessage = "XV9Q" // Message d'identification à envoyer au serveur Telnet
|
||||
)
|
||||
|
||||
var DX = readDXExpeFile("dx.txt")
|
||||
|
||||
type ClusterMessage struct {
|
||||
@ -73,7 +66,7 @@ func readDXExpeFile(filename string) string {
|
||||
if err != nil {
|
||||
fmt.Println("Error while reading the file", err)
|
||||
}
|
||||
log.Println("DX Expe file has been loaded properly")
|
||||
log.Printf("DX Expe file has been loaded properly with following calls: %s", content)
|
||||
return string(content)
|
||||
}
|
||||
|
||||
@ -119,7 +112,7 @@ func sendToGotify(title string, sMess ClusterMessage, priority int, cfg Config)
|
||||
}
|
||||
|
||||
func SanitizeClusterMessage(message string) ClusterMessage {
|
||||
r := regexp.MustCompile(`DX\sde\s([A-Z0-9]+)[-#:]+[\s]+([0-9]+.[0-9])[\s]+([^\s]+)[\s]+([A-Z]+[0-9])\s+(.*dB).*(.{4})Z$`)
|
||||
r := regexp.MustCompile(`DX\sde\s([A-Z0-9]+)[-#:]+[\s]+([0-9]+.[0-9])[\s]+([^\s]+)[\s]+(\bFT8\b|\bFT4\b|\bCW\b)+\s+(.*dB).*(.{4})Z$`)
|
||||
matches := r.FindStringSubmatch(message)
|
||||
|
||||
mes := ClusterMessage{}
|
||||
@ -141,10 +134,30 @@ func SanitizeClusterMessage(message string) ClusterMessage {
|
||||
|
||||
return mes
|
||||
}
|
||||
|
||||
return mes
|
||||
}
|
||||
|
||||
func sendTelnetMessage(conn net.Conn, message string) {
|
||||
if !strings.HasPrefix(message, "F4BPO") {
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
_, err := conn.Write([]byte(message + "\n"))
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
time.Sleep(5 * time.Second) // Wait before retrying
|
||||
}
|
||||
}
|
||||
|
||||
func sendFilters(conn net.Conn) {
|
||||
go sendTelnetMessage(conn, "set/ft8")
|
||||
time.Sleep(1 * time.Second)
|
||||
go sendTelnetMessage(conn, "SET/FILTER DOC/PASS F")
|
||||
time.Sleep(1 * time.Second)
|
||||
go sendTelnetMessage(conn, "set/skimmer")
|
||||
time.Sleep(1 * time.Second)
|
||||
go sendTelnetMessage(conn, "set/ft4")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Generate our config based on the config supplied
|
||||
@ -158,52 +171,21 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
login := false
|
||||
filters_sent := false
|
||||
|
||||
fmt.Println("PushDXCluster v0.1")
|
||||
for {
|
||||
// Connect to the Telnet server
|
||||
conn, err := net.Dial("tcp", cfg.Cluster.Host)
|
||||
addr, err := net.ResolveTCPAddr("tcp", cfg.Cluster.Host)
|
||||
conn, err := net.DialTCP("tcp", nil, addr)
|
||||
if err != nil {
|
||||
log.Printf("Failed to connect to Telnet server: %v", err)
|
||||
time.Sleep(5 * time.Second) // Wait before retrying
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println("Connected to Telnet server")
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// Send identification message
|
||||
_, err = conn.Write([]byte(identificationMessage + "\n"))
|
||||
if err != nil {
|
||||
log.Printf("Failed to send identification message: %v", err)
|
||||
conn.Close()
|
||||
time.Sleep(5 * time.Second) // Wait before retrying
|
||||
continue
|
||||
}
|
||||
log.Println("Identification message sent")
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
_, err = conn.Write([]byte("set/ft8" + "\n"))
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to send FT8 message: %v", err)
|
||||
conn.Close()
|
||||
time.Sleep(5 * time.Second) // Wait before retrying
|
||||
continue
|
||||
}
|
||||
log.Println("Set FT8 message sent")
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
_, err = conn.Write([]byte("SET/FILTER DOC/PASS 3W" + "\n"))
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to send Filter message: %v", err)
|
||||
conn.Close()
|
||||
time.Sleep(5 * time.Second) // Wait before retrying
|
||||
continue
|
||||
}
|
||||
log.Println("Set filter Vietnam message sent")
|
||||
log.Printf("Connected to %s server", cfg.Cluster.Host)
|
||||
|
||||
// Create a buffered reader to read from the Telnet server
|
||||
reader := bufio.NewReader(conn)
|
||||
@ -211,18 +193,45 @@ func main() {
|
||||
// Loop to read from the Telnet server
|
||||
for {
|
||||
message, err := reader.ReadString('\n')
|
||||
message, _ = strings.CutSuffix(message, "\n")
|
||||
message, _ = strings.CutSuffix(message, "\r")
|
||||
if err != nil {
|
||||
log.Printf("Error reading from Telnet server: %v", err)
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
|
||||
// Trim and Sanitize spots messages
|
||||
message = strings.TrimSpace(message)
|
||||
sMess := SanitizeClusterMessage(message)
|
||||
|
||||
if sMess.DX != "" {
|
||||
log.Printf("Sanitized message: Reporter: %s, DX: %s, Freq: %s, Mode: %s, Report: %s, Time: %s", sMess.From, sMess.DX, sMess.Freq, sMess.Mode, sMess.Report, sMess.Time)
|
||||
} else {
|
||||
log.Printf("Received message: %s", message)
|
||||
if sMess.DX != "" && sMess.From == "XV9Q" && strings.Contains(DX, sMess.DX) {
|
||||
sendToGotify("Spot", sMess, 5, *cfg)
|
||||
}
|
||||
|
||||
// Send Call to ID to the Server
|
||||
if message != "" && strings.Contains("Please enter your call:", message) {
|
||||
go sendTelnetMessage(conn, "F4BPO-2")
|
||||
login = true
|
||||
}
|
||||
|
||||
if message != "" && strings.Contains("login:", message) {
|
||||
go sendTelnetMessage(conn, "F4BPO-2")
|
||||
login = true
|
||||
}
|
||||
|
||||
// Set the FT8, CW, FT4 and only spots from Vietnam filters only once
|
||||
if login && !filters_sent {
|
||||
go sendFilters(conn)
|
||||
filters_sent = true
|
||||
}
|
||||
|
||||
// If calls is in the DX List then send a Gotify notification
|
||||
if sMess.DX != "" && sMess.From == "F4BPO" && strings.Contains(DX, sMess.DX) {
|
||||
sendToGotify("Spot", sMess, 5, *cfg)
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("Disconnected from Telnet server, reconnecting...")
|
||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user