* move "dhcpServer" to "config"
This commit is contained in:
parent
5e309a7b3a
commit
001b4b981f
|
@ -122,7 +122,7 @@ func (clients *clientsContainer) Find(ip string) (Client, bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ipAddr := dhcpServer.FindIPbyMAC(mac)
|
ipAddr := config.dhcpServer.FindIPbyMAC(mac)
|
||||||
if ipAddr == nil {
|
if ipAddr == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ func handleGetClients(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if len(c.MAC) != 0 {
|
if len(c.MAC) != 0 {
|
||||||
hwAddr, _ := net.ParseMAC(c.MAC)
|
hwAddr, _ := net.ParseMAC(c.MAC)
|
||||||
ipAddr := dhcpServer.FindIPbyMAC(hwAddr)
|
ipAddr := config.dhcpServer.FindIPbyMAC(hwAddr)
|
||||||
if ipAddr != nil {
|
if ipAddr != nil {
|
||||||
cj.IP = ipAddr.String()
|
cj.IP = ipAddr.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ type configuration struct {
|
||||||
versionCheckJSON []byte
|
versionCheckJSON []byte
|
||||||
versionCheckLastTime time.Time
|
versionCheckLastTime time.Time
|
||||||
|
|
||||||
|
dhcpServer dhcpd.Server
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
httpsServer HTTPSServer
|
httpsServer HTTPSServer
|
||||||
|
|
||||||
|
|
24
home/dhcp.go
24
home/dhcp.go
|
@ -18,8 +18,6 @@ import (
|
||||||
"github.com/joomcode/errorx"
|
"github.com/joomcode/errorx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dhcpServer = dhcpd.Server{}
|
|
||||||
|
|
||||||
// []dhcpd.Lease -> JSON
|
// []dhcpd.Lease -> JSON
|
||||||
func convertLeases(inputLeases []dhcpd.Lease, includeExpires bool) []map[string]string {
|
func convertLeases(inputLeases []dhcpd.Lease, includeExpires bool) []map[string]string {
|
||||||
leases := []map[string]string{}
|
leases := []map[string]string{}
|
||||||
|
@ -41,8 +39,8 @@ func convertLeases(inputLeases []dhcpd.Lease, includeExpires bool) []map[string]
|
||||||
|
|
||||||
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
leases := convertLeases(dhcpServer.Leases(), true)
|
leases := convertLeases(config.dhcpServer.Leases(), true)
|
||||||
staticLeases := convertLeases(dhcpServer.StaticLeases(), false)
|
staticLeases := convertLeases(config.dhcpServer.StaticLeases(), false)
|
||||||
status := map[string]interface{}{
|
status := map[string]interface{}{
|
||||||
"config": config.DHCP,
|
"config": config.DHCP,
|
||||||
"leases": leases,
|
"leases": leases,
|
||||||
|
@ -77,18 +75,18 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dhcpServer.CheckConfig(newconfig.ServerConfig)
|
err = config.dhcpServer.CheckConfig(newconfig.ServerConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dhcpServer.Stop()
|
err = config.dhcpServer.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed to stop the DHCP server: %s", err)
|
log.Error("failed to stop the DHCP server: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dhcpServer.Init(newconfig.ServerConfig)
|
err = config.dhcpServer.Init(newconfig.ServerConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -105,7 +103,7 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dhcpServer.Start()
|
err = config.dhcpServer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err)
|
httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -389,7 +387,7 @@ func handleDHCPAddStaticLease(w http.ResponseWriter, r *http.Request) {
|
||||||
HWAddr: mac,
|
HWAddr: mac,
|
||||||
Hostname: lj.Hostname,
|
Hostname: lj.Hostname,
|
||||||
}
|
}
|
||||||
err = dhcpServer.AddStaticLease(lease)
|
err = config.dhcpServer.AddStaticLease(lease)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "%s", err)
|
httpError(w, http.StatusBadRequest, "%s", err)
|
||||||
return
|
return
|
||||||
|
@ -420,7 +418,7 @@ func handleDHCPRemoveStaticLease(w http.ResponseWriter, r *http.Request) {
|
||||||
HWAddr: mac,
|
HWAddr: mac,
|
||||||
Hostname: lj.Hostname,
|
Hostname: lj.Hostname,
|
||||||
}
|
}
|
||||||
err = dhcpServer.RemoveStaticLease(lease)
|
err = config.dhcpServer.RemoveStaticLease(lease)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "%s", err)
|
httpError(w, http.StatusBadRequest, "%s", err)
|
||||||
return
|
return
|
||||||
|
@ -434,12 +432,12 @@ func startDHCPServer() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dhcpServer.Init(config.DHCP)
|
err := config.dhcpServer.Init(config.DHCP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't init DHCP server")
|
return errorx.Decorate(err, "Couldn't init DHCP server")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = dhcpServer.Start()
|
err = config.dhcpServer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start DHCP server")
|
return errorx.Decorate(err, "Couldn't start DHCP server")
|
||||||
}
|
}
|
||||||
|
@ -451,7 +449,7 @@ func stopDHCPServer() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dhcpServer.Stop()
|
err := config.dhcpServer.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't stop DHCP server")
|
return errorx.Decorate(err, "Couldn't stop DHCP server")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue