Project

General

Profile

Download (74.4 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
	 *    - Hover (www.hover.com)
96
	 * +----------------------------------------------------+
97
	 *  Requirements:
98
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
99
	 * +----------------------------------------------------+
100
	 *  Public Functions
101
	 *    - updatedns()
102
	 *
103
	 *  Private Functions
104
	 *    - _update()
105
	 *    - _checkStatus()
106
	 *    - _error()
107
	 *    - _detectChange()
108
	 *    - _debug()
109
	 *    - _checkIP()
110
	 * +----------------------------------------------------+
111
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
112
	 *  DynDNS Static   - Last Tested: NEVER
113
	 *  DynDNS Custom   - Last Tested: NEVER
114
	 *  No-IP           - Last Tested: 20 July 2008
115
	 *  HN.org          - Last Tested: 12 July 2005
116
	 *  EasyDNS         - Last Tested: 20 July 2008
117
	 *  DHS             - Last Tested: 12 July 2005
118
	 *  ZoneEdit        - Last Tested: NEVER
119
	 *  Dyns            - Last Tested: NEVER
120
	 *  ODS             - Last Tested: 02 August 2005
121
	 *  FreeDNS         - Last Tested: 01 May 2016
122
	 *  FreeDNS IPv6    - Last Tested: 01 May 2016
123
	 *  Loopia          - Last Tested: NEVER
124
	 *  StaticCling     - Last Tested: 27 April 2006
125
	 *  DNSexit         - Last Tested: 20 July 2008
126
	 *  OpenDNS         - Last Tested: 4 August 2008
127
	 *  Namecheap       - Last Tested: 31 August 2010
128
	 *  HE.net          - Last Tested: 7 July 2013
129
	 *  HE.net IPv6     - Last Tested: 7 July 2013
130
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
131
	 *  SelfHost        - Last Tested: 26 December 2011
132
	 *  Amazon Route 53 - Last Tested: 04 February 2017
133
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
134
	 *  CloudFlare      - Last Tested: 05 September 2016
135
	 *  CloudFlare IPv6 - Last Tested: 17 July 2016
136
	 *  Eurodns         - Last Tested: 27 June 2013
137
	 *  GratisDNS       - Last Tested: 15 August 2012
138
	 *  OVH DynHOST     - Last Tested: NEVER
139
	 *  City Network    - Last Tested: 13 November 2013
140
	 *  GleSYS          - Last Tested: 3 February 2015
141
	 *  DNSimple        - Last Tested: 09 February 2015
142
	 *  Google Domains  - Last Tested: 27 April 2015
143
	 *  DNS Made Easy   - Last Tested: 27 April 2015
144
	 *  SPDYN           - Last Tested: 02 July 2016
145
	 *  SPDYN IPv6      - Last Tested: 02 July 2016
146
	 *  All-Inkl        - Last Tested: 12 November 2016
147
	 *  DuiaDNS         - Last Tested: 25 November 2016
148
	 *  DuiaDNS IPv6    - Last Tested: 25 November 2016
149
	 *  Hover           - Last Tested: 15 February 2017
150
	 * +====================================================+
151
	 *
152
	 * @author 	E.Kristensen
153
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
154
	 * @version 	0.8
155
	 * @updated	13 October 05 at 21:02:42 GMT
156
	 *
157
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
158
	 * Custom DNS support by Matt Corallo
159
	 *
160
	 */
161

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

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

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

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

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

    
231
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
232

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

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

    
303
			// Ensure that we were able to lookup the IP
304
			if (!is_ipaddr($this->_dnsIP)) {
305
				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));
306
				unlock($dyndnslck);
307
				return;
308
			}
309

    
310
			$this->_debugID = rand(1000000, 9999999);
311

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

    
374
			unlock($dyndnslck);
375
		}
376

    
377
		/*
378
		 * Private Function (added 12 July 05) [beta]
379
		 *   Send Update To Selected Service.
380
		 */
381
		function _update() {
382

    
383
			if ($this->_dnsVerboseLog) {
384
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
385
			}
386

    
387
			if (strstr($this->_dnsRequestIf, "_vip")) {
388
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
389
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
390
			} else {
391
				$realparentif = $this->_dnsRequestIf;
392
			}
393

    
394
			$ch = curl_init();
395

    
396
			if ($this->_useIPv6 == false) {
397
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
398
			}
399

    
400
			if ($this->_dnsService != 'ods') {
401
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
402
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
403
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
404
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
405
			}
406

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

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

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

    
734
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
735
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
736
						'X-Auth-Email: '.$this->_dnsUser.'',
737
						'X-Auth-Key: '.$this->_dnsPass.'',
738
						'Content-Type: application/json'
739
					));
740

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

    
865
					//step 1: login to API
866
					$post_data['username'] = $this->_dnsUser;
867
					$post_data['password'] = $this->_dnsPass;
868
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
869
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/login");
870
					curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies
871
					$output = curl_exec($ch);
872

    
873
					//extract the cookies
874
					preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies);
875
					if( count($cookies[1]) > 0 ){
876
						$cookie_data = implode("; ",$cookies[1]);
877
					}
878

    
879
					//step 2: find the id of the A record
880
					$post_data = null;
881
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
882
					curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
883
					curl_setopt($ch, CURLOPT_HEADER, 0);
884
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns");
885
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
886

    
887
					$output = curl_exec($ch);
888
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{\"id\":\"([^\"]*?)\",\"name\":\"{$this->_dnsHost}\".*?\$/", $output, $hostID);
889
					$hostID = $hostID[1];
890
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{[^\}]*?\"name\":\"{$this->_dnsHost}\".*?content\":\"([^\"]*?)\".*?\$/", $output, $hostIP);
891
					$hostIP = $hostIP[1];
892

    
893
					//step 3: update the IP
894
					if ($hostID) {
895
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
896
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
897
						curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
898
						$post_data['content'] = $this->_dnsIP;
899
						curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
900
						curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
901
						curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns/{$hostID}");
902
						log_error("HostID:{$hostID}, OldIP:{$hostIP}");
903
					}
904
					break;
905
				default:
906
					break;
907
			}
908
			if ($this->_dnsService != 'ods') {
909
				curl_setopt($ch, CURLOPT_HEADER, 1);
910
				$response = curl_exec($ch);
911
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
912
				$header = substr($response, 0, $header_size);
913
				$data = substr($response, $header_size);
914
				$this->_checkStatus($ch, $data, $header);
915
				@curl_close($ch);
916
			}
917
		}
918

    
919
		/*
920
		 * Private Function (added 12 July 2005) [beta]
921
		 *   Retrieve Update Status
922
		 */
923
		function _checkStatus($ch, $data, $header) {
924
			if ($this->_dnsVerboseLog) {
925
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
926
			}
927
			$successful_update = false;
928
			$success_str = "(" . gettext("Success") . ") ";
929
			$error_str = "(" . gettext("Error") . ") ";
930
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
931

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

    
1581
			if ($successful_update == true) {
1582
				/* Write WAN IP to cache file */
1583
				$wan_ip = $this->_checkIP();
1584
				conf_mount_rw();
1585
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1586
					$currentTime = time();
1587
					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));
1588
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1589
					@file_put_contents($this->_cacheFile, "{$wan_ip}|{$currentTime}");
1590
				} else {
1591
					@unlink($this->_cacheFile);
1592
				}
1593
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1594
					$currentTime = time();
1595
					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));
1596
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1597
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1598
				} else {
1599
					@unlink($this->_cacheFile_v6);
1600
				}
1601
				conf_mount_ro();
1602
			}
1603
			$this->status = $status;
1604
			log_error($status);
1605
		}
1606

    
1607
		/*
1608
		 * Private Function (added 12 July 05) [beta]
1609
		 *   Return Error, Set Last Error, and Die.
1610
		 */
1611
		function _error($errorNumber = '1') {
1612
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1613
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1614
			switch ($errorNumber) {
1615
				case 0:
1616
					break;
1617
				case 2:
1618
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1619
					break;
1620
				case 3:
1621
					$error = $err_str . gettext('No Username Provided.');
1622
					break;
1623
				case 4:
1624
					$error = $err_str . gettext('No Password Provided.');
1625
					break;
1626
				case 5:
1627
					$error = $err_str . gettext('No Hostname Provided.');
1628
					break;
1629
				case 6:
1630
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
1631
					break;
1632
				case 7:
1633
					$error = $err_str . gettext('No Update URL Provided.');
1634
					break;
1635
				case 8:
1636
					$status = $err_str_r53 . gettext("Invalid ZoneID");
1637
					break;
1638
				case 9:
1639
					$status = $err_str_r53 . gettext("Invalid TTL");
1640
					break;
1641
				case 10:
1642
					$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);
1643
					break;
1644
				default:
1645
					$error = $err_str . gettext('Unknown Response.');
1646
					/* FIXME: $data isn't in scope here */
1647
					/* $this->_debug($data); */
1648
					break;
1649
			}
1650
			$this->lastError = $error;
1651
			log_error($error);
1652
		}
1653

    
1654
		/*
1655
		 * Private Function (added 12 July 05) [beta]
1656
		 *   - Detect whether or not IP needs to be updated.
1657
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1658
		 *      | work with other systems. pfSense base is FreeBSD.
1659
		 */
1660
		function _detectChange() {
1661
			global $debug;
1662

    
1663
			if ($debug) {
1664
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
1665
			}
1666

    
1667
			$currentTime = time();
1668

    
1669
			$wan_ip = $this->_checkIP();
1670
			if ($wan_ip == 0) {
1671
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
1672
				return false;
1673
			}
1674
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
1675

    
1676
			if ($this->_useIPv6 == true) {
1677
				if (file_exists($this->_cacheFile_v6)) {
1678
					$contents = file_get_contents($this->_cacheFile_v6);
1679
					list($cacheIP, $cacheTime) = explode('|', $contents);
1680
					$this->_debug($cacheIP.'/'.$cacheTime);
1681
					$initial = false;
1682
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
1683
				} else {
1684
					conf_mount_rw();
1685
					$cacheIP = '::';
1686
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1687
					conf_mount_ro();
1688
					$cacheTime = $currentTime;
1689
					$initial = true;
1690
					$log_error .= gettext("No Cached IPv6 found.");
1691
				}
1692
			} else {
1693
				if (file_exists($this->_cacheFile)) {
1694
					$contents = file_get_contents($this->_cacheFile);
1695
					list($cacheIP, $cacheTime) = explode('|', $contents);
1696
					$this->_debug($cacheIP.'/'.$cacheTime);
1697
					$initial = false;
1698
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
1699
				} else {
1700
					conf_mount_rw();
1701
					$cacheIP = '0.0.0.0';
1702
					@file_put_contents($this->_cacheFile, "0.0.0.0|{$currentTime}");
1703
					conf_mount_ro();
1704
					$cacheTime = $currentTime;
1705
					$initial = true;
1706
					$log_error .= gettext("No Cached IP found.");
1707
				}
1708
			}
1709
			if ($this->_dnsVerboseLog) {
1710
				log_error($log_error);
1711
			}
1712

    
1713
			// Convert seconds = days * hr/day * min/hr * sec/min
1714
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1715

    
1716
			$needs_updating = FALSE;
1717
			/* lets determine if the item needs updating */
1718
			if ($cacheIP != $wan_ip) {
1719
				$needs_updating = true;
1720
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
1721
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
1722
			}
1723
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1724
				$needs_updating = true;
1725
				$this->_forceUpdateNeeded = true;
1726
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
1727
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1728
			}
1729
			if ($initial == true) {
1730
				$needs_updating = true;
1731
				$update_reason .= gettext("Initial update.");
1732
			}
1733

    
1734
			/*   finally if we need updating then store the
1735
			 *   new cache value and return true
1736
			 */
1737
			if ($needs_updating == true) {
1738
				if ($this->_dnsVerboseLog) {
1739
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1740
				}
1741
				return true;
1742
			}
1743

    
1744
			return false;
1745
		}
1746

    
1747
		/*
1748
		 * Private Function (added 16 July 05) [beta]
1749
		 *   - Writes debug information to a file.
1750
		 *   - This function is only called when a unknown response
1751
		 *   - status is returned from a DynDNS service provider.
1752
		 */
1753
		function _debug($data) {
1754
			global $g;
1755

    
1756
			if (!$g['debug']) {
1757
				return;
1758
			}
1759
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1760
			conf_mount_rw();
1761
			$file = fopen($this->_debugFile, 'a');
1762
			fwrite($file, $string);
1763
			fclose($file);
1764
			conf_mount_ro();
1765
		}
1766
		function _checkIP() {
1767
			global $debug;
1768

    
1769
			if ($debug) {
1770
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
1771
			}
1772

    
1773
			if ($this->_useIPv6 == true) {
1774
				$ip_address = get_interface_ipv6($this->_if);
1775
				if (!is_ipaddrv6($ip_address)) {
1776
					return 0;
1777
				}
1778
			} else {
1779
				$ip_address = get_interface_ip($this->_if);
1780
				if (!is_ipaddr($ip_address)) {
1781
					return 0;
1782
				}
1783
			}
1784
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1785
				$hosttocheck = "checkip.dyndns.org";
1786
				$try = 0;
1787
				while ($try < 3) {
1788
					$checkip = gethostbyname($hosttocheck);
1789
					if (is_ipaddr($checkip)) {
1790
						break;
1791
					}
1792
					$try++;
1793
				}
1794
				if ($try >= 3) {
1795
					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));
1796
					return 0;
1797
				}
1798
				$ip_ch = curl_init("http://{$checkip}");
1799
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1800
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1801
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1802
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1803
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1804
				if ($this->_useIPv6 == false) {
1805
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1806
				}
1807
				$ip_result_page = curl_exec($ip_ch);
1808
				curl_close($ip_ch);
1809
				$ip_result_decoded = urldecode($ip_result_page);
1810
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1811
				$ip_address = trim($matches[1]);
1812
				if (is_ipaddr($ip_address)) {
1813
					if ($this->_dnsVerboseLog) {
1814
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
1815
					}
1816
				} else {
1817
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
1818
					return 0;
1819
				}
1820
			} else {
1821
				if ($this->_dnsVerboseLog) {
1822
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
1823
				}
1824
			}
1825
			$this->_dnsIP = $ip_address;
1826

    
1827
			return $ip_address;
1828
		}
1829

    
1830
	}
1831

    
1832
?>
(16-16/65)