From 290311fca4e195a17820d02f17af89d811d223e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20T=C3=A4ffner?= Date: Sat, 23 Jan 2016 01:37:54 +0100 Subject: [PATCH] I hate git :D Forgot to run git add --- .../classes/cron.d/550-bind_dnssec.inc.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 server/lib/classes/cron.d/550-bind_dnssec.inc.php diff --git a/server/lib/classes/cron.d/550-bind_dnssec.inc.php b/server/lib/classes/cron.d/550-bind_dnssec.inc.php new file mode 100644 index 0000000000..ae01b8b4ed --- /dev/null +++ b/server/lib/classes/cron.d/550-bind_dnssec.inc.php @@ -0,0 +1,86 @@ +uses("getconf,tpl"); + + //* load the server configuration options + $dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns'); + + //TODO : change this when distribution information has been integrated into server record + $filespre = (file_exists('/etc/gentoo-release')) ? 'pri/' : 'pri.'; + + $soas = $app->db->queryAllRecords('SELECT * FROM dns_soa WHERE dnssec_wanted=\'Y\' AND dnssec_initialized=\'Y\' AND dnssec_last_signed < '.(time()-(3600*24*5-900))); //Resign zones every 5 days (expiry is 16 days so we have enough safety, 15 minutes tolerance) + + while ($data = next($soas)) { + $domain = substr($data['origin'], 0, strlen($data['origin'])-1); + if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) return false; + + $zonefile = file_get_contents($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain); + $keycount=0; + foreach (glob($dns_config['bind_zonefiles_dir'].'/K'.$domain.'*.key') as $keyfile) { + $includeline = '$INCLUDE '.basename($keyfile); + if (!preg_match('@'.preg_quote($includeline).'@', $zonefile)) $zonefile .= "\n".$includeline."\n"; + $keycount++; + } + if ($keycount != 2) $app->log('DNSSEC Warning: There are more or less than 2 keyfiles for zone '.$domain, LOGLEVEL_WARN); + file_put_contents($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain, $zonefile); + + //Sign the zone and set it valid for max. 16 days + exec('cd '.escapeshellcmd($dns_config['bind_zonefiles_dir']).';'. + '/usr/sbin/dnssec-signzone -A -e +1382400 -3 $(head -c 1000 /dev/random | sha1sum | cut -b 1-16) -N increment -o '.escapeshellcmd($domain).' -t '.$filespre.escapeshellcmd($domain)); + + //Write Data back ino DB + $dnssecdata = "DS-Records:\n".file_get_contents($dns_config['bind_zonefiles_dir'].'/dsset-'.$domain.'.'); + $dnssecdata .= "\n------------------------------------\n\nDNSKEY-Records:\n"; + foreach (glob($dns_config['bind_zonefiles_dir'].'/K'.$domain.'*.key') as $keyfile) { + $dnssecdata .= file_get_contents($keyfile)."\n\n"; + } + + $app->db->query('UPDATE dns_soa SET dnssec_info=\''.$dnssecdata.'\', dnssec_initialized=\'Y\', dnssec_last_signed=\''.time().'\' WHERE id='.$data['id']); + } + + parent::onRunJob(); + } + +} + +?> -- GitLab