2016-06-19 11:33:25 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jessevdk/go-flags"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Verbose bool `long:"verbose" short:"v"`
|
|
|
|
|
|
|
|
Interface string `long:"interface" short:"i" value-name:"IFACE" description:"Use address from interface"`
|
|
|
|
InterfaceFamily Family `long:"interface-family"`
|
|
|
|
|
|
|
|
Server string `long:"server" value-name:"HOST[:PORT]"`
|
|
|
|
Timeout time.Duration `long:"timeout" value-name:"DURATION" default:"10s"`
|
|
|
|
TSIGName string `long:"tsig-name"`
|
|
|
|
TSIGSecret string `long:"tsig-secret" env:"TSIG_SECRET"`
|
|
|
|
TSIGAlgorithm TSIGAlgorithm `long:"tsig-algorithm" default:"hmac-sha1."`
|
|
|
|
|
|
|
|
Zone string `long:"zone" description:"Zone to update"`
|
|
|
|
Name string `long:"name" description:"Name to update"`
|
|
|
|
TTL int `long:"ttl" default:"60"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var options Options
|
|
|
|
|
|
|
|
if args, err := flags.Parse(&options); err != nil {
|
|
|
|
log.Fatalf("flags.Parse: %v", err)
|
|
|
|
os.Exit(1)
|
|
|
|
} else if len(args) > 0 {
|
|
|
|
log.Fatalf("Usage: no args")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
var update = Update{
|
2016-06-19 11:33:25 -05:00
|
|
|
ttl: options.TTL,
|
|
|
|
timeout: options.Timeout,
|
|
|
|
}
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
if err := update.Init(options.Name, options.Zone, options.Server); err != nil {
|
|
|
|
log.Fatalf("init: %v", err)
|
2016-06-19 11:33:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if options.TSIGName != "" {
|
|
|
|
log.Printf("using TSIG: %v (algo=%v)", options.TSIGName, options.TSIGAlgorithm)
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
update.InitTSIG(options.TSIGName, options.TSIGSecret, options.TSIGAlgorithm)
|
2016-06-19 11:33:25 -05:00
|
|
|
}
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
// addrs
|
|
|
|
var addrs = new(AddrSet)
|
|
|
|
|
2016-06-19 11:33:25 -05:00
|
|
|
if options.Interface == "" {
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
} else if err := addrs.ScanInterface(options.Interface, options.InterfaceFamily); err != nil {
|
|
|
|
log.Fatalf("addrs scan: %v", err)
|
2016-06-19 11:33:25 -05:00
|
|
|
}
|
|
|
|
|
2016-06-19 11:46:23 -05:00
|
|
|
// update
|
|
|
|
if err := update.Update(addrs, options.Verbose); err != nil {
|
2016-06-19 11:33:25 -05:00
|
|
|
log.Fatalf("update: %v", err)
|
|
|
|
}
|
|
|
|
}
|