From 9667a03e323445cb9b4038d0b8818c2fb95ffdf2 Mon Sep 17 00:00:00 2001 From: talkkonnect Date: Wed, 5 Jan 2022 06:45:42 +0000 Subject: [PATCH] version checking --- talkkonnect.go | 7 ++++++- utils.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ version.go | 2 +- xmlparser.go | 38 +----------------------------------- 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/talkkonnect.go b/talkkonnect.go index 375b255..863b958 100644 --- a/talkkonnect.go +++ b/talkkonnect.go @@ -53,7 +53,12 @@ func talkkonnectBanner(backgroundcolor string) { log.Println("info: " + backgroundcolor + "│Additional Modifications Released under MPL 2.0 License │" + backgroundreset) log.Println("info: " + backgroundcolor + "│Blog at www.talkkonnect.com, source at github.com/talkkonnect │" + backgroundreset) log.Println("info: " + backgroundcolor + "└────────────────────────────────────────────────────────────────┘" + backgroundreset) - log.Printf("info: Talkkonnect Version %v Released %v", talkkonnectVersion, talkkonnectReleased) + releasedVersion := checkGitHubVersion() + if talkkonnectVersion != releasedVersion { + log.Printf("warn: Ver %v Rel %v (Newer Ver %v Available!)\n", talkkonnectVersion, talkkonnectReleased, releasedVersion) + } else { + log.Printf("info: Ver %v Rel %v (Latest Release)\n", talkkonnectVersion, talkkonnectReleased) + } log.Printf("info: ") } diff --git a/utils.go b/utils.go index 2c5e9b4..6cb285d 100644 --- a/utils.go +++ b/utils.go @@ -37,6 +37,7 @@ import ( "encoding/hex" "fmt" "io" + "io/ioutil" "log" "math" "net" @@ -399,3 +400,55 @@ func generateHashName(name string) string { hash := md5.Sum([]byte(name)) return hex.EncodeToString(hash[:]) } + +func checkGitHubVersion() string { + + tmpfileName := "githubversion.txt" + + if FileExists(tmpfileName) { + err := os.Remove(tmpfileName) + if err != nil { + log.Println("error: Cannot Remove Version File so Cannot Check Current GitHub Version") + return talkkonnectVersion + } + } + + file, err := os.Open(tmpfileName) + + if err != nil { + defer file.Close() + url := "https://raw.githubusercontent.com/talkkonnect/talkkonnect/main/version.go" + response, err := http.Get(url) + if err != nil { + log.Println("error: Cannot Get Version from GitHub") + return talkkonnectVersion + } + defer response.Body.Close() + + output, err := os.Create(tmpfileName) + if err != nil { + log.Println("error: Cannot Create Temporary File for Version Checking") + return talkkonnectVersion + } + + _, _ = io.Copy(output, response.Body) + } + + fileContent, err := ioutil.ReadFile(tmpfileName) + if err != nil { + log.Println("error: Cannot Read Temporary File for Version Checking") + return talkkonnectVersion + } + + temp := strings.Split(string(fileContent), "\n") + + for _, item := range temp { + if checkRegex("talkkonnectVersion", item) { + regex := regexp.MustCompile(`"(.*)"`) + match := regex.FindStringSubmatch(item)[1] + return match // this will return the version found on github + } + } + + return talkkonnectVersion +} diff --git a/version.go b/version.go index 98eb2ad..30360d9 100644 --- a/version.go +++ b/version.go @@ -31,6 +31,6 @@ package talkkonnect const ( - talkkonnectVersion string = "2.07.13" + talkkonnectVersion string = "2.07.14" talkkonnectReleased string = "Jan 05 2022" ) diff --git a/xmlparser.go b/xmlparser.go index 0682730..8f2f527 100644 --- a/xmlparser.go +++ b/xmlparser.go @@ -163,14 +163,6 @@ type ConfigStruct struct { Enabled bool `xml:"enabled,attr"` ToneFrequencyHz int `xml:"tonefrequencyhz"` ToneDurationSec float32 `xml:"tonedurationsec"` - Sound struct { - Event string `xml:"event,attr"` - Tonefrequencyhz int `xml:"tonefrequencyhz,attr"` - Volume int `xml:"volume,attr"` - Tonedurationsec int `xml:"tonedurationsec,attr"` - Blocking bool `xml:"blocking,attr"` - Enabled bool `xml:"enabled,attr"` - } `xml:"sound"` } `xml:"repeatertone"` } `xml:"sounds"` TxTimeOut struct { @@ -395,18 +387,6 @@ type ConfigStruct struct { } `xml:"opengts"` } `xml:"protocol"` } `xml:"traccar"` - GPSTrackingFunction struct { - TrackEnabled bool `xml:"enabled,attr"` - TraccarSendTo bool `xml:"traccarsendto"` - TraccarServerURL string `xml:"traccarserverurl"` - TraccarServerIP string `xml:"traccarserverip"` - TraccarClientId string `xml:"traccarclientid"` - TraccarReportFrequency int64 `xml:"traccarreportfrequency"` - TraccarProto string `xml:"traccarproto"` - TraccarServerFullURL string `xml:"traccarserverfullurl"` - TrackGPSShowLCD bool `xml:"trackgpsshowlcd"` - TrackVerbose bool `xml:"trackverbose"` - } `xml:"gpstrackingfunction"` PanicFunction struct { Enabled bool `xml:"enabled,attr"` FilenameAndPath string `xml:"filenameandpath"` @@ -1098,23 +1078,6 @@ func printxmlconfig() { log.Println("info: ------------ GPS ------------------------ SKIPPED ") } - if Config.Global.Software.PrintVariables.PrintTraccar { - log.Println("info: ------------ TRACCAR Info ----------------------- ") - log.Println("info: Track Enabled " + fmt.Sprintf("%t", Config.Global.Hardware.GPSTrackingFunction.TrackEnabled)) - log.Println("info: Traccar Send To " + fmt.Sprintf("%t", Config.Global.Hardware.GPSTrackingFunction.TraccarSendTo)) - log.Println("info: Traccar Server URL ", Config.Global.Hardware.GPSTrackingFunction.TraccarServerURL) - log.Println("info: Traccar Server IP ", Config.Global.Hardware.GPSTrackingFunction.TraccarServerIP) - log.Println("info: Traccar Client ID ", Config.Global.Hardware.GPSTrackingFunction.TraccarClientId) - log.Println("info: Traccar Report Frequency " + fmt.Sprintf("%v", Config.Global.Hardware.GPSTrackingFunction.TraccarReportFrequency)) - log.Println("info: Traccar Proto ", Config.Global.Hardware.GPSTrackingFunction.TraccarProto) - log.Println("info: Traccar Server Full URL ", Config.Global.Hardware.GPSTrackingFunction.TraccarServerFullURL) - log.Println("info: Track GPS Show Lcd " + fmt.Sprintf("%t", Config.Global.Hardware.GPSTrackingFunction.TrackGPSShowLCD)) - log.Println("info: Track Verbose " + fmt.Sprintf("%t", Config.Global.Hardware.GPSTrackingFunction.TrackVerbose)) - - } else { - log.Println("info: ------------ TRACCAR Info ------------------------ SKIPPED ") - } - if Config.Global.Software.PrintVariables.PrintPanic { log.Println("info: ------------ PANIC Function -------------- ") log.Println("info: Panic Function Enable ", fmt.Sprintf("%t", Config.Global.Hardware.PanicFunction.Enabled)) @@ -1556,6 +1519,7 @@ func CheckConfigSanity(reloadxml bool) { } } } + if Warnings+Alerts > 0 { if Alerts > 0 { FatalCleanUp("alert: Fatal Errors Found In talkkonnect.xml config file please fix errors, talkkonnect stopping now!")