From b11c8ef6c683c2a55f97e25963ad0ec2a118db4d Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 23 Feb 2017 23:50:20 -0500 Subject: Added Dreamhost and Dreamhost V6 to list of DYNDNS services. --- src/etc/inc/services.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 021fb7e..fdf2c8c 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -23,8 +23,8 @@ * limitations under the License. */ -define('DYNDNS_PROVIDER_VALUES', 'all-inkl citynetwork cloudflare cloudflare-v6 custom custom-v6 dnsexit dnsimple dnsmadeeasy dnsomatic duiadns duiadns-v6 dyndns dyndns-custom dyndns-static dyns easydns eurodns freedns freedns-v6 glesys googledomains gratisdns he-net he-net-v6 he-net-tunnelbroker loopia namecheap noip noip-free ods opendns ovh-dynhost route53 selfhost spdyn spdyn-v6 zoneedit'); -define('DYNDNS_PROVIDER_DESCRIPTIONS', 'All-Inkl.com,City Network,CloudFlare,CloudFlare (v6),Custom,Custom (v6),DNSexit,DNSimple,DNS Made Easy,DNS-O-Matic,DuiaDns.net,DuiaDns.net (v6),DynDNS (dynamic),DynDNS (custom),DynDNS (static),DyNS,easyDNS,Euro Dns,freeDNS,freeDNS (v6),GleSYS,Google Domains,GratisDNS,HE.net,HE.net (v6),HE.net Tunnelbroker,Loopia,Namecheap,No-IP,No-IP (free),ODS.org,OpenDNS,OVH DynHOST,Route 53,SelfHost,SPDYN,SPDYN (v6),ZoneEdit'); +define('DYNDNS_PROVIDER_VALUES', 'all-inkl citynetwork cloudflare cloudflare-v6 custom custom-v6 dnsexit dnsimple dnsmadeeasy dnsomatic dreamhost dreamhost-v6 duiadns duiadns-v6 dyndns dyndns-custom dyndns-static dyns easydns eurodns freedns freedns-v6 glesys googledomains gratisdns he-net he-net-v6 he-net-tunnelbroker loopia namecheap noip noip-free ods opendns ovh-dynhost route53 selfhost spdyn spdyn-v6 zoneedit'); +define('DYNDNS_PROVIDER_DESCRIPTIONS', 'All-Inkl.com,City Network,CloudFlare,CloudFlare (v6),Custom,Custom (v6),DNSexit,DNSimple,DNS Made Easy,DNS-O-Matic,DreamHost,Dreamhost (v6),DuiaDns.net,DuiaDns.net (v6),DynDNS (dynamic),DynDNS (custom),DynDNS (static),DyNS,easyDNS,Euro Dns,freeDNS,freeDNS (v6),GleSYS,Google Domains,GratisDNS,HE.net,HE.net (v6),HE.net Tunnelbroker,Loopia,Namecheap,No-IP,No-IP (free),ODS.org,OpenDNS,OVH DynHOST,Route 53,SelfHost,SPDYN,SPDYN (v6),ZoneEdit'); /* implement ipv6 route advertising daemon */ function services_radvd_configure($blacklist = array()) { -- cgit v1.1 From 9a3ec9a5917bbb3d9978dec769cf895eb56422e8 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 23 Feb 2017 23:57:11 -0500 Subject: Implemented Dreamhost ISP dynamic DNS updates. Dreamhost does not allow direct record updates through their API. Records must be deleted and then added. Unfortunately, to delete the record you must first retrieve the existing record to be able to pass back the old IP address for delete. Rather than copy what CloudFlare had done and embed several of the queries into its own update process I broke out some of the operations into _lookup_current and _remove(existing_ip) methods. This will allow for more consistent logging output if others use these features, too. --- src/etc/inc/dyndns.class | 296 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index c88feca..72d3f23 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -60,6 +60,7 @@ * - All-Inkl (all-inkl.com) * - DuiaDNS (www.duiadns.net) * - DuiaDNS IPv6 (www.duiadns.net) + * - DreamHost DNS (www.dreamhost.com) * +----------------------------------------------------+ * Requirements: * - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library @@ -113,6 +114,8 @@ * All-Inkl - Last Tested: 12 November 2016 * DuiaDNS - Last Tested: 25 November 2016 * DuiaDNS IPv6 - Last Tested: 25 November 2016 + * DreamHost - Not Tested + * DreamHost IPv6 - Not Tested * +====================================================+ * * @author E.Kristensen @@ -160,6 +163,7 @@ var $_dnsDummyUpdateDone; var $_forceUpdateNeeded; var $_useIPv6; + var $_existingRecords; /* * Public Constructor Function (added 12 July 05) [beta] @@ -235,6 +239,7 @@ case 'duiadns-v6': case 'freedns-v6': case 'cloudflare-v6': + case 'dreamhost-v6': $this->_useIPv6 = true; break; default: @@ -329,6 +334,17 @@ $this->_update(); } break; + case 'dreamhost': + case 'dreamhost-v6': + $this->_lookup_current(); + if (isset($this->status)) { + return; + } + foreach ($this->_existingRecords as $record) { + $this->_remove($record['existing_val']); + $this->_update(); + } + break; default: $this->_error(6); break; @@ -819,6 +835,29 @@ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass); curl_setopt($ch, CURLOPT_URL, $server . 'myip=' . $this->_dnsIP); break; + case 'dreamhost': + case 'dreamhost-v6': + $needsIP = TRUE; + $isv6 = ($this->_dnsService === 'dreamhost-v6'); + $server = 'https://api.dreamhost.com/'; + $post_data['key'] = $this->_dnsUser; + $post_data['unique_id'] = uniqid($this->_dnsHost); + $post_data['cmd'] = 'dns-add_record'; + $post_data['format'] = 'json'; + $post_data['value'] = $this->_dnsIP; + $post_data['record'] = $this->_dnsHost; + $post_data['type'] = $isv6 ? 'AAAA' : 'A'; + $post_data['comment'] = "Updated by pfsense on ".date('c'); + $port = ""; + if ($this->_dnsServer) { + $server = $this->_dnsServer; + } + if ($this->_dnsPort) { + $port = ":" . $this->_dnsPort; + } + curl_setopt($ch, CURLOPT_URL, $server . $port); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + break; default: break; } @@ -832,6 +871,191 @@ @curl_close($ch); } } + + /** + * Private Function (added 23 Feb 17) + * Send Removal To Selected Service. + * + * Some services do not perform an inplace upgrade. If they do not then the solution + * is to remove the existing record and add a new record. + * + * @param unknown $existing_ip If required, an existing IP address for the record. + */ + function _remove($existing_ip = NULL) { + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _remove() starting.'), $this->_dnsService, $this->_FQDN)); + } + + if (strstr($this->_dnsRequestIf, "_vip")) { + $parentif = get_configured_vip_interface($this->_dnsRequestIf); + $realparentif = convert_friendly_interface_to_real_interface_name($parentif); + } else { + $realparentif = $this->_dnsRequestIf; + } + + $ch = curl_init(); + + if ($this->_useIPv6 == false) { + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + } + + if ($this->_dnsService != 'ods') { + curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); + curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical + } + + switch ($this->_dnsService) { + case 'dreamhost': + case 'dreamhost-v6': + $server = 'https://api.dreamhost.com/'; + $post_data['key'] = $this->_dnsUser; + $post_data['unique_id'] = uniqid($this->_dnsHost); + $post_data['cmd'] = 'dns-remove_record'; + $post_data['format'] = 'json'; + $post_data['value'] = $existing_ip; + $post_data['record'] = $this->_dnsHost; + $isv6 = ($this->_dnsService === 'dreamhost-v6'); + $post_data['type'] = $isv6 ? 'AAAA' : 'A'; + $port = ""; + if ($this->_dnsServer) { + $server = $this->_dnsServer; + } + if ($this->_dnsPort) { + $port = ":" . $this->_dnsPort; + } + curl_setopt($ch, CURLOPT_URL, $server . $port); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + break; + default: + break; + } + if ($this->_dnsService != 'ods') { + curl_setopt($ch, CURLOPT_HEADER, 1); + $response = curl_exec($ch); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $data = substr($response, $header_size); + $this->_checkStatus($ch, $data, $header); + @curl_close($ch); + } + } + + /** + * Private Function (added 23 Feb 17) + * Retrieves current DNS records. + * + * Some services cannot perform new operations without the caller + * providing existing record information. + */ + function _lookup_current() { + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _listCurrent() starting.'), $this->_dnsService, $this->_FQDN)); + } + + if (strstr($this->_dnsRequestIf, "_vip")) { + $parentif = get_configured_vip_interface($this->_dnsRequestIf); + $realparentif = convert_friendly_interface_to_real_interface_name($parentif); + } else { + $realparentif = $this->_dnsRequestIf; + } + + $ch = curl_init(); + + if ($this->_useIPv6 == false) { + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + } + + if ($this->_dnsService != 'ods') { + curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); + curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical + } + + switch ($this->_dnsService) { + case 'dreamhost': + case 'dreamhost-v6': + $server = 'https://api.dreamhost.com/'; + $post_data['key'] = $this->_dnsUser; + $post_data['unique_id'] = uniqid($this->_dnsHost); + $post_data['cmd'] = 'dns-list_records'; + $post_data['format'] = 'json'; + $port = ""; + if ($this->_dnsServer) { + $server = $this->_dnsServer; + } + if ($this->_dnsPort) { + $port = ":" . $this->_dnsPort; + } + curl_setopt($ch, CURLOPT_URL, $server . $port); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + break; + default: + break; + } + if ($this->_dnsService != 'ods') { + curl_setopt($ch, CURLOPT_HEADER, 1); + $response = curl_exec($ch); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $data = substr($response, $header_size); + $this->_checkLookupStatus($ch, $data, $header); + @curl_close($ch); + } + } + + /* + * Private Function (added 12 July 2005) [beta] + * Retrieve Lookup Status + */ + function _checkLookupStatus($ch, $data, $header) { + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() starting.'), $this->_dnsService, $this->_FQDN)); + } + $success_str = "(" . gettext("Success") . ") "; + $error_str = "(" . gettext("Error") . ") "; + $status_intro = "phpDynDNS ({$this->_dnsHost}): "; + + if ($this->_dnsService != 'ods' && @curl_error($ch)) { + $status = gettext("Curl error occurred:") . " " . curl_error($ch); + log_error($status); + $this->status = $status; + return; + } + switch ($this->_dnsService) { + case 'dreamhost': + case 'dreamhost-v6': + $result = json_decode($data,true); + if($result["result"] != "success") { + log_error($status_intro . gettext("PAYLOAD:") . " {$data}"); + $this->_debug($data); + return; + } else { + foreach($result["data"] as $key => $row) { + if($row["record"] == $this->_dnsHost && + (($row["type"] == "A" && !$this->_useIPv6) + || ($row["type"] == "AAAA" && $this->_useIPv6) + )) { + if($row["editable"] == 0) { + log_error($status_intro . "host " . $this->_dnsHost . " is not editable."); + continue; + } + $this->_existingRecords[]=array("record"=>$row["type"], "type"=>$row["type"], "existing_val"=>$row["value"]); + } + } + } + if (!is_array($this->_existingRecords)){ + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() ending. No matching records found.'), $this->_dnsService, $this->_FQDN)); + } + } + break; + default: + break; + } + } /* * Private Function (added 12 July 2005) [beta] @@ -1483,6 +1707,78 @@ $this->_debug($header); } break; + case 'dreamhost': + case 'dreamhost-v6': + $result = json_decode($data,true); + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('_checkStatus() results: %1$s'), $data)); + } + switch ($result['data']) { + case 'success': + case 'record_added': + case 'record_removed': + $status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")"; + $successful_update = true; + break; + case 'no_record': + $status = $status_intro . $error_str . gettext("No record exists."); + break; + case 'no_type': + $status = $status_intro . $error_str . gettext("No type exists."); + break; + case 'no_value': + $status = $status_intro . $error_str . gettext("No value exists."); + break; + case 'no_such_record ': + $status = $status_intro . $error_str . gettext("No record exists."); + break; + case 'no_such_type ': + $status = $status_intro . $error_str . gettext("No type exists."); + break; + case 'no_such_value ': + $status = $status_intro . $error_str . gettext("No value exists."); + break; + case 'no_such_zone': + $status = $status_intro . $error_str . gettext("No such zone exists."); + break; + case 'invalid_record': + $status = $status_intro . $error_str . gettext("The specified record is invalid."); + break; + case 'invalid_type': + $status = $status_intro . $error_str . gettext("The specified type is invalid."); + break; + case 'invalid_value': + $status = $status_intro . $error_str . gettext("The specified value is invalid."); + break; + case 'not_editable ': + $status = $status_intro . $error_str . gettext("Record is not editable."); + break; + case 'record_already_exists_not_editable': + $status = $status_intro . $error_str . gettext("Record exists but is not editable."); + break; + case 'record_already_exists_remove_first': + $status = $status_intro . $error_str . gettext("Record exists and must be removed before adding."); + break; + case 'internal_error_updating_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); + break; + case 'internal_error_could_not_load_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred loading the zone."); + break; + case 'internal_error_could_not_update_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); + break; + case 'internal_error_could_not_add_record': + $status = $status_intro . $error_str . gettext("A remote server error occurred adding a new record."); + break; + case 'internal_error_could_not_destroy_record ': + $status = $status_intro . $error_str . gettext("A remote server error occurred removing an existing record."); + break; + default: + break; + } + default: + break; } if ($successful_update == true) { -- cgit v1.1 From a71deb5a634df93c11ed7a25c2ea001edb273127 Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 26 Feb 2017 15:04:53 -0500 Subject: Switched API key usage from username to password fields for protection. This prevents accidentally leaking the Dreamhost API key to casual router administrators. --- src/etc/inc/dyndns.class | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index 72d3f23..1c3a5fc 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -840,14 +840,14 @@ $needsIP = TRUE; $isv6 = ($this->_dnsService === 'dreamhost-v6'); $server = 'https://api.dreamhost.com/'; - $post_data['key'] = $this->_dnsUser; + $post_data['key'] = $this->_dnsPass; $post_data['unique_id'] = uniqid($this->_dnsHost); $post_data['cmd'] = 'dns-add_record'; $post_data['format'] = 'json'; $post_data['value'] = $this->_dnsIP; $post_data['record'] = $this->_dnsHost; $post_data['type'] = $isv6 ? 'AAAA' : 'A'; - $post_data['comment'] = "Updated by pfsense on ".date('c'); + $post_data['comment'] = "Updated by pfSense:$this->_dnsUser on ".date('c'); $port = ""; if ($this->_dnsServer) { $server = $this->_dnsServer; @@ -910,7 +910,7 @@ case 'dreamhost': case 'dreamhost-v6': $server = 'https://api.dreamhost.com/'; - $post_data['key'] = $this->_dnsUser; + $post_data['key'] = $this->_dnsPass; $post_data['unique_id'] = uniqid($this->_dnsHost); $post_data['cmd'] = 'dns-remove_record'; $post_data['format'] = 'json'; @@ -978,7 +978,7 @@ case 'dreamhost': case 'dreamhost-v6': $server = 'https://api.dreamhost.com/'; - $post_data['key'] = $this->_dnsUser; + $post_data['key'] = $this->_dnsPass; $post_data['unique_id'] = uniqid($this->_dnsHost); $post_data['cmd'] = 'dns-list_records'; $post_data['format'] = 'json'; -- cgit v1.1 From 6c6daeaefa895ab557de0ac63a15cec6512b59d0 Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 22 Apr 2017 00:21:39 -0400 Subject: Resolved some unusual formatting errors that crept into the request. --- src/etc/inc/dyndns.class | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index b32d761..d8f0500 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -844,7 +844,7 @@ $port = ""; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - + //step 1: login to API $post_data['username'] = $this->_dnsUser; $post_data['password'] = $this->_dnsPass; @@ -852,13 +852,13 @@ curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/login"); curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies $output = curl_exec($ch); - + //extract the cookies preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies); if( count($cookies[1]) > 0 ){ $cookie_data = implode("; ",$cookies[1]); } - + //step 2: find the id of the A record $post_data = null; curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); @@ -866,13 +866,13 @@ curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); - + $output = curl_exec($ch); preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{\"id\":\"([^\"]*?)\",\"name\":\"{$this->_dnsHost}\".*?\$/", $output, $hostID); $hostID = $hostID[1]; preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{[^\}]*?\"name\":\"{$this->_dnsHost}\".*?content\":\"([^\"]*?)\".*?\$/", $output, $hostIP); $hostIP = $hostIP[1]; - + //step 3: update the IP if ($hostID) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); -- cgit v1.1 From 9d26673dfc2def135c8a887ff13c7c3002b1a69d Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 1 May 2017 00:04:59 -0400 Subject: Added last tested date to DreamHost IPv4 record. I cannot add a test date to IPv6 because my local ISP does not support it yet. Dreamhost supports IPv6 records and I can manually alter an IPv6 address through the same API. I just can't test it through pfsense. --- src/etc/inc/dyndns.class | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index d8f0500..d0a2e26 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -116,8 +116,8 @@ * DuiaDNS - Last Tested: 25 November 2016 * DuiaDNS IPv6 - Last Tested: 25 November 2016 * Hover - Last Tested: 15 February 2017 - * DreamHost - Not Tested - * DreamHost IPv6 - Not Tested + * DreamHost - Last Tested: 30 April 2017 + * DreamHost IPv6 - Not Yet Tested * +====================================================+ * * @author E.Kristensen -- cgit v1.1 From e350558a62c82420e0c1ce5160711d79b8e2e013 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 1 May 2017 20:40:36 -0400 Subject: Changes tab levels for new case/switch blocks to match K&R BSD style. https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9 --- src/etc/inc/dyndns.class | 274 +++++++++++++++++++++++------------------------ 1 file changed, 137 insertions(+), 137 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index d0a2e26..318e2fb 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -957,40 +957,40 @@ } switch ($this->_dnsService) { - case 'dreamhost': - case 'dreamhost-v6': - $server = 'https://api.dreamhost.com/'; - $post_data['key'] = $this->_dnsPass; - $post_data['unique_id'] = uniqid($this->_dnsHost); - $post_data['cmd'] = 'dns-remove_record'; - $post_data['format'] = 'json'; - $post_data['value'] = $existing_ip; - $post_data['record'] = $this->_dnsHost; - $isv6 = ($this->_dnsService === 'dreamhost-v6'); - $post_data['type'] = $isv6 ? 'AAAA' : 'A'; - $port = ""; - if ($this->_dnsServer) { - $server = $this->_dnsServer; - } - if ($this->_dnsPort) { - $port = ":" . $this->_dnsPort; - } - curl_setopt($ch, CURLOPT_URL, $server . $port); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - break; - default: - break; + case 'dreamhost': + case 'dreamhost-v6': + $server = 'https://api.dreamhost.com/'; + $post_data['key'] = $this->_dnsPass; + $post_data['unique_id'] = uniqid($this->_dnsHost); + $post_data['cmd'] = 'dns-remove_record'; + $post_data['format'] = 'json'; + $post_data['value'] = $existing_ip; + $post_data['record'] = $this->_dnsHost; + $isv6 = ($this->_dnsService === 'dreamhost-v6'); + $post_data['type'] = $isv6 ? 'AAAA' : 'A'; + $port = ""; + if ($this->_dnsServer) { + $server = $this->_dnsServer; } - if ($this->_dnsService != 'ods') { - curl_setopt($ch, CURLOPT_HEADER, 1); - $response = curl_exec($ch); - $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $header = substr($response, 0, $header_size); - $data = substr($response, $header_size); - $this->_checkStatus($ch, $data, $header); - @curl_close($ch); + if ($this->_dnsPort) { + $port = ":" . $this->_dnsPort; } + curl_setopt($ch, CURLOPT_URL, $server . $port); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + break; + default: + break; } + if ($this->_dnsService != 'ods') { + curl_setopt($ch, CURLOPT_HEADER, 1); + $response = curl_exec($ch); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $data = substr($response, $header_size); + $this->_checkStatus($ch, $data, $header); + @curl_close($ch); + } + } /** * Private Function (added 23 Feb 17) @@ -1025,25 +1025,25 @@ } switch ($this->_dnsService) { - case 'dreamhost': - case 'dreamhost-v6': - $server = 'https://api.dreamhost.com/'; - $post_data['key'] = $this->_dnsPass; - $post_data['unique_id'] = uniqid($this->_dnsHost); - $post_data['cmd'] = 'dns-list_records'; - $post_data['format'] = 'json'; - $port = ""; - if ($this->_dnsServer) { - $server = $this->_dnsServer; - } - if ($this->_dnsPort) { - $port = ":" . $this->_dnsPort; - } - curl_setopt($ch, CURLOPT_URL, $server . $port); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - break; - default: - break; + case 'dreamhost': + case 'dreamhost-v6': + $server = 'https://api.dreamhost.com/'; + $post_data['key'] = $this->_dnsPass; + $post_data['unique_id'] = uniqid($this->_dnsHost); + $post_data['cmd'] = 'dns-list_records'; + $post_data['format'] = 'json'; + $port = ""; + if ($this->_dnsServer) { + $server = $this->_dnsServer; + } + if ($this->_dnsPort) { + $port = ":" . $this->_dnsPort; + } + curl_setopt($ch, CURLOPT_URL, $server . $port); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + break; + default: + break; } if ($this->_dnsService != 'ods') { curl_setopt($ch, CURLOPT_HEADER, 1); @@ -1075,35 +1075,35 @@ return; } switch ($this->_dnsService) { - case 'dreamhost': - case 'dreamhost-v6': - $result = json_decode($data,true); - if($result["result"] != "success") { - log_error($status_intro . gettext("PAYLOAD:") . " {$data}"); - $this->_debug($data); - return; - } else { - foreach($result["data"] as $key => $row) { - if($row["record"] == $this->_dnsHost && - (($row["type"] == "A" && !$this->_useIPv6) - || ($row["type"] == "AAAA" && $this->_useIPv6) - )) { - if($row["editable"] == 0) { - log_error($status_intro . "host " . $this->_dnsHost . " is not editable."); - continue; - } - $this->_existingRecords[]=array("record"=>$row["type"], "type"=>$row["type"], "existing_val"=>$row["value"]); + case 'dreamhost': + case 'dreamhost-v6': + $result = json_decode($data,true); + if($result["result"] != "success") { + log_error($status_intro . gettext("PAYLOAD:") . " {$data}"); + $this->_debug($data); + return; + } else { + foreach($result["data"] as $key => $row) { + if($row["record"] == $this->_dnsHost && + (($row["type"] == "A" && !$this->_useIPv6) + || ($row["type"] == "AAAA" && $this->_useIPv6) + )) { + if($row["editable"] == 0) { + log_error($status_intro . "host " . $this->_dnsHost . " is not editable."); + continue; } + $this->_existingRecords[]=array("record"=>$row["type"], "type"=>$row["type"], "existing_val"=>$row["value"]); } } - if (!is_array($this->_existingRecords)){ - if ($this->_dnsVerboseLog) { - log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() ending. No matching records found.'), $this->_dnsService, $this->_FQDN)); - } + } + if (!is_array($this->_existingRecords)){ + if ($this->_dnsVerboseLog) { + log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() ending. No matching records found.'), $this->_dnsService, $this->_FQDN)); } - break; - default: - break; + } + break; + default: + break; } } @@ -1774,68 +1774,68 @@ log_error(sprintf(gettext('_checkStatus() results: %1$s'), $data)); } switch ($result['data']) { - case 'success': - case 'record_added': - case 'record_removed': - $status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")"; - $successful_update = true; - break; - case 'no_record': - $status = $status_intro . $error_str . gettext("No record exists."); - break; - case 'no_type': - $status = $status_intro . $error_str . gettext("No type exists."); - break; - case 'no_value': - $status = $status_intro . $error_str . gettext("No value exists."); - break; - case 'no_such_record ': - $status = $status_intro . $error_str . gettext("No record exists."); - break; - case 'no_such_type ': - $status = $status_intro . $error_str . gettext("No type exists."); - break; - case 'no_such_value ': - $status = $status_intro . $error_str . gettext("No value exists."); - break; - case 'no_such_zone': - $status = $status_intro . $error_str . gettext("No such zone exists."); - break; - case 'invalid_record': - $status = $status_intro . $error_str . gettext("The specified record is invalid."); - break; - case 'invalid_type': - $status = $status_intro . $error_str . gettext("The specified type is invalid."); - break; - case 'invalid_value': - $status = $status_intro . $error_str . gettext("The specified value is invalid."); - break; - case 'not_editable ': - $status = $status_intro . $error_str . gettext("Record is not editable."); - break; - case 'record_already_exists_not_editable': - $status = $status_intro . $error_str . gettext("Record exists but is not editable."); - break; - case 'record_already_exists_remove_first': - $status = $status_intro . $error_str . gettext("Record exists and must be removed before adding."); - break; - case 'internal_error_updating_zone': - $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); - break; - case 'internal_error_could_not_load_zone': - $status = $status_intro . $error_str . gettext("A remote server error occurred loading the zone."); - break; - case 'internal_error_could_not_update_zone': - $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); - break; - case 'internal_error_could_not_add_record': - $status = $status_intro . $error_str . gettext("A remote server error occurred adding a new record."); - break; - case 'internal_error_could_not_destroy_record ': - $status = $status_intro . $error_str . gettext("A remote server error occurred removing an existing record."); - break; - default: - break; + case 'success': + case 'record_added': + case 'record_removed': + $status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")"; + $successful_update = true; + break; + case 'no_record': + $status = $status_intro . $error_str . gettext("No record exists."); + break; + case 'no_type': + $status = $status_intro . $error_str . gettext("No type exists."); + break; + case 'no_value': + $status = $status_intro . $error_str . gettext("No value exists."); + break; + case 'no_such_record ': + $status = $status_intro . $error_str . gettext("No record exists."); + break; + case 'no_such_type ': + $status = $status_intro . $error_str . gettext("No type exists."); + break; + case 'no_such_value ': + $status = $status_intro . $error_str . gettext("No value exists."); + break; + case 'no_such_zone': + $status = $status_intro . $error_str . gettext("No such zone exists."); + break; + case 'invalid_record': + $status = $status_intro . $error_str . gettext("The specified record is invalid."); + break; + case 'invalid_type': + $status = $status_intro . $error_str . gettext("The specified type is invalid."); + break; + case 'invalid_value': + $status = $status_intro . $error_str . gettext("The specified value is invalid."); + break; + case 'not_editable ': + $status = $status_intro . $error_str . gettext("Record is not editable."); + break; + case 'record_already_exists_not_editable': + $status = $status_intro . $error_str . gettext("Record exists but is not editable."); + break; + case 'record_already_exists_remove_first': + $status = $status_intro . $error_str . gettext("Record exists and must be removed before adding."); + break; + case 'internal_error_updating_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); + break; + case 'internal_error_could_not_load_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred loading the zone."); + break; + case 'internal_error_could_not_update_zone': + $status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone."); + break; + case 'internal_error_could_not_add_record': + $status = $status_intro . $error_str . gettext("A remote server error occurred adding a new record."); + break; + case 'internal_error_could_not_destroy_record ': + $status = $status_intro . $error_str . gettext("A remote server error occurred removing an existing record."); + break; + default: + break; } default: break; -- cgit v1.1 From 598c1d972afd7b5633de7d4eaf52d68750bd61a2 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 1 May 2017 20:51:16 -0400 Subject: Aggregated case statements to avoid duplication. --- src/etc/inc/dyndns.class | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index 318e2fb..46c3ac7 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -1781,20 +1781,14 @@ $successful_update = true; break; case 'no_record': - $status = $status_intro . $error_str . gettext("No record exists."); - break; - case 'no_type': - $status = $status_intro . $error_str . gettext("No type exists."); - break; - case 'no_value': - $status = $status_intro . $error_str . gettext("No value exists."); - break; case 'no_such_record ': $status = $status_intro . $error_str . gettext("No record exists."); break; + case 'no_type': case 'no_such_type ': $status = $status_intro . $error_str . gettext("No type exists."); break; + case 'no_value': case 'no_such_value ': $status = $status_intro . $error_str . gettext("No value exists."); break; -- cgit v1.1 From f2e702b175ba03ce31fb847b408a7f5ab170ea25 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 1 May 2017 21:07:47 -0400 Subject: Removed previous invalid conditionals and replaced with guard flags. Also updated some comments based on review / feedback. --- src/etc/inc/dyndns.class | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/etc/inc') diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/dyndns.class index 46c3ac7..39b532c 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/dyndns.class @@ -932,6 +932,7 @@ * @param unknown $existing_ip If required, an existing IP address for the record. */ function _remove($existing_ip = NULL) { + $remove_allowed = false; if ($this->_dnsVerboseLog) { log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _remove() starting.'), $this->_dnsService, $this->_FQDN)); } @@ -949,12 +950,10 @@ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } - if ($this->_dnsService != 'ods') { - curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); - curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical - } + curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); + curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical switch ($this->_dnsService) { case 'dreamhost': @@ -977,11 +976,12 @@ } curl_setopt($ch, CURLOPT_URL, $server . $port); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + $remove_allowed = true; break; default: break; } - if ($this->_dnsService != 'ods') { + if ($remove_allowed) { curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); @@ -994,12 +994,13 @@ /** * Private Function (added 23 Feb 17) - * Retrieves current DNS records. + * Retrieves current DNS records from an external API source. * * Some services cannot perform new operations without the caller * providing existing record information. */ function _lookup_current() { + $lookup_allowed = false; if ($this->_dnsVerboseLog) { log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _listCurrent() starting.'), $this->_dnsService, $this->_FQDN)); } @@ -1017,12 +1018,10 @@ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } - if ($this->_dnsService != 'ods') { - curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); - curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical - } + curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif); + curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical switch ($this->_dnsService) { case 'dreamhost': @@ -1041,11 +1040,12 @@ } curl_setopt($ch, CURLOPT_URL, $server . $port); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + $lookup_allowed = true; break; default: break; } - if ($this->_dnsService != 'ods') { + if ($lookup_allowed) { curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); @@ -1057,8 +1057,8 @@ } /* - * Private Function (added 12 July 2005) [beta] - * Retrieve Lookup Status + * Private Function (added 23 Feb 17) + * Retrieve Lookup Status from the provided data and/or header */ function _checkLookupStatus($ch, $data, $header) { if ($this->_dnsVerboseLog) { -- cgit v1.1