Project

General

Profile

Download (67.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
	/*
3
	 * PHP.updateDNS (pfSense version)
4
	 *
5
	 * +====================================================+
6
	 *  Services Supported:
7
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
8
	 *    - No-IP (no-ip.com)
9
	 *    - EasyDNS (easydns.com)
10
	 *    - DHS (www.dhs.org)
11
	 *    - HN (hn.org) -- incomplete checking!
12
	 *    - DynS (dyns.org)
13
	 *    - ZoneEdit (zoneedit.com)
14
	 *    - FreeDNS (freedns.afraid.org)
15
	 *    - Loopia (loopia.se)
16
	 *    - StaticCling (staticcling.org)
17
	 *    - DNSexit (dnsexit.com)
18
	 *    - OpenDNS (opendns.com)
19
	 *    - Namecheap (namecheap.com)
20
	 *    - HE.net (dns.he.net)
21
	 *    - HE.net IPv6 (dns.he.net)
22
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
23
	 *    - SelfHost (selfhost.de)
24
	 *    - Amazon Route 53 (aws.amazon.com)
25
	 *    - DNS-O-Matic (dnsomatic.com)
26
	 *    - Custom DDNS (any URL)
27
	 *    - Custom DDNS IPv6 (any URL)
28
	 *    - CloudFlare (www.cloudflare.com)
29
	 *    - Eurodns (eurodns.com)
30
	 *    - GratisDNS (gratisdns.dk)
31
	 *    - City Network (citynetwork.se)
32
	 *    - GleSYS (glesys.com)
33
	 *    - DNSimple (dnsimple.com)
34
	 *    - Google Domains (domains.google.com)
35
	 *    - DNS Made Easy (www.dnsmadeeasy.com)
36
	 *    - SPDNS (spdns.de)
37
	 *    - SPDNS IPv6 (spdns.de)
38
	 * +----------------------------------------------------+
39
	 *  Requirements:
40
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
41
	 * +----------------------------------------------------+
42
	 *  Public Functions
43
	 *    - updatedns()
44
	 *
45
	 *  Private Functions
46
	 *    - _update()
47
	 *    - _checkStatus()
48
	 *    - _error()
49
	 *    - _detectChange()
50
	 *    - _debug()
51
	 *    - _checkIP()
52
	 * +----------------------------------------------------+
53
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
54
	 *  DynDNS Static   - Last Tested: NEVER
55
	 *  DynDNS Custom   - Last Tested: NEVER
56
	 *  No-IP           - Last Tested: 20 July 2008
57
	 *  HN.org          - Last Tested: 12 July 2005
58
	 *  EasyDNS         - Last Tested: 20 July 2008
59
	 *  DHS             - Last Tested: 12 July 2005
60
	 *  ZoneEdit        - Last Tested: NEVER
61
	 *  Dyns            - Last Tested: NEVER
62
	 *  ODS             - Last Tested: 02 August 2005
63
	 *  FreeDNS         - Last Tested: 23 Feb 2011
64
	 *  Loopia          - Last Tested: NEVER
65
	 *  StaticCling     - Last Tested: 27 April 2006
66
	 *  DNSexit         - Last Tested: 20 July 2008
67
	 *  OpenDNS         - Last Tested: 4 August 2008
68
	 *  Namecheap       - Last Tested: 31 August 2010
69
	 *  HE.net          - Last Tested: 7 July 2013
70
	 *  HE.net IPv6     - Last Tested: 7 July 2013
71
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
72
	 *  SelfHost        - Last Tested: 26 December 2011
73
	 *  Amazon Route 53 - Last tested: 01 April 2012
74
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
75
	 *  CloudFlare      - Last Tested: 30 May 2013
76
	 *  Eurodns         - Last Tested: 27 June 2013
77
	 *  GratisDNS       - Last Tested: 15 August 2012
78
	 *  OVH DynHOST     - Last Tested: NEVER
79
	 *  City Network    - Last Tested: 13 November 2013
80
	 *  GleSYS          - Last Tested: 3 February 2015
81
	 *  DNSimple        - Last Tested: 09 February 2015
82
	 *  Google Domains  - Last Tested: 27 April 2015
83
	 *  DNS Made Easy   - Last Tested: 27 April 2015
84
	 *  SPDNS           - Last Tested: 04 December 2015
85
	 *  SPDNS IPv6      - Last Tested: 04 December 2015
86
	 * +====================================================+
87
	 *
88
	 * @author 	E.Kristensen
89
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
90
	 * @version 	0.8
91
	 * @updated	13 October 05 at 21:02:42 GMT
92
	 *
93
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
94
	 * Custom DNS support by Matt Corallo
95
	 *
96
	 */
97

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

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

    
148
			global $config, $g;
149

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

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

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

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

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

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

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

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

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

    
290
			unlock($dyndnslck);
291
		}
292

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

    
299
			if ($this->_dnsVerboseLog) {
300
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
301
			}
302

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

    
310
			$ch = curl_init();
311

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

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

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

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

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

    
595
					/* Setting Variables */
596
					$hostname = "{$this->_dnsHost}.";
597
					$ZoneID = $this->_dnsZoneID;
598
					$AccessKeyId = $this->_dnsUser;
599
					$SecretAccessKey = $this->_dnsPass;
600
					$NewIP = $this->_dnsIP;
601
					$NewTTL = $this->_dnsTTL;
602

    
603
					/* Include Route 53 Library Class */
604
					require_once('/etc/inc/r53.class');
605

    
606
					/* Set Amazon AWS Credentials for this record */
607
					$r53 = new Route53($AccessKeyId, $SecretAccessKey);
608

    
609
					/* Function to find old values of records in Route 53 */
610
					if (!function_exists('Searchrecords')) {
611
						function SearchRecords($records, $name) {
612
							$result = array();
613
							foreach ($records as $record) {
614
								if (strtolower($record['Name']) == strtolower($name)) {
615
									$result [] = $record;
616
								}
617
							}
618
							return ($result) ? $result : false;
619
						}
620
					}
621

    
622
					$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
623

    
624
					/* Get IP for your hostname in Route 53 */
625
					if (false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
626
						$OldTTL = $a_result[0][TTL];
627
						$OldIP = $a_result[0][ResourceRecords][0];
628
					} else {
629
						$OldIP = "";
630
					}
631

    
632
					/* Check if we need to update DNS Record */
633
					if ($OldIP !== $NewIP) {
634
						if (!empty($OldIP)) {
635
							/* Your Hostname already exists, deleting and creating it again */
636
							$changes = array();
637
							$changes[] = $r53->prepareChange(DELETE, $hostname, A, $OldTTL, $OldIP);
638
							$changes[] = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
639
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
640
						} else {
641
							/* Your Hostname does not exist yet, creating it */
642
							$changes = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
643
							$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
644
						}
645
					}
646
					$this->_checkStatus(0, $result);
647
					break;
648
				case 'custom':
649
				case 'custom-v6':
650
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
651
					if ($this->_dnsUser != '') {
652
						if ($this->_curlIpresolveV4) {
653
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
654
						}
655
						if ($this->_curlSslVerifypeer) {
656
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
657
						} else {
658
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
659
						}
660
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
661
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
662
					}
663
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
664
					if ($this->_dnsVerboseLog) {
665
						log_error(sprintf(gettext("Sending request to: %s"), $server));
666
					}
667
					curl_setopt($ch, CURLOPT_URL, $server);
668
					break;
669
				case 'cloudflare':
670
					$needsIP = TRUE;
671
					$dnsServer ='api.cloudflare.com';
672
					$dnsHost = str_replace(' ', '', $this->_dnsHost);
673
					$host_names = explode(".", $dnsHost);
674
					$bottom_host_name = $host_names[count($host_names)-2] . "." . $host_names[count($host_names)-1];
675

    
676
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
677
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
678
						'X-Auth-Email: '.$this->_dnsUser.'',
679
						'X-Auth-Key: '.$this->_dnsPass.'',
680
						'Content-Type: application/json'
681
					));
682

    
683
					// Get zone ID
684
					$getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$bottom_host_name}";
685
					curl_setopt($ch, CURLOPT_URL, $getZoneId);
686
					$output = json_decode(curl_exec($ch));
687
					$zone = $output->result[0]->id;
688
					if ($zone) { // If zone ID was found get host ID
689
						$getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_dnsHost}";
690
						curl_setopt($ch, CURLOPT_URL, $getHostId);
691
						$output = json_decode(curl_exec($ch));
692
						$host = $output->result[0]->id;
693
						if ($host) { // If host ID was found update host
694
							$hostData = array(
695
								"content" => "{$this->_dnsIP}",
696
								"type" => "A",
697
								"name" => "{$this->_dnsHost}"
698
							);
699
							$data_json = json_encode($hostData);
700
							$updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}";
701
							curl_setopt($ch, CURLOPT_URL, $updateHostId);
702
							curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
703
							curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
704
						}
705
					}
706
					break;
707
				case 'eurodns':
708
					$needsIP = TRUE;
709
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
710
					$server = "https://update.eurodyndns.org/update/";
711
					$port = "";
712
					if ($this->_dnsPort) {
713
						$port = ":" . $this->_dnsPort;
714
					}
715
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
716
					break;
717
				case 'gratisdns':
718
					$needsIP = TRUE;
719
					$server = "https://ssl.gratisdns.dk/ddns.phtml";
720
					$host = trim($this->_dnsHost);
721
					$hostnames = explode(".", $host);
722
					$hostnames_count = count($hostnames);
723
					if ($hostnames_count > 2) {
724
						$domain = $hostnames[$hostnames_count-2] . "." . $hostnames[$hostnames_count-1];
725
					} else {
726
						$domain = $host;
727
					}
728
					curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $host . '&d=' . $domain . '&i=' . $this->_dnsIP);
729
					break;
730
				case 'ovh-dynhost':
731
					$needsIP = FALSE;
732
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
733
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
734
					$server = "https://www.ovh.com/nic/update";
735
					$port = "";
736
					if ($this->_dnsServer) {
737
						$server = $this->_dnsServer;
738
					}
739
					if ($this->_dnsPort) {
740
						$port = ":" . $this->_dnsPort;
741
					}
742
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
743
					break;
744
				case 'citynetwork':
745
					$needsIP = TRUE;
746
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
747
					$server = 'https://dyndns.citynetwork.se/nic/update';
748
					$port = "";
749
					if ($this->_dnsServer) {
750
						$server = $this->_dnsServer;
751
					}
752
					if ($this->_dnsPort) {
753
						$port = ":" . $this->_dnsPort;
754
					}
755
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
756
					break;
757
				case 'dnsimple':
758
					/* Uses DNSimple's REST API
759
					   Requires username and Account API token passed in header
760
					   Piggybacks on Route 53's ZoneID field for DNSimple record ID
761
					   Data sent as JSON */
762
					$needsIP = TRUE;
763
					$server = 'https://api.dnsimple.com/v1/domains/';
764
					$token = $this->_dnsUser . ':' . $this->_dnsPass;
765
					$jsondata = '{"record":{"content":"' . $this->_dnsIP . '","ttl":"' . $this->_dnsTTL . '"}}';
766
					curl_setopt($ch, CURLOPT_HEADER, 1);
767
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
768
					curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-DNSimple-Token: ' . $token));
769
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '/records/' . $this->_dnsZoneID);
770
					curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
771
					break;
772
				case 'googledomains':
773
					$needsIP = FALSE;
774
					$post_data['username:password'] = $this->_dnsUser . ':' . $this->_dnsPass;
775
					$post_data['hostname'] = $this->_dnsHost;
776
					$post_data['myip'] = $this->_dnsIP;
777
					$post_data['offline'] = 'no';
778
					$server = "https://domains.google.com/nic/update";
779
					$port = "";
780
					curl_setopt($ch, CURLOPT_URL, 'https://domains.google.com/nic/update');
781
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
782
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
783
					break;
784
				case 'dnsmadeeasy':
785
					$needsIP = TRUE;
786
					$server = "https://cp.dnsmadeeasy.com/servlet/updateip";
787
					curl_setopt($ch, CURLOPT_URL, $server . '?username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&id=' . $this->_dnsHost . '&ip=' . $this->_dnsIP);
788
					break;
789
				case 'spdns':
790
				case 'spdns-v6':
791
					$needsIP = FALSE;
792
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
793
					$server = "https://update.spdns.de/nic/update";
794
					$port = "";
795
					if ($this->_dnsServer) {
796
						$server = $this->_dnsServer;
797
					}
798
					if ($this->_dnsPort) {
799
						$port = ":" . $this->_dnsPort;
800
					}
801
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
802
					break;
803
				default:
804
					break;
805
			}
806
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53') {
807
				$data = curl_exec($ch);
808
				$this->_checkStatus($ch, $data);
809
				@curl_close($ch);
810
			}
811
		}
812

    
813
		/*
814
		 * Private Function (added 12 July 2005) [beta]
815
		 *   Retrieve Update Status
816
		 */
817
		function _checkStatus($ch, $data) {
818
			if ($this->_dnsVerboseLog) {
819
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
820
			}
821
			$successful_update = false;
822
			$success_str = "(" . gettext("Success") . ") ";
823
			$error_str = "(" . gettext("Error") . ") ";
824
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
825

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

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

    
1423
			if ($successful_update == true) {
1424
				/* Write WAN IP to cache file */
1425
				$wan_ip = $this->_checkIP();
1426
				conf_mount_rw();
1427
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1428
					$currentTime = time();
1429
					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));
1430
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1431
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1432
				} else {
1433
					@unlink($this->_cacheFile);
1434
				}
1435
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1436
					$currentTime = time();
1437
					notify_all_remote(sprintf(gettext("DynDNS updated IPv6 Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1438
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1439
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1440
				} else {
1441
					@unlink($this->_cacheFile_v6);
1442
				}
1443
				conf_mount_ro();
1444
			}
1445
			$this->status = $status;
1446
			log_error($status);
1447
		}
1448

    
1449
		/*
1450
		 * Private Function (added 12 July 05) [beta]
1451
		 *   Return Error, Set Last Error, and Die.
1452
		 */
1453
		function _error($errorNumber = '1') {
1454
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1455
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1456
			switch ($errorNumber) {
1457
				case 0:
1458
					break;
1459
				case 2:
1460
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1461
					break;
1462
				case 3:
1463
					$error = $err_str . gettext('No Username Provided.');
1464
					break;
1465
				case 4:
1466
					$error = $err_str . gettext('No Password Provided.');
1467
					break;
1468
				case 5:
1469
					$error = $err_str . gettext('No Hostname Provided.');
1470
					break;
1471
				case 6:
1472
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
1473
					break;
1474
				case 7:
1475
					$error = $err_str . gettext('No Update URL Provided.');
1476
					break;
1477
				case 8:
1478
					$status = $err_str_r53 . gettext("Invalid ZoneID");
1479
					break;
1480
				case 9:
1481
					$status = $err_str_r53 . gettext("Invalid TTL");
1482
					break;
1483
				case 10:
1484
					$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);
1485
					break;
1486
				default:
1487
					$error = $err_str . gettext('Unknown Response.');
1488
					/* FIXME: $data isn't in scope here */
1489
					/* $this->_debug($data); */
1490
					break;
1491
			}
1492
			$this->lastError = $error;
1493
			log_error($error);
1494
		}
1495

    
1496
		/*
1497
		 * Private Function (added 12 July 05) [beta]
1498
		 *   - Detect whether or not IP needs to be updated.
1499
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1500
		 *      | work with other systems. pfSense base is FreeBSD.
1501
		 */
1502
		function _detectChange() {
1503
			global $debug;
1504

    
1505
			if ($debug) {
1506
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
1507
			}
1508

    
1509
			$currentTime = time();
1510

    
1511
			$wan_ip = $this->_checkIP();
1512
			if ($wan_ip == 0) {
1513
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
1514
				return false;
1515
			}
1516
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
1517

    
1518
			if ($this->_useIPv6 == true) {
1519
				if (file_exists($this->_cacheFile_v6)) {
1520
					$contents = file_get_contents($this->_cacheFile_v6);
1521
					list($cacheIP, $cacheTime) = explode('|', $contents);
1522
					$this->_debug($cacheIP.'/'.$cacheTime);
1523
					$initial = false;
1524
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
1525
				} else {
1526
					conf_mount_rw();
1527
					$cacheIP = '::';
1528
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1529
					conf_mount_ro();
1530
					$cacheTime = $currentTime;
1531
					$initial = true;
1532
					$log_error .= gettext("No Cached IPv6 found.");
1533
				}
1534
			} else {
1535
				if (file_exists($this->_cacheFile)) {
1536
					$contents = file_get_contents($this->_cacheFile);
1537
					list($cacheIP, $cacheTime) = explode(':', $contents);
1538
					$this->_debug($cacheIP.'/'.$cacheTime);
1539
					$initial = false;
1540
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
1541
				} else {
1542
					conf_mount_rw();
1543
					$cacheIP = '0.0.0.0';
1544
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1545
					conf_mount_ro();
1546
					$cacheTime = $currentTime;
1547
					$initial = true;
1548
					$log_error .= gettext("No Cached IP found.");
1549
				}
1550
			}
1551
			if ($this->_dnsVerboseLog) {
1552
				log_error($log_error);
1553
			}
1554

    
1555
			// Convert seconds = days * hr/day * min/hr * sec/min
1556
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1557

    
1558
			$needs_updating = FALSE;
1559
			/* lets determine if the item needs updating */
1560
			if ($cacheIP != $wan_ip) {
1561
				$needs_updating = true;
1562
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
1563
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
1564
			}
1565
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1566
				$needs_updating = true;
1567
				$this->_forceUpdateNeeded = true;
1568
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
1569
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1570
			}
1571
			if ($initial == true) {
1572
				$needs_updating = true;
1573
				$update_reason .= gettext("Initial update.");
1574
			}
1575

    
1576
			/*   finally if we need updating then store the
1577
			 *   new cache value and return true
1578
			 */
1579
			if ($needs_updating == true) {
1580
				if ($this->_dnsVerboseLog) {
1581
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1582
				}
1583
				return true;
1584
			}
1585

    
1586
			return false;
1587
		}
1588

    
1589
		/*
1590
		 * Private Function (added 16 July 05) [beta]
1591
		 *   - Writes debug information to a file.
1592
		 *   - This function is only called when a unknown response
1593
		 *   - status is returned from a DynDNS service provider.
1594
		 */
1595
		function _debug($data) {
1596
			global $g;
1597

    
1598
			if (!$g['debug']) {
1599
				return;
1600
			}
1601
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1602
			conf_mount_rw();
1603
			$file = fopen($this->_debugFile, 'a');
1604
			fwrite($file, $string);
1605
			fclose($file);
1606
			conf_mount_ro();
1607
		}
1608
		function _checkIP() {
1609
			global $debug;
1610

    
1611
			if ($debug) {
1612
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
1613
			}
1614

    
1615
			if ($this->_useIPv6 == true) {
1616
				$ip_address = find_interface_ipv6($this->_if);
1617
				if (!is_ipaddrv6($ip_address)) {
1618
					return 0;
1619
				}
1620
			} else {
1621
				$ip_address = find_interface_ip($this->_if);
1622
				if (!is_ipaddr($ip_address)) {
1623
					return 0;
1624
				}
1625
			}
1626
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1627
				$hosttocheck = "checkip.dyndns.org";
1628
				$try = 0;
1629
				while ($try < 3) {
1630
					$checkip = gethostbyname($hosttocheck);
1631
					if (is_ipaddr($checkip)) {
1632
						break;
1633
					}
1634
					$try++;
1635
				}
1636
				if ($try >= 3) {
1637
					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));
1638
					return 0;
1639
				}
1640
				$ip_ch = curl_init("http://{$checkip}");
1641
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1642
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1643
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1644
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1645
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1646
				if ($this->_useIPv6 == false) {
1647
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1648
				}
1649
				$ip_result_page = curl_exec($ip_ch);
1650
				curl_close($ip_ch);
1651
				$ip_result_decoded = urldecode($ip_result_page);
1652
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1653
				$ip_address = trim($matches[1]);
1654
				if (is_ipaddr($ip_address)) {
1655
					if ($this->_dnsVerboseLog) {
1656
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
1657
					}
1658
				} else {
1659
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
1660
					return 0;
1661
				}
1662
			} else {
1663
				if ($this->_dnsVerboseLog) {
1664
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
1665
				}
1666
			}
1667
			$this->_dnsIP = $ip_address;
1668

    
1669
			return $ip_address;
1670
		}
1671

    
1672
	}
1673

    
1674
?>
(16-16/65)