Add DN42 specific whois handling
This commit is contained in:
parent
5157f64f9d
commit
abd0eda45b
47
frontend/dn42.go
Normal file
47
frontend/dn42.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dn42WhoisFilter(whois string) string {
|
||||||
|
commandResult := ""
|
||||||
|
isNextSection := false
|
||||||
|
skippedLines := 0
|
||||||
|
|
||||||
|
// Filter out some long (and useless) keys
|
||||||
|
filteredPrefix := []string{
|
||||||
|
"descr:", "remarks:", "ds-rdata:", "auth:", "country:",
|
||||||
|
"nserver:", "status:", "pgp-fingerprint:", "mp-import:", "mp-export:",
|
||||||
|
"members:", "key:", "inetnum:", "inet6num:", "%",
|
||||||
|
}
|
||||||
|
for _, s := range strings.Split(whois, "\n") {
|
||||||
|
if len(s) == 0 {
|
||||||
|
// This line is a separation between parts of results
|
||||||
|
// Only keep last part of result
|
||||||
|
isNextSection = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
shouldSkip := false
|
||||||
|
for _, filtered := range filteredPrefix {
|
||||||
|
if strings.HasPrefix(s, filtered) {
|
||||||
|
shouldSkip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if shouldSkip {
|
||||||
|
skippedLines++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if isNextSection {
|
||||||
|
isNextSection = false
|
||||||
|
skippedLines = 0
|
||||||
|
commandResult = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
commandResult += s + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return commandResult + fmt.Sprintf("\n%d line(s) skipped.\n", skippedLines)
|
||||||
|
}
|
@ -14,6 +14,7 @@ type settingType struct {
|
|||||||
whoisServer string
|
whoisServer string
|
||||||
listen string
|
listen string
|
||||||
dnsInterface string
|
dnsInterface string
|
||||||
|
netSpecificMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
var setting settingType
|
var setting settingType
|
||||||
@ -26,6 +27,7 @@ func main() {
|
|||||||
"whois.verisign-grs.com",
|
"whois.verisign-grs.com",
|
||||||
":5000",
|
":5000",
|
||||||
"asn.cymru.com",
|
"asn.cymru.com",
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
|
|
||||||
if env := os.Getenv("BIRDLG_SERVERS"); env != "" {
|
if env := os.Getenv("BIRDLG_SERVERS"); env != "" {
|
||||||
@ -50,12 +52,17 @@ func main() {
|
|||||||
settingDefault.dnsInterface = env
|
settingDefault.dnsInterface = env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if env := os.Getenv("BIRDLG_NET_SPECIFIC_MODE"); env != "" {
|
||||||
|
settingDefault.netSpecificMode = env
|
||||||
|
}
|
||||||
|
|
||||||
serversPtr := flag.String("servers", strings.Join(settingDefault.servers, ","), "server name prefixes, separated by comma")
|
serversPtr := flag.String("servers", strings.Join(settingDefault.servers, ","), "server name prefixes, separated by comma")
|
||||||
domainPtr := flag.String("domain", settingDefault.domain, "server name domain suffixes")
|
domainPtr := flag.String("domain", settingDefault.domain, "server name domain suffixes")
|
||||||
proxyPortPtr := flag.Int("proxy-port", settingDefault.proxyPort, "port bird-lgproxy is running on")
|
proxyPortPtr := flag.Int("proxy-port", settingDefault.proxyPort, "port bird-lgproxy is running on")
|
||||||
whoisPtr := flag.String("whois", settingDefault.whoisServer, "whois server for queries")
|
whoisPtr := flag.String("whois", settingDefault.whoisServer, "whois server for queries")
|
||||||
listenPtr := flag.String("listen", settingDefault.listen, "address bird-lg is listening on")
|
listenPtr := flag.String("listen", settingDefault.listen, "address bird-lg is listening on")
|
||||||
dnsInterfacePtr := flag.String("dns-interface", settingDefault.dnsInterface, "dns zone to query ASN information")
|
dnsInterfacePtr := flag.String("dns-interface", settingDefault.dnsInterface, "dns zone to query ASN information")
|
||||||
|
netSpecificModePtr := flag.String("net-specific-mode", settingDefault.netSpecificMode, "network specific operation mode, [(none)|dn42]")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *serversPtr == "" {
|
if *serversPtr == "" {
|
||||||
@ -71,6 +78,7 @@ func main() {
|
|||||||
*whoisPtr,
|
*whoisPtr,
|
||||||
*listenPtr,
|
*listenPtr,
|
||||||
*dnsInterfacePtr,
|
*dnsInterfacePtr,
|
||||||
|
strings.ToLower(*netSpecificModePtr),
|
||||||
}
|
}
|
||||||
|
|
||||||
webServerStart()
|
webServerStart()
|
||||||
|
@ -94,28 +94,10 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
} else if telegramIsCommand(request.Message.Text, "whois") {
|
} else if telegramIsCommand(request.Message.Text, "whois") {
|
||||||
tempResult := whois(target)
|
tempResult := whois(target)
|
||||||
|
if setting.netSpecificMode == "dn42" {
|
||||||
// Filter out some long (and useless) keys
|
commandResult = dn42WhoisFilter(tempResult)
|
||||||
filteredPrefix := []string{
|
} else {
|
||||||
"descr:", "remarks:", "ds-rdata:", "auth:", "country:",
|
commandResult = tempResult
|
||||||
"nserver:", "status:", "pgp-fingerprint:", "mp-import:", "mp-export:",
|
|
||||||
"members:", "key:", "inetnum:", "inet6num:", "%",
|
|
||||||
}
|
|
||||||
for _, s := range strings.Split(tempResult, "\n") {
|
|
||||||
if len(s) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
shouldSkip := false
|
|
||||||
for _, filtered := range filteredPrefix {
|
|
||||||
if strings.HasPrefix(s, filtered) {
|
|
||||||
shouldSkip = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if shouldSkip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
commandResult += s + "\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if telegramIsCommand(request.Message.Text, "help") {
|
} else if telegramIsCommand(request.Message.Text, "help") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user