aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-21 01:40:58 +0700
committerShulhan <ms@kilabit.info>2022-04-21 01:40:58 +0700
commit00ecc95e8af5d2e15927579894f2f92346453134 (patch)
tree49afb561c60f990506e81cadb7e98aec6935e149
parent26bbadb4ca1c38f2d34a722b0c7d9509135a7eb2 (diff)
downloadrescached-00ecc95e8af5d2e15927579894f2f92346453134.tar.xz
cmd/resolver: implement command to disable or enable hosts in block.d
The following command enable specific hosts in block.d by name: resolver block.d enable <name> and the following command disable it resolver block.d disable <name>
-rw-r--r--_doc/resolver.adoc12
-rw-r--r--_sys/usr/share/man/man1/resolver.1.gzbin2439 -> 2470 bytes
-rw-r--r--cmd/rescached/main.go2
-rw-r--r--cmd/resolver/main.go36
-rw-r--r--cmd/resolver/resolver.go48
5 files changed, 94 insertions, 4 deletions
diff --git a/_doc/resolver.adoc b/_doc/resolver.adoc
index d259983..d4eb5e9 100644
--- a/_doc/resolver.adoc
+++ b/_doc/resolver.adoc
@@ -94,6 +94,18 @@ List of valid types,
The "class" parameter is optional, its either IN (default), CS, or HS.
--
+block.d disable <name>::
++
+--
+Disable specific hosts on block.d.
+--
+
+block.d enable <name>::
++
+--
+Enable specific hosts on block.d.
+--
+
block.d update <name>::
+
--
diff --git a/_sys/usr/share/man/man1/resolver.1.gz b/_sys/usr/share/man/man1/resolver.1.gz
index 78211df..635cd25 100644
--- a/_sys/usr/share/man/man1/resolver.1.gz
+++ b/_sys/usr/share/man/man1/resolver.1.gz
Binary files differ
diff --git a/cmd/rescached/main.go b/cmd/rescached/main.go
index 069d126..52b9a44 100644
--- a/cmd/rescached/main.go
+++ b/cmd/rescached/main.go
@@ -108,7 +108,7 @@ func debugRuntime() {
func watchWww(env *rescached.Environment, running chan bool) {
var (
logp = "watchWww"
- tick = time.NewTicker(5 * time.Second)
+ tick = time.NewTicker(3 * time.Second)
isRunning = true
dw *memfs.DirWatcher
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go
index a3ecbe5..0678b21 100644
--- a/cmd/resolver/main.go
+++ b/cmd/resolver/main.go
@@ -20,9 +20,11 @@ const (
cmdEnv = "env"
cmdQuery = "query"
- subCmdSearch = "search"
- subCmdRemove = "remove"
- subCmdUpdate = "update"
+ subCmdEnable = "enable"
+ subCmdDisable = "disable"
+ subCmdRemove = "remove"
+ subCmdSearch = "search"
+ subCmdUpdate = "update"
)
func main() {
@@ -68,6 +70,26 @@ func main() {
subCmd = strings.ToLower(args[0])
switch subCmd {
+ case subCmdDisable:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing argument", rsol.cmd, subCmd)
+ }
+ err = rsol.blockdDisable(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s %s: %s", rsol.cmd, subCmd, err)
+ }
+
+ case subCmdEnable:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing argument", rsol.cmd, subCmd)
+ }
+ err = rsol.blockdEnable(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s %s: %s", rsol.cmd, subCmd, err)
+ }
+
case subCmdUpdate:
args = args[1:]
if len(args) == 0 {
@@ -199,6 +221,14 @@ query <domain / ip-address> [type] [class]
Valid class are either IN, CS, HS.
Default value is IN.
+block.d disable <name>
+
+ Disable specific hosts on block.d.
+
+block.d enable <name>
+
+ Enable specific hosts on block.d.
+
block.d update <name>
Fetch the latest hosts file from remote block.d URL defined by
diff --git a/cmd/resolver/resolver.go b/cmd/resolver/resolver.go
index 76c5a13..bdebe0d 100644
--- a/cmd/resolver/resolver.go
+++ b/cmd/resolver/resolver.go
@@ -45,6 +45,54 @@ type resolver struct {
insecure bool
}
+// blockdDisable disable specific hosts on block.d.
+func (rsol *resolver) blockdDisable(name string) (err error) {
+ var (
+ resc = rsol.newRescachedClient()
+
+ hb interface{}
+ hbjson []byte
+ )
+
+ hb, err = resc.BlockdDisable(name)
+ if err != nil {
+ return err
+ }
+
+ hbjson, err = json.MarshalIndent(hb, "", " ")
+ if err != nil {
+ return err
+ }
+
+ fmt.Println(string(hbjson))
+
+ return nil
+}
+
+// blockdEnable enable specific hosts on block.d.
+func (rsol *resolver) blockdEnable(name string) (err error) {
+ var (
+ resc = rsol.newRescachedClient()
+
+ hb interface{}
+ hbjson []byte
+ )
+
+ hb, err = resc.BlockdEnable(name)
+ if err != nil {
+ return err
+ }
+
+ hbjson, err = json.MarshalIndent(hb, "", " ")
+ if err != nil {
+ return err
+ }
+
+ fmt.Println(string(hbjson))
+
+ return nil
+}
+
// blockdUpdate fetch the latest hosts file from remote block.d URL defined by
// its name.
func (rsol *resolver) blockdUpdate(blockdName string) (err error) {