mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/cli,internal/router: detect unbound/dnsmasq status correctly on *BSD
Also detect cd mode for stop/uninstall command correctly, too.
This commit is contained in:
committed by
Cuong Manh Le
parent
ab88174091
commit
43d82cf1a7
40
internal/router/os_config_freebsd.go
Normal file
40
internal/router/os_config_freebsd.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config represents /conf/config.xml file found on pfsense/opnsense.
|
||||
type Config struct {
|
||||
PfsenseUnbound *string `xml:"unbound>enable,omitempty"`
|
||||
OPNsenseUnbound *string `xml:"OPNsense>unboundplus>general>enabled,omitempty"`
|
||||
Dnsmasq *string `xml:"dnsmasq>enable,omitempty"`
|
||||
}
|
||||
|
||||
// DnsmasqEnabled reports whether dnsmasq is enabled.
|
||||
func (c *Config) DnsmasqEnabled() bool {
|
||||
if isPfsense() { // pfsense only set the attribute if dnsmasq is enabled.
|
||||
return c.Dnsmasq != nil
|
||||
}
|
||||
return c.Dnsmasq != nil && *c.Dnsmasq == "1"
|
||||
}
|
||||
|
||||
// UnboundEnabled reports whether unbound is enabled.
|
||||
func (c *Config) UnboundEnabled() bool {
|
||||
if isPfsense() { // pfsense only set the attribute if unbound is enabled.
|
||||
return c.PfsenseUnbound != nil
|
||||
}
|
||||
return c.OPNsenseUnbound != nil && *c.OPNsenseUnbound == "1"
|
||||
}
|
||||
|
||||
// currentConfig does unmarshalling /conf/config.xml file,
|
||||
// return the corresponding *Config represent it.
|
||||
func currentConfig() (*Config, error) {
|
||||
buf, _ := os.ReadFile("/conf/config.xml")
|
||||
c := Config{}
|
||||
if err := xml.Unmarshal(buf, &c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
@@ -111,8 +111,16 @@ func (or *osRouter) Setup() error {
|
||||
|
||||
func (or *osRouter) Cleanup() error {
|
||||
if or.cdMode {
|
||||
_ = exec.Command(unboundRcPath, "onerestart").Run()
|
||||
_ = exec.Command(dnsmasqRcPath, "onerestart").Run()
|
||||
c, err := currentConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.UnboundEnabled() {
|
||||
_ = exec.Command(unboundRcPath, "onerestart").Run()
|
||||
}
|
||||
if c.DnsmasqEnabled() {
|
||||
_ = exec.Command(dnsmasqRcPath, "onerestart").Run()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user