aboutsummaryrefslogtreecommitdiff
path: root/cmd/resolver
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/resolver')
-rw-r--r--cmd/resolver/main.go56
-rw-r--r--cmd/resolver/resolver.go64
2 files changed, 118 insertions, 2 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go
index 0678b21..9ffc60b 100644
--- a/cmd/resolver/main.go
+++ b/cmd/resolver/main.go
@@ -18,10 +18,14 @@ const (
cmdBlockd = "block.d"
cmdCaches = "caches"
cmdEnv = "env"
+ cmdHostsd = "hosts.d"
cmdQuery = "query"
- subCmdEnable = "enable"
+ subCmdCreate = "create"
+ subCmdDelete = "delete"
subCmdDisable = "disable"
+ subCmdEnable = "enable"
+ subCmdGet = "get"
subCmdRemove = "remove"
subCmdSearch = "search"
subCmdUpdate = "update"
@@ -154,6 +158,9 @@ func main() {
os.Exit(2)
}
+ case cmdHostsd:
+ rsol.doCmdHostsd(args[1:])
+
case cmdQuery:
args = args[1:]
if len(args) == 0 {
@@ -262,6 +269,20 @@ env update <path-to-file / "-">
If the argument is "-", the new environment is read from stdin.
If the environment is valid, the server will be restarted.
+hosts.d create <name>
+
+ Create new hosts file inside the hosts.d directory with specific file
+ name.
+
+hosts.d delete <name>
+
+ Delete hosts file inside the hosts.d directory by file name.
+
+hosts.d get <name>
+
+ Get the content of hosts file inside the hosts.d directory by file
+ name.
+
== Examples
@@ -314,5 +335,36 @@ Update the server environment from JSON file in /tmp/env.json,
Update the server environment by reading JSON from standard input,
- $ cat /tmp/env.json | resolver env update -`)
+ $ cat /tmp/env.json | resolver env update -
+
+Create new hosts file named "myhosts" inside the hosts.d directory,
+
+ $ resolver hosts.d create myhosts
+ OK
+
+Delete hosts file named "myhosts" inside the hosts.d directory,
+
+ $ resolver hosts.d delete myhosts
+ OK
+
+Get the content of hosts file named "myhosts" inside the hosts.d directory,
+
+ $ resolver hosts.d get myhosts
+ [
+ {
+ "Value": "127.0.0.1",
+ "Name": "localhost",
+ "Type": 1,
+ "Class": 1,
+ "TTL": 604800
+ },
+ {
+ "Value": "::1",
+ "Name": "localhost",
+ "Type": 28,
+ "Class": 1,
+ "TTL": 604800
+ }
+ ]
+`)
}
diff --git a/cmd/resolver/resolver.go b/cmd/resolver/resolver.go
index bdebe0d..47f5e15 100644
--- a/cmd/resolver/resolver.go
+++ b/cmd/resolver/resolver.go
@@ -242,6 +242,70 @@ func (rsol *resolver) doCmdEnvUpdate(fileOrStdin string) (err error) {
return nil
}
+func (rsol *resolver) doCmdHostsd(args []string) {
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s: missing argument", rsol.cmd)
+ }
+
+ var (
+ subCmd = strings.ToLower(args[0])
+
+ resc *rescached.Client
+ listrr []*dns.ResourceRecord
+ jsonb []byte
+ err error
+ )
+ switch subCmd {
+ case subCmdCreate:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing hosts name argument", rsol.cmd, subCmd)
+ }
+
+ resc = rsol.newRescachedClient()
+ _, err = resc.HostsdCreate(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s", err)
+ }
+ fmt.Println("OK")
+
+ case subCmdDelete:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing hosts name argument", rsol.cmd, subCmd)
+ }
+
+ resc = rsol.newRescachedClient()
+ _, err = resc.HostsdDelete(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s", err)
+ }
+ fmt.Println("OK")
+
+ case subCmdGet:
+ args = args[1:]
+ if len(args) == 0 {
+ log.Fatalf("resolver: %s %s: missing hosts name argument", rsol.cmd, subCmd)
+ }
+
+ resc = rsol.newRescachedClient()
+ listrr, err = resc.HostsdGet(args[0])
+ if err != nil {
+ log.Fatalf("resolver: %s", err)
+ }
+
+ jsonb, err = json.MarshalIndent(listrr, "", " ")
+ if err != nil {
+ log.Fatalf("resolver: %s", err)
+ }
+
+ fmt.Println(string(jsonb))
+
+ default:
+ log.Fatalf("resolver: %s: unknown sub command: %s", rsol.cmd, subCmd)
+ }
+}
+
func (rsol *resolver) doCmdQuery(args []string) {
var (
maxAttempts = defAttempts