Project

General

Profile

Download (65.3 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
	 *    - GleSYS (glesys.com)
33
	 *    - DNSimple (dnsimple.com)
34
	 *    - Google Domains (domains.google.com)
35
	 *    - DNS Made Easy (www.dnsmadeeasy.com)
36
	 * +----------------------------------------------------+
37
	 *  Requirements:
38
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
39
	 * +----------------------------------------------------+
40
	 *  Public Functions
41
	 *    - updatedns()
42
	 *
43
	 *  Private Functions
44
	 *    - _update()
45
	 *    - _checkStatus()
46
	 *    - _error()
47
	 *    - _detectChange()
48
	 *    - _debug()
49
	 *    - _checkIP()
50
	 * +----------------------------------------------------+
51
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
52
	 *  DynDNS Static   - Last Tested: NEVER
53
	 *  DynDNS Custom   - Last Tested: NEVER
54
	 *  No-IP           - Last Tested: 20 July 2008
55
	 *  HN.org          - Last Tested: 12 July 2005
56
	 *  EasyDNS         - Last Tested: 20 July 2008
57
	 *  DHS             - Last Tested: 12 July 2005
58
	 *  ZoneEdit        - Last Tested: NEVER
59
	 *  Dyns            - Last Tested: NEVER
60
	 *  ODS             - Last Tested: 02 August 2005
61
	 *  FreeDNS         - Last Tested: 23 Feb 2011
62
	 *  Loopia          - Last Tested: NEVER
63
	 *  StaticCling     - Last Tested: 27 April 2006
64
	 *  DNSexit         - Last Tested: 20 July 2008
65
	 *  OpenDNS         - Last Tested: 4 August 2008
66
	 *  Namecheap       - Last Tested: 31 August 2010
67
	 *  HE.net          - Last Tested: 7 July 2013
68
	 *  HE.net IPv6     - Last Tested: 7 July 2013
69
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
70
	 *  SelfHost        - Last Tested: 26 December 2011
71
	 *  Amazon Route 53 - Last tested: 01 April 2012
72
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
73
	 *  CloudFlare      - Last Tested: 30 May 2013
74
	 *  Eurodns         - Last Tested: 27 June 2013
75
	 *  GratisDNS       - Last Tested: 15 August 2012
76
	 *  OVH DynHOST     - Last Tested: NEVER
77
	 *  City Network    - Last Tested: 13 November 2013
78
	 *  GleSYS          - Last Tested: 3 February 2015
79
	 *  DNSimple        - Last Tested: 09 February 2015
80
	 *  Google Domains  - Last Tested: 27 April 2015
81
	 *  DNS Made Easy   - Last Tested: 27 April 2015
82
	 * +====================================================+
83
	 *
84
	 * @author 	E.Kristensen
85
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
86
	 * @version 	0.8
87
	 * @updated	13 October 05 at 21:02:42 GMT
88
	 *
89
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
90
	 * Custom DNS support by Matt Corallo
91
	 *
92
	 */
93

    
94
	class updatedns {
95
		var $_cacheFile;
96
		var $_cacheFile_v6;
97
		var $_debugFile;
98
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
99
		var $_errorVerbosity = 0;
100
		var $_dnsService;
101
		var $_dnsUser;
102
		var $_dnsPass;
103
		var $_dnsHost;
104
		var $_dnsIP;
105
		var $_dnsWildcard;
106
		var $_dnsMX;
107
		var $_dnsBackMX;
108
		var $_dnsServer;
109
		var $_dnsPort;
110
		var $_dnsUpdateURL;
111
		var $_dnsZoneID;
112
		var $_dnsTTL;
113
		var $status;
114
		var $_debugID;
115
		var $_if;
116
		var $_dnsResultMatch;
117
		var $_dnsRequestIf;
118
		var $_dnsRequestIfIP;
119
		var $_dnsVerboseLog;
120
		var $_curlIpresolveV4;
121
		var $_curlSslVerifypeer;
122
		var $_dnsMaxCacheAgeDays;
123
		var $_dnsDummyUpdateDone;
124
		var $_forceUpdateNeeded;
125
		var $_useIPv6;
126

    
127
		/*
128
		 * Public Constructor Function (added 12 July 05) [beta]
129
		 *   - Gets the dice rolling for the update.
130
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
131
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
132
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
133
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
134
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
135
		 */
136
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
137
					$dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
138
					$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
139
					$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
140
					$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
141

    
142
			global $config, $g;
143

    
144
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache";
145
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}_v6.cache";
146
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.debug";
147

    
148
			$this->_curlIpresolveV4 = $curlIpresolveV4;
149
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
150
			$this->_dnsVerboseLog = $dnsVerboseLog;
151
			if ($this->_dnsVerboseLog) {
152
				log_error("DynDns: updatedns() starting");
153
			}
154

    
155
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
156

    
157
			if (!$dnsService) $this->_error(2);
158
			switch ($dnsService) {
159
			case 'freedns':
160
				if (!$dnsHost) $this->_error(5);
161
				break;
162
			case 'namecheap':
163
				if (!$dnsPass) $this->_error(4);
164
				if (!$dnsHost) $this->_error(5);
165
				break;
166
			case 'route53':
167
				if (!$dnsZoneID) $this->_error(8);
168
				if (!$dnsTTL) $this->_error(9);
169
				break;
170
			case 'custom':
171
				if (!$dnsUpdateURL) $this->_error(7);
172
				break;
173
			default:
174
				if (!$dnsUser) $this->_error(3);
175
				if (!$dnsPass) $this->_error(4);
176
				if (!$dnsHost) $this->_error(5);
177
			}
178

    
179
			switch ($dnsService) {
180
				case 'he-net-v6':
181
				case 'custom-v6':
182
					$this->_useIPv6 = true;
183
					break;
184
				default:
185
					$this->_useIPv6 = false;
186
			}
187
			$this->_dnsService = strtolower($dnsService);
188
			$this->_dnsUser = $dnsUser;
189
			$this->_dnsPass = $dnsPass;
190
			$this->_dnsHost = $dnsHost;
191
			$this->_dnsServer = $dnsServer;
192
			$this->_dnsPort = $dnsPort;
193
			$this->_dnsWildcard = $dnsWildcard;
194
			$this->_dnsMX = $dnsMX;
195
			$this->_dnsZoneID = $dnsZoneID;
196
			$this->_dnsTTL = $dnsTTL;
197
			$this->_if = get_failover_interface($dnsIf);
198
			$this->_checkIP();
199
			$this->_dnsUpdateURL = $dnsUpdateURL;
200
			$this->_dnsResultMatch = $dnsResultMatch;
201
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
202
			if ($this->_dnsVerboseLog) {
203
				log_error("DynDNS ({$this->_dnsHost}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}");
204
			}
205
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
206
			$this->_dnsMaxCacheAgeDays = 25;
207
			$this->_dnsDummyUpdateDone = false;
208
			$this->_forceUpdateNeeded = $forceUpdate;
209

    
210
			// Ensure that we were able to lookup the IP
211
			if (!is_ipaddr($this->_dnsIP)) {
212
				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.");
213
				unlock($dyndnslck);
214
				return;
215
			}
216

    
217
			$this->_debugID = rand(1000000, 9999999);
218

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

    
273
			unlock($dyndnslck);
274
		}
275

    
276
		/*
277
		 * Private Function (added 12 July 05) [beta]
278
		 *   Send Update To Selected Service.
279
		 */
280
		function _update() {
281

    
282
			if ($this->_dnsVerboseLog) {
283
				log_error("DynDNS ({$this->_dnsHost}): DynDns _update() starting.");
284
			}
285

    
286
			if (strstr($this->_dnsRequestIf, "_vip")) {
287
				$parentif = link_carp_interface_to_parent($this->_dnsRequestIf);
288
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
289
			} else {
290
				$realparentif = $this->_dnsRequestIf;
291
			}
292

    
293
			$ch = curl_init();
294

    
295
			if ($this->_useIPv6 == false) {
296
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
297
			}
298

    
299
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
300
				curl_setopt($ch, CURLOPT_HEADER, 0);
301
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
302
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
303
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
304
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
305
			}
306

    
307
			switch ($this->_dnsService) {
308
				case 'glesys':
309
					$needsIP = TRUE;
310
					if ($this->_dnsVerboseLog) {
311
						log_error("DynDNS: ({$this->_dnsHost}) DNS update() starting.");
312
					}
313
					$server = 'https://api.glesys.com/domain/updaterecord/format/json';
314
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
315
					$post_data['recordid'] = $this->_dnsHost;
316
					$post_data['data'] = $this->_dnsIP;
317
					curl_setopt($ch, CURLOPT_URL, $server);
318
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
319
					break;
320
				case 'dyndns':
321
				case 'dyndns-static':
322
				case 'dyndns-custom':
323
					$needsIP = FALSE;
324
					if ($this->_dnsVerboseLog) {
325
						log_error("DynDNS: ({$this->_dnsHost}) DNS update() starting.");
326
					}
327
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
328
						$this->_dnsWildcard = "ON";
329
					}
330
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
331
					$server = "https://members.dyndns.org/nic/update";
332
					$port = "";
333
					if ($this->_dnsServer) {
334
						$server = $this->_dnsServer;
335
					}
336
					if ($this->_dnsPort) {
337
						$port = ":" . $this->_dnsPort;
338
					}
339
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
340
					break;
341
				case 'dhs':
342
					// DHS is disabled in the GUI because the following doesn't work.
343
					$needsIP = TRUE;
344
					$post_data['hostscmd'] = 'edit';
345
					$post_data['hostscmdstage'] = '2';
346
					$post_data['type'] = '4';
347
					$post_data['updatetype'] = 'Online';
348
					$post_data['mx'] = $this->_dnsMX;
349
					$post_data['mx2'] = '';
350
					$post_data['txt'] = '';
351
					$post_data['offline_url'] = '';
352
					$post_data['cloak'] = 'Y';
353
					$post_data['cloak_title'] = '';
354
					$post_data['ip'] = $this->_dnsIP;
355
					$post_data['domain'] = 'dyn.dhs.org';
356
					$post_data['hostname'] = $this->_dnsHost;
357
					$post_data['submit'] = 'Update';
358
					$server = "https://members.dhs.org/nic/hosts";
359
					$port = "";
360
					if ($this->_dnsServer) {
361
						$server = $this->_dnsServer;
362
					}
363
					if ($this->_dnsPort) {
364
						$port = ":" . $this->_dnsPort;
365
					}
366
					curl_setopt($ch, CURLOPT_URL, $server . $port);
367
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
368
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
369
					break;
370
				case 'noip':
371
				case 'noip-free':
372
					$needsIP = TRUE;
373
					$server = "https://dynupdate.no-ip.com/ducupdate.php";
374
					$port = "";
375
					if ($this->_dnsServer) {
376
						$server = $this->_dnsServer;
377
					}
378
					if ($this->_dnsPort) {
379
						$port = ":" . $this->_dnsPort;
380
					}
381
					if (($this->_dnsService == "noip-free") &&
382
					    ($this->_forceUpdateNeeded == true) &&
383
					    ($this->_dnsDummyUpdateDone == false)) {
384
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
385
						$iptoset = "192.168.1.1";
386
						$this->_dnsDummyUpdateDone = true;
387
						log_error("DynDNS ({$this->_dnsHost}): Processing dummy update on No-IP free account. IP temporarily set to " . $iptoset);
388
					} else {
389
						$iptoset = $this->_dnsIP;
390
					}
391
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&hostname=' . $this->_dnsHost.'&ip=' . $iptoset);
392
					break;
393
				case 'easydns':
394
					$needsIP = TRUE;
395
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
396
					$server = "https://members.easydns.com/dyn/dyndns.php";
397
					$port = "";
398
					if ($this->_dnsServer) {
399
						$server = $this->_dnsServer;
400
					}
401
					if ($this->_dnsPort) {
402
						$port = ":" . $this->_dnsPort;
403
					}
404
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
405
					break;
406
				case 'hn':
407
					$needsIP = TRUE;
408
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
409
					$server = "http://dup.hn.org/vanity/update";
410
					$port = "";
411
					if ($this->_dnsServer) {
412
						$server = $this->_dnsServer;
413
					}
414
					if ($this->_dnsPort) {
415
						$port = ":" . $this->_dnsPort;
416
					}
417
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
418
					break;
419
				case 'zoneedit':
420
					$needsIP = FALSE;
421
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
422

    
423
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
424
					$port = "";
425
					if ($this->_dnsServer) {
426
						$server = $this->_dnsServer;
427
					}
428
					if ($this->_dnsPort) {
429
						$port = ":" . $this->_dnsPort;
430
					}
431
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
432
					break;
433
				case 'dyns':
434
					$needsIP = FALSE;
435
					$server = "https://www.dyns.cx/postscript011.php";
436
					$port = "";
437
					if ($this->_dnsServer) {
438
						$server = $this->_dnsServer;
439
					}
440
					if ($this->_dnsPort) {
441
						$port = ":" . $this->_dnsPort;
442
					}
443
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
444
					break;
445
				case 'ods':
446
					$needsIP = FALSE;
447
					$misc_errno = 0;
448
					$misc_error = "";
449
					$server = "ods.org";
450
					$port = "";
451
					if ($this->_dnsServer) {
452
						$server = $this->_dnsServer;
453
					}
454
					if ($this->_dnsPort) {
455
						$port = ":" . $this->_dnsPort;
456
					}
457
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
458
					/* Check that we have connected */
459
					if (!$this->con['socket']) {
460
						print "error! could not connect.";
461
						break;
462
					}
463
					/* Here is the loop. Read the incoming data (from the socket connection) */
464
					while (!feof($this->con['socket'])) {
465
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
466
						$code = substr($this->con['buffer']['all'], 0, 3);
467
						sleep(1);
468
						switch ($code) {
469
							case 100:
470
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
471
								break;
472
							case 225:
473
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
474
								break;
475
							case 901:
476
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
477
								break;
478
							case 795:
479
								fputs($this->con['socket'], "QUIT\n");
480
								break;
481
						}
482
					}
483
					$this->_checkStatus(0, $code);
484
					break;
485
				case 'freedns':
486
					$needIP = FALSE;
487
					curl_setopt($ch, CURLOPT_URL, 'https://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
488
					break;
489
				case 'dnsexit':
490
					$needsIP = TRUE;
491
					curl_setopt($ch, CURLOPT_URL, 'https://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
492
					break;
493
				case 'loopia':
494
					$needsIP = TRUE;
495
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
496
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
497
					break;
498
				case 'opendns':
499
					$needsIP = FALSE;
500
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
501
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
502
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
503
					$port = "";
504
					if ($this->_dnsServer) {
505
						$server = $this->_dnsServer;
506
					}
507
					if ($this->_dnsPort) {
508
						$port = ":" . $this->_dnsPort;
509
					}
510
					curl_setopt($ch, CURLOPT_URL, $server .$port);
511
					break;
512

    
513
				case 'staticcling':
514
					$needsIP = FALSE;
515
					curl_setopt($ch, CURLOPT_URL, 'https://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
516
					break;
517
				case 'dnsomatic':
518
					/* Example syntax
519
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
520
					*/
521
					$needsIP = FALSE;
522
					if ($this->_dnsVerboseLog) {
523
						log_error("DNS-O-Matic: DNS update() starting.");
524
					}
525
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
526
						$this->_dnsWildcard = "ON";
527
					}
528
					/*
529
					Reference: https://www.dnsomatic.com/wiki/api
530
						DNS-O-Matic usernames are 3-25 characters.
531
						DNS-O-Matic passwords are 6-20 characters.
532
						All ASCII letters and numbers accepted.
533
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
534
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
535
						Encodes the given string according to RFC 3986.
536
					*/
537
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
538
					if ($this->_dnsServer) {
539
						$server = $this->_dnsServer;
540
					}
541
					if ($this->_dnsPort) {
542
						$port = ":" . $this->_dnsPort;
543
					}
544
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
545
					break;
546
				case 'namecheap':
547
					/* Example:
548
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
549
					*/
550
					$needsIP = FALSE;
551
					if ($this->_dnsVerboseLog) {
552
						log_error("Namecheap ({$this->_dnsHost}): DNS update() starting.");
553
					}
554
					$dparts = explode(".", trim($this->_dnsHost));
555
					$domain_part_count = ($dparts[count($dparts)-1] == "uk") ? 3 : 2;
556
					$domain_offset = count($dparts) - $domain_part_count;
557
					$hostname = implode(".", array_slice($dparts, 0, $domain_offset));
558
					$domain = implode(".", array_slice($dparts, $domain_offset));
559
					$dnspass = trim($this->_dnsPass);
560
					$server = "https://dynamicdns.park-your-domain.com/update?host={$hostname}&domain={$domain}&password={$dnspass}&ip={$this->_dnsIP}";
561
					curl_setopt($ch, CURLOPT_URL, $server);
562
					break;
563
				case 'he-net':
564
				case 'he-net-v6':
565
					$needsIP = FALSE;
566
					if ($this->_dnsVerboseLog) {
567
						log_error("HE.net ({$this->_dnsHost}): DNS update() starting.");
568
					}
569
					$server = "https://dyn.dns.he.net/nic/update?";
570
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
571
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
572
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
573
					break;
574
				case 'he-net-tunnelbroker':
575
					$needsIP = FALSE;
576
					if ($this->_dnsVerboseLog) {
577
						log_error("HE.net Tunnelbroker: DNS update() starting.");
578
					}
579
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
580
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
581
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
582
					break;
583
				case 'selfhost':
584
					$needsIP = FALSE;
585
					if ($this->_dnsVerboseLog) {
586
						log_error("SelfHost: DNS update() starting.");
587
					}
588
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
589
						$this->_dnsWildcard = "ON";
590
					}
591
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
592
					$server = "https://carol.selfhost.de/nic/update";
593
					$port = "";
594
					if ($this->_dnsServer) {
595
						$server = $this->_dnsServer;
596
					}
597
					if ($this->_dnsPort) {
598
						$port = ":" . $this->_dnsPort;
599
					}
600
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
601
					break;
602
				case 'route53':
603
					if ($this->_dnsVerboseLog) {
604
						log_error("Route53 ({$this->_dnsHost}): DNS update() starting.");
605
					}
606

    
607
					/* Setting Variables */
608
					$hostname = "{$this->_dnsHost}.";
609
					$ZoneID = $this->_dnsZoneID;
610
					$AccessKeyId = $this->_dnsUser;
611
					$SecretAccessKey = $this->_dnsPass;
612
					$NewIP = $this->_dnsIP;
613
					$NewTTL = $this->_dnsTTL;
614

    
615
					/* Include Route 53 Library Class */
616
					require_once('/etc/inc/r53.class');
617

    
618
					/* Set Amazon AWS Credentials for this record */
619
					$r53 = new Route53($AccessKeyId, $SecretAccessKey);
620

    
621
					/* Function to find old values of records in Route 53 */
622
					if (!function_exists('Searchrecords')) {
623
						function SearchRecords($records, $name) {
624
							$result = array();
625
							foreach ($records as $record) {
626
								if (strtolower($record['Name']) == strtolower($name)) {
627
									$result [] = $record;
628
								}
629
							}
630
							return ($result) ? $result : false;
631
						}
632
					}
633

    
634
					$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
635

    
636
					/* Get IP for your hostname in Route 53 */
637
					if (false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
638
						$OldTTL = $a_result[0][TTL];
639
						$OldIP = $a_result[0][ResourceRecords][0];
640
					} else {
641
						$OldIP = "";
642
					}
643

    
644
					/* Check if we need to update DNS Record */
645
					if ($OldIP !== $NewIP) {
646
						if (!empty($OldIP)) {
647
							/* Your Hostname already exists, deleting and creating it again */
648
							$changes = array();
649
							$changes[] = $r53->prepareChange(DELETE, $hostname, A, $OldTTL, $OldIP);
650
							$changes[] = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
651
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
652
						} else {
653
							/* Your Hostname does not exist yet, creating it */
654
							$changes = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
655
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
656
						}
657
					}
658
					$this->_checkStatus(0, $result);
659
					break;
660
				case 'custom':
661
				case 'custom-v6':
662
					if ($this->_dnsVerboseLog) {
663
						log_error("Custom DDNS ({$this->_dnsHost}): DNS update() starting.");
664
					}
665
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
666
					if ($this->_dnsUser != '') {
667
						if ($this->_curlIpresolveV4) {
668
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
669
						}
670
						if ($this->_curlSslVerifypeer) {
671
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
672
						} else {
673
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
674
						}
675
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
676
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
677
					}
678
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
679
					if ($this->_dnsVerboseLog) {
680
						log_error("Sending request to: ".$server);
681
					}
682
					curl_setopt($ch, CURLOPT_URL, $server);
683
					break;
684
				case 'cloudflare':
685
					$needsIP = TRUE;
686
					$dnsServer ='api.cloudflare.com';
687
					$dnsHost = str_replace(' ','', $this->_dnsHost);
688
					$host_names = explode(".", $dnsHost);
689
					$bottom_host_name = $host_names[count($host_names)-2] . "." . $host_names[count($host_names)-1];
690

    
691
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
692
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
693
						'X-Auth-Email: '.$this->_dnsUser.'',
694
						'X-Auth-Key: '.$this->_dnsPass.'',
695
						'Content-Type: application/json'
696
					));
697

    
698
					// Get zone ID
699
					$getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$bottom_host_name}";
700
					curl_setopt($ch, CURLOPT_URL, $getZoneId);
701
					$output = json_decode(curl_exec($ch));
702
					$zone = $output->result[0]->id;
703
					if ($zone){ // If zone ID was found get host ID
704
						$getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_dnsHost}";
705
						curl_setopt($ch, CURLOPT_URL, $getHostId);
706
						$output = json_decode(curl_exec($ch));
707
						$host = $output->result[0]->id;
708
						if ($host){ // If host ID was found update host
709
							$hostData = array(
710
								"content" => "{$this->_dnsIP}",
711
								"type" => "A",
712
								"name" => "{$this->_dnsHost}",
713
								"proxiable" => false,
714
								"proxied" => false
715
							);
716
							$data_json = json_encode($hostData);
717
							$updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}";
718
							curl_setopt($ch, CURLOPT_URL, $updateHostId);
719
							curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
720
							curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
721
						}
722
					}
723
					break;
724
				case 'eurodns':
725
					$needsIP = TRUE;
726
					if ($this->_dnsVerboseLog) {
727
						log_error("EuroDynDns ({$this->_dnsHost}) DNS update() starting.");
728
					}
729
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
730
					$server = "https://update.eurodyndns.org/update/";
731
					$port = "";
732
					if ($this->_dnsPort) {
733
						$port = ":" . $this->_dnsPort;
734
					}
735
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
736
					break;
737
				case 'gratisdns':
738
					$needsIP = TRUE;
739
					if ($this->_dnsVerboseLog) {
740
						log_error("GratisDNS.dk ({$this->_dnsHost}): DNS update() starting.");
741
					}
742
					$server = "https://ssl.gratisdns.dk/ddns.phtml";
743
					$host = trim($this->_dnsHost);
744
					$hostnames = explode(".", $host);
745
					$hostnames_count = count($hostnames);
746
					if ($hostnames_count > 2) {
747
						$domain = $hostnames[$hostnames_count-2] . "." . $hostnames[$hostnames_count-1];
748
					} else {
749
						$domain = $host;
750
					}
751
					curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $host . '&d=' . $domain . '&i=' . $this->_dnsIP);
752
					break;
753
				case 'ovh-dynhost':
754
					$needsIP = FALSE;
755
					if ($this->_dnsVerboseLog) {
756
						log_error("OVH DynHOST: ({$this->_dnsHost}) DNS update() starting.");
757
					}
758
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
759
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
760
					$server = "https://www.ovh.com/nic/update";
761
					$port = "";
762
					if ($this->_dnsServer) {
763
						$server = $this->_dnsServer;
764
					}
765
					if ($this->_dnsPort) {
766
						$port = ":" . $this->_dnsPort;
767
					}
768
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
769
					break;
770
				case 'citynetwork':
771
					$needsIP = TRUE;
772
					if ($this->_dnsVerboseLog) {
773
						log_error("City Network: ({$this->_dnsHost}) DNS update() starting.");
774
					}
775
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
776
					$server = 'https://dyndns.citynetwork.se/nic/update';
777
					$port = "";
778
					if ($this->_dnsServer) {
779
						$server = $this->_dnsServer;
780
					}
781
					if ($this->_dnsPort) {
782
						$port = ":" . $this->_dnsPort;
783
					}
784
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
785
					break;
786
				case 'dnsimple':
787
					/* Uses DNSimple's REST API
788
					   Requires username and Account API token passed in header
789
					   Piggybacks on Route 53's ZoneID field for DNSimple record ID
790
					   Data sent as JSON */
791
					$needsIP = TRUE;
792
					$server = 'https://api.dnsimple.com/v1/domains/';
793
					$token = $this->_dnsUser . ':' . $this->_dnsPass;
794
					$jsondata = '{"record":{"content":"' . $this->_dnsIP . '","ttl":"' . $this->_dnsTTL . '"}}';
795
					curl_setopt($ch, CURLOPT_HEADER, 1);
796
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
797
					curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-DNSimple-Token: ' . $token));
798
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '/records/' . $this->_dnsZoneID);
799
					curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
800
					break;
801
				case 'googledomains':
802
					$needsIP = FALSE;
803
					if ($this->_dnsVerboseLog) {
804
						log_error("Google Domains: ({$this->_dnsHost}) DNS update() starting.");
805
					}
806
					$post_data['username:password'] = $this->_dnsUser . ':' . $this->_dnsPass;
807
					$post_data['hostname'] = $this->_dnsHost;
808
					$post_data['myip'] = $this->_dnsIP;
809
					$post_data['offline'] = 'no';
810
					$server = "https://domains.google.com/nic/update";
811
					$port = "";
812
					curl_setopt($ch, CURLOPT_URL, 'https://domains.google.com/nic/update');
813
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
814
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
815
					break;
816
				case 'dnsmadeeasy':
817
					$needsIP = TRUE;
818
					if ($this->_dnsVerboseLog) {
819
						log_error("DNS Made Easy ({$this->_dnsHost}): DNS update() starting.");
820
					}
821
					$server = "https://cp.dnsmadeeasy.com/servlet/updateip";
822
					curl_setopt($ch, CURLOPT_URL, $server . '?username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&id=' . $this->_dnsHost . '&ip=' . $this->_dnsIP);
823
					break;
824
				default:
825
					break;
826
			}
827
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53') {
828
				$data = curl_exec($ch);
829
				$this->_checkStatus($ch, $data);
830
				@curl_close($ch);
831
			}
832
		}
833

    
834
		/*
835
		 * Private Function (added 12 July 2005) [beta]
836
		 *   Retrieve Update Status
837
		 */
838
		function _checkStatus($ch, $data) {
839
			if ($this->_dnsVerboseLog) {
840
				log_error("DynDNS ({$this->_dnsHost}): DynDns _checkStatus() starting.");
841
				log_error("DynDNS ({$this->_dnsHost}): Current Service: {$this->_dnsService}");
842
			}
843
			$successful_update = false;
844
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53' && @curl_error($ch)) {
845
				$status = "Curl error occurred: " . curl_error($ch);
846
				log_error($status);
847
				$this->status = $status;
848
				return;
849
			}
850
			switch ($this->_dnsService) {
851
				case 'glesys':
852
					if (preg_match('/Record updated/i', $data)) {
853
						$status = "GleSYS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
854
						$successful_update = true;
855
					} else {
856
						$status = "GleSYS ({$this->_dnsHost}): (Unknown Response)";
857
						log_error("GleSYS ({$this->_dnsHost}): PAYLOAD: {$data}");
858
						$this->_debug($data);
859
					}
860
					break;
861
				case 'dnsomatic':
862
					if (preg_match('/badauth/i', $data)) {
863
						$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.";
864
					} else if (preg_match('/notfqdn /i', $data)) {
865
						$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.";
866
					} else if (preg_match('/nohost/i', $data)) {
867
						$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.";
868
					} else if (preg_match('/numhost/i', $data)) {
869
						$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.";
870
					} else if (preg_match('/abuse/i', $data)) {
871
						$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname is blocked for update abuse.";
872
					} else if (preg_match('/good/i', $data)) {
873
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
874
						$successful_update = true;
875
					} else if (preg_match('/dnserr/i', $data)) {
876
						$status = "DNS-O-Matic ({$this->_dnsHost}): DNS error encountered. Stop updating for 30 minutes.";
877
					} else {
878
						$status = "DNS-O-Matic ({$this->_dnsHost}): (Unknown Response)";
879
						log_error("DNS-O-Matic ({$this->_dnsHost}): PAYLOAD: {$data}");
880
						$this->_debug($data);
881
					}
882
					break;
883
				case 'citynetwork':
884
					if (preg_match('/notfqdn/i', $data)) {
885
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
886
					} else if (preg_match('/nohost/i', $data)) {
887
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) No such host";
888
					} else if (preg_match('/nochg/i', $data)) {
889
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
890
						$successful_update = true;
891
					} else if (preg_match('/good/i', $data)) {
892
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
893
						$successful_update = true;
894
					} else if (preg_match('/badauth/i', $data)) {
895
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
896
					} else {
897
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
898
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
899
						$this->_debug($data);
900
					}
901
					break;
902
				case 'ovh-dynhost':
903
				case 'dyndns':
904
					if (preg_match('/notfqdn/i', $data)) {
905
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
906
					} else if (preg_match('/nochg/i', $data)) {
907
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
908
						$successful_update = true;
909
					} else if (preg_match('/good/i', $data)) {
910
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
911
						$successful_update = true;
912
					} else if (preg_match('/noauth/i', $data)) {
913
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
914
					} else {
915
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
916
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
917
						$this->_debug($data);
918
					}
919
					break;
920
				case 'dyndns-static':
921
					if (preg_match('/notfqdn/i', $data)) {
922
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
923
					} else if (preg_match('/nochg/i', $data)) {
924
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
925
						$successful_update = true;
926
					} else if (preg_match('/good/i', $data)) {
927
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
928
						$successful_update = true;
929
					} else if (preg_match('/noauth/i', $data)) {
930
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
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 'dyndns-custom':
938
					if (preg_match('/notfqdn/i', $data)) {
939
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
940
					} else if (preg_match('/nochg/i', $data)) {
941
						$status = "phpDynDNS: (Success) No Change In IP Address";
942
						$successful_update = true;
943
					} else if (preg_match('/good/i', $data)) {
944
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
945
						$successful_update = true;
946
					} else if (preg_match('/noauth/i', $data)) {
947
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
948
					} else {
949
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
950
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
951
						$this->_debug($data);
952
					}
953
					break;
954
				case 'dhs':
955
					break;
956
				case 'noip':
957
				case 'noip-free':
958
					list($ip, $code) = explode(":", $data);
959
					switch ($code) {
960
						case 0:
961
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP address is current, no update performed.";
962
							$successful_update = true;
963
							break;
964
						case 1:
965
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS hostname update successful.";
966
							$successful_update = true;
967
							break;
968
						case 2:
969
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not exist.";
970
							break;
971
						case 3:
972
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Username.";
973
							break;
974
						case 4:
975
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Password.";
976
							break;
977
						case 5:
978
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too many updates sent.";
979
							break;
980
						case 6:
981
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account disabled due to violation of No-IP terms of service.";
982
							break;
983
						case 7:
984
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
985
							break;
986
						case 8:
987
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Disabled / Locked Hostname.";
988
							break;
989
						case 9:
990
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Host updated is configured as a web redirect and no update was performed.";
991
							break;
992
						case 10:
993
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Group supplied does not exist.";
994
							break;
995
						case 11:
996
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group update is successful.";
997
							$successful_update = true;
998
							break;
999
						case 12:
1000
							$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group is current, no update performed.";
1001
							$successful_update = true;
1002
							break;
1003
						case 13:
1004
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update client support not available for supplied hostname or group.";
1005
							break;
1006
						case 14:
1007
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not have offline settings configured.";
1008
							break;
1009
						case 99:
1010
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
1011
							break;
1012
						case 100:
1013
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
1014
							break;
1015
						default:
1016
							$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1017
							$this->_debug("Unknown Response: ".$data);
1018
							break;
1019
					}
1020
					break;
1021
				case 'easydns':
1022
					if (preg_match('/NOACCESS/i', $data)) {
1023
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Authentication Failed: Username and/or Password was Incorrect.";
1024
					} else if (preg_match('/NOSERVICE/i', $data)) {
1025
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
1026
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
1027
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Illegal Input: Self-Explanatory";
1028
					} else if (preg_match('/TOOSOON/i', $data)) {
1029
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
1030
					} else if (preg_match('/NOERROR/i', $data)) {
1031
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Updated Successfully!";
1032
						$successful_update = true;
1033
					} else {
1034
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1035
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1036
						$this->_debug($data);
1037
					}
1038
					break;
1039
				case 'hn':
1040
					/* FIXME: add checks */
1041
					break;
1042
				case 'zoneedit':
1043
					if (preg_match('/799/i', $data)) {
1044
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 799) Update Failed!";
1045
					} else if (preg_match('/700/i', $data)) {
1046
						$status = "phpDynDNS ({$this->_dnsHost}): (Error 700) Update Failed!";
1047
					} else if (preg_match('/200/i', $data)) {
1048
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1049
						$successful_update = true;
1050
					} else if (preg_match('/201/i', $data)) {
1051
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1052
						$successful_update = true;
1053
					} else {
1054
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1055
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1056
						$this->_debug($data);
1057
					}
1058
					break;
1059
				case 'dyns':
1060
					if (preg_match("/400/i", $data)) {
1061
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
1062
					} else if (preg_match('/402/i', $data)) {
1063
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update Too Soon - You have tried updating to quickly since last change.";
1064
					} else if (preg_match('/403/i', $data)) {
1065
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Database Error - There was a server-sided database error.";
1066
					} else if (preg_match('/405/i', $data)) {
1067
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
1068
					} else if (preg_match('/200/i', $data)) {
1069
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1070
						$successful_update = true;
1071
					} else {
1072
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1073
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1074
						$this->_debug($data);
1075
					}
1076
					break;
1077
				case 'ods':
1078
					if (preg_match("/299/i", $data)) {
1079
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1080
						$successful_update = true;
1081
					} else {
1082
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1083
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1084
						$this->_debug($data);
1085
					}
1086
					break;
1087
				case 'freedns':
1088
					if (preg_match("/has not changed./i", $data)) {
1089
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
1090
						$successful_update = true;
1091
					} else if (preg_match("/Updated/i", $data)) {
1092
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
1093
						$successful_update = true;
1094
					} else {
1095
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1096
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1097
						$this->_debug($data);
1098
					}
1099
					break;
1100
				case 'dnsexit':
1101
					if (preg_match("/is the same/i", $data)) {
1102
						$status = "phpDynDns ({$this->_dnsHost}): (Success) No Change In IP Address";
1103
						$successful_update = true;
1104
					} else if (preg_match("/Success/i", $data)) {
1105
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
1106
						$successful_update = true;
1107
					} else {
1108
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1109
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1110
						$this->_debug($data);
1111
					}
1112
					break;
1113
				case 'loopia':
1114
					if (preg_match("/nochg/i", $data)) {
1115
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
1116
						$successful_update = true;
1117
					} else if (preg_match("/good/i", $data)) {
1118
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
1119
						$successful_update = true;
1120
					} else if (preg_match('/badauth/i', $data)) {
1121
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
1122
					} else {
1123
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1124
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1125
						$this->_debug($data);
1126
					}
1127
					break;
1128
				case 'opendns':
1129
					if (preg_match('/badauth/i', $data)) {
1130
						$status = "phpDynDNS({$this->_dnsHost}): (Error) Not a valid username or password!";
1131
					} else if (preg_match('/nohost/i', $data)) {
1132
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname you are trying to update does not exist.";
1133
						$successful_update = true;
1134
					} else if (preg_match('/good/i', $data)) {
1135
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
1136
						$successful_update = true;
1137
					} else if (preg_match('/yours/i', $data)) {
1138
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) hostname specified exists, but not under the username specified.";
1139
					} else if (preg_match('/abuse/i', $data)) {
1140
						$status = "phpDynDns ({$this->_dnsHost}): (Error) Updating too frequently, considered abuse.";
1141
					} else {
1142
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1143
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1144
						$this->_debug($data);
1145
					}
1146
					break;
1147
				case 'staticcling':
1148
					if (preg_match("/invalid ip/i", $data)) {
1149
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The IP provided was invalid.";
1150
					} else if (preg_match('/required info missing/i', $data)) {
1151
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Required parameters were not provided.";
1152
					} else if (preg_match('/invalid characters/i', $data)) {
1153
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Illegal characters in either the username or the password.";
1154
					} else if (preg_match('/bad password/i', $data)) {
1155
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid password.";
1156
					} else if (preg_match('/account locked/i', $data)) {
1157
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) This account has been administratively locked.";
1158
					} else if (preg_match('/update too frequent/i', $data)) {
1159
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Updating too frequently.";
1160
					} else if (preg_match('/DB error/i', $data)) {
1161
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Server side error.";
1162
					} else if (preg_match('/success/i', $data)) {
1163
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1164
						$successful_update = true;
1165
					} else {
1166
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1167
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1168
						$this->_debug($data);
1169
					}
1170
					break;
1171
				case 'namecheap':
1172
					$tmp = str_replace("^M", "", $data);
1173
					$ncresponse = @xml2array($tmp);
1174
					if (preg_match("/internal server error/i", $data)) {
1175
						$status = "phpDynDNS: (Error) Server side error.";
1176
					} else if (preg_match("/request is badly formed/i", $data)) {
1177
						$status = "phpDynDNS: (Error) Badly Formed Request (check your settings).";
1178
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1179
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1180
						$successful_update = true;
1181
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1182
						$status = "phpDynDNS: (Error) " . implode(", ", $ncresponse["interface-response"]["errors"]);
1183
						$successful_update = true;
1184
					} else {
1185
						$status = "phpDynDNS: (Unknown Response)";
1186
						log_error("phpDynDNS: PAYLOAD: {$data}");
1187
						$this->_debug($data);
1188
					}
1189
					break;
1190

    
1191
				case 'he-net':
1192
				case 'he-net-v6':
1193
					if (preg_match("/badip/i", $data)) {
1194
						$status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
1195
					} else if (preg_match('/nohost/i', $data)) {
1196
						$status = "phpDynDNS: (Error) Bad Request - A hostname was not provided.";
1197
					} else if (preg_match('/badauth/i', $data)) {
1198
						$status = "phpDynDNS: (Error) Invalid username or password.";
1199
					} else if (preg_match('/good/i', $data)) {
1200
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1201
						$successful_update = true;
1202
					} else if (preg_match('/nochg/i', $data)) {
1203
						$status = "phpDynDNS: (Success) No Change In IP Address.";
1204
						$successful_update = true;
1205
					} else {
1206
						$status = "phpDynDNS: (Unknown Response)";
1207
						log_error("phpDynDNS: PAYLOAD: {$data}");
1208
						$this->_debug($data);
1209
					}
1210
					break;
1211
				case 'he-net-tunnelbroker':
1212
					/*
1213
					-ERROR: Missing parameter(s).
1214
					-ERROR: Invalid API key or password
1215
					-ERROR: Tunnel not found
1216
					-ERROR: Another tunnel exists for this IP.
1217
					-ERROR: This tunnel is already associated with this IP address
1218
					+OK: Tunnel endpoint updated to: x.x.x.x
1219
					*/
1220
					if (preg_match("/Missing parameter/i", $data)) {
1221
						$status = "phpDynDNS: (Error) Bad Request - Missing/Invalid Parameters.";
1222
					} else if (preg_match('/Tunnel not found/i', $data)) {
1223
						$status = "phpDynDNS: (Error) Bad Request - Invalid Tunnel ID.";
1224
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1225
						$status = "phpDynDNS: (Error) Invalid username or password.";
1226
					} else if (preg_match('/OK:/i', $data)) {
1227
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1228
						$successful_update = true;
1229
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1230
						$status = "phpDynDNS: (Success) No Change In IP Address.";
1231
						$successful_update = true;
1232
					} else {
1233
						$status = "phpDynDNS: (Unknown Response)";
1234
						log_error("phpDynDNS: PAYLOAD: {$data}");
1235
						$this->_debug($data);
1236
					}
1237
					break;
1238
				case 'selfhost':
1239
					if (preg_match('/notfqdn/i', $data)) {
1240
						$status = "phpDynDNS: (Error) Not A FQDN!";
1241
					} else if (preg_match('/nochg/i', $data)) {
1242
						$status = "phpDynDNS: (Success) No Change In IP Address";
1243
						$successful_update = true;
1244
					} else if (preg_match('/good/i', $data)) {
1245
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
1246
						$successful_update = true;
1247
					} else if (preg_match('/noauth/i', $data)) {
1248
						$status = "phpDynDNS: (Error) User Authorization Failed";
1249
					} else {
1250
						$status = "phpDynDNS: (Unknown Response)";
1251
						log_error("phpDynDNS: PAYLOAD: {$data}");
1252
						$this->_debug($data);
1253
					}
1254
					break;
1255
				case 'route53':
1256
					$successful_update = true;
1257
					break;
1258
				case 'custom':
1259
				case 'custom-v6':
1260
					$successful_update = false;
1261
					if ($this->_dnsResultMatch == "") {
1262
						$successful_update = true;
1263
					} else {
1264
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1265
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1266
						foreach ($matches as $match) {
1267
							$match= str_replace("\\|", "|", $match);
1268
							if (strcmp($match, trim($data, "\t\n\r")) == 0) {
1269
								$successful_update = true;
1270
							}
1271
						}
1272
						unset ($matches);
1273
					}
1274
					if ($successful_update == true) {
1275
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1276
					} else {
1277
						$status = "phpDynDNS: (Error) Result did not match. [$data]";
1278
					}
1279
					break;
1280
				case 'cloudflare':
1281
					$output = json_decode($data);
1282
					if ($output->result->content === $this->_dnsIP){
1283
						$status = "DynDNS: (Success) {$this->_dnsHost} updated to {$this->_dnsIP}";
1284
						$successful_update = true;
1285
					}
1286
					elseif ($output->errors[0]->code === 9103){
1287
						$status = "DynDNS ({$this->_dnsHost}): ERROR - Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.";
1288
					}
1289
					elseif (($output->success) && (!$output->result[0]->id)) {
1290
						$status = "DynDNS ({$this->_dnsHost}): ERROR - Zone or Host ID was not found, check your hostname.";
1291
					}
1292
					else {
1293
						$status = "DynDNS ({$this->_dnsHost}): UNKNOWN ERROR - {$output->errors[0]->message}";
1294
						log_error("DynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1295
					}
1296
					break;
1297
				case 'eurodns':
1298
					if (preg_match('/notfqdn/i', $data)) {
1299
						$status = "phpDynDNS: (Error) Not A FQDN!";
1300
					} else if (preg_match('/nochg/i', $data)) {
1301
						$status = "phpDynDNS: (Success) No Change In IP Address";
1302
						$successful_update = true;
1303
					} else if (preg_match('/good/i', $data)) {
1304
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
1305
						$successful_update = true;
1306
					} else if (preg_match('/badauth/i', $data)) {
1307
						$status = "phpDynDNS: (Error) User Authorization Failed";
1308
					} else {
1309
						$status = "phpDynDNS: (Unknown Response)";
1310
						log_error("phpDynDNS: PAYLOAD: {$data}");
1311
						$this->_debug($data);
1312
					}
1313
					break;
1314
				case 'gratisdns':
1315
					if (preg_match('/Forkerte værdier/i', $data)) {
1316
						$status = "phpDynDNS: (Error) Wrong values - Update could not be completed.";
1317
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1318
						$status = "phpDynDNS: (Error) Unknown username - User does not exist.";
1319
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1320
						$status = "phpDynDNS: (Error) Wrong password - Remember password is case sensitive.";
1321
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1322
						$status = "phpDynDNS: (Error) User unable to administer the selected domain.";
1323
					} else if (preg_match('/OK/i', $data)) {
1324
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
1325
						$successful_update = true;
1326
					} else {
1327
						$status = "phpDynDNS: (Unknown Response)";
1328
						log_error("phpDynDNS: PAYLOAD: {$data}");
1329
						$this->_debug($data);
1330
					}
1331
					break;
1332
				case 'dnsimple':
1333
					/* Responds with HTTP 200 on success.
1334
					   Responds with HTTP 4xx on error.
1335
					   Returns JSON data as body */
1336
					$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1337
					$header = substr($data, 0, $header_size);
1338
					$body = substr($data, $header_size);
1339
					if (preg_match("/Status: 200\s/i", $header)) {
1340
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
1341
						$successful_update = true;
1342
					} else if (preg_match("/Status: 4\d\d\s/i", $header)) {
1343
						$arrbody = json_decode($body, true);
1344
						$message = $arrbody['message'] . ".";
1345
						if (isset($arrbody['errors']['content'])) {
1346
							foreach ($arrbody['errors']['content'] as $key => $content) {
1347
								$message .= " " . $content . ".";
1348
							}
1349
						}
1350
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) " . $message;
1351
					} else {
1352
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1353
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$body}");
1354
						$this->_debug($body);
1355
					}
1356
					break;
1357
				case 'googledomains':
1358
					if (preg_match('/notfqdn/i', $data)) {
1359
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN";
1360
					} else if (preg_match('/nochg/i', $data)) {
1361
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
1362
						$successful_update = true;
1363
					} else if (preg_match('/good/i', $data)) {
1364
						$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
1365
						$successful_update = true;
1366
					} else if (preg_match('/badauth/i', $data)) {
1367
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
1368
					} else if (preg_match('/nohost/i', $data)) {
1369
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname does not exist or DynDNS not enabled";
1370
					} else if (preg_match('/badagent/i', $data)) {
1371
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad request";
1372
					} else if (preg_match('/abuse/i', $data)) {
1373
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Dynamic DNS access has been blocked!";
1374
					} else if (preg_match('/911/i', $data)) {
1375
						$status = "phpDynDNS ({$this->_dnsHost}): (Error) Error on Google's end, retry in 5 minutes";
1376
					} else {
1377
						$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1378
						log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1379
						$this->_debug($data);
1380
					}
1381
					break;
1382
				case 'dnsmadeeasy':
1383
					switch ($data) {
1384
						case 'success':
1385
							$status = "phpDynDNS({$this->_dnsHost}): (Success) IP Address Changed Successfully! (" . $this->_dnsIP . ")";
1386
							$successful_update = true;
1387
							break;
1388
						case 'error-auth':
1389
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid username or password";
1390
							break;
1391
						case 'error-auth-suspend':
1392
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account suspended";
1393
							break;
1394
						case 'error-auth-voided':
1395
							$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account revoked";
1396
							break;
1397
						case 'error-record-invalid':
1398
							$status = "phpDynDns ({$this->_dnsHost}): (Error) Record does not exist in the system. Unable to update record";
1399
							break;
1400
						case 'error-record-auth':
1401
							$status = "phpDynDns ({$this->_dnsHost}): (Error) User does not have access to this record";
1402
							break;
1403
						case 'error-record-ip-same':
1404
							$status = "phpDynDns ({$this->_dnsHost}): (Success) No change in IP Address";
1405
							$successful_update = true;
1406
							break;
1407
						case 'error-system':
1408
							$status = "phpDynDns ({$this->_dnsHost}): (Error) General system error recognized by the system";
1409
							break;
1410
						case 'error':
1411
							$status = "phpDynDns ({$this->_dnsHost}): (Error) General system error unrecognized by the system";
1412
							break;
1413
						default:
1414
							$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
1415
							log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
1416
							$this->_debug($data);
1417
							break;
1418
					}
1419
					break;
1420
			}
1421

    
1422
			if ($successful_update == true) {
1423
				/* Write WAN IP to cache file */
1424
				$wan_ip = $this->_checkIP();
1425
				conf_mount_rw();
1426
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1427
					$currentTime = time();
1428
					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));
1429
					log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
1430
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1431
				} else {
1432
					@unlink($this->_cacheFile);
1433
				}
1434
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1435
					$currentTime = time();
1436
					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));
1437
					log_error("phpDynDNS: updating cache file {$this->_cacheFile_v6}: {$wan_ip}");
1438
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1439
				} else {
1440
					@unlink($this->_cacheFile_v6);
1441
				}
1442
				conf_mount_ro();
1443
			}
1444
			$this->status = $status;
1445
			log_error($status);
1446
		}
1447

    
1448
		/*
1449
		 * Private Function (added 12 July 05) [beta]
1450
		 *   Return Error, Set Last Error, and Die.
1451
		 */
1452
		function _error($errorNumber = '1') {
1453
			switch ($errorNumber) {
1454
				case 0:
1455
					break;
1456
				case 2:
1457
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
1458
					break;
1459
				case 3:
1460
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
1461
					break;
1462
				case 4:
1463
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
1464
					break;
1465
				case 5:
1466
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
1467
					break;
1468
				case 6:
1469
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
1470
					break;
1471
				case 7:
1472
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
1473
					break;
1474
				case 8:
1475
					$status = "Route 53: (Error) Invalid ZoneID";
1476
					break;
1477
				case 9:
1478
					$status = "Route 53: (Error) Invalid TTL";
1479
					break;
1480
				case 10:
1481
					$error = "phpDynDNS ({$this->_dnsHost}): No change in my IP address and/or " . $this->_dnsMaxCacheAgeDays . " days has not passed. Not updating dynamic DNS entry.";
1482
					break;
1483
				default:
1484
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
1485
					/* FIXME: $data isn't in scope here */
1486
					/* $this->_debug($data); */
1487
					break;
1488
			}
1489
			$this->lastError = $error;
1490
			log_error($error);
1491
		}
1492

    
1493
		/*
1494
		 * Private Function (added 12 July 05) [beta]
1495
		 *   - Detect whether or not IP needs to be updated.
1496
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1497
		 *      | work with other systems. pfSense base is FreeBSD.
1498
		 */
1499
		function _detectChange() {
1500
			global $debug;
1501

    
1502
			if ($debug) {
1503
				log_error("DynDns ({$this->_dnsHost}): _detectChange() starting.");
1504
			}
1505

    
1506
			$currentTime = time();
1507

    
1508
			$wan_ip = $this->_checkIP();
1509
			if ($wan_ip == 0) {
1510
				log_error("DynDns ({$this->_dnsHost}): Current WAN IP could not be determined, skipping update process.");
1511
				return false;
1512
			}
1513
			$log_error = "DynDns ({$this->_dnsHost}): Current WAN IP: {$wan_ip} ";
1514

    
1515
			if ($this->_useIPv6 == true) {
1516
				if (file_exists($this->_cacheFile_v6)) {
1517
					$contents = file_get_contents($this->_cacheFile_v6);
1518
					list($cacheIP, $cacheTime) = explode('|', $contents);
1519
					$this->_debug($cacheIP.'/'.$cacheTime);
1520
					$initial = false;
1521
					$log_error .= "Cached IPv6: {$cacheIP} ";
1522
				} else {
1523
					conf_mount_rw();
1524
					$cacheIP = '::';
1525
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1526
					conf_mount_ro();
1527
					$cacheTime = $currentTime;
1528
					$initial = true;
1529
					$log_error .= "No Cached IPv6 found.";
1530
				}
1531
			} else {
1532
				if (file_exists($this->_cacheFile)) {
1533
					$contents = file_get_contents($this->_cacheFile);
1534
					list($cacheIP, $cacheTime) = explode(':', $contents);
1535
					$this->_debug($cacheIP.'/'.$cacheTime);
1536
					$initial = false;
1537
					$log_error .= "Cached IP: {$cacheIP} ";
1538
				} else {
1539
					conf_mount_rw();
1540
					$cacheIP = '0.0.0.0';
1541
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1542
					conf_mount_ro();
1543
					$cacheTime = $currentTime;
1544
					$initial = true;
1545
					$log_error .= "No Cached IP found.";
1546
				}
1547
			}
1548
			if ($this->_dnsVerboseLog) {
1549
				log_error($log_error);
1550
			}
1551

    
1552
			// Convert seconds = days * hr/day * min/hr * sec/min
1553
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1554

    
1555
			$needs_updating = FALSE;
1556
			/* lets determine if the item needs updating */
1557
			if ($cacheIP != $wan_ip) {
1558
				$needs_updating = true;
1559
				$update_reason = "DynDns: cacheIP != wan_ip.  Updating. ";
1560
				$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
1561
			}
1562
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1563
				$needs_updating = true;
1564
				$this->_forceUpdateNeeded = true;
1565
				$update_reason = "DynDns: More than " . $this->_dnsMaxCacheAgeDays . " days.  Updating. ";
1566
				$update_reason .= "{$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1567
			}
1568
			if ($initial == true) {
1569
				$needs_updating = true;
1570
				$update_reason .= "Initial update. ";
1571
			}
1572

    
1573
			/*   finally if we need updating then store the
1574
			 *   new cache value and return true
1575
			 */
1576
			if ($needs_updating == true) {
1577
				if ($this->_dnsVerboseLog) {
1578
					log_error("DynDns ({$this->_dnsHost}): {$update_reason}");
1579
				}
1580
				return true;
1581
			}
1582

    
1583
			return false;
1584
		}
1585

    
1586
		/*
1587
		 * Private Function (added 16 July 05) [beta]
1588
		 *   - Writes debug information to a file.
1589
		 *   - This function is only called when a unknown response
1590
		 *   - status is returned from a DynDNS service provider.
1591
		 */
1592
		function _debug($data) {
1593
			global $g;
1594

    
1595
			if (!$g['debug']) {
1596
				return;
1597
			}
1598
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1599
			conf_mount_rw();
1600
			$file = fopen($this->_debugFile, 'a');
1601
			fwrite($file, $string);
1602
			fclose($file);
1603
			conf_mount_ro();
1604
		}
1605
		function _checkIP() {
1606
			global $debug;
1607

    
1608
			if ($debug) {
1609
				log_error("DynDns ({$this->_dnsHost}): _checkIP() starting.");
1610
			}
1611

    
1612
			if ($this->_useIPv6 == true) {
1613
				$ip_address = find_interface_ipv6($this->_if);
1614
				if (!is_ipaddrv6($ip_address)) {
1615
					return 0;
1616
				}
1617
			} else {
1618
				$ip_address = find_interface_ip($this->_if);
1619
				if (!is_ipaddr($ip_address)) {
1620
					return 0;
1621
				}
1622
			}
1623
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1624
				$hosttocheck = "checkip.dyndns.org";
1625
				$try = 0;
1626
				while ($try < 3) {
1627
					$checkip = gethostbyname($hosttocheck);
1628
					if (is_ipaddr($checkip)) {
1629
						break;
1630
					}
1631
					$try++;
1632
				}
1633
				if ($try >= 3) {
1634
					log_error("Dyndns debug information ({$this->_dnsHost}): Could not resolve {$hosttocheck} to IP using interface IP {$ip_address}.");
1635
					return 0;
1636
				}
1637
				$ip_ch = curl_init("http://{$checkip}");
1638
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1639
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1640
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1641
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1642
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1643
				if ($this->_useIPv6 == false) {
1644
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1645
				}
1646
				$ip_result_page = curl_exec($ip_ch);
1647
				curl_close($ip_ch);
1648
				$ip_result_decoded = urldecode($ip_result_page);
1649
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1650
				$ip_address = trim($matches[1]);
1651
				if (is_ipaddr($ip_address)) {
1652
					if ($this->_dnsVerboseLog) {
1653
						log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from {$hosttocheck}");
1654
					}
1655
				} else {
1656
					log_error("DynDns ({$this->_dnsHost}): IP address could not be extracted from {$hosttocheck}");
1657
					return 0;
1658
				}
1659
			} else {
1660
				if ($this->_dnsVerboseLog) {
1661
					log_error("DynDns ({$this->_dnsHost}): {$ip_address} extracted from local system.");
1662
				}
1663
			}
1664
			$this->_dnsIP = $ip_address;
1665

    
1666
			return $ip_address;
1667
		}
1668

    
1669
	}
1670

    
1671
?>
(16-16/65)