summaryrefslogtreecommitdiffstats
path: root/etc/inc/dyndns.class
diff options
context:
space:
mode:
Diffstat (limited to 'etc/inc/dyndns.class')
-rw-r--r--etc/inc/dyndns.class60
1 files changed, 40 insertions, 20 deletions
diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class
index 150dedc..65defb2 100644
--- a/etc/inc/dyndns.class
+++ b/etc/inc/dyndns.class
@@ -98,7 +98,9 @@
$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . ".debug";
log_error("DynDns: updatedns() starting");
-
+
+ $dyndnslck = lock($dnsHost, LOCK_EX);
+
if (!$dnsService) $this->_error(2);
switch ($dnsService) {
case 'freedns':
@@ -128,6 +130,7 @@
// Ensure that we where able to lookup the IP
if(!is_ipaddr($this->_ifIP)) {
log_error("There was an error trying to determine the IP for interface - {$dnsIf}({$this->_if}). Probably interface has no ip or is down. Dyndns update not possible for {$dnsService}.");
+ unlock($dyndnslck);
return;
}
@@ -162,6 +165,8 @@
break;
}
}
+
+ unlock($dyndnslck);
}
/*
@@ -178,7 +183,7 @@
curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_INTERFACE, $this->_ifIP);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Completely empirical
+ curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
}
switch ($this->_dnsService) {
@@ -795,12 +800,13 @@
if($successful_update == true) {
/* Write WAN IP to cache file */
$wan_ip = $this->_checkIP();
- $currentTime = time();
- log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
conf_mount_rw();
- $file = fopen($this->_cacheFile, 'w');
- fwrite($file, $wan_ip.':'.$currentTime);
- fclose($file);
+ if ($wan_ip > 0) {
+ $currentTime = time();
+ log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
+ @file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
+ } else
+ @unlink($this->_cacheFile);
conf_mount_ro();
}
$this->status = $status;
@@ -853,32 +859,37 @@
* | work with other systems. pfSense base is FreeBSD.
*/
function _detectChange() {
-
- log_error("DynDns: _detectChange() starting.");
+ global $debug;
+
+ if ($debug)
+ log_error("DynDns: _detectChange() starting.");
$currentTime = time();
$wan_ip = $this->_checkIP();
+ if ($wan_ip == 0) {
+ log_error("DynDns: Current WAN IP could not be determined, skipping update process.");
+ return false;
+ }
$this->_dnsIP = $wan_ip;
- log_error("DynDns: Current WAN IP: {$wan_ip}");
+ $log_error = "DynDns: Current WAN IP: {$wan_ip} ";
if (file_exists($this->_cacheFile)) {
$contents = file_get_contents($this->_cacheFile);
list($cacheIP,$cacheTime) = split(':', $contents);
$this->_debug($cacheIP.'/'.$cacheTime);
$initial = false;
- log_error("DynDns: Cached IP: {$cacheIP}");
+ $log_error .= "Cached IP: {$cacheIP} ";
} else {
conf_mount_rw();
- $file = fopen($this->_cacheFile, 'w');
- fwrite($file, '0.0.0.0:'.$currentTime);
- fclose($file);
- conf_mount_ro();
$cacheIP = '0.0.0.0';
+ @file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
+ conf_mount_ro();
$cacheTime = $currentTime;
$initial = true;
- log_error("DynDns: No Cached IP found.");
+ $log_error .= "No Cached IP found.";
}
+ log_error($log_error);
/* use 2419200 for dyndns, dhs, easydns, noip, hn
* zoneedit, dyns, ods
@@ -928,10 +939,14 @@
conf_mount_ro();
}
function _checkIP() {
+ global $debug;
- log_error("DynDns: _checkIP() starting.");
+ if ($debug)
+ log_error("DynDns: _checkIP() starting.");
$ip_address = find_interface_ip($this->_if);
+ if (!is_ipaddr($ip_address))
+ return 0;
$this->_ifIP = $ip_address;
if (is_private_ip($ip_address)) {
$hosttocheck = "checkip.dyndns.org";
@@ -944,20 +959,25 @@
}
if ($try >= 3) {
log_error("Dyndns debug information: Could not resolve {$hosttocheck} to ip using interface ip {$ip_address}.");
- return $ip_address; /* XXX: Might return private ip address! */
+ return 0;
}
$ip_ch = curl_init("http://{$checkip}");
curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
- curl_setopt($ip_ch, CURLOPT_TIMEOUT, 60);
+ curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
$ip_result_page = curl_exec($ip_ch);
curl_close($ip_ch);
$ip_result_decoded = urldecode($ip_result_page);
preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
$ip_address = trim($matches[1]);
- log_error("DynDns debug information: {$ip_address} extracted from {$hosttocheck}");
+ if (is_ipaddr($ip_address))
+ log_error("DynDns debug information: {$ip_address} extracted from {$hosttocheck}");
+ else {
+ log_error("DynDns debug information: IP address could not be extracted from {$hosttocheck}");
+ return 0;
+ }
} else
log_error("DynDns debug information: {$ip_address} extracted from local system.");
OpenPOWER on IntegriCloud