Add BIRDLG_TRACEROUTE_RAW option to leave traceroute output in the default format (#47)

This commit is contained in:
James Lu
2022-01-08 22:14:31 -08:00
committed by GitHub
parent a4e0f4c193
commit e7f6026854
3 changed files with 24 additions and 8 deletions

View File

@@ -81,14 +81,18 @@ func tracerouteHandler(httpW http.ResponseWriter, httpR *http.Request) {
httpW.Write([]byte(errString))
}
if result != nil {
errString = string(result)
errString = regexp.MustCompile(`(?m)^\s*(\d*)\s*\*\n`).ReplaceAllStringFunc(errString, func(w string) string {
skippedCounter++
return ""
})
httpW.Write([]byte(strings.TrimSpace(errString)))
if skippedCounter > 0 {
httpW.Write([]byte("\n\n" + strconv.Itoa(skippedCounter) + " hops not responding."))
if setting.tr_raw {
httpW.Write(result)
} else {
errString = string(result)
errString = regexp.MustCompile(`(?m)^\s*(\d*)\s*\*\n`).ReplaceAllStringFunc(errString, func(w string) string {
skippedCounter++
return ""
})
httpW.Write([]byte(strings.TrimSpace(errString)))
if skippedCounter > 0 {
httpW.Write([]byte("\n\n" + strconv.Itoa(skippedCounter) + " hops not responding."))
}
}
}
}