summaryrefslogtreecommitdiffstats
path: root/etc/inc/dyndns.class
diff options
context:
space:
mode:
authorErik Kristensen <ekristen@pfsense.org>2005-09-26 01:58:07 +0000
committerErik Kristensen <ekristen@pfsense.org>2005-09-26 01:58:07 +0000
commit1fa2f630e9e37dc2e02dff9ffae230552b1fec6f (patch)
treeeac9497eba39835022749af6e5c7c9a92e366f0d /etc/inc/dyndns.class
parenta058fad4bdd0406dc88f3d44d64bdc957a137338 (diff)
downloadpfsense-1fa2f630e9e37dc2e02dff9ffae230552b1fec6f.zip
pfsense-1fa2f630e9e37dc2e02dff9ffae230552b1fec6f.tar.gz
Add a 30 timeout to the DynDNS client.
Diffstat (limited to 'etc/inc/dyndns.class')
-rw-r--r--etc/inc/dyndns.class1087
1 files changed, 544 insertions, 543 deletions
diff --git a/etc/inc/dyndns.class b/etc/inc/dyndns.class
index e1ecc5c..64eaa58 100644
--- a/etc/inc/dyndns.class
+++ b/etc/inc/dyndns.class
@@ -1,544 +1,545 @@
-<?
- /*
- * PHP.updateDNS (pfSense version)
- *
- * +====================================================+
- * Services Supported:
- * - DynDns (dyndns.org) [dynamic, static, custom)
- * - DHSDns (dhs.org)
- * - No-IP (no-ip.com)
- * - EasyDNS (easydns.com)
- * - DHS (www.dhs.org)
- * - HN (hn.org)
- * - DynS (dyns.org)
- * - ZoneEdit (zoneedit.com)
- * +----------------------------------------------------+
- * Requirements:
- * - PHP version 4.0.2 or higher with CURL Library
- * +----------------------------------------------------+
- * Public Functions
- * - updatedns()
- *
- * Private Functions
- * - _update()
- * - _checkStatus()
- * - _error()
- * - _detectChange()
- * - _debug()
- * +----------------------------------------------------+
- * DynDNS Dynamic - Last Tested: 12 July 2005
- * DynDNS Static - Last Tested: NEVER
- * DynDNS Custom - Last Tested: NEVER
- * No-IP - Last Tested: 12 July 2005
- * HN.org - Last Tested: 12 July 2005
- * EasyDNS - Last Tested: NEVER
- * DHS - Last Tested: 12 July 2005
- * ZoneEdit - Last Tested: NEVER
- * Dyns - Last Tested: NEVER
- * +====================================================+
- *
- * @author E.Kristensen
- * @link http://www.idylldesigns.com/projects/phpdns/
- * @version 0.7
- * @updated 1 August 05 at 21:02:42 GMT
- *
- */
-
- class updatedns {
- var $_cacheFile = '/var/etc/dyndns.cache';
- var $_debugFile = '/var/etc/dyndns.debug';
- var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
- var $_errorVerbosity = 0;
- var $_dnsService;
- var $_dnsUser;
- var $_dnsPass;
- var $_dnsHost;
- var $_dnsIP;
- var $_dnsWildcard;
- var $_dnsMX;
- var $_dnsBackMX;
- var $status;
- var $_debugID;
-
- /*
- * Public Constructor Function (added 12 July 05) [beta]
- * - Gets the dice rolling for the update.
- */
- function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '', $dnsWildcard = 'OFF', $dnsMX = '', $dnsBackMX = '') {
- if (!$dnsService) $this->_error(2);
- if (!$dnsUser) $this->_error(3);
- if (!$dnsPass) $this->_error(4);
- if (!$dnsHost) $this->_error(5);
-
- $this->_dnsService = strtolower($dnsService);
- $this->_dnsUser = $dnsUser;
- $this->_dnsPass = $dnsPass;
- $this->_dnsHost = $dnsHost;
- $this->_dnsIP = $dnsIP;
- $this->_debugID = rand(1000000, 9999999);
-
- if ($this->_detectChange() == FALSE) {
- $this->_error(10);
- } else {
- if ($this->_dnsService == 'dyndns' ||
- $this->_dnsService == 'dyndns-static' ||
- $this->_dnsService == 'dyndns-custom' ||
- $this->_dnsService == 'dhs' ||
- $this->_dnsService == 'noip' ||
- $this->_dnsService == 'easydns' ||
- $this->_dnsService == 'hn' ||
- $this->_dnsService == 'zoneedit' ||
- $this->_dnsService == 'dyns' ||
- $this->_dnsService == 'ods')
- {
- $this->_update();
- } else {
- $this->_error(6);
- }
- }
-
- }
-
-
- /*
- * Private Function (added 12 July 05) [beta]
- * Send Update To Selected Service.
- */
- function _update() {
- if ($this->_dnsService != 'ods') {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- }
-
- switch ($this->_dnsService) {
- case 'dyndns':
- $needsIP = FALSE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'dyndns-static':
- $needsIP = FALSE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=statdns&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'dyndns-custom':
- $needsIP = FALSE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=custom&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'dhs':
- $needsIP = TRUE;
- $post_data['hostscmd'] = 'edit';
- $post_data['hostscmdstage'] = '2';
- $post_data['type'] = '4';
- $post_data['updatetype'] = 'Online';
- $post_data['mx'] = $this->_dnsMX;
- $post_data['mx2'] = '';
- $post_data['txt'] = '';
- $post_data['offline_url'] = '';
- $post_data['cloak'] = 'Y';
- $post_data['cloak_title'] = '';
- $post_data['ip'] = $this->_dnsIP;
- $post_data['domain'] = 'dyn.dhs.org';
- $post_data['hostname'] = $this->_dnsHost;
- $post_data['submit'] = 'Update';
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_URL, 'https://members.dhs.org/nic/hosts');
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'noip':
- $needsIP = TRUE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_URL, 'http://dynupdate.no-ip.com/dns?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&hostname='.$this->_dnsHost.'&ip='.$this->_dnsIP);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'easydns':
- $needsIP = TRUE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_URL, 'http://members.easydns.com/dyn/dyndns.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx='.$this->_dnsBackMX);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'hn':
- $needsIP = TRUE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
- curl_setopt($ch, CURLOPT_URL, 'http://dup.hn.org/vanity/update?ver=1&IP='.$this->_dnsIP);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'zoneedit':
- $needsIP = FALSE;
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_URL, 'https://dynamic.zoneedit.com/auth/dynamic.html?host='.$this->_dnsHost.'&dnsto='.$this->_dnsIP);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'dyns':
- $needsIP = FALSE;
- curl_setopt($ch, CURLOPT_URL, 'http://www.dyns.cx/postscript011.php?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&host='.$this->_dnsHost);
- $data = curl_exec($ch);
- curl_close($ch);
- $this->_checkStatus($data);
- break;
- case 'ods':
- $needsIP = FALSE;
- $this->con['socket'] = fsockopen("ods.org", "7070");
- /* Check that we have connected */
- if (!$this->con['socket']) {
- print "error! could not connect.";
- break;
- }
- /* Here is the loop. Read the incoming data (from the socket connection) */
- while (!feof($this->con['socket'])) {
- $this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
- $code = substr($this->con['buffer']['all'], 0, 3);
- sleep(1);
- switch($code) {
- case 100:
- fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
- break;
- case 225:
- fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
- break;
- case 901:
- fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
- break;
- case 795:
- fputs($this->con['socket'], "QUIT\n");
- break;
- }
- }
- $this->_checkStatus($code);
- break;
- default:
- break;
- }
- }
-
-
- /*
- * Private Function (added 12 July 2005) [beta]
- * Retrieve Update Status
- */
- function _checkStatus($data) {
- switch ($this->_dnsService) {
- case 'dyndns':
- if (preg_match('/notfqdn/i', $data)) {
- $status = "phpDynDNS: (Error) Not A FQDN!";
- } else if (preg_match('/nochg/i', $data)) {
- $status = "phpDynDNS: (Success) No Change In IP Address";
- } else if (preg_match('/good/i', $data)) {
- $status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
- } else if (preg_match('/noauth/i', $data)) {
- $status = "phpDynDNS: (Error) User Authorization Failed";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'dyndns-static':
- if (preg_match('/notfqdn/i', $data)) {
- $status = "phpDynDNS: (Error) Not A FQDN!";
- } else if (preg_match('/nochg/i', $data)) {
- $status = "phpDynDNS: (Success) No Change In IP Address";
- } else if (preg_match('/good/i', $data)) {
- $status = "phpDynDNS: (Success) IP Address Changed Successfully!";
- } else if (preg_match('/noauth/i', $data)) {
- $status = "phpDynDNS: (Error) User Authorization Failed";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'dyndns-custom':
- if (preg_match('/notfqdn/i', $data)) {
- $status = "phpDynDNS: (Error) Not A FQDN!";
- } else if (preg_match('/nochg/i', $data)) {
- $status = "phpDynDNS: (Success) No Change In IP Address";
- } else if (preg_match('/good/i', $data)) {
- $status = "phpDynDNS: (Success) IP Address Changed Successfully!";
- } else if (preg_match('/noauth/i', $data)) {
- $status = "phpDynDNS: (Error) User Authorization Failed";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'dhs':
- break;
- case 'noip':
- list($ip,$code) = split(":",$data);
- switch ($code) {
- case 0:
- $status = "phpDynDNS: (Success) IP address is current, no update performed.";
- break;
- case 1:
- $status = "phpDynDNS: (Success) DNS hostname update successful.";
- break;
- case 2:
- $status = "phpDynDNS: (Error) Hostname supplied does not exist.";
- break;
- case 3:
- $status = "phpDynDNS: (Error) Invalid Username.";
- break;
- case 4:
- $status = "phpDynDNS: (Error) Invalid Password.";
- break;
- case 5:
- $status = "phpDynDNS: (Error) To many updates sent.";
- break;
- case 6:
- $status = "phpDynDNS: (Error) Account disabled due to violation of No-IP terms of service.";
- break;
- case 7:
- $status = "phpDynDNS: (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
- break;
- case 8:
- $status = "phpDynDNS: (Error) Disabled / Locked Hostname.";
- break;
- case 9:
- $status = "phpDynDNS: (Error) Host updated is configured as a web redirect and no update was performed.";
- break;
- case 10:
- $status = "phpDynDNS: (Error) Group supplied does not exist.";
- break;
- case 11:
- $status = "phpDynDNS: (Success) DNS group update is successful.";
- break;
- case 12:
- $status = "phpDynDNS: (Success) DNS group is current, no update performed.";
- break;
- case 13:
- $status = "phpDynDNS: (Error) Update client support not available for supplied hostname or group.";
- break;
- case 14:
- $status = "phpDynDNS: (Error) Hostname supplied does not have offline settings configured.";
- break;
- case 99:
- $status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
- break;
- case 100:
- $status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
- break;
- default:
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- break;
- }
- break;
- case 'easydns':
- if (preg_match('/NOACCESS/i', $data)) {
- $status = "phpDynDNS: (Error) Authentication Failed: Username and/or Password was Incorrect.";
- } else if (preg_match('/NOSERVICE/i', $data)) {
- $status = "phpDynDNS: (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
- } else if (preg_match('/ILLEGAL INPUT/i', $data)) {
- $status = "phpDynDNS: (Error) Illegal Input: Self-Explantory";
- } else if (preg_match('/TOOSOON/i', $data)) {
- $status = "phpDynDNS: (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
- } else if (preg_match('/NOERROR/i', $data)) {
- $status = "phpDynDNS: (Success) IP Updated Successfully!";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'hn':
- break;
- case 'zoneedit':
- if (preg_match('/{700,799}/i', $data)) {
- $status = "phpDynDNS: (Error) Update Failed!";
- } else if (preg_match('/{200,201}/i', $data)) {
- $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'dyns':
- if (preg_match("/400/i", $data)) {
- $status = "phpDynDNS: (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
- } else if (preg_match('/402/i', $data)) {
- $status = "phpDynDNS: (Error) Update Too Soon - You have tried updating to quickly since last change.";
- } else if (preg_match('/403/i', $data)) {
- $status = "phpDynDNS: (Error) Database Error - There was a server-sided database error.";
- } else if (preg_match('/405/i', $data)) {
- $status = "phpDynDNS: (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
- } else if (preg_match('/200/i', $data)) {
- $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- case 'ods':
- if (preg_match("/299/i", $data)) {
- $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
- } else {
- $status = "phpDynDNS: (Unknown Response)";
- $this->_debug($data);
- }
- break;
- }
- $this->status = $status;
- log_error($status);
- }
-
-
- /*
- * Private Function (added 12 July 05) [beta]
- * Return Error, Set Last Error, and Die.
- */
- function _error($errorNumber = '1') {
- switch ($errorNumber) {
- case 0:
- break;
- case 2:
- $error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
- break;
- case 3:
- $error = 'phpDynDNS: (ERROR!) No Username Provided.';
- break;
- case 4:
- $error = 'phpDynDNS: (ERROR!) No Password Provided.';
- break;
- case 5:
- $error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
- break;
- case 6:
- $error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
- break;
- case 10:
- $error = 'phpDynDNS: No Change In My IP Address and/or 28 Days Has Not Past. Not Updating Dynamic DNS Entry.';
- break;
- default:
- $error = "phpDynDNS: (ERROR!) Unknown Response.";
- $this->_debug($data);
- break;
- }
- $this->lastError = $error;
- log_error($error);
- }
-
-
- /*
- * Private Function (added 12 July 05) [beta]
- * - Detect whether or not IP needs to be updated.
- * | Written Specifically for pfSense (pfsense.com) may
- * | work with other systems. pfSense base is FreeBSD.
- */
- function _detectChange() {
- $currentTime = time();
-
- #$wan_if = get_real_wan_interface();
- #$wan_ip = find_interface_ip($wan_if);
- $wan_ip = get_current_wan_address();
- $this->_dnsIP = $wan_ip;
-
- if (file_exists($this->_cacheFile)) {
- $file = fopen($this->_cacheFile, 'r');
- $contents = fread($file, filesize($this->_cacheFile));
- fclose($file);
- list($cacheIP,$cacheTime) = split(':', $contents);
-
- $this->_debug($cacheIP.'/'.$cacheTime);
-
- $initial = true;
- } else {
- $file = fopen($this->_cacheFile, 'w');
- fwrite($file, '0.0.0.0:'.$currentTime);
- fclose($file);
- $cacheIP = '0.0.0.0';
- $cacheTime = $currentTime;
-
- $initial = false;
- }
-
- switch ($this->_dnsService) {
- case 'dyndns':
- $time = '2419200';
- break;
- case 'dyndns-static':
- $time = '2419200';
- break;
- case 'dyndns-custom':
- $time = '2419200';
- break;
- case 'dhs':
- $time = '2419200';
- break;
- case 'easydns':
- $time = '2419200';
- break;
- case 'noip':
- $time = '2419200';
- break;
- case 'hn':
- $time = '2419200';
- break;
- case 'zoneedit':
- $time = '2419200';
- break;
- case 'dyns':
- $time = '2419200';
- break;
- case 'ods':
- $time = '2419200';
- break;
- }
-
- /* If IP addresses are different or 28 days have passed update record */
- if ( ($cacheIP != $wan_ip) || ( ($currentTime - $cacheTime) > $time ) || ($initial == true) ) {
- /* Write WAN IP to cache file */
- $file = fopen($this->_cacheFile, 'w');
- fwrite($file, $wan_ip.':'.$currentTime);
- fclose($file);
-
- return TRUE;
- } else {
-
- return FALSE;
- }
- }
-
-
- /*
- * Private Funcation (added 16 July 05) [beta]
- * - Writes debug information to a file.
- * - This function is only called when a unknown response
- * - status is returned from a DynDNS service provider.
- */
- function _debug ($data) {
- $string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data;
- $file = fopen($this->_debugFile, 'a');
- fwrite($file, $string);
- fclose($file);
- }
-
- }
-
+<?
+ /*
+ * PHP.updateDNS (pfSense version)
+ *
+ * +====================================================+
+ * Services Supported:
+ * - DynDns (dyndns.org) [dynamic, static, custom)
+ * - DHSDns (dhs.org)
+ * - No-IP (no-ip.com)
+ * - EasyDNS (easydns.com)
+ * - DHS (www.dhs.org)
+ * - HN (hn.org)
+ * - DynS (dyns.org)
+ * - ZoneEdit (zoneedit.com)
+ * +----------------------------------------------------+
+ * Requirements:
+ * - PHP version 4.0.2 or higher with CURL Library
+ * +----------------------------------------------------+
+ * Public Functions
+ * - updatedns()
+ *
+ * Private Functions
+ * - _update()
+ * - _checkStatus()
+ * - _error()
+ * - _detectChange()
+ * - _debug()
+ * +----------------------------------------------------+
+ * DynDNS Dynamic - Last Tested: 12 July 2005
+ * DynDNS Static - Last Tested: NEVER
+ * DynDNS Custom - Last Tested: NEVER
+ * No-IP - Last Tested: 12 July 2005
+ * HN.org - Last Tested: 12 July 2005
+ * EasyDNS - Last Tested: NEVER
+ * DHS - Last Tested: 12 July 2005
+ * ZoneEdit - Last Tested: NEVER
+ * Dyns - Last Tested: NEVER
+ * +====================================================+
+ *
+ * @author E.Kristensen
+ * @link http://www.idylldesigns.com/projects/phpdns/
+ * @version 0.7
+ * @updated 1 August 05 at 21:02:42 GMT
+ *
+ */
+
+ class updatedns {
+ var $_cacheFile = '/var/etc/dyndns.cache';
+ var $_debugFile = '/var/etc/dyndns.debug';
+ var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
+ var $_errorVerbosity = 0;
+ var $_dnsService;
+ var $_dnsUser;
+ var $_dnsPass;
+ var $_dnsHost;
+ var $_dnsIP;
+ var $_dnsWildcard;
+ var $_dnsMX;
+ var $_dnsBackMX;
+ var $status;
+ var $_debugID;
+
+ /*
+ * Public Constructor Function (added 12 July 05) [beta]
+ * - Gets the dice rolling for the update.
+ */
+ function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '', $dnsWildcard = 'OFF', $dnsMX = '', $dnsBackMX = '') {
+ if (!$dnsService) $this->_error(2);
+ if (!$dnsUser) $this->_error(3);
+ if (!$dnsPass) $this->_error(4);
+ if (!$dnsHost) $this->_error(5);
+
+ $this->_dnsService = strtolower($dnsService);
+ $this->_dnsUser = $dnsUser;
+ $this->_dnsPass = $dnsPass;
+ $this->_dnsHost = $dnsHost;
+ $this->_dnsIP = $dnsIP;
+ $this->_debugID = rand(1000000, 9999999);
+
+ if ($this->_detectChange() == FALSE) {
+ $this->_error(10);
+ } else {
+ if ($this->_dnsService == 'dyndns' ||
+ $this->_dnsService == 'dyndns-static' ||
+ $this->_dnsService == 'dyndns-custom' ||
+ $this->_dnsService == 'dhs' ||
+ $this->_dnsService == 'noip' ||
+ $this->_dnsService == 'easydns' ||
+ $this->_dnsService == 'hn' ||
+ $this->_dnsService == 'zoneedit' ||
+ $this->_dnsService == 'dyns' ||
+ $this->_dnsService == 'ods')
+ {
+ $this->_update();
+ } else {
+ $this->_error(6);
+ }
+ }
+
+ }
+
+
+ /*
+ * Private Function (added 12 July 05) [beta]
+ * Send Update To Selected Service.
+ */
+ function _update() {
+ if ($this->_dnsService != 'ods') {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
+ }
+
+ switch ($this->_dnsService) {
+ case 'dyndns':
+ $needsIP = FALSE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'dyndns-static':
+ $needsIP = FALSE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=statdns&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'dyndns-custom':
+ $needsIP = FALSE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=custom&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'dhs':
+ $needsIP = TRUE;
+ $post_data['hostscmd'] = 'edit';
+ $post_data['hostscmdstage'] = '2';
+ $post_data['type'] = '4';
+ $post_data['updatetype'] = 'Online';
+ $post_data['mx'] = $this->_dnsMX;
+ $post_data['mx2'] = '';
+ $post_data['txt'] = '';
+ $post_data['offline_url'] = '';
+ $post_data['cloak'] = 'Y';
+ $post_data['cloak_title'] = '';
+ $post_data['ip'] = $this->_dnsIP;
+ $post_data['domain'] = 'dyn.dhs.org';
+ $post_data['hostname'] = $this->_dnsHost;
+ $post_data['submit'] = 'Update';
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_URL, 'https://members.dhs.org/nic/hosts');
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'noip':
+ $needsIP = TRUE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_URL, 'http://dynupdate.no-ip.com/dns?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&hostname='.$this->_dnsHost.'&ip='.$this->_dnsIP);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'easydns':
+ $needsIP = TRUE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_URL, 'http://members.easydns.com/dyn/dyndns.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx='.$this->_dnsBackMX);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'hn':
+ $needsIP = TRUE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
+ curl_setopt($ch, CURLOPT_URL, 'http://dup.hn.org/vanity/update?ver=1&IP='.$this->_dnsIP);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'zoneedit':
+ $needsIP = FALSE;
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch, CURLOPT_URL, 'https://dynamic.zoneedit.com/auth/dynamic.html?host='.$this->_dnsHost.'&dnsto='.$this->_dnsIP);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'dyns':
+ $needsIP = FALSE;
+ curl_setopt($ch, CURLOPT_URL, 'http://www.dyns.cx/postscript011.php?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&host='.$this->_dnsHost);
+ $data = curl_exec($ch);
+ curl_close($ch);
+ $this->_checkStatus($data);
+ break;
+ case 'ods':
+ $needsIP = FALSE;
+ $this->con['socket'] = fsockopen("ods.org", "7070", $misc_errno, $misc_error, 30);
+ /* Check that we have connected */
+ if (!$this->con['socket']) {
+ print "error! could not connect.";
+ break;
+ }
+ /* Here is the loop. Read the incoming data (from the socket connection) */
+ while (!feof($this->con['socket'])) {
+ $this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
+ $code = substr($this->con['buffer']['all'], 0, 3);
+ sleep(1);
+ switch($code) {
+ case 100:
+ fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
+ break;
+ case 225:
+ fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
+ break;
+ case 901:
+ fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
+ break;
+ case 795:
+ fputs($this->con['socket'], "QUIT\n");
+ break;
+ }
+ }
+ $this->_checkStatus($code);
+ break;
+ default:
+ break;
+ }
+ }
+
+
+ /*
+ * Private Function (added 12 July 2005) [beta]
+ * Retrieve Update Status
+ */
+ function _checkStatus($data) {
+ switch ($this->_dnsService) {
+ case 'dyndns':
+ if (preg_match('/notfqdn/i', $data)) {
+ $status = "phpDynDNS: (Error) Not A FQDN!";
+ } else if (preg_match('/nochg/i', $data)) {
+ $status = "phpDynDNS: (Success) No Change In IP Address";
+ } else if (preg_match('/good/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
+ } else if (preg_match('/noauth/i', $data)) {
+ $status = "phpDynDNS: (Error) User Authorization Failed";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'dyndns-static':
+ if (preg_match('/notfqdn/i', $data)) {
+ $status = "phpDynDNS: (Error) Not A FQDN!";
+ } else if (preg_match('/nochg/i', $data)) {
+ $status = "phpDynDNS: (Success) No Change In IP Address";
+ } else if (preg_match('/good/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Address Changed Successfully!";
+ } else if (preg_match('/noauth/i', $data)) {
+ $status = "phpDynDNS: (Error) User Authorization Failed";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'dyndns-custom':
+ if (preg_match('/notfqdn/i', $data)) {
+ $status = "phpDynDNS: (Error) Not A FQDN!";
+ } else if (preg_match('/nochg/i', $data)) {
+ $status = "phpDynDNS: (Success) No Change In IP Address";
+ } else if (preg_match('/good/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Address Changed Successfully!";
+ } else if (preg_match('/noauth/i', $data)) {
+ $status = "phpDynDNS: (Error) User Authorization Failed";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'dhs':
+ break;
+ case 'noip':
+ list($ip,$code) = split(":",$data);
+ switch ($code) {
+ case 0:
+ $status = "phpDynDNS: (Success) IP address is current, no update performed.";
+ break;
+ case 1:
+ $status = "phpDynDNS: (Success) DNS hostname update successful.";
+ break;
+ case 2:
+ $status = "phpDynDNS: (Error) Hostname supplied does not exist.";
+ break;
+ case 3:
+ $status = "phpDynDNS: (Error) Invalid Username.";
+ break;
+ case 4:
+ $status = "phpDynDNS: (Error) Invalid Password.";
+ break;
+ case 5:
+ $status = "phpDynDNS: (Error) To many updates sent.";
+ break;
+ case 6:
+ $status = "phpDynDNS: (Error) Account disabled due to violation of No-IP terms of service.";
+ break;
+ case 7:
+ $status = "phpDynDNS: (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
+ break;
+ case 8:
+ $status = "phpDynDNS: (Error) Disabled / Locked Hostname.";
+ break;
+ case 9:
+ $status = "phpDynDNS: (Error) Host updated is configured as a web redirect and no update was performed.";
+ break;
+ case 10:
+ $status = "phpDynDNS: (Error) Group supplied does not exist.";
+ break;
+ case 11:
+ $status = "phpDynDNS: (Success) DNS group update is successful.";
+ break;
+ case 12:
+ $status = "phpDynDNS: (Success) DNS group is current, no update performed.";
+ break;
+ case 13:
+ $status = "phpDynDNS: (Error) Update client support not available for supplied hostname or group.";
+ break;
+ case 14:
+ $status = "phpDynDNS: (Error) Hostname supplied does not have offline settings configured.";
+ break;
+ case 99:
+ $status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
+ break;
+ case 100:
+ $status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
+ break;
+ default:
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ break;
+ }
+ break;
+ case 'easydns':
+ if (preg_match('/NOACCESS/i', $data)) {
+ $status = "phpDynDNS: (Error) Authentication Failed: Username and/or Password was Incorrect.";
+ } else if (preg_match('/NOSERVICE/i', $data)) {
+ $status = "phpDynDNS: (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
+ } else if (preg_match('/ILLEGAL INPUT/i', $data)) {
+ $status = "phpDynDNS: (Error) Illegal Input: Self-Explantory";
+ } else if (preg_match('/TOOSOON/i', $data)) {
+ $status = "phpDynDNS: (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
+ } else if (preg_match('/NOERROR/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Updated Successfully!";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'hn':
+ break;
+ case 'zoneedit':
+ if (preg_match('/{700,799}/i', $data)) {
+ $status = "phpDynDNS: (Error) Update Failed!";
+ } else if (preg_match('/{200,201}/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'dyns':
+ if (preg_match("/400/i", $data)) {
+ $status = "phpDynDNS: (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
+ } else if (preg_match('/402/i', $data)) {
+ $status = "phpDynDNS: (Error) Update Too Soon - You have tried updating to quickly since last change.";
+ } else if (preg_match('/403/i', $data)) {
+ $status = "phpDynDNS: (Error) Database Error - There was a server-sided database error.";
+ } else if (preg_match('/405/i', $data)) {
+ $status = "phpDynDNS: (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
+ } else if (preg_match('/200/i', $data)) {
+ $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ case 'ods':
+ if (preg_match("/299/i", $data)) {
+ $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
+ } else {
+ $status = "phpDynDNS: (Unknown Response)";
+ $this->_debug($data);
+ }
+ break;
+ }
+ $this->status = $status;
+ log_error($status);
+ }
+
+
+ /*
+ * Private Function (added 12 July 05) [beta]
+ * Return Error, Set Last Error, and Die.
+ */
+ function _error($errorNumber = '1') {
+ switch ($errorNumber) {
+ case 0:
+ break;
+ case 2:
+ $error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
+ break;
+ case 3:
+ $error = 'phpDynDNS: (ERROR!) No Username Provided.';
+ break;
+ case 4:
+ $error = 'phpDynDNS: (ERROR!) No Password Provided.';
+ break;
+ case 5:
+ $error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
+ break;
+ case 6:
+ $error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
+ break;
+ case 10:
+ $error = 'phpDynDNS: No Change In My IP Address and/or 28 Days Has Not Past. Not Updating Dynamic DNS Entry.';
+ break;
+ default:
+ $error = "phpDynDNS: (ERROR!) Unknown Response.";
+ $this->_debug($data);
+ break;
+ }
+ $this->lastError = $error;
+ log_error($error);
+ }
+
+
+ /*
+ * Private Function (added 12 July 05) [beta]
+ * - Detect whether or not IP needs to be updated.
+ * | Written Specifically for pfSense (pfsense.com) may
+ * | work with other systems. pfSense base is FreeBSD.
+ */
+ function _detectChange() {
+ $currentTime = time();
+
+ #$wan_if = get_real_wan_interface();
+ #$wan_ip = find_interface_ip($wan_if);
+ $wan_ip = get_current_wan_address();
+ $this->_dnsIP = $wan_ip;
+
+ if (file_exists($this->_cacheFile)) {
+ $file = fopen($this->_cacheFile, 'r');
+ $contents = fread($file, filesize($this->_cacheFile));
+ fclose($file);
+ list($cacheIP,$cacheTime) = split(':', $contents);
+
+ $this->_debug($cacheIP.'/'.$cacheTime);
+
+ $initial = true;
+ } else {
+ $file = fopen($this->_cacheFile, 'w');
+ fwrite($file, '0.0.0.0:'.$currentTime);
+ fclose($file);
+ $cacheIP = '0.0.0.0';
+ $cacheTime = $currentTime;
+
+ $initial = false;
+ }
+
+ switch ($this->_dnsService) {
+ case 'dyndns':
+ $time = '2419200';
+ break;
+ case 'dyndns-static':
+ $time = '2419200';
+ break;
+ case 'dyndns-custom':
+ $time = '2419200';
+ break;
+ case 'dhs':
+ $time = '2419200';
+ break;
+ case 'easydns':
+ $time = '2419200';
+ break;
+ case 'noip':
+ $time = '2419200';
+ break;
+ case 'hn':
+ $time = '2419200';
+ break;
+ case 'zoneedit':
+ $time = '2419200';
+ break;
+ case 'dyns':
+ $time = '2419200';
+ break;
+ case 'ods':
+ $time = '2419200';
+ break;
+ }
+
+ /* If IP addresses are different or 28 days have passed update record */
+ if ( ($cacheIP != $wan_ip) || ( ($currentTime - $cacheTime) > $time ) || ($initial == true) ) {
+ /* Write WAN IP to cache file */
+ $file = fopen($this->_cacheFile, 'w');
+ fwrite($file, $wan_ip.':'.$currentTime);
+ fclose($file);
+
+ return TRUE;
+ } else {
+
+ return FALSE;
+ }
+ }
+
+
+ /*
+ * Private Funcation (added 16 July 05) [beta]
+ * - Writes debug information to a file.
+ * - This function is only called when a unknown response
+ * - status is returned from a DynDNS service provider.
+ */
+ function _debug ($data) {
+ $string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data;
+ $file = fopen($this->_debugFile, 'a');
+ fwrite($file, $string);
+ fclose($file);
+ }
+
+ }
+
?> \ No newline at end of file
OpenPOWER on IntegriCloud