Start DHCP on launch if it's enabled in config.
This commit is contained in:
parent
f868fdbf7a
commit
03effab345
5
app.go
5
app.go
|
@ -192,6 +192,11 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = startDHCPServer()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
URL := fmt.Sprintf("http://%s", address)
|
URL := fmt.Sprintf("http://%s", address)
|
||||||
log.Println("Go to " + URL)
|
log.Println("Go to " + URL)
|
||||||
log.Fatal(http.ListenAndServe(address, nil))
|
log.Fatal(http.ListenAndServe(address, nil))
|
||||||
|
|
10
dhcp.go
10
dhcp.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dhcpd"
|
"github.com/AdguardTeam/AdGuardHome/dhcpd"
|
||||||
|
"github.com/joomcode/errorx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dhcpServer = dhcpd.Server{}
|
var dhcpServer = dhcpd.Server{}
|
||||||
|
@ -107,7 +108,6 @@ func handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implement
|
|
||||||
func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
|
func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
|
||||||
found, err := dhcpd.CheckIfOtherDHCPServersPresent(config.DHCP.InterfaceName)
|
found, err := dhcpd.CheckIfOtherDHCPServersPresent(config.DHCP.InterfaceName)
|
||||||
result := map[string]interface{}{}
|
result := map[string]interface{}{}
|
||||||
|
@ -123,3 +123,11 @@ func handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startDHCPServer() error {
|
||||||
|
err := dhcpServer.Start(&config.DHCP)
|
||||||
|
if err != nil {
|
||||||
|
return errorx.Decorate(err, "Couldn't start DHCP server")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue