+ POST /control/dhcp/reset: Reset DHCP configuration
This commit is contained in:
parent
477a4bbf54
commit
df92941ae0
|
@ -28,6 +28,7 @@ Contents:
|
|||
* "Enable DHCP" command
|
||||
* Static IP check/set
|
||||
* Add a static lease
|
||||
* API: Reset DHCP configuration
|
||||
* DNS access settings
|
||||
* List access settings
|
||||
* Set access settings
|
||||
|
@ -543,6 +544,20 @@ Response:
|
|||
200 OK
|
||||
|
||||
|
||||
### API: Reset DHCP configuration
|
||||
|
||||
Clear all DHCP leases and configuration settings.
|
||||
DHCP server will be stopped if it's currently running.
|
||||
|
||||
Request:
|
||||
|
||||
POST /control/dhcp/reset
|
||||
|
||||
Response:
|
||||
|
||||
200 OK
|
||||
|
||||
|
||||
## TLS
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -451,6 +452,28 @@ func (s *Server) handleDHCPRemoveStaticLease(w http.ResponseWriter, r *http.Requ
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) {
|
||||
err := s.Stop()
|
||||
if err != nil {
|
||||
log.Error("DHCP: Stop: %s", err)
|
||||
}
|
||||
|
||||
err = os.Remove(s.conf.DBFilePath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
log.Error("DHCP: os.Remove: %s: %s", s.conf.DBFilePath, err)
|
||||
}
|
||||
|
||||
oldconf := s.conf
|
||||
s.conf = ServerConfig{}
|
||||
s.conf.LeaseDuration = 86400
|
||||
s.conf.ICMPTimeout = 1000
|
||||
s.conf.WorkDir = oldconf.WorkDir
|
||||
s.conf.HTTPRegister = oldconf.HTTPRegister
|
||||
s.conf.ConfigModified = oldconf.ConfigModified
|
||||
s.conf.DBFilePath = oldconf.DBFilePath
|
||||
s.conf.ConfigModified()
|
||||
}
|
||||
|
||||
func (s *Server) registerHandlers() {
|
||||
s.conf.HTTPRegister("GET", "/control/dhcp/status", s.handleDHCPStatus)
|
||||
s.conf.HTTPRegister("GET", "/control/dhcp/interfaces", s.handleDHCPInterfaces)
|
||||
|
@ -458,4 +481,5 @@ func (s *Server) registerHandlers() {
|
|||
s.conf.HTTPRegister("POST", "/control/dhcp/find_active_dhcp", s.handleDHCPFindActiveServer)
|
||||
s.conf.HTTPRegister("POST", "/control/dhcp/add_static_lease", s.handleDHCPAddStaticLease)
|
||||
s.conf.HTTPRegister("POST", "/control/dhcp/remove_static_lease", s.handleDHCPRemoveStaticLease)
|
||||
s.conf.HTTPRegister("POST", "/control/dhcp/reset", s.handleReset)
|
||||
}
|
||||
|
|
|
@ -39,13 +39,14 @@ type ServerConfig struct {
|
|||
SubnetMask string `json:"subnet_mask" yaml:"subnet_mask"`
|
||||
RangeStart string `json:"range_start" yaml:"range_start"`
|
||||
RangeEnd string `json:"range_end" yaml:"range_end"`
|
||||
LeaseDuration uint `json:"lease_duration" yaml:"lease_duration"` // in seconds
|
||||
WorkDir string `json:"-" yaml:"-"`
|
||||
DBFilePath string `json:"-" yaml:"-"` // path to DB file
|
||||
LeaseDuration uint32 `json:"lease_duration" yaml:"lease_duration"` // in seconds
|
||||
|
||||
// IP conflict detector: time (ms) to wait for ICMP reply.
|
||||
// 0: disable
|
||||
ICMPTimeout uint `json:"icmp_timeout_msec" yaml:"icmp_timeout_msec"`
|
||||
ICMPTimeout uint32 `json:"icmp_timeout_msec" yaml:"icmp_timeout_msec"`
|
||||
|
||||
WorkDir string `json:"-" yaml:"-"`
|
||||
DBFilePath string `json:"-" yaml:"-"` // path to DB file
|
||||
|
||||
// Called when the configuration is changed by HTTP request
|
||||
ConfigModified func() `json:"-" yaml:"-"`
|
||||
|
|
Loading…
Reference in New Issue