From 7b1dc6718db1c19cbc8d2ade2ee93700b9ac256c Mon Sep 17 00:00:00 2001 From: Arnie97 Date: Tue, 28 Jul 2020 17:57:38 +0800 Subject: [PATCH] frontend: support rebranding --- frontend/main.go | 28 ++++++++++++++++++++-------- frontend/render.go | 3 ++- frontend/template.go | 3 ++- frontend/webserver.go | 6 +++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/frontend/main.go b/frontend/main.go index 66f9dc2..4072e08 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -15,19 +15,21 @@ type settingType struct { listen string dnsInterface string netSpecificMode string + titleBrand string + navBarBrand string } var setting settingType func main() { var settingDefault = settingType{ - []string{""}, - "", - 8000, - "whois.verisign-grs.com", - ":5000", - "asn.cymru.com", - "", + servers: []string{""}, + proxyPort: 8000, + whoisServer: "whois.verisign-grs.com", + listen: ":5000", + dnsInterface: "asn.cymru.com", + titleBrand: "Bird-lg Go", + navBarBrand: "Bird-lg Go", } if env := os.Getenv("BIRDLG_SERVERS"); env != "" { @@ -51,10 +53,16 @@ func main() { if env := os.Getenv("BIRDLG_DNS_INTERFACE"); env != "" { settingDefault.dnsInterface = env } - if env := os.Getenv("BIRDLG_NET_SPECIFIC_MODE"); env != "" { settingDefault.netSpecificMode = env } + if env := os.Getenv("BIRDLG_TITLE_BRAND"); env != "" { + settingDefault.titleBrand = env + settingDefault.navBarBrand = env + } + if env := os.Getenv("BIRDLG_NAVBAR_BRAND"); env != "" { + settingDefault.navBarBrand = env + } serversPtr := flag.String("servers", strings.Join(settingDefault.servers, ","), "server name prefixes, separated by comma") domainPtr := flag.String("domain", settingDefault.domain, "server name domain suffixes") @@ -63,6 +71,8 @@ func main() { 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") 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") flag.Parse() if *serversPtr == "" { @@ -79,6 +89,8 @@ func main() { *listenPtr, *dnsInterfacePtr, strings.ToLower(*netSpecificModePtr), + *titleBrandPtr, + *navBarBrandPtr, } webServerStart() diff --git a/frontend/render.go b/frontend/render.go index f1af942..9aaa4f4 100644 --- a/frontend/render.go +++ b/frontend/render.go @@ -50,7 +50,8 @@ func renderTemplate(w http.ResponseWriter, r *http.Request, title string, conten args.URLServer = strings.ToLower(split[2]) args.URLCommand = split[3] - args.Title = title + args.Title = setting.titleBrand + title + args.Brand = setting.navBarBrand args.Content = content err := tmpl.Execute(w, args) diff --git a/frontend/template.go b/frontend/template.go index 3c84484..910a5da 100644 --- a/frontend/template.go +++ b/frontend/template.go @@ -24,6 +24,7 @@ type tmplArguments struct { // Generated content to be displayed Title string + Brand string Content string } @@ -41,7 +42,7 @@ var tmpl = template.Must(template.New("tmpl").Parse(`