Add BIRDLG_TRACEROUTE_RAW option to leave traceroute output in the default format (#47)
This commit is contained in:
parent
a4e0f4c193
commit
e7f6026854
@ -136,6 +136,7 @@ Usage: all configuration is done via commandline parameters or environment varia
|
|||||||
| --bird | BIRD_SOCKET | socket file for bird, set either in parameter or environment variable BIRD_SOCKET (default "/var/run/bird/bird.ctl") |
|
| --bird | BIRD_SOCKET | socket file for bird, set either in parameter or environment variable BIRD_SOCKET (default "/var/run/bird/bird.ctl") |
|
||||||
| --listen | BIRDLG_PROXY_PORT | listen address, set either in parameter or environment variable BIRDLG_PROXY_PORT(default "8000") |
|
| --listen | BIRDLG_PROXY_PORT | listen address, set either in parameter or environment variable BIRDLG_PROXY_PORT(default "8000") |
|
||||||
| --traceroute_bin | BIRDLG_TRACEROUTE_BIN | traceroute binary file, set either in parameter or environment variable BIRDLG_TRACEROUTE_BIN(default "traceroute") |
|
| --traceroute_bin | BIRDLG_TRACEROUTE_BIN | traceroute binary file, set either in parameter or environment variable BIRDLG_TRACEROUTE_BIN(default "traceroute") |
|
||||||
|
| --traceroute_raw | BIRDLG_TRACEROUTE_RAW | whether to display traceroute outputs raw (default false) |
|
||||||
|
|
||||||
Example: start proxy with default configuration, should work "out of the box" on Debian 9 with BIRDv1:
|
Example: start proxy with default configuration, should work "out of the box" on Debian 9 with BIRDv1:
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
@ -54,6 +55,7 @@ type settingType struct {
|
|||||||
listen string
|
listen string
|
||||||
allowedIPs []string
|
allowedIPs []string
|
||||||
tr_bin string
|
tr_bin string
|
||||||
|
tr_raw bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var setting settingType
|
var setting settingType
|
||||||
@ -66,6 +68,7 @@ func main() {
|
|||||||
"8000",
|
"8000",
|
||||||
[]string{""},
|
[]string{""},
|
||||||
"traceroute",
|
"traceroute",
|
||||||
|
false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if birdSocketEnv := os.Getenv("BIRD_SOCKET"); birdSocketEnv != "" {
|
if birdSocketEnv := os.Getenv("BIRD_SOCKET"); birdSocketEnv != "" {
|
||||||
@ -83,12 +86,19 @@ func main() {
|
|||||||
if tr_binEnv := os.Getenv("BIRDLG_TRACEROUTE_BIN"); tr_binEnv != "" {
|
if tr_binEnv := os.Getenv("BIRDLG_TRACEROUTE_BIN"); tr_binEnv != "" {
|
||||||
settingDefault.tr_bin = tr_binEnv
|
settingDefault.tr_bin = tr_binEnv
|
||||||
}
|
}
|
||||||
|
if tracerouteRawEnv := os.Getenv("BIRDLG_TRACEROUTE_RAW"); tracerouteRawEnv != "" {
|
||||||
|
tracerouteRaw, err := strconv.ParseBool(tracerouteRawEnv)
|
||||||
|
if err == nil {
|
||||||
|
settingDefault.tr_raw = tracerouteRaw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Allow parameters to override environment variables
|
// Allow parameters to override environment variables
|
||||||
birdParam := flag.String("bird", settingDefault.birdSocket, "socket file for bird, set either in parameter or environment variable BIRD_SOCKET")
|
birdParam := flag.String("bird", settingDefault.birdSocket, "socket file for bird, set either in parameter or environment variable BIRD_SOCKET")
|
||||||
listenParam := flag.String("listen", settingDefault.listen, "listen address, set either in parameter or environment variable BIRDLG_PROXY_PORT")
|
listenParam := flag.String("listen", settingDefault.listen, "listen address, set either in parameter or environment variable BIRDLG_PROXY_PORT")
|
||||||
AllowedIPsParam := flag.String("allowed", strings.Join(settingDefault.allowedIPs, ","), "IPs allowed to access this proxy, separated by commas. Don't set to allow all IPs.")
|
AllowedIPsParam := flag.String("allowed", strings.Join(settingDefault.allowedIPs, ","), "IPs allowed to access this proxy, separated by commas. Don't set to allow all IPs.")
|
||||||
tr_binParam := flag.String("traceroute_bin", settingDefault.tr_bin, "traceroute binary file, set either in parameter or environment variable BIRDLG_TRACEROUTE_BIN")
|
tr_binParam := flag.String("traceroute_bin", settingDefault.tr_bin, "traceroute binary file, set either in parameter or environment variable BIRDLG_TRACEROUTE_BIN")
|
||||||
|
tr_rawParam := flag.Bool("traceroute_raw", settingDefault.tr_raw, "whether to display traceroute outputs raw; set via parameter or environment variable BIRDLG_TRACEROUTE_RAW")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if !strings.Contains(*listenParam, ":") {
|
if !strings.Contains(*listenParam, ":") {
|
||||||
@ -100,6 +110,7 @@ func main() {
|
|||||||
setting.listen = *listenParam
|
setting.listen = *listenParam
|
||||||
setting.allowedIPs = strings.Split(*AllowedIPsParam, ",")
|
setting.allowedIPs = strings.Split(*AllowedIPsParam, ",")
|
||||||
setting.tr_bin = *tr_binParam
|
setting.tr_bin = *tr_binParam
|
||||||
|
setting.tr_raw = *tr_rawParam
|
||||||
|
|
||||||
// Start HTTP server
|
// Start HTTP server
|
||||||
http.HandleFunc("/", invalidHandler)
|
http.HandleFunc("/", invalidHandler)
|
||||||
|
@ -81,14 +81,18 @@ func tracerouteHandler(httpW http.ResponseWriter, httpR *http.Request) {
|
|||||||
httpW.Write([]byte(errString))
|
httpW.Write([]byte(errString))
|
||||||
}
|
}
|
||||||
if result != nil {
|
if result != nil {
|
||||||
errString = string(result)
|
if setting.tr_raw {
|
||||||
errString = regexp.MustCompile(`(?m)^\s*(\d*)\s*\*\n`).ReplaceAllStringFunc(errString, func(w string) string {
|
httpW.Write(result)
|
||||||
skippedCounter++
|
} else {
|
||||||
return ""
|
errString = string(result)
|
||||||
})
|
errString = regexp.MustCompile(`(?m)^\s*(\d*)\s*\*\n`).ReplaceAllStringFunc(errString, func(w string) string {
|
||||||
httpW.Write([]byte(strings.TrimSpace(errString)))
|
skippedCounter++
|
||||||
if skippedCounter > 0 {
|
return ""
|
||||||
httpW.Write([]byte("\n\n" + strconv.Itoa(skippedCounter) + " hops not responding."))
|
})
|
||||||
|
httpW.Write([]byte(strings.TrimSpace(errString)))
|
||||||
|
if skippedCounter > 0 {
|
||||||
|
httpW.Write([]byte("\n\n" + strconv.Itoa(skippedCounter) + " hops not responding."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user