diff --git a/dns/dyndns/Makefile b/dns/dyndns/Makefile index 3a4c119a0..49d8929ec 100644 --- a/dns/dyndns/Makefile +++ b/dns/dyndns/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= dyndns -PLUGIN_VERSION= 1.4 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.5 PLUGIN_COMMENT= Dynamic DNS Support PLUGIN_MAINTAINER= franco@opnsense.org diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc index 741130982..bfe345048 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns.inc @@ -148,20 +148,21 @@ function dyndns_configure_client($conf) return; } - $dns = new updatedns($dnsService = $conf['type'], + $dns = new updatedns( + $dnsService = $conf['type'], $dnsHost = $conf['host'], $dnsUser = $conf['username'], $dnsPass = $conf['password'], $dnsWilcard = $conf['wildcard'], $dnsMX = $conf['mx'], $dnsIf = "{$conf['interface']}", - $dnsBackMX = NULL, - $dnsServer = NULL, - $dnsPort = NULL, + $dnsBackMX = null, + $dnsServer = null, + $dnsPort = null, $dnsUpdateURL = "{$conf['updateurl']}", $forceUpdate = $conf['force'], - $dnsZoneID=$conf['zoneid'], - $dnsTTL=$conf['ttl'], + $dnsZoneID = $conf['zoneid'], + $dnsTTL = $conf['ttl'], $dnsResultMatch = "{$conf['resultmatch']}", $dnsRequestIf = "{$conf['requestif']}", $dnsID = "{$conf['id']}", diff --git a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc index d98ebc314..b92fc6647 100644 --- a/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc +++ b/dns/dyndns/src/etc/inc/plugins.inc.d/dyndns/phpDynDNS.inc @@ -99,7 +99,8 @@ * Custom DNS support by Matt Corallo */ -class updatedns { +class updatedns +{ var $_cacheFile; var $_cacheFile_v6; var $_debugFile; @@ -141,11 +142,28 @@ class updatedns { * - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL. * - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP. */ - public function __construct ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '', - $dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '', - $dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false, - $dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '', - $dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) { + public function __construct( + $dnsService = '', + $dnsHost = '', + $dnsUser = '', + $dnsPass = '', + $dnsWildcard = 'OFF', + $dnsMX = '', + $dnsIf = '', + $dnsBackMX = '', + $dnsServer = '', + $dnsPort = '', + $dnsUpdateURL = '', + $forceUpdate = false, + $dnsZoneID = '', + $dnsTTL = '', + $dnsResultMatch = '', + $dnsRequestIf = '', + $dnsID = '', + $dnsVerboseLog = false, + $curlIpresolveV4 = false, + $curlSslVerifypeer = true + ) { /* XXX because the call stack is upside down we need to reassemble config parts here... */ $conf = array('host' => $dnsHost, 'id' => $dnsID, 'interface' => $dnsIf); @@ -157,50 +175,75 @@ class updatedns { $this->_curlIpresolveV4 = $curlIpresolveV4; $this->_curlSslVerifypeer = $curlSslVerifypeer; $this->_dnsVerboseLog = $dnsVerboseLog; - if ($this->_dnsVerboseLog) + if ($this->_dnsVerboseLog) { log_error("Dynamic DNS: updatedns() starting"); + } $dyndnslck = lock("DDNS".$dnsID, LOCK_EX); - if (!$dnsService) $this->_error(2); + if (!$dnsService) { + $this->_error(2); + } switch ($dnsService) { - case 'freedns': - if (!$dnsHost) $this->_error(5); - break; - case 'namecheap': - if (!$dnsPass) $this->_error(4); - if (!$dnsHost) $this->_error(5); - break; - case 'route53': - case 'route53-v6': - if (!$dnsZoneID) $this->_error(8); - if (!$dnsTTL) $this->_error(9); - break; - case 'custom': - if (!$dnsUpdateURL) $this->_error(7); - break; - case 'duckdns': - case 'regfish': - case 'regfish-v6': - if (!$dnsUser) $this->_error(3); - if (!$dnsHost) $this->_error(5); - break; - default: - if (!$dnsUser) $this->_error(3); - if (!$dnsPass) $this->_error(4); - if (!$dnsHost) $this->_error(5); - break; + case 'freedns': + if (!$dnsHost) { + $this->_error(5); + } + break; + case 'namecheap': + if (!$dnsPass) { + $this->_error(4); + } + if (!$dnsHost) { + $this->_error(5); + } + break; + case 'route53': + case 'route53-v6': + if (!$dnsZoneID) { + $this->_error(8); + } + if (!$dnsTTL) { + $this->_error(9); + } + break; + case 'custom': + if (!$dnsUpdateURL) { + $this->_error(7); + } + break; + case 'duckdns': + case 'regfish': + case 'regfish-v6': + if (!$dnsUser) { + $this->_error(3); + } + if (!$dnsHost) { + $this->_error(5); + } + break; + default: + if (!$dnsUser) { + $this->_error(3); + } + if (!$dnsPass) { + $this->_error(4); + } + if (!$dnsHost) { + $this->_error(5); + } + break; } switch ($dnsService) { - case 'custom-v6': - case 'he-net-v6': - case 'regfish-v6': - case 'route53-v6': - $this->_useIPv6 = true; - break; - default: - $this->_useIPv6 = false; + case 'custom-v6': + case 'he-net-v6': + case 'regfish-v6': + case 'route53-v6': + $this->_useIPv6 = true; + break; + default: + $this->_useIPv6 = false; } $this->_dnsService = strtolower($dnsService); $this->_dnsUser = $dnsUser; @@ -217,15 +260,16 @@ class updatedns { $this->_dnsUpdateURL = $dnsUpdateURL; $this->_dnsResultMatch = $dnsResultMatch; $this->_dnsRequestIf = get_failover_interface($dnsRequestIf); - if ($this->_dnsVerboseLog) + if ($this->_dnsVerboseLog) { log_error("Dynamic DNS ({$this->_dnsHost}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}"); + } $this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf); $this->_dnsMaxCacheAgeDays = 25; $this->_dnsDummyUpdateDone = false; $this->_forceUpdateNeeded = $forceUpdate; // Ensure that we were able to lookup the IP - if(!is_ipaddr($this->_dnsIP)) { + if (!is_ipaddr($this->_dnsIP)) { log_error("Dynamic DNS ({$this->_dnsHost}) There was an error trying to determine the public IP for interface - {$dnsIf}({$this->_if}). Probably interface is not a WAN interface."); unlock($dyndnslck); return; @@ -237,57 +281,57 @@ class updatedns { $this->_error(10); } else { switch ($this->_dnsService) { - case '3322': - case 'citynetwork': - case 'cloudflare': - case 'custom': - case 'custom-v6': - case 'dhs': - case 'dnsexit': - case 'dnsomatic': - case 'duckdns': - case 'dyndns': - case 'dyndns-custom': - case 'dyndns-static': - case 'dyns': - case 'easydns': - case 'eurodns': - case 'freedns': - case 'googledomains': - case 'gratisdns': - case 'he-net': - case 'he-net-tunnelbroker': - case 'he-net-v6': - case 'hn': - case 'loopia': - case 'namecheap': - case 'noip': - case 'noip-free': - case 'ods': - case 'opendns': - case 'ovh-dynhost': - case 'oray': - case 'regfish': - case 'regfish-v6': - case 'route53': - case 'route53-v6': - case 'selfhost': - case 'strato': - case 'staticcling': - case 'zoneedit': - $this->_update(); - if($this->_dnsDummyUpdateDone == true) { - // If a dummy update was needed, then sleep a while and do the update again to put the proper address back. - // Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month. - // If the address has not changed recently, or the user did "Force Update", then the code does - // a dummy address change for providers like this. - sleep(10); + case '3322': + case 'citynetwork': + case 'cloudflare': + case 'custom': + case 'custom-v6': + case 'dhs': + case 'dnsexit': + case 'dnsomatic': + case 'duckdns': + case 'dyndns': + case 'dyndns-custom': + case 'dyndns-static': + case 'dyns': + case 'easydns': + case 'eurodns': + case 'freedns': + case 'googledomains': + case 'gratisdns': + case 'he-net': + case 'he-net-tunnelbroker': + case 'he-net-v6': + case 'hn': + case 'loopia': + case 'namecheap': + case 'noip': + case 'noip-free': + case 'ods': + case 'opendns': + case 'ovh-dynhost': + case 'oray': + case 'regfish': + case 'regfish-v6': + case 'route53': + case 'route53-v6': + case 'selfhost': + case 'strato': + case 'staticcling': + case 'zoneedit': $this->_update(); - } - break; - default: - $this->_error(6); - break; + if ($this->_dnsDummyUpdateDone == true) { + // If a dummy update was needed, then sleep a while and do the update again to put the proper address back. + // Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month. + // If the address has not changed recently, or the user did "Force Update", then the code does + // a dummy address change for providers like this. + sleep(10); + $this->_update(); + } + break; + default: + $this->_error(6); + break; } } @@ -317,15 +361,19 @@ class updatedns { case 'dyndns': case 'dyndns-static': case 'dyndns-custom': - if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON"; + if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { + $this->_dnsWildcard = "ON"; + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://members.dyndns.org/nic/update"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO'); break; case 'dhs': @@ -346,10 +394,12 @@ class updatedns { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $server = "https://members.dhs.org/nic/hosts"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, '{$server}{$port}'); curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); @@ -359,11 +409,13 @@ class updatedns { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $server = "https://dynupdate.no-ip.com/ducupdate.php"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; - if(($this->_dnsService == "noip-free") && + } + if (($this->_dnsService == "noip-free") && ($this->_forceUpdateNeeded == true) && ($this->_dnsDummyUpdateDone == false)) { // Update the IP to a dummy value to force No-IP free accounts to see a change. @@ -380,20 +432,24 @@ class updatedns { curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://members.easydns.com/dyn/dyndns.php"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX); break; case 'hn': curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "http://dup.hn.org/vanity/update"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP); break; case 'zoneedit': @@ -403,19 +459,23 @@ class updatedns { $server = "https://dynamic.zoneedit.com/auth/dynamic.html"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost); break; case 'dyns': $server = "https://www.dyns.cx/postscript011.php"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost); break; case 'ods': @@ -423,10 +483,12 @@ class updatedns { $misc_error = ""; $server = "ods.org"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } $this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30); /* Check that we have connected */ if (!$this->con['socket']) { @@ -438,7 +500,7 @@ class updatedns { $this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096)); $code = substr($this->con['buffer']['all'], 0, 3); sleep(1); - switch($code) { + switch ($code) { case 100: fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n"); break; @@ -468,15 +530,19 @@ class updatedns { curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard); break; case 'opendns': - if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON"; + if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { + $this->_dnsWildcard = "ON"; + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port); break; @@ -487,7 +553,9 @@ class updatedns { /* Example syntax https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG */ - if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON"; + if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { + $this->_dnsWildcard = "ON"; + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); /* Reference: https://www.dnsomatic.com/wiki/api @@ -499,10 +567,12 @@ class updatedns { Encodes the given string according to RFC 3986. */ $server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname="; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG'); break; case 'namecheap': @@ -523,7 +593,7 @@ class updatedns { case 'he-net-v6': $server = "https://dyn.dns.he.net/nic/update?"; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP); break; case 'he-net-tunnelbroker': @@ -533,15 +603,19 @@ class updatedns { curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost); break; case 'selfhost': - if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON"; + if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { + $this->_dnsWildcard = "ON"; + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://carol.selfhost.de/nic/update"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO'); break; case 'route53': @@ -559,14 +633,15 @@ class updatedns { $r53 = new Route53($AccessKeyId, $SecretAccessKey); /* Function to find old values of records in Route 53 */ - if(!function_exists('Searchrecords')) { - function SearchRecords($records, $name) { + if (!function_exists('Searchrecords')) { + function SearchRecords($records, $name) + { if (!is_array($records)) { return false; } $result = array(); - foreach($records as $record) { - if(strtolower($record['Name']) == strtolower($name)) { + foreach ($records as $record) { + if (strtolower($record['Name']) == strtolower($name)) { $result [] = $record; } } @@ -577,7 +652,7 @@ class updatedns { $records = $r53->listResourceRecordSets("/hostedzone/$ZoneID"); /* Get IP for your hostname in Route 53 */ - if(false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) { + if (false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) { $OldTTL=$a_result[0][TTL]; $OldIP=$a_result[0][ResourceRecords][0]; } else { @@ -586,7 +661,7 @@ class updatedns { /* Check if we need to update DNS Record */ if ($OldIP !== $NewIP) { - if(!empty($OldIP)) { + if (!empty($OldIP)) { /* Your Hostname already exists, deleting and creating it again */ $changes = array(); $changes[] = $r53->prepareChange(DELETE, $hostname, $RecordType, $OldTTL, $OldIP); @@ -604,7 +679,7 @@ class updatedns { case 'custom-v6': if ($this->_dnsUser != '') { if ($this->_curlIpresolveV4) { - curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } if ($this->_curlSslVerifypeer) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); @@ -618,7 +693,7 @@ class updatedns { break; case 'cloudflare': $dnsServer ='api.cloudflare.com'; - $dnsHost = str_replace(' ','', $this->_dnsHost); + $dnsHost = str_replace(' ', '', $this->_dnsHost); $host_names = explode('.', $dnsHost); $bottom_host_name = $host_names[count($host_names) - 2] . '.' . $host_names[count($host_names) - 1]; @@ -634,12 +709,12 @@ class updatedns { curl_setopt($ch, CURLOPT_URL, $getZoneId); $output = json_decode(curl_exec($ch)); $zone = $output->result[0]->id; - if ($zone){ // If zone ID was found get host ID + if ($zone) { // If zone ID was found get host ID $getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_dnsHost}"; curl_setopt($ch, CURLOPT_URL, $getHostId); $output = json_decode(curl_exec($ch)); $host = $output->result[0]->id; - if ($host){ // If host ID was found update host + if ($host) { // If host ID was found update host $hostData = array( "content" => "{$this->_dnsIP}", "type" => "A", @@ -660,8 +735,9 @@ class updatedns { curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://eurodyndns.org/update/"; $port = ""; - if($this->_dnsPort) + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP); break; case 'gratisdns': @@ -671,15 +747,19 @@ class updatedns { curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $this->_dnsHost . '&d=' . $domain); break; case 'ovh-dynhost': - if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON"; + if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") { + $this->_dnsWildcard = "ON"; + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = "https://www.ovh.com/nic/update"; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO'); break; case 'citynetwork': @@ -687,10 +767,12 @@ class updatedns { curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); $server = 'https://dyndns.citynetwork.se/nic/update'; $port = ""; - if($this->_dnsServer) + if ($this->_dnsServer) { $server = $this->_dnsServer; - if($this->_dnsPort) + } + if ($this->_dnsPort) { $port = ":" . $this->_dnsPort; + } curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP); break; case 'duckdns': @@ -748,7 +830,8 @@ class updatedns { * Private Function (added 12 July 2005) [beta] * Retrieve Update Status */ - function _checkStatus($ch, $data) { + function _checkStatus($ch, $data) + { if ($this->_dnsVerboseLog) { log_error("Dynamic DNS ({$this->_dnsHost}): _checkStatus() starting."); log_error("Dynamic DNS ({$this->_dnsHost}): Current Service: {$this->_dnsService}"); @@ -765,7 +848,7 @@ class updatedns { break; case 'noip': case 'noip-free': - list($ip,$code) = explode(":",$data); + list($ip,$code) = explode(":", $data); switch ($code) { case 0: $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP address is current, no update performed."; @@ -831,13 +914,13 @@ class updatedns { case 'easydns': if (preg_match('/NOACCESS/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Authentication Failed: Username and/or Password was Incorrect."; - } else if (preg_match('/NOSERVICE/i', $data)) { + } elseif (preg_match('/NOSERVICE/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) No Service: Dynamic DNS Service has been disabled for this domain."; - } else if (preg_match('/ILLEGAL INPUT/i', $data)) { + } elseif (preg_match('/ILLEGAL INPUT/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Illegal Input: Self-Explanatory"; - } else if (preg_match('/TOOSOON/i', $data)) { + } elseif (preg_match('/TOOSOON/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update"; - } else if (preg_match('/NOERROR/i', $data)) { + } elseif (preg_match('/NOERROR/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Updated Successfully!"; $successful_update = true; } else { @@ -852,12 +935,12 @@ class updatedns { case 'zoneedit': if (preg_match('/799/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error 799) Update Failed!"; - } else if (preg_match('/700/i', $data)) { + } elseif (preg_match('/700/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error 700) Update Failed!"; - } else if (preg_match('/200/i', $data)) { + } elseif (preg_match('/200/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!"; $successful_update = true; - } else if (preg_match('/201/i', $data)) { + } elseif (preg_match('/201/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!"; $successful_update = true; } else { @@ -869,13 +952,13 @@ class updatedns { case 'dyns': if (preg_match("/400/i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Bad Request - The URL was malformed. Required parameters were not provided."; - } else if (preg_match('/402/i', $data)) { + } elseif (preg_match('/402/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Update Too Soon - You have tried updating to quickly since last change."; - } else if (preg_match('/403/i', $data)) { + } elseif (preg_match('/403/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Database Error - There was a server-sided database error."; - } else if (preg_match('/405/i', $data)) { + } elseif (preg_match('/405/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you."; - } else if (preg_match('/200/i', $data)) { + } elseif (preg_match('/200/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!"; $successful_update = true; } else { @@ -898,7 +981,7 @@ class updatedns { if (preg_match("/has not changed./i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) No Change In IP Address"; $successful_update = true; - } else if (preg_match("/Updated/i", $data)) { + } elseif (preg_match("/Updated/i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!"; $successful_update = true; } else { @@ -911,7 +994,7 @@ class updatedns { if (preg_match("/is the same/i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) No Change In IP Address"; $successful_update = true; - } else if (preg_match("/Success/i", $data)) { + } elseif (preg_match("/Success/i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!"; $successful_update = true; } else { @@ -923,19 +1006,19 @@ class updatedns { case 'staticcling': if (preg_match("/invalid ip/i", $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Bad Request - The IP provided was invalid."; - } else if (preg_match('/required info missing/i', $data)) { + } elseif (preg_match('/required info missing/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Bad Request - Required parameters were not provided."; - } else if (preg_match('/invalid characters/i', $data)) { + } elseif (preg_match('/invalid characters/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Bad Request - Illegal characters in either the username or the password."; - } else if (preg_match('/bad password/i', $data)) { + } elseif (preg_match('/bad password/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Invalid password."; - } else if (preg_match('/account locked/i', $data)) { + } elseif (preg_match('/account locked/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) This account has been administratively locked."; - } else if (preg_match('/update too frequent/i', $data)) { + } elseif (preg_match('/update too frequent/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Updating too frequently."; - } else if (preg_match('/DB error/i', $data)) { + } elseif (preg_match('/DB error/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Error) Server side error."; - } else if (preg_match('/success/i', $data)) { + } elseif (preg_match('/success/i', $data)) { $status = "Dynamic DNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!"; $successful_update = true; } else { @@ -979,14 +1062,14 @@ class updatedns { */ if (preg_match("/Missing parameter/i", $data)) { $status = "Dynamic DNS: (Error) Bad Request - Missing/Invalid Parameters."; - } else if (preg_match('/Tunnel not found/i', $data)) { + } elseif (preg_match('/Tunnel not found/i', $data)) { $status = "Dynamic DNS: (Error) Bad Request - Invalid Tunnel ID."; - } else if (preg_match('/Invalid API key or password/i', $data)) { + } elseif (preg_match('/Invalid API key or password/i', $data)) { $status = "Dynamic DNS: (Error) Invalid username or password."; - } else if (preg_match('/OK:/i', $data)) { + } elseif (preg_match('/OK:/i', $data)) { $status = "Dynamic DNS: (Success) IP Address Updated Successfully!"; $successful_update = true; - } else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) { + } elseif (preg_match('/This tunnel is already associated with this IP address/i', $data)) { $status = "Dynamic DNS: (Success) No Change In IP Address."; $successful_update = true; } else { @@ -1004,34 +1087,33 @@ class updatedns { $successful_update = false; if ($this->_dnsResultMatch == "") { $successful_update = true; - }else { + } else { $this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch); $matches = preg_split("/(?_dnsResultMatch); - foreach($matches as $match) { + foreach ($matches as $match) { $match= str_replace("\\|", "|", $match); - if(strcmp($match, trim($data, "\t\n\r")) == 0) + if (strcmp($match, trim($data, "\t\n\r")) == 0) { $successful_update = true; + } } - unset ($matches); + unset($matches); } - if ($successful_update == true) + if ($successful_update == true) { $status = "Dynamic DNS: (Success) IP Address Updated Successfully!"; - else + } else { $status = "Dynamic DNS: (Error) Result did not match."; + } break; case 'cloudflare': $output = json_decode($data); - if ($output->result->content === $this->_dnsIP){ + if ($output->result->content === $this->_dnsIP) { $status = "Dynamic DNS: (Success) {$this->_dnsHost} updated to {$this->_dnsIP}"; $successful_update = true; - } - elseif ($output->errors[0]->code === 9103){ + } elseif ($output->errors[0]->code === 9103) { $status = "Dynamic DNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with CloudFlare."; - } - elseif (($output->success) && (!$output->result[0]->id)) { + } elseif (($output->success) && (!$output->result[0]->id)) { $status = "Dynamic DNS ({$this->_dnsHost}): ERROR - Zone or Host ID was not found, check your hostname."; - } - else { + } else { $status = "Dynamic DNS ({$this->_dnsHost}): UNKNOWN ERROR - {$output->errors[0]->message}"; log_error("Dynamic DNS ({$this->_dnsHost}): PAYLOAD: {$data}"); } @@ -1039,13 +1121,13 @@ class updatedns { case 'gratisdns': if (preg_match('/Forkerte værdier/i', $data)) { $status = "Dynamic DNS: (Error) Wrong values - Update could not be completed."; - } else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) { + } elseif (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) { $status = "Dynamic DNS: (Error) Unknown username - User does not exist."; - } else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) { + } elseif (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) { $status = "Dynamic DNS: (Error) Wrong password - Remember password is case sensitive."; - } else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) { + } elseif (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) { $status = "Dynamic DNS: (Error) User unable to administer the selected domain."; - } else if (preg_match('/OK/i', $data)) { + } elseif (preg_match('/OK/i', $data)) { $status = "Dynamic DNS: (Success) IP Address Updated Successfully!"; $successful_update = true; } else { @@ -1175,7 +1257,8 @@ class updatedns { * Private Function (added 12 July 05) [beta] * Return Error, Set Last Error, and Die. */ - function _error($errorNumber = '1') { + function _error($errorNumber = '1') + { switch ($errorNumber) { case 0: break; @@ -1222,7 +1305,8 @@ class updatedns { * | Written Specifically for pfSense (https://www.pfsense.org) may * | work with other systems. pfSense base is FreeBSD. */ - function _detectChange() { + function _detectChange() + { $currentTime = time(); $wan_ip = $this->_checkIP(); @@ -1261,8 +1345,9 @@ class updatedns { $log_error .= "No Cached IP found."; } } - if ($this->_dnsVerboseLog) + if ($this->_dnsVerboseLog) { log_error($log_error); + } // Convert seconds = days * hr/day * min/hr * sec/min $maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60; @@ -1289,8 +1374,9 @@ class updatedns { * new cache value and return true */ if ($needs_updating == true) { - if ($this->_dnsVerboseLog) + if ($this->_dnsVerboseLog) { log_error("Dynamic DNS ({$this->_dnsHost}): {$update_reason}"); + } return true; } @@ -1303,14 +1389,16 @@ class updatedns { * - This function is only called when a unknown response * - status is returned from a dynamic DNS service provider. */ - function _debug($data) { + function _debug($data) + { $string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n"; $file = fopen($this->_debugFile, 'a'); fwrite($file, $string); fclose($file); } - function _checkIP() { + function _checkIP() + { $ip_address = get_dyndns_ip($this->_if, $this->_useIPv6 ? 6 : 4); if (!is_ipaddr($ip_address)) { if ($this->_dnsVerboseLog) { diff --git a/dns/dyndns/src/www/services_dyndns.php b/dns/dyndns/src/www/services_dyndns.php index 86869fa4e..be55a0c2b 100644 --- a/dns/dyndns/src/www/services_dyndns.php +++ b/dns/dyndns/src/www/services_dyndns.php @@ -181,7 +181,7 @@ $main_buttons = array(