summaryrefslogtreecommitdiffstats
path: root/etc/inc/services.inc
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2013-07-02 16:15:03 -0400
committerjim-p <jimp@pfsense.org>2013-07-02 16:58:03 -0400
commit7c9da7be0c52a5838302fb9b3f89ddfdebfc2f82 (patch)
tree6570597ccc8d23349177e4dac6775723fc745747 /etc/inc/services.inc
parentbdba4fa76214dc8c73e679f6da1d346d1e77b4b2 (diff)
downloadpfsense-7c9da7be0c52a5838302fb9b3f89ddfdebfc2f82.zip
pfsense-7c9da7be0c52a5838302fb9b3f89ddfdebfc2f82.tar.gz
Add cached IP support to RFC2136, add GUI button to force update for single host.
Diffstat (limited to 'etc/inc/services.inc')
-rw-r--r--etc/inc/services.inc78
1 files changed, 59 insertions, 19 deletions
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index 85edc70..381d1b9 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -1940,7 +1940,7 @@ EOD;
return 0;
}
-function services_dnsupdate_process($int = "") {
+function services_dnsupdate_process($int = "", $updatehost = "", $forced = false) {
global $config, $g;
if(isset($config['system']['developerspew'])) {
$mt = microtime();
@@ -1949,18 +1949,24 @@ function services_dnsupdate_process($int = "") {
/* Dynamic DNS updating active? */
if (is_array($config['dnsupdates']['dnsupdate'])) {
+ $notify_text = "";
foreach ($config['dnsupdates']['dnsupdate'] as $i => $dnsupdate) {
if (!isset($dnsupdate['enable']))
continue;
if (!empty($int) && $int != $dnsupdate['interface'])
continue;
+ if (!empty($updatehost) && ($updatehost != $dnsupdate['host']))
+ continue;
/* determine interface name */
$if = get_real_interface($dnsupdate['interface']);
$wanip = get_interface_ip($dnsupdate['interface']);
$wanipv6 = get_interface_ipv6($dnsupdate['interface']);
- if ($wanip || $wanipv6) {
+ $cacheFile = "{$g['conf_path']}/dyndns_{$dnsupdate['interface']}_rfc2136_" . escapeshellarg($dnsupdate['host']) . "_{$dnsupdate['server']}.cache";
+ $currentTime = time();
+
+ if ($wanip || $wanipv6) {
$keyname = $dnsupdate['keyname'];
/* trailing dot */
if (substr($keyname, -1) != ".")
@@ -2004,31 +2010,65 @@ EOD;
$upinst = "";
if (!empty($dnsupdate['server']))
$upinst .= "server {$dnsupdate['server']}\n";
+
+ if (file_exists($cacheFile)) {
+ list($cachedipv4, $cacheTimev4) = explode("|", file_get_contents($cacheFile));
+ }
+ if (file_exists("{$cacheFile}.ipv6")) {
+ list($cachedipv6, $cacheTimev6) = explode("|", file_get_contents("{$cacheFile}.ipv6"));
+ }
+
+ // 25 Days
+ $maxCacheAgeSecs = 25 * 24 * 60 * 60;
+ $need_update = false;
/* Update IPv4 if we have it. */
if (is_ipaddrv4($wanip)) {
- $upinst .= "update delete {$dnsupdate['host']}. A\n";
- $upinst .= "update add {$dnsupdate['host']}. {$dnsupdate['ttl']} A {$wanip}\n";
- }
+ if (($wanip != $cachedipv4) || (($currentTime - $cacheTimev4) > $maxCacheAgeSecs) || $forced) {
+ $upinst .= "update delete {$dnsupdate['host']}. A\n";
+ $upinst .= "update add {$dnsupdate['host']}. {$dnsupdate['ttl']} A {$wanip}\n";
+ $notify_text .= sprintf(gettext("DynDNS updated IP Address (A) for {$dnsupdate['host']} on %s (%s) to %s"), convert_real_interface_to_friendly_descr($if), $if, $wanip) . "\n";
+ @file_put_contents($cacheFile, "{$wanip}|{$currentTime}");
+ log_error("phpDynDNS: updating cache file {$cacheFile}: {$wanip}");
+ $need_update = true;
+ } else {
+ log_error("phpDynDNS: Not updating {$dnsupdate['host']} A record because the IP address has not changed.");
+ }
+ } else
+ @unlink($cacheFile);
+
/* Update IPv6 if we have it. */
if (is_ipaddrv6($wanipv6)) {
- $upinst .= "update delete {$dnsupdate['host']}. AAAA\n";
- $upinst .= "update add {$dnsupdate['host']}. {$dnsupdate['ttl']} AAAA {$wanipv6}\n";
- }
- $upinst .= "\n"; /* mind that trailing newline! */
-
- @file_put_contents("{$g['varetc_path']}/nsupdatecmds{$i}", $upinst);
- unset($upinst);
+ if (($wanipv6 != $cachedipv6) || (($currentTime - $cacheTimev6) > $maxCacheAgeSecs) || $forced) {
+ $upinst .= "update delete {$dnsupdate['host']}. AAAA\n";
+ $upinst .= "update add {$dnsupdate['host']}. {$dnsupdate['ttl']} AAAA {$wanipv6}\n";
+ $notify_text .= sprintf(gettext("DynDNS updated IPv6 Address (AAAA) for {$dnsupdate['host']} on %s (%s) to %s"), convert_real_interface_to_friendly_descr($if), $if, $wanipv6) . "\n";
+ @file_put_contents("{$cacheFile}.ipv6", "{$wanipv6}|{$currentTime}");
+ log_error("phpDynDNS: updating cache file {$cacheFile}.ipv6: {$wanipv6}");
+ $need_update = true;
+ } else {
+ log_error("phpDynDNS: Not updating {$dnsupdate['host']} AAAA record because the IPv6 address has not changed.");
+ }
+ } else
+ @unlink("{$cacheFile}.ipv6");
- /* invoke nsupdate */
- $cmd = "/usr/bin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
- if (isset($dnsupdate['usetcp']))
- $cmd .= " -v";
- $cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
+ $upinst .= "\n"; /* mind that trailing newline! */
- mwexec_bg($cmd);
- unset($cmd);
+ if ($need_update) {
+ @file_put_contents("{$g['varetc_path']}/nsupdatecmds{$i}", $upinst);
+ unset($upinst);
+ /* invoke nsupdate */
+ $cmd = "/usr/bin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
+ if (isset($dnsupdate['usetcp']))
+ $cmd .= " -v";
+ $cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
+ mwexec_bg($cmd);
+ unset($cmd);
+ }
}
}
+ if (!empty($notify_text)) {
+ notify_all_remote($notify_text);
+ }
}
return 0;
OpenPOWER on IntegriCloud