Project

General

Profile

Download (72.9 KB) Statistics
| Branch: | Tag: | Revision:
1 d237be68 Scott Ullrich
<?php
2 8acd654a Renato Botelho
/*
3
 * dyndns.class
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 8acd654a Renato Botelho
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52
 */
53
54 1fa2f630 Erik Kristensen
	/*
55
	 * PHP.updateDNS (pfSense version)
56
	 *
57
	 * +====================================================+
58
	 *  Services Supported:
59 9b8dc821 Scott Ullrich
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
60 1fa2f630 Erik Kristensen
	 *    - No-IP (no-ip.com)
61
	 *    - EasyDNS (easydns.com)
62
	 *    - DHS (www.dhs.org)
63 9b8dc821 Scott Ullrich
	 *    - HN (hn.org) -- incomplete checking!
64 1fa2f630 Erik Kristensen
	 *    - DynS (dyns.org)
65
	 *    - ZoneEdit (zoneedit.com)
66 9b8dc821 Scott Ullrich
	 *    - FreeDNS (freedns.afraid.org)
67 7f1349f7 TechSmurf
	 *    - FreeDNS IPv6 (freedns.afraid.org)
68 9b8dc821 Scott Ullrich
	 *    - Loopia (loopia.se)
69
	 *    - StaticCling (staticcling.org)
70 0a1b0183 Ermal Luçi
	 *    - DNSexit (dnsexit.com)
71 2d78b166 Ermal Luçi
	 *    - OpenDNS (opendns.com)
72 61c30081 jim-p
	 *    - Namecheap (namecheap.com)
73 8ea77433 Chris Wells
	 *    - HE.net (dns.he.net)
74 da40615d Daniel Becker
	 *    - HE.net IPv6 (dns.he.net)
75 38a481ad jim-p
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
76 fb403496 Gerald Raaf
	 *    - SelfHost (selfhost.de)
77 37f3e704 Matt Corallo
	 *    - Amazon Route 53 (aws.amazon.com)
78
	 *    - DNS-O-Matic (dnsomatic.com)
79
	 *    - Custom DDNS (any URL)
80 da40615d Daniel Becker
	 *    - Custom DDNS IPv6 (any URL)
81 e26e1f76 Andrew Senetar
	 *    - CloudFlare (www.cloudflare.com)
82 b18e885c Phil Davis
	 *    - CloudFlare IPv6 (www.cloudflare.com)
83 1e0b1727 Phil Davis
	 *    - Eurodns (eurodns.com)
84
	 *    - GratisDNS (gratisdns.dk)
85 a0b470ee Chris Buechler
	 *    - City Network (citynetwork.se)
86 e0a4147b surrural
	 *    - GleSYS (glesys.com)
87 916d683e surrural
	 *    - DNSimple (dnsimple.com)
88 6c92b378 Christopher Fazendin
	 *    - Google Domains (domains.google.com)
89 c5ecdc25 Jose Luis Duran
	 *    - DNS Made Easy (www.dnsmadeeasy.com)
90 608090e8 exii1988
	 *    - SPDYN (spdyn.de)
91
	 *    - SPDYN IPv6 (spdyn.de)
92 3c2a6448 Christoph Filnkößl
	 *    - All-Inkl (all-inkl.com)
93 4a77c4ea Ionut
	 *    - DuiaDNS (www.duiadns.net)
94
	 *    - DuiaDNS IPv6 (www.duiadns.net)
95 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
96
	 *  Requirements:
97 37f3e704 Matt Corallo
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
98 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
99
	 *  Public Functions
100
	 *    - updatedns()
101
	 *
102
	 *  Private Functions
103
	 *    - _update()
104
	 *    - _checkStatus()
105
	 *    - _error()
106
	 *    - _detectChange()
107
	 *    - _debug()
108 22de7804 Bill Marquette
	 *    - _checkIP()
109 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
110 01c155f2 Phil Davis
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
111
	 *  DynDNS Static   - Last Tested: NEVER
112
	 *  DynDNS Custom   - Last Tested: NEVER
113
	 *  No-IP           - Last Tested: 20 July 2008
114
	 *  HN.org          - Last Tested: 12 July 2005
115
	 *  EasyDNS         - Last Tested: 20 July 2008
116
	 *  DHS             - Last Tested: 12 July 2005
117
	 *  ZoneEdit        - Last Tested: NEVER
118
	 *  Dyns            - Last Tested: NEVER
119
	 *  ODS             - Last Tested: 02 August 2005
120 7f1349f7 TechSmurf
	 *  FreeDNS         - Last Tested: 01 May 2016
121
	 *  FreeDNS IPv6    - Last Tested: 01 May 2016
122 01c155f2 Phil Davis
	 *  Loopia          - Last Tested: NEVER
123
	 *  StaticCling     - Last Tested: 27 April 2006
124
	 *  DNSexit         - Last Tested: 20 July 2008
125
	 *  OpenDNS         - Last Tested: 4 August 2008
126
	 *  Namecheap       - Last Tested: 31 August 2010
127
	 *  HE.net          - Last Tested: 7 July 2013
128
	 *  HE.net IPv6     - Last Tested: 7 July 2013
129
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
130
	 *  SelfHost        - Last Tested: 26 December 2011
131 37f3e704 Matt Corallo
	 *  Amazon Route 53 - Last tested: 01 April 2012
132 1e0b1727 Phil Davis
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
133 b18e885c Phil Davis
	 *  CloudFlare      - Last Tested: 17 July 2016
134
	 *  CloudFlare IPv6 - Last Tested: 17 July 2016
135 1e0b1727 Phil Davis
	 *  Eurodns         - Last Tested: 27 June 2013
136
	 *  GratisDNS       - Last Tested: 15 August 2012
137
	 *  OVH DynHOST     - Last Tested: NEVER
138
	 *  City Network    - Last Tested: 13 November 2013
139
	 *  GleSYS          - Last Tested: 3 February 2015
140
	 *  DNSimple        - Last Tested: 09 February 2015
141 6c92b378 Christopher Fazendin
	 *  Google Domains  - Last Tested: 27 April 2015
142 c5ecdc25 Jose Luis Duran
	 *  DNS Made Easy   - Last Tested: 27 April 2015
143 608090e8 exii1988
	 *  SPDYN           - Last Tested: 02 July 2016
144
	 *  SPDYN IPv6      - Last Tested: 02 July 2016
145 3c2a6448 Christoph Filnkößl
	 *  All-Inkl        - Last Tested: 12 November 2016
146 4a77c4ea Ionut
	 *  DuiaDNS         - Last Tested: 25 November 2016
147
	 *  DuiaDNS IPv6    - Last Tested: 25 November 2016
148 1fa2f630 Erik Kristensen
	 * +====================================================+
149
	 *
150 e24b26e9 Scott Ullrich
	 * @author 	E.Kristensen
151 1fa2f630 Erik Kristensen
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
152 0da417be Erik Kristensen
	 * @version 	0.8
153 e24b26e9 Scott Ullrich
	 * @updated	13 October 05 at 21:02:42 GMT
154 1fa2f630 Erik Kristensen
	 *
155 d98a2e6a Jose Luis Duran
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
156 37f3e704 Matt Corallo
	 * Custom DNS support by Matt Corallo
157 0a1b0183 Ermal Luçi
	 *
158 1fa2f630 Erik Kristensen
	 */
159
160
	class updatedns {
161 67ee1ec5 Ermal Luçi
		var $_cacheFile;
162 d7e6f573 Daniel Becker
		var $_cacheFile_v6;
163 67ee1ec5 Ermal Luçi
		var $_debugFile;
164 2d8770b2 Philip Soeberg
		var $_UserAgent = 'phpDynDNS/0.7';
165 1fa2f630 Erik Kristensen
		var $_errorVerbosity = 0;
166
		var $_dnsService;
167
		var $_dnsUser;
168
		var $_dnsPass;
169
		var $_dnsHost;
170 6635aa0f jim-p
		var $_dnsDomain;
171
		var $_FQDN;
172 1fa2f630 Erik Kristensen
		var $_dnsIP;
173
		var $_dnsWildcard;
174
		var $_dnsMX;
175
		var $_dnsBackMX;
176 9b8dc821 Scott Ullrich
		var $_dnsServer;
177
		var $_dnsPort;
178
		var $_dnsUpdateURL;
179 cd132e86 Edson Brandi
		var $_dnsZoneID;
180
		var $_dnsTTL;
181 1fa2f630 Erik Kristensen
		var $status;
182
		var $_debugID;
183 67ee1ec5 Ermal Luçi
		var $_if;
184 37f3e704 Matt Corallo
		var $_dnsResultMatch;
185
		var $_dnsRequestIf;
186
		var $_dnsRequestIfIP;
187 87b91672 Phil Davis
		var $_dnsVerboseLog;
188 aa79f351 Sebastian Chrostek
		var $_curlIpresolveV4;
189
		var $_curlSslVerifypeer;
190 f5e293e6 Phil Davis
		var $_dnsMaxCacheAgeDays;
191 0333f968 Phil Davis
		var $_dnsDummyUpdateDone;
192
		var $_forceUpdateNeeded;
193 b4025ccd Daniel Becker
		var $_useIPv6;
194 1e0b1727 Phil Davis
195
		/*
196 1fa2f630 Erik Kristensen
		 * Public Constructor Function (added 12 July 05) [beta]
197 1e0b1727 Phil Davis
		 *   - Gets the dice rolling for the update.
198 37f3e704 Matt Corallo
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
199 1e0b1727 Phil Davis
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
200 1bf52c67 Phil Davis
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
201 37f3e704 Matt Corallo
		 *   - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
202
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
203 1fa2f630 Erik Kristensen
		 */
204 6635aa0f jim-p
		function updatedns ($dnsService = '', $dnsHost = '', $dnsDomain = '', $dnsUser = '', $dnsPass = '',
205 1e0b1727 Phil Davis
					$dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
206
					$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
207
					$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
208
					$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
209
210 be17e372 Phil Davis
			global $config, $g, $dyndns_split_domain_types;
211
			if (in_array($dnsService, $dyndns_split_domain_types)) {
212 6635aa0f jim-p
				$this->_FQDN = $dnsHost . "." . $dnsDomain;
213
			} else {
214
				$this->_FQDN = $dnsHost;
215
			}
216
217
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.cache";
218
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}_v6.cache";
219
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.debug";
220 67ee1ec5 Ermal Luçi
221 aa79f351 Sebastian Chrostek
			$this->_curlIpresolveV4 = $curlIpresolveV4;
222
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
223 87b91672 Phil Davis
			$this->_dnsVerboseLog = $dnsVerboseLog;
224 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
225 9557ca30 Phil Davis
				log_error(gettext("Dynamic DNS: updatedns() starting"));
226 1e0b1727 Phil Davis
			}
227 71070cc5 Ermal
228 37f3e704 Matt Corallo
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
229 71070cc5 Ermal
230 1fa2f630 Erik Kristensen
			if (!$dnsService) $this->_error(2);
231 ce6d1106 jim-p
			switch ($dnsService) {
232
			case 'freedns':
233 7f1349f7 TechSmurf
			case 'freedns-v6':
234 ce6d1106 jim-p
				if (!$dnsHost) $this->_error(5);
235
				break;
236 be17e372 Phil Davis
			case "namecheap":
237
				if (!$dnsPass) $this->_error(4);
238
				if (!$dnsHost) $this->_error(5);
239
				if (!$dnsDomain) $this->_error(5);
240
				break;
241
			case "cloudflare-v6":
242
			case "cloudflare":
243
			case "gratisdns":
244
				if (!$dnsUser) $this->_error(3);
245 9b8dc821 Scott Ullrich
				if (!$dnsPass) $this->_error(4);
246
				if (!$dnsHost) $this->_error(5);
247 6635aa0f jim-p
				if (!$dnsDomain) $this->_error(5);
248 ce6d1106 jim-p
				break;
249 37f3e704 Matt Corallo
			case 'route53':
250
				if (!$dnsZoneID) $this->_error(8);
251
				if (!$dnsTTL) $this->_error(9);
252
				break;
253
			case 'custom':
254
				if (!$dnsUpdateURL) $this->_error(7);
255
				break;
256 ce6d1106 jim-p
			default:
257
				if (!$dnsUser) $this->_error(3);
258
				if (!$dnsPass) $this->_error(4);
259 99295d7b Scott Ullrich
				if (!$dnsHost) $this->_error(5);
260 9b8dc821 Scott Ullrich
			}
261 1e0b1727 Phil Davis
262 b4025ccd Daniel Becker
			switch ($dnsService) {
263 1e0b1727 Phil Davis
				case 'he-net-v6':
264
				case 'custom-v6':
265 608090e8 exii1988
				case 'spdyn-v6':
266 4a77c4ea Ionut
				case 'duiadns-v6':
267 7f1349f7 TechSmurf
				case 'freedns-v6':
268 b18e885c Phil Davis
				case 'cloudflare-v6':
269 1e0b1727 Phil Davis
					$this->_useIPv6 = true;
270
					break;
271
				default:
272
					$this->_useIPv6 = false;
273 b4025ccd Daniel Becker
			}
274 1fa2f630 Erik Kristensen
			$this->_dnsService = strtolower($dnsService);
275
			$this->_dnsUser = $dnsUser;
276 be17e372 Phil Davis
			$this->_dnsPass = base64_decode($dnsPass);
277 1fa2f630 Erik Kristensen
			$this->_dnsHost = $dnsHost;
278 6635aa0f jim-p
			$this->_dnsDomain = $dnsDomain;
279 9b8dc821 Scott Ullrich
			$this->_dnsServer = $dnsServer;
280
			$this->_dnsPort = $dnsPort;
281
			$this->_dnsWildcard = $dnsWildcard;
282
			$this->_dnsMX = $dnsMX;
283 0c7bb880 Phil Davis
			$this->_dnsZoneID = $dnsZoneID;
284
			$this->_dnsTTL = $dnsTTL;
285 bf001dec smos
			$this->_if = get_failover_interface($dnsIf);
286 fffbfef0 Matt Corallo
			$this->_checkIP();
287 37f3e704 Matt Corallo
			$this->_dnsUpdateURL = $dnsUpdateURL;
288
			$this->_dnsResultMatch = $dnsResultMatch;
289 bf001dec smos
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
290 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
291 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS (%1$s): running get_failover_interface for %2$s. found %3$s'), $this->_FQDN, $dnsRequestIf, $this->_dnsRequestIf));
292 1e0b1727 Phil Davis
			}
293 37f3e704 Matt Corallo
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
294 f5e293e6 Phil Davis
			$this->_dnsMaxCacheAgeDays = 25;
295 0333f968 Phil Davis
			$this->_dnsDummyUpdateDone = false;
296
			$this->_forceUpdateNeeded = $forceUpdate;
297 1e0b1727 Phil Davis
298 0c7bb880 Phil Davis
			// Ensure that we were able to lookup the IP
299 1e0b1727 Phil Davis
			if (!is_ipaddr($this->_dnsIP)) {
300 140a87c5 Chris Buechler
				log_error(sprintf(gettext('Dynamic DNS (%1$s) There was an error trying to determine the public IP for interface - %2$s (%3$s %4$s).'), $this->_FQDN, $dnsIf, $this->_if, $this->_dnsIP));
301 fffbfef0 Matt Corallo
				unlock($dyndnslck);
302
				return;
303
			}
304 07a3b40b sullrich
305 1fa2f630 Erik Kristensen
			$this->_debugID = rand(1000000, 9999999);
306 1e0b1727 Phil Davis
307 d7e6f573 Daniel Becker
			if ($forceUpdate == false && $this->_detectChange() == false) {
308 1fa2f630 Erik Kristensen
				$this->_error(10);
309
			} else {
310 9d96a475 Ermal Lu?i
				switch ($this->_dnsService) {
311 1e0b1727 Phil Davis
					case 'glesys':
312
					case 'dnsomatic':
313
					case 'dyndns':
314
					case 'dyndns-static':
315
					case 'dyndns-custom':
316
					case 'dhs':
317
					case 'noip':
318
					case 'noip-free':
319
					case 'easydns':
320
					case 'hn':
321
					case 'zoneedit':
322
					case 'dyns':
323
					case 'ods':
324
					case 'freedns':
325 7f1349f7 TechSmurf
					case 'freedns-v6':
326 1e0b1727 Phil Davis
					case 'loopia':
327
					case 'staticcling':
328
					case 'dnsexit':
329
					case 'custom':
330
					case 'custom-v6':
331
					case 'opendns':
332
					case 'namecheap':
333
					case 'he-net':
334
					case 'he-net-v6':
335 4a77c4ea Ionut
					case 'duiadns':
336
					case 'duiadns-v6':
337 1e0b1727 Phil Davis
					case 'selfhost':
338
					case 'he-net-tunnelbroker':
339
					case 'route53':
340
					case 'cloudflare':
341 b18e885c Phil Davis
					case 'cloudflare-v6':
342 1e0b1727 Phil Davis
					case 'eurodns':
343
					case 'gratisdns':
344
					case 'ovh-dynhost':
345
					case 'citynetwork':
346
					case 'dnsimple':
347 c5ecdc25 Jose Luis Duran
					case 'googledomains':
348
					case 'dnsmadeeasy':
349 608090e8 exii1988
					case 'spdyn':
350
					case 'spdyn-v6':
351 3c2a6448 Christoph Filnkößl
					case 'all-inkl':
352 0333f968 Phil Davis
						$this->_update();
353 1e0b1727 Phil Davis
						if ($this->_dnsDummyUpdateDone == true) {
354
							// If a dummy update was needed, then sleep a while and do the update again to put the proper address back.
355
							// Some providers (e.g. No-IP free accounts) need to have at least 1 address change every month.
356
							// If the address has not changed recently, or the user did "Force Update", then the code does
357
							// a dummy address change for providers like this.
358
							sleep(10);
359
							$this->_update();
360
						}
361
						break;
362
					default:
363
						$this->_error(6);
364
						break;
365 1fa2f630 Erik Kristensen
				}
366 9d96a475 Ermal Lu?i
			}
367 71070cc5 Ermal
368
			unlock($dyndnslck);
369 1fa2f630 Erik Kristensen
		}
370 1e0b1727 Phil Davis
371 1fa2f630 Erik Kristensen
		/*
372
		 * Private Function (added 12 July 05) [beta]
373
		 *   Send Update To Selected Service.
374
		 */
375
		function _update() {
376 1e0b1727 Phil Davis
377
			if ($this->_dnsVerboseLog) {
378 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
379 1e0b1727 Phil Davis
			}
380 b37b4034 Phil Davis
381 f1d3adf1 Chris Buechler
			if (strstr($this->_dnsRequestIf, "_vip")) {
382 ac5c0cfe Chris Buechler
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
383 f1d3adf1 Chris Buechler
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
384
			} else {
385
				$realparentif = $this->_dnsRequestIf;
386
			}
387 1e0b1727 Phil Davis
388 0ec4b3b4 Chris Buechler
			$ch = curl_init();
389
390 becd6caa Chris Buechler
			if ($this->_useIPv6 == false) {
391 4e322e2c Phil Davis
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
392 becd6caa Chris Buechler
			}
393
394 cd132e86 Edson Brandi
			if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
395 b6417760 Christoph Filnkößl
				curl_setopt($ch, CURLOPT_HEADER, 1);
396 1fa2f630 Erik Kristensen
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
397
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
398 f1d3adf1 Chris Buechler
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
399 93b8df2a Ermal
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
400 1fa2f630 Erik Kristensen
			}
401
402
			switch ($this->_dnsService) {
403 197cf433 McB
				case 'glesys':
404
					$needsIP = TRUE;
405
					$server = 'https://api.glesys.com/domain/updaterecord/format/json';
406
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
407 6635aa0f jim-p
					$post_data['recordid'] = $this->_FQDN;
408 197cf433 McB
					$post_data['data'] = $this->_dnsIP;
409
					curl_setopt($ch, CURLOPT_URL, $server);
410
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
411
					break;
412 1fa2f630 Erik Kristensen
				case 'dyndns':
413
				case 'dyndns-static':
414 52e95286 Ermal
				case 'dyndns-custom':
415 1fa2f630 Erik Kristensen
					$needsIP = FALSE;
416 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
417
						$this->_dnsWildcard = "ON";
418
					}
419 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
420 9b8dc821 Scott Ullrich
					$server = "https://members.dyndns.org/nic/update";
421
					$port = "";
422 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
423 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
424 1e0b1727 Phil Davis
					}
425
					if ($this->_dnsPort) {
426 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
427 1e0b1727 Phil Davis
					}
428 52e95286 Ermal
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
429 1fa2f630 Erik Kristensen
					break;
430
				case 'dhs':
431 34c9962b Chris Buechler
					// DHS is disabled in the GUI because the following doesn't work.
432 1fa2f630 Erik Kristensen
					$needsIP = TRUE;
433 a255e1f7 Scott Ullrich
					$post_data['hostscmd'] = 'edit';
434
					$post_data['hostscmdstage'] = '2';
435
					$post_data['type'] = '4';
436
					$post_data['updatetype'] = 'Online';
437
					$post_data['mx'] = $this->_dnsMX;
438
					$post_data['mx2'] = '';
439
					$post_data['txt'] = '';
440
					$post_data['offline_url'] = '';
441
					$post_data['cloak'] = 'Y';
442
					$post_data['cloak_title'] = '';
443
					$post_data['ip'] = $this->_dnsIP;
444
					$post_data['domain'] = 'dyn.dhs.org';
445
					$post_data['hostname'] = $this->_dnsHost;
446
					$post_data['submit'] = 'Update';
447 9b8dc821 Scott Ullrich
					$server = "https://members.dhs.org/nic/hosts";
448
					$port = "";
449 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
450 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
451 1e0b1727 Phil Davis
					}
452
					if ($this->_dnsPort) {
453
						$port = ":" . $this->_dnsPort;
454
					}
455 34c9962b Chris Buechler
					curl_setopt($ch, CURLOPT_URL, $server . $port);
456 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
457
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
458
					break;
459
				case 'noip':
460 0333f968 Phil Davis
				case 'noip-free':
461 1fa2f630 Erik Kristensen
					$needsIP = TRUE;
462 64746cf6 Chris Buechler
					$server = "https://dynupdate.no-ip.com/ducupdate.php";
463 9b8dc821 Scott Ullrich
					$port = "";
464 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
465 472da675 Phil Davis
						$server = $this->_dnsServer;
466 1e0b1727 Phil Davis
					}
467
					if ($this->_dnsPort) {
468 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
469 1e0b1727 Phil Davis
					}
470
					if (($this->_dnsService == "noip-free") &&
471 ae52d165 Renato Botelho
					    ($this->_forceUpdateNeeded == true) &&
472
					    ($this->_dnsDummyUpdateDone == false)) {
473 0333f968 Phil Davis
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
474
						$iptoset = "192.168.1.1";
475
						$this->_dnsDummyUpdateDone = true;
476 9557ca30 Phil Davis
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): Processing dummy update on No-IP free account. IP temporarily set to %3$s'), $this->_dnsService, $this->_dnsHost, $iptoset));
477 0333f968 Phil Davis
					} else {
478
						$iptoset = $this->_dnsIP;
479
					}
480 70a84c25 Tiago Barrionuevo
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&h[]=' . $this->_dnsHost.'&ip=' . $iptoset);
481 1fa2f630 Erik Kristensen
					break;
482
				case 'easydns':
483
					$needsIP = TRUE;
484
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
485 64746cf6 Chris Buechler
					$server = "https://members.easydns.com/dyn/dyndns.php";
486 9b8dc821 Scott Ullrich
					$port = "";
487 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
488 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
489 1e0b1727 Phil Davis
					}
490
					if ($this->_dnsPort) {
491 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
492 1e0b1727 Phil Davis
					}
493 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
494 1fa2f630 Erik Kristensen
					break;
495
				case 'hn':
496
					$needsIP = TRUE;
497
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
498 9b8dc821 Scott Ullrich
					$server = "http://dup.hn.org/vanity/update";
499
					$port = "";
500 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
501 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
502 1e0b1727 Phil Davis
					}
503
					if ($this->_dnsPort) {
504 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
505 1e0b1727 Phil Davis
					}
506 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
507 1fa2f630 Erik Kristensen
					break;
508
				case 'zoneedit':
509
					$needsIP = FALSE;
510 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
511
512 9b8dc821 Scott Ullrich
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
513
					$port = "";
514 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
515 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
516 1e0b1727 Phil Davis
					}
517
					if ($this->_dnsPort) {
518 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
519 1e0b1727 Phil Davis
					}
520 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
521 1fa2f630 Erik Kristensen
					break;
522
				case 'dyns':
523
					$needsIP = FALSE;
524 ea46d833 Chris Buechler
					$server = "http://www.dyns.net/postscript011.php";
525 9b8dc821 Scott Ullrich
					$port = "";
526 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
527 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
528 1e0b1727 Phil Davis
					}
529
					if ($this->_dnsPort) {
530
						$port = ":" . $this->_dnsPort;
531
					}
532 fdcaa527 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
533 1fa2f630 Erik Kristensen
					break;
534
				case 'ods':
535
					$needsIP = FALSE;
536 9b8dc821 Scott Ullrich
					$misc_errno = 0;
537
					$misc_error = "";
538
					$server = "ods.org";
539
					$port = "";
540 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
541 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
542 1e0b1727 Phil Davis
					}
543
					if ($this->_dnsPort) {
544
						$port = ":" . $this->_dnsPort;
545
					}
546 9b8dc821 Scott Ullrich
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
547 1fa2f630 Erik Kristensen
					/* Check that we have connected */
548
					if (!$this->con['socket']) {
549
						print "error! could not connect.";
550
						break;
551
					}
552
					/* Here is the loop. Read the incoming data (from the socket connection) */
553
					while (!feof($this->con['socket'])) {
554
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
555
						$code = substr($this->con['buffer']['all'], 0, 3);
556
						sleep(1);
557 1e0b1727 Phil Davis
						switch ($code) {
558 1fa2f630 Erik Kristensen
							case 100:
559
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
560
								break;
561
							case 225:
562
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
563
								break;
564
							case 901:
565
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
566
								break;
567
							case 795:
568
								fputs($this->con['socket'], "QUIT\n");
569
								break;
570
						}
571
					}
572 425ba708 Ermal
					$this->_checkStatus(0, $code);
573 1fa2f630 Erik Kristensen
					break;
574 9b8dc821 Scott Ullrich
				case 'freedns':
575 7f1349f7 TechSmurf
				case 'freedns-v6':
576 9b8dc821 Scott Ullrich
					$needIP = FALSE;
577 64746cf6 Chris Buechler
					curl_setopt($ch, CURLOPT_URL, 'https://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
578 9b8dc821 Scott Ullrich
					break;
579 0a1b0183 Ermal Luçi
				case 'dnsexit':
580
					$needsIP = TRUE;
581 64746cf6 Chris Buechler
					curl_setopt($ch, CURLOPT_URL, 'https://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
582 0a1b0183 Ermal Luçi
					break;
583 9b8dc821 Scott Ullrich
				case 'loopia':
584
					$needsIP = TRUE;
585
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
586 99295d7b Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
587 9b8dc821 Scott Ullrich
					break;
588 2d78b166 Ermal Luçi
				case 'opendns':
589
					$needsIP = FALSE;
590
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
591
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
592 6bccf4ca smos
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
593 2d78b166 Ermal Luçi
					$port = "";
594 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
595 2d78b166 Ermal Luçi
						$server = $this->_dnsServer;
596 1e0b1727 Phil Davis
					}
597
					if ($this->_dnsPort) {
598 2d78b166 Ermal Luçi
						$port = ":" . $this->_dnsPort;
599 1e0b1727 Phil Davis
					}
600 2d78b166 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server .$port);
601
					break;
602
603 d74b5b8b sullrich
				case 'staticcling':
604
					$needsIP = FALSE;
605 64746cf6 Chris Buechler
					curl_setopt($ch, CURLOPT_URL, 'https://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
606 1e0b1727 Phil Davis
					break;
607 52e6fdfd Scott Dale
				case 'dnsomatic':
608 1e0b1727 Phil Davis
					/* Example syntax
609 52e6fdfd Scott Dale
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
610
					*/
611
					$needsIP = FALSE;
612 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
613
						$this->_dnsWildcard = "ON";
614
					}
615 99438649 swatspyder
					/*
616
					Reference: https://www.dnsomatic.com/wiki/api
617
						DNS-O-Matic usernames are 3-25 characters.
618
						DNS-O-Matic passwords are 6-20 characters.
619
						All ASCII letters and numbers accepted.
620
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
621
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
622
						Encodes the given string according to RFC 3986.
623
					*/
624
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
625 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
626 52e6fdfd Scott Dale
						$server = $this->_dnsServer;
627 1e0b1727 Phil Davis
					}
628
					if ($this->_dnsPort) {
629 52e6fdfd Scott Dale
						$port = ":" . $this->_dnsPort;
630 1e0b1727 Phil Davis
					}
631 52e6fdfd Scott Dale
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
632
					break;
633 61c30081 jim-p
				case 'namecheap':
634
					/* Example:
635
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
636
					*/
637
					$needsIP = FALSE;
638 4178d033 jim-p
					$dnspass = trim($this->_dnsPass);
639 6635aa0f jim-p
					$server = "https://dynamicdns.park-your-domain.com/update?host={$this->_dnsHost}&domain={$this->_dnsDomain}&password={$dnspass}&ip={$this->_dnsIP}";
640 61c30081 jim-p
					curl_setopt($ch, CURLOPT_URL, $server);
641 8ea77433 Chris Wells
					break;
642 4a77c4ea Ionut
				case 'duiadns':
643
				case 'duiadns-v6':
644
					$needsIP = FALSE;
645
					$server = "https://ipv4.duiadns.net/dyndns.duia?";
646
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
647
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
648
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
649
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
650
					break;
651 8ea77433 Chris Wells
				case 'he-net':
652 d7e6f573 Daniel Becker
				case 'he-net-v6':
653 8ea77433 Chris Wells
					$needsIP = FALSE;
654
					$server = "https://dyn.dns.he.net/nic/update?";
655 086cf944 Phil Davis
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
656 393dac91 Chris Buechler
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
657 16fea0ce Cedric Ohle
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
658 8ea77433 Chris Wells
					break;
659 38a481ad jim-p
				case 'he-net-tunnelbroker':
660
					$needsIP = FALSE;
661
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
662
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
663
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
664
					break;
665 fb403496 Gerald Raaf
				case 'selfhost':
666
					$needsIP = FALSE;
667 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
668
						$this->_dnsWildcard = "ON";
669
					}
670 fb403496 Gerald Raaf
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
671
					$server = "https://carol.selfhost.de/nic/update";
672
					$port = "";
673 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
674 fb403496 Gerald Raaf
						$server = $this->_dnsServer;
675 1e0b1727 Phil Davis
					}
676
					if ($this->_dnsPort) {
677 fb403496 Gerald Raaf
						$port = ":" . $this->_dnsPort;
678 1e0b1727 Phil Davis
					}
679 fb403496 Gerald Raaf
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
680
					break;
681 0c7bb880 Phil Davis
				case 'route53':
682 a0dd4ec2 Jason McCormick
					/* http://docs.aws.amazon.com/Route53/latest/APIReference/Welcome.html */
683
					$reqdate = gmdate('D, d M Y H:i:s e');
684
					$httphead[] = array();
685 9783e0c2 Jason McCormick
					$httphead[] = sprintf("Date: %s", $reqdate);
686 a0dd4ec2 Jason McCormick
					/* to avoid having user to know their AWS Region, for now use V3 */
687
					$httphead[] = sprintf(
688 9783e0c2 Jason McCormick
							"X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HMACSHA256,SignedHeaders=date,Signature=%s",
689 a0dd4ec2 Jason McCormick
							$this->_dnsUser,
690 9783e0c2 Jason McCormick
							base64_encode(hash_hmac("sha256", $reqdate, $this->_dnsPass, true))
691 a0dd4ec2 Jason McCormick
					);					
692
					$apiurl = sprintf("https://route53.amazonaws.com/2013-04-01/hostedzone/%s/rrset", $this->_dnsZoneID);
693
					$xmlreq .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
694 9783e0c2 Jason McCormick
					$xmlreq .= "<ChangeResourceRecordSetsRequest xmlns=\"https://route53.amazonaws.com/doc/2013-04-01/\">";
695 a0dd4ec2 Jason McCormick
					$xmlreq .= "<ChangeBatch><Changes><Change>";
696
					$xmlreq .= "<Action>UPSERT</Action>";
697
					$xmlreq .= "<ResourceRecordSet>";
698
					$xmlreq .= sprintf("<Name>%s</Name>", $this->_dnsHost);
699
					$xmlreq .= "<Type>A</Type>";
700
					$xmlreq .= sprintf("<TTL>%d</TTL>", $this->_dnsTTL);
701
					$xmlreq .= sprintf("<ResourceRecords><ResourceRecord><Value>%s</Value></ResourceRecord></ResourceRecords>",
702
								$this->_dnsIP);
703
					$xmlreq .= "</ResourceRecordSet>";
704
					$xmlreq .= "</Change></Changes></ChangeBatch>";
705 9783e0c2 Jason McCormick
					$xmlreq .= "</ChangeResourceRecordSetsRequest>";
706 a0dd4ec2 Jason McCormick
					
707
					$httphead[] = "Content-Type: text/plain";
708
					$httphead[] = sprintf("Content-Length: %d", strlen($xmlreq));
709
					
710
					curl_setopt($ch, CURLOPT_HTTPHEADER, $httphead);
711
					if($this->_dnsVerboseLog){
712
						log_error(sprintf("Sending reuquest to: %s", $apiurl));
713
						foreach($httphead as $hv){
714
							log_error(sprintf("Header: %s", $hv));
715 0c7bb880 Phil Davis
						}
716 a0dd4ec2 Jason McCormick
						log_error(sprintf("XMLPOST:\n%s\n\n", $xmlreq));
717 0c7bb880 Phil Davis
					}
718 a0dd4ec2 Jason McCormick
					curl_setopt($ch, CURLOPT_URL, $apiurl);
719
					curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlreq);
720 0c7bb880 Phil Davis
					break;
721 37f3e704 Matt Corallo
				case 'custom':
722 da40615d Daniel Becker
				case 'custom-v6':
723 37f3e704 Matt Corallo
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
724
					if ($this->_dnsUser != '') {
725 1e0b1727 Phil Davis
						if ($this->_curlIpresolveV4) {
726 086cf944 Phil Davis
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
727 1e0b1727 Phil Davis
						}
728
						if ($this->_curlSslVerifypeer) {
729 aa79f351 Sebastian Chrostek
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
730 1e0b1727 Phil Davis
						} else {
731 aa79f351 Sebastian Chrostek
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
732 1e0b1727 Phil Davis
						}
733
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
734 37f3e704 Matt Corallo
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
735
					}
736
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
737 1e0b1727 Phil Davis
					if ($this->_dnsVerboseLog) {
738 9557ca30 Phil Davis
						log_error(sprintf(gettext("Sending request to: %s"), $server));
739 1e0b1727 Phil Davis
					}
740 37f3e704 Matt Corallo
					curl_setopt($ch, CURLOPT_URL, $server);
741
					break;
742 b18e885c Phil Davis
				case 'cloudflare-v6':
743 e26e1f76 Andrew Senetar
				case 'cloudflare':
744 b18e885c Phil Davis
					$isv6 = ($this->_dnsService === 'cloudflare-v6');
745
					$recordType = $isv6 ? "AAAA" : "A";
746 e26e1f76 Andrew Senetar
					$needsIP = TRUE;
747 22d95a68 doktornotor
					$dnsServer ='api.cloudflare.com';
748 4e322e2c Phil Davis
					$dnsHost = str_replace(' ', '', $this->_dnsHost);
749 22d95a68 doktornotor
750
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
751
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
752
						'X-Auth-Email: '.$this->_dnsUser.'',
753
						'X-Auth-Key: '.$this->_dnsPass.'',
754
						'Content-Type: application/json'
755
					));
756
757
					// Get zone ID
758 be17e372 Phil Davis
					$getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$this->_dnsDomain}";
759 b37b4034 Phil Davis
					curl_setopt($ch, CURLOPT_URL, $getZoneId);
760 22d95a68 doktornotor
					$output = json_decode(curl_exec($ch));
761
					$zone = $output->result[0]->id;
762 4e322e2c Phil Davis
					if ($zone) { // If zone ID was found get host ID
763 be17e372 Phil Davis
						$getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_FQDN}&type={$recordType}";
764 b37b4034 Phil Davis
						curl_setopt($ch, CURLOPT_URL, $getHostId);
765 22d95a68 doktornotor
						$output = json_decode(curl_exec($ch));
766
						$host = $output->result[0]->id;
767 4e322e2c Phil Davis
						if ($host) { // If host ID was found update host
768 22d95a68 doktornotor
							$hostData = array(
769
								"content" => "{$this->_dnsIP}",
770 b18e885c Phil Davis
								"type" => "{$recordType}",
771 e93a7c71 calvinbui
								"name" => "{$this->_dnsHost}"
772 22d95a68 doktornotor
							);
773
							$data_json = json_encode($hostData);
774
							$updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}";
775 b37b4034 Phil Davis
							curl_setopt($ch, CURLOPT_URL, $updateHostId);
776 22d95a68 doktornotor
							curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
777 4e322e2c Phil Davis
							curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
778 22d95a68 doktornotor
						}
779
					}
780 e26e1f76 Andrew Senetar
					break;
781 1e0b1727 Phil Davis
				case 'eurodns':
782 ec66caa6 John Byron
					$needsIP = TRUE;
783
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
784 874599b9 johnbyronent
					$server = "https://update.eurodyndns.org/update/";
785 ec66caa6 John Byron
					$port = "";
786 1e0b1727 Phil Davis
					if ($this->_dnsPort) {
787 ec66caa6 John Byron
						$port = ":" . $this->_dnsPort;
788 1e0b1727 Phil Davis
					}
789 ec66caa6 John Byron
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
790 5458bc59 Scavy
					break;
791
				case 'gratisdns':
792 3e31a7f8 mortencombat
					$needsIP = TRUE;
793 5458bc59 Scavy
					$server = "https://ssl.gratisdns.dk/ddns.phtml";
794 be17e372 Phil Davis
					curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $this->_dnsHost . '&d=' . $this->_dnsDomain . '&i=' . $this->_dnsIP);
795 5458bc59 Scavy
					break;
796 a4a56eb0 Stéphane
				case 'ovh-dynhost':
797
					$needsIP = FALSE;
798
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
799
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
800
					$server = "https://www.ovh.com/nic/update";
801
					$port = "";
802 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
803 a4a56eb0 Stéphane
						$server = $this->_dnsServer;
804 1e0b1727 Phil Davis
					}
805
					if ($this->_dnsPort) {
806 a4a56eb0 Stéphane
						$port = ":" . $this->_dnsPort;
807 1e0b1727 Phil Davis
					}
808 a4a56eb0 Stéphane
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
809
					break;
810 2206f1b9 Mathias Andersson
				case 'citynetwork':
811
					$needsIP = TRUE;
812
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
813
					$server = 'https://dyndns.citynetwork.se/nic/update';
814
					$port = "";
815 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
816 2206f1b9 Mathias Andersson
						$server = $this->_dnsServer;
817 1e0b1727 Phil Davis
					}
818
					if ($this->_dnsPort) {
819 2206f1b9 Mathias Andersson
						$port = ":" . $this->_dnsPort;
820 1e0b1727 Phil Davis
					}
821 2206f1b9 Mathias Andersson
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
822
					break;
823 916d683e surrural
				case 'dnsimple':
824
					/* Uses DNSimple's REST API
825
					   Requires username and Account API token passed in header
826
					   Piggybacks on Route 53's ZoneID field for DNSimple record ID
827
					   Data sent as JSON */
828
					$needsIP = TRUE;
829
					$server = 'https://api.dnsimple.com/v1/domains/';
830
					$token = $this->_dnsUser . ':' . $this->_dnsPass;
831
					$jsondata = '{"record":{"content":"' . $this->_dnsIP . '","ttl":"' . $this->_dnsTTL . '"}}';
832
					curl_setopt($ch, CURLOPT_HEADER, 1);
833
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
834 086cf944 Phil Davis
					curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-DNSimple-Token: ' . $token));
835 916d683e surrural
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '/records/' . $this->_dnsZoneID);
836
					curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
837
					break;
838 c5ecdc25 Jose Luis Duran
				case 'googledomains':
839 6c92b378 Christopher Fazendin
					$needsIP = FALSE;
840
					$post_data['username:password'] = $this->_dnsUser . ':' . $this->_dnsPass;
841
					$post_data['hostname'] = $this->_dnsHost;
842
					$post_data['myip'] = $this->_dnsIP;
843
					$post_data['offline'] = 'no';
844 404ff523 Christopher Fazendin
					$server = "https://domains.google.com/nic/update";
845 6c92b378 Christopher Fazendin
					$port = "";
846
					curl_setopt($ch, CURLOPT_URL, 'https://domains.google.com/nic/update');
847
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
848
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
849
					break;
850 c5ecdc25 Jose Luis Duran
				case 'dnsmadeeasy':
851
					$needsIP = TRUE;
852
					$server = "https://cp.dnsmadeeasy.com/servlet/updateip";
853
					curl_setopt($ch, CURLOPT_URL, $server . '?username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&id=' . $this->_dnsHost . '&ip=' . $this->_dnsIP);
854
					break;
855 608090e8 exii1988
				case 'spdyn':
856
				case 'spdyn-v6':
857 f3ee8545 Rene Schuster
					$needsIP = FALSE;
858
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
859 608090e8 exii1988
					$server = "https://update.spdyn.de/nic/update";
860 f3ee8545 Rene Schuster
					$port = "";
861 4e322e2c Phil Davis
					if ($this->_dnsServer) {
862 f3ee8545 Rene Schuster
						$server = $this->_dnsServer;
863 4e322e2c Phil Davis
					}
864
					if ($this->_dnsPort) {
865 f3ee8545 Rene Schuster
						$port = ":" . $this->_dnsPort;
866 4e322e2c Phil Davis
					}
867 f3ee8545 Rene Schuster
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
868
					break;
869 3c2a6448 Christoph Filnkößl
				case 'all-inkl':
870
					$needsIP = FALSE;
871
					$server = 'https://dyndns.kasserver.com/';
872
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
873
					curl_setopt($ch, CURLOPT_URL, $server . 'myip=' . $this->_dnsIP);
874
					break;
875 1fa2f630 Erik Kristensen
				default:
876
					break;
877
			}
878 a0dd4ec2 Jason McCormick
			if ($this->_dnsService != 'ods') {
879 b6417760 Christoph Filnkößl
				$response = curl_exec($ch);
880
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
881
				$header = substr($response, 0, $header_size);
882
				$data = substr($response, $header_size);
883
				$this->_checkStatus($ch, $data, $header);
884 425ba708 Ermal
				@curl_close($ch);
885
			}
886 1fa2f630 Erik Kristensen
		}
887
888
		/*
889
		 * Private Function (added 12 July 2005) [beta]
890
		 *   Retrieve Update Status
891
		 */
892 dd28abbd Ermal
		function _checkStatus($ch, $data) {
893 87b91672 Phil Davis
			if ($this->_dnsVerboseLog) {
894 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
895 87b91672 Phil Davis
			}
896 4a6bb2ff Scott Ullrich
			$successful_update = false;
897 9557ca30 Phil Davis
			$success_str = "(" . gettext("Success") . ") ";
898
			$error_str = "(" . gettext("Error") . ") ";
899
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
900
901 a0dd4ec2 Jason McCormick
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
902 9557ca30 Phil Davis
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
903 425ba708 Ermal
				log_error($status);
904
				$this->status = $status;
905
				return;
906
			}
907 1fa2f630 Erik Kristensen
			switch ($this->_dnsService) {
908 197cf433 McB
				case 'glesys':
909 9557ca30 Phil Davis
					$status_intro = "GleSYS ({$this->_dnsHost}): ";
910 197cf433 McB
					if (preg_match('/Record updated/i', $data)) {
911 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
912 197cf433 McB
						$successful_update = true;
913
					} else {
914 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
915
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
916 197cf433 McB
						$this->_debug($data);
917
					}
918
					break;
919 52e6fdfd Scott Dale
				case 'dnsomatic':
920 9557ca30 Phil Davis
					$status_intro = "DNS-O-Matic ({$this->_dnsHost}): ";
921 52e6fdfd Scott Dale
					if (preg_match('/badauth/i', $data)) {
922 9557ca30 Phil Davis
						$status = $status_intro . gettext("The DNS-O-Matic username or password specified are incorrect. No updates will be distributed to services until this is resolved.");
923 52e6fdfd Scott Dale
					} else if (preg_match('/notfqdn /i', $data)) {
924 9557ca30 Phil Davis
						$status = $status_intro . gettext("The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.");
925 52e6fdfd Scott Dale
					} else if (preg_match('/nohost/i', $data)) {
926 9557ca30 Phil Davis
						$status = $status_intro . gettext("The hostname passed could not be matched to any services configured. The service field will be blank in the return code.");
927 52e6fdfd Scott Dale
					} else if (preg_match('/numhost/i', $data)) {
928 1c92c5b1 Stephen Beaver
						$status = $status_intro . gettext("Up to 20 hosts my be updated. numhost is returned if attempting to update more than 20 or update a round-robin.");
929 52e6fdfd Scott Dale
					} else if (preg_match('/abuse/i', $data)) {
930 9557ca30 Phil Davis
						$status = $status_intro . gettext("The hostname is blocked for update abuse.");
931 52e6fdfd Scott Dale
					} else if (preg_match('/good/i', $data)) {
932 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
933 52e6fdfd Scott Dale
						$successful_update = true;
934
					} else if (preg_match('/dnserr/i', $data)) {
935 9557ca30 Phil Davis
						$status = $status_intro . gettext("DNS error encountered. Stop updating for 30 minutes.");
936 52e6fdfd Scott Dale
					} else {
937 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
938
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
939 52e6fdfd Scott Dale
						$this->_debug($data);
940
					}
941
					break;
942 2206f1b9 Mathias Andersson
				case 'citynetwork':
943
					if (preg_match('/notfqdn/i', $data)) {
944 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
945 2206f1b9 Mathias Andersson
					} else if (preg_match('/nohost/i', $data)) {
946 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No such host");
947 2206f1b9 Mathias Andersson
					} else if (preg_match('/nochg/i', $data)) {
948 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
949 2206f1b9 Mathias Andersson
						$successful_update = true;
950
					} else if (preg_match('/good/i', $data)) {
951 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
952 2206f1b9 Mathias Andersson
						$successful_update = true;
953
					} else if (preg_match('/badauth/i', $data)) {
954 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
955 2206f1b9 Mathias Andersson
					} else {
956 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
957
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
958 2206f1b9 Mathias Andersson
						$this->_debug($data);
959
					}
960
					break;
961 a4a56eb0 Stéphane
				case 'ovh-dynhost':
962 1fa2f630 Erik Kristensen
				case 'dyndns':
963
					if (preg_match('/notfqdn/i', $data)) {
964 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
965 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
966 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
967 0ede1bf7 Scott Ullrich
						$successful_update = true;
968 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
969 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
970 4a6bb2ff Scott Ullrich
						$successful_update = true;
971 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
972 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
973 1fa2f630 Erik Kristensen
					} else {
974 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
975
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
976 1fa2f630 Erik Kristensen
						$this->_debug($data);
977
					}
978
					break;
979
				case 'dyndns-static':
980
					if (preg_match('/notfqdn/i', $data)) {
981 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
982 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
983 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
984 9b8dc821 Scott Ullrich
						$successful_update = true;
985 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
986 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
987 4a6bb2ff Scott Ullrich
						$successful_update = true;
988 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
989 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
990 1fa2f630 Erik Kristensen
					} else {
991 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
992
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
993 1fa2f630 Erik Kristensen
						$this->_debug($data);
994
					}
995
					break;
996
				case 'dyndns-custom':
997
					if (preg_match('/notfqdn/i', $data)) {
998 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
999 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
1000 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1001 9b8dc821 Scott Ullrich
						$successful_update = true;
1002 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
1003 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1004 4a6bb2ff Scott Ullrich
						$successful_update = true;
1005 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
1006 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1007 1fa2f630 Erik Kristensen
					} else {
1008 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1009
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1010 1fa2f630 Erik Kristensen
						$this->_debug($data);
1011
					}
1012
					break;
1013
				case 'dhs':
1014
					break;
1015
				case 'noip':
1016 0333f968 Phil Davis
				case 'noip-free':
1017 086cf944 Phil Davis
					list($ip, $code) = explode(":", $data);
1018 1fa2f630 Erik Kristensen
					switch ($code) {
1019
						case 0:
1020 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("IP address is current, no update performed.");
1021 4a6bb2ff Scott Ullrich
							$successful_update = true;
1022 1fa2f630 Erik Kristensen
							break;
1023
						case 1:
1024 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS hostname update successful.");
1025 4a6bb2ff Scott Ullrich
							$successful_update = true;
1026 1fa2f630 Erik Kristensen
							break;
1027
						case 2:
1028 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Hostname supplied does not exist.");
1029 1fa2f630 Erik Kristensen
							break;
1030
						case 3:
1031 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid Username.");
1032 1fa2f630 Erik Kristensen
							break;
1033
						case 4:
1034 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid Password.");
1035 1fa2f630 Erik Kristensen
							break;
1036
						case 5:
1037 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Too many updates sent.");
1038 1fa2f630 Erik Kristensen
							break;
1039
						case 6:
1040 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account disabled due to violation of No-IP terms of service.");
1041 1fa2f630 Erik Kristensen
							break;
1042
						case 7:
1043 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.");
1044 1fa2f630 Erik Kristensen
							break;
1045
						case 8:
1046 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Disabled / Locked Hostname.");
1047 1fa2f630 Erik Kristensen
							break;
1048
						case 9:
1049 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Host updated is configured as a web redirect and no update was performed.");
1050 1fa2f630 Erik Kristensen
							break;
1051
						case 10:
1052 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Group supplied does not exist.");
1053 1fa2f630 Erik Kristensen
							break;
1054
						case 11:
1055 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS group update is successful.");
1056 4a6bb2ff Scott Ullrich
							$successful_update = true;
1057 1fa2f630 Erik Kristensen
							break;
1058
						case 12:
1059 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS group is current, no update performed.");
1060 4a6bb2ff Scott Ullrich
							$successful_update = true;
1061 1fa2f630 Erik Kristensen
							break;
1062
						case 13:
1063 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Update client support not available for supplied hostname or group.");
1064 1fa2f630 Erik Kristensen
							break;
1065
						case 14:
1066 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Hostname supplied does not have offline settings configured.");
1067 1fa2f630 Erik Kristensen
							break;
1068
						case 99:
1069 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1070 1fa2f630 Erik Kristensen
							break;
1071
						case 100:
1072 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1073 1fa2f630 Erik Kristensen
							break;
1074
						default:
1075 9557ca30 Phil Davis
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1076
							$this->_debug(gettext("Unknown Response:") . " " . $data);
1077 1fa2f630 Erik Kristensen
							break;
1078
					}
1079
					break;
1080
				case 'easydns':
1081
					if (preg_match('/NOACCESS/i', $data)) {
1082 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Authentication Failed: Username and/or Password was Incorrect.");
1083 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOSERVICE/i', $data)) {
1084 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No Service: Dynamic DNS Service has been disabled for this domain.");
1085 1fa2f630 Erik Kristensen
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
1086 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Illegal Input: Self-Explanatory");
1087 1fa2f630 Erik Kristensen
					} else if (preg_match('/TOOSOON/i', $data)) {
1088 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Too Soon: Not Enough Time Has Elapsed Since Last Update");
1089 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOERROR/i', $data)) {
1090 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Updated Successfully!");
1091 4a6bb2ff Scott Ullrich
						$successful_update = true;
1092 1fa2f630 Erik Kristensen
					} else {
1093 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1094
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1095 1fa2f630 Erik Kristensen
						$this->_debug($data);
1096
					}
1097
					break;
1098
				case 'hn':
1099 9b8dc821 Scott Ullrich
					/* FIXME: add checks */
1100 1fa2f630 Erik Kristensen
					break;
1101
				case 'zoneedit':
1102 9b9e5f09 Scott Ullrich
					if (preg_match('/799/i', $data)) {
1103 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Error 799") . ") " . gettext("Update Failed!");
1104 332a3e59 Scott Ullrich
					} else if (preg_match('/700/i', $data)) {
1105 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Error 700") . ") " . gettext("Update Failed!");
1106 9b9e5f09 Scott Ullrich
					} else if (preg_match('/200/i', $data)) {
1107 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1108 4a6bb2ff Scott Ullrich
						$successful_update = true;
1109 9b9e5f09 Scott Ullrich
					} else if (preg_match('/201/i', $data)) {
1110 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1111 1e0b1727 Phil Davis
						$successful_update = true;
1112 1fa2f630 Erik Kristensen
					} else {
1113 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1114
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1115 1fa2f630 Erik Kristensen
						$this->_debug($data);
1116
					}
1117
					break;
1118
				case 'dyns':
1119
					if (preg_match("/400/i", $data)) {
1120 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The URL was malformed. Required parameters were not provided.");
1121 1fa2f630 Erik Kristensen
					} else if (preg_match('/402/i', $data)) {
1122 1c92c5b1 Stephen Beaver
						$status = $status_intro . $error_str . gettext("Update Too Soon - Attempted to update too quickly since last change.");
1123 1fa2f630 Erik Kristensen
					} else if (preg_match('/403/i', $data)) {
1124 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Database Error - There was a server-sided database error.");
1125 1fa2f630 Erik Kristensen
					} else if (preg_match('/405/i', $data)) {
1126 b9f7281a NOYB
						$status = $status_intro . $error_str . sprintf(gettext("Hostname Error - The hostname (%s) doesn't belong to user (%s)."), $this->_dnsHost, $this->_dnsUser);
1127 1fa2f630 Erik Kristensen
					} else if (preg_match('/200/i', $data)) {
1128 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1129 4a6bb2ff Scott Ullrich
						$successful_update = true;
1130 1fa2f630 Erik Kristensen
					} else {
1131 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1132
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1133 1fa2f630 Erik Kristensen
						$this->_debug($data);
1134
					}
1135
					break;
1136
				case 'ods':
1137
					if (preg_match("/299/i", $data)) {
1138 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1139 4a6bb2ff Scott Ullrich
						$successful_update = true;
1140 1fa2f630 Erik Kristensen
					} else {
1141 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1142
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1143 1fa2f630 Erik Kristensen
						$this->_debug($data);
1144
					}
1145
					break;
1146 9b8dc821 Scott Ullrich
				case 'freedns':
1147 7f1349f7 TechSmurf
				case 'freedns-v6':
1148 9b8dc821 Scott Ullrich
					if (preg_match("/has not changed./i", $data)) {
1149 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1150 9b8dc821 Scott Ullrich
						$successful_update = true;
1151
					} else if (preg_match("/Updated/i", $data)) {
1152 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1153 9b8dc821 Scott Ullrich
						$successful_update = true;
1154
					} else {
1155 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1156
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1157 9b8dc821 Scott Ullrich
						$this->_debug($data);
1158 1e0b1727 Phil Davis
					}
1159 9b8dc821 Scott Ullrich
					break;
1160 0a1b0183 Ermal Luçi
				case 'dnsexit':
1161
					if (preg_match("/is the same/i", $data)) {
1162 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1163 0a1b0183 Ermal Luçi
						$successful_update = true;
1164
					} else if (preg_match("/Success/i", $data)) {
1165 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1166 0a1b0183 Ermal Luçi
						$successful_update = true;
1167
					} else {
1168 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1169
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1170 87b91672 Phil Davis
						$this->_debug($data);
1171 0a1b0183 Ermal Luçi
					}
1172
					break;
1173 9b8dc821 Scott Ullrich
				case 'loopia':
1174
					if (preg_match("/nochg/i", $data)) {
1175 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1176 9b8dc821 Scott Ullrich
						$successful_update = true;
1177
					} else if (preg_match("/good/i", $data)) {
1178 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1179 9b8dc821 Scott Ullrich
						$successful_update = true;
1180
					} else if (preg_match('/badauth/i', $data)) {
1181 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1182 9b8dc821 Scott Ullrich
					} else {
1183 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1184
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1185 9b8dc821 Scott Ullrich
						$this->_debug($data);
1186
					}
1187
					break;
1188 2d78b166 Ermal Luçi
				case 'opendns':
1189
					if (preg_match('/badauth/i', $data)) {
1190 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not a valid username or password!");
1191 2d78b166 Ermal Luçi
					} else if (preg_match('/nohost/i', $data)) {
1192 1c92c5b1 Stephen Beaver
						$status = $status_intro . $error_str . gettext("Hostname specified does not exist.");
1193 2d78b166 Ermal Luçi
						$successful_update = true;
1194
					} else if (preg_match('/good/i', $data)) {
1195 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1196 2d78b166 Ermal Luçi
						$successful_update = true;
1197
					} else if (preg_match('/yours/i', $data)) {
1198 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Hostname specified exists, but not under the username specified.");
1199 2d78b166 Ermal Luçi
					} else if (preg_match('/abuse/i', $data)) {
1200 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Updating too frequently, considered abuse.");
1201 2d78b166 Ermal Luçi
					} else {
1202 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1203
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1204 2d78b166 Ermal Luçi
						$this->_debug($data);
1205
					}
1206
					break;
1207 37f3e704 Matt Corallo
				case 'staticcling':
1208 d74b5b8b sullrich
					if (preg_match("/invalid ip/i", $data)) {
1209 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1210 d74b5b8b sullrich
					} else if (preg_match('/required info missing/i', $data)) {
1211 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Required parameters were not provided.");
1212 d74b5b8b sullrich
					} else if (preg_match('/invalid characters/i', $data)) {
1213 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Illegal characters in either the username or the password.");
1214 d74b5b8b sullrich
					} else if (preg_match('/bad password/i', $data)) {
1215 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid password.");
1216 d74b5b8b sullrich
					} else if (preg_match('/account locked/i', $data)) {
1217 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("This account has been administratively locked.");
1218 d74b5b8b sullrich
					} else if (preg_match('/update too frequent/i', $data)) {
1219 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Updating too frequently.");
1220 d74b5b8b sullrich
					} else if (preg_match('/DB error/i', $data)) {
1221 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Server side error.");
1222 d74b5b8b sullrich
					} else if (preg_match('/success/i', $data)) {
1223 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1224 0c7bb880 Phil Davis
						$successful_update = true;
1225 d74b5b8b sullrich
					} else {
1226 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1227
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1228 0c7bb880 Phil Davis
						$this->_debug($data);
1229 d74b5b8b sullrich
					}
1230
					break;
1231 61c30081 jim-p
				case 'namecheap':
1232 18f15f68 jim-p
					$tmp = str_replace("^M", "", $data);
1233
					$ncresponse = @xml2array($tmp);
1234 61c30081 jim-p
					if (preg_match("/internal server error/i", $data)) {
1235 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Server side error.");
1236 3dc3b15b jim-p
					} else if (preg_match("/request is badly formed/i", $data)) {
1237 1c92c5b1 Stephen Beaver
						$status = $status_intro . $error_str . gettext("Badly Formed Request (check the settings).");
1238 18f15f68 jim-p
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1239 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1240 c305abd5 jim-p
						$successful_update = true;
1241 18f15f68 jim-p
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1242 9557ca30 Phil Davis
						$status = $status_intro . $error_str . implode(", ", $ncresponse["interface-response"]["errors"]);
1243 c305abd5 jim-p
						$successful_update = true;
1244 61c30081 jim-p
					} else {
1245 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1246
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1247 61c30081 jim-p
						$this->_debug($data);
1248
					}
1249
					break;
1250 4a77c4ea Ionut
				case 'duiadns':
1251
				case 'duiadns-v6':
1252
					if (preg_match("/error/i", $data)) {
1253
						$status = $status_intro . $error_str . gettext("Server side error.");
1254
					} else if (preg_match('/nohost/i', $data)) {
1255
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1256
					} else if (preg_match('/badauth/i', $data)) {
1257
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1258
					} else if (preg_match('/good/i', $data)) {
1259
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1260
						$successful_update = true;
1261
					} else if (preg_match('/nochg/i', $data)) {
1262
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1263
						$successful_update = true;
1264
					} else {
1265
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1266
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1267
						$this->_debug($data);
1268
					}
1269
					break;
1270 8ea77433 Chris Wells
				case 'he-net':
1271 b4025ccd Daniel Becker
				case 'he-net-v6':
1272 8ea77433 Chris Wells
					if (preg_match("/badip/i", $data)) {
1273 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1274 8ea77433 Chris Wells
					} else if (preg_match('/nohost/i', $data)) {
1275 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1276 8ea77433 Chris Wells
					} else if (preg_match('/badauth/i', $data)) {
1277 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1278 8ea77433 Chris Wells
					} else if (preg_match('/good/i', $data)) {
1279 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1280 0c7bb880 Phil Davis
						$successful_update = true;
1281 8ea77433 Chris Wells
					} else if (preg_match('/nochg/i', $data)) {
1282 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1283 0c7bb880 Phil Davis
						$successful_update = true;
1284 8ea77433 Chris Wells
					} else {
1285 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1286
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1287 0c7bb880 Phil Davis
						$this->_debug($data);
1288 8ea77433 Chris Wells
					}
1289
					break;
1290 38a481ad jim-p
				case 'he-net-tunnelbroker':
1291
					/*
1292
					-ERROR: Missing parameter(s).
1293
					-ERROR: Invalid API key or password
1294
					-ERROR: Tunnel not found
1295
					-ERROR: Another tunnel exists for this IP.
1296
					-ERROR: This tunnel is already associated with this IP address
1297
					+OK: Tunnel endpoint updated to: x.x.x.x
1298
					*/
1299
					if (preg_match("/Missing parameter/i", $data)) {
1300 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Missing/Invalid Parameters.");
1301 38a481ad jim-p
					} else if (preg_match('/Tunnel not found/i', $data)) {
1302 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Invalid Tunnel ID.");
1303 38a481ad jim-p
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1304 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1305 38a481ad jim-p
					} else if (preg_match('/OK:/i', $data)) {
1306 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1307 0c7bb880 Phil Davis
						$successful_update = true;
1308 38a481ad jim-p
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1309 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1310 0c7bb880 Phil Davis
						$successful_update = true;
1311 38a481ad jim-p
					} else {
1312 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1313
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1314 0c7bb880 Phil Davis
						$this->_debug($data);
1315 38a481ad jim-p
					}
1316
					break;
1317 fb403496 Gerald Raaf
				case 'selfhost':
1318
					if (preg_match('/notfqdn/i', $data)) {
1319 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1320 fb403496 Gerald Raaf
					} else if (preg_match('/nochg/i', $data)) {
1321 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1322 fb403496 Gerald Raaf
						$successful_update = true;
1323
					} else if (preg_match('/good/i', $data)) {
1324 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1325 fb403496 Gerald Raaf
						$successful_update = true;
1326
					} else if (preg_match('/noauth/i', $data)) {
1327 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1328 fb403496 Gerald Raaf
					} else {
1329 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1330
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1331 fb403496 Gerald Raaf
						$this->_debug($data);
1332
					}
1333
					break;
1334 0c7bb880 Phil Davis
				case 'route53':
1335 a0dd4ec2 Jason McCormick
					if(preg_match('/ErrorResponse/', $data)){
1336
						$status = $status_intro . $error_str . gettext("Route53 API call failed");
1337
						log_error(sprintf("error message: %s", $data));
1338
						$status_update = false;
1339
					} else {
1340 4bc737dc Jason McCormick
						$status = $status_intro . $success_str . gettext("IP address changed successfully");
1341 a0dd4ec2 Jason McCormick
						$successful_update = true;
1342
					}
1343 0c7bb880 Phil Davis
					break;
1344 37f3e704 Matt Corallo
				case 'custom':
1345 da40615d Daniel Becker
				case 'custom-v6':
1346 37f3e704 Matt Corallo
					$successful_update = false;
1347
					if ($this->_dnsResultMatch == "") {
1348
						$successful_update = true;
1349 1e0b1727 Phil Davis
					} else {
1350 37f3e704 Matt Corallo
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1351
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1352 1e0b1727 Phil Davis
						foreach ($matches as $match) {
1353 37f3e704 Matt Corallo
							$match= str_replace("\\|", "|", $match);
1354 1e0b1727 Phil Davis
							if (strcmp($match, trim($data, "\t\n\r")) == 0) {
1355 37f3e704 Matt Corallo
								$successful_update = true;
1356 1e0b1727 Phil Davis
							}
1357 37f3e704 Matt Corallo
						}
1358
						unset ($matches);
1359
					}
1360 1e0b1727 Phil Davis
					if ($successful_update == true) {
1361 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1362 1e0b1727 Phil Davis
					} else {
1363 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Result did not match.") . " [" . $data . "]";
1364 1e0b1727 Phil Davis
					}
1365 37f3e704 Matt Corallo
					break;
1366 b18e885c Phil Davis
				case 'cloudflare-v6':
1367 e26e1f76 Andrew Senetar
				case 'cloudflare':
1368 22d95a68 doktornotor
					$output = json_decode($data);
1369 4e322e2c Phil Davis
					if ($output->result->content === $this->_dnsIP) {
1370 9557ca30 Phil Davis
						$status = $status_intro . $success_str . sprintf(gettext('%1$s updated to %2$s'), $this->_dnsHost, $this->_dnsIP);
1371 22d95a68 doktornotor
						$successful_update = true;
1372 4e322e2c Phil Davis
					} elseif ($output->errors[0]->code === 9103) {
1373 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.");
1374 4e322e2c Phil Davis
					} elseif (($output->success) && (!$output->result[0]->id)) {
1375 1c92c5b1 Stephen Beaver
						$status = $status_intro . $error_str . gettext("Zone or Host ID was not found, check the hostname.");
1376 4e322e2c Phil Davis
					} else {
1377 9557ca30 Phil Davis
						$status = $status_intro . gettext("UNKNOWN ERROR") . " - " . $output->errors[0]->message;
1378
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1379 ffa1acdc Andrew Senetar
					}
1380
					break;
1381 ec66caa6 John Byron
				case 'eurodns':
1382
					if (preg_match('/notfqdn/i', $data)) {
1383 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1384 ec66caa6 John Byron
					} else if (preg_match('/nochg/i', $data)) {
1385 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1386 ec66caa6 John Byron
						$successful_update = true;
1387
					} else if (preg_match('/good/i', $data)) {
1388 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1389 ec66caa6 John Byron
						$successful_update = true;
1390
					} else if (preg_match('/badauth/i', $data)) {
1391 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1392 ec66caa6 John Byron
					} else {
1393 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1394
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1395 ec66caa6 John Byron
						$this->_debug($data);
1396
					}
1397
					break;
1398 5458bc59 Scavy
				case 'gratisdns':
1399
					if (preg_match('/Forkerte værdier/i', $data)) {
1400 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Wrong values - Update could not be completed.");
1401 5458bc59 Scavy
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1402 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Unknown username - User does not exist.");
1403 5458bc59 Scavy
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1404 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Wrong password - Remember password is case sensitive.");
1405 5458bc59 Scavy
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1406 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User unable to administer the selected domain.");
1407 5458bc59 Scavy
					} else if (preg_match('/OK/i', $data)) {
1408 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1409 1e0b1727 Phil Davis
						$successful_update = true;
1410 5458bc59 Scavy
					} else {
1411 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1412
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1413 1e0b1727 Phil Davis
						$this->_debug($data);
1414 5458bc59 Scavy
					}
1415
					break;
1416 916d683e surrural
				case 'dnsimple':
1417
					/* Responds with HTTP 200 on success.
1418
					   Responds with HTTP 4xx on error.
1419
					   Returns JSON data as body */
1420 b6417760 Christoph Filnkößl
;
1421
					if (preg_match("/\s200\sOK/i", $header)) {
1422 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1423 916d683e surrural
						$successful_update = true;
1424 b6417760 Christoph Filnkößl
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1425
						$arrbody = json_decode($data, true);
1426 916d683e surrural
						$message = $arrbody['message'] . ".";
1427
						if (isset($arrbody['errors']['content'])) {
1428 1e0b1727 Phil Davis
							foreach ($arrbody['errors']['content'] as $key => $content) {
1429 916d683e surrural
								$message .= " " . $content . ".";
1430
							}
1431
						}
1432 9557ca30 Phil Davis
						$status = $status_intro . $error_str . $message;
1433 916d683e surrural
					} else {
1434 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1435 b6417760 Christoph Filnkößl
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1436
						$this->_debug($data);
1437 916d683e surrural
					}
1438
					break;
1439 c5ecdc25 Jose Luis Duran
				case 'googledomains':
1440 6c92b378 Christopher Fazendin
					if (preg_match('/notfqdn/i', $data)) {
1441 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN");
1442 6c92b378 Christopher Fazendin
					} else if (preg_match('/nochg/i', $data)) {
1443 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1444 6c92b378 Christopher Fazendin
						$successful_update = true;
1445
					} else if (preg_match('/good/i', $data)) {
1446 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1447 6c92b378 Christopher Fazendin
						$successful_update = true;
1448
					} else if (preg_match('/badauth/i', $data)) {
1449 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1450 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/nohost/i', $data)) {
1451 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Hostname does not exist or DynDNS not enabled");
1452 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/badagent/i', $data)) {
1453 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad request");
1454 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/abuse/i', $data)) {
1455 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Dynamic DNS access has been blocked!");
1456 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/911/i', $data)) {
1457 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Error on Google's end, retry in 5 minutes");
1458 6c92b378 Christopher Fazendin
					} else {
1459 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1460
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1461 6c92b378 Christopher Fazendin
						$this->_debug($data);
1462
					}
1463
					break;
1464 c5ecdc25 Jose Luis Duran
				case 'dnsmadeeasy':
1465
					switch ($data) {
1466
						case 'success':
1467 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1468 c5ecdc25 Jose Luis Duran
							$successful_update = true;
1469
							break;
1470
						case 'error-auth':
1471 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid username or password");
1472 c5ecdc25 Jose Luis Duran
							break;
1473
						case 'error-auth-suspend':
1474 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account suspended");
1475 c5ecdc25 Jose Luis Duran
							break;
1476
						case 'error-auth-voided':
1477 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account revoked");
1478 c5ecdc25 Jose Luis Duran
							break;
1479
						case 'error-record-invalid':
1480 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Record does not exist in the system. Unable to update record");
1481 c5ecdc25 Jose Luis Duran
							break;
1482
						case 'error-record-auth':
1483 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("User does not have access to this record");
1484 c5ecdc25 Jose Luis Duran
							break;
1485
						case 'error-record-ip-same':
1486 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("No Change In IP Address");
1487 c5ecdc25 Jose Luis Duran
							$successful_update = true;
1488
							break;
1489
						case 'error-system':
1490 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("General system error recognized by the system");
1491 c5ecdc25 Jose Luis Duran
							break;
1492
						case 'error':
1493 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("General system error unrecognized by the system");
1494 c5ecdc25 Jose Luis Duran
							break;
1495
						default:
1496 9557ca30 Phil Davis
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1497
							log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1498 c5ecdc25 Jose Luis Duran
							$this->_debug($data);
1499
							break;
1500
					}
1501
					break;
1502 608090e8 exii1988
				case 'spdyn':
1503
				case 'spdyn-v6':
1504 f3ee8545 Rene Schuster
					if (preg_match('/notfqdn/i', $data)) {
1505 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1506 f3ee8545 Rene Schuster
					} else if (preg_match('/nohost/i', $data)) {
1507 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No such host");
1508 f3ee8545 Rene Schuster
					} else if (preg_match('/nochg/i', $data)) {
1509 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1510
						$successful_update = true;
1511 f3ee8545 Rene Schuster
					} else if (preg_match('/good/i', $data)) {
1512 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1513
						$successful_update = true;
1514 f3ee8545 Rene Schuster
					} else if (preg_match('/badauth/i', $data)) {
1515 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1516 f3ee8545 Rene Schuster
					} else {
1517 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1518
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1519
						$this->_debug($data);
1520 f3ee8545 Rene Schuster
					}
1521
					break;
1522 3c2a6448 Christoph Filnkößl
				case 'all-inkl':
1523
 					if (preg_match('/good\s'.$this->_dnsIP.'/i', $data)) {
1524
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1525
 							$successful_update = true;
1526
 					} else if (preg_match('/good/i', $data)) {
1527
						$status = $status_intro . $error_str . gettext("Result did not match.");
1528
					} else if (preg_match("/\s401\sUnauthorized/i", $header)) {
1529
						$status = $status_intro . $error_str . gettext("Invalid username or password");
1530
					} 
1531
					else {
1532
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1533
							log_error($status_intro . gettext("PAYLOAD:") . " " . $header.$data);
1534
 							$this->_debug($data);
1535
 							$this->_debug($header);
1536
 					}
1537
 					break;
1538 1fa2f630 Erik Kristensen
			}
1539 916d683e surrural
1540 1e0b1727 Phil Davis
			if ($successful_update == true) {
1541 4a6bb2ff Scott Ullrich
				/* Write WAN IP to cache file */
1542 22de7804 Bill Marquette
				$wan_ip = $this->_checkIP();
1543 dd575ea4 Ermal
				conf_mount_rw();
1544 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1545 53842a6c jim-p
					$currentTime = time();
1546 9557ca30 Phil Davis
					notify_all_remote(sprintf(gettext('DynDNS updated IP Address on %1$s (%2$s) to %3$s'), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1547
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1548 dd575ea4 Ermal
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
1549 1e0b1727 Phil Davis
				} else {
1550 dd575ea4 Ermal
					@unlink($this->_cacheFile);
1551 1e0b1727 Phil Davis
				}
1552 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1553 b4025ccd Daniel Becker
					$currentTime = time();
1554 d7e6f573 Daniel Becker
					notify_all_remote(sprintf(gettext("DynDNS updated IPv6 Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1555 9557ca30 Phil Davis
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1556 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1557 1e0b1727 Phil Davis
				} else {
1558 d7e6f573 Daniel Becker
					@unlink($this->_cacheFile_v6);
1559 1e0b1727 Phil Davis
				}
1560 dd575ea4 Ermal
				conf_mount_ro();
1561 4a6bb2ff Scott Ullrich
			}
1562 1fa2f630 Erik Kristensen
			$this->status = $status;
1563
			log_error($status);
1564
		}
1565
1566
		/*
1567
		 * Private Function (added 12 July 05) [beta]
1568
		 *   Return Error, Set Last Error, and Die.
1569
		 */
1570
		function _error($errorNumber = '1') {
1571 9557ca30 Phil Davis
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1572
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1573 1fa2f630 Erik Kristensen
			switch ($errorNumber) {
1574
				case 0:
1575
					break;
1576
				case 2:
1577 9557ca30 Phil Davis
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1578 1fa2f630 Erik Kristensen
					break;
1579
				case 3:
1580 9557ca30 Phil Davis
					$error = $err_str . gettext('No Username Provided.');
1581 1fa2f630 Erik Kristensen
					break;
1582
				case 4:
1583 9557ca30 Phil Davis
					$error = $err_str . gettext('No Password Provided.');
1584 1fa2f630 Erik Kristensen
					break;
1585
				case 5:
1586 9557ca30 Phil Davis
					$error = $err_str . gettext('No Hostname Provided.');
1587 1fa2f630 Erik Kristensen
					break;
1588
				case 6:
1589 9557ca30 Phil Davis
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
1590 1fa2f630 Erik Kristensen
					break;
1591 9b8dc821 Scott Ullrich
				case 7:
1592 9557ca30 Phil Davis
					$error = $err_str . gettext('No Update URL Provided.');
1593 9b8dc821 Scott Ullrich
					break;
1594 0c7bb880 Phil Davis
				case 8:
1595 9557ca30 Phil Davis
					$status = $err_str_r53 . gettext("Invalid ZoneID");
1596 cd132e86 Edson Brandi
					break;
1597 0c7bb880 Phil Davis
				case 9:
1598 9557ca30 Phil Davis
					$status = $err_str_r53 . gettext("Invalid TTL");
1599 1e0b1727 Phil Davis
					break;
1600 1fa2f630 Erik Kristensen
				case 10:
1601 9557ca30 Phil Davis
					$error = "phpDynDNS ({$this->_FQDN}): " . sprintf(gettext("No change in my IP address and/or %s days has not passed. Not updating dynamic DNS entry."), $this->_dnsMaxCacheAgeDays);
1602 1fa2f630 Erik Kristensen
					break;
1603
				default:
1604 9557ca30 Phil Davis
					$error = $err_str . gettext('Unknown Response.');
1605 9b8dc821 Scott Ullrich
					/* FIXME: $data isn't in scope here */
1606
					/* $this->_debug($data); */
1607 1fa2f630 Erik Kristensen
					break;
1608
			}
1609
			$this->lastError = $error;
1610
			log_error($error);
1611
		}
1612
1613
		/*
1614
		 * Private Function (added 12 July 05) [beta]
1615
		 *   - Detect whether or not IP needs to be updated.
1616 5775f324 Chris Buechler
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
1617 1fa2f630 Erik Kristensen
		 *      | work with other systems. pfSense base is FreeBSD.
1618
		 */
1619
		function _detectChange() {
1620 dceff62e Ermal
			global $debug;
1621
1622 1e0b1727 Phil Davis
			if ($debug) {
1623 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
1624 1e0b1727 Phil Davis
			}
1625
1626 1fa2f630 Erik Kristensen
			$currentTime = time();
1627
1628 22de7804 Bill Marquette
			$wan_ip = $this->_checkIP();
1629 dd575ea4 Ermal
			if ($wan_ip == 0) {
1630 9557ca30 Phil Davis
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
1631 193ee786 Ermal
				return false;
1632 dd575ea4 Ermal
			}
1633 9557ca30 Phil Davis
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
1634 1fa2f630 Erik Kristensen
1635 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
1636
				if (file_exists($this->_cacheFile_v6)) {
1637
					$contents = file_get_contents($this->_cacheFile_v6);
1638 086cf944 Phil Davis
					list($cacheIP, $cacheTime) = explode('|', $contents);
1639 d7e6f573 Daniel Becker
					$this->_debug($cacheIP.'/'.$cacheTime);
1640
					$initial = false;
1641 9557ca30 Phil Davis
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
1642 d7e6f573 Daniel Becker
				} else {
1643
					conf_mount_rw();
1644
					$cacheIP = '::';
1645 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
1646 d7e6f573 Daniel Becker
					conf_mount_ro();
1647
					$cacheTime = $currentTime;
1648
					$initial = true;
1649 9557ca30 Phil Davis
					$log_error .= gettext("No Cached IPv6 found.");
1650 d7e6f573 Daniel Becker
				}
1651 1fa2f630 Erik Kristensen
			} else {
1652 d7e6f573 Daniel Becker
				if (file_exists($this->_cacheFile)) {
1653
					$contents = file_get_contents($this->_cacheFile);
1654 086cf944 Phil Davis
					list($cacheIP, $cacheTime) = explode(':', $contents);
1655 d7e6f573 Daniel Becker
					$this->_debug($cacheIP.'/'.$cacheTime);
1656
					$initial = false;
1657 9557ca30 Phil Davis
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
1658 d7e6f573 Daniel Becker
				} else {
1659
					conf_mount_rw();
1660
					$cacheIP = '0.0.0.0';
1661
					@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
1662
					conf_mount_ro();
1663
					$cacheTime = $currentTime;
1664
					$initial = true;
1665 9557ca30 Phil Davis
					$log_error .= gettext("No Cached IP found.");
1666 d7e6f573 Daniel Becker
				}
1667 1fa2f630 Erik Kristensen
			}
1668 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
1669 87b91672 Phil Davis
				log_error($log_error);
1670 1e0b1727 Phil Davis
			}
1671 1fa2f630 Erik Kristensen
1672 f5e293e6 Phil Davis
			// Convert seconds = days * hr/day * min/hr * sec/min
1673
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
1674 1fa2f630 Erik Kristensen
1675 e24b26e9 Scott Ullrich
			$needs_updating = FALSE;
1676 4494cf6a Chris Buechler
			/* lets determine if the item needs updating */
1677 a255e1f7 Scott Ullrich
			if ($cacheIP != $wan_ip) {
1678 eb346556 Ermal Lu?i
				$needs_updating = true;
1679 9557ca30 Phil Davis
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
1680
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
1681 a255e1f7 Scott Ullrich
			}
1682 f5e293e6 Phil Davis
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
1683 c3c3e03b Ermal
				$needs_updating = true;
1684 0333f968 Phil Davis
				$this->_forceUpdateNeeded = true;
1685 9557ca30 Phil Davis
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
1686
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
1687 a255e1f7 Scott Ullrich
			}
1688 eb346556 Ermal Lu?i
			if ($initial == true) {
1689
				$needs_updating = true;
1690 9557ca30 Phil Davis
				$update_reason .= gettext("Initial update.");
1691 a255e1f7 Scott Ullrich
			}
1692 eb346556 Ermal Lu?i
1693 a255e1f7 Scott Ullrich
			/*   finally if we need updating then store the
1694
			 *   new cache value and return true
1695 0c7bb880 Phil Davis
			 */
1696 eb346556 Ermal Lu?i
			if ($needs_updating == true) {
1697 086cf944 Phil Davis
				if ($this->_dnsVerboseLog) {
1698 6635aa0f jim-p
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
1699 086cf944 Phil Davis
				}
1700 eb346556 Ermal Lu?i
				return true;
1701 1fa2f630 Erik Kristensen
			}
1702 eb346556 Ermal Lu?i
1703 1e0b1727 Phil Davis
			return false;
1704 1fa2f630 Erik Kristensen
		}
1705
1706
		/*
1707 0c7bb880 Phil Davis
		 * Private Function (added 16 July 05) [beta]
1708 1fa2f630 Erik Kristensen
		 *   - Writes debug information to a file.
1709
		 *   - This function is only called when a unknown response
1710
		 *   - status is returned from a DynDNS service provider.
1711
		 */
1712 6a45171d Ermal
		function _debug($data) {
1713
			global $g;
1714
1715 1e0b1727 Phil Davis
			if (!$g['debug']) {
1716 6a45171d Ermal
				return;
1717 1e0b1727 Phil Davis
			}
1718 bb9ccd63 bcyrill
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
1719 53d366fd Scott Ullrich
			conf_mount_rw();
1720 1fa2f630 Erik Kristensen
			$file = fopen($this->_debugFile, 'a');
1721
			fwrite($file, $string);
1722
			fclose($file);
1723 53d366fd Scott Ullrich
			conf_mount_ro();
1724 1fa2f630 Erik Kristensen
		}
1725 22de7804 Bill Marquette
		function _checkIP() {
1726 dceff62e Ermal
			global $debug;
1727 22de7804 Bill Marquette
1728 1e0b1727 Phil Davis
			if ($debug) {
1729 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
1730 1e0b1727 Phil Davis
			}
1731 22de7804 Bill Marquette
1732 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
1733 d20a3d08 Chris Buechler
				$ip_address = get_interface_ipv6($this->_if);
1734 1e0b1727 Phil Davis
				if (!is_ipaddrv6($ip_address)) {
1735 d7e6f573 Daniel Becker
					return 0;
1736 1e0b1727 Phil Davis
				}
1737 d7e6f573 Daniel Becker
			} else {
1738 d20a3d08 Chris Buechler
				$ip_address = get_interface_ip($this->_if);
1739 1e0b1727 Phil Davis
				if (!is_ipaddr($ip_address)) {
1740 d7e6f573 Daniel Becker
					return 0;
1741 1e0b1727 Phil Davis
				}
1742 d7e6f573 Daniel Becker
			}
1743
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
1744 1b665090 Ermal Lu?i
				$hosttocheck = "checkip.dyndns.org";
1745 83ae8103 Ermal
				$try = 0;
1746
				while ($try < 3) {
1747
					$checkip = gethostbyname($hosttocheck);
1748 1e0b1727 Phil Davis
					if (is_ipaddr($checkip)) {
1749 83ae8103 Ermal
						break;
1750 1e0b1727 Phil Davis
					}
1751 83ae8103 Ermal
					$try++;
1752
				}
1753
				if ($try >= 3) {
1754 9557ca30 Phil Davis
					log_error(sprintf(gettext('Dynamic DNS %1$s debug information (%2$s): Could not resolve %3$s to IP using interface IP %4$s.'), $this->_dnsService, $this->_FQDN, $hosttocheck, $ip_address));
1755 dd575ea4 Ermal
					return 0;
1756 83ae8103 Ermal
				}
1757 7ae7a972 Ermal Lu?i
				$ip_ch = curl_init("http://{$checkip}");
1758
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
1759
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
1760 e1eee3d2 Renato Botelho
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
1761 83ae8103 Ermal
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
1762 93b8df2a Ermal
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
1763 cd8f7eee Florian Asche
				if ($this->_useIPv6 == false) {
1764
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1765 7dc42e4a Florian Asche
				}
1766 7ae7a972 Ermal Lu?i
				$ip_result_page = curl_exec($ip_ch);
1767
				curl_close($ip_ch);
1768
				$ip_result_decoded = urldecode($ip_result_page);
1769 c3c3e03b Ermal
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
1770 7ae7a972 Ermal Lu?i
				$ip_address = trim($matches[1]);
1771 87b91672 Phil Davis
				if (is_ipaddr($ip_address)) {
1772 1e0b1727 Phil Davis
					if ($this->_dnsVerboseLog) {
1773 9557ca30 Phil Davis
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from %4$s'), $this->_dnsService, $this->_FQDN, $ip_address, $hosttocheck));
1774 1e0b1727 Phil Davis
					}
1775 87b91672 Phil Davis
				} else {
1776 9557ca30 Phil Davis
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): IP address could not be extracted from %3$s'), $this->_dnsService, $this->_FQDN, $hosttocheck));
1777 c749ef62 Ermal
					return 0;
1778
				}
1779 87b91672 Phil Davis
			} else {
1780 1e0b1727 Phil Davis
				if ($this->_dnsVerboseLog) {
1781 9557ca30 Phil Davis
					log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): %3$s extracted from local system.'), $this->_dnsService, $this->_FQDN, $ip_address));
1782 1e0b1727 Phil Davis
				}
1783 87b91672 Phil Davis
			}
1784 fffbfef0 Matt Corallo
			$this->_dnsIP = $ip_address;
1785
1786 22de7804 Bill Marquette
			return $ip_address;
1787
		}
1788 1fa2f630 Erik Kristensen
1789
	}
1790
1791 aa7c49b9 Ermal
?>