Project

General

Profile

Download (71.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * dyndns.class
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52
 */
53

    
54
	/*
55
	 * PHP.updateDNS (pfSense version)
56
	 *
57
	 * +====================================================+
58
	 *  Services Supported:
59
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
60
	 *    - No-IP (no-ip.com)
61
	 *    - EasyDNS (easydns.com)
62
	 *    - DHS (www.dhs.org)
63
	 *    - HN (hn.org) -- incomplete checking!
64
	 *    - DynS (dyns.org)
65
	 *    - ZoneEdit (zoneedit.com)
66
	 *    - FreeDNS (freedns.afraid.org)
67
	 *    - FreeDNS IPv6 (freedns.afraid.org)
68
	 *    - Loopia (loopia.se)
69
	 *    - StaticCling (staticcling.org)
70
	 *    - DNSexit (dnsexit.com)
71
	 *    - OpenDNS (opendns.com)
72
	 *    - Namecheap (namecheap.com)
73
	 *    - HE.net (dns.he.net)
74
	 *    - HE.net IPv6 (dns.he.net)
75
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
76
	 *    - SelfHost (selfhost.de)
77
	 *    - Amazon Route 53 (aws.amazon.com)
78
	 *    - DNS-O-Matic (dnsomatic.com)
79
	 *    - Custom DDNS (any URL)
80
	 *    - Custom DDNS IPv6 (any URL)
81
	 *    - CloudFlare (www.cloudflare.com)
82
	 *    - CloudFlare IPv6 (www.cloudflare.com)
83
	 *    - Eurodns (eurodns.com)
84
	 *    - GratisDNS (gratisdns.dk)
85
	 *    - City Network (citynetwork.se)
86
	 *    - GleSYS (glesys.com)
87
	 *    - DNSimple (dnsimple.com)
88
	 *    - Google Domains (domains.google.com)
89
	 *    - DNS Made Easy (www.dnsmadeeasy.com)
90
	 *    - SPDYN (spdyn.de)
91
	 *    - SPDYN IPv6 (spdyn.de)
92
	 *    - All-Inkl (all-inkl.com)
93
	 *    - DuiaDNS (www.duiadns.net)
94
	 *    - DuiaDNS IPv6 (www.duiadns.net)
95
	 * +----------------------------------------------------+
96
	 *  Requirements:
97
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
98
	 * +----------------------------------------------------+
99
	 *  Public Functions
100
	 *    - updatedns()
101
	 *
102
	 *  Private Functions
103
	 *    - _update()
104
	 *    - _checkStatus()
105
	 *    - _error()
106
	 *    - _detectChange()
107
	 *    - _debug()
108
	 *    - _checkIP()
109
	 * +----------------------------------------------------+
110
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
111
	 *  DynDNS Static   - Last Tested: NEVER
112
	 *  DynDNS Custom   - Last Tested: NEVER
113
	 *  No-IP           - Last Tested: 20 July 2008
114
	 *  HN.org          - Last Tested: 12 July 2005
115
	 *  EasyDNS         - Last Tested: 20 July 2008
116
	 *  DHS             - Last Tested: 12 July 2005
117
	 *  ZoneEdit        - Last Tested: NEVER
118
	 *  Dyns            - Last Tested: NEVER
119
	 *  ODS             - Last Tested: 02 August 2005
120
	 *  FreeDNS         - Last Tested: 01 May 2016
121
	 *  FreeDNS IPv6    - Last Tested: 01 May 2016
122
	 *  Loopia          - Last Tested: NEVER
123
	 *  StaticCling     - Last Tested: 27 April 2006
124
	 *  DNSexit         - Last Tested: 20 July 2008
125
	 *  OpenDNS         - Last Tested: 4 August 2008
126
	 *  Namecheap       - Last Tested: 31 August 2010
127
	 *  HE.net          - Last Tested: 7 July 2013
128
	 *  HE.net IPv6     - Last Tested: 7 July 2013
129
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
130
	 *  SelfHost        - Last Tested: 26 December 2011
131
	 *  Amazon Route 53 - Last Tested: 30 August 2016 
132
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
133
	 *  CloudFlare      - Last Tested: 17 July 2016
134
	 *  CloudFlare IPv6 - Last Tested: 17 July 2016
135
	 *  Eurodns         - Last Tested: 27 June 2013
136
	 *  GratisDNS       - Last Tested: 15 August 2012
137
	 *  OVH DynHOST     - Last Tested: NEVER
138
	 *  City Network    - Last Tested: 13 November 2013
139
	 *  GleSYS          - Last Tested: 3 February 2015
140
	 *  DNSimple        - Last Tested: 09 February 2015
141
	 *  Google Domains  - Last Tested: 27 April 2015
142
	 *  DNS Made Easy   - Last Tested: 27 April 2015
143
	 *  SPDYN           - Last Tested: 02 July 2016
144
	 *  SPDYN IPv6      - Last Tested: 02 July 2016
145
	 *  All-Inkl        - Last Tested: 12 November 2016
146
	 *  DuiaDNS         - Last Tested: 25 November 2016
147
	 *  DuiaDNS IPv6    - Last Tested: 25 November 2016
148
	 * +====================================================+
149
	 *
150
	 * @author 	E.Kristensen
151
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
152
	 * @version 	0.8
153
	 * @updated	13 October 05 at 21:02:42 GMT
154
	 *
155
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
156
	 * Custom DNS support by Matt Corallo
157
	 *
158
	 */
159

    
160
	class updatedns {
161
		var $_cacheFile;
162
		var $_cacheFile_v6;
163
		var $_debugFile;
164
		var $_UserAgent = 'phpDynDNS/0.7';
165
		var $_errorVerbosity = 0;
166
		var $_dnsService;
167
		var $_dnsUser;
168
		var $_dnsPass;
169
		var $_dnsHost;
170
		var $_dnsDomain;
171
		var $_FQDN;
172
		var $_dnsIP;
173
		var $_dnsWildcard;
174
		var $_dnsMX;
175
		var $_dnsBackMX;
176
		var $_dnsServer;
177
		var $_dnsPort;
178
		var $_dnsUpdateURL;
179
		var $_dnsZoneID;
180
		var $_dnsTTL;
181
		var $status;
182
		var $_debugID;
183
		var $_if;
184
		var $_dnsResultMatch;
185
		var $_dnsRequestIf;
186
		var $_dnsRequestIfIP;
187
		var $_dnsVerboseLog;
188
		var $_curlIpresolveV4;
189
		var $_curlSslVerifypeer;
190
		var $_dnsMaxCacheAgeDays;
191
		var $_dnsDummyUpdateDone;
192
		var $_forceUpdateNeeded;
193
		var $_useIPv6;
194

    
195
		/*
196
		 * Public Constructor Function (added 12 July 05) [beta]
197
		 *   - Gets the dice rolling for the update.
198
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
199
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
200
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
201
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
202
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
203
		 */
204
		function updatedns ($dnsService = '', $dnsHost = '', $dnsDomain = '', $dnsUser = '', $dnsPass = '',
205
					$dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
206
					$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
207
					$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
208
					$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
209

    
210
			global $config, $g, $dyndns_split_domain_types;
211
			if (in_array($dnsService, $dyndns_split_domain_types)) {
212
				$this->_FQDN = $dnsHost . "." . $dnsDomain;
213
			} else {
214
				$this->_FQDN = $dnsHost;
215
			}
216

    
217
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.cache";
218
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}_v6.cache";
219
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.debug";
220

    
221
			$this->_curlIpresolveV4 = $curlIpresolveV4;
222
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
223
			$this->_dnsVerboseLog = $dnsVerboseLog;
224
			if ($this->_dnsVerboseLog) {
225
				log_error(gettext("Dynamic DNS: updatedns() starting"));
226
			}
227

    
228
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
229

    
230
			if (!$dnsService) $this->_error(2);
231
			switch ($dnsService) {
232
			case 'freedns':
233
			case 'freedns-v6':
234
				if (!$dnsHost) $this->_error(5);
235
				break;
236
			case "namecheap":
237
				if (!$dnsPass) $this->_error(4);
238
				if (!$dnsHost) $this->_error(5);
239
				if (!$dnsDomain) $this->_error(5);
240
				break;
241
			case "cloudflare-v6":
242
			case "cloudflare":
243
			case "gratisdns":
244
				if (!$dnsUser) $this->_error(3);
245
				if (!$dnsPass) $this->_error(4);
246
				if (!$dnsHost) $this->_error(5);
247
				if (!$dnsDomain) $this->_error(5);
248
				break;
249
			case 'route53':
250
				if (!$dnsZoneID) $this->_error(8);
251
				if (!$dnsTTL) $this->_error(9);
252
				break;
253
			case 'custom':
254
				if (!$dnsUpdateURL) $this->_error(7);
255
				break;
256
			default:
257
				if (!$dnsUser) $this->_error(3);
258
				if (!$dnsPass) $this->_error(4);
259
				if (!$dnsHost) $this->_error(5);
260
			}
261

    
262
			switch ($dnsService) {
263
				case 'he-net-v6':
264
				case 'custom-v6':
265
				case 'spdyn-v6':
266
				case 'duiadns-v6':
267
				case 'freedns-v6':
268
				case 'cloudflare-v6':
269
					$this->_useIPv6 = true;
270
					break;
271
				default:
272
					$this->_useIPv6 = false;
273
			}
274
			$this->_dnsService = strtolower($dnsService);
275
			$this->_dnsUser = $dnsUser;
276
			$this->_dnsPass = base64_decode($dnsPass);
277
			$this->_dnsHost = $dnsHost;
278
			$this->_dnsDomain = $dnsDomain;
279
			$this->_dnsServer = $dnsServer;
280
			$this->_dnsPort = $dnsPort;
281
			$this->_dnsWildcard = $dnsWildcard;
282
			$this->_dnsMX = $dnsMX;
283
			$this->_dnsZoneID = $dnsZoneID;
284
			$this->_dnsTTL = $dnsTTL;
285
			$this->_if = get_failover_interface($dnsIf);
286
			$this->_checkIP();
287
			$this->_dnsUpdateURL = $dnsUpdateURL;
288
			$this->_dnsResultMatch = $dnsResultMatch;
289
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
290
			if ($this->_dnsVerboseLog) {
291
				log_error(sprintf(gettext('Dynamic DNS (%1$s): running get_failover_interface for %2$s. found %3$s'), $this->_FQDN, $dnsRequestIf, $this->_dnsRequestIf));
292
			}
293
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
294
			$this->_dnsMaxCacheAgeDays = 25;
295
			$this->_dnsDummyUpdateDone = false;
296
			$this->_forceUpdateNeeded = $forceUpdate;
297

    
298
			// Ensure that we were able to lookup the IP
299
			if (!is_ipaddr($this->_dnsIP)) {
300
				log_error(sprintf(gettext('Dynamic DNS (%1$s) There was an error trying to determine the public IP for interface - %2$s (%3$s %4$s).'), $this->_FQDN, $dnsIf, $this->_if, $this->_dnsIP));
301
				unlock($dyndnslck);
302
				return;
303
			}
304

    
305
			$this->_debugID = rand(1000000, 9999999);
306

    
307
			if ($forceUpdate == false && $this->_detectChange() == false) {
308
				$this->_error(10);
309
			} else {
310
				switch ($this->_dnsService) {
311
					case 'glesys':
312
					case 'dnsomatic':
313
					case 'dyndns':
314
					case 'dyndns-static':
315
					case 'dyndns-custom':
316
					case 'dhs':
317
					case 'noip':
318
					case 'noip-free':
319
					case 'easydns':
320
					case 'hn':
321
					case 'zoneedit':
322
					case 'dyns':
323
					case 'ods':
324
					case 'freedns':
325
					case 'freedns-v6':
326
					case 'loopia':
327
					case 'staticcling':
328
					case 'dnsexit':
329
					case 'custom':
330
					case 'custom-v6':
331
					case 'opendns':
332
					case 'namecheap':
333
					case 'he-net':
334
					case 'he-net-v6':
335
					case 'duiadns':
336
					case 'duiadns-v6':
337
					case 'selfhost':
338
					case 'he-net-tunnelbroker':
339
					case 'route53':
340
					case 'cloudflare':
341
					case 'cloudflare-v6':
342
					case 'eurodns':
343
					case 'gratisdns':
344
					case 'ovh-dynhost':
345
					case 'citynetwork':
346
					case 'dnsimple':
347
					case 'googledomains':
348
					case 'dnsmadeeasy':
349
					case 'spdyn':
350
					case 'spdyn-v6':
351
					case 'all-inkl':
352
						$this->_update();
353
						if ($this->_dnsDummyUpdateDone == true) {
354
							// If a dummy update was needed, then sleep a while and do the update again to put the proper address back.
355
							// Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month.
356
							// If the address has not changed recently, or the user did "Force Update", then the code does
357
							// a dummy address change for providers like this.
358
							sleep(10);
359
							$this->_update();
360
						}
361
						break;
362
					default:
363
						$this->_error(6);
364
						break;
365
				}
366
			}
367

    
368
			unlock($dyndnslck);
369
		}
370

    
371
		/*
372
		 * Private Function (added 12 July 05) [beta]
373
		 *   Send Update To Selected Service.
374
		 */
375
		function _update() {
376

    
377
			if ($this->_dnsVerboseLog) {
378
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
379
			}
380

    
381
			if (strstr($this->_dnsRequestIf, "_vip")) {
382
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
383
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
384
			} else {
385
				$realparentif = $this->_dnsRequestIf;
386
			}
387

    
388
			$ch = curl_init();
389

    
390
			if ($this->_useIPv6 == false) {
391
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
392
			}
393

    
394
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
395
				curl_setopt($ch, CURLOPT_HEADER, 1);
396
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
397
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
398
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
399
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
400
			}
401

    
402
			switch ($this->_dnsService) {
403
				case 'glesys':
404
					$needsIP = TRUE;
405
					$server = 'https://api.glesys.com/domain/updaterecord/format/json';
406
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
407
					$post_data['recordid'] = $this->_FQDN;
408
					$post_data['data'] = $this->_dnsIP;
409
					curl_setopt($ch, CURLOPT_URL, $server);
410
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
411
					break;
412
				case 'dyndns':
413
				case 'dyndns-static':
414
				case 'dyndns-custom':
415
					$needsIP = FALSE;
416
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
417
						$this->_dnsWildcard = "ON";
418
					}
419
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
420
					$server = "https://members.dyndns.org/nic/update";
421
					$port = "";
422
					if ($this->_dnsServer) {
423
						$server = $this->_dnsServer;
424
					}
425
					if ($this->_dnsPort) {
426
						$port = ":" . $this->_dnsPort;
427
					}
428
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
429
					break;
430
				case 'dhs':
431
					// DHS is disabled in the GUI because the following doesn't work.
432
					$needsIP = TRUE;
433
					$post_data['hostscmd'] = 'edit';
434
					$post_data['hostscmdstage'] = '2';
435
					$post_data['type'] = '4';
436
					$post_data['updatetype'] = 'Online';
437
					$post_data['mx'] = $this->_dnsMX;
438
					$post_data['mx2'] = '';
439
					$post_data['txt'] = '';
440
					$post_data['offline_url'] = '';
441
					$post_data['cloak'] = 'Y';
442
					$post_data['cloak_title'] = '';
443
					$post_data['ip'] = $this->_dnsIP;
444
					$post_data['domain'] = 'dyn.dhs.org';
445
					$post_data['hostname'] = $this->_dnsHost;
446
					$post_data['submit'] = 'Update';
447
					$server = "https://members.dhs.org/nic/hosts";
448
					$port = "";
449
					if ($this->_dnsServer) {
450
						$server = $this->_dnsServer;
451
					}
452
					if ($this->_dnsPort) {
453
						$port = ":" . $this->_dnsPort;
454
					}
455
					curl_setopt($ch, CURLOPT_URL, $server . $port);
456
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
457
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
458
					break;
459
				case 'noip':
460
				case 'noip-free':
461
					$needsIP = TRUE;
462
					$server = "https://dynupdate.no-ip.com/ducupdate.php";
463
					$port = "";
464
					if ($this->_dnsServer) {
465
						$server = $this->_dnsServer;
466
					}
467
					if ($this->_dnsPort) {
468
						$port = ":" . $this->_dnsPort;
469
					}
470
					if (($this->_dnsService == "noip-free") &&
471
					    ($this->_forceUpdateNeeded == true) &&
472
					    ($this->_dnsDummyUpdateDone == false)) {
473
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
474
						$iptoset = "192.168.1.1";
475
						$this->_dnsDummyUpdateDone = true;
476
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): Processing dummy update on No-IP free account. IP temporarily set to %3$s'), $this->_dnsService, $this->_dnsHost, $iptoset));
477
					} else {
478
						$iptoset = $this->_dnsIP;
479
					}
480
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&h[]=' . $this->_dnsHost.'&ip=' . $iptoset);
481
					break;
482
				case 'easydns':
483
					$needsIP = TRUE;
484
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
485
					$server = "https://members.easydns.com/dyn/dyndns.php";
486
					$port = "";
487
					if ($this->_dnsServer) {
488
						$server = $this->_dnsServer;
489
					}
490
					if ($this->_dnsPort) {
491
						$port = ":" . $this->_dnsPort;
492
					}
493
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
494
					break;
495
				case 'hn':
496
					$needsIP = TRUE;
497
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
498
					$server = "http://dup.hn.org/vanity/update";
499
					$port = "";
500
					if ($this->_dnsServer) {
501
						$server = $this->_dnsServer;
502
					}
503
					if ($this->_dnsPort) {
504
						$port = ":" . $this->_dnsPort;
505
					}
506
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
507
					break;
508
				case 'zoneedit':
509
					$needsIP = FALSE;
510
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
511

    
512
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
513
					$port = "";
514
					if ($this->_dnsServer) {
515
						$server = $this->_dnsServer;
516
					}
517
					if ($this->_dnsPort) {
518
						$port = ":" . $this->_dnsPort;
519
					}
520
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
521
					break;
522
				case 'dyns':
523
					$needsIP = FALSE;
524
					$server = "http://www.dyns.net/postscript011.php";
525
					$port = "";
526
					if ($this->_dnsServer) {
527
						$server = $this->_dnsServer;
528
					}
529
					if ($this->_dnsPort) {
530
						$port = ":" . $this->_dnsPort;
531
					}
532
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
533
					break;
534
				case 'ods':
535
					$needsIP = FALSE;
536
					$misc_errno = 0;
537
					$misc_error = "";
538
					$server = "ods.org";
539
					$port = "";
540
					if ($this->_dnsServer) {
541
						$server = $this->_dnsServer;
542
					}
543
					if ($this->_dnsPort) {
544
						$port = ":" . $this->_dnsPort;
545
					}
546
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
547
					/* Check that we have connected */
548
					if (!$this->con['socket']) {
549
						print "error! could not connect.";
550
						break;
551
					}
552
					/* Here is the loop. Read the incoming data (from the socket connection) */
553
					while (!feof($this->con['socket'])) {
554
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
555
						$code = substr($this->con['buffer']['all'], 0, 3);
556
						sleep(1);
557
						switch ($code) {
558
							case 100:
559
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
560
								break;
561
							case 225:
562
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
563
								break;
564
							case 901:
565
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
566
								break;
567
							case 795:
568
								fputs($this->con['socket'], "QUIT\n");
569
								break;
570
						}
571
					}
572
					$this->_checkStatus(0, $code);
573
					break;
574
				case 'freedns':
575
				case 'freedns-v6':
576
					$needIP = FALSE;
577
					curl_setopt($ch, CURLOPT_URL, 'https://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
578
					break;
579
				case 'dnsexit':
580
					$needsIP = TRUE;
581
					curl_setopt($ch, CURLOPT_URL, 'https://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
582
					break;
583
				case 'loopia':
584
					$needsIP = TRUE;
585
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
586
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
587
					break;
588
				case 'opendns':
589
					$needsIP = FALSE;
590
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
591
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
592
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
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);
601
					break;
602

    
603
				case 'staticcling':
604
					$needsIP = FALSE;
605
					curl_setopt($ch, CURLOPT_URL, 'https://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
606
					break;
607
				case 'dnsomatic':
608
					/* Example syntax
609
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
610
					*/
611
					$needsIP = FALSE;
612
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
613
						$this->_dnsWildcard = "ON";
614
					}
615
					/*
616
					Reference: https://www.dnsomatic.com/wiki/api
617
						DNS-O-Matic usernames are 3-25 characters.
618
						DNS-O-Matic passwords are 6-20 characters.
619
						All ASCII letters and numbers accepted.
620
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
621
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
622
						Encodes the given string according to RFC 3986.
623
					*/
624
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
625
					if ($this->_dnsServer) {
626
						$server = $this->_dnsServer;
627
					}
628
					if ($this->_dnsPort) {
629
						$port = ":" . $this->_dnsPort;
630
					}
631
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
632
					break;
633
				case 'namecheap':
634
					/* Example:
635
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
636
					*/
637
					$needsIP = FALSE;
638
					$dnspass = trim($this->_dnsPass);
639
					$server = "https://dynamicdns.park-your-domain.com/update?host={$this->_dnsHost}&domain={$this->_dnsDomain}&password={$dnspass}&ip={$this->_dnsIP}";
640
					curl_setopt($ch, CURLOPT_URL, $server);
641
					break;
642
				case 'duiadns':
643
				case 'duiadns-v6':
644
					$needsIP = FALSE;
645
					$server = "https://ipv4.duiadns.net/dyndns.duia?";
646
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
647
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
648
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
649
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
650
					break;
651
				case 'he-net':
652
				case 'he-net-v6':
653
					$needsIP = FALSE;
654
					$server = "https://dyn.dns.he.net/nic/update?";
655
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
656
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
657
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
658
					break;
659
				case 'he-net-tunnelbroker':
660
					$needsIP = FALSE;
661
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
662
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
663
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
664
					break;
665
				case 'selfhost':
666
					$needsIP = FALSE;
667
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
668
						$this->_dnsWildcard = "ON";
669
					}
670
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
671
					$server = "https://carol.selfhost.de/nic/update";
672
					$port = "";
673
					if ($this->_dnsServer) {
674
						$server = $this->_dnsServer;
675
					}
676
					if ($this->_dnsPort) {
677
						$port = ":" . $this->_dnsPort;
678
					}
679
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
680
					break;
681
				case 'route53':		
682
					require_once("r53.class");
683
					$r53 = new Route53($this->_dnsUser, $this->_dnsPass);
684
					$apiurl = $r53->getApiUrl($this->_dnsZoneID);
685
					$xmlreq = $r53->getRequestBody($this->_dnsHost, $this->_dnsIP, $this->_dnsTTL);
686
					$httphead = $r53->getHttpPostHeaders(strlen($xmlreq));
687
					curl_setopt($ch, CURLOPT_HTTPHEADER, $httphead);
688
					if($this->_dnsVerboseLog){
689
						log_error(sprintf("Sending reuquest to: %s", $apiurl));
690
						foreach($httphead as $hv){
691
							log_error(sprintf("Header: %s", $hv));
692
						}
693
						log_error(sprintf("XMLPOST: %s", $xmlreq));
694
					}
695
					curl_setopt($ch, CURLOPT_URL, $apiurl);
696
					curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlreq);
697
					break;
698
				case 'custom':
699
				case 'custom-v6':
700
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
701
					if ($this->_dnsUser != '') {
702
						if ($this->_curlIpresolveV4) {
703
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
704
						}
705
						if ($this->_curlSslVerifypeer) {
706
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
707
						} else {
708
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
709
						}
710
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
711
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
712
					}
713
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
714
					if ($this->_dnsVerboseLog) {
715
						log_error(sprintf(gettext("Sending request to: %s"), $server));
716
					}
717
					curl_setopt($ch, CURLOPT_URL, $server);
718
					break;
719
				case 'cloudflare-v6':
720
				case 'cloudflare':
721
					$isv6 = ($this->_dnsService === 'cloudflare-v6');
722
					$recordType = $isv6 ? "AAAA" : "A";
723
					$needsIP = TRUE;
724
					$dnsServer ='api.cloudflare.com';
725
					$dnsHost = str_replace(' ', '', $this->_dnsHost);
726

    
727
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
728
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
729
						'X-Auth-Email: '.$this->_dnsUser.'',
730
						'X-Auth-Key: '.$this->_dnsPass.'',
731
						'Content-Type: application/json'
732
					));
733

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

    
865
		/*
866
		 * Private Function (added 12 July 2005) [beta]
867
		 *   Retrieve Update Status
868
		 */
869
		function _checkStatus($ch, $data) {
870
			if ($this->_dnsVerboseLog) {
871
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
872
			}
873
			$successful_update = false;
874
			$success_str = "(" . gettext("Success") . ") ";
875
			$error_str = "(" . gettext("Error") . ") ";
876
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
877

    
878
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
879
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
880
				log_error($status);
881
				$this->status = $status;
882
				return;
883
			}
884
			switch ($this->_dnsService) {
885
				case 'glesys':
886
					$status_intro = "GleSYS ({$this->_dnsHost}): ";
887
					if (preg_match('/Record updated/i', $data)) {
888
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
889
						$successful_update = true;
890
					} else {
891
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
892
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
893
						$this->_debug($data);
894
					}
895
					break;
896
				case 'dnsomatic':
897
					$status_intro = "DNS-O-Matic ({$this->_dnsHost}): ";
898
					if (preg_match('/badauth/i', $data)) {
899
						$status = $status_intro . gettext("The DNS-O-Matic username or password specified are incorrect. No updates will be distributed to services until this is resolved.");
900
					} else if (preg_match('/notfqdn /i', $data)) {
901
						$status = $status_intro . gettext("The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.");
902
					} else if (preg_match('/nohost/i', $data)) {
903
						$status = $status_intro . gettext("The hostname passed could not be matched to any services configured. The service field will be blank in the return code.");
904
					} else if (preg_match('/numhost/i', $data)) {
905
						$status = $status_intro . gettext("Up to 20 hosts my be updated. numhost is returned if attempting to update more than 20 or update a round-robin.");
906
					} else if (preg_match('/abuse/i', $data)) {
907
						$status = $status_intro . gettext("The hostname is blocked for update abuse.");
908
					} else if (preg_match('/good/i', $data)) {
909
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
910
						$successful_update = true;
911
					} else if (preg_match('/dnserr/i', $data)) {
912
						$status = $status_intro . gettext("DNS error encountered. Stop updating for 30 minutes.");
913
					} else {
914
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
915
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
916
						$this->_debug($data);
917
					}
918
					break;
919
				case 'citynetwork':
920
					if (preg_match('/notfqdn/i', $data)) {
921
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
922
					} else if (preg_match('/nohost/i', $data)) {
923
						$status = $status_intro . $error_str . gettext("No such host");
924
					} else if (preg_match('/nochg/i', $data)) {
925
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
926
						$successful_update = true;
927
					} else if (preg_match('/good/i', $data)) {
928
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
929
						$successful_update = true;
930
					} else if (preg_match('/badauth/i', $data)) {
931
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
932
					} else {
933
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
934
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
935
						$this->_debug($data);
936
					}
937
					break;
938
				case 'ovh-dynhost':
939
				case 'dyndns':
940
					if (preg_match('/notfqdn/i', $data)) {
941
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
942
					} else if (preg_match('/nochg/i', $data)) {
943
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
944
						$successful_update = true;
945
					} else if (preg_match('/good/i', $data)) {
946
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
947
						$successful_update = true;
948
					} else if (preg_match('/noauth/i', $data)) {
949
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
950
					} else {
951
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
952
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
953
						$this->_debug($data);
954
					}
955
					break;
956
				case 'dyndns-static':
957
					if (preg_match('/notfqdn/i', $data)) {
958
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
959
					} else if (preg_match('/nochg/i', $data)) {
960
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
961
						$successful_update = true;
962
					} else if (preg_match('/good/i', $data)) {
963
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
964
						$successful_update = true;
965
					} else if (preg_match('/noauth/i', $data)) {
966
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
967
					} else {
968
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
969
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
970
						$this->_debug($data);
971
					}
972
					break;
973
				case 'dyndns-custom':
974
					if (preg_match('/notfqdn/i', $data)) {
975
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
976
					} else if (preg_match('/nochg/i', $data)) {
977
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
978
						$successful_update = true;
979
					} else if (preg_match('/good/i', $data)) {
980
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
981
						$successful_update = true;
982
					} else if (preg_match('/noauth/i', $data)) {
983
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
984
					} else {
985
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
986
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
987
						$this->_debug($data);
988
					}
989
					break;
990
				case 'dhs':
991
					break;
992
				case 'noip':
993
				case 'noip-free':
994
					list($ip, $code) = explode(":", $data);
995
					switch ($code) {
996
						case 0:
997
							$status = $status_intro . $success_str . gettext("IP address is current, no update performed.");
998
							$successful_update = true;
999
							break;
1000
						case 1:
1001
							$status = $status_intro . $success_str . gettext("DNS hostname update successful.");
1002
							$successful_update = true;
1003
							break;
1004
						case 2:
1005
							$status = $status_intro . $error_str . gettext("Hostname supplied does not exist.");
1006
							break;
1007
						case 3:
1008
							$status = $status_intro . $error_str . gettext("Invalid Username.");
1009
							break;
1010
						case 4:
1011
							$status = $status_intro . $error_str . gettext("Invalid Password.");
1012
							break;
1013
						case 5:
1014
							$status = $status_intro . $error_str . gettext("Too many updates sent.");
1015
							break;
1016
						case 6:
1017
							$status = $status_intro . $error_str . gettext("Account disabled due to violation of No-IP terms of service.");
1018
							break;
1019
						case 7:
1020
							$status = $status_intro . $error_str . gettext("Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.");
1021
							break;
1022
						case 8:
1023
							$status = $status_intro . $error_str . gettext("Disabled / Locked Hostname.");
1024
							break;
1025
						case 9:
1026
							$status = $status_intro . $error_str . gettext("Host updated is configured as a web redirect and no update was performed.");
1027
							break;
1028
						case 10:
1029
							$status = $status_intro . $error_str . gettext("Group supplied does not exist.");
1030
							break;
1031
						case 11:
1032
							$status = $status_intro . $success_str . gettext("DNS group update is successful.");
1033
							$successful_update = true;
1034
							break;
1035
						case 12:
1036
							$status = $status_intro . $success_str . gettext("DNS group is current, no update performed.");
1037
							$successful_update = true;
1038
							break;
1039
						case 13:
1040
							$status = $status_intro . $error_str . gettext("Update client support not available for supplied hostname or group.");
1041
							break;
1042
						case 14:
1043
							$status = $status_intro . $error_str . gettext("Hostname supplied does not have offline settings configured.");
1044
							break;
1045
						case 99:
1046
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1047
							break;
1048
						case 100:
1049
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1050
							break;
1051
						default:
1052
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1053
							$this->_debug(gettext("Unknown Response:") . " " . $data);
1054
							break;
1055
					}
1056
					break;
1057
				case 'easydns':
1058
					if (preg_match('/NOACCESS/i', $data)) {
1059
						$status = $status_intro . $error_str . gettext("Authentication Failed: Username and/or Password was Incorrect.");
1060
					} else if (preg_match('/NOSERVICE/i', $data)) {
1061
						$status = $status_intro . $error_str . gettext("No Service: Dynamic DNS Service has been disabled for this domain.");
1062
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
1063
						$status = $status_intro . $error_str . gettext("Illegal Input: Self-Explanatory");
1064
					} else if (preg_match('/TOOSOON/i', $data)) {
1065
						$status = $status_intro . $error_str . gettext("Too Soon: Not Enough Time Has Elapsed Since Last Update");
1066
					} else if (preg_match('/NOERROR/i', $data)) {
1067
						$status = $status_intro . $success_str . gettext("IP Updated Successfully!");
1068
						$successful_update = true;
1069
					} else {
1070
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1071
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1072
						$this->_debug($data);
1073
					}
1074
					break;
1075
				case 'hn':
1076
					/* FIXME: add checks */
1077
					break;
1078
				case 'zoneedit':
1079
					if (preg_match('/799/i', $data)) {
1080
						$status = $status_intro . "(" . gettext("Error 799") . ") " . gettext("Update Failed!");
1081
					} else if (preg_match('/700/i', $data)) {
1082
						$status = $status_intro . "(" . gettext("Error 700") . ") " . gettext("Update Failed!");
1083
					} else if (preg_match('/200/i', $data)) {
1084
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1085
						$successful_update = true;
1086
					} else if (preg_match('/201/i', $data)) {
1087
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1088
						$successful_update = true;
1089
					} else {
1090
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1091
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1092
						$this->_debug($data);
1093
					}
1094
					break;
1095
				case 'dyns':
1096
					if (preg_match("/400/i", $data)) {
1097
						$status = $status_intro . $error_str . gettext("Bad Request - The URL was malformed. Required parameters were not provided.");
1098
					} else if (preg_match('/402/i', $data)) {
1099
						$status = $status_intro . $error_str . gettext("Update Too Soon - Attempted to update too quickly since last change.");
1100
					} else if (preg_match('/403/i', $data)) {
1101
						$status = $status_intro . $error_str . gettext("Database Error - There was a server-sided database error.");
1102
					} else if (preg_match('/405/i', $data)) {
1103
						$status = $status_intro . $error_str . sprintf(gettext("Hostname Error - The hostname (%s) doesn't belong to user (%s)."), $this->_dnsHost, $this->_dnsUser);
1104
					} else if (preg_match('/200/i', $data)) {
1105
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1106
						$successful_update = true;
1107
					} else {
1108
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1109
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1110
						$this->_debug($data);
1111
					}
1112
					break;
1113
				case 'ods':
1114
					if (preg_match("/299/i", $data)) {
1115
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1116
						$successful_update = true;
1117
					} else {
1118
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1119
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1120
						$this->_debug($data);
1121
					}
1122
					break;
1123
				case 'freedns':
1124
				case 'freedns-v6':
1125
					if (preg_match("/has not changed./i", $data)) {
1126
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1127
						$successful_update = true;
1128
					} else if (preg_match("/Updated/i", $data)) {
1129
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1130
						$successful_update = true;
1131
					} else {
1132
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1133
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1134
						$this->_debug($data);
1135
					}
1136
					break;
1137
				case 'dnsexit':
1138
					if (preg_match("/is the same/i", $data)) {
1139
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1140
						$successful_update = true;
1141
					} else if (preg_match("/Success/i", $data)) {
1142
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1143
						$successful_update = true;
1144
					} else {
1145
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1146
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1147
						$this->_debug($data);
1148
					}
1149
					break;
1150
				case 'loopia':
1151
					if (preg_match("/nochg/i", $data)) {
1152
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1153
						$successful_update = true;
1154
					} else if (preg_match("/good/i", $data)) {
1155
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1156
						$successful_update = true;
1157
					} else if (preg_match('/badauth/i', $data)) {
1158
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1159
					} else {
1160
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1161
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1162
						$this->_debug($data);
1163
					}
1164
					break;
1165
				case 'opendns':
1166
					if (preg_match('/badauth/i', $data)) {
1167
						$status = $status_intro . $error_str . gettext("Not a valid username or password!");
1168
					} else if (preg_match('/nohost/i', $data)) {
1169
						$status = $status_intro . $error_str . gettext("Hostname specified does not exist.");
1170
						$successful_update = true;
1171
					} else if (preg_match('/good/i', $data)) {
1172
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1173
						$successful_update = true;
1174
					} else if (preg_match('/yours/i', $data)) {
1175
						$status = $status_intro . $error_str . gettext("Hostname specified exists, but not under the username specified.");
1176
					} else if (preg_match('/abuse/i', $data)) {
1177
						$status = $status_intro . $error_str . gettext("Updating too frequently, considered abuse.");
1178
					} else {
1179
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1180
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1181
						$this->_debug($data);
1182
					}
1183
					break;
1184
				case 'staticcling':
1185
					if (preg_match("/invalid ip/i", $data)) {
1186
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1187
					} else if (preg_match('/required info missing/i', $data)) {
1188
						$status = $status_intro . $error_str . gettext("Bad Request - Required parameters were not provided.");
1189
					} else if (preg_match('/invalid characters/i', $data)) {
1190
						$status = $status_intro . $error_str . gettext("Bad Request - Illegal characters in either the username or the password.");
1191
					} else if (preg_match('/bad password/i', $data)) {
1192
						$status = $status_intro . $error_str . gettext("Invalid password.");
1193
					} else if (preg_match('/account locked/i', $data)) {
1194
						$status = $status_intro . $error_str . gettext("This account has been administratively locked.");
1195
					} else if (preg_match('/update too frequent/i', $data)) {
1196
						$status = $status_intro . $error_str . gettext("Updating too frequently.");
1197
					} else if (preg_match('/DB error/i', $data)) {
1198
						$status = $status_intro . $error_str . gettext("Server side error.");
1199
					} else if (preg_match('/success/i', $data)) {
1200
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1201
						$successful_update = true;
1202
					} else {
1203
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1204
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1205
						$this->_debug($data);
1206
					}
1207
					break;
1208
				case 'namecheap':
1209
					$tmp = str_replace("^M", "", $data);
1210
					$ncresponse = @xml2array($tmp);
1211
					if (preg_match("/internal server error/i", $data)) {
1212
						$status = $status_intro . $error_str . gettext("Server side error.");
1213
					} else if (preg_match("/request is badly formed/i", $data)) {
1214
						$status = $status_intro . $error_str . gettext("Badly Formed Request (check the settings).");
1215
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1216
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1217
						$successful_update = true;
1218
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1219
						$status = $status_intro . $error_str . implode(", ", $ncresponse["interface-response"]["errors"]);
1220
						$successful_update = true;
1221
					} else {
1222
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1223
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1224
						$this->_debug($data);
1225
					}
1226
					break;
1227
				case 'duiadns':
1228
				case 'duiadns-v6':
1229
					if (preg_match("/error/i", $data)) {
1230
						$status = $status_intro . $error_str . gettext("Server side error.");
1231
					} else if (preg_match('/nohost/i', $data)) {
1232
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1233
					} else if (preg_match('/badauth/i', $data)) {
1234
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1235
					} else if (preg_match('/good/i', $data)) {
1236
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1237
						$successful_update = true;
1238
					} else if (preg_match('/nochg/i', $data)) {
1239
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1240
						$successful_update = true;
1241
					} else {
1242
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1243
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1244
						$this->_debug($data);
1245
					}
1246
					break;
1247
				case 'he-net':
1248
				case 'he-net-v6':
1249
					if (preg_match("/badip/i", $data)) {
1250
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1251
					} else if (preg_match('/nohost/i', $data)) {
1252
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1253
					} else if (preg_match('/badauth/i', $data)) {
1254
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1255
					} else if (preg_match('/good/i', $data)) {
1256
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1257
						$successful_update = true;
1258
					} else if (preg_match('/nochg/i', $data)) {
1259
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1260
						$successful_update = true;
1261
					} else {
1262
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1263
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1264
						$this->_debug($data);
1265
					}
1266
					break;
1267
				case 'he-net-tunnelbroker':
1268
					/*
1269
					-ERROR: Missing parameter(s).
1270
					-ERROR: Invalid API key or password
1271
					-ERROR: Tunnel not found
1272
					-ERROR: Another tunnel exists for this IP.
1273
					-ERROR: This tunnel is already associated with this IP address
1274
					+OK: Tunnel endpoint updated to: x.x.x.x
1275
					*/
1276
					if (preg_match("/Missing parameter/i", $data)) {
1277
						$status = $status_intro . $error_str . gettext("Bad Request - Missing/Invalid Parameters.");
1278
					} else if (preg_match('/Tunnel not found/i', $data)) {
1279
						$status = $status_intro . $error_str . gettext("Bad Request - Invalid Tunnel ID.");
1280
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1281
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1282
					} else if (preg_match('/OK:/i', $data)) {
1283
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1284
						$successful_update = true;
1285
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1286
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1287
						$successful_update = true;
1288
					} else {
1289
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1290
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1291
						$this->_debug($data);
1292
					}
1293
					break;
1294
				case 'selfhost':
1295
					if (preg_match('/notfqdn/i', $data)) {
1296
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1297
					} else if (preg_match('/nochg/i', $data)) {
1298
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1299
						$successful_update = true;
1300
					} else if (preg_match('/good/i', $data)) {
1301
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1302
						$successful_update = true;
1303
					} else if (preg_match('/noauth/i', $data)) {
1304
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1305
					} else {
1306
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1307
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1308
						$this->_debug($data);
1309
					}
1310
					break;
1311
				case 'route53':
1312
					if(preg_match('/ErrorResponse/', $data)){
1313
						$status = $status_intro . $error_str . gettext("Route53 API call failed");
1314
						log_error(sprintf("error message: %s", $data));
1315
						$status_update = false;
1316
					} else {
1317
						$status = $status_intro . $success_str . gettext("IP address changed successfully");
1318
						$successful_update = true;
1319
					}
1320
					break;
1321
				case 'custom':
1322
				case 'custom-v6':
1323
					$successful_update = false;
1324
					if ($this->_dnsResultMatch == "") {
1325
						$successful_update = true;
1326
					} else {
1327
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1328
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1329
						foreach ($matches as $match) {
1330
							$match= str_replace("\\|", "|", $match);
1331
							if (strcmp($match, trim($data, "\t\n\r")) == 0) {
1332
								$successful_update = true;
1333
							}
1334
						}
1335
						unset ($matches);
1336
					}
1337
					if ($successful_update == true) {
1338
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1339
					} else {
1340
						$status = $status_intro . $error_str . gettext("Result did not match.") . " [" . $data . "]";
1341
					}
1342
					break;
1343
				case 'cloudflare-v6':
1344
				case 'cloudflare':
1345
					$output = json_decode($data);
1346
					if ($output->result->content === $this->_dnsIP) {
1347
						$status = $status_intro . $success_str . sprintf(gettext('%1$s updated to %2$s'), $this->_dnsHost, $this->_dnsIP);
1348
						$successful_update = true;
1349
					} elseif ($output->errors[0]->code === 9103) {
1350
						$status = $status_intro . $error_str . gettext("Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.");
1351
					} elseif (($output->success) && (!$output->result[0]->id)) {
1352
						$status = $status_intro . $error_str . gettext("Zone or Host ID was not found, check the hostname.");
1353
					} else {
1354
						$status = $status_intro . gettext("UNKNOWN ERROR") . " - " . $output->errors[0]->message;
1355
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1356
					}
1357
					break;
1358
				case 'eurodns':
1359
					if (preg_match('/notfqdn/i', $data)) {
1360
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1361
					} else if (preg_match('/nochg/i', $data)) {
1362
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1363
						$successful_update = true;
1364
					} else if (preg_match('/good/i', $data)) {
1365
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1366
						$successful_update = true;
1367
					} else if (preg_match('/badauth/i', $data)) {
1368
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1369
					} else {
1370
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1371
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1372
						$this->_debug($data);
1373
					}
1374
					break;
1375
				case 'gratisdns':
1376
					if (preg_match('/Forkerte værdier/i', $data)) {
1377
						$status = $status_intro . $error_str . gettext("Wrong values - Update could not be completed.");
1378
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1379
						$status = $status_intro . $error_str . gettext("Unknown username - User does not exist.");
1380
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1381
						$status = $status_intro . $error_str . gettext("Wrong password - Remember password is case sensitive.");
1382
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1383
						$status = $status_intro . $error_str . gettext("User unable to administer the selected domain.");
1384
					} else if (preg_match('/OK/i', $data)) {
1385
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1386
						$successful_update = true;
1387
					} else {
1388
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1389
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1390
						$this->_debug($data);
1391
					}
1392
					break;
1393
				case 'dnsimple':
1394
					/* Responds with HTTP 200 on success.
1395
					   Responds with HTTP 4xx on error.
1396
					   Returns JSON data as body */
1397
;
1398
					if (preg_match("/\s200\sOK/i", $header)) {
1399
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1400
						$successful_update = true;
1401
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1402
						$arrbody = json_decode($data, true);
1403
						$message = $arrbody['message'] . ".";
1404
						if (isset($arrbody['errors']['content'])) {
1405
							foreach ($arrbody['errors']['content'] as $key => $content) {
1406
								$message .= " " . $content . ".";
1407
							}
1408
						}
1409
						$status = $status_intro . $error_str . $message;
1410
					} else {
1411
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1412
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1413
						$this->_debug($data);
1414
					}
1415
					break;
1416
				case 'googledomains':
1417
					if (preg_match('/notfqdn/i', $data)) {
1418
						$status = $status_intro . $error_str . gettext("Not A FQDN");
1419
					} else if (preg_match('/nochg/i', $data)) {
1420
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1421
						$successful_update = true;
1422
					} else if (preg_match('/good/i', $data)) {
1423
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1424
						$successful_update = true;
1425
					} else if (preg_match('/badauth/i', $data)) {
1426
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1427
					} else if (preg_match('/nohost/i', $data)) {
1428
						$status = $status_intro . $error_str . gettext("Hostname does not exist or DynDNS not enabled");
1429
					} else if (preg_match('/badagent/i', $data)) {
1430
						$status = $status_intro . $error_str . gettext("Bad request");
1431
					} else if (preg_match('/abuse/i', $data)) {
1432
						$status = $status_intro . $error_str . gettext("Dynamic DNS access has been blocked!");
1433
					} else if (preg_match('/911/i', $data)) {
1434
						$status = $status_intro . $error_str . gettext("Error on Google's end, retry in 5 minutes");
1435
					} else {
1436
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1437
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1438
						$this->_debug($data);
1439
					}
1440
					break;
1441
				case 'dnsmadeeasy':
1442
					switch ($data) {
1443
						case 'success':
1444
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1445
							$successful_update = true;
1446
							break;
1447
						case 'error-auth':
1448
							$status = $status_intro . $error_str . gettext("Invalid username or password");
1449
							break;
1450
						case 'error-auth-suspend':
1451
							$status = $status_intro . $error_str . gettext("Account suspended");
1452
							break;
1453
						case 'error-auth-voided':
1454
							$status = $status_intro . $error_str . gettext("Account revoked");
1455
							break;
1456
						case 'error-record-invalid':
1457
							$status = $status_intro . $error_str . gettext("Record does not exist in the system. Unable to update record");
1458
							break;
1459
						case 'error-record-auth':
1460
							$status = $status_intro . $error_str . gettext("User does not have access to this record");
1461
							break;
1462
						case 'error-record-ip-same':
1463
							$status = $status_intro . $success_str . gettext("No Change In IP Address");
1464
							$successful_update = true;
1465
							break;
1466
						case 'error-system':
1467
							$status = $status_intro . $error_str . gettext("General system error recognized by the system");
1468
							break;
1469
						case 'error':
1470
							$status = $status_intro . $error_str . gettext("General system error unrecognized by the system");
1471
							break;
1472
						default:
1473
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1474
							log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1475
							$this->_debug($data);
1476
							break;
1477
					}
1478
					break;
1479
				case 'spdyn':
1480
				case 'spdyn-v6':
1481
					if (preg_match('/notfqdn/i', $data)) {
1482
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1483
					} else if (preg_match('/nohost/i', $data)) {
1484
						$status = $status_intro . $error_str . gettext("No such host");
1485
					} else if (preg_match('/nochg/i', $data)) {
1486
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1487
						$successful_update = true;
1488
					} else if (preg_match('/good/i', $data)) {
1489
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1490
						$successful_update = true;
1491
					} else if (preg_match('/badauth/i', $data)) {
1492
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1493
					} else {
1494
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1495
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1496
						$this->_debug($data);
1497
					}
1498
					break;
1499
				case 'all-inkl':
1500
 					if (preg_match('/good\s'.$this->_dnsIP.'/i', $data)) {
1501
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1502
 							$successful_update = true;
1503
 					} else if (preg_match('/good/i', $data)) {
1504
						$status = $status_intro . $error_str . gettext("Result did not match.");
1505
					} else if (preg_match("/\s401\sUnauthorized/i", $header)) {
1506
						$status = $status_intro . $error_str . gettext("Invalid username or password");
1507
					} 
1508
					else {
1509
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1510
							log_error($status_intro . gettext("PAYLOAD:") . " " . $header.$data);
1511
 							$this->_debug($data);
1512
 							$this->_debug($header);
1513
 					}
1514
 					break;
1515
			}
1516

    
1517
			if ($successful_update == true) {
1518
				/* Write WAN IP to cache file */
1519
				$wan_ip = $this->_checkIP();
1520
				conf_mount_rw();
1521
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1522
					$currentTime = time();
1523
					notify_all_remote(sprintf(gettext('DynDNS updated IP Address on %1$s (%2$s) to %3$s'), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1524
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1525
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1526
				} else {
1527
					@unlink($this->_cacheFile);
1528
				}
1529
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1530
					$currentTime = time();
1531
					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));
1532
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1533
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1534
				} else {
1535
					@unlink($this->_cacheFile_v6);
1536
				}
1537
				conf_mount_ro();
1538
			}
1539
			$this->status = $status;
1540
			log_error($status);
1541
		}
1542

    
1543
		/*
1544
		 * Private Function (added 12 July 05) [beta]
1545
		 *   Return Error, Set Last Error, and Die.
1546
		 */
1547
		function _error($errorNumber = '1') {
1548
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1549
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1550
			switch ($errorNumber) {
1551
				case 0:
1552
					break;
1553
				case 2:
1554
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1555
					break;
1556
				case 3:
1557
					$error = $err_str . gettext('No Username Provided.');
1558
					break;
1559
				case 4:
1560
					$error = $err_str . gettext('No Password Provided.');
1561
					break;
1562
				case 5:
1563
					$error = $err_str . gettext('No Hostname Provided.');
1564
					break;
1565
				case 6:
1566
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
1567
					break;
1568
				case 7:
1569
					$error = $err_str . gettext('No Update URL Provided.');
1570
					break;
1571
				case 8:
1572
					$status = $err_str_r53 . gettext("Invalid ZoneID");
1573
					break;
1574
				case 9:
1575
					$status = $err_str_r53 . gettext("Invalid TTL");
1576
					break;
1577
				case 10:
1578
					$error = "phpDynDNS ({$this->_FQDN}): " . sprintf(gettext("No change in my IP address and/or %s days has not passed. Not updating dynamic DNS entry."), $this->_dnsMaxCacheAgeDays);
1579
					break;
1580
				default:
1581
					$error = $err_str . gettext('Unknown Response.');
1582
					/* FIXME: $data isn't in scope here */
1583
					/* $this->_debug($data); */
1584
					break;
1585
			}
1586
			$this->lastError = $error;
1587
			log_error($error);
1588
		}
1589

    
1590
		/*
1591
		 * Private Function (added 12 July 05) [beta]
1592
		 *   - Detect whether or not IP needs to be updated.
1593
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1594
		 *      | work with other systems. pfSense base is FreeBSD.
1595
		 */
1596
		function _detectChange() {
1597
			global $debug;
1598

    
1599
			if ($debug) {
1600
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
1601
			}
1602

    
1603
			$currentTime = time();
1604

    
1605
			$wan_ip = $this->_checkIP();
1606
			if ($wan_ip == 0) {
1607
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
1608
				return false;
1609
			}
1610
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
1611

    
1612
			if ($this->_useIPv6 == true) {
1613
				if (file_exists($this->_cacheFile_v6)) {
1614
					$contents = file_get_contents($this->_cacheFile_v6);
1615
					list($cacheIP, $cacheTime) = explode('|', $contents);
1616
					$this->_debug($cacheIP.'/'.$cacheTime);
1617
					$initial = false;
1618
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
1619
				} else {
1620
					conf_mount_rw();
1621
					$cacheIP = '::';
1622
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1623
					conf_mount_ro();
1624
					$cacheTime = $currentTime;
1625
					$initial = true;
1626
					$log_error .= gettext("No Cached IPv6 found.");
1627
				}
1628
			} else {
1629
				if (file_exists($this->_cacheFile)) {
1630
					$contents = file_get_contents($this->_cacheFile);
1631
					list($cacheIP, $cacheTime) = explode(':', $contents);
1632
					$this->_debug($cacheIP.'/'.$cacheTime);
1633
					$initial = false;
1634
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
1635
				} else {
1636
					conf_mount_rw();
1637
					$cacheIP = '0.0.0.0';
1638
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1639
					conf_mount_ro();
1640
					$cacheTime = $currentTime;
1641
					$initial = true;
1642
					$log_error .= gettext("No Cached IP found.");
1643
				}
1644
			}
1645
			if ($this->_dnsVerboseLog) {
1646
				log_error($log_error);
1647
			}
1648

    
1649
			// Convert seconds = days * hr/day * min/hr * sec/min
1650
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1651

    
1652
			$needs_updating = FALSE;
1653
			/* lets determine if the item needs updating */
1654
			if ($cacheIP != $wan_ip) {
1655
				$needs_updating = true;
1656
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
1657
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
1658
			}
1659
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1660
				$needs_updating = true;
1661
				$this->_forceUpdateNeeded = true;
1662
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
1663
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1664
			}
1665
			if ($initial == true) {
1666
				$needs_updating = true;
1667
				$update_reason .= gettext("Initial update.");
1668
			}
1669

    
1670
			/*   finally if we need updating then store the
1671
			 *   new cache value and return true
1672
			 */
1673
			if ($needs_updating == true) {
1674
				if ($this->_dnsVerboseLog) {
1675
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1676
				}
1677
				return true;
1678
			}
1679

    
1680
			return false;
1681
		}
1682

    
1683
		/*
1684
		 * Private Function (added 16 July 05) [beta]
1685
		 *   - Writes debug information to a file.
1686
		 *   - This function is only called when a unknown response
1687
		 *   - status is returned from a DynDNS service provider.
1688
		 */
1689
		function _debug($data) {
1690
			global $g;
1691

    
1692
			if (!$g['debug']) {
1693
				return;
1694
			}
1695
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1696
			conf_mount_rw();
1697
			$file = fopen($this->_debugFile, 'a');
1698
			fwrite($file, $string);
1699
			fclose($file);
1700
			conf_mount_ro();
1701
		}
1702
		function _checkIP() {
1703
			global $debug;
1704

    
1705
			if ($debug) {
1706
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
1707
			}
1708

    
1709
			if ($this->_useIPv6 == true) {
1710
				$ip_address = get_interface_ipv6($this->_if);
1711
				if (!is_ipaddrv6($ip_address)) {
1712
					return 0;
1713
				}
1714
			} else {
1715
				$ip_address = get_interface_ip($this->_if);
1716
				if (!is_ipaddr($ip_address)) {
1717
					return 0;
1718
				}
1719
			}
1720
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1721
				$hosttocheck = "checkip.dyndns.org";
1722
				$try = 0;
1723
				while ($try < 3) {
1724
					$checkip = gethostbyname($hosttocheck);
1725
					if (is_ipaddr($checkip)) {
1726
						break;
1727
					}
1728
					$try++;
1729
				}
1730
				if ($try >= 3) {
1731
					log_error(sprintf(gettext('Dynamic DNS %1$s debug information (%2$s): Could not resolve %3$s to IP using interface IP %4$s.'), $this->_dnsService, $this->_FQDN, $hosttocheck, $ip_address));
1732
					return 0;
1733
				}
1734
				$ip_ch = curl_init("http://{$checkip}");
1735
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1736
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1737
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1738
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1739
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1740
				if ($this->_useIPv6 == false) {
1741
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1742
				}
1743
				$ip_result_page = curl_exec($ip_ch);
1744
				curl_close($ip_ch);
1745
				$ip_result_decoded = urldecode($ip_result_page);
1746
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1747
				$ip_address = trim($matches[1]);
1748
				if (is_ipaddr($ip_address)) {
1749
					if ($this->_dnsVerboseLog) {
1750
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
1751
					}
1752
				} else {
1753
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
1754
					return 0;
1755
				}
1756
			} else {
1757
				if ($this->_dnsVerboseLog) {
1758
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
1759
				}
1760
			}
1761
			$this->_dnsIP = $ip_address;
1762

    
1763
			return $ip_address;
1764
		}
1765

    
1766
	}
1767

    
1768
?>
(16-16/65)