BIRDLG_BGPMAP_INFO 選項 (#44)

* BIRDLG_BGPMAP_INFO

update the paramater

description fix for bgpmap_test

singleline and multiline

* Static file instead of jsdelivr; favicon.ico

Co-authored-by: testscript <testscript@example.com>
This commit is contained in:
日下部 詩 2021-12-20 17:35:43 +08:00 committed by GitHub
parent 58847759b3
commit af5b653326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 163 additions and 17 deletions

View File

@ -85,6 +85,7 @@ Usage: all configuration is done via commandline parameters or environment varia
| --proxy-port | BIRDLG_PROXY_PORT | port bird-lgproxy is running on (default 8000) |
| --whois | BIRDLG_WHOIS | whois server for queries (default "whois.verisign-grs.com") |
| --dns-interface | BIRDLG_DNS_INTERFACE | dns zone to query ASN information (default "asn.cymru.com") |
| --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 | BIRDLG_TITLE_BRAND | prefix of page titles in browser tabs (default "Bird-lg Go") |
| --navbar-brand | BIRDLG_NAVBAR_BRAND | brand to show in the navigation bar (default "Bird-lg Go") |
| --navbar-brand-url | BIRDLG_NAVBAR_BRAND_URL | the url of the brand to show in the navigation bar (default "/") |

BIN
frontend/assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,8 @@
<div id="bgpmap">
</div>
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2/viz.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2/lite.render.js" crossorigin="anonymous"></script>
<script src="/static/jsdelivr/npm/viz.js@2.1.2/viz.min.js" crossorigin="anonymous"></script>
<script src="/static/jsdelivr/npm/viz.js@2.1.2/lite.render.js" crossorigin="anonymous"></script>
<script>
var viz = new Viz();
viz.renderSVGElement(`{{ .Result }}`)

View File

@ -1,12 +1,13 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<title>{{ html .Title }}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.1/dist/css/bootstrap.min.css" integrity="sha256-VoFZSlmyTXsegReQCNmbXrS4hBBUl/cexZvPmPWoJsY=" crossorigin="anonymous">
<link rel="stylesheet" href="/static/jsdelivr/npm/bootstrap@4.5.1/dist/css/bootstrap.min.css" integrity="sha256-VoFZSlmyTXsegReQCNmbXrS4hBBUl/cexZvPmPWoJsY=" crossorigin="anonymous">
<meta name="robots" content="noindex, nofollow">
</head>
<body>
@ -73,8 +74,8 @@
{{ .Content }}
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.1/dist/js/bootstrap.min.js" integrity="sha256-0IiaoZCI++9oAAvmCb5Y0r93XkuhvJpRalZLffQXLok=" crossorigin="anonymous"></script>
<script src="/static/jsdelivr/npm/jquery@3.5.1/dist/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="/static/jsdelivr/npm/bootstrap@4.5.1/dist/js/bootstrap.min.js" integrity="sha256-0IiaoZCI++9oAAvmCb5Y0r93XkuhvJpRalZLffQXLok=" crossorigin="anonymous"></script>
<script>
function goto() {

View File

@ -23,23 +23,46 @@ func getASNRepresentation(asn string) string {
if setting.whoisServer != "" {
// get ASN representation using WHOIS
if setting.bgpmapInfo == "" {
setting.bgpmapInfo = "asn,as-name,ASName,descr"
}
records := whois(fmt.Sprintf("AS%s", asn))
if records != "" {
recordsSplit := strings.Split(records, "\n")
result := ""
for _, line := range recordsSplit {
if strings.Contains(line, "as-name:") || strings.Contains(line, "ASName:") {
result = result + strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
} else if strings.Contains(line, "descr:") {
result = result + "\\n" + strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
var result []string
for _, title := range strings.Split(setting.bgpmapInfo, ",") {
if title == "asn" {
result = append(result, "AS"+asn)
}
}
if result != "" {
return fmt.Sprintf("AS%s\\n%s", asn, result)
for _, title := range strings.Split(setting.bgpmapInfo, ",") {
allow_multiline := false
if title[0] == ':' && len(title) >= 2 {
title = title[1:]
allow_multiline = true
}
for _, line := range recordsSplit {
if len(line) == 0 || line[0] == '%' || !strings.Contains(line, ":") {
continue
}
linearr := strings.SplitN(line, ":", 2)
line_title := linearr[0]
content := strings.TrimSpace(linearr[1])
if line_title != title {
continue
}
result = append(result, content)
if !allow_multiline {
break
}
}
}
if len(result) > 0 {
return fmt.Sprintf("%s", strings.Join(result, "\n"))
}
}
}
return fmt.Sprintf("AS%s", asn)
}

View File

@ -21,6 +21,7 @@ type settingType struct {
navBarBrandURL string
navBarAllServer string
navBarAllURL string
bgpmapInfo string
telegramBotName string
protocolFilter []string
}
@ -39,6 +40,7 @@ func main() {
navBarBrandURL: "/",
navBarAllServer: "All Servers",
navBarAllURL: "all",
bgpmapInfo: "asn,as-name,ASName,descr",
telegramBotName: "",
protocolFilter: []string{},
}
@ -83,6 +85,9 @@ func main() {
if env := os.Getenv("BIRDLG_NAVBAR_ALL_URL"); env != "" {
settingDefault.navBarAllURL = env
}
if env := os.Getenv("BIRDLG_BGPMAP_INFO"); env != "" {
settingDefault.bgpmapInfo = env
}
if env := os.Getenv("BIRDLG_TELEGRAM_BOT_NAME"); env != "" {
settingDefault.telegramBotName = env
}
@ -99,9 +104,10 @@ func main() {
netSpecificModePtr := flag.String("net-specific-mode", settingDefault.netSpecificMode, "network specific operation mode, [(none)|dn42]")
titleBrandPtr := flag.String("title-brand", settingDefault.titleBrand, "prefix of page titles in browser tabs")
navBarBrandPtr := flag.String("navbar-brand", settingDefault.navBarBrand, "brand to show in the navigation bar")
navBarBrandURLPtr := flag.String("navbar-brand-url", settingDefault.navBarBrandURL, "brand to show in the navigation bar")
navBarAllServerPtr := flag.String("navbar-all-servers", settingDefault.navBarAllServer, "brand to show in the navigation bar")
navBarAllURL := flag.String("navbar-all-url", settingDefault.navBarAllURL, "brand to show in the navigation bar")
navBarBrandURLPtr := flag.String("navbar-brand-url", settingDefault.navBarBrandURL, "the url of the brand to show in the navigation bar")
navBarAllServerPtr := flag.String("navbar-all-servers", settingDefault.navBarAllServer, "the text of \"All servers\" button in the navigation bar")
navBarAllURL := flag.String("navbar-all-url", settingDefault.navBarAllURL, "the URL of \"All servers\" button")
bgpmapInfo := flag.String("bgpmap-info", settingDefault.bgpmapInfo, "the infos displayed in bgpmap, separated by comma, start with \":\" means allow multiline")
telegramBotNamePtr := flag.String("telegram-bot-name", settingDefault.telegramBotName, "telegram bot name (used to filter @bot commands)")
protocolFilterPtr := flag.String("protocol-filter", strings.Join(settingDefault.protocolFilter, ","),
"protocol types to show in summary tables (comma separated list); defaults to all if not set")
@ -148,6 +154,7 @@ func main() {
*navBarBrandURLPtr,
*navBarAllServerPtr,
*navBarAllURL,
*bgpmapInfo,
*telegramBotNamePtr,
protocolFilter,
}