Skip to content

Commit

Permalink
version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jan 5, 2022
1 parent 7f48b84 commit 9667a03
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 39 deletions.
7 changes: 6 additions & 1 deletion talkkonnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
}

Expand Down
53 changes: 53 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"net"
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
package talkkonnect

const (
talkkonnectVersion string = "2.07.13"
talkkonnectVersion string = "2.07.14"
talkkonnectReleased string = "Jan 05 2022"
)
38 changes: 1 addition & 37 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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!")
Expand Down

0 comments on commit 9667a03

Please sign in to comment.