Browse Source

add an automatic RR generator

pull/2/head
Boian Bonev 9 months ago
committed by Ralph Ronnquist
parent
commit
a32b29a5d2
  1. 139
      generate-rr.php
  2. 2
      zonediff.sh

139
generate-rr.php

@ -0,0 +1,139 @@
#!/usr/bin/php -q
<?php
// this will check if /etc/nsd/mirror_list.txt differs, rm to force processing
$url='https://pkgmaster.devuan.org/mirror_list.txt';
$timeout=10; // seconds
$loc='/etc/nsd';
$zone='rr.devuan.org.work';
// end of config
$c=curl_init();
curl_setopt($c,CURLOPT_URL,$url);
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($c,CURLOPT_TIMEOUT,$timeout);
$r=curl_exec($c);
curl_close($c);
if ($r===false||trim($r)=='') {
echo "Could't get the mirror list\n";
exit;
}
$lr=@file_get_contents("{$loc}/mirror_list.txt");
if ($lr==$r) {
echo "No changes in mirrors, nothing to do...\n";
exit;
}
$m=[];
$ra=explode("\n\n",trim($r));
for ($i=0;$i<count($ra);$i++) {
$ma=explode("\n",trim($ra[$i]));
$me=[];
for ($j=0;$j<count($ma);$j++) {
$ea=explode(': ',$ma[$j],2);
$me[$ea[0]]=trim($ea[1]);
}
if (!isset($me['FQDN'])) {
echo "Skipping entry w/o FQDN:\n{$ra[$i]}\n";
continue;
}
if (!isset($me['Active'])) {
echo "Skipping entry w/o Active: {$me['FQDN']}\n";
continue;
}
if (!isset($me['DNSRR'])) {
echo "Skipping entry w/o DNSRR: {$me['FQDN']}\n";
continue;
}
if (!isset($me['BaseURL'])) {
echo "Skipping entry w/o BaseURL: {$me['FQDN']}\n";
continue;
}
if (strtolower($me['DNSRR'])!='yes') {
echo "Skipping entry not intended for DNSRR: {$me['FQDN']}\n";
continue;
}
if (strtolower($me['Active'])!='yes') {
echo "Skipping entry that is not active: {$me['FQDN']}\n";
continue;
}
if ($me['BaseURL']!=$me['FQDN']) {
echo "Warning: entry with non-standard base url: {$me['FQDN']}\n";
// should check if the mirror works with base url / when invoked via deb.devuan.org
//continue;
}
$v4=[];
$v4r=dns_get_record($me['FQDN'],DNS_A);
foreach ($v4r as $v)
if (isset($v['ip']))
$v4[]=$v['ip'];
$v6=[];
$v6r=dns_get_record($me['FQDN'],DNS_AAAA);
foreach ($v6r as $v)
if (isset($v['ipv6']))
$v6[]=$v['ipv6'];
$me['ipv4']=$v4;
$me['ipv6']=$v6;
$m[$me['FQDN']]=$me;
}
if (!isset($m['pkgmaster.devuan.org'])) {
echo "pkgmaster is not on the list, something went terribly wrong\n";
exit;
}
if (count($m)>1) // we have at least one active mirror, remove pkgmaster from the RR
unset($m['pkgmaster.devuan.org']);
$zonedata='';
foreach ($m as $me) {
$zonedata.="; {$me['FQDN']}\n";
foreach ($me['ipv4'] as $v4)
$zonedata.="deb IN A {$v4}\n";
foreach ($me['ipv6'] as $v6)
$zonedata.="deb IN AAAA {$v6}\n";
}
$z=@file_get_contents("{$loc}/{$zone}");
if ($z===false||trim($z)=='') {
echo "Invalid zone template: {$loc}/{$zone}\n";
exit;
}
if (false===strstr($z,'@zone@')) {
echo "Zone template {$loc}/{$zone} is missing @zone@ marker\n";
exit;
}
if (false===strstr($z,'@rr@')) {
echo "Zone template {$loc}/{$zone} is missing @rr@ marker\n";
exit;
}
$zr='';
$za=explode("\n",$z);
$drop=false;
foreach ($za as $ln=>$v) {
if (false!==strstr($v,'@zone@')) {
$nser=date('Ymd01');
$oser=(int)trim($v);
while ($nser<=$oser)
$nser++;
$za[$ln]=" {$nser} ; @zone@ serial number for this zone file";
}
if (false!==strstr($v,'@rr@'))
$drop=true;
if ($drop)
unset($za[$ln]);
}
if (false===file_put_contents("{$loc}/{$zone}",join("\n",$za)."\n; @rr@\n\n{$zonedata}\n")) {
echo "Error writing {$loc}/{$zone}, will retry on next run...\n";
exit;
}
file_put_contents("{$loc}/mirror_list.txt",$r);
echo "Reloading zone...\n";
//`nsd-control reload rr.devuan.org`

2
zonediff.sh

@ -14,7 +14,7 @@ if [ $(pwd) != /etc/nsd/GIT ]; then
exit 1
fi
for i in *.zone nsd.conf; do
for i in *.zone nsd.conf generate-rr.php; do
if [ -f ../${i} ]; then
${DIFF} -u ../${i} ${i}
fi

Loading…
Cancel
Save