Project

General

Profile

Download (72.9 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: 01 April 2012
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
					/* http://docs.aws.amazon.com/Route53/latest/APIReference/Welcome.html */
683
					$reqdate = gmdate('D, d M Y H:i:s e');
684
					$httphead[] = array();
685
					$httphead[] = sprintf("Date: %s", $reqdate);
686
					/* to avoid having user to know their AWS Region, for now use V3 */
687
					$httphead[] = sprintf(
688
							"X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HMACSHA256,SignedHeaders=date,Signature=%s",
689
							$this->_dnsUser,
690
							base64_encode(hash_hmac("sha256", $reqdate, $this->_dnsPass, true))
691
					);					
692
					$apiurl = sprintf("https://route53.amazonaws.com/2013-04-01/hostedzone/%s/rrset", $this->_dnsZoneID);
693
					$xmlreq .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
694
					$xmlreq .= "<ChangeResourceRecordSetsRequest xmlns=\"https://route53.amazonaws.com/doc/2013-04-01/\">";
695
					$xmlreq .= "<ChangeBatch><Changes><Change>";
696
					$xmlreq .= "<Action>UPSERT</Action>";
697
					$xmlreq .= "<ResourceRecordSet>";
698
					$xmlreq .= sprintf("<Name>%s</Name>", $this->_dnsHost);
699
					$xmlreq .= "<Type>A</Type>";
700
					$xmlreq .= sprintf("<TTL>%d</TTL>", $this->_dnsTTL);
701
					$xmlreq .= sprintf("<ResourceRecords><ResourceRecord><Value>%s</Value></ResourceRecord></ResourceRecords>",
702
								$this->_dnsIP);
703
					$xmlreq .= "</ResourceRecordSet>";
704
					$xmlreq .= "</Change></Changes></ChangeBatch>";
705
					$xmlreq .= "</ChangeResourceRecordSetsRequest>";
706
					
707
					$httphead[] = "Content-Type: text/plain";
708
					$httphead[] = sprintf("Content-Length: %d", strlen($xmlreq));
709
					
710
					curl_setopt($ch, CURLOPT_HTTPHEADER, $httphead);
711
					if($this->_dnsVerboseLog){
712
						log_error(sprintf("Sending reuquest to: %s", $apiurl));
713
						foreach($httphead as $hv){
714
							log_error(sprintf("Header: %s", $hv));
715
						}
716
						log_error(sprintf("XMLPOST:\n%s\n\n", $xmlreq));
717
					}
718
					curl_setopt($ch, CURLOPT_URL, $apiurl);
719
					curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlreq);
720
					break;
721
				case 'custom':
722
				case 'custom-v6':
723
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
724
					if ($this->_dnsUser != '') {
725
						if ($this->_curlIpresolveV4) {
726
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
727
						}
728
						if ($this->_curlSslVerifypeer) {
729
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
730
						} else {
731
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
732
						}
733
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
734
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
735
					}
736
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
737
					if ($this->_dnsVerboseLog) {
738
						log_error(sprintf(gettext("Sending request to: %s"), $server));
739
					}
740
					curl_setopt($ch, CURLOPT_URL, $server);
741
					break;
742
				case 'cloudflare-v6':
743
				case 'cloudflare':
744
					$isv6 = ($this->_dnsService === 'cloudflare-v6');
745
					$recordType = $isv6 ? "AAAA" : "A";
746
					$needsIP = TRUE;
747
					$dnsServer ='api.cloudflare.com';
748
					$dnsHost = str_replace(' ', '', $this->_dnsHost);
749

    
750
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
751
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
752
						'X-Auth-Email: '.$this->_dnsUser.'',
753
						'X-Auth-Key: '.$this->_dnsPass.'',
754
						'Content-Type: application/json'
755
					));
756

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

    
888
		/*
889
		 * Private Function (added 12 July 2005) [beta]
890
		 *   Retrieve Update Status
891
		 */
892
		function _checkStatus($ch, $data) {
893
			if ($this->_dnsVerboseLog) {
894
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
895
			}
896
			$successful_update = false;
897
			$success_str = "(" . gettext("Success") . ") ";
898
			$error_str = "(" . gettext("Error") . ") ";
899
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
900

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

    
1540
			if ($successful_update == true) {
1541
				/* Write WAN IP to cache file */
1542
				$wan_ip = $this->_checkIP();
1543
				conf_mount_rw();
1544
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1545
					$currentTime = time();
1546
					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));
1547
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1548
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1549
				} else {
1550
					@unlink($this->_cacheFile);
1551
				}
1552
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1553
					$currentTime = time();
1554
					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));
1555
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1556
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1557
				} else {
1558
					@unlink($this->_cacheFile_v6);
1559
				}
1560
				conf_mount_ro();
1561
			}
1562
			$this->status = $status;
1563
			log_error($status);
1564
		}
1565

    
1566
		/*
1567
		 * Private Function (added 12 July 05) [beta]
1568
		 *   Return Error, Set Last Error, and Die.
1569
		 */
1570
		function _error($errorNumber = '1') {
1571
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1572
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1573
			switch ($errorNumber) {
1574
				case 0:
1575
					break;
1576
				case 2:
1577
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1578
					break;
1579
				case 3:
1580
					$error = $err_str . gettext('No Username Provided.');
1581
					break;
1582
				case 4:
1583
					$error = $err_str . gettext('No Password Provided.');
1584
					break;
1585
				case 5:
1586
					$error = $err_str . gettext('No Hostname Provided.');
1587
					break;
1588
				case 6:
1589
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
1590
					break;
1591
				case 7:
1592
					$error = $err_str . gettext('No Update URL Provided.');
1593
					break;
1594
				case 8:
1595
					$status = $err_str_r53 . gettext("Invalid ZoneID");
1596
					break;
1597
				case 9:
1598
					$status = $err_str_r53 . gettext("Invalid TTL");
1599
					break;
1600
				case 10:
1601
					$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);
1602
					break;
1603
				default:
1604
					$error = $err_str . gettext('Unknown Response.');
1605
					/* FIXME: $data isn't in scope here */
1606
					/* $this->_debug($data); */
1607
					break;
1608
			}
1609
			$this->lastError = $error;
1610
			log_error($error);
1611
		}
1612

    
1613
		/*
1614
		 * Private Function (added 12 July 05) [beta]
1615
		 *   - Detect whether or not IP needs to be updated.
1616
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1617
		 *      | work with other systems. pfSense base is FreeBSD.
1618
		 */
1619
		function _detectChange() {
1620
			global $debug;
1621

    
1622
			if ($debug) {
1623
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
1624
			}
1625

    
1626
			$currentTime = time();
1627

    
1628
			$wan_ip = $this->_checkIP();
1629
			if ($wan_ip == 0) {
1630
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
1631
				return false;
1632
			}
1633
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
1634

    
1635
			if ($this->_useIPv6 == true) {
1636
				if (file_exists($this->_cacheFile_v6)) {
1637
					$contents = file_get_contents($this->_cacheFile_v6);
1638
					list($cacheIP, $cacheTime) = explode('|', $contents);
1639
					$this->_debug($cacheIP.'/'.$cacheTime);
1640
					$initial = false;
1641
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
1642
				} else {
1643
					conf_mount_rw();
1644
					$cacheIP = '::';
1645
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1646
					conf_mount_ro();
1647
					$cacheTime = $currentTime;
1648
					$initial = true;
1649
					$log_error .= gettext("No Cached IPv6 found.");
1650
				}
1651
			} else {
1652
				if (file_exists($this->_cacheFile)) {
1653
					$contents = file_get_contents($this->_cacheFile);
1654
					list($cacheIP, $cacheTime) = explode(':', $contents);
1655
					$this->_debug($cacheIP.'/'.$cacheTime);
1656
					$initial = false;
1657
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
1658
				} else {
1659
					conf_mount_rw();
1660
					$cacheIP = '0.0.0.0';
1661
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1662
					conf_mount_ro();
1663
					$cacheTime = $currentTime;
1664
					$initial = true;
1665
					$log_error .= gettext("No Cached IP found.");
1666
				}
1667
			}
1668
			if ($this->_dnsVerboseLog) {
1669
				log_error($log_error);
1670
			}
1671

    
1672
			// Convert seconds = days * hr/day * min/hr * sec/min
1673
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1674

    
1675
			$needs_updating = FALSE;
1676
			/* lets determine if the item needs updating */
1677
			if ($cacheIP != $wan_ip) {
1678
				$needs_updating = true;
1679
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
1680
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
1681
			}
1682
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1683
				$needs_updating = true;
1684
				$this->_forceUpdateNeeded = true;
1685
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
1686
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1687
			}
1688
			if ($initial == true) {
1689
				$needs_updating = true;
1690
				$update_reason .= gettext("Initial update.");
1691
			}
1692

    
1693
			/*   finally if we need updating then store the
1694
			 *   new cache value and return true
1695
			 */
1696
			if ($needs_updating == true) {
1697
				if ($this->_dnsVerboseLog) {
1698
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1699
				}
1700
				return true;
1701
			}
1702

    
1703
			return false;
1704
		}
1705

    
1706
		/*
1707
		 * Private Function (added 16 July 05) [beta]
1708
		 *   - Writes debug information to a file.
1709
		 *   - This function is only called when a unknown response
1710
		 *   - status is returned from a DynDNS service provider.
1711
		 */
1712
		function _debug($data) {
1713
			global $g;
1714

    
1715
			if (!$g['debug']) {
1716
				return;
1717
			}
1718
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1719
			conf_mount_rw();
1720
			$file = fopen($this->_debugFile, 'a');
1721
			fwrite($file, $string);
1722
			fclose($file);
1723
			conf_mount_ro();
1724
		}
1725
		function _checkIP() {
1726
			global $debug;
1727

    
1728
			if ($debug) {
1729
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
1730
			}
1731

    
1732
			if ($this->_useIPv6 == true) {
1733
				$ip_address = get_interface_ipv6($this->_if);
1734
				if (!is_ipaddrv6($ip_address)) {
1735
					return 0;
1736
				}
1737
			} else {
1738
				$ip_address = get_interface_ip($this->_if);
1739
				if (!is_ipaddr($ip_address)) {
1740
					return 0;
1741
				}
1742
			}
1743
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1744
				$hosttocheck = "checkip.dyndns.org";
1745
				$try = 0;
1746
				while ($try < 3) {
1747
					$checkip = gethostbyname($hosttocheck);
1748
					if (is_ipaddr($checkip)) {
1749
						break;
1750
					}
1751
					$try++;
1752
				}
1753
				if ($try >= 3) {
1754
					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));
1755
					return 0;
1756
				}
1757
				$ip_ch = curl_init("http://{$checkip}");
1758
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1759
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1760
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1761
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1762
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1763
				if ($this->_useIPv6 == false) {
1764
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1765
				}
1766
				$ip_result_page = curl_exec($ip_ch);
1767
				curl_close($ip_ch);
1768
				$ip_result_decoded = urldecode($ip_result_page);
1769
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1770
				$ip_address = trim($matches[1]);
1771
				if (is_ipaddr($ip_address)) {
1772
					if ($this->_dnsVerboseLog) {
1773
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
1774
					}
1775
				} else {
1776
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
1777
					return 0;
1778
				}
1779
			} else {
1780
				if ($this->_dnsVerboseLog) {
1781
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
1782
				}
1783
			}
1784
			$this->_dnsIP = $ip_address;
1785

    
1786
			return $ip_address;
1787
		}
1788

    
1789
	}
1790

    
1791
?>
(16-16/64)