Project

General

Profile

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

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

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

    
148
			global $config, $g;
149

    
150
			if ($dnsService == "namecheap") {
151
				$this->_FQDN = $dnsHost . "." . $dnsDomain;
152
			} else {
153
				$this->_FQDN = $dnsHost;
154
			}
155

    
156
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.cache";
157
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}_v6.cache";
158
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.debug";
159

    
160
			$this->_curlIpresolveV4 = $curlIpresolveV4;
161
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
162
			$this->_dnsVerboseLog = $dnsVerboseLog;
163
			if ($this->_dnsVerboseLog) {
164
				log_error("DynDns: updatedns() starting");
165
			}
166

    
167
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
168

    
169
			if (!$dnsService) $this->_error(2);
170
			switch ($dnsService) {
171
			case 'freedns':
172
				if (!$dnsHost) $this->_error(5);
173
				break;
174
			case 'namecheap':
175
				if (!$dnsPass) $this->_error(4);
176
				if (!$dnsHost) $this->_error(5);
177
				if (!$dnsDomain) $this->_error(5);
178
				break;
179
			case 'route53':
180
				if (!$dnsZoneID) $this->_error(8);
181
				if (!$dnsTTL) $this->_error(9);
182
				break;
183
			case 'custom':
184
				if (!$dnsUpdateURL) $this->_error(7);
185
				break;
186
			default:
187
				if (!$dnsUser) $this->_error(3);
188
				if (!$dnsPass) $this->_error(4);
189
				if (!$dnsHost) $this->_error(5);
190
			}
191

    
192
			switch ($dnsService) {
193
				case 'he-net-v6':
194
				case 'custom-v6':
195
				case 'spdns-v6':
196
					$this->_useIPv6 = true;
197
					break;
198
				default:
199
					$this->_useIPv6 = false;
200
			}
201
			$this->_dnsService = strtolower($dnsService);
202
			$this->_dnsUser = $dnsUser;
203
			$this->_dnsPass = $dnsPass;
204
			$this->_dnsHost = $dnsHost;
205
			$this->_dnsDomain = $dnsDomain;
206
			$this->_dnsServer = $dnsServer;
207
			$this->_dnsPort = $dnsPort;
208
			$this->_dnsWildcard = $dnsWildcard;
209
			$this->_dnsMX = $dnsMX;
210
			$this->_dnsZoneID = $dnsZoneID;
211
			$this->_dnsTTL = $dnsTTL;
212
			$this->_if = get_failover_interface($dnsIf);
213
			$this->_checkIP();
214
			$this->_dnsUpdateURL = $dnsUpdateURL;
215
			$this->_dnsResultMatch = $dnsResultMatch;
216
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
217
			if ($this->_dnsVerboseLog) {
218
				log_error("DynDNS ({$this->_FQDN}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}");
219
			}
220
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
221
			$this->_dnsMaxCacheAgeDays = 25;
222
			$this->_dnsDummyUpdateDone = false;
223
			$this->_forceUpdateNeeded = $forceUpdate;
224

    
225
			// Ensure that we were able to lookup the IP
226
			if (!is_ipaddr($this->_dnsIP)) {
227
				log_error("DynDNS ({$this->_FQDN}) There was an error trying to determine the public IP for interface - {$dnsIf}({$this->_if}). Probably interface is not a WAN interface.");
228
				unlock($dyndnslck);
229
				return;
230
			}
231

    
232
			$this->_debugID = rand(1000000, 9999999);
233

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

    
290
			unlock($dyndnslck);
291
		}
292

    
293
		/*
294
		 * Private Function (added 12 July 05) [beta]
295
		 *   Send Update To Selected Service.
296
		 */
297
		function _update() {
298

    
299
			if ($this->_dnsVerboseLog) {
300
				log_error("DynDNS ({$this->_FQDN}): DynDns _update() starting.");
301
			}
302

    
303
			if (strstr($this->_dnsRequestIf, "_vip")) {
304
				$parentif = link_carp_interface_to_parent($this->_dnsRequestIf);
305
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
306
			} else {
307
				$realparentif = $this->_dnsRequestIf;
308
			}
309

    
310
			$ch = curl_init();
311

    
312
			if ($this->_useIPv6 == false) {
313
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
314
			}
315

    
316
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
317
				curl_setopt($ch, CURLOPT_HEADER, 0);
318
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
319
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
320
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
321
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
322
			}
323

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

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

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

    
619
					/* Setting Variables */
620
					$hostname = "{$this->_dnsHost}.";
621
					$ZoneID = $this->_dnsZoneID;
622
					$AccessKeyId = $this->_dnsUser;
623
					$SecretAccessKey = $this->_dnsPass;
624
					$NewIP = $this->_dnsIP;
625
					$NewTTL = $this->_dnsTTL;
626

    
627
					/* Include Route 53 Library Class */
628
					require_once('/etc/inc/r53.class');
629

    
630
					/* Set Amazon AWS Credentials for this record */
631
					$r53 = new Route53($AccessKeyId, $SecretAccessKey);
632

    
633
					/* Function to find old values of records in Route 53 */
634
					if (!function_exists('Searchrecords')) {
635
						function SearchRecords($records, $name) {
636
							$result = array();
637
							foreach ($records as $record) {
638
								if (strtolower($record['Name']) == strtolower($name)) {
639
									$result [] = $record;
640
								}
641
							}
642
							return ($result) ? $result : false;
643
						}
644
					}
645

    
646
					$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
647

    
648
					/* Get IP for your hostname in Route 53 */
649
					if (false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
650
						$OldTTL = $a_result[0][TTL];
651
						$OldIP = $a_result[0][ResourceRecords][0];
652
					} else {
653
						$OldIP = "";
654
					}
655

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

    
703
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
704
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
705
						'X-Auth-Email: '.$this->_dnsUser.'',
706
						'X-Auth-Key: '.$this->_dnsPass.'',
707
						'Content-Type: application/json'
708
					));
709

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

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

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

    
1466
			if ($successful_update == true) {
1467
				/* Write WAN IP to cache file */
1468
				$wan_ip = $this->_checkIP();
1469
				conf_mount_rw();
1470
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1471
					$currentTime = time();
1472
					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));
1473
					log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
1474
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1475
				} else {
1476
					@unlink($this->_cacheFile);
1477
				}
1478
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1479
					$currentTime = time();
1480
					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));
1481
					log_error("phpDynDNS: updating cache file {$this->_cacheFile_v6}: {$wan_ip}");
1482
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1483
				} else {
1484
					@unlink($this->_cacheFile_v6);
1485
				}
1486
				conf_mount_ro();
1487
			}
1488
			$this->status = $status;
1489
			log_error($status);
1490
		}
1491

    
1492
		/*
1493
		 * Private Function (added 12 July 05) [beta]
1494
		 *   Return Error, Set Last Error, and Die.
1495
		 */
1496
		function _error($errorNumber = '1') {
1497
			switch ($errorNumber) {
1498
				case 0:
1499
					break;
1500
				case 2:
1501
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
1502
					break;
1503
				case 3:
1504
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
1505
					break;
1506
				case 4:
1507
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
1508
					break;
1509
				case 5:
1510
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
1511
					break;
1512
				case 6:
1513
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
1514
					break;
1515
				case 7:
1516
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
1517
					break;
1518
				case 8:
1519
					$status = "Route 53: (Error) Invalid ZoneID";
1520
					break;
1521
				case 9:
1522
					$status = "Route 53: (Error) Invalid TTL";
1523
					break;
1524
				case 10:
1525
					$error = "phpDynDNS ({$this->_FQDN}): No change in my IP address and/or " . $this->_dnsMaxCacheAgeDays . " days has not passed. Not updating dynamic DNS entry.";
1526
					break;
1527
				default:
1528
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
1529
					/* FIXME: $data isn't in scope here */
1530
					/* $this->_debug($data); */
1531
					break;
1532
			}
1533
			$this->lastError = $error;
1534
			log_error($error);
1535
		}
1536

    
1537
		/*
1538
		 * Private Function (added 12 July 05) [beta]
1539
		 *   - Detect whether or not IP needs to be updated.
1540
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1541
		 *      | work with other systems. pfSense base is FreeBSD.
1542
		 */
1543
		function _detectChange() {
1544
			global $debug;
1545

    
1546
			if ($debug) {
1547
				log_error("DynDns ({$this->_FQDN}): _detectChange() starting.");
1548
			}
1549

    
1550
			$currentTime = time();
1551

    
1552
			$wan_ip = $this->_checkIP();
1553
			if ($wan_ip == 0) {
1554
				log_error("DynDns ({$this->_FQDN}): Current WAN IP could not be determined, skipping update process.");
1555
				return false;
1556
			}
1557
			$log_error = "DynDns ({$this->_FQDN}): Current WAN IP: {$wan_ip} ";
1558

    
1559
			if ($this->_useIPv6 == true) {
1560
				if (file_exists($this->_cacheFile_v6)) {
1561
					$contents = file_get_contents($this->_cacheFile_v6);
1562
					list($cacheIP, $cacheTime) = explode('|', $contents);
1563
					$this->_debug($cacheIP.'/'.$cacheTime);
1564
					$initial = false;
1565
					$log_error .= "Cached IPv6: {$cacheIP} ";
1566
				} else {
1567
					conf_mount_rw();
1568
					$cacheIP = '::';
1569
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1570
					conf_mount_ro();
1571
					$cacheTime = $currentTime;
1572
					$initial = true;
1573
					$log_error .= "No Cached IPv6 found.";
1574
				}
1575
			} else {
1576
				if (file_exists($this->_cacheFile)) {
1577
					$contents = file_get_contents($this->_cacheFile);
1578
					list($cacheIP, $cacheTime) = explode(':', $contents);
1579
					$this->_debug($cacheIP.'/'.$cacheTime);
1580
					$initial = false;
1581
					$log_error .= "Cached IP: {$cacheIP} ";
1582
				} else {
1583
					conf_mount_rw();
1584
					$cacheIP = '0.0.0.0';
1585
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1586
					conf_mount_ro();
1587
					$cacheTime = $currentTime;
1588
					$initial = true;
1589
					$log_error .= "No Cached IP found.";
1590
				}
1591
			}
1592
			if ($this->_dnsVerboseLog) {
1593
				log_error($log_error);
1594
			}
1595

    
1596
			// Convert seconds = days * hr/day * min/hr * sec/min
1597
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1598

    
1599
			$needs_updating = FALSE;
1600
			/* lets determine if the item needs updating */
1601
			if ($cacheIP != $wan_ip) {
1602
				$needs_updating = true;
1603
				$update_reason = "DynDns: cacheIP != wan_ip.  Updating. ";
1604
				$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
1605
			}
1606
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1607
				$needs_updating = true;
1608
				$this->_forceUpdateNeeded = true;
1609
				$update_reason = "DynDns: More than " . $this->_dnsMaxCacheAgeDays . " days.  Updating. ";
1610
				$update_reason .= "{$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1611
			}
1612
			if ($initial == true) {
1613
				$needs_updating = true;
1614
				$update_reason .= "Initial update. ";
1615
			}
1616

    
1617
			/*   finally if we need updating then store the
1618
			 *   new cache value and return true
1619
			 */
1620
			if ($needs_updating == true) {
1621
				if ($this->_dnsVerboseLog) {
1622
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1623
				}
1624
				return true;
1625
			}
1626

    
1627
			return false;
1628
		}
1629

    
1630
		/*
1631
		 * Private Function (added 16 July 05) [beta]
1632
		 *   - Writes debug information to a file.
1633
		 *   - This function is only called when a unknown response
1634
		 *   - status is returned from a DynDNS service provider.
1635
		 */
1636
		function _debug($data) {
1637
			global $g;
1638

    
1639
			if (!$g['debug']) {
1640
				return;
1641
			}
1642
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1643
			conf_mount_rw();
1644
			$file = fopen($this->_debugFile, 'a');
1645
			fwrite($file, $string);
1646
			fclose($file);
1647
			conf_mount_ro();
1648
		}
1649
		function _checkIP() {
1650
			global $debug;
1651

    
1652
			if ($debug) {
1653
				log_error("DynDns ({$this->_FQDN}): _checkIP() starting.");
1654
			}
1655

    
1656
			if ($this->_useIPv6 == true) {
1657
				$ip_address = find_interface_ipv6($this->_if);
1658
				if (!is_ipaddrv6($ip_address)) {
1659
					return 0;
1660
				}
1661
			} else {
1662
				$ip_address = find_interface_ip($this->_if);
1663
				if (!is_ipaddr($ip_address)) {
1664
					return 0;
1665
				}
1666
			}
1667
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1668
				$hosttocheck = "checkip.dyndns.org";
1669
				$try = 0;
1670
				while ($try < 3) {
1671
					$checkip = gethostbyname($hosttocheck);
1672
					if (is_ipaddr($checkip)) {
1673
						break;
1674
					}
1675
					$try++;
1676
				}
1677
				if ($try >= 3) {
1678
					log_error("Dyndns debug information ({$this->_FQDN}): Could not resolve {$hosttocheck} to IP using interface IP {$ip_address}.");
1679
					return 0;
1680
				}
1681
				$ip_ch = curl_init("http://{$checkip}");
1682
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1683
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1684
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1685
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1686
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1687
				if ($this->_useIPv6 == false) {
1688
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1689
				}
1690
				$ip_result_page = curl_exec($ip_ch);
1691
				curl_close($ip_ch);
1692
				$ip_result_decoded = urldecode($ip_result_page);
1693
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1694
				$ip_address = trim($matches[1]);
1695
				if (is_ipaddr($ip_address)) {
1696
					if ($this->_dnsVerboseLog) {
1697
						log_error("DynDns ({$this->_FQDN}): {$ip_address} extracted from {$hosttocheck}");
1698
					}
1699
				} else {
1700
					log_error("DynDns ({$this->_FQDN}): IP address could not be extracted from {$hosttocheck}");
1701
					return 0;
1702
				}
1703
			} else {
1704
				if ($this->_dnsVerboseLog) {
1705
					log_error("DynDns ({$this->_FQDN}): {$ip_address} extracted from local system.");
1706
				}
1707
			}
1708
			$this->_dnsIP = $ip_address;
1709

    
1710
			return $ip_address;
1711
		}
1712

    
1713
	}
1714

    
1715
?>
(16-16/65)