+ "dhcp_available"

This commit is contained in:
Simon Zolin 2020-05-29 14:25:20 +03:00
parent 82bd8dbbf2
commit 4f0a4173b5
4 changed files with 21 additions and 10 deletions

View file

@ -388,6 +388,7 @@ Response:
"language":"en",
"protection_enabled":true,
"running":true,
"dhcp_available":true,
"version":"undefined"
}

View file

@ -56,6 +56,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
"protection_enabled": c.ProtectionEnabled,
}
data["dhcp_available"] = (Context.dhcpServer != nil)
jsonVal, err := json.Marshal(data)
if err != nil {

View file

@ -211,10 +211,12 @@ func run(args options) {
config.DHCP.WorkDir = Context.workDir
config.DHCP.HTTPRegister = httpRegister
config.DHCP.ConfigModified = onConfigModified
Context.dhcpServer = dhcpd.Create(config.DHCP)
if Context.dhcpServer == nil {
log.Error("Failed to initialize DHCP server, exiting")
os.Exit(1)
if runtime.GOOS != "windows" {
Context.dhcpServer = dhcpd.Create(config.DHCP)
if Context.dhcpServer == nil {
log.Error("Failed to initialize DHCP server, exiting")
os.Exit(1)
}
}
Context.autoHosts.Init("")
Context.clients.Init(config.Clients, Context.dhcpServer, &Context.autoHosts)
@ -296,9 +298,11 @@ func run(args options) {
}
}()
err = Context.dhcpServer.Start()
if err != nil {
log.Fatal(err)
if Context.dhcpServer != nil {
err = Context.dhcpServer.Start()
if err != nil {
log.Fatal(err)
}
}
}
@ -447,9 +451,12 @@ func cleanup() {
if err != nil {
log.Error("Couldn't stop DNS server: %s", err)
}
err = Context.dhcpServer.Stop()
if err != nil {
log.Error("Couldn't stop DHCP server: %s", err)
if Context.dhcpServer != nil {
err = Context.dhcpServer.Stop()
if err != nil {
log.Error("Couldn't stop DHCP server: %s", err)
}
}
Context.autoHosts.Close()

View file

@ -1049,6 +1049,8 @@ definitions:
maximum: 65535
protection_enabled:
type: "boolean"
dhcp_available:
type: "boolean"
querylog_enabled:
type: "boolean"
running: