#!/usr/bin/php
<?php 
require_once "/opt/zonemaster/includes/functions.php";
if ($argc < 4) {
    die("usage: {$argv['0']} <awscli-profile-name> <domain-name> <zone-id>\n");
}
$profile = $argv[1];
$domain = $argv[2];
$zoneid = escapeshellarg($argv[3]);
$aws = aws_client($profile);
$master = load_dns_entries("public", $domain);
$current = array();
$changes = array();
$types = array("A", "CNAME", "TXT");
$json = shell_exec("{$aws} route53 list-resource-record-sets --hosted-zone-id {$zoneid}");
$sets = json_decode($json, true);
foreach ($sets["ResourceRecordSets"] as $entry) {
    $type = $entry["Type"];
    $name = str_replace("\\052", "*", $entry["Name"]);
    $value = $entry["ResourceRecords"][0]["Value"];
    if (in_array($type, $types, true)) {
        $current[$type][substr($name, 0, -1)] = $value;
    }
}
foreach ($types as $type) {
    foreach ($master[$type] as $host => $value) {
        if ($host != $domain && strrpos($host, "." . $domain, -1 - strlen($domain)) === false) {
            continue;
        }
        if (!isset($current[$type][$host])) {
            $changes[] = aws_record_change("CREATE", $type, $host, $value);
#!/usr/bin/php
<?php 
require_once "/opt/zonemaster/includes/functions.php";
if ($argc < 3) {
    die("usage: {$argv['0']} <load-zone> <router-hostname[:port]> [debug]\n");
}
$inzone = $argv[1];
$router = $argv[2];
$debug = isset($argv[3]) && $argv[3] == "debug";
$master = load_dns_entries("internal", $inzone);
$mikrotik = mikrotik($router);
$data = shell_exec("{$mikrotik} ip dns export");
$data = str_replace("\\\r\n    ", "", $data);
$lines = explode("\n", $data);
$current = array();
$changes = array();
$types = array("A", "CNAME");
foreach ($lines as $line) {
    if (preg_match("#^add address=([0-9.]+) (disabled=(yes|no) )?name=([a-zA-Z0-9-_.]+)#", $line, $matches)) {
        if ($matches[3] != "yes") {
            $current[$matches[4]] = $matches[1];
        }
    }
}
foreach ($master["A"] as $host => $value) {
    if (strpos($host, "*") !== false) {
        continue;
    }
    if (!isset($current[$host])) {
        $changes[] = "ip dns static add address={$value} disabled=no name={$host} ttl=1d";
    } else {
#!/usr/bin/php
<?php 
require_once "/opt/zonemaster/includes/functions.php";
if ($argc < 5) {
    die("usage: {$argv['0']} <load-zone> <generate-zone> <bind9-zone-file> <internal/public>\n");
}
$inzone = $argv[1];
$outzone = $argv[2];
$file = $argv[3];
$type = $argv[4];
$master = load_dns_entries($type, $inzone);
$data = "";
foreach ($master["TXT"] as $host => $value) {
    $len = strlen($outzone);
    if (strrpos($host, "." . $outzone, -$len - 1) !== false) {
        $short = substr($host, 0, -$len - 1);
        $data .= sprintf("%-50s%-10s%s\n", $short, "IN TXT", $value);
    } else {
        if ($host == $outzone) {
            $data .= sprintf("%-50s%-10s%s\n", "@", "IN TXT", $value);
        }
    }
}
$data .= "\n";
foreach ($master["A"] as $host => $ip) {
    $len = strlen($outzone);
    if (strrpos($host, "." . $outzone, -$len - 1) !== false) {
        $short = substr($host, 0, -$len - 1);
        $data .= sprintf("%-50s%-10s%s\n", $short, "IN A", $ip);
    } else {
        if ($host == $outzone) {