Ejemplo n.º 1
0
func main() {
	flag.StringVar(&getIPCommand, "cmd", getIPCommand, "Command to get external IP")
	flag.StringVar(&zoneID, "zone", zoneID, "Cloudflare Zone ID")
	flag.StringVar(&name, "name", name, "DNS record to update")
	flag.StringVar(&authEmail, "email", authEmail, "Cloudflare Auth Email")
	flag.StringVar(&authKey, "key", authKey, "Cloudflare API Key")
	flag.IntVar(&ttl, "ttl", ttl, "DNS record TTL (seconds)")
	flag.DurationVar(&interval, "intv", interval, "External IP check interval")
	flag.Parse()

	if name == "" {
		fmt.Println("Option -name is mandatory")
		os.Exit(1)
	}
	if authEmail == "" {
		fmt.Println("Option -email is mandatory")
		os.Exit(1)
	}
	if authKey == "" {
		fmt.Println("Option -key is mandatory")
		os.Exit(1)
	}

	client := cfdns.NewClient(authEmail, authKey)
	main := suture.NewSimple("main")
	checker := newIPChecker(getIPCommand, interval)
	main.Add(checker)
	updater := newDNSUpdater(name, client, checker.changes)
	main.Add(updater)
	main.Serve()
}
Ejemplo n.º 2
0
func ExampleClient() {
	// Create a new Client
	client := cfdns.NewClient("*****@*****.**", "dc771129ae047c934adba2d1dc4fe184")

	// List all available zones
	zones, err := client.ListZones()
	if err != nil {
		panic(err)
	}

	// Find the "example.com" zone
	var exampleZone cfdns.Zone
	for _, zone := range zones {
		if zone.Name == "example.com" {
			exampleZone = zone
			break
		}
	}

	// If we found it ...
	if exampleZone.ID != "" {
		// ... create a new record "test.example.com A 192.168.0.2"
		if err := client.CreateDNSRecord(exampleZone.ID, "test.example.com", "A", "192.168.0.2"); err != nil {
			panic(err)
		}
	}
}