* /status: "dns_addresses": add port if not 53

This commit is contained in:
Simon Zolin 2019-07-02 12:19:36 +03:00
parent 1445940473
commit ad7c5cb9dc

View File

@ -80,27 +80,43 @@ func httpUpdateConfigReloadDNSReturnOK(w http.ResponseWriter, r *http.Request) {
returnOK(w) returnOK(w)
} }
func handleStatus(w http.ResponseWriter, r *http.Request) { func addDNSAddress(dnsAddresses *[]string, addr string) {
log.Tracef("%s %v", r.Method, r.URL) if config.DNS.Port != 53 {
addr = fmt.Sprintf("%s:%d", addr, config.DNS.Port)
}
*dnsAddresses = append(*dnsAddresses, addr)
}
// Get the list of DNS addresses the server is listening on
func getDNSAddresses() []string {
dnsAddresses := []string{} dnsAddresses := []string{}
if config.DNS.BindHost == "0.0.0.0" { if config.DNS.BindHost == "0.0.0.0" {
ifaces, e := getValidNetInterfacesForWeb() ifaces, e := getValidNetInterfacesForWeb()
if e != nil { if e != nil {
log.Error("Couldn't get network interfaces: %v", e) log.Error("Couldn't get network interfaces: %v", e)
} return []string{}
for _, iface := range ifaces {
for _, addr := range iface.Addresses {
dnsAddresses = append(dnsAddresses, addr)
}
}
}
if len(dnsAddresses) == 0 {
dnsAddresses = append(dnsAddresses, config.DNS.BindHost)
} }
for _, iface := range ifaces {
for _, addr := range iface.Addresses {
addDNSAddress(&dnsAddresses, addr)
}
}
} else {
addDNSAddress(&dnsAddresses, config.DNS.BindHost)
}
return dnsAddresses
}
func handleStatus(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL)
data := map[string]interface{}{ data := map[string]interface{}{
"dns_addresses": dnsAddresses, "dns_addresses": getDNSAddresses(),
"http_port": config.BindPort, "http_port": config.BindPort,
"dns_port": config.DNS.Port, "dns_port": config.DNS.Port,
"protection_enabled": config.DNS.ProtectionEnabled, "protection_enabled": config.DNS.ProtectionEnabled,