Skip to content

Instantly share code, notes, and snippets.

@Thomas2500
Created August 12, 2017 15:22
Show Gist options
  • Save Thomas2500/5fba2760204c0efc960ce6ca1ddf89eb to your computer and use it in GitHub Desktop.
Save Thomas2500/5fba2760204c0efc960ce6ca1ddf89eb to your computer and use it in GitHub Desktop.
PowerDNS Update
<?php
// SQL-class from https://git.bella.network/unterhaltungsbox/class-templates/blob/master/class/SQL.class.php
require "SQL.class.php";
$SQL = new SQL("localhost", "<username>", "<password>", "<database>");
if ($_GET["host"] == "bella.ml") {
// Check current record if update is needed
$ip = $SQL->single("SELECT `content` FROM `records` WHERE `name` = 'bella.ml' AND `type` = 'A'");
if ($ip == $_SERVER["REMOTE_ADDR"]) {
exit("No update needed");
}
// -- BELLA.ML --
// Update A record
$a = $SQL->query("UPDATE `records` SET `content` = :addr WHERE `name` = 'bella.ml' AND `type` = 'A'",
[ "addr" => $_SERVER["REMOTE_ADDR"] ]);
// Update SOA-serial
$today = (int)date("Ymd") . "00";
$serial = $SQL->single("SELECT `content` FROM `records` WHERE `name` = 'bella.ml' AND `type` = 'SOA'");
preg_match("#\.network\. ([0-9]*) #", $serial, $matches);
$serial = (int)$matches[1];
if ($serial < $today) {
$serial = $today;
} else {
$serial++;
}
$SQL->query("UPDATE `records` SET `content` = :addr WHERE `name` = 'bella.ml' AND `type` = 'SOA'",
[ "addr" => "ns1.dynadns.eu dns.bella.network. " . $serial . " 3600 900 604800 60" ]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment