frontend: support listening on unix socket (#54)
This commit is contained in:
parent
348295b9aa
commit
892a7bee22
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -112,7 +113,7 @@ func main() {
|
||||
domainPtr := flag.String("domain", settingDefault.domain, "server name domain suffixes")
|
||||
proxyPortPtr := flag.Int("proxy-port", settingDefault.proxyPort, "port bird-lgproxy is running on")
|
||||
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 or unix socket 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")
|
||||
@ -132,11 +133,6 @@ func main() {
|
||||
panic("no server set")
|
||||
}
|
||||
|
||||
if !strings.Contains(*listenPtr, ":") {
|
||||
listenHost := ":" + (*listenPtr)
|
||||
listenPtr = &listenHost
|
||||
}
|
||||
|
||||
servers := strings.Split(*serversPtr, ",")
|
||||
serversDisplay := strings.Split(*serversPtr, ",")
|
||||
|
||||
@ -177,5 +173,25 @@ func main() {
|
||||
}
|
||||
|
||||
ImportTemplates()
|
||||
webServerStart()
|
||||
|
||||
var l net.Listener
|
||||
var err error
|
||||
|
||||
if strings.HasPrefix(setting.listen, "/") {
|
||||
// Delete existing socket file, ignore errors (will fail later anyway)
|
||||
os.Remove(setting.listen)
|
||||
l, err = net.Listen("unix", setting.listen)
|
||||
} else {
|
||||
listenAddr := setting.listen
|
||||
if !strings.Contains(listenAddr, ":") {
|
||||
listenAddr = ":" + listenAddr
|
||||
}
|
||||
l, err = net.Listen("tcp", listenAddr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
webServerStart(l)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"html"
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -176,7 +177,7 @@ func webHandlerBGPMap(endpoint string, command string) func(w http.ResponseWrite
|
||||
}
|
||||
|
||||
// set up routing paths and start webserver
|
||||
func webServerStart() {
|
||||
func webServerStart(l net.Listener) {
|
||||
|
||||
// redirect main page to all server summary
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -211,5 +212,5 @@ func webServerStart() {
|
||||
http.HandleFunc("/telegram/", webHandlerTelegramBot)
|
||||
|
||||
// Start HTTP server
|
||||
http.ListenAndServe(setting.listen, handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))
|
||||
http.Serve(l, handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user