Created
August 12, 2017 15:22
-
-
Save Thomas2500/5fba2760204c0efc960ce6ca1ddf89eb to your computer and use it in GitHub Desktop.
PowerDNS Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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