From 0b92dbb8463dee31c005c59f67c2bf754a9eae12 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 22 May 2022 21:29:35 +0700 Subject: all: export and rename the hostsBlock type to Blockd In the Environment, we have a field HostsBlocks that reference an unexported type hostsFile. In order for any package to be able to use this field, we need to export this type. While at it, we rename the type from hostsBlock to Blockd to make it simple and consistent with name. --- blockd.go | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ blockd_test.go | 104 ++++++++++++++++++++++++++++++++++++ client.go | 6 +-- environment.go | 16 +++--- environment_test.go | 10 ++-- hosts_block.go | 148 ---------------------------------------------------- hosts_block_test.go | 104 ------------------------------------ httpd.go | 50 +++++++++--------- rescached.go | 6 +-- 9 files changed, 296 insertions(+), 296 deletions(-) create mode 100644 blockd.go create mode 100644 blockd_test.go delete mode 100644 hosts_block.go delete mode 100644 hosts_block_test.go diff --git a/blockd.go b/blockd.go new file mode 100644 index 0000000..398bb96 --- /dev/null +++ b/blockd.go @@ -0,0 +1,148 @@ +// SPDX-FileCopyrightText: 2020 M. Shulhan +// SPDX-License-Identifier: GPL-3.0-or-later + +package rescached + +import ( + "bytes" + "fmt" + "io" + "log" + "net/http" + "os" + "path/filepath" + "time" +) + +const ( + lastUpdatedFormat = "2006-01-02 15:04:05 MST" +) + +type Blockd struct { + lastUpdated time.Time + + Name string `ini:"::name"` // Derived from hostname in URL. + URL string `ini:"::url"` + + file string + fileDisabled string + LastUpdated string + + IsEnabled bool // True if the hosts file un-hidden in block.d directory. + isFileExist bool // True if the file exist and enabled or disabled. +} + +// disable the hosts block by prefixing the file name with single dot. +func (hb *Blockd) disable() (err error) { + err = os.Rename(hb.file, hb.fileDisabled) + if err != nil { + return fmt.Errorf("disable: %w", err) + } + hb.IsEnabled = false + return nil +} + +// enable the hosts block file by removing the dot prefix from file name. +func (hb *Blockd) enable() (err error) { + if hb.isFileExist { + err = os.Rename(hb.fileDisabled, hb.file) + } else { + err = os.WriteFile(hb.file, []byte(""), 0600) + } + if err != nil { + return fmt.Errorf("enable: %w", err) + } + hb.IsEnabled = true + hb.isFileExist = true + return nil +} + +func (hb *Blockd) init(pathDirBlock string) { + var ( + fi os.FileInfo + err error + ) + + hb.file = filepath.Join(pathDirBlock, hb.Name) + hb.fileDisabled = filepath.Join(pathDirBlock, "."+hb.Name) + + fi, err = os.Stat(hb.file) + if err != nil { + hb.IsEnabled = false + + fi, err = os.Stat(hb.fileDisabled) + if err != nil { + return + } + + hb.isFileExist = true + } else { + hb.IsEnabled = true + hb.isFileExist = true + } + + hb.lastUpdated = fi.ModTime() + hb.LastUpdated = hb.lastUpdated.Format(lastUpdatedFormat) +} + +// isOld will return true if the host file has not been updated since seven +// days. +func (hb *Blockd) isOld() bool { + oneWeek := 7 * 24 * time.Hour + lastWeek := time.Now().Add(-1 * oneWeek) + + return hb.lastUpdated.Before(lastWeek) +} + +func (hb *Blockd) update() (err error) { + if !hb.isOld() { + return nil + } + + var ( + logp = "Blockd.update" + + res *http.Response + body []byte + errClose error + ) + + fmt.Printf("%s %s: updating ...\n", logp, hb.Name) + + err = os.MkdirAll(filepath.Dir(hb.file), 0700) + if err != nil { + return fmt.Errorf("%s %s: %w", logp, hb.Name, err) + } + + res, err = http.Get(hb.URL) + if err != nil { + return fmt.Errorf("%s %s: %w", logp, hb.Name, err) + } + defer func() { + errClose = res.Body.Close() + if errClose != nil { + log.Printf("%s %q: %s", logp, hb.Name, err) + } + }() + + body, err = io.ReadAll(res.Body) + if err != nil { + return fmt.Errorf("%s %q: %w", logp, hb.Name, err) + } + + body = bytes.ReplaceAll(body, []byte("\r\n"), []byte("\n")) + + if hb.IsEnabled { + err = os.WriteFile(hb.file, body, 0644) + } else { + err = os.WriteFile(hb.fileDisabled, body, 0644) + } + if err != nil { + return fmt.Errorf("%s %q: %w", logp, hb.Name, err) + } + + hb.lastUpdated = time.Now() + hb.LastUpdated = hb.lastUpdated.Format(lastUpdatedFormat) + + return nil +} diff --git a/blockd_test.go b/blockd_test.go new file mode 100644 index 0000000..f1d6abf --- /dev/null +++ b/blockd_test.go @@ -0,0 +1,104 @@ +// SPDX-FileCopyrightText: 2020 M. Shulhan +// SPDX-License-Identifier: GPL-3.0-or-later + +package rescached + +import ( + "os" + "path/filepath" + "testing" + + "github.com/shuLhan/share/lib/test" +) + +func TestBlockd_init(t *testing.T) { + type testCase struct { + desc string + hb Blockd + exp Blockd + } + + var ( + testDirBase = t.TempDir() + pathDirBlock = filepath.Join(testDirBase, dirBlock) + fileEnabled = "fileEnabled" + fileDisabled = "fileDisabled" + fileNotExist = "fileNotExist" + hostsFileEnabled = filepath.Join(pathDirBlock, fileEnabled) + hostsFileDisabled = filepath.Join(pathDirBlock, "."+fileDisabled) + + fiEnabled os.FileInfo + fiDisabled os.FileInfo + cases []testCase + c testCase + err error + ) + + err = os.MkdirAll(pathDirBlock, 0700) + if err != nil { + t.Fatal(err) + } + + err = os.WriteFile(hostsFileEnabled, []byte("127.0.0.2 localhost"), 0600) + if err != nil { + t.Fatal(err) + } + err = os.WriteFile(hostsFileDisabled, []byte("127.0.0.2 localhost"), 0600) + if err != nil { + t.Fatal(err) + } + + fiEnabled, err = os.Stat(hostsFileEnabled) + if err != nil { + t.Fatal(err) + } + fiDisabled, err = os.Stat(hostsFileDisabled) + if err != nil { + t.Fatal(err) + } + + cases = []testCase{{ + desc: "With hosts block file enabled", + hb: Blockd{ + Name: fileEnabled, + }, + exp: Blockd{ + Name: fileEnabled, + lastUpdated: fiEnabled.ModTime(), + LastUpdated: fiEnabled.ModTime().Format(lastUpdatedFormat), + file: hostsFileEnabled, + fileDisabled: filepath.Join(pathDirBlock, "."+fileEnabled), + IsEnabled: true, + isFileExist: true, + }, + }, { + desc: "With hosts block file disabled", + hb: Blockd{ + Name: fileDisabled, + }, + exp: Blockd{ + Name: fileDisabled, + lastUpdated: fiDisabled.ModTime(), + LastUpdated: fiDisabled.ModTime().Format(lastUpdatedFormat), + file: filepath.Join(pathDirBlock, fileDisabled), + fileDisabled: hostsFileDisabled, + isFileExist: true, + }, + }, { + desc: "With hosts block file not exist", + hb: Blockd{ + Name: fileNotExist, + }, + exp: Blockd{ + Name: fileNotExist, + file: filepath.Join(pathDirBlock, fileNotExist), + fileDisabled: filepath.Join(pathDirBlock, "."+fileNotExist), + }, + }} + + for _, c = range cases { + c.hb.init(pathDirBlock) + + test.Assert(t, c.desc, c.exp, c.hb) + } +} diff --git a/client.go b/client.go index 24e7fb6..53e057b 100644 --- a/client.go +++ b/client.go @@ -40,7 +40,7 @@ func (cl *Client) BlockdDisable(blockdName string) (an interface{}, err error) { res = libhttp.EndpointResponse{} params = url.Values{} - hb *hostsBlock + hb *Blockd resb []byte ) @@ -70,7 +70,7 @@ func (cl *Client) BlockdEnable(blockdName string) (an interface{}, err error) { res = libhttp.EndpointResponse{} params = url.Values{} - hb *hostsBlock + hb *Blockd resb []byte ) @@ -101,7 +101,7 @@ func (cl *Client) BlockdUpdate(blockdName string) (an interface{}, err error) { params = url.Values{} res = libhttp.EndpointResponse{} - hb *hostsBlock + hb *Blockd resb []byte ) diff --git a/environment.go b/environment.go index b5c226c..1dcd2c1 100644 --- a/environment.go +++ b/environment.go @@ -76,8 +76,8 @@ type Environment struct { FileResolvConf string `ini:"rescached::file.resolvconf"` WUIListen string `ini:"rescached::wui.listen"` - HostsBlocks map[string]*hostsBlock `ini:"block.d"` - hostsBlocksFile map[string]*dns.HostsFile + HostBlockd map[string]*Blockd `ini:"block.d"` + hostBlockdFile map[string]*dns.HostsFile // The options for WUI HTTP server. HttpdOptions *libhttp.ServerOptions `json:"-"` @@ -126,8 +126,8 @@ func newEnvironment(dirBase, fileConfig string) *Environment { pathDirZone: filepath.Join(dirBase, dirZone), pathFileCaches: filepath.Join(dirBase, dirCaches, fileCaches), - fileConfig: filepath.Join(dirBase, fileConfig), - hostsBlocksFile: make(map[string]*dns.HostsFile), + fileConfig: filepath.Join(dirBase, fileConfig), + hostBlockdFile: make(map[string]*dns.HostsFile), HttpdOptions: &libhttp.ServerOptions{ Memfs: mfsWww, Address: defWuiAddress, @@ -190,9 +190,9 @@ func (env *Environment) init() (err error) { func (env *Environment) initHostsBlock() { var ( - hb *hostsBlock + hb *Blockd ) - for _, hb = range env.HostsBlocks { + for _, hb = range env.HostBlockd { hb.init(env.pathDirBlock) } } @@ -230,7 +230,7 @@ func (env *Environment) save(file string) (in *ini.Ini, err error) { var ( logp = "save" - hb *hostsBlock + hb *Blockd vstr string ) @@ -247,7 +247,7 @@ func (env *Environment) save(file string) (in *ini.Ini, err error) { in.Set(sectionNameRescached, "", keyDebug, strconv.Itoa(env.Debug)) in.Set(sectionNameRescached, "", keyWUIListen, strings.TrimSpace(env.WUIListen)) - for _, hb = range env.HostsBlocks { + for _, hb = range env.HostBlockd { in.Set(sectionNameBlockd, hb.Name, keyName, hb.Name) in.Set(sectionNameBlockd, hb.Name, keyUrl, hb.URL) } diff --git a/environment_test.go b/environment_test.go index 4c3393e..99d0950 100644 --- a/environment_test.go +++ b/environment_test.go @@ -73,16 +73,16 @@ func TestLoadEnvironment(t *testing.T) { fileConfig: filepath.Join(testDirBase, "/etc/rescached/rescached.cfg"), WUIListen: "127.0.0.1:5381", - HostsBlocks: map[string]*hostsBlock{ - "pgl.yoyo.org": &hostsBlock{ + HostBlockd: map[string]*Blockd{ + "pgl.yoyo.org": &Blockd{ Name: "pgl.yoyo.org", URL: `http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext`, }, - "winhelp2002.mvps.org": &hostsBlock{ + "winhelp2002.mvps.org": &Blockd{ Name: "winhelp2002.mvps.org", URL: `http://winhelp2002.mvps.org/hosts.txt`, }, - "someonewhocares.org": &hostsBlock{ + "someonewhocares.org": &Blockd{ Name: "someonewhocares.org", URL: `http://someonewhocares.org/hosts/hosts`, }, @@ -120,7 +120,7 @@ func TestLoadEnvironment(t *testing.T) { test.Assert(t, "LoadEnvironment", expEnv, gotEnv) - gotEnv.HostsBlocks["test"] = &hostsBlock{ + gotEnv.HostBlockd["test"] = &Blockd{ Name: "test", URL: "http://someurl", } diff --git a/hosts_block.go b/hosts_block.go deleted file mode 100644 index dc65464..0000000 --- a/hosts_block.go +++ /dev/null @@ -1,148 +0,0 @@ -// SPDX-FileCopyrightText: 2020 M. Shulhan -// SPDX-License-Identifier: GPL-3.0-or-later - -package rescached - -import ( - "bytes" - "fmt" - "io" - "log" - "net/http" - "os" - "path/filepath" - "time" -) - -const ( - lastUpdatedFormat = "2006-01-02 15:04:05 MST" -) - -type hostsBlock struct { - lastUpdated time.Time - - Name string `ini:"::name"` // Derived from hostname in URL. - URL string `ini:"::url"` - - file string - fileDisabled string - LastUpdated string - - IsEnabled bool // True if the hosts file un-hidden in block.d directory. - isFileExist bool // True if the file exist and enabled or disabled. -} - -// disable the hosts block by prefixing the file name with single dot. -func (hb *hostsBlock) disable() (err error) { - err = os.Rename(hb.file, hb.fileDisabled) - if err != nil { - return fmt.Errorf("disable: %w", err) - } - hb.IsEnabled = false - return nil -} - -// enable the hosts block file by removing the dot prefix from file name. -func (hb *hostsBlock) enable() (err error) { - if hb.isFileExist { - err = os.Rename(hb.fileDisabled, hb.file) - } else { - err = os.WriteFile(hb.file, []byte(""), 0600) - } - if err != nil { - return fmt.Errorf("enable: %w", err) - } - hb.IsEnabled = true - hb.isFileExist = true - return nil -} - -func (hb *hostsBlock) init(pathDirBlock string) { - var ( - fi os.FileInfo - err error - ) - - hb.file = filepath.Join(pathDirBlock, hb.Name) - hb.fileDisabled = filepath.Join(pathDirBlock, "."+hb.Name) - - fi, err = os.Stat(hb.file) - if err != nil { - hb.IsEnabled = false - - fi, err = os.Stat(hb.fileDisabled) - if err != nil { - return - } - - hb.isFileExist = true - } else { - hb.IsEnabled = true - hb.isFileExist = true - } - - hb.lastUpdated = fi.ModTime() - hb.LastUpdated = hb.lastUpdated.Format(lastUpdatedFormat) -} - -// isOld will return true if the host file has not been updated since seven -// days. -func (hb *hostsBlock) isOld() bool { - oneWeek := 7 * 24 * time.Hour - lastWeek := time.Now().Add(-1 * oneWeek) - - return hb.lastUpdated.Before(lastWeek) -} - -func (hb *hostsBlock) update() (err error) { - if !hb.isOld() { - return nil - } - - var ( - logp = "hostsBlock.update" - - res *http.Response - body []byte - errClose error - ) - - fmt.Printf("%s %s: updating ...\n", logp, hb.Name) - - err = os.MkdirAll(filepath.Dir(hb.file), 0700) - if err != nil { - return fmt.Errorf("%s %s: %w", logp, hb.Name, err) - } - - res, err = http.Get(hb.URL) - if err != nil { - return fmt.Errorf("%s %s: %w", logp, hb.Name, err) - } - defer func() { - errClose = res.Body.Close() - if errClose != nil { - log.Printf("%s %q: %s", logp, hb.Name, err) - } - }() - - body, err = io.ReadAll(res.Body) - if err != nil { - return fmt.Errorf("%s %q: %w", logp, hb.Name, err) - } - - body = bytes.ReplaceAll(body, []byte("\r\n"), []byte("\n")) - - if hb.IsEnabled { - err = os.WriteFile(hb.file, body, 0644) - } else { - err = os.WriteFile(hb.fileDisabled, body, 0644) - } - if err != nil { - return fmt.Errorf("%s %q: %w", logp, hb.Name, err) - } - - hb.lastUpdated = time.Now() - hb.LastUpdated = hb.lastUpdated.Format(lastUpdatedFormat) - - return nil -} diff --git a/hosts_block_test.go b/hosts_block_test.go deleted file mode 100644 index 18652fc..0000000 --- a/hosts_block_test.go +++ /dev/null @@ -1,104 +0,0 @@ -// SPDX-FileCopyrightText: 2020 M. Shulhan -// SPDX-License-Identifier: GPL-3.0-or-later - -package rescached - -import ( - "os" - "path/filepath" - "testing" - - "github.com/shuLhan/share/lib/test" -) - -func TestHostsBlock_init(t *testing.T) { - type testCase struct { - desc string - hb hostsBlock - exp hostsBlock - } - - var ( - testDirBase = t.TempDir() - pathDirBlock = filepath.Join(testDirBase, dirBlock) - fileEnabled = "fileEnabled" - fileDisabled = "fileDisabled" - fileNotExist = "fileNotExist" - hostsFileEnabled = filepath.Join(pathDirBlock, fileEnabled) - hostsFileDisabled = filepath.Join(pathDirBlock, "."+fileDisabled) - - fiEnabled os.FileInfo - fiDisabled os.FileInfo - cases []testCase - c testCase - err error - ) - - err = os.MkdirAll(pathDirBlock, 0700) - if err != nil { - t.Fatal(err) - } - - err = os.WriteFile(hostsFileEnabled, []byte("127.0.0.2 localhost"), 0600) - if err != nil { - t.Fatal(err) - } - err = os.WriteFile(hostsFileDisabled, []byte("127.0.0.2 localhost"), 0600) - if err != nil { - t.Fatal(err) - } - - fiEnabled, err = os.Stat(hostsFileEnabled) - if err != nil { - t.Fatal(err) - } - fiDisabled, err = os.Stat(hostsFileDisabled) - if err != nil { - t.Fatal(err) - } - - cases = []testCase{{ - desc: "With hosts block file enabled", - hb: hostsBlock{ - Name: fileEnabled, - }, - exp: hostsBlock{ - Name: fileEnabled, - lastUpdated: fiEnabled.ModTime(), - LastUpdated: fiEnabled.ModTime().Format(lastUpdatedFormat), - file: hostsFileEnabled, - fileDisabled: filepath.Join(pathDirBlock, "."+fileEnabled), - IsEnabled: true, - isFileExist: true, - }, - }, { - desc: "With hosts block file disabled", - hb: hostsBlock{ - Name: fileDisabled, - }, - exp: hostsBlock{ - Name: fileDisabled, - lastUpdated: fiDisabled.ModTime(), - LastUpdated: fiDisabled.ModTime().Format(lastUpdatedFormat), - file: filepath.Join(pathDirBlock, fileDisabled), - fileDisabled: hostsFileDisabled, - isFileExist: true, - }, - }, { - desc: "With hosts block file not exist", - hb: hostsBlock{ - Name: fileNotExist, - }, - exp: hostsBlock{ - Name: fileNotExist, - file: filepath.Join(pathDirBlock, fileNotExist), - fileDisabled: filepath.Join(pathDirBlock, "."+fileNotExist), - }, - }} - - for _, c = range cases { - c.hb.init(pathDirBlock) - - test.Assert(t, c.desc, c.exp, c.hb) - } -} diff --git a/httpd.go b/httpd.go index 3c819bf..3f8964d 100644 --- a/httpd.go +++ b/httpd.go @@ -306,13 +306,13 @@ func (srv *Server) httpApiBlockdDisable(epr *libhttp.EndpointRequest) (resBody [ var ( res = libhttp.EndpointResponse{} - hb *hostsBlock + hb *Blockd hbName string ) hbName = strings.ToLower(epr.HttpRequest.Form.Get(paramNameName)) - hb = srv.env.HostsBlocks[hbName] + hb = srv.env.HostBlockd[hbName] if hb == nil { res.Code = http.StatusBadRequest res.Message = fmt.Sprintf("hosts block.d name not found: %s", hbName) @@ -340,13 +340,13 @@ func (srv *Server) httpApiBlockdEnable(epr *libhttp.EndpointRequest) (resBody [] var ( res = libhttp.EndpointResponse{} - hb *hostsBlock + hb *Blockd hbName string ) hbName = strings.ToLower(epr.HttpRequest.Form.Get(paramNameName)) - hb = srv.env.HostsBlocks[hbName] + hb = srv.env.HostBlockd[hbName] if hb == nil { res.Code = http.StatusBadRequest res.Message = fmt.Sprintf("hosts block.d name not found: %s", hbName) @@ -388,13 +388,13 @@ func (srv *Server) httpApiBlockdUpdate(epr *libhttp.EndpointRequest) (resBody [] logp = "httpApiBlockdUpdate" res = libhttp.EndpointResponse{} - hb *hostsBlock + hb *Blockd hbName string ) hbName = strings.ToLower(epr.HttpRequest.Form.Get(paramNameName)) - hb = srv.env.HostsBlocks[hbName] + hb = srv.env.HostBlockd[hbName] if hb == nil { res.Code = http.StatusBadRequest res.Message = fmt.Sprintf("%s: unknown hosts block.d name: %s", logp, hbName) @@ -562,20 +562,20 @@ func (srv *Server) httpApiEnvironmentUpdate(epr *libhttp.EndpointRequest) (resBo // apiHostsBlockUpdate set the HostsBlock to be enabled or disabled. // // If its status changes to enabled, unhide the hosts block file, populate the -// hosts back to caches, and add it to list of hostsBlocksFile. +// hosts back to caches, and add it to list of hostBlockdFile. // // If its status changes to disabled, remove the hosts from caches, hide it, -// and remove it from list of hostsBlocksFile. +// and remove it from list of hostBlockdFile. func (srv *Server) apiHostsBlockUpdate(epr *libhttp.EndpointRequest) (resBody []byte, err error) { var ( - res = libhttp.EndpointResponse{} - hostsBlocks = make(map[string]*hostsBlock, 0) + res = libhttp.EndpointResponse{} + hostBlockd = make(map[string]*Blockd, 0) - hbx *hostsBlock - hby *hostsBlock + hbx *Blockd + hby *Blockd ) - err = json.Unmarshal(epr.RequestBody, &hostsBlocks) + err = json.Unmarshal(epr.RequestBody, &hostBlockd) if err != nil { res.Code = http.StatusBadRequest res.Message = err.Error() @@ -584,8 +584,8 @@ func (srv *Server) apiHostsBlockUpdate(epr *libhttp.EndpointRequest) (resBody [] res.Code = http.StatusInternalServerError - for _, hbx = range hostsBlocks { - for _, hby = range srv.env.HostsBlocks { + for _, hbx = range hostBlockd { + for _, hby = range srv.env.HostBlockd { if hbx.Name != hby.Name { continue } @@ -594,13 +594,13 @@ func (srv *Server) apiHostsBlockUpdate(epr *libhttp.EndpointRequest) (resBody [] } if hbx.IsEnabled { - err = srv.hostsBlockEnable(hby) + err = srv.blockdEnable(hby) if err != nil { res.Message = err.Error() return nil, &res } } else { - err = srv.hostsBlockDisable(hby) + err = srv.blockdDisable(hby) if err != nil { res.Message = err.Error() return nil, &res @@ -618,14 +618,14 @@ func (srv *Server) apiHostsBlockUpdate(epr *libhttp.EndpointRequest) (resBody [] } res.Code = http.StatusOK - res.Data = hostsBlocks + res.Data = hostBlockd return json.Marshal(&res) } -func (srv *Server) hostsBlockEnable(hb *hostsBlock) (err error) { +func (srv *Server) blockdEnable(hb *Blockd) (err error) { var ( - logp = "hostsBlockEnable" + logp = "blockdEnable" hfile *dns.HostsFile ) @@ -650,19 +650,19 @@ func (srv *Server) hostsBlockEnable(hb *hostsBlock) (err error) { return fmt.Errorf("%s: %w", logp, err) } - srv.env.hostsBlocksFile[hfile.Name] = hfile + srv.env.hostBlockdFile[hfile.Name] = hfile return nil } -func (srv *Server) hostsBlockDisable(hb *hostsBlock) (err error) { +func (srv *Server) blockdDisable(hb *Blockd) (err error) { var ( - logp = "hostsBlockDisable" + logp = "blockdDisable" hfile *dns.HostsFile ) - hfile = srv.env.hostsBlocksFile[hb.Name] + hfile = srv.env.hostBlockdFile[hb.Name] if hfile == nil { return fmt.Errorf("%s: unknown hosts block: %q", logp, hb.Name) } @@ -674,7 +674,7 @@ func (srv *Server) hostsBlockDisable(hb *hostsBlock) (err error) { return fmt.Errorf("%s: %w", logp, err) } - delete(srv.env.hostsBlocksFile, hfile.Name) + delete(srv.env.hostBlockdFile, hfile.Name) return nil } diff --git a/rescached.go b/rescached.go index 694f6b6..f8caf05 100644 --- a/rescached.go +++ b/rescached.go @@ -63,7 +63,7 @@ func (srv *Server) Start() (err error) { logp = "Start" fcaches *os.File - hb *hostsBlock + hb *Blockd hfile *dns.HostsFile zone *dns.Zone answers []*dns.Answer @@ -99,7 +99,7 @@ func (srv *Server) Start() (err error) { return err } - for _, hb = range srv.env.HostsBlocks { + for _, hb = range srv.env.HostBlockd { if !hb.IsEnabled { continue } @@ -114,7 +114,7 @@ func (srv *Server) Start() (err error) { return fmt.Errorf("%s: %w", logp, err) } - srv.env.hostsBlocksFile[hfile.Name] = hfile + srv.env.hostBlockdFile[hfile.Name] = hfile } srv.env.HostsFiles, err = dns.LoadHostsDir(srv.env.pathDirHosts) -- cgit v1.3