Project

General

Profile

Download (87.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * dyndns.class
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21

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

    
138
	class updatedns {
139
		var $_cacheFile;
140
		var $_cacheFile_v6;
141
		var $_debugFile;
142
		var $_UserAgent = 'phpDynDNS/0.7';
143
		var $_errorVerbosity = 0;
144
		var $_dnsService;
145
		var $_dnsUser;
146
		var $_dnsPass;
147
		var $_dnsHost;
148
		var $_dnsDomain;
149
		var $_FQDN;
150
		var $_dnsIP;
151
		var $_dnsWildcard;
152
		var $_dnsProxied;
153
		var $_dnsMX;
154
		var $_dnsBackMX;
155
		var $_dnsServer;
156
		var $_dnsPort;
157
		var $_dnsUpdateURL;
158
		var $_dnsZoneID;
159
		var $_dnsTTL;
160
		var $status;
161
		var $_debugID;
162
		var $_if;
163
		var $_dnsResultMatch;
164
		var $_dnsRequestIf;
165
		var $_dnsRequestIfIP;
166
		var $_dnsVerboseLog;
167
		var $_curlIpresolveV4;
168
		var $_curlSslVerifypeer;
169
		var $_dnsMaxCacheAgeDays;
170
		var $_dnsDummyUpdateDone;
171
		var $_forceUpdateNeeded;
172
		var $_useIPv6;
173
		var $_existingRecords;
174

    
175
		/*
176
		 * Public Constructor Function (added 12 July 05) [beta]
177
		 *   - Gets the dice rolling for the update.
178
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
179
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
180
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
181
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
182
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
183
		 */
184
		function updatedns ($dnsService = '', $dnsHost = '', $dnsDomain = '', $dnsUser = '', $dnsPass = '',
185
					$dnsWildcard = 'OFF', $dnsProxied = false, $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
186
					$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
187
					$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
188
					$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
189

    
190
			global $config, $g, $dyndns_split_domain_types;
191
			if (in_array($dnsService, $dyndns_split_domain_types)) {
192
				$this->_FQDN = $dnsHost . "." . $dnsDomain;
193
			} else {
194
				$this->_FQDN = $dnsHost;
195
			}
196

    
197
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.cache";
198
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}_v6.cache";
199
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.debug";
200

    
201
			$this->_curlIpresolveV4 = $curlIpresolveV4;
202
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
203
			$this->_dnsVerboseLog = $dnsVerboseLog;
204
			if ($this->_dnsVerboseLog) {
205
				log_error(gettext("Dynamic DNS: updatedns() starting"));
206
			}
207

    
208
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
209

    
210
			if (!$dnsService) $this->_error(2);
211
			switch ($dnsService) {
212
			case 'freedns':
213
			case 'freedns-v6':
214
				if (!$dnsHost) $this->_error(5);
215
				break;
216
			case "namecheap":
217
				if (!$dnsPass) $this->_error(4);
218
				if (!$dnsHost) $this->_error(5);
219
				if (!$dnsDomain) $this->_error(5);
220
				break;
221
			case "cloudflare-v6":
222
			case "cloudflare":
223
			case "gratisdns":
224
			case "hover":
225
				if (!$dnsUser) $this->_error(3);
226
				if (!$dnsPass) $this->_error(4);
227
				if (!$dnsHost) $this->_error(5);
228
				if (!$dnsDomain) $this->_error(5);
229
				break;
230
			case 'route53-v6':
231
			case 'route53':
232
				if (!$dnsZoneID) $this->_error(8);
233
				if (!$dnsTTL) $this->_error(9);
234
				break;
235
			case 'cloudns':
236
			case "godaddy":
237
			case "godaddy-v6":
238
				if (!$dnsUser) $this->_error(3);
239
				if (!$dnsPass) $this->_error(4);
240
				if (!$dnsHost) $this->_error(5);
241
				if (!$dnsDomain) $this->_error(5);
242
				if (!$dnsTTL) $this->_error(9);
243
				break;
244
			case 'custom':
245
				if (!$dnsUpdateURL) $this->_error(7);
246
				break;
247
			default:
248
				if (!$dnsUser) $this->_error(3);
249
				if (!$dnsPass) $this->_error(4);
250
				if (!$dnsHost) $this->_error(5);
251
			}
252

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

    
293
			// Ensure that we were able to lookup the IP
294
			if (!is_ipaddr($this->_dnsIP)) {
295
				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));
296
				unlock($dyndnslck);
297
				return;
298
			}
299

    
300
			$this->_debugID = rand(1000000, 9999999);
301

    
302
			if ($forceUpdate == false && $this->_detectChange() == false) {
303
				$this->_error(10);
304
			} else {
305
				switch ($this->_dnsService) {
306
					case 'glesys':
307
					case 'dnsomatic':
308
					case 'dyndns':
309
					case 'dyndns-static':
310
					case 'dyndns-custom':
311
					case 'dhs':
312
					case 'noip':
313
					case 'noip-free':
314
					case 'easydns':
315
					case 'hn':
316
					case 'zoneedit':
317
					case 'dyns':
318
					case 'ods':
319
					case 'freedns':
320
					case 'freedns-v6':
321
					case 'loopia':
322
					case 'staticcling':
323
					case 'dnsexit':
324
					case 'custom':
325
					case 'custom-v6':
326
					case 'opendns':
327
					case 'namecheap':
328
					case 'he-net':
329
					case 'he-net-v6':
330
					case 'duiadns':
331
					case 'duiadns-v6':
332
					case 'selfhost':
333
					case 'he-net-tunnelbroker':
334
					case 'route53':
335
					case 'route53-v6':
336
					case 'cloudflare':
337
					case 'cloudflare-v6':
338
					case 'eurodns':
339
					case 'gratisdns':
340
					case 'ovh-dynhost':
341
					case 'citynetwork':
342
					case 'dnsimple':
343
					case 'googledomains':
344
					case 'dnsmadeeasy':
345
					case 'spdyn':
346
					case 'spdyn-v6':
347
					case 'all-inkl':
348
					case 'cloudns':
349
					case 'hover':
350
					case 'godaddy':
351
					case 'godaddy-v6':
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
					case 'dreamhost':
363
					case 'dreamhost-v6':
364
						$this->_lookup_current();
365
						if (isset($this->status)) {
366
							return;
367
						}
368
						foreach ($this->_existingRecords as $record) {
369
							$this->_remove($record['existing_val']);
370
							$this->_update();
371
						}
372
						break;
373
					default:
374
						$this->_error(6);
375
						break;
376
				}
377
			}
378

    
379
			unlock($dyndnslck);
380
		}
381

    
382
		/*
383
		 * Private Function (added 12 July 05) [beta]
384
		 *   Send Update To Selected Service.
385
		 */
386
		function _update() {
387

    
388
			if ($this->_dnsVerboseLog) {
389
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
390
			}
391

    
392
			if (strstr($this->_dnsRequestIf, "_vip")) {
393
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
394
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
395
			} else {
396
				$realparentif = $this->_dnsRequestIf;
397
			}
398

    
399
			$ch = curl_init();
400

    
401
			if ($this->_useIPv6 == false) {
402
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
403
			}
404

    
405
			if ($this->_dnsService != 'ods') {
406
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
407
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
408
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
409
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
410
			}
411

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

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

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

    
756
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
757
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
758
						'X-Auth-Email: '.$this->_dnsUser.'',
759
						'X-Auth-Key: '.$this->_dnsPass.'',
760
						'Content-Type: application/json'
761
					));
762

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

    
906
					//step 1: login to API
907
					$post_data['username'] = $this->_dnsUser;
908
					$post_data['password'] = $this->_dnsPass;
909
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
910
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/login");
911
					curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies
912
					$output = curl_exec($ch);
913

    
914
					//extract the cookies
915
					preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies);
916
					if( count($cookies[1]) > 0 ){
917
						$cookie_data = implode("; ",$cookies[1]);
918
					}
919

    
920
					//step 2: find the id of the A record
921
					$post_data = null;
922
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
923
					curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
924
					curl_setopt($ch, CURLOPT_HEADER, 0);
925
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns");
926
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
927

    
928
					$output = curl_exec($ch);
929
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{\"id\":\"([^\"]*?)\",\"name\":\"{$this->_dnsHost}\".*?\$/", $output, $hostID);
930
					$hostID = $hostID[1];
931
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{[^\}]*?\"name\":\"{$this->_dnsHost}\".*?content\":\"([^\"]*?)\".*?\$/", $output, $hostIP);
932
					$hostIP = $hostIP[1];
933

    
934
					//step 3: update the IP
935
					if ($hostID) {
936
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
937
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
938
						curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
939
						$post_data['content'] = $this->_dnsIP;
940
						curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
941
						curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
942
						curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns/{$hostID}");
943
						log_error("HostID:{$hostID}, OldIP:{$hostIP}");
944
					}
945
					break;
946
				case 'dreamhost':
947
				case 'dreamhost-v6':
948
					$needsIP = TRUE;
949
					$isv6 = ($this->_dnsService === 'dreamhost-v6');
950
					$server = 'https://api.dreamhost.com/';
951
					$post_data['key'] = $this->_dnsPass;
952
					$post_data['unique_id'] = uniqid($this->_dnsHost);
953
					$post_data['cmd'] = 'dns-add_record';
954
					$post_data['format'] = 'json';
955
					$post_data['value'] = $this->_dnsIP;
956
					$post_data['record'] = $this->_dnsHost;
957
					$post_data['type'] = $isv6 ? 'AAAA' : 'A';
958
					$post_data['comment'] = "Updated by pfSense:$this->_dnsUser on ".date('c');
959
					$port = "";
960
					if ($this->_dnsServer) {
961
						$server = $this->_dnsServer;
962
					}
963
					if ($this->_dnsPort) {
964
						$port = ":" . $this->_dnsPort;
965
					}
966
					curl_setopt($ch, CURLOPT_URL, $server . $port);
967
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
968
					break;
969
				case 'cloudns':
970
					/* Uses ClouDNS REST API
971
					   Requires auth-id or sub-auth-id or sub-auth-user */
972
					// Step 1: Find the Record ID
973
					$url = 'https://api.cloudns.net/dns/records.json';
974
					$post_data['auth-id'] = $this->_dnsUser;
975
					$post_data['auth-password'] = $this->_dnsPass;
976
					$post_data['domain-name'] = $this->_dnsDomain;
977
					$post_data['host'] = $this->_dnsHost;
978
					$post_data['type'] = 'a';
979
					curl_setopt($ch, CURLOPT_URL, $url);
980
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
981
					$output = json_decode(curl_exec($ch));
982
					$recordID = key(get_object_vars($output));
983

    
984
					// Step 2: Set the record
985
					$needsIP = TRUE;
986
					$url = 'https://api.cloudns.net/dns/mod-record.json';
987
					$post_data = array();
988
					$post_data['auth-id'] = $this->_dnsUser;
989
					$post_data['auth-password'] = $this->_dnsPass;
990
					$post_data['domain-name'] = $this->_dnsDomain;
991
					$post_data['record-id'] = $recordID;
992
					$post_data['host'] = $this->_dnsHost;
993
					$post_data['record'] = $this->_dnsIP;
994
					$post_data['ttl'] = $this->_dnsTTL;
995
					curl_setopt($ch, CURLOPT_URL, $url);
996
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
997
					break;
998

    
999
				default:
1000
					break;
1001
			}
1002
			if ($this->_dnsService != 'ods') {
1003
				curl_setopt($ch, CURLOPT_HEADER, 1);
1004
				$response = curl_exec($ch);
1005
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1006
				$header = substr($response, 0, $header_size);
1007
				$data = substr($response, $header_size);
1008
				$this->_checkStatus($ch, $data, $header);
1009
				@curl_close($ch);
1010
			}
1011
		}
1012

    
1013
		/**
1014
		 * Private Function (added 23 Feb 17)
1015
		 *   Send Removal To Selected Service.
1016
		 *
1017
		 *   Some services do not perform an inplace upgrade.  If they do not then the solution
1018
		 *   is to remove the existing record and add a new record.
1019
		 *
1020
		 * @param unknown $existing_ip If required, an existing IP address for the record.
1021
		 */
1022
		function _remove($existing_ip = NULL) {
1023
			$remove_allowed = false;
1024
			if ($this->_dnsVerboseLog) {
1025
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _remove() starting.'), $this->_dnsService, $this->_FQDN));
1026
			}
1027

    
1028
			if (strstr($this->_dnsRequestIf, "_vip")) {
1029
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
1030
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
1031
			} else {
1032
				$realparentif = $this->_dnsRequestIf;
1033
			}
1034

    
1035
			$ch = curl_init();
1036

    
1037
			if ($this->_useIPv6 == false) {
1038
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1039
			}
1040

    
1041
			curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1042
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
1043
			curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
1044
			curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
1045

    
1046
			switch ($this->_dnsService) {
1047
			case 'dreamhost':
1048
			case 'dreamhost-v6':
1049
				$server = 'https://api.dreamhost.com/';
1050
				$post_data['key'] = $this->_dnsPass;
1051
				$post_data['unique_id'] = uniqid($this->_dnsHost);
1052
				$post_data['cmd'] = 'dns-remove_record';
1053
				$post_data['format'] = 'json';
1054
				$post_data['value'] = $existing_ip;
1055
				$post_data['record'] = $this->_dnsHost;
1056
				$isv6 = ($this->_dnsService === 'dreamhost-v6');
1057
				$post_data['type'] = $isv6 ? 'AAAA' : 'A';
1058
				$port = "";
1059
				if ($this->_dnsServer) {
1060
					$server = $this->_dnsServer;
1061
				}
1062
				if ($this->_dnsPort) {
1063
					$port = ":" . $this->_dnsPort;
1064
				}
1065
				curl_setopt($ch, CURLOPT_URL, $server . $port);
1066
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1067
				$remove_allowed = true;
1068
				break;
1069
			default:
1070
				break;
1071
			}
1072
			if ($remove_allowed) {
1073
				curl_setopt($ch, CURLOPT_HEADER, 1);
1074
				$response = curl_exec($ch);
1075
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1076
				$header = substr($response, 0, $header_size);
1077
				$data = substr($response, $header_size);
1078
				$this->_checkStatus($ch, $data, $header);
1079
				@curl_close($ch);
1080
			}
1081
		}
1082

    
1083
		/**
1084
		 * Private Function (added 23 Feb 17)
1085
		 * Retrieves current DNS records from an external API source.
1086
		 *
1087
		 * Some services cannot perform new operations without the caller
1088
		 * providing existing record information.
1089
		 */
1090
		function _lookup_current() {
1091
			$lookup_allowed = false;
1092
			if ($this->_dnsVerboseLog) {
1093
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _listCurrent() starting.'), $this->_dnsService, $this->_FQDN));
1094
			}
1095

    
1096
			if (strstr($this->_dnsRequestIf, "_vip")) {
1097
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
1098
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
1099
			} else {
1100
				$realparentif = $this->_dnsRequestIf;
1101
			}
1102

    
1103
			$ch = curl_init();
1104

    
1105
			if ($this->_useIPv6 == false) {
1106
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1107
			}
1108

    
1109
			curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1110
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
1111
			curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
1112
			curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
1113

    
1114
			switch ($this->_dnsService) {
1115
			case 'dreamhost':
1116
			case 'dreamhost-v6':
1117
				$server = 'https://api.dreamhost.com/';
1118
				$post_data['key'] = $this->_dnsPass;
1119
				$post_data['unique_id'] = uniqid($this->_dnsHost);
1120
				$post_data['cmd'] = 'dns-list_records';
1121
				$post_data['format'] = 'json';
1122
				$port = "";
1123
				if ($this->_dnsServer) {
1124
					$server = $this->_dnsServer;
1125
				}
1126
				if ($this->_dnsPort) {
1127
					$port = ":" . $this->_dnsPort;
1128
				}
1129
				curl_setopt($ch, CURLOPT_URL, $server . $port);
1130
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1131
				$lookup_allowed = true;
1132
				break;
1133
			default:
1134
				break;
1135
			}
1136
			if ($lookup_allowed) {
1137
				curl_setopt($ch, CURLOPT_HEADER, 1);
1138
				$response = curl_exec($ch);
1139
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1140
				$header = substr($response, 0, $header_size);
1141
				$data = substr($response, $header_size);
1142
				$this->_checkLookupStatus($ch, $data, $header);
1143
				@curl_close($ch);
1144
			}
1145
		}
1146

    
1147
		/*
1148
		 * Private Function (added 23 Feb 17)
1149
		 *   Retrieve Lookup Status from the provided data and/or header
1150
		 */
1151
		function _checkLookupStatus($ch, $data, $header) {
1152
			if ($this->_dnsVerboseLog) {
1153
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() starting.'), $this->_dnsService, $this->_FQDN));
1154
			}
1155
			$success_str = "(" . gettext("Success") . ") ";
1156
			$error_str = "(" . gettext("Error") . ") ";
1157
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
1158

    
1159
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
1160
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
1161
				log_error($status);
1162
				$this->status = $status;
1163
				return;
1164
			}
1165
			switch ($this->_dnsService) {
1166
			case 'dreamhost':
1167
			case 'dreamhost-v6':
1168
				$result = json_decode($data,true);
1169
				if($result["result"] != "success") {
1170
					log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1171
					$this->_debug($data);
1172
					return;
1173
				} else {
1174
					foreach($result["data"] as $key => $row) {
1175
						if($row["record"] == $this->_dnsHost &&
1176
								(($row["type"] == "A" && !$this->_useIPv6)
1177
										|| ($row["type"] == "AAAA" && $this->_useIPv6)
1178
								)) {
1179
							if($row["editable"] == 0) {
1180
								log_error($status_intro . "host " . $this->_dnsHost . " is not editable.");
1181
								continue;
1182
							}
1183
							$this->_existingRecords[]=array("record"=>$row["type"], "type"=>$row["type"], "existing_val"=>$row["value"]);
1184
						}
1185
					}
1186
				}
1187
				if (!is_array($this->_existingRecords)){
1188
					if ($this->_dnsVerboseLog) {
1189
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() ending.  No matching records found.'), $this->_dnsService, $this->_FQDN));
1190
					}
1191
				}
1192
				break;
1193
			default:
1194
				break;
1195
			}
1196
		}
1197

    
1198
		/*
1199
		 * Private Function (added 12 July 2005) [beta]
1200
		 *   Retrieve Update Status
1201
		 */
1202
		function _checkStatus($ch, $data, $header) {
1203
			if ($this->_dnsVerboseLog) {
1204
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
1205
			}
1206
			$successful_update = false;
1207
			$success_str = "(" . gettext("Success") . ") ";
1208
			$error_str = "(" . gettext("Error") . ") ";
1209
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
1210

    
1211
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
1212
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
1213
				log_error($status);
1214
				$this->status = $status;
1215
				return;
1216
			}
1217
			switch ($this->_dnsService) {
1218
				case 'glesys':
1219
					$status_intro = "GleSYS ({$this->_dnsHost}): ";
1220
					if (preg_match('/Record updated/i', $data)) {
1221
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1222
						$successful_update = true;
1223
					} else {
1224
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1225
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1226
						$this->_debug($data);
1227
					}
1228
					break;
1229
				case 'dnsomatic':
1230
					$status_intro = "DNS-O-Matic ({$this->_dnsHost}): ";
1231
					if (preg_match('/badauth/i', $data)) {
1232
						$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.");
1233
					} else if (preg_match('/notfqdn /i', $data)) {
1234
						$status = $status_intro . gettext("The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.");
1235
					} else if (preg_match('/nohost/i', $data)) {
1236
						$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.");
1237
					} else if (preg_match('/numhost/i', $data)) {
1238
						$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.");
1239
					} else if (preg_match('/abuse/i', $data)) {
1240
						$status = $status_intro . gettext("The hostname is blocked for update abuse.");
1241
					} else if (preg_match('/good/i', $data)) {
1242
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1243
						$successful_update = true;
1244
					} else if (preg_match('/dnserr/i', $data)) {
1245
						$status = $status_intro . gettext("DNS error encountered. Stop updating for 30 minutes.");
1246
					} else {
1247
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1248
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1249
						$this->_debug($data);
1250
					}
1251
					break;
1252
				case 'citynetwork':
1253
					if (preg_match('/notfqdn/i', $data)) {
1254
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1255
					} else if (preg_match('/nohost/i', $data)) {
1256
						$status = $status_intro . $error_str . gettext("No such host");
1257
					} else if (preg_match('/nochg/i', $data)) {
1258
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1259
						$successful_update = true;
1260
					} else if (preg_match('/good/i', $data)) {
1261
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1262
						$successful_update = true;
1263
					} else if (preg_match('/badauth/i', $data)) {
1264
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1265
					} else {
1266
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1267
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1268
						$this->_debug($data);
1269
					}
1270
					break;
1271
				case 'ovh-dynhost':
1272
				case 'dyndns':
1273
					if (preg_match('/notfqdn/i', $data)) {
1274
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1275
					} else if (preg_match('/nochg/i', $data)) {
1276
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1277
						$successful_update = true;
1278
					} else if (preg_match('/good/i', $data)) {
1279
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1280
						$successful_update = true;
1281
					} else if (preg_match('/noauth/i', $data)) {
1282
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1283
					} else {
1284
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1285
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1286
						$this->_debug($data);
1287
					}
1288
					break;
1289
				case 'dyndns-static':
1290
					if (preg_match('/notfqdn/i', $data)) {
1291
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
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 if (preg_match('/good/i', $data)) {
1296
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1297
						$successful_update = true;
1298
					} else if (preg_match('/noauth/i', $data)) {
1299
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1300
					} else {
1301
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1302
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1303
						$this->_debug($data);
1304
					}
1305
					break;
1306
				case 'dyndns-custom':
1307
					if (preg_match('/notfqdn/i', $data)) {
1308
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1309
					} else if (preg_match('/nochg/i', $data)) {
1310
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1311
						$successful_update = true;
1312
					} else if (preg_match('/good/i', $data)) {
1313
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1314
						$successful_update = true;
1315
					} else if (preg_match('/noauth/i', $data)) {
1316
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1317
					} else {
1318
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1319
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1320
						$this->_debug($data);
1321
					}
1322
					break;
1323
				case 'dhs':
1324
					break;
1325
				case 'noip':
1326
				case 'noip-free':
1327
					list($ip, $code) = explode(":", $data);
1328
					switch ($code) {
1329
						case 0:
1330
							$status = $status_intro . $success_str . gettext("IP address is current, no update performed.");
1331
							$successful_update = true;
1332
							break;
1333
						case 1:
1334
							$status = $status_intro . $success_str . gettext("DNS hostname update successful.");
1335
							$successful_update = true;
1336
							break;
1337
						case 2:
1338
							$status = $status_intro . $error_str . gettext("Hostname supplied does not exist.");
1339
							break;
1340
						case 3:
1341
							$status = $status_intro . $error_str . gettext("Invalid Username.");
1342
							break;
1343
						case 4:
1344
							$status = $status_intro . $error_str . gettext("Invalid Password.");
1345
							break;
1346
						case 5:
1347
							$status = $status_intro . $error_str . gettext("Too many updates sent.");
1348
							break;
1349
						case 6:
1350
							$status = $status_intro . $error_str . gettext("Account disabled due to violation of No-IP terms of service.");
1351
							break;
1352
						case 7:
1353
							$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.");
1354
							break;
1355
						case 8:
1356
							$status = $status_intro . $error_str . gettext("Disabled / Locked Hostname.");
1357
							break;
1358
						case 9:
1359
							$status = $status_intro . $error_str . gettext("Host updated is configured as a web redirect and no update was performed.");
1360
							break;
1361
						case 10:
1362
							$status = $status_intro . $error_str . gettext("Group supplied does not exist.");
1363
							break;
1364
						case 11:
1365
							$status = $status_intro . $success_str . gettext("DNS group update is successful.");
1366
							$successful_update = true;
1367
							break;
1368
						case 12:
1369
							$status = $status_intro . $success_str . gettext("DNS group is current, no update performed.");
1370
							$successful_update = true;
1371
							break;
1372
						case 13:
1373
							$status = $status_intro . $error_str . gettext("Update client support not available for supplied hostname or group.");
1374
							break;
1375
						case 14:
1376
							$status = $status_intro . $error_str . gettext("Hostname supplied does not have offline settings configured.");
1377
							break;
1378
						case 99:
1379
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1380
							break;
1381
						case 100:
1382
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1383
							break;
1384
						default:
1385
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1386
							$this->_debug(gettext("Unknown Response:") . " " . $data);
1387
							break;
1388
					}
1389
					break;
1390
				case 'easydns':
1391
					if (preg_match('/NOACCESS/i', $data)) {
1392
						$status = $status_intro . $error_str . gettext("Authentication Failed: Username and/or Password was Incorrect.");
1393
					} else if (preg_match('/NOSERVICE/i', $data)) {
1394
						$status = $status_intro . $error_str . gettext("No Service: Dynamic DNS Service has been disabled for this domain.");
1395
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
1396
						$status = $status_intro . $error_str . gettext("Illegal Input: Self-Explanatory");
1397
					} else if (preg_match('/TOOSOON/i', $data)) {
1398
						$status = $status_intro . $error_str . gettext("Too Soon: Not Enough Time Has Elapsed Since Last Update");
1399
					} else if (preg_match('/NOERROR/i', $data)) {
1400
						$status = $status_intro . $success_str . gettext("IP Updated Successfully!");
1401
						$successful_update = true;
1402
					} else {
1403
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1404
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1405
						$this->_debug($data);
1406
					}
1407
					break;
1408
				case 'hn':
1409
					/* FIXME: add checks */
1410
					break;
1411
				case 'zoneedit':
1412
					if (preg_match('/799/i', $data)) {
1413
						$status = $status_intro . "(" . gettext("Error 799") . ") " . gettext("Update Failed!");
1414
					} else if (preg_match('/700/i', $data)) {
1415
						$status = $status_intro . "(" . gettext("Error 700") . ") " . gettext("Update Failed!");
1416
					} else if (preg_match('/200/i', $data)) {
1417
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1418
						$successful_update = true;
1419
					} else if (preg_match('/201/i', $data)) {
1420
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1421
						$successful_update = true;
1422
					} else {
1423
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1424
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1425
						$this->_debug($data);
1426
					}
1427
					break;
1428
				case 'dyns':
1429
					if (preg_match("/400/i", $data)) {
1430
						$status = $status_intro . $error_str . gettext("Bad Request - The URL was malformed. Required parameters were not provided.");
1431
					} else if (preg_match('/402/i', $data)) {
1432
						$status = $status_intro . $error_str . gettext("Update Too Soon - Attempted to update too quickly since last change.");
1433
					} else if (preg_match('/403/i', $data)) {
1434
						$status = $status_intro . $error_str . gettext("Database Error - There was a server-sided database error.");
1435
					} else if (preg_match('/405/i', $data)) {
1436
						$status = $status_intro . $error_str . sprintf(gettext('Hostname Error - The hostname (%1$s) doesn\'t belong to user (%2$s).'), $this->_dnsHost, $this->_dnsUser);
1437
					} else if (preg_match('/200/i', $data)) {
1438
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1439
						$successful_update = true;
1440
					} else {
1441
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1442
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1443
						$this->_debug($data);
1444
					}
1445
					break;
1446
				case 'ods':
1447
					if (preg_match("/299/i", $data)) {
1448
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1449
						$successful_update = true;
1450
					} else {
1451
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1452
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1453
						$this->_debug($data);
1454
					}
1455
					break;
1456
				case 'freedns':
1457
				case 'freedns-v6':
1458
					if (preg_match("/has not changed./i", $data)) {
1459
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1460
						$successful_update = true;
1461
					} else if (preg_match("/Updated/i", $data)) {
1462
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1463
						$successful_update = true;
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 'dnsexit':
1471
					if (preg_match("/is the same/i", $data)) {
1472
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1473
						$successful_update = true;
1474
					} else if (preg_match("/Success/i", $data)) {
1475
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1476
						$successful_update = true;
1477
					} else {
1478
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1479
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1480
						$this->_debug($data);
1481
					}
1482
					break;
1483
				case 'loopia':
1484
					if (preg_match("/nochg/i", $data)) {
1485
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1486
						$successful_update = true;
1487
					} else if (preg_match("/good/i", $data)) {
1488
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1489
						$successful_update = true;
1490
					} else if (preg_match('/badauth/i', $data)) {
1491
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1492
					} else {
1493
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1494
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1495
						$this->_debug($data);
1496
					}
1497
					break;
1498
				case 'opendns':
1499
					if (preg_match('/badauth/i', $data)) {
1500
						$status = $status_intro . $error_str . gettext("Not a valid username or password!");
1501
					} else if (preg_match('/nohost/i', $data)) {
1502
						$status = $status_intro . $error_str . gettext("Hostname specified does not exist.");
1503
						$successful_update = true;
1504
					} else if (preg_match('/good/i', $data)) {
1505
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1506
						$successful_update = true;
1507
					} else if (preg_match('/yours/i', $data)) {
1508
						$status = $status_intro . $error_str . gettext("Hostname specified exists, but not under the username specified.");
1509
					} else if (preg_match('/abuse/i', $data)) {
1510
						$status = $status_intro . $error_str . gettext("Updating too frequently, considered abuse.");
1511
					} else {
1512
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1513
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1514
						$this->_debug($data);
1515
					}
1516
					break;
1517
				case 'staticcling':
1518
					if (preg_match("/invalid ip/i", $data)) {
1519
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1520
					} else if (preg_match('/required info missing/i', $data)) {
1521
						$status = $status_intro . $error_str . gettext("Bad Request - Required parameters were not provided.");
1522
					} else if (preg_match('/invalid characters/i', $data)) {
1523
						$status = $status_intro . $error_str . gettext("Bad Request - Illegal characters in either the username or the password.");
1524
					} else if (preg_match('/bad password/i', $data)) {
1525
						$status = $status_intro . $error_str . gettext("Invalid password.");
1526
					} else if (preg_match('/account locked/i', $data)) {
1527
						$status = $status_intro . $error_str . gettext("This account has been administratively locked.");
1528
					} else if (preg_match('/update too frequent/i', $data)) {
1529
						$status = $status_intro . $error_str . gettext("Updating too frequently.");
1530
					} else if (preg_match('/DB error/i', $data)) {
1531
						$status = $status_intro . $error_str . gettext("Server side error.");
1532
					} else if (preg_match('/success/i', $data)) {
1533
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1534
						$successful_update = true;
1535
					} else {
1536
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1537
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1538
						$this->_debug($data);
1539
					}
1540
					break;
1541
				case 'namecheap':
1542
					$tmp = str_replace("^M", "", $data);
1543
					$ncresponse = @xml2array($tmp);
1544
					if (preg_match("/internal server error/i", $data)) {
1545
						$status = $status_intro . $error_str . gettext("Server side error.");
1546
					} else if (preg_match("/request is badly formed/i", $data)) {
1547
						$status = $status_intro . $error_str . gettext("Badly Formed Request (check the settings).");
1548
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1549
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1550
						$successful_update = true;
1551
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1552
						$status = $status_intro . $error_str . implode(", ", $ncresponse["interface-response"]["errors"]);
1553
						$successful_update = true;
1554
					} else {
1555
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1556
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1557
						$this->_debug($data);
1558
					}
1559
					break;
1560
				case 'duiadns':
1561
				case 'duiadns-v6':
1562
					if (preg_match("/error/i", $data)) {
1563
						$status = $status_intro . $error_str . gettext("Server side error.");
1564
					} else if (preg_match('/nohost/i', $data)) {
1565
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1566
					} else if (preg_match('/badauth/i', $data)) {
1567
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1568
					} else if (preg_match('/good/i', $data)) {
1569
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1570
						$successful_update = true;
1571
					} else if (preg_match('/nochg/i', $data)) {
1572
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1573
						$successful_update = true;
1574
					} else {
1575
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1576
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1577
						$this->_debug($data);
1578
					}
1579
					break;
1580
				case 'he-net':
1581
				case 'he-net-v6':
1582
					if (preg_match("/badip/i", $data)) {
1583
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1584
					} else if (preg_match('/nohost/i', $data)) {
1585
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1586
					} else if (preg_match('/badauth/i', $data)) {
1587
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1588
					} else if (preg_match('/good/i', $data)) {
1589
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1590
						$successful_update = true;
1591
					} else if (preg_match('/nochg/i', $data)) {
1592
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1593
						$successful_update = true;
1594
					} else {
1595
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1596
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1597
						$this->_debug($data);
1598
					}
1599
					break;
1600
				case 'he-net-tunnelbroker':
1601
					/*
1602
					-ERROR: Missing parameter(s).
1603
					-ERROR: Invalid API key or password
1604
					-ERROR: Tunnel not found
1605
					-ERROR: Another tunnel exists for this IP.
1606
					-ERROR: This tunnel is already associated with this IP address
1607
					+OK: Tunnel endpoint updated to: x.x.x.x
1608
					*/
1609
					if (preg_match("/Missing parameter/i", $data)) {
1610
						$status = $status_intro . $error_str . gettext("Bad Request - Missing/Invalid Parameters.");
1611
					} else if (preg_match('/Tunnel not found/i', $data)) {
1612
						$status = $status_intro . $error_str . gettext("Bad Request - Invalid Tunnel ID.");
1613
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1614
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1615
					} else if (preg_match('/OK:/i', $data)) {
1616
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1617
						$successful_update = true;
1618
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1619
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1620
						$successful_update = true;
1621
					} else {
1622
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1623
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1624
						$this->_debug($data);
1625
					}
1626
					break;
1627
				case 'selfhost':
1628
					if (preg_match('/notfqdn/i', $data)) {
1629
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1630
					} else if (preg_match('/nochg/i', $data)) {
1631
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1632
						$successful_update = true;
1633
					} else if (preg_match('/good/i', $data)) {
1634
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1635
						$successful_update = true;
1636
					} else if (preg_match('/noauth/i', $data)) {
1637
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1638
					} else {
1639
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1640
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1641
						$this->_debug($data);
1642
					}
1643
					break;
1644
				case 'route53':
1645
				case 'route53-v6':
1646
					if(preg_match('/ErrorResponse/', $data)){
1647
						$status = $status_intro . $error_str . gettext("Route53 API call failed");
1648
						log_error(sprintf("error message: %s", $data));
1649
						$status_update = false;
1650
					} else {
1651
						$status = $status_intro . $success_str . gettext("IP address changed successfully");
1652
						$successful_update = true;
1653
					}
1654
					break;
1655
				case 'custom':
1656
				case 'custom-v6':
1657
					$successful_update = false;
1658
					if ($this->_dnsResultMatch == "") {
1659
						$successful_update = true;
1660
					} else {
1661
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1662
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1663
						foreach ($matches as $match) {
1664
							$match= str_replace("\\|", "|", $match);
1665
							if (strcmp($match, trim($data, "\t\n\r")) == 0) {
1666
								$successful_update = true;
1667
							}
1668
						}
1669
						unset ($matches);
1670
					}
1671
					if ($successful_update == true) {
1672
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1673
					} else {
1674
						$status = $status_intro . $error_str . gettext("Result did not match.") . " [" . $data . "]";
1675
					}
1676
					break;
1677
				case 'cloudflare-v6':
1678
				case 'cloudflare':
1679
					$output = json_decode($data);
1680
					if ($output->result->content === $this->_dnsIP) {
1681
						$status = $status_intro . $success_str . sprintf(gettext('%1$s updated to %2$s'), $this->_dnsHost, $this->_dnsIP);
1682
						$successful_update = true;
1683
					} elseif ($output->errors[0]->code === 9103) {
1684
						$status = $status_intro . $error_str . gettext("Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.");
1685
					} elseif (($output->success) && (!$output->result[0]->id)) {
1686
						$status = $status_intro . $error_str . gettext("Zone or Host ID was not found, check the hostname.");
1687
					} else {
1688
						$status = $status_intro . gettext("UNKNOWN ERROR") . " - " . $output->errors[0]->message;
1689
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1690
					}
1691
					break;
1692
				case 'eurodns':
1693
					if (preg_match('/notfqdn/i', $data)) {
1694
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1695
					} else if (preg_match('/nochg/i', $data)) {
1696
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1697
						$successful_update = true;
1698
					} else if (preg_match('/good/i', $data)) {
1699
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1700
						$successful_update = true;
1701
					} else if (preg_match('/badauth/i', $data)) {
1702
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1703
					} else {
1704
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1705
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1706
						$this->_debug($data);
1707
					}
1708
					break;
1709
				case 'gratisdns':
1710
					if (preg_match('/Forkerte værdier/i', $data)) {
1711
						$status = $status_intro . $error_str . gettext("Wrong values - Update could not be completed.");
1712
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1713
						$status = $status_intro . $error_str . gettext("Unknown username - User does not exist.");
1714
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1715
						$status = $status_intro . $error_str . gettext("Wrong password - Remember password is case sensitive.");
1716
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1717
						$status = $status_intro . $error_str . gettext("User unable to administer the selected domain.");
1718
					} else if (preg_match('/OK/i', $data)) {
1719
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1720
						$successful_update = true;
1721
					} else {
1722
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1723
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1724
						$this->_debug($data);
1725
					}
1726
					break;
1727
				case 'dnsimple':
1728
					/* Responds with HTTP 200 on success.
1729
					   Responds with HTTP 4xx on error.
1730
					   Returns JSON data as body */
1731
;
1732
					if (preg_match("/\s200\sOK/i", $header)) {
1733
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1734
						$successful_update = true;
1735
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1736
						$arrbody = json_decode($data, true);
1737
						$message = $arrbody['message'] . ".";
1738
						if (isset($arrbody['errors']['content'])) {
1739
							foreach ($arrbody['errors']['content'] as $key => $content) {
1740
								$message .= " " . $content . ".";
1741
							}
1742
						}
1743
						$status = $status_intro . $error_str . $message;
1744
					} else {
1745
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1746
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1747
						$this->_debug($data);
1748
					}
1749
					break;
1750
				case 'godaddy':
1751
				case 'godaddy-v6':
1752
					/* Responds with HTTP 200 on success.
1753
					   Responds with HTTP 4xx or  on error.
1754
					   Returns JSON data as body */
1755
;
1756
					if (preg_match("/\s200\sOK/i", $header)) {
1757
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1758
						$successful_update = true;
1759
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1760
						$arrbody = json_decode($data, true);
1761
						$message = $arrbody['message'] . ".";
1762
						if (isset($arrbody['fields'])) {
1763
							foreach ($arrbody['fields'] as $error) {
1764
								$message .= " " . $error['path'] . ": " . $error['message'] . ".";
1765
							}
1766
						}
1767
						$status = $status_intro . $error_str . $message;
1768
					} else {
1769
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1770
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1771
						$this->_debug($data);
1772
					}
1773
					break;
1774
				case 'googledomains':
1775
					if (preg_match('/notfqdn/i', $data)) {
1776
						$status = $status_intro . $error_str . gettext("Not A FQDN");
1777
					} else if (preg_match('/nochg/i', $data)) {
1778
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1779
						$successful_update = true;
1780
					} else if (preg_match('/good/i', $data)) {
1781
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1782
						$successful_update = true;
1783
					} else if (preg_match('/badauth/i', $data)) {
1784
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1785
					} else if (preg_match('/nohost/i', $data)) {
1786
						$status = $status_intro . $error_str . gettext("Hostname does not exist or DynDNS not enabled");
1787
					} else if (preg_match('/badagent/i', $data)) {
1788
						$status = $status_intro . $error_str . gettext("Bad request");
1789
					} else if (preg_match('/abuse/i', $data)) {
1790
						$status = $status_intro . $error_str . gettext("Dynamic DNS access has been blocked!");
1791
					} else if (preg_match('/911/i', $data)) {
1792
						$status = $status_intro . $error_str . gettext("Error on Google's end, retry in 5 minutes");
1793
					} else {
1794
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1795
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1796
						$this->_debug($data);
1797
					}
1798
					break;
1799
				case 'dnsmadeeasy':
1800
					switch ($data) {
1801
						case 'success':
1802
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1803
							$successful_update = true;
1804
							break;
1805
						case 'error-auth':
1806
							$status = $status_intro . $error_str . gettext("Invalid username or password");
1807
							break;
1808
						case 'error-auth-suspend':
1809
							$status = $status_intro . $error_str . gettext("Account suspended");
1810
							break;
1811
						case 'error-auth-voided':
1812
							$status = $status_intro . $error_str . gettext("Account revoked");
1813
							break;
1814
						case 'error-record-invalid':
1815
							$status = $status_intro . $error_str . gettext("Record does not exist in the system. Unable to update record");
1816
							break;
1817
						case 'error-record-auth':
1818
							$status = $status_intro . $error_str . gettext("User does not have access to this record");
1819
							break;
1820
						case 'error-record-ip-same':
1821
							$status = $status_intro . $success_str . gettext("No Change In IP Address");
1822
							$successful_update = true;
1823
							break;
1824
						case 'error-system':
1825
							$status = $status_intro . $error_str . gettext("General system error recognized by the system");
1826
							break;
1827
						case 'error':
1828
							$status = $status_intro . $error_str . gettext("General system error unrecognized by the system");
1829
							break;
1830
						default:
1831
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1832
							log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1833
							$this->_debug($data);
1834
							break;
1835
					}
1836
					break;
1837
				case 'spdyn':
1838
				case 'spdyn-v6':
1839
					if (preg_match('/notfqdn/i', $data)) {
1840
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1841
					} else if (preg_match('/nohost/i', $data)) {
1842
						$status = $status_intro . $error_str . gettext("No such host");
1843
					} else if (preg_match('/nochg/i', $data)) {
1844
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1845
						$successful_update = true;
1846
					} else if (preg_match('/good/i', $data)) {
1847
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1848
						$successful_update = true;
1849
					} else if (preg_match('/badauth/i', $data)) {
1850
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1851
					} else {
1852
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1853
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1854
						$this->_debug($data);
1855
					}
1856
					break;
1857
				case 'all-inkl':
1858
 					if (preg_match('/good\s'.$this->_dnsIP.'/i', $data)) {
1859
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1860
 							$successful_update = true;
1861
 					} else if (preg_match('/good/i', $data)) {
1862
						$status = $status_intro . $error_str . gettext("Result did not match.");
1863
					} else if (preg_match("/\s401\sUnauthorized/i", $header)) {
1864
						$status = $status_intro . $error_str . gettext("Invalid username or password");
1865
					}
1866
					else {
1867
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1868
							log_error($status_intro . gettext("PAYLOAD:") . " " . $header.$data);
1869
 							$this->_debug($data);
1870
 							$this->_debug($header);
1871
 					}
1872
 					break;
1873
				case 'hover':
1874
					if (preg_match('/succeeded":true/i', $data)) {
1875
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1876
						$successful_update = true;
1877
					} else {
1878
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1879
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1880
						$this->_debug($data);
1881
					}
1882
					break;
1883
				case 'cloudns':
1884
					$result = json_decode($data, true);
1885
					if ($result['status'] == 'Success') {
1886
						$successful_update = true;
1887
					} else {
1888
						log_error($result['status'] . "(" . $result['statusDescription'] . ")");
1889
					}
1890
					break;
1891
				case 'dreamhost':
1892
				case 'dreamhost-v6':
1893
					$result = json_decode($data,true);
1894
					if ($this->_dnsVerboseLog) {
1895
						log_error(sprintf(gettext('_checkStatus() results: %1$s'), $data));
1896
					}
1897
					switch ($result['data']) {
1898
					case 'success':
1899
					case 'record_added':
1900
					case 'record_removed':
1901
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1902
						$successful_update = true;
1903
						break;
1904
					case 'no_record':
1905
					case 'no_such_record ':
1906
						$status = $status_intro . $error_str . gettext("No record exists.");
1907
						break;
1908
					case 'no_type':
1909
					case 'no_such_type ':
1910
						$status = $status_intro . $error_str . gettext("No type exists.");
1911
						break;
1912
					case 'no_value':
1913
					case 'no_such_value ':
1914
						$status = $status_intro . $error_str . gettext("No value exists.");
1915
						break;
1916
					case 'no_such_zone':
1917
						$status = $status_intro . $error_str . gettext("No such zone exists.");
1918
						break;
1919
					case 'invalid_record':
1920
						$status = $status_intro . $error_str . gettext("The specified record is invalid.");
1921
						break;
1922
					case 'invalid_type':
1923
						$status = $status_intro . $error_str . gettext("The specified type is invalid.");
1924
						break;
1925
					case 'invalid_value':
1926
						$status = $status_intro . $error_str . gettext("The specified value is invalid.");
1927
						break;
1928
					case 'not_editable ':
1929
						$status = $status_intro . $error_str . gettext("Record is not editable.");
1930
						break;
1931
					case 'record_already_exists_not_editable':
1932
						$status = $status_intro . $error_str . gettext("Record exists but is not editable.");
1933
						break;
1934
					case 'record_already_exists_remove_first':
1935
						$status = $status_intro . $error_str . gettext("Record exists and must be removed before adding.");
1936
						break;
1937
					case 'internal_error_updating_zone':
1938
						$status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone.");
1939
						break;
1940
					case 'internal_error_could_not_load_zone':
1941
						$status = $status_intro . $error_str . gettext("A remote server error occurred loading the zone.");
1942
						break;
1943
					case 'internal_error_could_not_update_zone':
1944
						$status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone.");
1945
						break;
1946
					case 'internal_error_could_not_add_record':
1947
						$status = $status_intro . $error_str . gettext("A remote server error occurred adding a new record.");
1948
						break;
1949
					case 'internal_error_could_not_destroy_record ':
1950
						$status = $status_intro . $error_str . gettext("A remote server error occurred removing an existing record.");
1951
						break;
1952
					default:
1953
						break;
1954
					}
1955
				default:
1956
					break;
1957
			}
1958

    
1959
			if ($successful_update == true) {
1960
				/* Write WAN IP to cache file */
1961
				$wan_ip = $this->_checkIP();
1962
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1963
					$currentTime = time();
1964
					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));
1965
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1966
					@file_put_contents($this->_cacheFile, "{$wan_ip}|{$currentTime}");
1967
				} else {
1968
					@unlink($this->_cacheFile);
1969
				}
1970
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1971
					$currentTime = time();
1972
					notify_all_remote(sprintf(gettext('DynDNS updated IPv6 Address on %1$s (%2$s) to %3$s'), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1973
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1974
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1975
				} else {
1976
					@unlink($this->_cacheFile_v6);
1977
				}
1978
			}
1979
			$this->status = $status;
1980
			log_error($status);
1981
		}
1982

    
1983
		/*
1984
		 * Private Function (added 12 July 05) [beta]
1985
		 *   Return Error, Set Last Error, and Die.
1986
		 */
1987
		function _error($errorNumber = '1') {
1988
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1989
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1990
			switch ($errorNumber) {
1991
				case 0:
1992
					break;
1993
				case 2:
1994
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1995
					break;
1996
				case 3:
1997
					$error = $err_str . gettext('No Username Provided.');
1998
					break;
1999
				case 4:
2000
					$error = $err_str . gettext('No Password Provided.');
2001
					break;
2002
				case 5:
2003
					$error = $err_str . gettext('No Hostname Provided.');
2004
					break;
2005
				case 6:
2006
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
2007
					break;
2008
				case 7:
2009
					$error = $err_str . gettext('No Update URL Provided.');
2010
					break;
2011
				case 8:
2012
					$status = $err_str_r53 . gettext("Invalid ZoneID");
2013
					break;
2014
				case 9:
2015
					$status = $err_str_r53 . gettext("Invalid TTL");
2016
					break;
2017
				case 10:
2018
					$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);
2019
					break;
2020
				default:
2021
					$error = $err_str . gettext('Unknown Response.');
2022
					/* FIXME: $data isn't in scope here */
2023
					/* $this->_debug($data); */
2024
					break;
2025
			}
2026
			$this->lastError = $error;
2027
			log_error($error);
2028
		}
2029

    
2030
		/*
2031
		 * Private Function (added 12 July 05) [beta]
2032
		 *   - Detect whether or not IP needs to be updated.
2033
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
2034
		 *      | work with other systems. pfSense base is FreeBSD.
2035
		 */
2036
		function _detectChange() {
2037
			global $debug;
2038

    
2039
			if ($debug) {
2040
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
2041
			}
2042

    
2043
			$currentTime = time();
2044

    
2045
			$wan_ip = $this->_checkIP();
2046
			if ($wan_ip == 0) {
2047
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
2048
				return false;
2049
			}
2050
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
2051

    
2052
			if ($this->_useIPv6 == true) {
2053
				if (file_exists($this->_cacheFile_v6)) {
2054
					$contents = file_get_contents($this->_cacheFile_v6);
2055
					list($cacheIP, $cacheTime) = explode('|', $contents);
2056
					$this->_debug($cacheIP.'/'.$cacheTime);
2057
					$initial = false;
2058
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
2059
				} else {
2060
					$cacheIP = '::';
2061
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
2062
					$cacheTime = $currentTime;
2063
					$initial = true;
2064
					$log_error .= gettext("No Cached IPv6 found.");
2065
				}
2066
			} else {
2067
				if (file_exists($this->_cacheFile)) {
2068
					$contents = file_get_contents($this->_cacheFile);
2069
					list($cacheIP, $cacheTime) = explode('|', $contents);
2070
					$this->_debug($cacheIP.'/'.$cacheTime);
2071
					$initial = false;
2072
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
2073
				} else {
2074
					$cacheIP = '0.0.0.0';
2075
					@file_put_contents($this->_cacheFile, "0.0.0.0|{$currentTime}");
2076
					$cacheTime = $currentTime;
2077
					$initial = true;
2078
					$log_error .= gettext("No Cached IP found.");
2079
				}
2080
			}
2081
			if ($this->_dnsVerboseLog) {
2082
				log_error($log_error);
2083
			}
2084

    
2085
			// Convert seconds = days * hr/day * min/hr * sec/min
2086
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
2087

    
2088
			$needs_updating = FALSE;
2089
			/* lets determine if the item needs updating */
2090
			if ($cacheIP != $wan_ip) {
2091
				$needs_updating = true;
2092
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
2093
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
2094
			}
2095
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
2096
				$needs_updating = true;
2097
				$this->_forceUpdateNeeded = true;
2098
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
2099
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
2100
			}
2101
			if ($initial == true) {
2102
				$needs_updating = true;
2103
				$update_reason .= gettext("Initial update.");
2104
			}
2105

    
2106
			/*   finally if we need updating then store the
2107
			 *   new cache value and return true
2108
			 */
2109
			if ($needs_updating == true) {
2110
				if ($this->_dnsVerboseLog) {
2111
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
2112
				}
2113
				return true;
2114
			}
2115

    
2116
			return false;
2117
		}
2118

    
2119
		/*
2120
		 * Private Function (added 16 July 05) [beta]
2121
		 *   - Writes debug information to a file.
2122
		 *   - This function is only called when a unknown response
2123
		 *   - status is returned from a DynDNS service provider.
2124
		 */
2125
		function _debug($data) {
2126
			global $g;
2127

    
2128
			if (!$g['debug']) {
2129
				return;
2130
			}
2131
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
2132
			$file = fopen($this->_debugFile, 'a');
2133
			fwrite($file, $string);
2134
			fclose($file);
2135
		}
2136
		function _checkIP() {
2137
			global $debug;
2138

    
2139
			if ($debug) {
2140
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
2141
			}
2142

    
2143
			if ($this->_useIPv6 == true) {
2144
				$ip_address = get_interface_ipv6($this->_if);
2145
				if (!is_ipaddrv6($ip_address)) {
2146
					return 0;
2147
				}
2148
			} else {
2149
				$ip_address = get_interface_ip($this->_if);
2150
				if (!is_ipaddr($ip_address)) {
2151
					return 0;
2152
				}
2153
			}
2154
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
2155
				$hosttocheck = "checkip.dyndns.org";
2156
				$try = 0;
2157
				while ($try < 3) {
2158
					$checkip = gethostbyname($hosttocheck);
2159
					if (is_ipaddr($checkip)) {
2160
						break;
2161
					}
2162
					$try++;
2163
				}
2164
				if ($try >= 3) {
2165
					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));
2166
					return 0;
2167
				}
2168
				$ip_ch = curl_init("http://{$checkip}");
2169
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
2170
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
2171
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
2172
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
2173
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
2174
				if ($this->_useIPv6 == false) {
2175
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
2176
				}
2177
				$ip_result_page = curl_exec($ip_ch);
2178
				curl_close($ip_ch);
2179
				$ip_result_decoded = urldecode($ip_result_page);
2180
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
2181
				$ip_address = trim($matches[1]);
2182
				if (is_ipaddr($ip_address)) {
2183
					if ($this->_dnsVerboseLog) {
2184
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
2185
					}
2186
				} else {
2187
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
2188
					return 0;
2189
				}
2190
			} else {
2191
				if ($this->_dnsVerboseLog) {
2192
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
2193
				}
2194
			}
2195
			$this->_dnsIP = $ip_address;
2196

    
2197
			return $ip_address;
2198
		}
2199

    
2200
	}
2201

    
2202
?>
(12-12/58)