aboutsummaryrefslogtreecommitdiff
path: root/cmd/resolver
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/resolver')
-rw-r--r--cmd/resolver/main.go28
-rw-r--r--cmd/resolver/resolver.go27
2 files changed, 53 insertions, 2 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go
index f2d4baf..a3ecbe5 100644
--- a/cmd/resolver/main.go
+++ b/cmd/resolver/main.go
@@ -15,6 +15,7 @@ import (
// List of valid commands.
const (
+ cmdBlockd = "block.d"
cmdCaches = "caches"
cmdEnv = "env"
cmdQuery = "query"
@@ -58,6 +59,26 @@ func main() {
rsol.cmd = strings.ToLower(args[0])
switch rsol.cmd {
+ case cmdBlockd:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s: missing sub command", cmdBlockd)
+ }
+
+ subCmd = strings.ToLower(args[0])
+
+ switch subCmd {
+ case subCmdUpdate:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing argument", rsol.cmd, subCmd)
+ }
+ err = rsol.blockdUpdate(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s %s: %s", rsol.cmd, subCmd, err)
+ }
+ }
+
case cmdCaches:
args = args[1:]
if len(args) == 0 {
@@ -178,6 +199,13 @@ query <domain / ip-address> [type] [class]
Valid class are either IN, CS, HS.
Default value is IN.
+block.d update <name>
+
+ Fetch the latest hosts file from remote block.d URL defined by
+ its name.
+ On success, the hosts file will be updated and the server will be
+ restarted.
+
caches
Fetch and print all caches from rescached server.
diff --git a/cmd/resolver/resolver.go b/cmd/resolver/resolver.go
index 697953d..76c5a13 100644
--- a/cmd/resolver/resolver.go
+++ b/cmd/resolver/resolver.go
@@ -45,6 +45,31 @@ type resolver struct {
insecure bool
}
+// blockdUpdate fetch the latest hosts file from remote block.d URL defined by
+// its name.
+func (rsol *resolver) blockdUpdate(blockdName string) (err error) {
+ var (
+ resc = rsol.newRescachedClient()
+
+ hb interface{}
+ hbjson []byte
+ )
+
+ hb, err = resc.BlockdUpdate(blockdName)
+ if err != nil {
+ return err
+ }
+
+ hbjson, err = json.MarshalIndent(hb, "", " ")
+ if err != nil {
+ return err
+ }
+
+ fmt.Println(string(hbjson))
+
+ return nil
+}
+
// doCmdCaches call the rescached HTTP API to fetch all caches.
func (rsol *resolver) doCmdCaches() {
var (
@@ -252,10 +277,8 @@ func (rsol *resolver) doCmdQuery(args []string) {
}
}
-//
// initSystemResolver read the system resolv.conf to create fallback DNS
// resolver.
-//
func (rsol *resolver) initSystemResolver() (err error) {
var (
logp = "initSystemResolver"