Initial implementation of welcome/firstrun/installer page in go backend
This commit is contained in:
43
dhcp.go
43
dhcp.go
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -70,50 +69,14 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
func handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
|
||||
response := map[string]interface{}{}
|
||||
|
||||
ifaces, err := net.Interfaces()
|
||||
ifaces, err := getValidNetInterfaces()
|
||||
if err != nil {
|
||||
httpError(w, http.StatusInternalServerError, "Couldn't get list of interfaces: %s", err)
|
||||
httpError(w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
type responseInterface struct {
|
||||
Name string `json:"name"`
|
||||
MTU int `json:"mtu"`
|
||||
HardwareAddr string `json:"hardware_address"`
|
||||
Addresses []string `json:"ip_addresses"`
|
||||
}
|
||||
|
||||
for i := range ifaces {
|
||||
if ifaces[i].Flags&net.FlagLoopback != 0 {
|
||||
// it's a loopback, skip it
|
||||
continue
|
||||
}
|
||||
if ifaces[i].Flags&net.FlagBroadcast == 0 {
|
||||
// this interface doesn't support broadcast, skip it
|
||||
continue
|
||||
}
|
||||
if ifaces[i].Flags&net.FlagPointToPoint != 0 {
|
||||
// this interface is ppp, don't do dhcp over it
|
||||
continue
|
||||
}
|
||||
iface := responseInterface{
|
||||
Name: ifaces[i].Name,
|
||||
MTU: ifaces[i].MTU,
|
||||
HardwareAddr: ifaces[i].HardwareAddr.String(),
|
||||
}
|
||||
addrs, errAddrs := ifaces[i].Addrs()
|
||||
if errAddrs != nil {
|
||||
httpError(w, http.StatusInternalServerError, "Failed to get addresses for interface %v: %s", ifaces[i].Name, errAddrs)
|
||||
return
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
iface.Addresses = append(iface.Addresses, addr.String())
|
||||
}
|
||||
if len(iface.Addresses) == 0 {
|
||||
// this interface has no addresses, skip it
|
||||
continue
|
||||
}
|
||||
response[ifaces[i].Name] = iface
|
||||
response[ifaces[i].Name] = ifaces[i]
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
|
||||
Reference in New Issue
Block a user