|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
package dns |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"context" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"os" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"darvaza.org/core" |
|
|
|
|
"github.com/libdns/libdns" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Show shows current DNS entries
|
|
|
|
@ -15,15 +19,40 @@ func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
|
|
|
|
return core.Wrap(err, "GetRecords") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SortRecords(recs) |
|
|
|
|
return writeRecords(recs, os.Stdout) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func writeRecords(recs []libdns.Record, w io.Writer) error { |
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
|
|
for _, rr := range recs { |
|
|
|
|
_, _ = fmt.Printf("%s\t%v\tIN\t%s\t%s\t; %s\n", |
|
|
|
|
rr.Name, |
|
|
|
|
int(rr.TTL/time.Second), |
|
|
|
|
rr.Type, |
|
|
|
|
rr.Value, |
|
|
|
|
rr.ID) |
|
|
|
|
_ = fmtRecord(&buf, rr) |
|
|
|
|
_, _ = buf.WriteRune('\n') |
|
|
|
|
} |
|
|
|
|
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs)) |
|
|
|
|
|
|
|
|
|
_, err := buf.WriteTo(w) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func fmtRecord(w io.Writer, rr libdns.Record) error { |
|
|
|
|
ttl := int(rr.TTL / time.Second) |
|
|
|
|
if ttl < 1 { |
|
|
|
|
ttl = 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err := fmt.Fprintf(w, "%s\t%v\tIN\t%s\t%s", |
|
|
|
|
rr.Name, |
|
|
|
|
ttl, |
|
|
|
|
rr.Type, |
|
|
|
|
rr.Value) |
|
|
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
if rr.ID != "" { |
|
|
|
|
_, err = fmt.Fprintf(w, "\t; %s", rr.ID) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, _ = fmt.Printf("; %v records\n", len(recs)) |
|
|
|
|
return nil |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|