Merge: DHCP: show static leases all the time
Closes #1023 * commit '60cbb93488ec3fa1ca720d88e79ae48130ac9461': + client: show DHCP static leases all the time * dhcp: now static leases functionality works before DHCP is started
This commit is contained in:
commit
24e8ef6b32
@ -219,46 +219,44 @@ class Dhcp extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
{dhcp.config.enabled && (
|
{dhcp.config.enabled && (
|
||||||
<Fragment>
|
<Card
|
||||||
<Card
|
title={t('dhcp_leases')}
|
||||||
title={t('dhcp_leases')}
|
bodyType="card-body box-body--settings"
|
||||||
bodyType="card-body box-body--settings"
|
>
|
||||||
>
|
<div className="row">
|
||||||
<div className="row">
|
<div className="col">
|
||||||
<div className="col">
|
<Leases leases={dhcp.leases} />
|
||||||
<Leases leases={dhcp.leases} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</div>
|
||||||
<Card
|
</Card>
|
||||||
title={t('dhcp_static_leases')}
|
|
||||||
bodyType="card-body box-body--settings"
|
|
||||||
>
|
|
||||||
<div className="row">
|
|
||||||
<div className="col-12">
|
|
||||||
<StaticLeases
|
|
||||||
staticLeases={dhcp.staticLeases}
|
|
||||||
isModalOpen={dhcp.isModalOpen}
|
|
||||||
addStaticLease={addStaticLease}
|
|
||||||
removeStaticLease={removeStaticLease}
|
|
||||||
toggleLeaseModal={toggleLeaseModal}
|
|
||||||
processingAdding={dhcp.processingAdding}
|
|
||||||
processingDeleting={dhcp.processingDeleting}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-12">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="btn btn-success btn-standard mt-3"
|
|
||||||
onClick={() => toggleLeaseModal()}
|
|
||||||
>
|
|
||||||
<Trans>dhcp_add_static_lease</Trans>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
</Fragment>
|
|
||||||
)}
|
)}
|
||||||
|
<Card
|
||||||
|
title={t('dhcp_static_leases')}
|
||||||
|
bodyType="card-body box-body--settings"
|
||||||
|
>
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12">
|
||||||
|
<StaticLeases
|
||||||
|
staticLeases={dhcp.staticLeases}
|
||||||
|
isModalOpen={dhcp.isModalOpen}
|
||||||
|
addStaticLease={addStaticLease}
|
||||||
|
removeStaticLease={removeStaticLease}
|
||||||
|
toggleLeaseModal={toggleLeaseModal}
|
||||||
|
processingAdding={dhcp.processingAdding}
|
||||||
|
processingDeleting={dhcp.processingDeleting}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-12">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-success btn-standard mt-3"
|
||||||
|
onClick={() => toggleLeaseModal()}
|
||||||
|
>
|
||||||
|
<Trans>dhcp_add_static_lease</Trans>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)}
|
)}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
@ -100,9 +100,14 @@ func (s *Server) CheckConfig(config ServerConfig) error {
|
|||||||
func Create(config ServerConfig) *Server {
|
func Create(config ServerConfig) *Server {
|
||||||
s := Server{}
|
s := Server{}
|
||||||
s.conf = config
|
s.conf = config
|
||||||
|
s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
|
||||||
if s.conf.HTTPRegister != nil {
|
if s.conf.HTTPRegister != nil {
|
||||||
s.registerHandlers()
|
s.registerHandlers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we can't delay database loading until DHCP server is started,
|
||||||
|
// because we need static leases functionality available beforehand
|
||||||
|
s.dbLoad()
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +117,6 @@ func (s *Server) Init(config ServerConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.dbLoad()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +182,7 @@ func (s *Server) setConfig(config ServerConfig) error {
|
|||||||
s.conf.WorkDir = oldconf.WorkDir
|
s.conf.WorkDir = oldconf.WorkDir
|
||||||
s.conf.HTTPRegister = oldconf.HTTPRegister
|
s.conf.HTTPRegister = oldconf.HTTPRegister
|
||||||
s.conf.ConfigModified = oldconf.ConfigModified
|
s.conf.ConfigModified = oldconf.ConfigModified
|
||||||
s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
|
s.conf.DBFilePath = oldconf.DBFilePath
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,10 +569,6 @@ func (s *Server) handleDecline(p dhcp4.Packet, options dhcp4.Options) dhcp4.Pack
|
|||||||
|
|
||||||
// AddStaticLease adds a static lease (thread-safe)
|
// AddStaticLease adds a static lease (thread-safe)
|
||||||
func (s *Server) AddStaticLease(l Lease) error {
|
func (s *Server) AddStaticLease(l Lease) error {
|
||||||
if s.IPpool == nil {
|
|
||||||
return fmt.Errorf("DHCP server isn't started")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(l.IP) != 4 {
|
if len(l.IP) != 4 {
|
||||||
return fmt.Errorf("Invalid IP")
|
return fmt.Errorf("Invalid IP")
|
||||||
}
|
}
|
||||||
@ -629,10 +629,6 @@ func (s *Server) rmLease(l Lease) error {
|
|||||||
|
|
||||||
// RemoveStaticLease removes a static lease (thread-safe)
|
// RemoveStaticLease removes a static lease (thread-safe)
|
||||||
func (s *Server) RemoveStaticLease(l Lease) error {
|
func (s *Server) RemoveStaticLease(l Lease) error {
|
||||||
if s.IPpool == nil {
|
|
||||||
return fmt.Errorf("DHCP server isn't started")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(l.IP) != 4 {
|
if len(l.IP) != 4 {
|
||||||
return fmt.Errorf("Invalid IP")
|
return fmt.Errorf("Invalid IP")
|
||||||
}
|
}
|
||||||
@ -675,10 +671,6 @@ func (s *Server) StaticLeases() []Lease {
|
|||||||
s.leasesLock.Lock()
|
s.leasesLock.Lock()
|
||||||
defer s.leasesLock.Unlock()
|
defer s.leasesLock.Unlock()
|
||||||
|
|
||||||
if s.IPpool == nil {
|
|
||||||
s.dbLoad()
|
|
||||||
}
|
|
||||||
|
|
||||||
var result []Lease
|
var result []Lease
|
||||||
for _, lease := range s.leases {
|
for _, lease := range s.leases {
|
||||||
if lease.Expiry.Unix() == 1 {
|
if lease.Expiry.Unix() == 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user