diff options
author | Erich Eckner <git@eckner.net> | 2019-04-01 21:12:35 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-04-01 21:12:35 +0200 |
commit | 77d4ea28c7aaa960f4e201cd88c9d5e5a074df9b (patch) | |
tree | 6c00d950f06991a03e5ed5cb4d4cbcdca9b91f56 /ddns-status.php | |
parent | 9c19bdbf7d75c971df449923e31272efa610430c (diff) | |
download | ddns-77d4ea28c7aaa960f4e201cd88c9d5e5a074df9b.tar.xz |
ddns-status.php new
Diffstat (limited to 'ddns-status.php')
-rw-r--r-- | ddns-status.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/ddns-status.php b/ddns-status.php new file mode 100644 index 0000000..5c42ca7 --- /dev/null +++ b/ddns-status.php @@ -0,0 +1,108 @@ +<?php + +$pin = popen('dig @127.0.0.1 ddns.eckner.net AXFR', 'r'); + +if (!$pin) + die(); + +$found = false; +$axfr = array(); +while (($line = fgets($pin)) !== false) { + $line = trim($line); + if (substr($line, 0, 1) == ';' || $line == '') + continue; + + $line = preg_split("/[\s]+/", $line); + + if ($line[0] == 'pool32.ddns.eckner.net.') + continue; + + if ($line[2] != 'IN') + continue; + + if ($line[3] == 'A') + $axfr[$line[0]][$line[3]] = "IPv4"; + if ($line[3] == 'AAAA') + $axfr[$line[0]][$line[3]] = "IPv6"; + if ($_SERVER['REMOTE_ADDR'] == $line[4]) + $found = true; +} +pclose($pin); + +if (! $found) + die(); + +$hosts = explode( + "\n", + trim( + shell_exec( + 'cut -d" " -f2 < /srv/http/vhosts/eckner.net/ddns/tokens' + ) + ) +); + +$filters = explode( + "\n", + shell_exec( + 'cut -d" " -f1 < /srv/http/vhosts/eckner.net/ddns/ip-filters' + ) . "v4\nv6" +); + +sort($filters); +sort($hosts); + +function print_existence($prefix, $host) { + global $axfr; + if (!array_key_exists($host . '.ddns.eckner.net.', $axfr)) { + print $prefix . "<font color=\"ff0000\">\n"; + print $prefix . " Nö\n"; + print $prefix . "</font>\n"; + return; + } + print $prefix . "<font color=\"00ff00\">\n"; + print $prefix . " " . implode(' & ', $axfr[$host . '.ddns.eckner.net.']) . "\n"; + print $prefix . "</font>\n"; +} + +print "<html>\n"; +print " <head>\n"; +print " <title>\n"; +print " ddns status\n"; +print " </title>\n"; +print " </head>\n"; +print " <body>\n"; +print " <table>\n"; + +print " <tr>\n"; +print " <th>\n"; +print " Host\n"; +print " </th>\n"; +print " <th>\n"; +print " \n"; +print " </th>\n"; +foreach ($filters as $filter) { + print " <th>\n"; + print " " . $filter . "\n"; + print " </th>\n"; +} +print " </tr>\n"; + +foreach ($hosts as $host) { + print " <tr>\n"; + print " <td>\n"; + print " " . $host . "\n"; + print " </td>\n"; + print " <td>\n"; + print_existence(' ', $host); + print " </td>\n"; + foreach ($filters as $filter) { + print " <td>\n"; + print_existence(' ', $host . '.' . $filter); + print " </td>\n"; + } + print " </tr>\n"; +} + +print " </table>\n"; +print " </body>\n"; +print "</html>"; |