Project

General

Profile

Download (53.4 KB) Statistics
| Branch: | Tag: | Revision:
1 d237be68 Scott Ullrich
<?php
2 1fa2f630 Erik Kristensen
	/*
3
	 * PHP.updateDNS (pfSense version)
4
	 *
5
	 * +====================================================+
6
	 *  Services Supported:
7 9b8dc821 Scott Ullrich
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
8 1fa2f630 Erik Kristensen
	 *    - DHSDns (dhs.org)
9
	 *    - No-IP (no-ip.com)
10
	 *    - EasyDNS (easydns.com)
11
	 *    - DHS (www.dhs.org)
12 9b8dc821 Scott Ullrich
	 *    - HN (hn.org) -- incomplete checking!
13 1fa2f630 Erik Kristensen
	 *    - DynS (dyns.org)
14
	 *    - ZoneEdit (zoneedit.com)
15 9b8dc821 Scott Ullrich
	 *    - FreeDNS (freedns.afraid.org)
16
	 *    - Loopia (loopia.se)
17
	 *    - StaticCling (staticcling.org)
18 0a1b0183 Ermal Luçi
	 *    - DNSexit (dnsexit.com)
19 2d78b166 Ermal Luçi
	 *    - OpenDNS (opendns.com)
20 61c30081 jim-p
	 *    - Namecheap (namecheap.com)
21 8ea77433 Chris Wells
	 *    - HE.net (dns.he.net)
22 da40615d Daniel Becker
	 *    - HE.net IPv6 (dns.he.net)
23 38a481ad jim-p
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
24 fb403496 Gerald Raaf
	 *    - SelfHost (selfhost.de)
25 37f3e704 Matt Corallo
	 *    - Amazon Route 53 (aws.amazon.com)
26
	 *    - DNS-O-Matic (dnsomatic.com)
27
	 *    - Custom DDNS (any URL)
28 da40615d Daniel Becker
	 *    - Custom DDNS IPv6 (any URL)
29 e26e1f76 Andrew Senetar
	 *    - CloudFlare (www.cloudflare.com)
30 ec66caa6 John Byron
 	 *    - Eurodns (eurodns.com)
31 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
32
	 *  Requirements:
33 37f3e704 Matt Corallo
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
34 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
35
	 *  Public Functions
36
	 *    - updatedns()
37
	 *
38
	 *  Private Functions
39
	 *    - _update()
40
	 *    - _checkStatus()
41
	 *    - _error()
42
	 *    - _detectChange()
43
	 *    - _debug()
44 22de7804 Bill Marquette
	 *    - _checkIP()
45 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
46
	 *  DynDNS Dynamic - Last Tested: 12 July 2005
47
	 *  DynDNS Static  - Last Tested: NEVER
48
	 *  DynDNS Custom  - Last Tested: NEVER
49 fdcaa527 Ermal Luçi
	 *  No-IP          - Last Tested: 20 July 2008
50 1fa2f630 Erik Kristensen
	 *  HN.org         - Last Tested: 12 July 2005
51 fdcaa527 Ermal Luçi
	 *  EasyDNS        - Last Tested: 20 July 2008
52 1fa2f630 Erik Kristensen
	 *  DHS            - Last Tested: 12 July 2005
53
	 *  ZoneEdit       - Last Tested: NEVER
54
	 *  Dyns           - Last Tested: NEVER
55 0da417be Erik Kristensen
	 *  ODS            - Last Tested: 02 August 2005
56 62ce9874 gnhb
	 *  FreeDNS        - Last Tested: 23 Feb 2011
57 9b8dc821 Scott Ullrich
	 *  Loopia         - Last Tested: NEVER
58
	 *  StaticCling    - Last Tested: 27 April 2006
59 0a1b0183 Ermal Luçi
	 *  DNSexit	   - Last Tested: 20 July 2008
60 2d78b166 Ermal Luçi
	 *  OpenDNS	   - Last Tested: 4 August 2008
61 18f15f68 jim-p
	 *  Namecheap	   - Last Tested: 31 August 2010
62 da40615d Daniel Becker
	 *  HE.net         - Last Tested: 7 July 2013
63
	 *  HE.net IPv6    - Last Tested: 7 July 2013
64 38a481ad jim-p
	 *  HE.net Tunnel  - Last Tested: 28 June 2011
65 fb403496 Gerald Raaf
	 *  SelfHost       - Last Tested: 26 December 2011
66 37f3e704 Matt Corallo
	 *  Amazon Route 53 - Last tested: 01 April 2012
67
	 *  DNS-O-Matic	   - Last Tested: 9 September 2010
68 e26e1f76 Andrew Senetar
	 *  CloudFlare     - Last Tested: 30 May 2013
69 ec66caa6 John Byron
  	 *  Eurodns	   		- Last Tested : 27 June 2013
70 1fa2f630 Erik Kristensen
	 * +====================================================+
71
	 *
72 e24b26e9 Scott Ullrich
	 * @author 	E.Kristensen
73 1fa2f630 Erik Kristensen
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
74 0da417be Erik Kristensen
	 * @version 	0.8
75 e24b26e9 Scott Ullrich
	 * @updated	13 October 05 at 21:02:42 GMT
76 1fa2f630 Erik Kristensen
	 *
77 1bf52c67 Phil Davis
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luci
78 37f3e704 Matt Corallo
	 * Custom DNS support by Matt Corallo
79 0a1b0183 Ermal Luçi
	 *
80 1fa2f630 Erik Kristensen
	 */
81
82
	class updatedns {
83 67ee1ec5 Ermal Luçi
		var $_cacheFile;
84 d7e6f573 Daniel Becker
		var $_cacheFile_v6;
85 67ee1ec5 Ermal Luçi
		var $_debugFile;
86 1fa2f630 Erik Kristensen
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
87
		var $_errorVerbosity = 0;
88
		var $_dnsService;
89
		var $_dnsUser;
90
		var $_dnsPass;
91
		var $_dnsHost;
92
		var $_dnsIP;
93
		var $_dnsWildcard;
94
		var $_dnsMX;
95
		var $_dnsBackMX;
96 9b8dc821 Scott Ullrich
		var $_dnsServer;
97
		var $_dnsPort;
98
		var $_dnsUpdateURL;
99 cd132e86 Edson Brandi
		var $_dnsZoneID;
100
		var $_dnsTTL;
101 1fa2f630 Erik Kristensen
		var $status;
102
		var $_debugID;
103 67ee1ec5 Ermal Luçi
		var $_if;
104 37f3e704 Matt Corallo
		var $_dnsResultMatch;
105
		var $_dnsRequestIf;
106
		var $_dnsRequestIfIP;
107 87b91672 Phil Davis
		var $_dnsVerboseLog;
108 aa79f351 Sebastian Chrostek
		var $_curlIpresolveV4;
109
		var $_curlSslVerifypeer;
110 f5e293e6 Phil Davis
		var $_dnsMaxCacheAgeDays;
111 0333f968 Phil Davis
		var $_dnsDummyUpdateDone;
112
		var $_forceUpdateNeeded;
113 b4025ccd Daniel Becker
		var $_useIPv6;
114 9b8dc821 Scott Ullrich
		
115 1fa2f630 Erik Kristensen
		/* 
116
		 * Public Constructor Function (added 12 July 05) [beta]
117
		 *   - Gets the dice rolling for the update. 
118 37f3e704 Matt Corallo
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
119
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to, 
120 1bf52c67 Phil Davis
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
121 37f3e704 Matt Corallo
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
122
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
123 1fa2f630 Erik Kristensen
		 */
124 9b8dc821 Scott Ullrich
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
125 21d41faa Ermal Lu?i
				    $dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
126 cd132e86 Edson Brandi
				    $dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
127 37f3e704 Matt Corallo
				    $dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
128 aa79f351 Sebastian Chrostek
				    $dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
129 9b8dc821 Scott Ullrich
			
130 23e69ae8 Ermal Lu?i
			global $config, $g;
131 9b8dc821 Scott Ullrich
			
132 37f3e704 Matt Corallo
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache";
133 d7e6f573 Daniel Becker
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache";
134 37f3e704 Matt Corallo
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.debug";
135 67ee1ec5 Ermal Luçi
136 aa79f351 Sebastian Chrostek
			$this->_curlIpresolveV4 = $curlIpresolveV4;
137
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
138 87b91672 Phil Davis
			$this->_dnsVerboseLog = $dnsVerboseLog;
139
			if ($this->_dnsVerboseLog)
140
				log_error("DynDns: updatedns() starting");
141 71070cc5 Ermal
142 37f3e704 Matt Corallo
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
143 71070cc5 Ermal
144 1fa2f630 Erik Kristensen
			if (!$dnsService) $this->_error(2);
145 ce6d1106 jim-p
			switch ($dnsService) {
146
			case 'freedns':
147
				if (!$dnsHost) $this->_error(5);
148
				break;
149
			case 'namecheap':
150 9b8dc821 Scott Ullrich
				if (!$dnsPass) $this->_error(4);
151
				if (!$dnsHost) $this->_error(5);
152 ce6d1106 jim-p
				break;
153 37f3e704 Matt Corallo
			case 'route53':
154
				if (!$dnsZoneID) $this->_error(8);
155
				if (!$dnsTTL) $this->_error(9);
156
				break;
157
			case 'custom':
158
				if (!$dnsUpdateURL) $this->_error(7);
159
				break;
160 ce6d1106 jim-p
			default:
161
				if (!$dnsUser) $this->_error(3);
162
				if (!$dnsPass) $this->_error(4);
163 99295d7b Scott Ullrich
				if (!$dnsHost) $this->_error(5);
164 9b8dc821 Scott Ullrich
			}
165
			
166 b4025ccd Daniel Becker
			switch ($dnsService) {
167
			case 'he-net-v6':
168 da40615d Daniel Becker
			case 'custom-v6':
169 b4025ccd Daniel Becker
				$this->_useIPv6 = true;
170
				break;
171
			default:
172
				$this->_useIPv6 = false;
173
			}
174 1fa2f630 Erik Kristensen
			$this->_dnsService = strtolower($dnsService);
175
			$this->_dnsUser = $dnsUser;
176
			$this->_dnsPass = $dnsPass;
177
			$this->_dnsHost = $dnsHost;
178 9b8dc821 Scott Ullrich
			$this->_dnsServer = $dnsServer;
179
			$this->_dnsPort = $dnsPort;
180
			$this->_dnsWildcard = $dnsWildcard;
181
			$this->_dnsMX = $dnsMX;
182 0c7bb880 Phil Davis
			$this->_dnsZoneID = $dnsZoneID;
183
			$this->_dnsTTL = $dnsTTL;
184 bf001dec smos
			$this->_if = get_failover_interface($dnsIf);
185 fffbfef0 Matt Corallo
			$this->_checkIP();
186 37f3e704 Matt Corallo
			$this->_dnsUpdateURL = $dnsUpdateURL;
187
			$this->_dnsResultMatch = $dnsResultMatch;
188 bf001dec smos
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
189 87b91672 Phil Davis
			if ($this->_dnsVerboseLog)
190
				log_error("DynDNS ({$this->_dnsHost}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}");
191 37f3e704 Matt Corallo
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
192 f5e293e6 Phil Davis
			$this->_dnsMaxCacheAgeDays = 25;
193 0333f968 Phil Davis
			$this->_dnsDummyUpdateDone = false;
194
			$this->_forceUpdateNeeded = $forceUpdate;
195
			
196 0c7bb880 Phil Davis
			// Ensure that we were able to lookup the IP
197 fffbfef0 Matt Corallo
			if(!is_ipaddr($this->_dnsIP)) {
198 2223aa95 smos
				log_error("DynDNS ({$this->_dnsHost}) There was an error trying to determine the public IP for interface - {$dnsIf}({$this->_if}). Probably interface is not a WAN interface.");
199 fffbfef0 Matt Corallo
				unlock($dyndnslck);
200
				return;
201
			}
202 07a3b40b sullrich
203 1fa2f630 Erik Kristensen
			$this->_debugID = rand(1000000, 9999999);
204 9b8dc821 Scott Ullrich
			
205 d7e6f573 Daniel Becker
			if ($forceUpdate == false && $this->_detectChange() == false) {
206 1fa2f630 Erik Kristensen
				$this->_error(10);
207
			} else {
208 9d96a475 Ermal Lu?i
				switch ($this->_dnsService) {
209
				case 'dnsomatic':
210
				case 'dyndns':
211
				case 'dyndns-static':
212
				case 'dyndns-custom':
213
				case 'dhs':
214
				case 'noip':
215 0333f968 Phil Davis
				case 'noip-free':
216 9d96a475 Ermal Lu?i
				case 'easydns':
217
				case 'hn':
218
				case 'zoneedit':
219
				case 'dyns':
220
				case 'ods':
221
				case 'freedns':
222
				case 'loopia':
223
				case 'staticcling':
224
				case 'dnsexit':
225 37f3e704 Matt Corallo
				case 'custom':
226 da40615d Daniel Becker
				case 'custom-v6':
227 9d96a475 Ermal Lu?i
				case 'opendns':
228 61c30081 jim-p
				case 'namecheap':
229 8ea77433 Chris Wells
				case 'he-net':
230 b4025ccd Daniel Becker
				case 'he-net-v6':
231 fb403496 Gerald Raaf
				case 'selfhost':
232 37f3e704 Matt Corallo
				case 'he-net-tunnelbroker':
233 cd132e86 Edson Brandi
				case 'route53':
234 e26e1f76 Andrew Senetar
				case 'cloudflare':
235 ec66caa6 John Byron
				case 'eurodns':
236 0333f968 Phil Davis
					$this->_update();
237
					if($this->_dnsDummyUpdateDone == true) {
238
						// If a dummy update was needed, then sleep a while and do the update again to put the proper address back.
239
						// Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month.
240
						// If the address has not changed recently, or the user did "Force Update", then the code does
241
						// a dummy address change for providers like this.
242
						sleep(10);
243
						$this->_update();
244
					}
245 9d96a475 Ermal Lu?i
					break;
246
				default:
247 1fa2f630 Erik Kristensen
					$this->_error(6);
248 9d96a475 Ermal Lu?i
					break;
249 1fa2f630 Erik Kristensen
				}
250 9d96a475 Ermal Lu?i
			}
251 71070cc5 Ermal
252
			unlock($dyndnslck);
253 1fa2f630 Erik Kristensen
		}
254 9b8dc821 Scott Ullrich
			
255 1fa2f630 Erik Kristensen
		/*
256
		 * Private Function (added 12 July 05) [beta]
257
		 *   Send Update To Selected Service.
258
		 */
259
		function _update() {
260 1331005d Scott Ullrich
		
261 87b91672 Phil Davis
			if ($this->_dnsVerboseLog)
262
				log_error("DynDNS ({$this->_dnsHost}): DynDns _update() starting.");
263 1331005d Scott Ullrich
		
264 cd132e86 Edson Brandi
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
265 1fa2f630 Erik Kristensen
				$ch = curl_init();
266
				curl_setopt($ch, CURLOPT_HEADER, 0);
267
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
268
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
269 37f3e704 Matt Corallo
				curl_setopt($ch, CURLOPT_INTERFACE, $this->_dnsRequestIfIP);
270 93b8df2a Ermal
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
271 1fa2f630 Erik Kristensen
			}
272
273
			switch ($this->_dnsService) {
274
				case 'dyndns':
275
				case 'dyndns-static':
276 52e95286 Ermal
				case 'dyndns-custom':
277 1fa2f630 Erik Kristensen
					$needsIP = FALSE;
278 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
279
						log_error("DynDNS: ({$this->_dnsHost}) DNS update() starting.");
280 9b8dc821 Scott Ullrich
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
281 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
282
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
283 9b8dc821 Scott Ullrich
					$server = "https://members.dyndns.org/nic/update";
284
					$port = "";
285
					if($this->_dnsServer)
286
						$server = $this->_dnsServer;
287
					if($this->_dnsPort)
288
						$port = ":" . $this->_dnsPort;
289 52e95286 Ermal
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
290 1fa2f630 Erik Kristensen
					break;
291
				case 'dhs':
292
					$needsIP = TRUE;
293 a255e1f7 Scott Ullrich
					$post_data['hostscmd'] = 'edit';
294
					$post_data['hostscmdstage'] = '2';
295
					$post_data['type'] = '4';
296
					$post_data['updatetype'] = 'Online';
297
					$post_data['mx'] = $this->_dnsMX;
298
					$post_data['mx2'] = '';
299
					$post_data['txt'] = '';
300
					$post_data['offline_url'] = '';
301
					$post_data['cloak'] = 'Y';
302
					$post_data['cloak_title'] = '';
303
					$post_data['ip'] = $this->_dnsIP;
304
					$post_data['domain'] = 'dyn.dhs.org';
305
					$post_data['hostname'] = $this->_dnsHost;
306
					$post_data['submit'] = 'Update';
307 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
308 9b8dc821 Scott Ullrich
					$server = "https://members.dhs.org/nic/hosts";
309
					$port = "";
310
					if($this->_dnsServer)
311
						$server = $this->_dnsServer;
312
					if($this->_dnsPort)
313
						$port = ":" . $this->_dnsPort;					
314
					curl_setopt($ch, CURLOPT_URL, '{$server}{$port}');
315 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
316
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
317
					break;
318
				case 'noip':
319 0333f968 Phil Davis
				case 'noip-free':
320 1fa2f630 Erik Kristensen
					$needsIP = TRUE;
321
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
322 c61e56a7 Scott Ullrich
					$server = "http://dynupdate.no-ip.com/ducupdate.php";
323 9b8dc821 Scott Ullrich
					$port = "";
324
					if($this->_dnsServer)
325
						$server = $this->_dnsServer;
326
					if($this->_dnsPort)
327
						$port = ":" . $this->_dnsPort;
328 0333f968 Phil Davis
					if(($this->_dnsService == "noip-free") && 
329
					   ($this->_forceUpdateNeeded == true) && 
330
					   ($this->_dnsDummyUpdateDone == false)) {
331
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
332
						$iptoset = "192.168.1.1";
333
						$this->_dnsDummyUpdateDone = true;
334
						log_error("DynDNS ({$this->_dnsHost}): Processing dummy update on No-IP free account. IP temporarily set to " . $iptoset);
335
					} else {
336
						$iptoset = $this->_dnsIP;
337
					}
338
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&hostname=' . $this->_dnsHost.'&ip=' . $iptoset);
339 1fa2f630 Erik Kristensen
					break;
340
				case 'easydns':
341
					$needsIP = TRUE;
342
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
343
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
344 9b8dc821 Scott Ullrich
					$server = "http://members.easydns.com/dyn/dyndns.php";
345
					$port = "";
346
					if($this->_dnsServer)
347
						$server = $this->_dnsServer;
348
					if($this->_dnsPort)
349
						$port = ":" . $this->_dnsPort;
350 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
351 1fa2f630 Erik Kristensen
					break;
352
				case 'hn':
353
					$needsIP = TRUE;
354
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
355
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
356 9b8dc821 Scott Ullrich
					$server = "http://dup.hn.org/vanity/update";
357
					$port = "";
358
					if($this->_dnsServer)
359
						$server = $this->_dnsServer;
360
					if($this->_dnsPort)
361
						$port = ":" . $this->_dnsPort;
362 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
363 1fa2f630 Erik Kristensen
					break;
364
				case 'zoneedit':
365
					$needsIP = FALSE;
366
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
367 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
368
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
369
370 9b8dc821 Scott Ullrich
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
371
					$port = "";
372
					if($this->_dnsServer)
373
						$server = $this->_dnsServer;
374
					if($this->_dnsPort)
375
						$port = ":" . $this->_dnsPort;
376 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
377 1fa2f630 Erik Kristensen
					break;
378
				case 'dyns':
379
					$needsIP = FALSE;
380 9b8dc821 Scott Ullrich
					$server = "http://www.dyns.cx/postscript011.php";
381
					$port = "";
382
					if($this->_dnsServer)
383
						$server = $this->_dnsServer;
384
					if($this->_dnsPort)
385
						$port = ":" . $this->_dnsPort;					
386 fdcaa527 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
387 1fa2f630 Erik Kristensen
					break;
388
				case 'ods':
389
					$needsIP = FALSE;
390 9b8dc821 Scott Ullrich
					$misc_errno = 0;
391
					$misc_error = "";
392
					$server = "ods.org";
393
					$port = "";
394
					if($this->_dnsServer)
395
						$server = $this->_dnsServer;
396
					if($this->_dnsPort)
397
						$port = ":" . $this->_dnsPort;						
398
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
399 1fa2f630 Erik Kristensen
					/* Check that we have connected */
400
					if (!$this->con['socket']) {
401
						print "error! could not connect.";
402
						break;
403
					}
404
					/* Here is the loop. Read the incoming data (from the socket connection) */
405
					while (!feof($this->con['socket'])) {
406
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
407
						$code = substr($this->con['buffer']['all'], 0, 3);
408
						sleep(1);
409
						switch($code) {
410
							case 100:
411
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
412
								break;
413
							case 225:
414
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
415
								break;
416
							case 901:
417
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
418
								break;
419
							case 795:
420
								fputs($this->con['socket'], "QUIT\n");
421
								break;
422
						}
423
					}
424 425ba708 Ermal
					$this->_checkStatus(0, $code);
425 1fa2f630 Erik Kristensen
					break;
426 9b8dc821 Scott Ullrich
				case 'freedns':
427
					$needIP = FALSE;
428 d9cc4b24 gnhb
					curl_setopt($ch, CURLOPT_URL, 'http://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
429 9b8dc821 Scott Ullrich
					break;
430 0a1b0183 Ermal Luçi
				case 'dnsexit':
431
					$needsIP = TRUE;
432 d74b5b8b sullrich
					curl_setopt($ch, CURLOPT_URL, 'http://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
433 0a1b0183 Ermal Luçi
					break;
434 9b8dc821 Scott Ullrich
				case 'loopia':
435
					$needsIP = TRUE;
436
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
437
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
438 99295d7b Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
439 9b8dc821 Scott Ullrich
					break;
440 2d78b166 Ermal Luçi
				case 'opendns':
441
					$needsIP = FALSE;
442
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
443
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
444
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
445 6bccf4ca smos
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
446 2d78b166 Ermal Luçi
					$port = "";
447
					if($this->_dnsServer)
448
						$server = $this->_dnsServer;
449
					if($this->_dnsPort)
450
						$port = ":" . $this->_dnsPort;
451
					curl_setopt($ch, CURLOPT_URL, $server .$port);
452
					break;
453
454 d74b5b8b sullrich
				case 'staticcling':
455
					$needsIP = FALSE;
456
					curl_setopt($ch, CURLOPT_URL, 'http://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
457
					break;	                    
458 52e6fdfd Scott Dale
				case 'dnsomatic':
459
					/* Example syntax 
460
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
461
					*/
462
					$needsIP = FALSE;
463 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
464
						log_error("DNS-O-Matic: DNS update() starting.");
465 52e6fdfd Scott Dale
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
466
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
467 99438649 swatspyder
					/*
468
					Reference: https://www.dnsomatic.com/wiki/api
469
						DNS-O-Matic usernames are 3-25 characters.
470
						DNS-O-Matic passwords are 6-20 characters.
471
						All ASCII letters and numbers accepted.
472
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
473
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
474
						Encodes the given string according to RFC 3986.
475
					*/
476
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
477 52e6fdfd Scott Dale
					if($this->_dnsServer)
478
						$server = $this->_dnsServer;
479
					if($this->_dnsPort)
480
						$port = ":" . $this->_dnsPort;
481
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
482
					break;
483 61c30081 jim-p
				case 'namecheap':
484
					/* Example:
485
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
486
					*/
487
					$needsIP = FALSE;
488 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
489
						log_error("Namecheap ({$this->_dnsHost}): DNS update() starting.");
490 61c30081 jim-p
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
491 4178d033 jim-p
					$dparts = explode(".", trim($this->_dnsHost));
492 e8fc69ff jim-p
					$domain_part_count = ($dparts[count($dparts)-1] == "uk") ? 3 : 2;
493
					$domain_offset = count($dparts) - $domain_part_count;
494
					$hostname = implode(".", array_slice($dparts, 0, $domain_offset));
495
					$domain = implode(".", array_slice($dparts, $domain_offset));
496 4178d033 jim-p
					$dnspass = trim($this->_dnsPass);
497
					$server = "https://dynamicdns.park-your-domain.com/update?host={$hostname}&domain={$domain}&password={$dnspass}&ip={$this->_dnsIP}";
498 61c30081 jim-p
					curl_setopt($ch, CURLOPT_URL, $server);
499 8ea77433 Chris Wells
					break;
500
				case 'he-net':
501 d7e6f573 Daniel Becker
				case 'he-net-v6':
502 8ea77433 Chris Wells
					$needsIP = FALSE;
503 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
504
						log_error("HE.net ({$this->_dnsHost}): DNS update() starting.");
505 8ea77433 Chris Wells
					$server = "https://dyn.dns.he.net/nic/update?";
506
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
507 16fea0ce Cedric Ohle
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
508
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
509 8ea77433 Chris Wells
					break;
510 38a481ad jim-p
				case 'he-net-tunnelbroker':
511
					$needsIP = FALSE;
512 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
513
						log_error("HE.net Tunnelbroker: DNS update() starting.");
514 38a481ad jim-p
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
515
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
516
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
517
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
518
					break;
519 fb403496 Gerald Raaf
				case 'selfhost':
520
					$needsIP = FALSE;
521 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
522
						log_error("SelfHost: DNS update() starting.");
523 fb403496 Gerald Raaf
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
524
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
525
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
526
					$server = "https://carol.selfhost.de/nic/update";
527
					$port = "";
528
					if($this->_dnsServer)
529
						$server = $this->_dnsServer;
530
					if($this->_dnsPort)
531
						$port = ":" . $this->_dnsPort;
532
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
533
					break;
534 0c7bb880 Phil Davis
				case 'route53':
535 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
536
						log_error("Route53 ({$this->_dnsHost}): DNS update() starting.");
537 0c7bb880 Phil Davis
					
538
					/* Setting Variables */
539
					$hostname = "{$this->_dnsHost}.";
540
					$ZoneID = $this->_dnsZoneID;
541
					$AccessKeyId=$this->_dnsUser;
542
					$SecretAccessKey=$this->_dnsPass;
543
					$NewIP=$this->_dnsIP;
544
					$NewTTL=$this->_dnsTTL;
545 cd132e86 Edson Brandi
546 0c7bb880 Phil Davis
					/* Include Route 53 Library Class */
547
					require_once('/etc/inc/r53.class');
548 cd132e86 Edson Brandi
549 0c7bb880 Phil Davis
					/* Set Amazon AWS Credentials for this record */
550
					$r53 = new Route53($AccessKeyId, $SecretAccessKey);
551 cd132e86 Edson Brandi
552 0c7bb880 Phil Davis
					/* Function to find old values of records in Route 53 */
553
					if(!function_exists('Searchrecords')) {
554
						function SearchRecords($records, $name) {
555
							$result = array();
556
							foreach($records as $record) {
557
								if(strtolower($record['Name']) == strtolower($name)) {
558
									$result [] = $record;
559
								}
560
							}
561
							return ($result) ? $result : false;
562
						}
563
					}
564 cd132e86 Edson Brandi
565 0c7bb880 Phil Davis
					$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
566 cd132e86 Edson Brandi
567 0c7bb880 Phil Davis
					/* Get IP for your hostname in Route 53 */
568
					if(false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
569
						$OldTTL=$a_result[0][TTL];
570
						$OldIP=$a_result[0][ResourceRecords][0];
571
					} else {
572
						$OldIP="";
573
					}
574 cd132e86 Edson Brandi
575 0c7bb880 Phil Davis
					/* Check if we need to update DNS Record */
576
					if ($OldIP !== $NewIP) {
577
						if(!empty($OldIP)) {
578
							/* Your Hostname already exists, deleting and creating it again */
579
							$changes = array();
580
							$changes[] = $r53->prepareChange(DELETE, $hostname, A, $OldTTL, $OldIP);
581
							$changes[] = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
582
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
583
						} else {
584
							/* Your Hostname does not exist yet, creating it */
585
							$changes = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
586
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
587
						}
588
					}
589
					$this->_checkStatus(0, $result);
590
					break;
591 37f3e704 Matt Corallo
				case 'custom':
592 da40615d Daniel Becker
				case 'custom-v6':
593 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
594
						log_error("Custom DDNS ({$this->_dnsHost}): DNS update() starting.");
595 37f3e704 Matt Corallo
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
596
					if ($this->_dnsUser != '') {
597 aa79f351 Sebastian Chrostek
						if ($this->_curlIpresolveV4)
598
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
599
						if ($this->_curlSslVerifypeer)
600
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
601
						else
602
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
603 37f3e704 Matt Corallo
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
604
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
605
					}
606
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
607 87b91672 Phil Davis
					if ($this->_dnsVerboseLog)
608
						log_error("Sending request to: ".$server);
609 37f3e704 Matt Corallo
					curl_setopt($ch, CURLOPT_URL, $server);
610
					break;
611 e26e1f76 Andrew Senetar
				case 'cloudflare':
612
					$needsIP = TRUE;
613
					$dnsServer ='www.cloudflare.com';
614
					$dnsHost = str_replace(' ','', $this->_dnsHost);
615
					$URL = "https://{$dnsServer}/api.html?a=DIUP&email={$this->_dnsUser}&tkn={$this->_dnsPass}&ip={$this->dnsIP}&hosts={$dnsHost}";
616
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
617
					curl_setopt($ch, CURLOPT_URL, $URL);
618
					break;
619 ec66caa6 John Byron
				case 'eurodns':		
620
					$needsIP = TRUE;
621
					if ($this->_dnsVerboseLog)
622
						log_error("EuroDynDns ({$this->_dnsHost}) DNS update() starting.");
623
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
624
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
625
					$server = "https://eurodyndns.org/update/";
626
					$port = "";
627
					if($this->_dnsPort)
628
						$port = ":" . $this->_dnsPort;
629
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
630
					break;	
631 1fa2f630 Erik Kristensen
				default:
632
					break;
633
			}
634 cd132e86 Edson Brandi
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53') {
635 425ba708 Ermal
				$data = curl_exec($ch);
636
				$this->_checkStatus($ch, $data);
637
				@curl_close($ch);
638
			}
639 1fa2f630 Erik Kristensen
		}
640
641
		/*
642
		 * Private Function (added 12 July 2005) [beta]
643
		 *   Retrieve Update Status
644
		 */
645 dd28abbd Ermal
		function _checkStatus($ch, $data) {
646 87b91672 Phil Davis
			if ($this->_dnsVerboseLog) {
647
				log_error("DynDNS ({$this->_dnsHost}): DynDns _checkStatus() starting.");
648
				log_error("DynDNS ({$this->_dnsHost}): Current Service: {$this->_dnsService}");
649
			}
650 4a6bb2ff Scott Ullrich
			$successful_update = false;
651 cd132e86 Edson Brandi
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53' && @curl_error($ch)) {
652 425ba708 Ermal
				$status = "Curl error occurred: " . curl_error($ch);
653
				log_error($status);
654
				$this->status = $status;
655
				return;
656
			}
657 1fa2f630 Erik Kristensen
			switch ($this->_dnsService) {
658 52e6fdfd Scott Dale
				case 'dnsomatic':
659
					if (preg_match('/badauth/i', $data)) {
660 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): The DNS-O-Matic username or password specified are incorrect. No updates will be distributed to services until this is resolved.";
661 52e6fdfd Scott Dale
					} else if (preg_match('/notfqdn /i', $data)) {
662 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.";
663 52e6fdfd Scott Dale
					} else if (preg_match('/nohost/i', $data)) {
664 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname passed could not be matched to any services configured. The service field will be blank in the return code.";
665 52e6fdfd Scott Dale
					} else if (preg_match('/numhost/i', $data)) {
666 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): You may update up to 20 hosts. numhost is returned if you try to update more than 20 or update a round-robin.";	
667 52e6fdfd Scott Dale
					} else if (preg_match('/abuse/i', $data)) {
668 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname is blocked for update abuse.";
669 52e6fdfd Scott Dale
					} else if (preg_match('/good/i', $data)) {
670 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
671 52e6fdfd Scott Dale
						$successful_update = true;
672
					} else if (preg_match('/dnserr/i', $data)) {
673 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): DNS error encountered. Stop updating for 30 minutes.";
674 52e6fdfd Scott Dale
					} else {
675 2223aa95 smos
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Unknown Response)";
676
						log_error("DNS-O-Matic ({$this->_dnsHost}): PAYLOAD: {$data}");
677 52e6fdfd Scott Dale
						$this->_debug($data);
678
					}
679
					break;
680 1fa2f630 Erik Kristensen
				case 'dyndns':
681
					if (preg_match('/notfqdn/i', $data)) {
682 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
683 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
684 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
685 0ede1bf7 Scott Ullrich
						$successful_update = true;
686 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
687 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
688 4a6bb2ff Scott Ullrich
						$successful_update = true;
689 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
690 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
691 1fa2f630 Erik Kristensen
					} else {
692 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
693
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
694 1fa2f630 Erik Kristensen
						$this->_debug($data);
695
					}
696
					break;
697
				case 'dyndns-static':
698
					if (preg_match('/notfqdn/i', $data)) {
699 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
700 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
701 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
702 9b8dc821 Scott Ullrich
						$successful_update = true;
703 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
704 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
705 4a6bb2ff Scott Ullrich
						$successful_update = true;
706 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
707 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
708 1fa2f630 Erik Kristensen
					} else {
709 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
710
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
711 1fa2f630 Erik Kristensen
						$this->_debug($data);
712
					}
713
					break;
714
				case 'dyndns-custom':
715
					if (preg_match('/notfqdn/i', $data)) {
716 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
717 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
718
						$status = "phpDynDNS: (Success) No Change In IP Address";
719 9b8dc821 Scott Ullrich
						$successful_update = true;
720 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
721 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
722 4a6bb2ff Scott Ullrich
						$successful_update = true;
723 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
724 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
725 1fa2f630 Erik Kristensen
					} else {
726 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
727
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
728 1fa2f630 Erik Kristensen
						$this->_debug($data);
729
					}
730
					break;
731
				case 'dhs':
732
					break;
733
				case 'noip':
734 0333f968 Phil Davis
				case 'noip-free':
735 cfbfd941 smos
					list($ip,$code) = explode(":",$data);
736 1fa2f630 Erik Kristensen
					switch ($code) {
737
						case 0:
738 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP address is current, no update performed.";
739 4a6bb2ff Scott Ullrich
							$successful_update = true;
740 1fa2f630 Erik Kristensen
							break;
741
						case 1:
742 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS hostname update successful.";
743 4a6bb2ff Scott Ullrich
							$successful_update = true;
744 1fa2f630 Erik Kristensen
							break;
745
						case 2:
746 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not exist.";
747 1fa2f630 Erik Kristensen
							break;
748
						case 3:
749 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Username.";
750 1fa2f630 Erik Kristensen
							break;
751
						case 4:
752 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Password.";
753 1fa2f630 Erik Kristensen
							break;
754
						case 5:
755 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) To many updates sent.";
756 1fa2f630 Erik Kristensen
							break;
757
						case 6:
758 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account disabled due to violation of No-IP terms of service.";
759 1fa2f630 Erik Kristensen
							break;
760
						case 7:
761 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
762 1fa2f630 Erik Kristensen
							break;
763
						case 8:
764 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Disabled / Locked Hostname.";
765 1fa2f630 Erik Kristensen
							break;
766
						case 9:
767 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Host updated is configured as a web redirect and no update was performed.";
768 1fa2f630 Erik Kristensen
							break;
769
						case 10:
770 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Group supplied does not exist.";
771 1fa2f630 Erik Kristensen
							break;
772
						case 11:
773 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group update is successful.";
774 4a6bb2ff Scott Ullrich
							$successful_update = true;
775 1fa2f630 Erik Kristensen
							break;
776
						case 12:
777 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group is current, no update performed.";
778 4a6bb2ff Scott Ullrich
							$successful_update = true;
779 1fa2f630 Erik Kristensen
							break;
780
						case 13:
781 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update client support not available for supplied hostname or group.";
782 1fa2f630 Erik Kristensen
							break;
783
						case 14:
784 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not have offline settings configured.";
785 1fa2f630 Erik Kristensen
							break;
786
						case 99:
787 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
788 1fa2f630 Erik Kristensen
							break;
789
						case 100:
790 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
791 1fa2f630 Erik Kristensen
							break;
792
						default:
793 2223aa95 smos
							$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
794 458d80d7 Scott Ullrich
							$this->_debug("Unknown Response: ".$data);
795 1fa2f630 Erik Kristensen
							break;
796
					}
797
					break;
798
				case 'easydns':
799
					if (preg_match('/NOACCESS/i', $data)) {
800 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Authentication Failed: Username and/or Password was Incorrect.";
801 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOSERVICE/i', $data)) {
802 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
803 1fa2f630 Erik Kristensen
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
804 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Illegal Input: Self-Explanatory";
805 1fa2f630 Erik Kristensen
					} else if (preg_match('/TOOSOON/i', $data)) {
806 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
807 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOERROR/i', $data)) {
808 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Updated Successfully!";
809 4a6bb2ff Scott Ullrich
						$successful_update = true;
810 1fa2f630 Erik Kristensen
					} else {
811 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
812
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
813 1fa2f630 Erik Kristensen
						$this->_debug($data);
814
					}
815
					break;
816
				case 'hn':
817 9b8dc821 Scott Ullrich
					/* FIXME: add checks */
818 1fa2f630 Erik Kristensen
					break;
819
				case 'zoneedit':
820 9b9e5f09 Scott Ullrich
					if (preg_match('/799/i', $data)) {
821 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 799) Update Failed!";				
822 332a3e59 Scott Ullrich
					} else if (preg_match('/700/i', $data)) {
823 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 700) Update Failed!";
824 9b9e5f09 Scott Ullrich
					} else if (preg_match('/200/i', $data)) {
825 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
826 4a6bb2ff Scott Ullrich
						$successful_update = true;
827 9b9e5f09 Scott Ullrich
					} else if (preg_match('/201/i', $data)) {
828 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
829 9b9e5f09 Scott Ullrich
						$successful_update = true;						
830 1fa2f630 Erik Kristensen
					} else {
831 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
832
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
833 1fa2f630 Erik Kristensen
						$this->_debug($data);
834
					}
835
					break;
836
				case 'dyns':
837
					if (preg_match("/400/i", $data)) {
838 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
839 1fa2f630 Erik Kristensen
					} else if (preg_match('/402/i', $data)) {
840 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update Too Soon - You have tried updating to quickly since last change.";
841 1fa2f630 Erik Kristensen
					} else if (preg_match('/403/i', $data)) {
842 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Database Error - There was a server-sided database error.";
843 1fa2f630 Erik Kristensen
					} else if (preg_match('/405/i', $data)) {
844 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
845 1fa2f630 Erik Kristensen
					} else if (preg_match('/200/i', $data)) {
846 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
847 4a6bb2ff Scott Ullrich
						$successful_update = true;
848 1fa2f630 Erik Kristensen
					} else {
849 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
850
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
851 1fa2f630 Erik Kristensen
						$this->_debug($data);
852
					}
853
					break;
854
				case 'ods':
855
					if (preg_match("/299/i", $data)) {
856 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
857 4a6bb2ff Scott Ullrich
						$successful_update = true;
858 1fa2f630 Erik Kristensen
					} else {
859 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
860
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
861 1fa2f630 Erik Kristensen
						$this->_debug($data);
862
					}
863
					break;
864 9b8dc821 Scott Ullrich
				case 'freedns':
865
					if (preg_match("/has not changed./i", $data)) {
866 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
867 9b8dc821 Scott Ullrich
						$successful_update = true;
868
					} else if (preg_match("/Updated/i", $data)) {
869 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
870 9b8dc821 Scott Ullrich
						$successful_update = true;
871
					} else {
872 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
873
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
874 9b8dc821 Scott Ullrich
						$this->_debug($data);
875
					} 
876
					break;
877 0a1b0183 Ermal Luçi
				case 'dnsexit':
878
					if (preg_match("/is the same/i", $data)) {
879 2223aa95 smos
						$status = "phpDynDns ({$this->_dnsHost}): (Success) No Change In IP Address";
880 0a1b0183 Ermal Luçi
						$successful_update = true;
881
					} else if (preg_match("/Success/i", $data)) {
882 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
883 0a1b0183 Ermal Luçi
						$successful_update = true;
884
					} else {
885 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
886 87b91672 Phil Davis
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
887
						$this->_debug($data);
888 0a1b0183 Ermal Luçi
					}
889
					break;
890 9b8dc821 Scott Ullrich
				case 'loopia':
891
					if (preg_match("/nochg/i", $data)) {
892 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
893 9b8dc821 Scott Ullrich
						$successful_update = true;
894
					} else if (preg_match("/good/i", $data)) {
895 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
896 9b8dc821 Scott Ullrich
						$successful_update = true;
897
					} else if (preg_match('/badauth/i', $data)) {
898 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
899 9b8dc821 Scott Ullrich
					} else {
900 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
901
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
902 9b8dc821 Scott Ullrich
						$this->_debug($data);
903
					}
904
					break;
905 2d78b166 Ermal Luçi
				case 'opendns':
906
					if (preg_match('/badauth/i', $data)) {
907 2223aa95 smos
						$status = "phpDynDNS({$this->_dnsHost}): (Error) Not a valid username or password!";
908 2d78b166 Ermal Luçi
					} else if (preg_match('/nohost/i', $data)) {
909 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname you are trying to update does not exist.";
910 2d78b166 Ermal Luçi
						$successful_update = true;
911
					} else if (preg_match('/good/i', $data)) {
912 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
913 2d78b166 Ermal Luçi
						$successful_update = true;
914
					} else if (preg_match('/yours/i', $data)) {
915 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) hostname specified exists, but not under the username specified.";
916 2d78b166 Ermal Luçi
					} else if (preg_match('/abuse/i', $data)) {
917 2223aa95 smos
						$status = "phpDynDns ({$this->_dnsHost}): (Error) Updating too frequently, considered abuse.";
918 2d78b166 Ermal Luçi
					} else {
919 2223aa95 smos
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
920
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
921 2d78b166 Ermal Luçi
						$this->_debug($data);
922
					}
923
					break;
924 37f3e704 Matt Corallo
				case 'staticcling':
925 d74b5b8b sullrich
					if (preg_match("/invalid ip/i", $data)) {
926 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The IP provided was invalid.";
927 d74b5b8b sullrich
					} else if (preg_match('/required info missing/i', $data)) {
928 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Required parameters were not provided.";
929 d74b5b8b sullrich
					} else if (preg_match('/invalid characters/i', $data)) {
930 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Illegal characters in either the username or the password.";
931 d74b5b8b sullrich
					} else if (preg_match('/bad password/i', $data)) {
932 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid password.";
933 d74b5b8b sullrich
					} else if (preg_match('/account locked/i', $data)) {
934 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) This account has been administratively locked.";
935 d74b5b8b sullrich
					} else if (preg_match('/update too frequent/i', $data)) {
936 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Updating too frequently.";
937 d74b5b8b sullrich
					} else if (preg_match('/DB error/i', $data)) {
938 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Server side error.";
939 d74b5b8b sullrich
					} else if (preg_match('/success/i', $data)) {
940 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
941
						$successful_update = true;
942 d74b5b8b sullrich
					} else {
943 0c7bb880 Phil Davis
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
944
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
945
						$this->_debug($data);
946 d74b5b8b sullrich
					}
947
					break;
948 61c30081 jim-p
				case 'namecheap':
949 18f15f68 jim-p
					$tmp = str_replace("^M", "", $data);
950
					$ncresponse = @xml2array($tmp);
951 61c30081 jim-p
					if (preg_match("/internal server error/i", $data)) {
952
						$status = "phpDynDNS: (Error) Server side error.";
953 3dc3b15b jim-p
					} else if (preg_match("/request is badly formed/i", $data)) {
954
						$status = "phpDynDNS: (Error) Badly Formed Request (check your settings).";
955 18f15f68 jim-p
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
956 c305abd5 jim-p
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
957
						$successful_update = true;
958 18f15f68 jim-p
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
959
						$status = "phpDynDNS: (Error) " . implode(", ", $ncresponse["interface-response"]["errors"]);
960 c305abd5 jim-p
						$successful_update = true;
961 61c30081 jim-p
					} else {
962
						$status = "phpDynDNS: (Unknown Response)";
963
						log_error("phpDynDNS: PAYLOAD: {$data}");
964
						$this->_debug($data);
965
					}
966
					break;
967 8ea77433 Chris Wells
					
968
				case 'he-net':
969 b4025ccd Daniel Becker
				case 'he-net-v6':
970 8ea77433 Chris Wells
					if (preg_match("/badip/i", $data)) {
971 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
972 8ea77433 Chris Wells
					} else if (preg_match('/nohost/i', $data)) {
973 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Bad Request - A hostname was not provided.";
974 8ea77433 Chris Wells
					} else if (preg_match('/badauth/i', $data)) {
975 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Invalid username or password.";
976 8ea77433 Chris Wells
					} else if (preg_match('/good/i', $data)) {
977 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
978
						$successful_update = true;
979 8ea77433 Chris Wells
					} else if (preg_match('/nochg/i', $data)) {
980 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Success) No Change In IP Address.";
981
						$successful_update = true;
982 8ea77433 Chris Wells
					} else {
983 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Unknown Response)";
984
						log_error("phpDynDNS: PAYLOAD: {$data}");
985
						$this->_debug($data);
986 8ea77433 Chris Wells
					}
987
					break;
988 38a481ad jim-p
				case 'he-net-tunnelbroker':
989
					/*
990
					-ERROR: Missing parameter(s).
991
					-ERROR: Invalid API key or password
992
					-ERROR: Tunnel not found
993
					-ERROR: Another tunnel exists for this IP.
994
					-ERROR: This tunnel is already associated with this IP address
995
					+OK: Tunnel endpoint updated to: x.x.x.x
996
					*/
997
					if (preg_match("/Missing parameter/i", $data)) {
998 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Bad Request - Missing/Invalid Parameters.";
999 38a481ad jim-p
					} else if (preg_match('/Tunnel not found/i', $data)) {
1000 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Bad Request - Invalid Tunnel ID.";
1001 38a481ad jim-p
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1002 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Invalid username or password.";
1003 38a481ad jim-p
					} else if (preg_match('/OK:/i', $data)) {
1004 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1005
						$successful_update = true;
1006 38a481ad jim-p
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1007 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Success) No Change In IP Address.";
1008
						$successful_update = true;
1009 38a481ad jim-p
					} else {
1010 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Unknown Response)";
1011
						log_error("phpDynDNS: PAYLOAD: {$data}");
1012
						$this->_debug($data);
1013 38a481ad jim-p
					}
1014
					break;
1015 fb403496 Gerald Raaf
				case 'selfhost':
1016
					if (preg_match('/notfqdn/i', $data)) {
1017
						$status = "phpDynDNS: (Error) Not A FQDN!";
1018
					} else if (preg_match('/nochg/i', $data)) {
1019
						$status = "phpDynDNS: (Success) No Change In IP Address";
1020
						$successful_update = true;
1021
					} else if (preg_match('/good/i', $data)) {
1022
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
1023
						$successful_update = true;
1024
					} else if (preg_match('/noauth/i', $data)) {
1025
						$status = "phpDynDNS: (Error) User Authorization Failed";
1026
					} else {
1027
						$status = "phpDynDNS: (Unknown Response)";
1028
						log_error("phpDynDNS: PAYLOAD: {$data}");
1029
						$this->_debug($data);
1030
					}
1031
					break;
1032 0c7bb880 Phil Davis
				case 'route53':
1033
					$successful_update = true;
1034
					break;
1035 37f3e704 Matt Corallo
				case 'custom':
1036 da40615d Daniel Becker
				case 'custom-v6':
1037 37f3e704 Matt Corallo
					$successful_update = false;
1038
					if ($this->_dnsResultMatch == "") {
1039
						$successful_update = true;
1040
					}else {
1041
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1042
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1043
						foreach($matches as $match) {
1044
							$match= str_replace("\\|", "|", $match);
1045
							if(strcmp($match, trim($data, "\t\n\r")) == 0)
1046
								$successful_update = true;
1047
						}
1048
						unset ($matches);
1049
					}
1050
					if ($successful_update == true)
1051 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1052 37f3e704 Matt Corallo
					else
1053 0c7bb880 Phil Davis
						$status = "phpDynDNS: (Error) Result did not match.";
1054 37f3e704 Matt Corallo
					break;
1055 e26e1f76 Andrew Senetar
				case 'cloudflare':
1056
					// recieve multipe results
1057
					$data = explode("\n",$data);
1058
					$lines = count($data)-1;
1059
1060
					// loop over the lines
1061
					for ($pos=0; ($successful_update || $pos == 0) && $pos < $lines; $pos++){
1062
						$resp = $data[$pos];
1063
						if (preg_match('/UAUTH/i', $resp)) {
1064
							$status = "DynDNS: The username specified is not authorized to update this hostname and domain.";
1065
						} else if (preg_match('/NOHOST/i', $resp)) {
1066
							$status = "DynDNS: No valid FQDN (fully qualified domain name) was specified";
1067
						} else if (preg_match('/INVLDHST/i', $resp)) {
1068
							$status = "DynDNS: An invalid hostname was specified. This may be due to the fact the hostname has not been created in the system. Creating new host names via clients is not supported.";
1069
						} else if (preg_match('/INVLDIP/i', $resp)) {
1070 3793649f Andrew Senetar
							$status = "DynDNS: The IP address given is not valid.";
1071
						} else if (preg_match('/DUPHST/i', $resp)) {
1072
							$status = "DynDNS: Duplicate values exist for a record. Only single values for records are supported currently.";
1073
						} else if (preg_match('/NOUPDATE/i', $resp)) {
1074
							$status = "DynDNS: No changes made to the hostname (".strtok($resp,' ')."). Continual updates with no changes lead to blocked clients.";
1075
							$successful_update = true; //success if it is the same so that it saves
1076
						} else if (preg_match('/OK/i', $resp)) {
1077 6bc58a97 Andrew Senetar
							$status = "DynDNS: (Success) (".strtok($resp,' ').") IP Address for Changed Successfully!";
1078 3793649f Andrew Senetar
							$successful_update = true;
1079
						} else {
1080
							$status = "DynDNS: (Unknown Response)";
1081
							log_error("DynDNS: PAYLOAD: {$resp}");
1082
							$this->_debug($resp);
1083
						}
1084
						log_error($status);
1085 ffa1acdc Andrew Senetar
					}
1086
					break;
1087 ec66caa6 John Byron
				case 'eurodns':
1088
					if (preg_match('/notfqdn/i', $data)) {
1089
						$status = "phpDynDNS: (Error) Not A FQDN!";
1090
					} else if (preg_match('/nochg/i', $data)) {
1091
						$status = "phpDynDNS: (Success) No Change In IP Address";
1092
						$successful_update = true;
1093
					} else if (preg_match('/good/i', $data)) {
1094
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
1095
						$successful_update = true;
1096
					} else if (preg_match('/badauth/i', $data)) {
1097
						$status = "phpDynDNS: (Error) User Authorization Failed";
1098
					} else {
1099
						$status = "phpDynDNS: (Unknown Response)";
1100
						log_error("phpDynDNS: PAYLOAD: {$data}");
1101
						$this->_debug($data);
1102
					}
1103
					break;
1104 1fa2f630 Erik Kristensen
			}
1105 4a6bb2ff Scott Ullrich
			
1106
			if($successful_update == true) {
1107
				/* Write WAN IP to cache file */
1108 22de7804 Bill Marquette
				$wan_ip = $this->_checkIP();
1109 dd575ea4 Ermal
				conf_mount_rw();
1110 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1111 53842a6c jim-p
					$currentTime = time();
1112
					notify_all_remote(sprintf(gettext("DynDNS updated IP Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1113 c749ef62 Ermal
					log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
1114 dd575ea4 Ermal
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1115
				} else
1116
					@unlink($this->_cacheFile);
1117 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1118 b4025ccd Daniel Becker
					$currentTime = time();
1119 d7e6f573 Daniel Becker
					notify_all_remote(sprintf(gettext("DynDNS updated IPv6 Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1120
					log_error("phpDynDNS: updating cache file {$this->_cacheFile_v6}: {$wan_ip}");
1121 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1122 b4025ccd Daniel Becker
				} else
1123 d7e6f573 Daniel Becker
					@unlink($this->_cacheFile_v6);
1124 dd575ea4 Ermal
				conf_mount_ro();
1125 4a6bb2ff Scott Ullrich
			}
1126 1fa2f630 Erik Kristensen
			$this->status = $status;
1127
			log_error($status);
1128
		}
1129
1130
		/*
1131
		 * Private Function (added 12 July 05) [beta]
1132
		 *   Return Error, Set Last Error, and Die.
1133
		 */
1134
		function _error($errorNumber = '1') {
1135
			switch ($errorNumber) {
1136
				case 0:
1137
					break;
1138
				case 2:
1139
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
1140
					break;
1141
				case 3:
1142
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
1143
					break;
1144
				case 4:
1145
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
1146
					break;
1147
				case 5:
1148
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
1149
					break;
1150
				case 6:
1151
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
1152
					break;
1153 9b8dc821 Scott Ullrich
				case 7:
1154
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
1155
					break;
1156 0c7bb880 Phil Davis
				case 8:
1157
					$status = "Route 53: (Error) Invalid ZoneID";
1158 cd132e86 Edson Brandi
					break;
1159 0c7bb880 Phil Davis
				case 9:
1160
					$status = "Route 53: (Error) Invalid TTL";
1161
					break;  
1162 1fa2f630 Erik Kristensen
				case 10:
1163 87b91672 Phil Davis
					$error = "phpDynDNS ({$this->_dnsHost}): No change in my IP address and/or " . $this->_dnsMaxCacheAgeDays . " days has not passed. Not updating dynamic DNS entry.";
1164 1fa2f630 Erik Kristensen
					break;
1165
				default:
1166
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
1167 9b8dc821 Scott Ullrich
					/* FIXME: $data isn't in scope here */
1168
					/* $this->_debug($data); */
1169 1fa2f630 Erik Kristensen
					break;
1170
			}
1171
			$this->lastError = $error;
1172
			log_error($error);
1173
		}
1174
1175
		/*
1176
		 * Private Function (added 12 July 05) [beta]
1177
		 *   - Detect whether or not IP needs to be updated.
1178
		 *      | Written Specifically for pfSense (pfsense.com) may
1179
		 *      | work with other systems. pfSense base is FreeBSD.
1180
		 */
1181
		function _detectChange() {
1182 dceff62e Ermal
			global $debug;
1183
1184
			if ($debug)
1185 2223aa95 smos
				log_error("DynDns ({$this->_dnsHost}): _detectChange() starting.");
1186 1331005d Scott Ullrich
		
1187 1fa2f630 Erik Kristensen
			$currentTime = time();
1188
1189 22de7804 Bill Marquette
			$wan_ip = $this->_checkIP();
1190 dd575ea4 Ermal
			if ($wan_ip == 0) {
1191 2223aa95 smos
				log_error("DynDns ({$this->_dnsHost}): Current WAN IP could not be determined, skipping update process.");
1192 193ee786 Ermal
				return false;
1193 dd575ea4 Ermal
			}
1194 2223aa95 smos
			$log_error = "DynDns ({$this->_dnsHost}): Current WAN IP: {$wan_ip} ";
1195 1fa2f630 Erik Kristensen
1196 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
1197
				if (file_exists($this->_cacheFile_v6)) {
1198
					$contents = file_get_contents($this->_cacheFile_v6);
1199 b4319c50 Daniel Becker
					list($cacheIP,$cacheTime) = explode('|', $contents);
1200 d7e6f573 Daniel Becker
					$this->_debug($cacheIP.'/'.$cacheTime);
1201
					$initial = false;
1202
					$log_error .= "Cached IPv6: {$cacheIP} ";
1203
				} else {
1204
					conf_mount_rw();
1205
					$cacheIP = '::';
1206 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1207 d7e6f573 Daniel Becker
					conf_mount_ro();
1208
					$cacheTime = $currentTime;
1209
					$initial = true;
1210
					$log_error .= "No Cached IPv6 found.";
1211
				}
1212 1fa2f630 Erik Kristensen
			} else {
1213 d7e6f573 Daniel Becker
				if (file_exists($this->_cacheFile)) {
1214
					$contents = file_get_contents($this->_cacheFile);
1215
					list($cacheIP,$cacheTime) = explode(':', $contents);
1216
					$this->_debug($cacheIP.'/'.$cacheTime);
1217
					$initial = false;
1218
					$log_error .= "Cached IP: {$cacheIP} ";
1219
				} else {
1220
					conf_mount_rw();
1221
					$cacheIP = '0.0.0.0';
1222
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1223
					conf_mount_ro();
1224
					$cacheTime = $currentTime;
1225
					$initial = true;
1226
					$log_error .= "No Cached IP found.";
1227
				}
1228 1fa2f630 Erik Kristensen
			}
1229 87b91672 Phil Davis
			if ($this->_dnsVerboseLog)
1230
				log_error($log_error);
1231 1fa2f630 Erik Kristensen
1232 f5e293e6 Phil Davis
			// Convert seconds = days * hr/day * min/hr * sec/min
1233
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1234 1fa2f630 Erik Kristensen
1235 e24b26e9 Scott Ullrich
			$needs_updating = FALSE;
1236 4494cf6a Chris Buechler
			/* lets determine if the item needs updating */
1237 a255e1f7 Scott Ullrich
			if ($cacheIP != $wan_ip) {
1238 eb346556 Ermal Lu?i
				$needs_updating = true;
1239
				$update_reason = "DynDns: cacheIP != wan_ip.  Updating. ";
1240
				$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
1241 a255e1f7 Scott Ullrich
			}
1242 f5e293e6 Phil Davis
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1243 c3c3e03b Ermal
				$needs_updating = true;
1244 0333f968 Phil Davis
				$this->_forceUpdateNeeded = true;
1245 f5e293e6 Phil Davis
				$update_reason = "DynDns: More than " . $this->_dnsMaxCacheAgeDays . " days.  Updating. ";
1246
				$update_reason .= "{$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1247 a255e1f7 Scott Ullrich
			}
1248 eb346556 Ermal Lu?i
			if ($initial == true) {
1249
				$needs_updating = true;
1250 1bf52c67 Phil Davis
				$update_reason .= "Initial update. ";
1251 a255e1f7 Scott Ullrich
			}
1252 eb346556 Ermal Lu?i
1253 a255e1f7 Scott Ullrich
			/*   finally if we need updating then store the
1254
			 *   new cache value and return true
1255 0c7bb880 Phil Davis
			 */
1256 eb346556 Ermal Lu?i
			if ($needs_updating == true) {
1257 87b91672 Phil Davis
				if ($this->_dnsVerboseLog)
1258
					log_error("DynDns ({$this->_dnsHost}): {$update_reason}");
1259 eb346556 Ermal Lu?i
				return true;
1260 1fa2f630 Erik Kristensen
			}
1261 eb346556 Ermal Lu?i
1262
			return false;			
1263 1fa2f630 Erik Kristensen
		}
1264
1265
		/*
1266 0c7bb880 Phil Davis
		 * Private Function (added 16 July 05) [beta]
1267 1fa2f630 Erik Kristensen
		 *   - Writes debug information to a file.
1268
		 *   - This function is only called when a unknown response
1269
		 *   - status is returned from a DynDNS service provider.
1270
		 */
1271 6a45171d Ermal
		function _debug($data) {
1272
			global $g;
1273
1274
			if (!$g['debug'])
1275
				return;
1276 bb9ccd63 bcyrill
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1277 53d366fd Scott Ullrich
			conf_mount_rw();
1278 1fa2f630 Erik Kristensen
			$file = fopen($this->_debugFile, 'a');
1279
			fwrite($file, $string);
1280
			fclose($file);
1281 53d366fd Scott Ullrich
			conf_mount_ro();
1282 1fa2f630 Erik Kristensen
		}
1283 22de7804 Bill Marquette
		function _checkIP() {
1284 dceff62e Ermal
			global $debug;
1285 22de7804 Bill Marquette
1286 dceff62e Ermal
			if ($debug)
1287 2223aa95 smos
				log_error("DynDns ({$this->_dnsHost}): _checkIP() starting.");
1288 22de7804 Bill Marquette
1289 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
1290
				$ip_address = find_interface_ipv6($this->_if);
1291
				if (!is_ipaddrv6($ip_address))
1292
					return 0;
1293
			} else {
1294
				$ip_address = find_interface_ip($this->_if);
1295
				if (!is_ipaddr($ip_address))
1296
					return 0;
1297
			}
1298
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1299 1b665090 Ermal Lu?i
				$hosttocheck = "checkip.dyndns.org";
1300 83ae8103 Ermal
				$try = 0;
1301
				while ($try < 3) {
1302
					$checkip = gethostbyname($hosttocheck);
1303
					if (is_ipaddr($checkip))
1304
						break;
1305
					$try++;
1306
				}
1307
				if ($try >= 3) {
1308 2223aa95 smos
					log_error("Dyndns debug information ({$this->_dnsHost}): Could not resolve {$hosttocheck} to ip using interface ip {$ip_address}.");
1309 dd575ea4 Ermal
					return 0;
1310 83ae8103 Ermal
				}
1311 7ae7a972 Ermal Lu?i
				$ip_ch = curl_init("http://{$checkip}");
1312
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1313
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1314 8f1b45aa Ermal Lu?i
				curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
1315 83ae8103 Ermal
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1316 93b8df2a Ermal
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1317 7ae7a972 Ermal Lu?i
				$ip_result_page = curl_exec($ip_ch);
1318
				curl_close($ip_ch);
1319
				$ip_result_decoded = urldecode($ip_result_page);
1320 c3c3e03b Ermal
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1321 7ae7a972 Ermal Lu?i
				$ip_address = trim($matches[1]);
1322 87b91672 Phil Davis
				if (is_ipaddr($ip_address)) {
1323
					if ($this->_dnsVerboseLog)
1324
						log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from {$hosttocheck}");
1325
				} else {
1326
					log_error("DynDns ({$this->_dnsHost}): IP address could not be extracted from {$hosttocheck}");
1327 c749ef62 Ermal
					return 0;
1328
				}
1329 87b91672 Phil Davis
			} else {
1330
				if ($this->_dnsVerboseLog)
1331
					log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from local system.");
1332
			}
1333 fffbfef0 Matt Corallo
			$this->_dnsIP = $ip_address;
1334
1335 22de7804 Bill Marquette
			return $ip_address;
1336
		}
1337 1fa2f630 Erik Kristensen
1338
	}
1339
1340 aa7c49b9 Ermal
?>