Project

General

Profile

Download (57.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
	/*
3
	 * PHP.updateDNS (pfSense version)
4
	 *
5
	 * +====================================================+
6
	 *  Services Supported:
7
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
8
	 *    - No-IP (no-ip.com)
9
	 *    - EasyDNS (easydns.com)
10
	 *    - DHS (www.dhs.org)
11
	 *    - HN (hn.org) -- incomplete checking!
12
	 *    - DynS (dyns.org)
13
	 *    - ZoneEdit (zoneedit.com)
14
	 *    - FreeDNS (freedns.afraid.org)
15
	 *    - Loopia (loopia.se)
16
	 *    - StaticCling (staticcling.org)
17
	 *    - DNSexit (dnsexit.com)
18
	 *    - OpenDNS (opendns.com)
19
	 *    - Namecheap (namecheap.com)
20
	 *    - HE.net (dns.he.net)
21
	 *    - HE.net IPv6 (dns.he.net)
22
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
23
	 *    - SelfHost (selfhost.de)
24
	 *    - Amazon Route 53 (aws.amazon.com)
25
	 *    - DNS-O-Matic (dnsomatic.com)
26
	 *    - Custom DDNS (any URL)
27
	 *    - Custom DDNS IPv6 (any URL)
28
	 *    - CloudFlare (www.cloudflare.com)
29
 	 *    - Eurodns (eurodns.com)
30
 	 *    - GratisDNS (gratisdns.dk)
31
	 *    - City Network (citynetwork.se)
32
	 * +----------------------------------------------------+
33
	 *  Requirements:
34
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
35
	 * +----------------------------------------------------+
36
	 *  Public Functions
37
	 *    - updatedns()
38
	 *
39
	 *  Private Functions
40
	 *    - _update()
41
	 *    - _checkStatus()
42
	 *    - _error()
43
	 *    - _detectChange()
44
	 *    - _debug()
45
	 *    - _checkIP()
46
	 * +----------------------------------------------------+
47
	 *  DynDNS Dynamic - Last Tested: 12 July 2005
48
	 *  DynDNS Static  - Last Tested: NEVER
49
	 *  DynDNS Custom  - Last Tested: NEVER
50
	 *  No-IP          - Last Tested: 20 July 2008
51
	 *  HN.org         - Last Tested: 12 July 2005
52
	 *  EasyDNS        - Last Tested: 20 July 2008
53
	 *  DHS            - Last Tested: 12 July 2005
54
	 *  ZoneEdit       - Last Tested: NEVER
55
	 *  Dyns           - Last Tested: NEVER
56
	 *  ODS            - Last Tested: 02 August 2005
57
	 *  FreeDNS        - Last Tested: 23 Feb 2011
58
	 *  Loopia         - Last Tested: NEVER
59
	 *  StaticCling    - Last Tested: 27 April 2006
60
	 *  DNSexit	   - Last Tested: 20 July 2008
61
	 *  OpenDNS	   - Last Tested: 4 August 2008
62
	 *  Namecheap	   - Last Tested: 31 August 2010
63
	 *  HE.net         - Last Tested: 7 July 2013
64
	 *  HE.net IPv6    - Last Tested: 7 July 2013
65
	 *  HE.net Tunnel  - Last Tested: 28 June 2011
66
	 *  SelfHost       - Last Tested: 26 December 2011
67
	 *  Amazon Route 53 - Last tested: 01 April 2012
68
	 *  DNS-O-Matic	   - Last Tested: 9 September 2010
69
	 *  CloudFlare     - Last Tested: 30 May 2013
70
  	 *  Eurodns	   - Last Tested: 27 June 2013
71
  	 *  GratisDNS      - Last Tested: 15 August 2012
72
	 *  OVH DynHOST	   - Last Tested: NEVER
73
	 *  City Network   - Last Tested: 13 November 2013
74
	 * +====================================================+
75
	 *
76
	 * @author 	E.Kristensen
77
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
78
	 * @version 	0.8
79
	 * @updated	13 October 05 at 21:02:42 GMT
80
	 *
81
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luci
82
	 * Custom DNS support by Matt Corallo
83
	 *
84
	 */
85

    
86
	class updatedns {
87
		var $_cacheFile;
88
		var $_cacheFile_v6;
89
		var $_debugFile;
90
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
91
		var $_errorVerbosity = 0;
92
		var $_dnsService;
93
		var $_dnsUser;
94
		var $_dnsPass;
95
		var $_dnsHost;
96
		var $_dnsIP;
97
		var $_dnsWildcard;
98
		var $_dnsMX;
99
		var $_dnsBackMX;
100
		var $_dnsServer;
101
		var $_dnsPort;
102
		var $_dnsUpdateURL;
103
		var $_dnsZoneID;
104
		var $_dnsTTL;
105
		var $status;
106
		var $_debugID;
107
		var $_if;
108
		var $_dnsResultMatch;
109
		var $_dnsRequestIf;
110
		var $_dnsRequestIfIP;
111
		var $_dnsVerboseLog;
112
		var $_curlIpresolveV4;
113
		var $_curlSslVerifypeer;
114
		var $_dnsMaxCacheAgeDays;
115
		var $_dnsDummyUpdateDone;
116
		var $_forceUpdateNeeded;
117
		var $_useIPv6;
118
		
119
		/* 
120
		 * Public Constructor Function (added 12 July 05) [beta]
121
		 *   - Gets the dice rolling for the update. 
122
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
123
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to, 
124
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
125
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
126
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
127
		 */
128
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
129
				    $dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
130
				    $dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
131
				    $dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
132
				    $dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
133
			
134
			global $config, $g;
135
			
136
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache";
137
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache";
138
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.debug";
139

    
140
			$this->_curlIpresolveV4 = $curlIpresolveV4;
141
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
142
			$this->_dnsVerboseLog = $dnsVerboseLog;
143
			if ($this->_dnsVerboseLog)
144
				log_error("DynDns: updatedns() starting");
145

    
146
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
147

    
148
			if (!$dnsService) $this->_error(2);
149
			switch ($dnsService) {
150
			case 'freedns':
151
				if (!$dnsHost) $this->_error(5);
152
				break;
153
			case 'namecheap':
154
				if (!$dnsPass) $this->_error(4);
155
				if (!$dnsHost) $this->_error(5);
156
				break;
157
			case 'route53':
158
				if (!$dnsZoneID) $this->_error(8);
159
				if (!$dnsTTL) $this->_error(9);
160
				break;
161
			case 'custom':
162
				if (!$dnsUpdateURL) $this->_error(7);
163
				break;
164
			default:
165
				if (!$dnsUser) $this->_error(3);
166
				if (!$dnsPass) $this->_error(4);
167
				if (!$dnsHost) $this->_error(5);
168
			}
169
			
170
			switch ($dnsService) {
171
			case 'he-net-v6':
172
			case 'custom-v6':
173
				$this->_useIPv6 = true;
174
				break;
175
			default:
176
				$this->_useIPv6 = false;
177
			}
178
			$this->_dnsService = strtolower($dnsService);
179
			$this->_dnsUser = $dnsUser;
180
			$this->_dnsPass = $dnsPass;
181
			$this->_dnsHost = $dnsHost;
182
			$this->_dnsServer = $dnsServer;
183
			$this->_dnsPort = $dnsPort;
184
			$this->_dnsWildcard = $dnsWildcard;
185
			$this->_dnsMX = $dnsMX;
186
			$this->_dnsZoneID = $dnsZoneID;
187
			$this->_dnsTTL = $dnsTTL;
188
			$this->_if = get_failover_interface($dnsIf);
189
			$this->_checkIP();
190
			$this->_dnsUpdateURL = $dnsUpdateURL;
191
			$this->_dnsResultMatch = $dnsResultMatch;
192
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
193
			if ($this->_dnsVerboseLog)
194
				log_error("DynDNS ({$this->_dnsHost}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}");
195
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
196
			$this->_dnsMaxCacheAgeDays = 25;
197
			$this->_dnsDummyUpdateDone = false;
198
			$this->_forceUpdateNeeded = $forceUpdate;
199
			
200
			// Ensure that we were able to lookup the IP
201
			if(!is_ipaddr($this->_dnsIP)) {
202
				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.");
203
				unlock($dyndnslck);
204
				return;
205
			}
206

    
207
			$this->_debugID = rand(1000000, 9999999);
208
			
209
			if ($forceUpdate == false && $this->_detectChange() == false) {
210
				$this->_error(10);
211
			} else {
212
				switch ($this->_dnsService) {
213
				case 'dnsomatic':
214
				case 'dyndns':
215
				case 'dyndns-static':
216
				case 'dyndns-custom':
217
				case 'dhs':
218
				case 'noip':
219
				case 'noip-free':
220
				case 'easydns':
221
				case 'hn':
222
				case 'zoneedit':
223
				case 'dyns':
224
				case 'ods':
225
				case 'freedns':
226
				case 'loopia':
227
				case 'staticcling':
228
				case 'dnsexit':
229
				case 'custom':
230
				case 'custom-v6':
231
				case 'opendns':
232
				case 'namecheap':
233
				case 'he-net':
234
				case 'he-net-v6':
235
				case 'selfhost':
236
				case 'he-net-tunnelbroker':
237
				case 'route53':
238
				case 'cloudflare':
239
				case 'eurodns':
240
				case 'gratisdns':
241
				case 'ovh-dynhost':
242
				case 'citynetwork':
243
					$this->_update();
244
					if($this->_dnsDummyUpdateDone == true) {
245
						// If a dummy update was needed, then sleep a while and do the update again to put the proper address back.
246
						// Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month.
247
						// If the address has not changed recently, or the user did "Force Update", then the code does
248
						// a dummy address change for providers like this.
249
						sleep(10);
250
						$this->_update();
251
					}
252
					break;
253
				default:
254
					$this->_error(6);
255
					break;
256
				}
257
			}
258

    
259
			unlock($dyndnslck);
260
		}
261
			
262
		/*
263
		 * Private Function (added 12 July 05) [beta]
264
		 *   Send Update To Selected Service.
265
		 */
266
		function _update() {
267
		
268
			if ($this->_dnsVerboseLog)
269
				log_error("DynDNS ({$this->_dnsHost}): DynDns _update() starting.");
270
			
271
			if (strstr($this->_dnsRequestIf, "_vip")) {
272
				$parentif = link_carp_interface_to_parent($this->_dnsRequestIf);
273
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
274
			} else {
275
				$realparentif = $this->_dnsRequestIf;
276
			}
277

    
278
			$ch = curl_init();
279

    
280
			if ($this->_useIPv6 == false) {
281
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
282
			}
283
			
284
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
285
				curl_setopt($ch, CURLOPT_HEADER, 0);
286
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
287
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
288
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
289
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
290
			}
291

    
292
			switch ($this->_dnsService) {
293
				case 'dyndns':
294
				case 'dyndns-static':
295
				case 'dyndns-custom':
296
					$needsIP = FALSE;
297
					if ($this->_dnsVerboseLog)
298
						log_error("DynDNS: ({$this->_dnsHost}) DNS update() starting.");
299
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
300
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
301
					$server = "https://members.dyndns.org/nic/update";
302
					$port = "";
303
					if($this->_dnsServer)
304
						$server = $this->_dnsServer;
305
					if($this->_dnsPort)
306
						$port = ":" . $this->_dnsPort;
307
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
308
					break;
309
				case 'dhs':
310
					// DHS is disabled in the GUI because the following doesn't work. 
311
					$needsIP = TRUE;
312
					$post_data['hostscmd'] = 'edit';
313
					$post_data['hostscmdstage'] = '2';
314
					$post_data['type'] = '4';
315
					$post_data['updatetype'] = 'Online';
316
					$post_data['mx'] = $this->_dnsMX;
317
					$post_data['mx2'] = '';
318
					$post_data['txt'] = '';
319
					$post_data['offline_url'] = '';
320
					$post_data['cloak'] = 'Y';
321
					$post_data['cloak_title'] = '';
322
					$post_data['ip'] = $this->_dnsIP;
323
					$post_data['domain'] = 'dyn.dhs.org';
324
					$post_data['hostname'] = $this->_dnsHost;
325
					$post_data['submit'] = 'Update';
326
					$server = "https://members.dhs.org/nic/hosts";
327
					$port = "";
328
					if($this->_dnsServer)
329
						$server = $this->_dnsServer;
330
					if($this->_dnsPort)
331
						$port = ":" . $this->_dnsPort;					
332
					curl_setopt($ch, CURLOPT_URL, $server . $port);
333
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
334
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
335
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
336
					break;
337
				case 'noip':
338
				case 'noip-free':
339
					$needsIP = TRUE;
340
					$server = "https://dynupdate.no-ip.com/ducupdate.php";
341
					$port = "";
342
					if($this->_dnsServer)
343
						$server = $this->_dnsServer;
344
					if($this->_dnsPort)
345
						$port = ":" . $this->_dnsPort;
346
					if(($this->_dnsService == "noip-free") && 
347
					   ($this->_forceUpdateNeeded == true) && 
348
					   ($this->_dnsDummyUpdateDone == false)) {
349
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
350
						$iptoset = "192.168.1.1";
351
						$this->_dnsDummyUpdateDone = true;
352
						log_error("DynDNS ({$this->_dnsHost}): Processing dummy update on No-IP free account. IP temporarily set to " . $iptoset);
353
					} else {
354
						$iptoset = $this->_dnsIP;
355
					}
356
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&hostname=' . $this->_dnsHost.'&ip=' . $iptoset);
357
					break;
358
				case 'easydns':
359
					$needsIP = TRUE;
360
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
361
					$server = "https://members.easydns.com/dyn/dyndns.php";
362
					$port = "";
363
					if($this->_dnsServer)
364
						$server = $this->_dnsServer;
365
					if($this->_dnsPort)
366
						$port = ":" . $this->_dnsPort;
367
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
368
					break;
369
				case 'hn':
370
					$needsIP = TRUE;
371
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
372
					$server = "http://dup.hn.org/vanity/update";
373
					$port = "";
374
					if($this->_dnsServer)
375
						$server = $this->_dnsServer;
376
					if($this->_dnsPort)
377
						$port = ":" . $this->_dnsPort;
378
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
379
					break;
380
				case 'zoneedit':
381
					$needsIP = FALSE;
382
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
383

    
384
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
385
					$port = "";
386
					if($this->_dnsServer)
387
						$server = $this->_dnsServer;
388
					if($this->_dnsPort)
389
						$port = ":" . $this->_dnsPort;
390
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
391
					break;
392
				case 'dyns':
393
					$needsIP = FALSE;
394
					$server = "https://www.dyns.cx/postscript011.php";
395
					$port = "";
396
					if($this->_dnsServer)
397
						$server = $this->_dnsServer;
398
					if($this->_dnsPort)
399
						$port = ":" . $this->_dnsPort;					
400
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
401
					break;
402
				case 'ods':
403
					$needsIP = FALSE;
404
					$misc_errno = 0;
405
					$misc_error = "";
406
					$server = "ods.org";
407
					$port = "";
408
					if($this->_dnsServer)
409
						$server = $this->_dnsServer;
410
					if($this->_dnsPort)
411
						$port = ":" . $this->_dnsPort;						
412
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
413
					/* Check that we have connected */
414
					if (!$this->con['socket']) {
415
						print "error! could not connect.";
416
						break;
417
					}
418
					/* Here is the loop. Read the incoming data (from the socket connection) */
419
					while (!feof($this->con['socket'])) {
420
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
421
						$code = substr($this->con['buffer']['all'], 0, 3);
422
						sleep(1);
423
						switch($code) {
424
							case 100:
425
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
426
								break;
427
							case 225:
428
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
429
								break;
430
							case 901:
431
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
432
								break;
433
							case 795:
434
								fputs($this->con['socket'], "QUIT\n");
435
								break;
436
						}
437
					}
438
					$this->_checkStatus(0, $code);
439
					break;
440
				case 'freedns':
441
					$needIP = FALSE;
442
					curl_setopt($ch, CURLOPT_URL, 'https://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
443
					break;
444
				case 'dnsexit':
445
					$needsIP = TRUE;
446
					curl_setopt($ch, CURLOPT_URL, 'https://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
447
					break;
448
				case 'loopia':
449
					$needsIP = TRUE;
450
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
451
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
452
					break;
453
				case 'opendns':
454
					$needsIP = FALSE;
455
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
456
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
457
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
458
					$port = "";
459
					if($this->_dnsServer)
460
						$server = $this->_dnsServer;
461
					if($this->_dnsPort)
462
						$port = ":" . $this->_dnsPort;
463
					curl_setopt($ch, CURLOPT_URL, $server .$port);
464
					break;
465

    
466
				case 'staticcling':
467
					$needsIP = FALSE;
468
					curl_setopt($ch, CURLOPT_URL, 'https://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
469
					break;	                    
470
				case 'dnsomatic':
471
					/* Example syntax 
472
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
473
					*/
474
					$needsIP = FALSE;
475
					if ($this->_dnsVerboseLog)
476
						log_error("DNS-O-Matic: DNS update() starting.");
477
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
478
					/*
479
					Reference: https://www.dnsomatic.com/wiki/api
480
						DNS-O-Matic usernames are 3-25 characters.
481
						DNS-O-Matic passwords are 6-20 characters.
482
						All ASCII letters and numbers accepted.
483
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
484
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
485
						Encodes the given string according to RFC 3986.
486
					*/
487
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
488
					if($this->_dnsServer)
489
						$server = $this->_dnsServer;
490
					if($this->_dnsPort)
491
						$port = ":" . $this->_dnsPort;
492
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
493
					break;
494
				case 'namecheap':
495
					/* Example:
496
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
497
					*/
498
					$needsIP = FALSE;
499
					if ($this->_dnsVerboseLog)
500
						log_error("Namecheap ({$this->_dnsHost}): DNS update() starting.");
501
					$dparts = explode(".", trim($this->_dnsHost));
502
					$domain_part_count = ($dparts[count($dparts)-1] == "uk") ? 3 : 2;
503
					$domain_offset = count($dparts) - $domain_part_count;
504
					$hostname = implode(".", array_slice($dparts, 0, $domain_offset));
505
					$domain = implode(".", array_slice($dparts, $domain_offset));
506
					$dnspass = trim($this->_dnsPass);
507
					$server = "https://dynamicdns.park-your-domain.com/update?host={$hostname}&domain={$domain}&password={$dnspass}&ip={$this->_dnsIP}";
508
					curl_setopt($ch, CURLOPT_URL, $server);
509
					break;
510
				case 'he-net':
511
				case 'he-net-v6':
512
					$needsIP = FALSE;
513
					if ($this->_dnsVerboseLog)
514
						log_error("HE.net ({$this->_dnsHost}): DNS update() starting.");
515
					$server = "https://dyn.dns.he.net/nic/update?";
516
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
517
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
518
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
519
					break;
520
				case 'he-net-tunnelbroker':
521
					$needsIP = FALSE;
522
					if ($this->_dnsVerboseLog)
523
						log_error("HE.net Tunnelbroker: DNS update() starting.");
524
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
525
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
526
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
527
					break;
528
				case 'selfhost':
529
					$needsIP = FALSE;
530
					if ($this->_dnsVerboseLog)
531
						log_error("SelfHost: DNS update() starting.");
532
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
533
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
534
					$server = "https://carol.selfhost.de/nic/update";
535
					$port = "";
536
					if($this->_dnsServer)
537
						$server = $this->_dnsServer;
538
					if($this->_dnsPort)
539
						$port = ":" . $this->_dnsPort;
540
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
541
					break;
542
				case 'route53':
543
					if ($this->_dnsVerboseLog)
544
						log_error("Route53 ({$this->_dnsHost}): DNS update() starting.");
545
					
546
					/* Setting Variables */
547
					$hostname = "{$this->_dnsHost}.";
548
					$ZoneID = $this->_dnsZoneID;
549
					$AccessKeyId=$this->_dnsUser;
550
					$SecretAccessKey=$this->_dnsPass;
551
					$NewIP=$this->_dnsIP;
552
					$NewTTL=$this->_dnsTTL;
553

    
554
					/* Include Route 53 Library Class */
555
					require_once('/etc/inc/r53.class');
556

    
557
					/* Set Amazon AWS Credentials for this record */
558
					$r53 = new Route53($AccessKeyId, $SecretAccessKey);
559

    
560
					/* Function to find old values of records in Route 53 */
561
					if(!function_exists('Searchrecords')) {
562
						function SearchRecords($records, $name) {
563
							$result = array();
564
							foreach($records as $record) {
565
								if(strtolower($record['Name']) == strtolower($name)) {
566
									$result [] = $record;
567
								}
568
							}
569
							return ($result) ? $result : false;
570
						}
571
					}
572

    
573
					$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
574

    
575
					/* Get IP for your hostname in Route 53 */
576
					if(false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
577
						$OldTTL=$a_result[0][TTL];
578
						$OldIP=$a_result[0][ResourceRecords][0];
579
					} else {
580
						$OldIP="";
581
					}
582

    
583
					/* Check if we need to update DNS Record */
584
					if ($OldIP !== $NewIP) {
585
						if(!empty($OldIP)) {
586
							/* Your Hostname already exists, deleting and creating it again */
587
							$changes = array();
588
							$changes[] = $r53->prepareChange(DELETE, $hostname, A, $OldTTL, $OldIP);
589
							$changes[] = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
590
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
591
						} else {
592
							/* Your Hostname does not exist yet, creating it */
593
							$changes = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
594
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
595
						}
596
					}
597
					$this->_checkStatus(0, $result);
598
					break;
599
				case 'custom':
600
				case 'custom-v6':
601
					if ($this->_dnsVerboseLog)
602
						log_error("Custom DDNS ({$this->_dnsHost}): DNS update() starting.");
603
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
604
					if ($this->_dnsUser != '') {
605
						if ($this->_curlIpresolveV4)
606
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
607
						if ($this->_curlSslVerifypeer)
608
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
609
						else
610
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
611
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
612
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
613
					}
614
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
615
					if ($this->_dnsVerboseLog)
616
						log_error("Sending request to: ".$server);
617
					curl_setopt($ch, CURLOPT_URL, $server);
618
					break;
619
				case 'cloudflare':
620
					$needsIP = TRUE;
621
					$dnsServer ='api.cloudflare.com';
622
					$dnsHost = str_replace(' ','', $this->_dnsHost);
623
					$host_names = explode(".", $dnsHost);
624
					$bottom_host_name = $host_names[count($host_names)-2] . "." . $host_names[count($host_names)-1];
625

    
626
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
627
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
628
						'X-Auth-Email: '.$this->_dnsUser.'',
629
						'X-Auth-Key: '.$this->_dnsPass.'',
630
						'Content-Type: application/json'
631
					));
632

    
633
					// Get zone ID
634
					$getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$bottom_host_name}";
635
					curl_setopt($ch, CURLOPT_URL, $getZoneId); 	
636
					$output = json_decode(curl_exec($ch));
637
					$zone = $output->result[0]->id;
638
					if ($zone){ // If zone ID was found get host ID
639
						$getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_dnsHost}";
640
						curl_setopt($ch, CURLOPT_URL, $getHostId); 
641
						$output = json_decode(curl_exec($ch));
642
						$host = $output->result[0]->id;
643
						if ($host){ // If host ID was found update host
644
							$hostData = array(
645
								"content" => "{$this->_dnsIP}",
646
								"type" => "A",
647
								"name" => "{$this->_dnsHost}",
648
								"proxiable" => false,
649
								"proxied" => false
650
							);
651
							$data_json = json_encode($hostData);
652
							$updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}";
653
							curl_setopt($ch, CURLOPT_URL, $updateHostId); 
654
							curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
655
							curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
656
						}
657
					}
658
					break;
659
				case 'eurodns':		
660
					$needsIP = TRUE;
661
					if ($this->_dnsVerboseLog)
662
						log_error("EuroDynDns ({$this->_dnsHost}) DNS update() starting.");
663
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
664
					$server = "https://update.eurodyndns.org/update/";
665
					$port = "";
666
					if($this->_dnsPort)
667
						$port = ":" . $this->_dnsPort;
668
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
669
					break;
670
				case 'gratisdns':
671
					$needsIP = TRUE;
672
					if ($this->_dnsVerboseLog)
673
						log_error("GratisDNS.dk ({$this->_dnsHost}): DNS update() starting.");
674
					$server = "https://ssl.gratisdns.dk/ddns.phtml";
675
					$host = trim($this->_dnsHost);
676
					$hostnames = explode(".", $host);
677
					$hostnames_count = count($hostnames);
678
					if ($hostnames_count > 2) {
679
						$domain = $hostnames[$hostnames_count-2] . "." . $hostnames[$hostnames_count-1];
680
					} else {
681
						$domain = $host;
682
					}
683
					curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $host . '&d=' . $domain . '&i=' . $this->_dnsIP);
684
					break;
685
				case 'ovh-dynhost':
686
					$needsIP = FALSE;
687
					if ($this->_dnsVerboseLog)
688
						log_error("OVH DynHOST: ({$this->_dnsHost}) DNS update() starting.");
689
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
690
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
691
					$server = "https://www.ovh.com/nic/update";
692
					$port = "";
693
					if($this->_dnsServer)
694
						$server = $this->_dnsServer;
695
					if($this->_dnsPort)
696
						$port = ":" . $this->_dnsPort;
697
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
698
					break;
699
				case 'citynetwork':
700
					$needsIP = TRUE;
701
					if ($this->_dnsVerboseLog)
702
						log_error("City Network: ({$this->_dnsHost}) DNS update() starting.");
703
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
704
					$server = 'https://dyndns.citynetwork.se/nic/update';
705
					$port = "";
706
					if($this->_dnsServer)
707
						$server = $this->_dnsServer;
708
					if($this->_dnsPort)
709
						$port = ":" . $this->_dnsPort;
710
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
711
					break;
712
				default:
713
					break;
714
			}
715
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53') {
716
				$data = curl_exec($ch);
717
				$this->_checkStatus($ch, $data);
718
				@curl_close($ch);
719
			}
720
		}
721

    
722
		/*
723
		 * Private Function (added 12 July 2005) [beta]
724
		 *   Retrieve Update Status
725
		 */
726
		function _checkStatus($ch, $data) {
727
			if ($this->_dnsVerboseLog) {
728
				log_error("DynDNS ({$this->_dnsHost}): DynDns _checkStatus() starting.");
729
				log_error("DynDNS ({$this->_dnsHost}): Current Service: {$this->_dnsService}");
730
			}
731
			$successful_update = false;
732
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53' && @curl_error($ch)) {
733
				$status = "Curl error occurred: " . curl_error($ch);
734
				log_error($status);
735
				$this->status = $status;
736
				return;
737
			}
738
			switch ($this->_dnsService) {
739
				case 'dnsomatic':
740
					if (preg_match('/badauth/i', $data)) {
741
						$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.";
742
					} else if (preg_match('/notfqdn /i', $data)) {
743
						$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.";
744
					} else if (preg_match('/nohost/i', $data)) {
745
						$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.";
746
					} else if (preg_match('/numhost/i', $data)) {
747
						$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.";	
748
					} else if (preg_match('/abuse/i', $data)) {
749
						$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname is blocked for update abuse.";
750
					} else if (preg_match('/good/i', $data)) {
751
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
752
						$successful_update = true;
753
					} else if (preg_match('/dnserr/i', $data)) {
754
						$status = "DNS-O-Matic ({$this->_dnsHost}): DNS error encountered. Stop updating for 30 minutes.";
755
					} else {
756
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Unknown Response)";
757
						log_error("DNS-O-Matic ({$this->_dnsHost}): PAYLOAD: {$data}");
758
						$this->_debug($data);
759
					}
760
					break;
761
				case 'citynetwork':
762
					if (preg_match('/notfqdn/i', $data)) {
763
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
764
					} else if (preg_match('/nohost/i', $data)) {
765
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) No such host";
766
					} else if (preg_match('/nochg/i', $data)) {
767
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
768
						$successful_update = true;
769
					} else if (preg_match('/good/i', $data)) {
770
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
771
						$successful_update = true;
772
					} else if (preg_match('/badauth/i', $data)) {
773
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
774
					} else {
775
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
776
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
777
						$this->_debug($data);
778
					}
779
					break;
780
				case 'ovh-dynhost':
781
				case 'dyndns':
782
					if (preg_match('/notfqdn/i', $data)) {
783
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
784
					} else if (preg_match('/nochg/i', $data)) {
785
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
786
						$successful_update = true;
787
					} else if (preg_match('/good/i', $data)) {
788
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
789
						$successful_update = true;
790
					} else if (preg_match('/noauth/i', $data)) {
791
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
792
					} else {
793
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
794
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
795
						$this->_debug($data);
796
					}
797
					break;
798
				case 'dyndns-static':
799
					if (preg_match('/notfqdn/i', $data)) {
800
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
801
					} else if (preg_match('/nochg/i', $data)) {
802
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
803
						$successful_update = true;
804
					} else if (preg_match('/good/i', $data)) {
805
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
806
						$successful_update = true;
807
					} else if (preg_match('/noauth/i', $data)) {
808
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
809
					} else {
810
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
811
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
812
						$this->_debug($data);
813
					}
814
					break;
815
				case 'dyndns-custom':
816
					if (preg_match('/notfqdn/i', $data)) {
817
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
818
					} else if (preg_match('/nochg/i', $data)) {
819
						$status = "phpDynDNS: (Success) No Change In IP Address";
820
						$successful_update = true;
821
					} else if (preg_match('/good/i', $data)) {
822
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
823
						$successful_update = true;
824
					} else if (preg_match('/noauth/i', $data)) {
825
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
826
					} else {
827
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
828
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
829
						$this->_debug($data);
830
					}
831
					break;
832
				case 'dhs':
833
					break;
834
				case 'noip':
835
				case 'noip-free':
836
					list($ip,$code) = explode(":",$data);
837
					switch ($code) {
838
						case 0:
839
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP address is current, no update performed.";
840
							$successful_update = true;
841
							break;
842
						case 1:
843
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS hostname update successful.";
844
							$successful_update = true;
845
							break;
846
						case 2:
847
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not exist.";
848
							break;
849
						case 3:
850
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Username.";
851
							break;
852
						case 4:
853
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Password.";
854
							break;
855
						case 5:
856
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too many updates sent.";
857
							break;
858
						case 6:
859
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account disabled due to violation of No-IP terms of service.";
860
							break;
861
						case 7:
862
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
863
							break;
864
						case 8:
865
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Disabled / Locked Hostname.";
866
							break;
867
						case 9:
868
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Host updated is configured as a web redirect and no update was performed.";
869
							break;
870
						case 10:
871
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Group supplied does not exist.";
872
							break;
873
						case 11:
874
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group update is successful.";
875
							$successful_update = true;
876
							break;
877
						case 12:
878
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group is current, no update performed.";
879
							$successful_update = true;
880
							break;
881
						case 13:
882
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update client support not available for supplied hostname or group.";
883
							break;
884
						case 14:
885
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not have offline settings configured.";
886
							break;
887
						case 99:
888
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
889
							break;
890
						case 100:
891
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
892
							break;
893
						default:
894
							$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
895
							$this->_debug("Unknown Response: ".$data);
896
							break;
897
					}
898
					break;
899
				case 'easydns':
900
					if (preg_match('/NOACCESS/i', $data)) {
901
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Authentication Failed: Username and/or Password was Incorrect.";
902
					} else if (preg_match('/NOSERVICE/i', $data)) {
903
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
904
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
905
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Illegal Input: Self-Explanatory";
906
					} else if (preg_match('/TOOSOON/i', $data)) {
907
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
908
					} else if (preg_match('/NOERROR/i', $data)) {
909
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Updated Successfully!";
910
						$successful_update = true;
911
					} else {
912
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
913
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
914
						$this->_debug($data);
915
					}
916
					break;
917
				case 'hn':
918
					/* FIXME: add checks */
919
					break;
920
				case 'zoneedit':
921
					if (preg_match('/799/i', $data)) {
922
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 799) Update Failed!";				
923
					} else if (preg_match('/700/i', $data)) {
924
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 700) Update Failed!";
925
					} else if (preg_match('/200/i', $data)) {
926
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
927
						$successful_update = true;
928
					} else if (preg_match('/201/i', $data)) {
929
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
930
						$successful_update = true;						
931
					} else {
932
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
933
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
934
						$this->_debug($data);
935
					}
936
					break;
937
				case 'dyns':
938
					if (preg_match("/400/i", $data)) {
939
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
940
					} else if (preg_match('/402/i', $data)) {
941
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update Too Soon - You have tried updating to quickly since last change.";
942
					} else if (preg_match('/403/i', $data)) {
943
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Database Error - There was a server-sided database error.";
944
					} else if (preg_match('/405/i', $data)) {
945
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
946
					} else if (preg_match('/200/i', $data)) {
947
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
948
						$successful_update = true;
949
					} else {
950
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
951
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
952
						$this->_debug($data);
953
					}
954
					break;
955
				case 'ods':
956
					if (preg_match("/299/i", $data)) {
957
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
958
						$successful_update = true;
959
					} else {
960
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
961
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
962
						$this->_debug($data);
963
					}
964
					break;
965
				case 'freedns':
966
					if (preg_match("/has not changed./i", $data)) {
967
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
968
						$successful_update = true;
969
					} else if (preg_match("/Updated/i", $data)) {
970
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
971
						$successful_update = true;
972
					} else {
973
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
974
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
975
						$this->_debug($data);
976
					} 
977
					break;
978
				case 'dnsexit':
979
					if (preg_match("/is the same/i", $data)) {
980
						$status = "phpDynDns ({$this->_dnsHost}): (Success) No Change In IP Address";
981
						$successful_update = true;
982
					} else if (preg_match("/Success/i", $data)) {
983
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
984
						$successful_update = true;
985
					} else {
986
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
987
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
988
						$this->_debug($data);
989
					}
990
					break;
991
				case 'loopia':
992
					if (preg_match("/nochg/i", $data)) {
993
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
994
						$successful_update = true;
995
					} else if (preg_match("/good/i", $data)) {
996
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
997
						$successful_update = true;
998
					} else if (preg_match('/badauth/i', $data)) {
999
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
1000
					} else {
1001
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1002
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1003
						$this->_debug($data);
1004
					}
1005
					break;
1006
				case 'opendns':
1007
					if (preg_match('/badauth/i', $data)) {
1008
						$status = "phpDynDNS({$this->_dnsHost}): (Error) Not a valid username or password!";
1009
					} else if (preg_match('/nohost/i', $data)) {
1010
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname you are trying to update does not exist.";
1011
						$successful_update = true;
1012
					} else if (preg_match('/good/i', $data)) {
1013
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
1014
						$successful_update = true;
1015
					} else if (preg_match('/yours/i', $data)) {
1016
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) hostname specified exists, but not under the username specified.";
1017
					} else if (preg_match('/abuse/i', $data)) {
1018
						$status = "phpDynDns ({$this->_dnsHost}): (Error) Updating too frequently, considered abuse.";
1019
					} else {
1020
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1021
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1022
						$this->_debug($data);
1023
					}
1024
					break;
1025
				case 'staticcling':
1026
					if (preg_match("/invalid ip/i", $data)) {
1027
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The IP provided was invalid.";
1028
					} else if (preg_match('/required info missing/i', $data)) {
1029
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Required parameters were not provided.";
1030
					} else if (preg_match('/invalid characters/i', $data)) {
1031
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Illegal characters in either the username or the password.";
1032
					} else if (preg_match('/bad password/i', $data)) {
1033
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid password.";
1034
					} else if (preg_match('/account locked/i', $data)) {
1035
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) This account has been administratively locked.";
1036
					} else if (preg_match('/update too frequent/i', $data)) {
1037
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Updating too frequently.";
1038
					} else if (preg_match('/DB error/i', $data)) {
1039
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Server side error.";
1040
					} else if (preg_match('/success/i', $data)) {
1041
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1042
						$successful_update = true;
1043
					} else {
1044
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1045
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1046
						$this->_debug($data);
1047
					}
1048
					break;
1049
				case 'namecheap':
1050
					$tmp = str_replace("^M", "", $data);
1051
					$ncresponse = @xml2array($tmp);
1052
					if (preg_match("/internal server error/i", $data)) {
1053
						$status = "phpDynDNS: (Error) Server side error.";
1054
					} else if (preg_match("/request is badly formed/i", $data)) {
1055
						$status = "phpDynDNS: (Error) Badly Formed Request (check your settings).";
1056
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1057
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1058
						$successful_update = true;
1059
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1060
						$status = "phpDynDNS: (Error) " . implode(", ", $ncresponse["interface-response"]["errors"]);
1061
						$successful_update = true;
1062
					} else {
1063
						$status = "phpDynDNS: (Unknown Response)";
1064
						log_error("phpDynDNS: PAYLOAD: {$data}");
1065
						$this->_debug($data);
1066
					}
1067
					break;
1068
					
1069
				case 'he-net':
1070
				case 'he-net-v6':
1071
					if (preg_match("/badip/i", $data)) {
1072
						$status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
1073
					} else if (preg_match('/nohost/i', $data)) {
1074
						$status = "phpDynDNS: (Error) Bad Request - A hostname was not provided.";
1075
					} else if (preg_match('/badauth/i', $data)) {
1076
						$status = "phpDynDNS: (Error) Invalid username or password.";
1077
					} else if (preg_match('/good/i', $data)) {
1078
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1079
						$successful_update = true;
1080
					} else if (preg_match('/nochg/i', $data)) {
1081
						$status = "phpDynDNS: (Success) No Change In IP Address.";
1082
						$successful_update = true;
1083
					} else {
1084
						$status = "phpDynDNS: (Unknown Response)";
1085
						log_error("phpDynDNS: PAYLOAD: {$data}");
1086
						$this->_debug($data);
1087
					}
1088
					break;
1089
				case 'he-net-tunnelbroker':
1090
					/*
1091
					-ERROR: Missing parameter(s).
1092
					-ERROR: Invalid API key or password
1093
					-ERROR: Tunnel not found
1094
					-ERROR: Another tunnel exists for this IP.
1095
					-ERROR: This tunnel is already associated with this IP address
1096
					+OK: Tunnel endpoint updated to: x.x.x.x
1097
					*/
1098
					if (preg_match("/Missing parameter/i", $data)) {
1099
						$status = "phpDynDNS: (Error) Bad Request - Missing/Invalid Parameters.";
1100
					} else if (preg_match('/Tunnel not found/i', $data)) {
1101
						$status = "phpDynDNS: (Error) Bad Request - Invalid Tunnel ID.";
1102
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1103
						$status = "phpDynDNS: (Error) Invalid username or password.";
1104
					} else if (preg_match('/OK:/i', $data)) {
1105
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1106
						$successful_update = true;
1107
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1108
						$status = "phpDynDNS: (Success) No Change In IP Address.";
1109
						$successful_update = true;
1110
					} else {
1111
						$status = "phpDynDNS: (Unknown Response)";
1112
						log_error("phpDynDNS: PAYLOAD: {$data}");
1113
						$this->_debug($data);
1114
					}
1115
					break;
1116
				case 'selfhost':
1117
					if (preg_match('/notfqdn/i', $data)) {
1118
						$status = "phpDynDNS: (Error) Not A FQDN!";
1119
					} else if (preg_match('/nochg/i', $data)) {
1120
						$status = "phpDynDNS: (Success) No Change In IP Address";
1121
						$successful_update = true;
1122
					} else if (preg_match('/good/i', $data)) {
1123
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
1124
						$successful_update = true;
1125
					} else if (preg_match('/noauth/i', $data)) {
1126
						$status = "phpDynDNS: (Error) User Authorization Failed";
1127
					} else {
1128
						$status = "phpDynDNS: (Unknown Response)";
1129
						log_error("phpDynDNS: PAYLOAD: {$data}");
1130
						$this->_debug($data);
1131
					}
1132
					break;
1133
				case 'route53':
1134
					$successful_update = true;
1135
					break;
1136
				case 'custom':
1137
				case 'custom-v6':
1138
					$successful_update = false;
1139
					if ($this->_dnsResultMatch == "") {
1140
						$successful_update = true;
1141
					}else {
1142
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1143
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1144
						foreach($matches as $match) {
1145
							$match= str_replace("\\|", "|", $match);
1146
							if(strcmp($match, trim($data, "\t\n\r")) == 0)
1147
								$successful_update = true;
1148
						}
1149
						unset ($matches);
1150
					}
1151
					if ($successful_update == true)
1152
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1153
					else
1154
						$status = "phpDynDNS: (Error) Result did not match.";
1155
					break;
1156
				case 'cloudflare':
1157
					$output = json_decode($data);
1158
					if ($output->result->content === $this->_dnsIP){
1159
						$status = "DynDNS: (Success) {$this->_dnsHost} updated to {$this->_dnsIP}";
1160
						$successful_update = true;
1161
					}
1162
					elseif ($output->errors[0]->code === 9103){
1163
						$status = "DynDNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.";
1164
					}
1165
					elseif (($output->success) && (!$output->result[0]->id)) {
1166
						$status = "DynDNS ({$this->_dnsHost}): ERROR - Zone or Host ID was not found, check your hostname.";
1167
					}
1168
					else {
1169
						$status = "DynDNS ({$this->_dnsHost}): UNKNOWN ERROR - {$output->errors[0]->message}";
1170
						log_error("DynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1171
					}
1172
					break;
1173
				case 'eurodns':
1174
					if (preg_match('/notfqdn/i', $data)) {
1175
						$status = "phpDynDNS: (Error) Not A FQDN!";
1176
					} else if (preg_match('/nochg/i', $data)) {
1177
						$status = "phpDynDNS: (Success) No Change In IP Address";
1178
						$successful_update = true;
1179
					} else if (preg_match('/good/i', $data)) {
1180
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
1181
						$successful_update = true;
1182
					} else if (preg_match('/badauth/i', $data)) {
1183
						$status = "phpDynDNS: (Error) User Authorization Failed";
1184
					} else {
1185
						$status = "phpDynDNS: (Unknown Response)";
1186
						log_error("phpDynDNS: PAYLOAD: {$data}");
1187
						$this->_debug($data);
1188
					}
1189
					break;
1190
				case 'gratisdns':
1191
					if (preg_match('/Forkerte værdier/i', $data)) {
1192
					        $status = "phpDynDNS: (Error) Wrong values - Update could not be completed.";
1193
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1194
					        $status = "phpDynDNS: (Error) Unknown username - User does not exist.";
1195
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1196
					        $status = "phpDynDNS: (Error) Wrong password - Remember password is case sensitive.";
1197
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1198
					        $status = "phpDynDNS: (Error) User unable to administer the selected domain.";
1199
					} else if (preg_match('/OK/i', $data)) {
1200
					        $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1201
					        $successful_update = true;
1202
					} else {
1203
					        $status = "phpDynDNS: (Unknown Response)";
1204
					        log_error("phpDynDNS: PAYLOAD: {$data}");
1205
					        $this->_debug($data);
1206
					}
1207
					break;
1208
			}
1209
			
1210
			if($successful_update == true) {
1211
				/* Write WAN IP to cache file */
1212
				$wan_ip = $this->_checkIP();
1213
				conf_mount_rw();
1214
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1215
					$currentTime = time();
1216
					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));
1217
					log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
1218
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1219
				} else
1220
					@unlink($this->_cacheFile);
1221
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1222
					$currentTime = time();
1223
					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));
1224
					log_error("phpDynDNS: updating cache file {$this->_cacheFile_v6}: {$wan_ip}");
1225
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1226
				} else
1227
					@unlink($this->_cacheFile_v6);
1228
				conf_mount_ro();
1229
			}
1230
			$this->status = $status;
1231
			log_error($status);
1232
		}
1233

    
1234
		/*
1235
		 * Private Function (added 12 July 05) [beta]
1236
		 *   Return Error, Set Last Error, and Die.
1237
		 */
1238
		function _error($errorNumber = '1') {
1239
			switch ($errorNumber) {
1240
				case 0:
1241
					break;
1242
				case 2:
1243
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
1244
					break;
1245
				case 3:
1246
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
1247
					break;
1248
				case 4:
1249
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
1250
					break;
1251
				case 5:
1252
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
1253
					break;
1254
				case 6:
1255
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
1256
					break;
1257
				case 7:
1258
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
1259
					break;
1260
				case 8:
1261
					$status = "Route 53: (Error) Invalid ZoneID";
1262
					break;
1263
				case 9:
1264
					$status = "Route 53: (Error) Invalid TTL";
1265
					break;  
1266
				case 10:
1267
					$error = "phpDynDNS ({$this->_dnsHost}): No change in my IP address and/or " . $this->_dnsMaxCacheAgeDays . " days has not passed. Not updating dynamic DNS entry.";
1268
					break;
1269
				default:
1270
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
1271
					/* FIXME: $data isn't in scope here */
1272
					/* $this->_debug($data); */
1273
					break;
1274
			}
1275
			$this->lastError = $error;
1276
			log_error($error);
1277
		}
1278

    
1279
		/*
1280
		 * Private Function (added 12 July 05) [beta]
1281
		 *   - Detect whether or not IP needs to be updated.
1282
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1283
		 *      | work with other systems. pfSense base is FreeBSD.
1284
		 */
1285
		function _detectChange() {
1286
			global $debug;
1287

    
1288
			if ($debug)
1289
				log_error("DynDns ({$this->_dnsHost}): _detectChange() starting.");
1290
		
1291
			$currentTime = time();
1292

    
1293
			$wan_ip = $this->_checkIP();
1294
			if ($wan_ip == 0) {
1295
				log_error("DynDns ({$this->_dnsHost}): Current WAN IP could not be determined, skipping update process.");
1296
				return false;
1297
			}
1298
			$log_error = "DynDns ({$this->_dnsHost}): Current WAN IP: {$wan_ip} ";
1299

    
1300
			if ($this->_useIPv6 == true) {
1301
				if (file_exists($this->_cacheFile_v6)) {
1302
					$contents = file_get_contents($this->_cacheFile_v6);
1303
					list($cacheIP,$cacheTime) = explode('|', $contents);
1304
					$this->_debug($cacheIP.'/'.$cacheTime);
1305
					$initial = false;
1306
					$log_error .= "Cached IPv6: {$cacheIP} ";
1307
				} else {
1308
					conf_mount_rw();
1309
					$cacheIP = '::';
1310
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1311
					conf_mount_ro();
1312
					$cacheTime = $currentTime;
1313
					$initial = true;
1314
					$log_error .= "No Cached IPv6 found.";
1315
				}
1316
			} else {
1317
				if (file_exists($this->_cacheFile)) {
1318
					$contents = file_get_contents($this->_cacheFile);
1319
					list($cacheIP,$cacheTime) = explode(':', $contents);
1320
					$this->_debug($cacheIP.'/'.$cacheTime);
1321
					$initial = false;
1322
					$log_error .= "Cached IP: {$cacheIP} ";
1323
				} else {
1324
					conf_mount_rw();
1325
					$cacheIP = '0.0.0.0';
1326
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1327
					conf_mount_ro();
1328
					$cacheTime = $currentTime;
1329
					$initial = true;
1330
					$log_error .= "No Cached IP found.";
1331
				}
1332
			}
1333
			if ($this->_dnsVerboseLog)
1334
				log_error($log_error);
1335

    
1336
			// Convert seconds = days * hr/day * min/hr * sec/min
1337
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1338

    
1339
			$needs_updating = FALSE;
1340
			/* lets determine if the item needs updating */
1341
			if ($cacheIP != $wan_ip) {
1342
				$needs_updating = true;
1343
				$update_reason = "DynDns: cacheIP != wan_ip.  Updating. ";
1344
				$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
1345
			}
1346
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1347
				$needs_updating = true;
1348
				$this->_forceUpdateNeeded = true;
1349
				$update_reason = "DynDns: More than " . $this->_dnsMaxCacheAgeDays . " days.  Updating. ";
1350
				$update_reason .= "{$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1351
			}
1352
			if ($initial == true) {
1353
				$needs_updating = true;
1354
				$update_reason .= "Initial update. ";
1355
			}
1356

    
1357
			/*   finally if we need updating then store the
1358
			 *   new cache value and return true
1359
			 */
1360
			if ($needs_updating == true) {
1361
				if ($this->_dnsVerboseLog)
1362
					log_error("DynDns ({$this->_dnsHost}): {$update_reason}");
1363
				return true;
1364
			}
1365

    
1366
			return false;			
1367
		}
1368

    
1369
		/*
1370
		 * Private Function (added 16 July 05) [beta]
1371
		 *   - Writes debug information to a file.
1372
		 *   - This function is only called when a unknown response
1373
		 *   - status is returned from a DynDNS service provider.
1374
		 */
1375
		function _debug($data) {
1376
			global $g;
1377

    
1378
			if (!$g['debug'])
1379
				return;
1380
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1381
			conf_mount_rw();
1382
			$file = fopen($this->_debugFile, 'a');
1383
			fwrite($file, $string);
1384
			fclose($file);
1385
			conf_mount_ro();
1386
		}
1387
		function _checkIP() {
1388
			global $debug;
1389

    
1390
			if ($debug)
1391
				log_error("DynDns ({$this->_dnsHost}): _checkIP() starting.");
1392

    
1393
			if ($this->_useIPv6 == true) {
1394
				$ip_address = get_interface_ipv6($this->_if);
1395
				if (!is_ipaddrv6($ip_address))
1396
					return 0;
1397
			} else {
1398
				$ip_address = get_interface_ip($this->_if);
1399
				if (!is_ipaddr($ip_address))
1400
					return 0;
1401
			}
1402
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1403
				$hosttocheck = "checkip.dyndns.org";
1404
				$try = 0;
1405
				while ($try < 3) {
1406
					$checkip = gethostbyname($hosttocheck);
1407
					if (is_ipaddr($checkip))
1408
						break;
1409
					$try++;
1410
				}
1411
				if ($try >= 3) {
1412
					log_error("Dyndns debug information ({$this->_dnsHost}): Could not resolve {$hosttocheck} to IP using interface IP {$ip_address}.");
1413
					return 0;
1414
				}
1415
				$ip_ch = curl_init("http://{$checkip}");
1416
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1417
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1418
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1419
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1420
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1421
				if ($this->_useIPv6 == false) {
1422
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1423
				}
1424
				$ip_result_page = curl_exec($ip_ch);
1425
				curl_close($ip_ch);
1426
				$ip_result_decoded = urldecode($ip_result_page);
1427
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1428
				$ip_address = trim($matches[1]);
1429
				if (is_ipaddr($ip_address)) {
1430
					if ($this->_dnsVerboseLog)
1431
						log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from {$hosttocheck}");
1432
				} else {
1433
					log_error("DynDns ({$this->_dnsHost}): IP address could not be extracted from {$hosttocheck}");
1434
					return 0;
1435
				}
1436
			} else {
1437
				if ($this->_dnsVerboseLog)
1438
					log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from local system.");
1439
			}
1440
			$this->_dnsIP = $ip_address;
1441

    
1442
			return $ip_address;
1443
		}
1444

    
1445
	}
1446

    
1447
?>
(17-17/68)