1. support local whois. 2 add some useful bird command (#59)
This commit is contained in:
parent
890ab51b07
commit
5ce0f55f35
@ -66,7 +66,7 @@ Configuration is handled by [viper](https://github.com/spf13/viper), any config
|
||||
| domain | --domain | BIRDLG_DOMAIN | server name domain suffixes |
|
||||
| listen | --listen | BIRDLG_LISTEN | address bird-lg is listening on (default "5000") |
|
||||
| proxy_port | --proxy-port | BIRDLG_PROXY_PORT | port bird-lgproxy is running on (default 8000) |
|
||||
| whois | --whois | BIRDLG_WHOIS | whois server for queries (default "whois.verisign-grs.com") |
|
||||
| whois | --whois | BIRDLG_WHOIS | whois server for queries (default "whois.verisign-grs.com"). Start with "/" to spacify local whois binary("/usr/local/whois"). |
|
||||
| dns_interface | --dns-interface | BIRDLG_DNS_INTERFACE | dns zone to query ASN information (default "asn.cymru.com") |
|
||||
| bgpmap_info | --bgpmap-info | BIRDLG_BGPMAP_INFO | the infos displayed in bgpmap, separated by comma, start with `:` means allow multiline (default "asn,as-name,ASName,descr") |
|
||||
| title_brand | --title-brand | BIRDLG_TITLE_BRAND | prefix of page titles in browser tabs (default "Bird-lg Go") |
|
||||
|
@ -13,18 +13,26 @@ import (
|
||||
|
||||
// static options map
|
||||
var optionsMap = map[string]string{
|
||||
"summary": "show protocols",
|
||||
"detail": "show protocols all",
|
||||
"route": "show route for ...",
|
||||
"route_all": "show route for ... all",
|
||||
"route_bgpmap": "show route for ... (bgpmap)",
|
||||
"route_where": "show route where net ~ [ ... ]",
|
||||
"route_where_all": "show route where net ~ [ ... ] all",
|
||||
"route_where_bgpmap": "show route where net ~ [ ... ] (bgpmap)",
|
||||
"route_generic": "show route ...",
|
||||
"generic": "show ...",
|
||||
"whois": "whois ...",
|
||||
"traceroute": "traceroute ...",
|
||||
"summary": "show protocols",
|
||||
"detail": "show protocols all ...",
|
||||
"route_from_protocol": "show route protocol ...",
|
||||
"route_from_protocol_all": "show route protocol ... all",
|
||||
"route_from_protocol_all_primary": "show route protocol ... all primary",
|
||||
"route_filtered_from_protocol": "show route filtered protocol ...",
|
||||
"route_filtered_from_protocol_all": "show route filtered protocol ... all",
|
||||
"route_from_origin": "show route where bgp_path.last = ...",
|
||||
"route_from_origin_all": "show route where bgp_path.last = ... all",
|
||||
"route_from_origin_all_primary": "show route where bgp_path.last = ... all primary",
|
||||
"route": "show route for ...",
|
||||
"route_all": "show route for ... all",
|
||||
"route_bgpmap": "show route for ... (bgpmap)",
|
||||
"route_where": "show route where net ~ [ ... ]",
|
||||
"route_where_all": "show route where net ~ [ ... ] all",
|
||||
"route_where_bgpmap": "show route where net ~ [ ... ] (bgpmap)",
|
||||
"route_generic": "show route ...",
|
||||
"generic": "show ...",
|
||||
"whois": "whois ...",
|
||||
"traceroute": "traceroute ...",
|
||||
}
|
||||
|
||||
// pre-compiled regexp and constant statemap for summary rendering
|
||||
|
@ -17,15 +17,26 @@ import (
|
||||
)
|
||||
|
||||
var primitiveMap = map[string]string{
|
||||
"summary": "show protocols",
|
||||
"detail": "show protocols all %s",
|
||||
"route": "show route for %s",
|
||||
"route_all": "show route for %s all",
|
||||
"route_where": "show route where net ~ [ %s ]",
|
||||
"route_where_all": "show route where net ~ [ %s ] all",
|
||||
"route_generic": "show route %s",
|
||||
"generic": "show %s",
|
||||
"traceroute": "%s",
|
||||
"summary": "show protocols",
|
||||
"detail": "show protocols all %s",
|
||||
"route_from_protocol": "show route protocol %s",
|
||||
"route_from_protocol_all": "show route protocol %s all",
|
||||
"route_from_protocol_primary": "show route protocol %s primary",
|
||||
"route_from_protocol_all_primary": "show route protocol %s all primary",
|
||||
"route_filtered_from_protocol": "show route filtered protocol %s",
|
||||
"route_filtered_from_protocol_all": "show route filtered protocol %s all",
|
||||
"route_from_origin": "show route where bgp_path.last = %s",
|
||||
"route_from_origin_all": "show route where bgp_path.last = %s all",
|
||||
"route_from_origin_primary": "show route where bgp_path.last = %s primary",
|
||||
"route_from_origin_all_primary": "show route where bgp_path.last = %s all primary",
|
||||
"route": "show route for %s",
|
||||
"route_all": "show route for %s all",
|
||||
"route_where": "show route where net ~ [ %s ]",
|
||||
"route_where_all": "show route where net ~ [ %s ] all",
|
||||
"route_generic": "show route %s",
|
||||
"generic": "show %s",
|
||||
"whois": "%s",
|
||||
"traceroute": "%s",
|
||||
}
|
||||
|
||||
// serve up a generic error
|
||||
@ -204,6 +215,16 @@ func webServerStart(l net.Listener) {
|
||||
// backend routes
|
||||
http.HandleFunc("/summary/", webBackendCommunicator("bird", "summary"))
|
||||
http.HandleFunc("/detail/", webBackendCommunicator("bird", "detail"))
|
||||
http.HandleFunc("/route_filtered_from_protocol/", webBackendCommunicator("bird", "route_filtered_from_protocol"))
|
||||
http.HandleFunc("/route_filtered_from_protocol_all/", webBackendCommunicator("bird", "route_filtered_from_protocol_all"))
|
||||
http.HandleFunc("/route_from_protocol/", webBackendCommunicator("bird", "route_from_protocol"))
|
||||
http.HandleFunc("/route_from_protocol_all/", webBackendCommunicator("bird", "route_from_protocol_all"))
|
||||
http.HandleFunc("/route_from_protocol_primary/", webBackendCommunicator("bird", "route_from_protocol_primary"))
|
||||
http.HandleFunc("/route_from_protocol_all_primary/", webBackendCommunicator("bird", "route_from_protocol_all_primary"))
|
||||
http.HandleFunc("/route_from_origin/", webBackendCommunicator("bird", "route_from_origin"))
|
||||
http.HandleFunc("/route_from_origin_all/", webBackendCommunicator("bird", "route_from_origin_all"))
|
||||
http.HandleFunc("/route_from_origin_primary/", webBackendCommunicator("bird", "route_from_origin_primary"))
|
||||
http.HandleFunc("/route_from_origin_all_primary/", webBackendCommunicator("bird", "route_from_origin_all_primary"))
|
||||
http.HandleFunc("/route/", webBackendCommunicator("bird", "route"))
|
||||
http.HandleFunc("/route_all/", webBackendCommunicator("bird", "route_all"))
|
||||
http.HandleFunc("/route_bgpmap/", webHandlerBGPMap("bird", "route_bgpmap"))
|
||||
|
@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -12,18 +14,31 @@ func whois(s string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
conn, err := net.DialTimeout("tcp", setting.whoisServer+":43", 5*time.Second)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
defer conn.Close()
|
||||
if strings.HasPrefix(setting.whoisServer, "/") {
|
||||
cmd := exec.Command(setting.whoisServer, s)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
if len(output) > 65535 {
|
||||
output = output[:65535]
|
||||
}
|
||||
return string(output)
|
||||
} else {
|
||||
buf := make([]byte, 65536)
|
||||
conn, err := net.DialTimeout("tcp", setting.whoisServer+":43", 5*time.Second)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
conn.Write([]byte(s + "\r\n"))
|
||||
conn.Write([]byte(s + "\r\n"))
|
||||
|
||||
buf := make([]byte, 65536)
|
||||
n, err := io.ReadFull(conn, buf)
|
||||
if err != nil && err != io.ErrUnexpectedEOF {
|
||||
return err.Error()
|
||||
n, err := io.ReadFull(conn, buf)
|
||||
if err != nil && err != io.ErrUnexpectedEOF {
|
||||
return err.Error()
|
||||
}
|
||||
return string(buf[:n])
|
||||
}
|
||||
return string(buf[:n])
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user