Project

General

Profile

Download (87.2 KB) Statistics
| Branch: | Tag: | Revision:
1 d237be68 Scott Ullrich
<?php
2 ac24dc24 Renato Botelho
/*
3
 * dyndns.class
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 ac24dc24 Renato Botelho
 * All rights reserved.
8
 *
9 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12 ac24dc24 Renato Botelho
 *
13 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
14 ac24dc24 Renato Botelho
 *
15 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20 ac24dc24 Renato Botelho
 */
21
22 1fa2f630 Erik Kristensen
	/*
23
	 * PHP.updateDNS (pfSense version)
24
	 *
25
	 * +====================================================+
26
	 *  Services Supported:
27 9b8dc821 Scott Ullrich
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
28 1fa2f630 Erik Kristensen
	 *    - No-IP (no-ip.com)
29
	 *    - EasyDNS (easydns.com)
30
	 *    - DHS (www.dhs.org)
31 9b8dc821 Scott Ullrich
	 *    - HN (hn.org) -- incomplete checking!
32 1fa2f630 Erik Kristensen
	 *    - DynS (dyns.org)
33
	 *    - ZoneEdit (zoneedit.com)
34 9b8dc821 Scott Ullrich
	 *    - FreeDNS (freedns.afraid.org)
35 ac16181a TechSmurf
	 *    - FreeDNS IPv6 (freedns.afraid.org)
36 9b8dc821 Scott Ullrich
	 *    - Loopia (loopia.se)
37
	 *    - StaticCling (staticcling.org)
38 0a1b0183 Ermal Luçi
	 *    - DNSexit (dnsexit.com)
39 2d78b166 Ermal Luçi
	 *    - OpenDNS (opendns.com)
40 61c30081 jim-p
	 *    - Namecheap (namecheap.com)
41 8ea77433 Chris Wells
	 *    - HE.net (dns.he.net)
42 da40615d Daniel Becker
	 *    - HE.net IPv6 (dns.he.net)
43 38a481ad jim-p
	 *    - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
44 fb403496 Gerald Raaf
	 *    - SelfHost (selfhost.de)
45 37f3e704 Matt Corallo
	 *    - Amazon Route 53 (aws.amazon.com)
46
	 *    - DNS-O-Matic (dnsomatic.com)
47
	 *    - Custom DDNS (any URL)
48 da40615d Daniel Becker
	 *    - Custom DDNS IPv6 (any URL)
49 e26e1f76 Andrew Senetar
	 *    - CloudFlare (www.cloudflare.com)
50 3a05e4c3 Austin Seipp
	 *    - CloudFlare IPv6 (www.cloudflare.com)
51 1e0b1727 Phil Davis
	 *    - Eurodns (eurodns.com)
52
	 *    - GratisDNS (gratisdns.dk)
53 a0b470ee Chris Buechler
	 *    - City Network (citynetwork.se)
54 e0a4147b surrural
	 *    - GleSYS (glesys.com)
55 916d683e surrural
	 *    - DNSimple (dnsimple.com)
56 6c92b378 Christopher Fazendin
	 *    - Google Domains (domains.google.com)
57 c5ecdc25 Jose Luis Duran
	 *    - DNS Made Easy (www.dnsmadeeasy.com)
58 1c2c08bd exii1988
	 *    - SPDYN (spdyn.de)
59
	 *    - SPDYN IPv6 (spdyn.de)
60 575b1dcf Christoph Filnkößl
	 *    - All-Inkl (all-inkl.com)
61 19b7263e Ionut
	 *    - DuiaDNS (www.duiadns.net)
62
	 *    - DuiaDNS IPv6 (www.duiadns.net)
63 74533d41 xygrec
	 *    - Hover (www.hover.com)
64 9a3ec9a5 frank
	 *    - DreamHost DNS (www.dreamhost.com)
65 745d3779 Wagner Sartori Junior
	 *    - ClouDNS (www.cloudns.net)
66 456ba14f Sam Neely
	 *    - GoDaddy (www.godaddy.com)
67 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
68
	 *  Requirements:
69 37f3e704 Matt Corallo
	 *    - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
70 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
71
	 *  Public Functions
72
	 *    - updatedns()
73
	 *
74
	 *  Private Functions
75
	 *    - _update()
76
	 *    - _checkStatus()
77
	 *    - _error()
78
	 *    - _detectChange()
79
	 *    - _debug()
80 22de7804 Bill Marquette
	 *    - _checkIP()
81 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
82 01c155f2 Phil Davis
	 *  DynDNS Dynamic  - Last Tested: 12 July 2005
83
	 *  DynDNS Static   - Last Tested: NEVER
84
	 *  DynDNS Custom   - Last Tested: NEVER
85
	 *  No-IP           - Last Tested: 20 July 2008
86
	 *  HN.org          - Last Tested: 12 July 2005
87
	 *  EasyDNS         - Last Tested: 20 July 2008
88
	 *  DHS             - Last Tested: 12 July 2005
89
	 *  ZoneEdit        - Last Tested: NEVER
90
	 *  Dyns            - Last Tested: NEVER
91
	 *  ODS             - Last Tested: 02 August 2005
92 ac16181a TechSmurf
	 *  FreeDNS         - Last Tested: 01 May 2016
93
	 *  FreeDNS IPv6    - Last Tested: 01 May 2016
94 01c155f2 Phil Davis
	 *  Loopia          - Last Tested: NEVER
95
	 *  StaticCling     - Last Tested: 27 April 2006
96
	 *  DNSexit         - Last Tested: 20 July 2008
97
	 *  OpenDNS         - Last Tested: 4 August 2008
98
	 *  Namecheap       - Last Tested: 31 August 2010
99
	 *  HE.net          - Last Tested: 7 July 2013
100
	 *  HE.net IPv6     - Last Tested: 7 July 2013
101
	 *  HE.net Tunnel   - Last Tested: 28 June 2011
102 8d8405ba Jason McCormick
	 *  SelfHost        - Last Tested: 26 December 2011
103 ac5ee07e Jason D. McCormick
	 *  Amazon Route 53 - Last Tested: 04 February 2017
104 1e0b1727 Phil Davis
	 *  DNS-O-Matic     - Last Tested: 9 September 2010
105 e10d25b4 CarlGill
	 *  CloudFlare      - Last Tested: 05 September 2016
106 3a05e4c3 Austin Seipp
	 *  CloudFlare IPv6 - Last Tested: 17 July 2016
107 1e0b1727 Phil Davis
	 *  Eurodns         - Last Tested: 27 June 2013
108
	 *  GratisDNS       - Last Tested: 15 August 2012
109
	 *  OVH DynHOST     - Last Tested: NEVER
110
	 *  City Network    - Last Tested: 13 November 2013
111
	 *  GleSYS          - Last Tested: 3 February 2015
112
	 *  DNSimple        - Last Tested: 09 February 2015
113 6c92b378 Christopher Fazendin
	 *  Google Domains  - Last Tested: 27 April 2015
114 c5ecdc25 Jose Luis Duran
	 *  DNS Made Easy   - Last Tested: 27 April 2015
115 1c2c08bd exii1988
	 *  SPDYN           - Last Tested: 02 July 2016
116
	 *  SPDYN IPv6      - Last Tested: 02 July 2016
117 575b1dcf Christoph Filnkößl
	 *  All-Inkl        - Last Tested: 12 November 2016
118 19b7263e Ionut
	 *  DuiaDNS         - Last Tested: 25 November 2016
119
	 *  DuiaDNS IPv6    - Last Tested: 25 November 2016
120 74533d41 xygrec
	 *  Hover           - Last Tested: 15 February 2017
121 9d26673d frank
	 *  DreamHost       - Last Tested: 30 April 2017
122
	 *  DreamHost IPv6  - Not Yet Tested
123 745d3779 Wagner Sartori Junior
	 *  ClouDNS         - Last Tested: 22 August 2017
124 456ba14f Sam Neely
	 *  GoDaddy         - Last Tested: 22 November 2017
125
	 *  GoDaddy IPv6    - Last Tested: 22 November 2017
126 1fa2f630 Erik Kristensen
	 * +====================================================+
127
	 *
128 e24b26e9 Scott Ullrich
	 * @author 	E.Kristensen
129 1fa2f630 Erik Kristensen
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
130 0da417be Erik Kristensen
	 * @version 	0.8
131 e24b26e9 Scott Ullrich
	 * @updated	13 October 05 at 21:02:42 GMT
132 1fa2f630 Erik Kristensen
	 *
133 d98a2e6a Jose Luis Duran
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luçi
134 37f3e704 Matt Corallo
	 * Custom DNS support by Matt Corallo
135 0a1b0183 Ermal Luçi
	 *
136 1fa2f630 Erik Kristensen
	 */
137
138
	class updatedns {
139 67ee1ec5 Ermal Luçi
		var $_cacheFile;
140 d7e6f573 Daniel Becker
		var $_cacheFile_v6;
141 67ee1ec5 Ermal Luçi
		var $_debugFile;
142 ce9a9572 Philip Soeberg
		var $_UserAgent = 'phpDynDNS/0.7';
143 1fa2f630 Erik Kristensen
		var $_errorVerbosity = 0;
144
		var $_dnsService;
145
		var $_dnsUser;
146
		var $_dnsPass;
147
		var $_dnsHost;
148 6635aa0f jim-p
		var $_dnsDomain;
149
		var $_FQDN;
150 1fa2f630 Erik Kristensen
		var $_dnsIP;
151
		var $_dnsWildcard;
152 e10d25b4 CarlGill
		var $_dnsProxied;
153 1fa2f630 Erik Kristensen
		var $_dnsMX;
154
		var $_dnsBackMX;
155 9b8dc821 Scott Ullrich
		var $_dnsServer;
156
		var $_dnsPort;
157
		var $_dnsUpdateURL;
158 cd132e86 Edson Brandi
		var $_dnsZoneID;
159
		var $_dnsTTL;
160 1fa2f630 Erik Kristensen
		var $status;
161
		var $_debugID;
162 67ee1ec5 Ermal Luçi
		var $_if;
163 37f3e704 Matt Corallo
		var $_dnsResultMatch;
164
		var $_dnsRequestIf;
165
		var $_dnsRequestIfIP;
166 87b91672 Phil Davis
		var $_dnsVerboseLog;
167 aa79f351 Sebastian Chrostek
		var $_curlIpresolveV4;
168
		var $_curlSslVerifypeer;
169 f5e293e6 Phil Davis
		var $_dnsMaxCacheAgeDays;
170 0333f968 Phil Davis
		var $_dnsDummyUpdateDone;
171
		var $_forceUpdateNeeded;
172 b4025ccd Daniel Becker
		var $_useIPv6;
173 9a3ec9a5 frank
		var $_existingRecords;
174 1e0b1727 Phil Davis
175
		/*
176 1fa2f630 Erik Kristensen
		 * Public Constructor Function (added 12 July 05) [beta]
177 1e0b1727 Phil Davis
		 *   - Gets the dice rolling for the update.
178 37f3e704 Matt Corallo
		 *   - $dnsResultMatch should only be used with $dnsService = 'custom'
179 1e0b1727 Phil Davis
		 *   -  $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
180 1bf52c67 Phil Davis
		 *   -  it is otherwise expected to be exactly identical to what is returned by the Provider.
181 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.
182
		 *   - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
183 1fa2f630 Erik Kristensen
		 */
184 6635aa0f jim-p
		function updatedns ($dnsService = '', $dnsHost = '', $dnsDomain = '', $dnsUser = '', $dnsPass = '',
185 e10d25b4 CarlGill
					$dnsWildcard = 'OFF', $dnsProxied = false, $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
186 1e0b1727 Phil Davis
					$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
187
					$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
188
					$dnsID = '', $dnsVerboseLog = false, $curlIpresolveV4 = false, $curlSslVerifypeer = true) {
189
190 2446fffa jim-p
			global $config, $g, $dyndns_split_domain_types;
191
			if (in_array($dnsService, $dyndns_split_domain_types)) {
192 6635aa0f jim-p
				$this->_FQDN = $dnsHost . "." . $dnsDomain;
193
			} else {
194
				$this->_FQDN = $dnsHost;
195
			}
196
197
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.cache";
198
			$this->_cacheFile_v6 = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}_v6.cache";
199
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($this->_FQDN) . "{$dnsID}.debug";
200 67ee1ec5 Ermal Luçi
201 aa79f351 Sebastian Chrostek
			$this->_curlIpresolveV4 = $curlIpresolveV4;
202
			$this->_curlSslVerifypeer = $curlSslVerifypeer;
203 87b91672 Phil Davis
			$this->_dnsVerboseLog = $dnsVerboseLog;
204 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
205 9557ca30 Phil Davis
				log_error(gettext("Dynamic DNS: updatedns() starting"));
206 1e0b1727 Phil Davis
			}
207 71070cc5 Ermal
208 37f3e704 Matt Corallo
			$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
209 71070cc5 Ermal
210 1fa2f630 Erik Kristensen
			if (!$dnsService) $this->_error(2);
211 ce6d1106 jim-p
			switch ($dnsService) {
212
			case 'freedns':
213 ac16181a TechSmurf
			case 'freedns-v6':
214 ce6d1106 jim-p
				if (!$dnsHost) $this->_error(5);
215
				break;
216 2446fffa jim-p
			case "namecheap":
217
				if (!$dnsPass) $this->_error(4);
218
				if (!$dnsHost) $this->_error(5);
219
				if (!$dnsDomain) $this->_error(5);
220
				break;
221
			case "cloudflare-v6":
222
			case "cloudflare":
223
			case "gratisdns":
224 74533d41 xygrec
			case "hover":
225 2446fffa jim-p
				if (!$dnsUser) $this->_error(3);
226 9b8dc821 Scott Ullrich
				if (!$dnsPass) $this->_error(4);
227
				if (!$dnsHost) $this->_error(5);
228 6635aa0f jim-p
				if (!$dnsDomain) $this->_error(5);
229 ce6d1106 jim-p
				break;
230 44c64da1 Matthew Fine
			case 'route53-v6':
231 37f3e704 Matt Corallo
			case 'route53':
232
				if (!$dnsZoneID) $this->_error(8);
233
				if (!$dnsTTL) $this->_error(9);
234
				break;
235 745d3779 Wagner Sartori Junior
			case 'cloudns':
236 456ba14f Sam Neely
			case "godaddy":
237
			case "godaddy-v6":
238 745d3779 Wagner Sartori Junior
				if (!$dnsUser) $this->_error(3);
239
				if (!$dnsPass) $this->_error(4);
240
				if (!$dnsHost) $this->_error(5);
241
				if (!$dnsDomain) $this->_error(5);
242
				if (!$dnsTTL) $this->_error(9);
243
				break;
244 37f3e704 Matt Corallo
			case 'custom':
245
				if (!$dnsUpdateURL) $this->_error(7);
246
				break;
247 ce6d1106 jim-p
			default:
248
				if (!$dnsUser) $this->_error(3);
249
				if (!$dnsPass) $this->_error(4);
250 99295d7b Scott Ullrich
				if (!$dnsHost) $this->_error(5);
251 9b8dc821 Scott Ullrich
			}
252 1e0b1727 Phil Davis
253 b4025ccd Daniel Becker
			switch ($dnsService) {
254 1e0b1727 Phil Davis
				case 'he-net-v6':
255
				case 'custom-v6':
256 1c2c08bd exii1988
				case 'spdyn-v6':
257 44c64da1 Matthew Fine
				case 'route53-v6':
258 19b7263e Ionut
				case 'duiadns-v6':
259 ac16181a TechSmurf
				case 'freedns-v6':
260 3a05e4c3 Austin Seipp
				case 'cloudflare-v6':
261 9a3ec9a5 frank
				case 'dreamhost-v6':
262 456ba14f Sam Neely
				case 'godaddy-v6':
263 1e0b1727 Phil Davis
					$this->_useIPv6 = true;
264
					break;
265
				default:
266
					$this->_useIPv6 = false;
267 b4025ccd Daniel Becker
			}
268 1fa2f630 Erik Kristensen
			$this->_dnsService = strtolower($dnsService);
269
			$this->_dnsUser = $dnsUser;
270 86584ded jim-p
			$this->_dnsPass = base64_decode($dnsPass);
271 1fa2f630 Erik Kristensen
			$this->_dnsHost = $dnsHost;
272 6635aa0f jim-p
			$this->_dnsDomain = $dnsDomain;
273 9b8dc821 Scott Ullrich
			$this->_dnsServer = $dnsServer;
274
			$this->_dnsPort = $dnsPort;
275
			$this->_dnsWildcard = $dnsWildcard;
276 e10d25b4 CarlGill
			$this->_dnsProxied = $dnsProxied;
277 9b8dc821 Scott Ullrich
			$this->_dnsMX = $dnsMX;
278 0c7bb880 Phil Davis
			$this->_dnsZoneID = $dnsZoneID;
279
			$this->_dnsTTL = $dnsTTL;
280 bf001dec smos
			$this->_if = get_failover_interface($dnsIf);
281 fffbfef0 Matt Corallo
			$this->_checkIP();
282 37f3e704 Matt Corallo
			$this->_dnsUpdateURL = $dnsUpdateURL;
283
			$this->_dnsResultMatch = $dnsResultMatch;
284 bf001dec smos
			$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
285 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
286 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));
287 1e0b1727 Phil Davis
			}
288 37f3e704 Matt Corallo
			$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
289 f5e293e6 Phil Davis
			$this->_dnsMaxCacheAgeDays = 25;
290 0333f968 Phil Davis
			$this->_dnsDummyUpdateDone = false;
291
			$this->_forceUpdateNeeded = $forceUpdate;
292 1e0b1727 Phil Davis
293 0c7bb880 Phil Davis
			// Ensure that we were able to lookup the IP
294 1e0b1727 Phil Davis
			if (!is_ipaddr($this->_dnsIP)) {
295 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));
296 fffbfef0 Matt Corallo
				unlock($dyndnslck);
297
				return;
298
			}
299 07a3b40b sullrich
300 1fa2f630 Erik Kristensen
			$this->_debugID = rand(1000000, 9999999);
301 1e0b1727 Phil Davis
302 d7e6f573 Daniel Becker
			if ($forceUpdate == false && $this->_detectChange() == false) {
303 1fa2f630 Erik Kristensen
				$this->_error(10);
304
			} else {
305 9d96a475 Ermal Lu?i
				switch ($this->_dnsService) {
306 1e0b1727 Phil Davis
					case 'glesys':
307
					case 'dnsomatic':
308
					case 'dyndns':
309
					case 'dyndns-static':
310
					case 'dyndns-custom':
311
					case 'dhs':
312
					case 'noip':
313
					case 'noip-free':
314
					case 'easydns':
315
					case 'hn':
316
					case 'zoneedit':
317
					case 'dyns':
318
					case 'ods':
319
					case 'freedns':
320 ac16181a TechSmurf
					case 'freedns-v6':
321 1e0b1727 Phil Davis
					case 'loopia':
322
					case 'staticcling':
323
					case 'dnsexit':
324
					case 'custom':
325
					case 'custom-v6':
326
					case 'opendns':
327
					case 'namecheap':
328
					case 'he-net':
329
					case 'he-net-v6':
330 19b7263e Ionut
					case 'duiadns':
331
					case 'duiadns-v6':
332 1e0b1727 Phil Davis
					case 'selfhost':
333
					case 'he-net-tunnelbroker':
334
					case 'route53':
335 44c64da1 Matthew Fine
					case 'route53-v6':
336 1e0b1727 Phil Davis
					case 'cloudflare':
337 3a05e4c3 Austin Seipp
					case 'cloudflare-v6':
338 1e0b1727 Phil Davis
					case 'eurodns':
339
					case 'gratisdns':
340
					case 'ovh-dynhost':
341
					case 'citynetwork':
342
					case 'dnsimple':
343 c5ecdc25 Jose Luis Duran
					case 'googledomains':
344
					case 'dnsmadeeasy':
345 1c2c08bd exii1988
					case 'spdyn':
346
					case 'spdyn-v6':
347 575b1dcf Christoph Filnkößl
					case 'all-inkl':
348 745d3779 Wagner Sartori Junior
					case 'cloudns':
349 74533d41 xygrec
					case 'hover':
350 456ba14f Sam Neely
					case 'godaddy':
351
					case 'godaddy-v6':
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 9a3ec9a5 frank
					case 'dreamhost':
363
					case 'dreamhost-v6':
364
						$this->_lookup_current();
365
						if (isset($this->status)) {
366
							return;
367
						}
368
						foreach ($this->_existingRecords as $record) {
369
							$this->_remove($record['existing_val']);
370
							$this->_update();
371
						}
372
						break;
373 1e0b1727 Phil Davis
					default:
374
						$this->_error(6);
375
						break;
376 1fa2f630 Erik Kristensen
				}
377 9d96a475 Ermal Lu?i
			}
378 71070cc5 Ermal
379
			unlock($dyndnslck);
380 1fa2f630 Erik Kristensen
		}
381 1e0b1727 Phil Davis
382 1fa2f630 Erik Kristensen
		/*
383
		 * Private Function (added 12 July 05) [beta]
384
		 *   Send Update To Selected Service.
385
		 */
386
		function _update() {
387 1e0b1727 Phil Davis
388
			if ($this->_dnsVerboseLog) {
389 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _update() starting.'), $this->_dnsService, $this->_FQDN));
390 1e0b1727 Phil Davis
			}
391 b37b4034 Phil Davis
392 f1d3adf1 Chris Buechler
			if (strstr($this->_dnsRequestIf, "_vip")) {
393 ac5c0cfe Chris Buechler
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
394 f1d3adf1 Chris Buechler
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
395
			} else {
396
				$realparentif = $this->_dnsRequestIf;
397
			}
398 1e0b1727 Phil Davis
399 0ec4b3b4 Chris Buechler
			$ch = curl_init();
400
401 becd6caa Chris Buechler
			if ($this->_useIPv6 == false) {
402 4e322e2c Phil Davis
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
403 becd6caa Chris Buechler
			}
404
405 15dcf132 PiBa-NL
			if ($this->_dnsService != 'ods') {
406 1fa2f630 Erik Kristensen
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
407
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
408 f1d3adf1 Chris Buechler
				curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
409 93b8df2a Ermal
				curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
410 1fa2f630 Erik Kristensen
			}
411
412
			switch ($this->_dnsService) {
413 197cf433 McB
				case 'glesys':
414
					$needsIP = TRUE;
415
					$server = 'https://api.glesys.com/domain/updaterecord/format/json';
416
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
417 6635aa0f jim-p
					$post_data['recordid'] = $this->_FQDN;
418 197cf433 McB
					$post_data['data'] = $this->_dnsIP;
419
					curl_setopt($ch, CURLOPT_URL, $server);
420
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
421
					break;
422 1fa2f630 Erik Kristensen
				case 'dyndns':
423
				case 'dyndns-static':
424 52e95286 Ermal
				case 'dyndns-custom':
425 1fa2f630 Erik Kristensen
					$needsIP = FALSE;
426 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
427
						$this->_dnsWildcard = "ON";
428
					}
429 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
430 9b8dc821 Scott Ullrich
					$server = "https://members.dyndns.org/nic/update";
431
					$port = "";
432 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
433 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
434 1e0b1727 Phil Davis
					}
435
					if ($this->_dnsPort) {
436 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
437 1e0b1727 Phil Davis
					}
438 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');
439 1fa2f630 Erik Kristensen
					break;
440
				case 'dhs':
441 34c9962b Chris Buechler
					// DHS is disabled in the GUI because the following doesn't work.
442 1fa2f630 Erik Kristensen
					$needsIP = TRUE;
443 a255e1f7 Scott Ullrich
					$post_data['hostscmd'] = 'edit';
444
					$post_data['hostscmdstage'] = '2';
445
					$post_data['type'] = '4';
446
					$post_data['updatetype'] = 'Online';
447
					$post_data['mx'] = $this->_dnsMX;
448
					$post_data['mx2'] = '';
449
					$post_data['txt'] = '';
450
					$post_data['offline_url'] = '';
451
					$post_data['cloak'] = 'Y';
452
					$post_data['cloak_title'] = '';
453
					$post_data['ip'] = $this->_dnsIP;
454
					$post_data['domain'] = 'dyn.dhs.org';
455
					$post_data['hostname'] = $this->_dnsHost;
456
					$post_data['submit'] = 'Update';
457 9b8dc821 Scott Ullrich
					$server = "https://members.dhs.org/nic/hosts";
458
					$port = "";
459 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
460 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
461 1e0b1727 Phil Davis
					}
462
					if ($this->_dnsPort) {
463
						$port = ":" . $this->_dnsPort;
464
					}
465 34c9962b Chris Buechler
					curl_setopt($ch, CURLOPT_URL, $server . $port);
466 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
467
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
468
					break;
469
				case 'noip':
470 0333f968 Phil Davis
				case 'noip-free':
471 1fa2f630 Erik Kristensen
					$needsIP = TRUE;
472 64746cf6 Chris Buechler
					$server = "https://dynupdate.no-ip.com/ducupdate.php";
473 9b8dc821 Scott Ullrich
					$port = "";
474 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
475 472da675 Phil Davis
						$server = $this->_dnsServer;
476 1e0b1727 Phil Davis
					}
477
					if ($this->_dnsPort) {
478 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
479 1e0b1727 Phil Davis
					}
480
					if (($this->_dnsService == "noip-free") &&
481 ae52d165 Renato Botelho
					    ($this->_forceUpdateNeeded == true) &&
482
					    ($this->_dnsDummyUpdateDone == false)) {
483 0333f968 Phil Davis
						// Update the IP to a dummy value to force No-IP free accounts to see a change.
484
						$iptoset = "192.168.1.1";
485
						$this->_dnsDummyUpdateDone = true;
486 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));
487 0333f968 Phil Davis
					} else {
488
						$iptoset = $this->_dnsIP;
489
					}
490 70a84c25 Tiago Barrionuevo
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&h[]=' . $this->_dnsHost.'&ip=' . $iptoset);
491 1fa2f630 Erik Kristensen
					break;
492
				case 'easydns':
493
					$needsIP = TRUE;
494
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
495 64746cf6 Chris Buechler
					$server = "https://members.easydns.com/dyn/dyndns.php";
496 9b8dc821 Scott Ullrich
					$port = "";
497 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
498 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
499 1e0b1727 Phil Davis
					}
500
					if ($this->_dnsPort) {
501 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
502 1e0b1727 Phil Davis
					}
503 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);
504 1fa2f630 Erik Kristensen
					break;
505
				case 'hn':
506
					$needsIP = TRUE;
507
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
508 9b8dc821 Scott Ullrich
					$server = "http://dup.hn.org/vanity/update";
509
					$port = "";
510 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
511 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
512 1e0b1727 Phil Davis
					}
513
					if ($this->_dnsPort) {
514 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
515 1e0b1727 Phil Davis
					}
516 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
517 1fa2f630 Erik Kristensen
					break;
518
				case 'zoneedit':
519
					$needsIP = FALSE;
520 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
521
522 9b8dc821 Scott Ullrich
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
523
					$port = "";
524 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
525 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
526 1e0b1727 Phil Davis
					}
527
					if ($this->_dnsPort) {
528 9b8dc821 Scott Ullrich
						$port = ":" . $this->_dnsPort;
529 1e0b1727 Phil Davis
					}
530 176d24e1 Phil Davis
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" . $this->_dnsHost . '&dnsto=' . $this->_dnsIP);
531 1fa2f630 Erik Kristensen
					break;
532
				case 'dyns':
533
					$needsIP = FALSE;
534 ea46d833 Chris Buechler
					$server = "http://www.dyns.net/postscript011.php";
535 9b8dc821 Scott Ullrich
					$port = "";
536 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
537 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
538 1e0b1727 Phil Davis
					}
539
					if ($this->_dnsPort) {
540
						$port = ":" . $this->_dnsPort;
541
					}
542 fdcaa527 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
543 1fa2f630 Erik Kristensen
					break;
544
				case 'ods':
545
					$needsIP = FALSE;
546 9b8dc821 Scott Ullrich
					$misc_errno = 0;
547
					$misc_error = "";
548
					$server = "ods.org";
549
					$port = "";
550 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
551 9b8dc821 Scott Ullrich
						$server = $this->_dnsServer;
552 1e0b1727 Phil Davis
					}
553
					if ($this->_dnsPort) {
554
						$port = ":" . $this->_dnsPort;
555
					}
556 9b8dc821 Scott Ullrich
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
557 1fa2f630 Erik Kristensen
					/* Check that we have connected */
558
					if (!$this->con['socket']) {
559
						print "error! could not connect.";
560
						break;
561
					}
562
					/* Here is the loop. Read the incoming data (from the socket connection) */
563
					while (!feof($this->con['socket'])) {
564
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
565
						$code = substr($this->con['buffer']['all'], 0, 3);
566
						sleep(1);
567 1e0b1727 Phil Davis
						switch ($code) {
568 1fa2f630 Erik Kristensen
							case 100:
569
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
570
								break;
571
							case 225:
572
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
573
								break;
574
							case 901:
575
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
576
								break;
577
							case 795:
578
								fputs($this->con['socket'], "QUIT\n");
579
								break;
580
						}
581
					}
582 425ba708 Ermal
					$this->_checkStatus(0, $code);
583 1fa2f630 Erik Kristensen
					break;
584 9b8dc821 Scott Ullrich
				case 'freedns':
585 ac16181a TechSmurf
				case 'freedns-v6':
586 9b8dc821 Scott Ullrich
					$needIP = FALSE;
587 64746cf6 Chris Buechler
					curl_setopt($ch, CURLOPT_URL, 'https://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
588 9b8dc821 Scott Ullrich
					break;
589 0a1b0183 Ermal Luçi
				case 'dnsexit':
590
					$needsIP = TRUE;
591 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);
592 0a1b0183 Ermal Luçi
					break;
593 9b8dc821 Scott Ullrich
				case 'loopia':
594
					$needsIP = TRUE;
595 6db16398 Martin Hagelin
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
596 9b8dc821 Scott Ullrich
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
597 6db16398 Martin Hagelin
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard);
598 9b8dc821 Scott Ullrich
					break;
599 2d78b166 Ermal Luçi
				case 'opendns':
600
					$needsIP = FALSE;
601
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
602
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
603 6bccf4ca smos
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
604 2d78b166 Ermal Luçi
					$port = "";
605 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
606 2d78b166 Ermal Luçi
						$server = $this->_dnsServer;
607 1e0b1727 Phil Davis
					}
608
					if ($this->_dnsPort) {
609 2d78b166 Ermal Luçi
						$port = ":" . $this->_dnsPort;
610 1e0b1727 Phil Davis
					}
611 2d78b166 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server .$port);
612
					break;
613
614 d74b5b8b sullrich
				case 'staticcling':
615
					$needsIP = FALSE;
616 64746cf6 Chris Buechler
					curl_setopt($ch, CURLOPT_URL, 'https://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
617 1e0b1727 Phil Davis
					break;
618 52e6fdfd Scott Dale
				case 'dnsomatic':
619 1e0b1727 Phil Davis
					/* Example syntax
620 52e6fdfd Scott Dale
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
621
					*/
622
					$needsIP = FALSE;
623 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
624
						$this->_dnsWildcard = "ON";
625
					}
626 99438649 swatspyder
					/*
627
					Reference: https://www.dnsomatic.com/wiki/api
628
						DNS-O-Matic usernames are 3-25 characters.
629
						DNS-O-Matic passwords are 6-20 characters.
630
						All ASCII letters and numbers accepted.
631
						Dots, dashes, and underscores allowed, but not at the beginning or end of the string.
632
					Required: "rawurlencode" http://www.php.net/manual/en/function.rawurlencode.php
633
						Encodes the given string according to RFC 3986.
634
					*/
635
					$server = "https://" . rawurlencode($this->_dnsUser) . ":" . rawurlencode($this->_dnsPass) . "@updates.dnsomatic.com/nic/update?hostname=";
636 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
637 52e6fdfd Scott Dale
						$server = $this->_dnsServer;
638 1e0b1727 Phil Davis
					}
639
					if ($this->_dnsPort) {
640 52e6fdfd Scott Dale
						$port = ":" . $this->_dnsPort;
641 1e0b1727 Phil Davis
					}
642 52e6fdfd Scott Dale
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
643
					break;
644 61c30081 jim-p
				case 'namecheap':
645
					/* Example:
646
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
647
					*/
648
					$needsIP = FALSE;
649 4178d033 jim-p
					$dnspass = trim($this->_dnsPass);
650 6635aa0f jim-p
					$server = "https://dynamicdns.park-your-domain.com/update?host={$this->_dnsHost}&domain={$this->_dnsDomain}&password={$dnspass}&ip={$this->_dnsIP}";
651 61c30081 jim-p
					curl_setopt($ch, CURLOPT_URL, $server);
652 8ea77433 Chris Wells
					break;
653 19b7263e Ionut
				case 'duiadns':
654
				case 'duiadns-v6':
655
					$needsIP = FALSE;
656
					$server = "https://ipv4.duiadns.net/dyndns.duia?";
657
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
658
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
659
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
660
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
661
					break;
662 8ea77433 Chris Wells
				case 'he-net':
663 d7e6f573 Daniel Becker
				case 'he-net-v6':
664 8ea77433 Chris Wells
					$needsIP = FALSE;
665
					$server = "https://dyn.dns.he.net/nic/update?";
666 086cf944 Phil Davis
					curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
667 393dac91 Chris Buechler
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
668 16fea0ce Cedric Ohle
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost . '&password=' . $this->_dnsPass . '&myip=' . $this->_dnsIP);
669 8ea77433 Chris Wells
					break;
670 38a481ad jim-p
				case 'he-net-tunnelbroker':
671
					$needsIP = FALSE;
672
					$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
673
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
674
					curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
675
					break;
676 fb403496 Gerald Raaf
				case 'selfhost':
677
					$needsIP = FALSE;
678 1e0b1727 Phil Davis
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") {
679
						$this->_dnsWildcard = "ON";
680
					}
681 fb403496 Gerald Raaf
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
682
					$server = "https://carol.selfhost.de/nic/update";
683
					$port = "";
684 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
685 fb403496 Gerald Raaf
						$server = $this->_dnsServer;
686 1e0b1727 Phil Davis
					}
687
					if ($this->_dnsPort) {
688 fb403496 Gerald Raaf
						$port = ":" . $this->_dnsPort;
689 1e0b1727 Phil Davis
					}
690 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');
691
					break;
692 16b16366 Jason McCormick
				case 'route53':		
693
					require_once("r53.class");
694
					$r53 = new Route53($this->_dnsUser, $this->_dnsPass);
695 b2cb7364 Jason D. McCormick
					$apiurl = $r53->getApiUrl($this->_dnsZoneID);
696 16b16366 Jason McCormick
					$xmlreq = $r53->getRequestBody($this->_dnsHost, $this->_dnsIP, $this->_dnsTTL);
697 56632443 Jason D. McCormick
					$httphead = $r53->getHttpPostHeaders($this->_dnsZoneID, "us-east-1", hash("sha256",$xmlreq));
698 cc5adcaa Jason McCormick
					curl_setopt($ch, CURLOPT_HTTPHEADER, $httphead);
699
					if($this->_dnsVerboseLog){
700 19e87bb3 Bryan Stenson
						log_error(sprintf("Sending request to: %s", $apiurl));
701 cc5adcaa Jason McCormick
						foreach($httphead as $hv){
702
							log_error(sprintf("Header: %s", $hv));
703 0c7bb880 Phil Davis
						}
704 16b16366 Jason McCormick
						log_error(sprintf("XMLPOST: %s", $xmlreq));
705 0c7bb880 Phil Davis
					}
706 cc5adcaa Jason McCormick
					curl_setopt($ch, CURLOPT_URL, $apiurl);
707
					curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlreq);
708 0c7bb880 Phil Davis
					break;
709 44c64da1 Matthew Fine
				case 'route53-v6':		
710
					require_once("r53.class");
711
					$r53 = new Route53($this->_dnsUser, $this->_dnsPass);
712
					$apiurl = $r53->getApiUrl($this->_dnsZoneID);
713
					$xmlreq = $r53->getRequestBodyV6($this->_dnsHost, $this->_dnsIP, $this->_dnsTTL);
714
					$httphead = $r53->getHttpPostHeaders($this->_dnsZoneID, "us-east-1", hash("sha256",$xmlreq));
715
					curl_setopt($ch, CURLOPT_HTTPHEADER, $httphead);
716
					if($this->_dnsVerboseLog){
717 19e87bb3 Bryan Stenson
						log_error(sprintf("Sending request to: %s", $apiurl));
718 44c64da1 Matthew Fine
						foreach($httphead as $hv){
719
							log_error(sprintf("Header: %s", $hv));
720
						}
721
						log_error(sprintf("XMLPOST: %s", $xmlreq));
722
					}
723
					curl_setopt($ch, CURLOPT_URL, $apiurl);
724
					curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlreq);
725
					break;
726 37f3e704 Matt Corallo
				case 'custom':
727 da40615d Daniel Becker
				case 'custom-v6':
728 37f3e704 Matt Corallo
					if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
729
					if ($this->_dnsUser != '') {
730 1e0b1727 Phil Davis
						if ($this->_curlIpresolveV4) {
731 086cf944 Phil Davis
							curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
732 1e0b1727 Phil Davis
						}
733
						if ($this->_curlSslVerifypeer) {
734 aa79f351 Sebastian Chrostek
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
735 1e0b1727 Phil Davis
						} else {
736 aa79f351 Sebastian Chrostek
							curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
737 1e0b1727 Phil Davis
						}
738
						curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
739 37f3e704 Matt Corallo
						curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
740
					}
741
					$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
742 1e0b1727 Phil Davis
					if ($this->_dnsVerboseLog) {
743 9557ca30 Phil Davis
						log_error(sprintf(gettext("Sending request to: %s"), $server));
744 1e0b1727 Phil Davis
					}
745 37f3e704 Matt Corallo
					curl_setopt($ch, CURLOPT_URL, $server);
746
					break;
747 3a05e4c3 Austin Seipp
				case 'cloudflare-v6':
748 e26e1f76 Andrew Senetar
				case 'cloudflare':
749 6534026b jim-p
					$this->_FQDN = ltrim($this->_FQDN, '@.');
750 3a05e4c3 Austin Seipp
					$isv6 = ($this->_dnsService === 'cloudflare-v6');
751
					$recordType = $isv6 ? "AAAA" : "A";
752 e26e1f76 Andrew Senetar
					$needsIP = TRUE;
753 22d95a68 doktornotor
					$dnsServer ='api.cloudflare.com';
754 4e322e2c Phil Davis
					$dnsHost = str_replace(' ', '', $this->_dnsHost);
755 22d95a68 doktornotor
756
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
757
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
758
						'X-Auth-Email: '.$this->_dnsUser.'',
759
						'X-Auth-Key: '.$this->_dnsPass.'',
760
						'Content-Type: application/json'
761
					));
762
763
					// Get zone ID
764 2446fffa jim-p
					$getZoneId = "https://{$dnsServer}/client/v4/zones/?name={$this->_dnsDomain}";
765 b37b4034 Phil Davis
					curl_setopt($ch, CURLOPT_URL, $getZoneId);
766 22d95a68 doktornotor
					$output = json_decode(curl_exec($ch));
767
					$zone = $output->result[0]->id;
768 4e322e2c Phil Davis
					if ($zone) { // If zone ID was found get host ID
769 2446fffa jim-p
						$getHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records?name={$this->_FQDN}&type={$recordType}";
770 b37b4034 Phil Davis
						curl_setopt($ch, CURLOPT_URL, $getHostId);
771 22d95a68 doktornotor
						$output = json_decode(curl_exec($ch));
772
						$host = $output->result[0]->id;
773 4e322e2c Phil Davis
						if ($host) { // If host ID was found update host
774 22d95a68 doktornotor
							$hostData = array(
775
								"content" => "{$this->_dnsIP}",
776 3a05e4c3 Austin Seipp
								"type" => "{$recordType}",
777 e10d25b4 CarlGill
								"proxied" => $this->_dnsProxied,
778 e93a7c71 calvinbui
								"name" => "{$this->_dnsHost}"
779 22d95a68 doktornotor
							);
780
							$data_json = json_encode($hostData);
781
							$updateHostId = "https://{$dnsServer}/client/v4/zones/{$zone}/dns_records/{$host}";
782 b37b4034 Phil Davis
							curl_setopt($ch, CURLOPT_URL, $updateHostId);
783 22d95a68 doktornotor
							curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
784 4e322e2c Phil Davis
							curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
785 22d95a68 doktornotor
						}
786
					}
787 e26e1f76 Andrew Senetar
					break;
788 1e0b1727 Phil Davis
				case 'eurodns':
789 ec66caa6 John Byron
					$needsIP = TRUE;
790
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
791 874599b9 johnbyronent
					$server = "https://update.eurodyndns.org/update/";
792 ec66caa6 John Byron
					$port = "";
793 1e0b1727 Phil Davis
					if ($this->_dnsPort) {
794 ec66caa6 John Byron
						$port = ":" . $this->_dnsPort;
795 1e0b1727 Phil Davis
					}
796 ec66caa6 John Byron
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
797 5458bc59 Scavy
					break;
798
				case 'gratisdns':
799 3e31a7f8 mortencombat
					$needsIP = TRUE;
800 5458bc59 Scavy
					$server = "https://ssl.gratisdns.dk/ddns.phtml";
801 2446fffa jim-p
					curl_setopt($ch, CURLOPT_URL, $server . '?u=' . $this->_dnsUser . '&p=' . $this->_dnsPass . '&h=' . $this->_dnsHost . '&d=' . $this->_dnsDomain . '&i=' . $this->_dnsIP);
802 5458bc59 Scavy
					break;
803 a4a56eb0 Stéphane
				case 'ovh-dynhost':
804
					$needsIP = FALSE;
805
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
806
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
807
					$server = "https://www.ovh.com/nic/update";
808
					$port = "";
809 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
810 a4a56eb0 Stéphane
						$server = $this->_dnsServer;
811 1e0b1727 Phil Davis
					}
812
					if ($this->_dnsPort) {
813 a4a56eb0 Stéphane
						$port = ":" . $this->_dnsPort;
814 1e0b1727 Phil Davis
					}
815 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');
816
					break;
817 2206f1b9 Mathias Andersson
				case 'citynetwork':
818
					$needsIP = TRUE;
819
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
820
					$server = 'https://dyndns.citynetwork.se/nic/update';
821
					$port = "";
822 1e0b1727 Phil Davis
					if ($this->_dnsServer) {
823 2206f1b9 Mathias Andersson
						$server = $this->_dnsServer;
824 1e0b1727 Phil Davis
					}
825
					if ($this->_dnsPort) {
826 2206f1b9 Mathias Andersson
						$port = ":" . $this->_dnsPort;
827 1e0b1727 Phil Davis
					}
828 2206f1b9 Mathias Andersson
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
829
					break;
830 916d683e surrural
				case 'dnsimple':
831
					/* Uses DNSimple's REST API
832
					   Requires username and Account API token passed in header
833
					   Piggybacks on Route 53's ZoneID field for DNSimple record ID
834
					   Data sent as JSON */
835
					$needsIP = TRUE;
836
					$server = 'https://api.dnsimple.com/v1/domains/';
837
					$token = $this->_dnsUser . ':' . $this->_dnsPass;
838
					$jsondata = '{"record":{"content":"' . $this->_dnsIP . '","ttl":"' . $this->_dnsTTL . '"}}';
839
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
840 086cf944 Phil Davis
					curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-DNSimple-Token: ' . $token));
841 916d683e surrural
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '/records/' . $this->_dnsZoneID);
842
					curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
843
					break;
844 456ba14f Sam Neely
				case 'godaddy':
845
				case 'godaddy-v6':
846
					/* Uses GoDaddy's REST API
847
					   Requires username and Account API sso-key passed in header
848
					   Data sent as JSON */
849
					$needsIP = TRUE;
850
					$server = 'https://api.godaddy.com/v1/domains/';
851
					$recordType = $this->_useIPv6 ? "AAAA" : "A";
852
					$url = $server  . $this->_dnsDomain . '/records/' . $recordType . '/' . $this->_dnsHost;
853
					$jsondata = '[{"data":"' . $this->_dnsIP . '","ttl":' . $this->_dnsTTL . '}]';
854
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
855
					curl_setopt($ch, CURLOPT_HTTPHEADER, array(
856
						'Accept: application/json',
857
						'Content-Type: application/json',
858
						'Authorization: sso-key ' . $this->_dnsUser . ':' . $this->_dnsPass
859
					));
860
					curl_setopt($ch, CURLOPT_URL, $url);
861
					curl_setopt($ch, CURLOPT_POSTFIELDS, $jsondata);
862
					break;
863 c5ecdc25 Jose Luis Duran
				case 'googledomains':
864 6c92b378 Christopher Fazendin
					$needsIP = FALSE;
865
					$post_data['username:password'] = $this->_dnsUser . ':' . $this->_dnsPass;
866
					$post_data['hostname'] = $this->_dnsHost;
867
					$post_data['myip'] = $this->_dnsIP;
868
					$post_data['offline'] = 'no';
869 404ff523 Christopher Fazendin
					$server = "https://domains.google.com/nic/update";
870 6c92b378 Christopher Fazendin
					$port = "";
871
					curl_setopt($ch, CURLOPT_URL, 'https://domains.google.com/nic/update');
872
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
873
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
874
					break;
875 c5ecdc25 Jose Luis Duran
				case 'dnsmadeeasy':
876
					$needsIP = TRUE;
877
					$server = "https://cp.dnsmadeeasy.com/servlet/updateip";
878
					curl_setopt($ch, CURLOPT_URL, $server . '?username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&id=' . $this->_dnsHost . '&ip=' . $this->_dnsIP);
879
					break;
880 1c2c08bd exii1988
				case 'spdyn':
881
				case 'spdyn-v6':
882 f3ee8545 Rene Schuster
					$needsIP = FALSE;
883
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
884 1c2c08bd exii1988
					$server = "https://update.spdyn.de/nic/update";
885 f3ee8545 Rene Schuster
					$port = "";
886 4e322e2c Phil Davis
					if ($this->_dnsServer) {
887 f3ee8545 Rene Schuster
						$server = $this->_dnsServer;
888 4e322e2c Phil Davis
					}
889
					if ($this->_dnsPort) {
890 f3ee8545 Rene Schuster
						$port = ":" . $this->_dnsPort;
891 4e322e2c Phil Davis
					}
892 f3ee8545 Rene Schuster
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP);
893
					break;
894 575b1dcf Christoph Filnkößl
				case 'all-inkl':
895
					$needsIP = FALSE;
896
					$server = 'https://dyndns.kasserver.com/';
897
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
898
					curl_setopt($ch, CURLOPT_URL, $server . 'myip=' . $this->_dnsIP);
899
					break;
900 74533d41 xygrec
				case 'hover':
901
					$needsIP = FALSE;
902
					$port = "";
903
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
904 61c813f9 xygrec
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
905 74533d41 xygrec
906
					//step 1: login to API
907
					$post_data['username'] = $this->_dnsUser;
908
					$post_data['password'] = $this->_dnsPass;
909
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
910
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/login");
911
					curl_setopt($ch, CURLOPT_HEADER, 1); //return the full headers to extract the cookies
912
					$output = curl_exec($ch);
913
914
					//extract the cookies
915
					preg_match_all("/^Set-cookie: (.*?);/ism", $output, $cookies);
916
					if( count($cookies[1]) > 0 ){
917
						$cookie_data = implode("; ",$cookies[1]);
918
					}
919
920
					//step 2: find the id of the A record
921
					$post_data = null;
922
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
923
					curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
924
					curl_setopt($ch, CURLOPT_HEADER, 0);
925
					curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns");
926
					curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
927
928
					$output = curl_exec($ch);
929
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{\"id\":\"([^\"]*?)\",\"name\":\"{$this->_dnsHost}\".*?\$/", $output, $hostID);
930
					$hostID = $hostID[1];
931
					preg_match("/^{\"succeeded\":true.*?domain_name\":\"{$this->_dnsDomain}.*?entries.*?{[^\}]*?\"name\":\"{$this->_dnsHost}\".*?content\":\"([^\"]*?)\".*?\$/", $output, $hostIP);
932
					$hostIP = $hostIP[1];
933
934
					//step 3: update the IP
935
					if ($hostID) {
936
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
937 61c813f9 xygrec
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
938 74533d41 xygrec
						curl_setopt($ch, CURLOPT_COOKIE, $cookie_data);
939
						$post_data['content'] = $this->_dnsIP;
940
						curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
941
						curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
942
						curl_setopt($ch, CURLOPT_URL, "https://www.hover.com/api/dns/{$hostID}");
943
						log_error("HostID:{$hostID}, OldIP:{$hostIP}");
944
					}
945
					break;
946 9a3ec9a5 frank
				case 'dreamhost':
947
				case 'dreamhost-v6':
948
					$needsIP = TRUE;
949
					$isv6 = ($this->_dnsService === 'dreamhost-v6');
950
					$server = 'https://api.dreamhost.com/';
951 a71deb5a frank
					$post_data['key'] = $this->_dnsPass;
952 9a3ec9a5 frank
					$post_data['unique_id'] = uniqid($this->_dnsHost);
953
					$post_data['cmd'] = 'dns-add_record';
954
					$post_data['format'] = 'json';
955
					$post_data['value'] = $this->_dnsIP;
956
					$post_data['record'] = $this->_dnsHost;
957
					$post_data['type'] = $isv6 ? 'AAAA' : 'A';
958 a71deb5a frank
					$post_data['comment'] = "Updated by pfSense:$this->_dnsUser on ".date('c');
959 9a3ec9a5 frank
					$port = "";
960
					if ($this->_dnsServer) {
961
						$server = $this->_dnsServer;
962
					}
963
					if ($this->_dnsPort) {
964
						$port = ":" . $this->_dnsPort;
965
					}
966
					curl_setopt($ch, CURLOPT_URL, $server . $port);
967
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
968
					break;
969 745d3779 Wagner Sartori Junior
				case 'cloudns':
970
					/* Uses ClouDNS REST API
971
					   Requires auth-id or sub-auth-id or sub-auth-user */
972
					// Step 1: Find the Record ID
973
					$url = 'https://api.cloudns.net/dns/records.json';
974
					$post_data['auth-id'] = $this->_dnsUser;
975
					$post_data['auth-password'] = $this->_dnsPass;
976
					$post_data['domain-name'] = $this->_dnsDomain;
977
					$post_data['host'] = $this->_dnsHost;
978
					$post_data['type'] = 'a';
979
					curl_setopt($ch, CURLOPT_URL, $url);
980
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
981
					$output = json_decode(curl_exec($ch));
982
					$recordID = key(get_object_vars($output));
983
984
					// Step 2: Set the record
985
					$needsIP = TRUE;
986
					$url = 'https://api.cloudns.net/dns/mod-record.json';
987
					$post_data = array();
988
					$post_data['auth-id'] = $this->_dnsUser;
989
					$post_data['auth-password'] = $this->_dnsPass;
990
					$post_data['domain-name'] = $this->_dnsDomain;
991
					$post_data['record-id'] = $recordID;
992
					$post_data['host'] = $this->_dnsHost;
993
					$post_data['record'] = $this->_dnsIP;
994
					$post_data['ttl'] = $this->_dnsTTL;
995
					curl_setopt($ch, CURLOPT_URL, $url);
996
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
997
					break;
998
999 1fa2f630 Erik Kristensen
				default:
1000
					break;
1001
			}
1002 cc5adcaa Jason McCormick
			if ($this->_dnsService != 'ods') {
1003 15dcf132 PiBa-NL
				curl_setopt($ch, CURLOPT_HEADER, 1);
1004 0e0f580d Christoph Filnkößl
				$response = curl_exec($ch);
1005 0f2fbcd7 Jason McCormick
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1006 0e0f580d Christoph Filnkößl
				$header = substr($response, 0, $header_size);
1007
				$data = substr($response, $header_size);
1008
				$this->_checkStatus($ch, $data, $header);
1009 425ba708 Ermal
				@curl_close($ch);
1010
			}
1011 1fa2f630 Erik Kristensen
		}
1012 9a3ec9a5 frank
		
1013
		/**
1014
		 * Private Function (added 23 Feb 17)
1015
		 *   Send Removal To Selected Service.
1016
		 *   
1017
		 *   Some services do not perform an inplace upgrade.  If they do not then the solution
1018
		 *   is to remove the existing record and add a new record.
1019
		 *   
1020
		 * @param unknown $existing_ip If required, an existing IP address for the record.
1021
		 */
1022
		function _remove($existing_ip = NULL) {
1023 f2e702b1 frank
			$remove_allowed = false;
1024 9a3ec9a5 frank
			if ($this->_dnsVerboseLog) {
1025
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _remove() starting.'), $this->_dnsService, $this->_FQDN));
1026
			}
1027
			
1028
			if (strstr($this->_dnsRequestIf, "_vip")) {
1029
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
1030
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
1031
			} else {
1032
				$realparentif = $this->_dnsRequestIf;
1033
			}
1034
			
1035
			$ch = curl_init();
1036
			
1037
			if ($this->_useIPv6 == false) {
1038
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1039
			}
1040
			
1041 f2e702b1 frank
			curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1042
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
1043
			curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
1044
			curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
1045 9a3ec9a5 frank
			
1046
			switch ($this->_dnsService) {
1047 e350558a frank
			case 'dreamhost':
1048
			case 'dreamhost-v6':
1049
				$server = 'https://api.dreamhost.com/';
1050
				$post_data['key'] = $this->_dnsPass;
1051
				$post_data['unique_id'] = uniqid($this->_dnsHost);
1052
				$post_data['cmd'] = 'dns-remove_record';
1053
				$post_data['format'] = 'json';
1054
				$post_data['value'] = $existing_ip;
1055
				$post_data['record'] = $this->_dnsHost;
1056
				$isv6 = ($this->_dnsService === 'dreamhost-v6');
1057
				$post_data['type'] = $isv6 ? 'AAAA' : 'A';
1058
				$port = "";
1059
				if ($this->_dnsServer) {
1060
					$server = $this->_dnsServer;
1061 9a3ec9a5 frank
				}
1062 e350558a frank
				if ($this->_dnsPort) {
1063
					$port = ":" . $this->_dnsPort;
1064 9a3ec9a5 frank
				}
1065 e350558a frank
				curl_setopt($ch, CURLOPT_URL, $server . $port);
1066
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1067 f2e702b1 frank
				$remove_allowed = true;
1068 e350558a frank
				break;
1069
			default:
1070
				break;
1071
			}
1072 f2e702b1 frank
			if ($remove_allowed) {
1073 e350558a frank
				curl_setopt($ch, CURLOPT_HEADER, 1);
1074
				$response = curl_exec($ch);
1075
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1076
				$header = substr($response, 0, $header_size);
1077
				$data = substr($response, $header_size);
1078
				$this->_checkStatus($ch, $data, $header);
1079
				@curl_close($ch);
1080 9a3ec9a5 frank
			}
1081 e350558a frank
		}
1082 9a3ec9a5 frank
		
1083
		/**
1084
		 * Private Function (added 23 Feb 17)
1085 f2e702b1 frank
		 * Retrieves current DNS records from an external API source.
1086 9a3ec9a5 frank
		 * 
1087
		 * Some services cannot perform new operations without the caller 
1088
		 * providing existing record information. 
1089
		 */
1090
		function _lookup_current() {
1091 f2e702b1 frank
			$lookup_allowed = false;
1092 9a3ec9a5 frank
			if ($this->_dnsVerboseLog) {
1093
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _listCurrent() starting.'), $this->_dnsService, $this->_FQDN));
1094
			}
1095
				
1096
			if (strstr($this->_dnsRequestIf, "_vip")) {
1097
				$parentif = get_configured_vip_interface($this->_dnsRequestIf);
1098
				$realparentif = convert_friendly_interface_to_real_interface_name($parentif);
1099
			} else {
1100
				$realparentif = $this->_dnsRequestIf;
1101
			}
1102
				
1103
			$ch = curl_init();
1104
				
1105
			if ($this->_useIPv6 == false) {
1106
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1107
			}
1108
				
1109 f2e702b1 frank
			curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
1110
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
1111
			curl_setopt($ch, CURLOPT_INTERFACE, 'if!' . $realparentif);
1112
			curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
1113 9a3ec9a5 frank
				
1114
			switch ($this->_dnsService) {
1115 e350558a frank
			case 'dreamhost':
1116
			case 'dreamhost-v6':
1117
				$server = 'https://api.dreamhost.com/';
1118
				$post_data['key'] = $this->_dnsPass;
1119
				$post_data['unique_id'] = uniqid($this->_dnsHost);
1120
				$post_data['cmd'] = 'dns-list_records';
1121
				$post_data['format'] = 'json';
1122
				$port = "";
1123
				if ($this->_dnsServer) {
1124
					$server = $this->_dnsServer;
1125
				}
1126
				if ($this->_dnsPort) {
1127
					$port = ":" . $this->_dnsPort;
1128
				}
1129
				curl_setopt($ch, CURLOPT_URL, $server . $port);
1130
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
1131 f2e702b1 frank
				$lookup_allowed = true;
1132 e350558a frank
				break;
1133
			default:
1134
				break;
1135 9a3ec9a5 frank
			}
1136 f2e702b1 frank
			if ($lookup_allowed) {
1137 9a3ec9a5 frank
				curl_setopt($ch, CURLOPT_HEADER, 1);
1138
				$response = curl_exec($ch);
1139
				$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
1140
				$header = substr($response, 0, $header_size);
1141
				$data = substr($response, $header_size);
1142
				$this->_checkLookupStatus($ch, $data, $header);
1143
				@curl_close($ch);
1144
			}
1145
		}
1146
1147
		/*
1148 f2e702b1 frank
		 * Private Function (added 23 Feb 17) 
1149
		 *   Retrieve Lookup Status from the provided data and/or header
1150 9a3ec9a5 frank
		 */
1151
		function _checkLookupStatus($ch, $data, $header) {
1152
			if ($this->_dnsVerboseLog) {
1153
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() starting.'), $this->_dnsService, $this->_FQDN));
1154
			}
1155
			$success_str = "(" . gettext("Success") . ") ";
1156
			$error_str = "(" . gettext("Error") . ") ";
1157
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
1158
1159
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
1160
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
1161
				log_error($status);
1162
				$this->status = $status;
1163
				return;
1164
			}
1165
			switch ($this->_dnsService) {
1166 e350558a frank
			case 'dreamhost':
1167
			case 'dreamhost-v6':
1168
				$result = json_decode($data,true);
1169
				if($result["result"] != "success") {
1170
					log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1171
					$this->_debug($data);
1172
					return;
1173
				} else {
1174
					foreach($result["data"] as $key => $row) {
1175
						if($row["record"] == $this->_dnsHost && 
1176
								(($row["type"] == "A" && !$this->_useIPv6)
1177
										|| ($row["type"] == "AAAA" && $this->_useIPv6)
1178
								)) {
1179
							if($row["editable"] == 0) {
1180
								log_error($status_intro . "host " . $this->_dnsHost . " is not editable.");
1181
								continue;
1182 9a3ec9a5 frank
							}
1183 e350558a frank
							$this->_existingRecords[]=array("record"=>$row["type"], "type"=>$row["type"], "existing_val"=>$row["value"]);
1184 9a3ec9a5 frank
						}
1185
					}
1186 e350558a frank
				}
1187
				if (!is_array($this->_existingRecords)){
1188
					if ($this->_dnsVerboseLog) {
1189
						log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkLookupStatus() ending.  No matching records found.'), $this->_dnsService, $this->_FQDN));
1190 9a3ec9a5 frank
					}
1191 e350558a frank
				}
1192
				break;
1193
			default:
1194
				break;
1195 9a3ec9a5 frank
			}
1196
		}
1197 1fa2f630 Erik Kristensen
1198
		/*
1199
		 * Private Function (added 12 July 2005) [beta]
1200
		 *   Retrieve Update Status
1201
		 */
1202 15dcf132 PiBa-NL
		function _checkStatus($ch, $data, $header) {
1203 87b91672 Phil Davis
			if ($this->_dnsVerboseLog) {
1204 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkStatus() starting.'), $this->_dnsService, $this->_FQDN));
1205 87b91672 Phil Davis
			}
1206 4a6bb2ff Scott Ullrich
			$successful_update = false;
1207 9557ca30 Phil Davis
			$success_str = "(" . gettext("Success") . ") ";
1208
			$error_str = "(" . gettext("Error") . ") ";
1209
			$status_intro = "phpDynDNS ({$this->_dnsHost}): ";
1210
1211 cc5adcaa Jason McCormick
			if ($this->_dnsService != 'ods' && @curl_error($ch)) {
1212 9557ca30 Phil Davis
				$status = gettext("Curl error occurred:") . " " . curl_error($ch);
1213 425ba708 Ermal
				log_error($status);
1214
				$this->status = $status;
1215
				return;
1216
			}
1217 1fa2f630 Erik Kristensen
			switch ($this->_dnsService) {
1218 197cf433 McB
				case 'glesys':
1219 9557ca30 Phil Davis
					$status_intro = "GleSYS ({$this->_dnsHost}): ";
1220 197cf433 McB
					if (preg_match('/Record updated/i', $data)) {
1221 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1222 197cf433 McB
						$successful_update = true;
1223
					} else {
1224 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1225
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1226 197cf433 McB
						$this->_debug($data);
1227
					}
1228
					break;
1229 52e6fdfd Scott Dale
				case 'dnsomatic':
1230 9557ca30 Phil Davis
					$status_intro = "DNS-O-Matic ({$this->_dnsHost}): ";
1231 52e6fdfd Scott Dale
					if (preg_match('/badauth/i', $data)) {
1232 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.");
1233 52e6fdfd Scott Dale
					} else if (preg_match('/notfqdn /i', $data)) {
1234 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.");
1235 52e6fdfd Scott Dale
					} else if (preg_match('/nohost/i', $data)) {
1236 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.");
1237 52e6fdfd Scott Dale
					} else if (preg_match('/numhost/i', $data)) {
1238 530e4707 NOYB
						$status = $status_intro . gettext("Up to 20 hosts my be updated. numhost is returned if attempting to update more than 20 or update a round-robin.");
1239 52e6fdfd Scott Dale
					} else if (preg_match('/abuse/i', $data)) {
1240 9557ca30 Phil Davis
						$status = $status_intro . gettext("The hostname is blocked for update abuse.");
1241 52e6fdfd Scott Dale
					} else if (preg_match('/good/i', $data)) {
1242 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1243 52e6fdfd Scott Dale
						$successful_update = true;
1244
					} else if (preg_match('/dnserr/i', $data)) {
1245 9557ca30 Phil Davis
						$status = $status_intro . gettext("DNS error encountered. Stop updating for 30 minutes.");
1246 52e6fdfd Scott Dale
					} else {
1247 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1248
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1249 52e6fdfd Scott Dale
						$this->_debug($data);
1250
					}
1251
					break;
1252 2206f1b9 Mathias Andersson
				case 'citynetwork':
1253
					if (preg_match('/notfqdn/i', $data)) {
1254 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1255 2206f1b9 Mathias Andersson
					} else if (preg_match('/nohost/i', $data)) {
1256 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No such host");
1257 2206f1b9 Mathias Andersson
					} else if (preg_match('/nochg/i', $data)) {
1258 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1259 2206f1b9 Mathias Andersson
						$successful_update = true;
1260
					} else if (preg_match('/good/i', $data)) {
1261 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1262 2206f1b9 Mathias Andersson
						$successful_update = true;
1263
					} else if (preg_match('/badauth/i', $data)) {
1264 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1265 2206f1b9 Mathias Andersson
					} else {
1266 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1267
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1268 2206f1b9 Mathias Andersson
						$this->_debug($data);
1269
					}
1270
					break;
1271 a4a56eb0 Stéphane
				case 'ovh-dynhost':
1272 1fa2f630 Erik Kristensen
				case 'dyndns':
1273
					if (preg_match('/notfqdn/i', $data)) {
1274 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1275 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
1276 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1277 0ede1bf7 Scott Ullrich
						$successful_update = true;
1278 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
1279 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1280 4a6bb2ff Scott Ullrich
						$successful_update = true;
1281 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
1282 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1283 1fa2f630 Erik Kristensen
					} else {
1284 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1285
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1286 1fa2f630 Erik Kristensen
						$this->_debug($data);
1287
					}
1288
					break;
1289
				case 'dyndns-static':
1290
					if (preg_match('/notfqdn/i', $data)) {
1291 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1292 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
1293 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1294 9b8dc821 Scott Ullrich
						$successful_update = true;
1295 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
1296 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1297 4a6bb2ff Scott Ullrich
						$successful_update = true;
1298 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
1299 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1300 1fa2f630 Erik Kristensen
					} else {
1301 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1302
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1303 1fa2f630 Erik Kristensen
						$this->_debug($data);
1304
					}
1305
					break;
1306
				case 'dyndns-custom':
1307
					if (preg_match('/notfqdn/i', $data)) {
1308 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1309 1fa2f630 Erik Kristensen
					} else if (preg_match('/nochg/i', $data)) {
1310 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1311 9b8dc821 Scott Ullrich
						$successful_update = true;
1312 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
1313 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1314 4a6bb2ff Scott Ullrich
						$successful_update = true;
1315 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
1316 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1317 1fa2f630 Erik Kristensen
					} else {
1318 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1319
						log_error($status_intro . gettext("PAYLOAD:") . " {$data}");
1320 1fa2f630 Erik Kristensen
						$this->_debug($data);
1321
					}
1322
					break;
1323
				case 'dhs':
1324
					break;
1325
				case 'noip':
1326 0333f968 Phil Davis
				case 'noip-free':
1327 086cf944 Phil Davis
					list($ip, $code) = explode(":", $data);
1328 1fa2f630 Erik Kristensen
					switch ($code) {
1329
						case 0:
1330 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("IP address is current, no update performed.");
1331 4a6bb2ff Scott Ullrich
							$successful_update = true;
1332 1fa2f630 Erik Kristensen
							break;
1333
						case 1:
1334 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS hostname update successful.");
1335 4a6bb2ff Scott Ullrich
							$successful_update = true;
1336 1fa2f630 Erik Kristensen
							break;
1337
						case 2:
1338 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Hostname supplied does not exist.");
1339 1fa2f630 Erik Kristensen
							break;
1340
						case 3:
1341 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid Username.");
1342 1fa2f630 Erik Kristensen
							break;
1343
						case 4:
1344 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid Password.");
1345 1fa2f630 Erik Kristensen
							break;
1346
						case 5:
1347 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Too many updates sent.");
1348 1fa2f630 Erik Kristensen
							break;
1349
						case 6:
1350 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account disabled due to violation of No-IP terms of service.");
1351 1fa2f630 Erik Kristensen
							break;
1352
						case 7:
1353 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.");
1354 1fa2f630 Erik Kristensen
							break;
1355
						case 8:
1356 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Disabled / Locked Hostname.");
1357 1fa2f630 Erik Kristensen
							break;
1358
						case 9:
1359 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Host updated is configured as a web redirect and no update was performed.");
1360 1fa2f630 Erik Kristensen
							break;
1361
						case 10:
1362 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Group supplied does not exist.");
1363 1fa2f630 Erik Kristensen
							break;
1364
						case 11:
1365 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS group update is successful.");
1366 4a6bb2ff Scott Ullrich
							$successful_update = true;
1367 1fa2f630 Erik Kristensen
							break;
1368
						case 12:
1369 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("DNS group is current, no update performed.");
1370 4a6bb2ff Scott Ullrich
							$successful_update = true;
1371 1fa2f630 Erik Kristensen
							break;
1372
						case 13:
1373 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Update client support not available for supplied hostname or group.");
1374 1fa2f630 Erik Kristensen
							break;
1375
						case 14:
1376 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Hostname supplied does not have offline settings configured.");
1377 1fa2f630 Erik Kristensen
							break;
1378
						case 99:
1379 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1380 1fa2f630 Erik Kristensen
							break;
1381
						case 100:
1382 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Client disabled. Client should exit and not perform any more updates without user intervention.");
1383 1fa2f630 Erik Kristensen
							break;
1384
						default:
1385 9557ca30 Phil Davis
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1386
							$this->_debug(gettext("Unknown Response:") . " " . $data);
1387 1fa2f630 Erik Kristensen
							break;
1388
					}
1389
					break;
1390
				case 'easydns':
1391
					if (preg_match('/NOACCESS/i', $data)) {
1392 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Authentication Failed: Username and/or Password was Incorrect.");
1393 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOSERVICE/i', $data)) {
1394 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No Service: Dynamic DNS Service has been disabled for this domain.");
1395 1fa2f630 Erik Kristensen
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
1396 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Illegal Input: Self-Explanatory");
1397 1fa2f630 Erik Kristensen
					} else if (preg_match('/TOOSOON/i', $data)) {
1398 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Too Soon: Not Enough Time Has Elapsed Since Last Update");
1399 1fa2f630 Erik Kristensen
					} else if (preg_match('/NOERROR/i', $data)) {
1400 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Updated Successfully!");
1401 4a6bb2ff Scott Ullrich
						$successful_update = true;
1402 1fa2f630 Erik Kristensen
					} else {
1403 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1404
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1405 1fa2f630 Erik Kristensen
						$this->_debug($data);
1406
					}
1407
					break;
1408
				case 'hn':
1409 9b8dc821 Scott Ullrich
					/* FIXME: add checks */
1410 1fa2f630 Erik Kristensen
					break;
1411
				case 'zoneedit':
1412 9b9e5f09 Scott Ullrich
					if (preg_match('/799/i', $data)) {
1413 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Error 799") . ") " . gettext("Update Failed!");
1414 332a3e59 Scott Ullrich
					} else if (preg_match('/700/i', $data)) {
1415 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Error 700") . ") " . gettext("Update Failed!");
1416 9b9e5f09 Scott Ullrich
					} else if (preg_match('/200/i', $data)) {
1417 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1418 4a6bb2ff Scott Ullrich
						$successful_update = true;
1419 9b9e5f09 Scott Ullrich
					} else if (preg_match('/201/i', $data)) {
1420 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1421 1e0b1727 Phil Davis
						$successful_update = true;
1422 1fa2f630 Erik Kristensen
					} else {
1423 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1424
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1425 1fa2f630 Erik Kristensen
						$this->_debug($data);
1426
					}
1427
					break;
1428
				case 'dyns':
1429
					if (preg_match("/400/i", $data)) {
1430 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The URL was malformed. Required parameters were not provided.");
1431 1fa2f630 Erik Kristensen
					} else if (preg_match('/402/i', $data)) {
1432 530e4707 NOYB
						$status = $status_intro . $error_str . gettext("Update Too Soon - Attempted to update too quickly since last change.");
1433 1fa2f630 Erik Kristensen
					} else if (preg_match('/403/i', $data)) {
1434 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Database Error - There was a server-sided database error.");
1435 1fa2f630 Erik Kristensen
					} else if (preg_match('/405/i', $data)) {
1436 1579e70f Phil Davis
						$status = $status_intro . $error_str . sprintf(gettext('Hostname Error - The hostname (%1$s) doesn\'t belong to user (%2$s).'), $this->_dnsHost, $this->_dnsUser);
1437 1fa2f630 Erik Kristensen
					} else if (preg_match('/200/i', $data)) {
1438 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1439 4a6bb2ff Scott Ullrich
						$successful_update = true;
1440 1fa2f630 Erik Kristensen
					} else {
1441 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1442
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1443 1fa2f630 Erik Kristensen
						$this->_debug($data);
1444
					}
1445
					break;
1446
				case 'ods':
1447
					if (preg_match("/299/i", $data)) {
1448 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1449 4a6bb2ff Scott Ullrich
						$successful_update = true;
1450 1fa2f630 Erik Kristensen
					} else {
1451 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1452
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1453 1fa2f630 Erik Kristensen
						$this->_debug($data);
1454
					}
1455
					break;
1456 9b8dc821 Scott Ullrich
				case 'freedns':
1457 ac16181a TechSmurf
				case 'freedns-v6':
1458 9b8dc821 Scott Ullrich
					if (preg_match("/has not changed./i", $data)) {
1459 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1460 9b8dc821 Scott Ullrich
						$successful_update = true;
1461
					} else if (preg_match("/Updated/i", $data)) {
1462 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1463 9b8dc821 Scott Ullrich
						$successful_update = true;
1464
					} else {
1465 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1466
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1467 9b8dc821 Scott Ullrich
						$this->_debug($data);
1468 1e0b1727 Phil Davis
					}
1469 9b8dc821 Scott Ullrich
					break;
1470 0a1b0183 Ermal Luçi
				case 'dnsexit':
1471
					if (preg_match("/is the same/i", $data)) {
1472 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1473 0a1b0183 Ermal Luçi
						$successful_update = true;
1474
					} else if (preg_match("/Success/i", $data)) {
1475 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1476 0a1b0183 Ermal Luçi
						$successful_update = true;
1477
					} else {
1478 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1479
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1480 87b91672 Phil Davis
						$this->_debug($data);
1481 0a1b0183 Ermal Luçi
					}
1482
					break;
1483 9b8dc821 Scott Ullrich
				case 'loopia':
1484
					if (preg_match("/nochg/i", $data)) {
1485 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1486 9b8dc821 Scott Ullrich
						$successful_update = true;
1487
					} else if (preg_match("/good/i", $data)) {
1488 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!");
1489 9b8dc821 Scott Ullrich
						$successful_update = true;
1490
					} else if (preg_match('/badauth/i', $data)) {
1491 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1492 9b8dc821 Scott Ullrich
					} else {
1493 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1494
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1495 9b8dc821 Scott Ullrich
						$this->_debug($data);
1496
					}
1497
					break;
1498 2d78b166 Ermal Luçi
				case 'opendns':
1499
					if (preg_match('/badauth/i', $data)) {
1500 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not a valid username or password!");
1501 2d78b166 Ermal Luçi
					} else if (preg_match('/nohost/i', $data)) {
1502 530e4707 NOYB
						$status = $status_intro . $error_str . gettext("Hostname specified does not exist.");
1503 2d78b166 Ermal Luçi
						$successful_update = true;
1504
					} else if (preg_match('/good/i', $data)) {
1505 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1506 2d78b166 Ermal Luçi
						$successful_update = true;
1507
					} else if (preg_match('/yours/i', $data)) {
1508 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Hostname specified exists, but not under the username specified.");
1509 2d78b166 Ermal Luçi
					} else if (preg_match('/abuse/i', $data)) {
1510 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Updating too frequently, considered abuse.");
1511 2d78b166 Ermal Luçi
					} else {
1512 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1513
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1514 2d78b166 Ermal Luçi
						$this->_debug($data);
1515
					}
1516
					break;
1517 37f3e704 Matt Corallo
				case 'staticcling':
1518 d74b5b8b sullrich
					if (preg_match("/invalid ip/i", $data)) {
1519 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1520 d74b5b8b sullrich
					} else if (preg_match('/required info missing/i', $data)) {
1521 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Required parameters were not provided.");
1522 d74b5b8b sullrich
					} else if (preg_match('/invalid characters/i', $data)) {
1523 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Illegal characters in either the username or the password.");
1524 d74b5b8b sullrich
					} else if (preg_match('/bad password/i', $data)) {
1525 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid password.");
1526 d74b5b8b sullrich
					} else if (preg_match('/account locked/i', $data)) {
1527 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("This account has been administratively locked.");
1528 d74b5b8b sullrich
					} else if (preg_match('/update too frequent/i', $data)) {
1529 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Updating too frequently.");
1530 d74b5b8b sullrich
					} else if (preg_match('/DB error/i', $data)) {
1531 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Server side error.");
1532 d74b5b8b sullrich
					} else if (preg_match('/success/i', $data)) {
1533 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1534 0c7bb880 Phil Davis
						$successful_update = true;
1535 d74b5b8b sullrich
					} else {
1536 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1537
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1538 0c7bb880 Phil Davis
						$this->_debug($data);
1539 d74b5b8b sullrich
					}
1540
					break;
1541 61c30081 jim-p
				case 'namecheap':
1542 18f15f68 jim-p
					$tmp = str_replace("^M", "", $data);
1543
					$ncresponse = @xml2array($tmp);
1544 61c30081 jim-p
					if (preg_match("/internal server error/i", $data)) {
1545 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Server side error.");
1546 3dc3b15b jim-p
					} else if (preg_match("/request is badly formed/i", $data)) {
1547 530e4707 NOYB
						$status = $status_intro . $error_str . gettext("Badly Formed Request (check the settings).");
1548 18f15f68 jim-p
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
1549 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1550 c305abd5 jim-p
						$successful_update = true;
1551 18f15f68 jim-p
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
1552 9557ca30 Phil Davis
						$status = $status_intro . $error_str . implode(", ", $ncresponse["interface-response"]["errors"]);
1553 c305abd5 jim-p
						$successful_update = true;
1554 61c30081 jim-p
					} else {
1555 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1556
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1557 61c30081 jim-p
						$this->_debug($data);
1558
					}
1559
					break;
1560 19b7263e Ionut
				case 'duiadns':
1561
				case 'duiadns-v6':
1562
					if (preg_match("/error/i", $data)) {
1563
						$status = $status_intro . $error_str . gettext("Server side error.");
1564
					} else if (preg_match('/nohost/i', $data)) {
1565
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1566
					} else if (preg_match('/badauth/i', $data)) {
1567
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1568
					} else if (preg_match('/good/i', $data)) {
1569
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1570
						$successful_update = true;
1571
					} else if (preg_match('/nochg/i', $data)) {
1572
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1573
						$successful_update = true;
1574
					} else {
1575
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1576
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1577
						$this->_debug($data);
1578
					}
1579
					break;
1580 8ea77433 Chris Wells
				case 'he-net':
1581 b4025ccd Daniel Becker
				case 'he-net-v6':
1582 8ea77433 Chris Wells
					if (preg_match("/badip/i", $data)) {
1583 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - The IP provided was invalid.");
1584 8ea77433 Chris Wells
					} else if (preg_match('/nohost/i', $data)) {
1585 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - A hostname was not provided.");
1586 8ea77433 Chris Wells
					} else if (preg_match('/badauth/i', $data)) {
1587 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1588 8ea77433 Chris Wells
					} else if (preg_match('/good/i', $data)) {
1589 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1590 0c7bb880 Phil Davis
						$successful_update = true;
1591 8ea77433 Chris Wells
					} else if (preg_match('/nochg/i', $data)) {
1592 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1593 0c7bb880 Phil Davis
						$successful_update = true;
1594 8ea77433 Chris Wells
					} else {
1595 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1596
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1597 0c7bb880 Phil Davis
						$this->_debug($data);
1598 8ea77433 Chris Wells
					}
1599
					break;
1600 38a481ad jim-p
				case 'he-net-tunnelbroker':
1601
					/*
1602
					-ERROR: Missing parameter(s).
1603
					-ERROR: Invalid API key or password
1604
					-ERROR: Tunnel not found
1605
					-ERROR: Another tunnel exists for this IP.
1606
					-ERROR: This tunnel is already associated with this IP address
1607
					+OK: Tunnel endpoint updated to: x.x.x.x
1608
					*/
1609
					if (preg_match("/Missing parameter/i", $data)) {
1610 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Missing/Invalid Parameters.");
1611 38a481ad jim-p
					} else if (preg_match('/Tunnel not found/i', $data)) {
1612 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad Request - Invalid Tunnel ID.");
1613 38a481ad jim-p
					} else if (preg_match('/Invalid API key or password/i', $data)) {
1614 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid username or password.");
1615 38a481ad jim-p
					} else if (preg_match('/OK:/i', $data)) {
1616 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1617 0c7bb880 Phil Davis
						$successful_update = true;
1618 38a481ad jim-p
					} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
1619 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1620 0c7bb880 Phil Davis
						$successful_update = true;
1621 38a481ad jim-p
					} else {
1622 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1623
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1624 0c7bb880 Phil Davis
						$this->_debug($data);
1625 38a481ad jim-p
					}
1626
					break;
1627 fb403496 Gerald Raaf
				case 'selfhost':
1628
					if (preg_match('/notfqdn/i', $data)) {
1629 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1630 fb403496 Gerald Raaf
					} else if (preg_match('/nochg/i', $data)) {
1631 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address.");
1632 fb403496 Gerald Raaf
						$successful_update = true;
1633
					} else if (preg_match('/good/i', $data)) {
1634 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1635 fb403496 Gerald Raaf
						$successful_update = true;
1636
					} else if (preg_match('/noauth/i', $data)) {
1637 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1638 fb403496 Gerald Raaf
					} else {
1639 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1640
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1641 fb403496 Gerald Raaf
						$this->_debug($data);
1642
					}
1643
					break;
1644 0c7bb880 Phil Davis
				case 'route53':
1645 44c64da1 Matthew Fine
				case 'route53-v6':
1646 cc5adcaa Jason McCormick
					if(preg_match('/ErrorResponse/', $data)){
1647
						$status = $status_intro . $error_str . gettext("Route53 API call failed");
1648
						log_error(sprintf("error message: %s", $data));
1649
						$status_update = false;
1650
					} else {
1651 166f4a4c Jason McCormick
						$status = $status_intro . $success_str . gettext("IP address changed successfully");
1652 cc5adcaa Jason McCormick
						$successful_update = true;
1653
					}
1654 0c7bb880 Phil Davis
					break;
1655 37f3e704 Matt Corallo
				case 'custom':
1656 da40615d Daniel Becker
				case 'custom-v6':
1657 37f3e704 Matt Corallo
					$successful_update = false;
1658
					if ($this->_dnsResultMatch == "") {
1659
						$successful_update = true;
1660 1e0b1727 Phil Davis
					} else {
1661 37f3e704 Matt Corallo
						$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
1662
						$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
1663 1e0b1727 Phil Davis
						foreach ($matches as $match) {
1664 37f3e704 Matt Corallo
							$match= str_replace("\\|", "|", $match);
1665 1e0b1727 Phil Davis
							if (strcmp($match, trim($data, "\t\n\r")) == 0) {
1666 37f3e704 Matt Corallo
								$successful_update = true;
1667 1e0b1727 Phil Davis
							}
1668 37f3e704 Matt Corallo
						}
1669
						unset ($matches);
1670
					}
1671 1e0b1727 Phil Davis
					if ($successful_update == true) {
1672 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1673 1e0b1727 Phil Davis
					} else {
1674 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Result did not match.") . " [" . $data . "]";
1675 1e0b1727 Phil Davis
					}
1676 37f3e704 Matt Corallo
					break;
1677 3a05e4c3 Austin Seipp
				case 'cloudflare-v6':
1678 e26e1f76 Andrew Senetar
				case 'cloudflare':
1679 22d95a68 doktornotor
					$output = json_decode($data);
1680 4e322e2c Phil Davis
					if ($output->result->content === $this->_dnsIP) {
1681 9557ca30 Phil Davis
						$status = $status_intro . $success_str . sprintf(gettext('%1$s updated to %2$s'), $this->_dnsHost, $this->_dnsIP);
1682 22d95a68 doktornotor
						$successful_update = true;
1683 4e322e2c Phil Davis
					} elseif ($output->errors[0]->code === 9103) {
1684 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Invalid Credentials! Don't forget to use API Key for password field with CloudFlare.");
1685 4e322e2c Phil Davis
					} elseif (($output->success) && (!$output->result[0]->id)) {
1686 530e4707 NOYB
						$status = $status_intro . $error_str . gettext("Zone or Host ID was not found, check the hostname.");
1687 4e322e2c Phil Davis
					} else {
1688 9557ca30 Phil Davis
						$status = $status_intro . gettext("UNKNOWN ERROR") . " - " . $output->errors[0]->message;
1689
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1690 ffa1acdc Andrew Senetar
					}
1691
					break;
1692 ec66caa6 John Byron
				case 'eurodns':
1693
					if (preg_match('/notfqdn/i', $data)) {
1694 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1695 ec66caa6 John Byron
					} else if (preg_match('/nochg/i', $data)) {
1696 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1697 ec66caa6 John Byron
						$successful_update = true;
1698
					} else if (preg_match('/good/i', $data)) {
1699 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1700 ec66caa6 John Byron
						$successful_update = true;
1701
					} else if (preg_match('/badauth/i', $data)) {
1702 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1703 ec66caa6 John Byron
					} else {
1704 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1705
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1706 ec66caa6 John Byron
						$this->_debug($data);
1707
					}
1708
					break;
1709 5458bc59 Scavy
				case 'gratisdns':
1710
					if (preg_match('/Forkerte værdier/i', $data)) {
1711 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Wrong values - Update could not be completed.");
1712 5458bc59 Scavy
					} else if (preg_match('/Bruger login: Bruger eksistere ikke/i', $data)) {
1713 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Unknown username - User does not exist.");
1714 5458bc59 Scavy
					} else if (preg_match('/Bruger login: 1Fejl i kodeord/i', $data)) {
1715 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Wrong password - Remember password is case sensitive.");
1716 5458bc59 Scavy
					} else if (preg_match('/Domæne kan IKKE administreres af bruger/i', $data)) {
1717 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User unable to administer the selected domain.");
1718 5458bc59 Scavy
					} else if (preg_match('/OK/i', $data)) {
1719 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1720 1e0b1727 Phil Davis
						$successful_update = true;
1721 5458bc59 Scavy
					} else {
1722 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1723
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1724 1e0b1727 Phil Davis
						$this->_debug($data);
1725 5458bc59 Scavy
					}
1726
					break;
1727 916d683e surrural
				case 'dnsimple':
1728
					/* Responds with HTTP 200 on success.
1729
					   Responds with HTTP 4xx on error.
1730
					   Returns JSON data as body */
1731 0e0f580d Christoph Filnkößl
;
1732
					if (preg_match("/\s200\sOK/i", $header)) {
1733 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1734 916d683e surrural
						$successful_update = true;
1735 0e0f580d Christoph Filnkößl
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1736
						$arrbody = json_decode($data, true);
1737 916d683e surrural
						$message = $arrbody['message'] . ".";
1738
						if (isset($arrbody['errors']['content'])) {
1739 1e0b1727 Phil Davis
							foreach ($arrbody['errors']['content'] as $key => $content) {
1740 916d683e surrural
								$message .= " " . $content . ".";
1741
							}
1742
						}
1743 9557ca30 Phil Davis
						$status = $status_intro . $error_str . $message;
1744 916d683e surrural
					} else {
1745 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1746 0e0f580d Christoph Filnkößl
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1747
						$this->_debug($data);
1748 916d683e surrural
					}
1749
					break;
1750 456ba14f Sam Neely
				case 'godaddy':
1751
				case 'godaddy-v6':
1752
					/* Responds with HTTP 200 on success.
1753
					   Responds with HTTP 4xx or  on error.
1754
					   Returns JSON data as body */
1755
;
1756
					if (preg_match("/\s200\sOK/i", $header)) {
1757
						$status = $status_intro . $success_str . gettext("IP Address Updated Successfully!");
1758
						$successful_update = true;
1759
					} else if (preg_match("/\s4\d\d\s/i", $header)) {
1760
						$arrbody = json_decode($data, true);
1761
						$message = $arrbody['message'] . ".";
1762
						if (isset($arrbody['fields'])) {
1763
							foreach ($arrbody['fields'] as $error) {
1764
								$message .= " " . $error['path'] . ": " . $error['message'] . ".";
1765
							}
1766
						}
1767
						$status = $status_intro . $error_str . $message;
1768
					} else {
1769
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1770
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1771
						$this->_debug($data);
1772
					}
1773
					break;
1774 c5ecdc25 Jose Luis Duran
				case 'googledomains':
1775 6c92b378 Christopher Fazendin
					if (preg_match('/notfqdn/i', $data)) {
1776 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN");
1777 6c92b378 Christopher Fazendin
					} else if (preg_match('/nochg/i', $data)) {
1778 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1779 6c92b378 Christopher Fazendin
						$successful_update = true;
1780
					} else if (preg_match('/good/i', $data)) {
1781 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1782 6c92b378 Christopher Fazendin
						$successful_update = true;
1783
					} else if (preg_match('/badauth/i', $data)) {
1784 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1785 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/nohost/i', $data)) {
1786 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Hostname does not exist or DynDNS not enabled");
1787 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/badagent/i', $data)) {
1788 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Bad request");
1789 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/abuse/i', $data)) {
1790 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Dynamic DNS access has been blocked!");
1791 c5ecdc25 Jose Luis Duran
					} else if (preg_match('/911/i', $data)) {
1792 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Error on Google's end, retry in 5 minutes");
1793 6c92b378 Christopher Fazendin
					} else {
1794 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1795
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1796 6c92b378 Christopher Fazendin
						$this->_debug($data);
1797
					}
1798
					break;
1799 c5ecdc25 Jose Luis Duran
				case 'dnsmadeeasy':
1800
					switch ($data) {
1801
						case 'success':
1802 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1803 c5ecdc25 Jose Luis Duran
							$successful_update = true;
1804
							break;
1805
						case 'error-auth':
1806 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Invalid username or password");
1807 c5ecdc25 Jose Luis Duran
							break;
1808
						case 'error-auth-suspend':
1809 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account suspended");
1810 c5ecdc25 Jose Luis Duran
							break;
1811
						case 'error-auth-voided':
1812 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Account revoked");
1813 c5ecdc25 Jose Luis Duran
							break;
1814
						case 'error-record-invalid':
1815 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("Record does not exist in the system. Unable to update record");
1816 c5ecdc25 Jose Luis Duran
							break;
1817
						case 'error-record-auth':
1818 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("User does not have access to this record");
1819 c5ecdc25 Jose Luis Duran
							break;
1820
						case 'error-record-ip-same':
1821 9557ca30 Phil Davis
							$status = $status_intro . $success_str . gettext("No Change In IP Address");
1822 c5ecdc25 Jose Luis Duran
							$successful_update = true;
1823
							break;
1824
						case 'error-system':
1825 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("General system error recognized by the system");
1826 c5ecdc25 Jose Luis Duran
							break;
1827
						case 'error':
1828 9557ca30 Phil Davis
							$status = $status_intro . $error_str . gettext("General system error unrecognized by the system");
1829 c5ecdc25 Jose Luis Duran
							break;
1830
						default:
1831 9557ca30 Phil Davis
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1832
							log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1833 c5ecdc25 Jose Luis Duran
							$this->_debug($data);
1834
							break;
1835
					}
1836
					break;
1837 1c2c08bd exii1988
				case 'spdyn':
1838
				case 'spdyn-v6':
1839 f3ee8545 Rene Schuster
					if (preg_match('/notfqdn/i', $data)) {
1840 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("Not A FQDN!");
1841 f3ee8545 Rene Schuster
					} else if (preg_match('/nohost/i', $data)) {
1842 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("No such host");
1843 f3ee8545 Rene Schuster
					} else if (preg_match('/nochg/i', $data)) {
1844 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("No Change In IP Address");
1845
						$successful_update = true;
1846 f3ee8545 Rene Schuster
					} else if (preg_match('/good/i', $data)) {
1847 9557ca30 Phil Davis
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1848
						$successful_update = true;
1849 f3ee8545 Rene Schuster
					} else if (preg_match('/badauth/i', $data)) {
1850 9557ca30 Phil Davis
						$status = $status_intro . $error_str . gettext("User Authorization Failed");
1851 f3ee8545 Rene Schuster
					} else {
1852 9557ca30 Phil Davis
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1853
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1854
						$this->_debug($data);
1855 f3ee8545 Rene Schuster
					}
1856
					break;
1857 575b1dcf Christoph Filnkößl
				case 'all-inkl':
1858
 					if (preg_match('/good\s'.$this->_dnsIP.'/i', $data)) {
1859
							$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1860
 							$successful_update = true;
1861
 					} else if (preg_match('/good/i', $data)) {
1862
						$status = $status_intro . $error_str . gettext("Result did not match.");
1863
					} else if (preg_match("/\s401\sUnauthorized/i", $header)) {
1864
						$status = $status_intro . $error_str . gettext("Invalid username or password");
1865
					} 
1866
					else {
1867
							$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1868
							log_error($status_intro . gettext("PAYLOAD:") . " " . $header.$data);
1869
 							$this->_debug($data);
1870
 							$this->_debug($header);
1871
 					}
1872
 					break;
1873 74533d41 xygrec
				case 'hover':
1874
					if (preg_match('/succeeded":true/i', $data)) {
1875
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1876
						$successful_update = true;
1877
					} else {
1878
						$status = $status_intro . "(" . gettext("Unknown Response") . ")";
1879
						log_error($status_intro . gettext("PAYLOAD:") . " " . $data);
1880
						$this->_debug($data);
1881
					}
1882
					break;
1883 745d3779 Wagner Sartori Junior
				case 'cloudns':
1884
					$result = json_decode($data, true);
1885
					if ($result['status'] == 'Success') {
1886
						$successful_update = true;
1887
					} else {
1888
						log_error($result['status'] . "(" . $result['statusDescription'] . ")");
1889
					}
1890
					break;
1891 9a3ec9a5 frank
				case 'dreamhost':
1892
				case 'dreamhost-v6':
1893
					$result = json_decode($data,true);
1894
					if ($this->_dnsVerboseLog) {
1895
						log_error(sprintf(gettext('_checkStatus() results: %1$s'), $data));
1896
					}
1897
					switch ($result['data']) {
1898 e350558a frank
					case 'success':
1899
					case 'record_added':
1900
					case 'record_removed':
1901
						$status = $status_intro . $success_str . gettext("IP Address Changed Successfully!") . " (" . $this->_dnsIP . ")";
1902
						$successful_update = true;
1903
						break;
1904
					case 'no_record':
1905
					case 'no_such_record ':
1906
						$status = $status_intro . $error_str . gettext("No record exists.");
1907
						break;
1908 598c1d97 frank
					case 'no_type':
1909 e350558a frank
					case 'no_such_type ':
1910
						$status = $status_intro . $error_str . gettext("No type exists.");
1911
						break;
1912 598c1d97 frank
					case 'no_value':
1913 e350558a frank
					case 'no_such_value ':
1914
						$status = $status_intro . $error_str . gettext("No value exists.");
1915
						break;
1916
					case 'no_such_zone':
1917
						$status = $status_intro . $error_str . gettext("No such zone exists.");
1918
						break;
1919
					case 'invalid_record':
1920
						$status = $status_intro . $error_str . gettext("The specified record is invalid.");
1921
						break;
1922
					case 'invalid_type':
1923
						$status = $status_intro . $error_str . gettext("The specified type is invalid.");
1924
						break;
1925
					case 'invalid_value':
1926
						$status = $status_intro . $error_str . gettext("The specified value is invalid.");
1927
						break;
1928
					case 'not_editable ':
1929
						$status = $status_intro . $error_str . gettext("Record is not editable.");
1930
						break;
1931
					case 'record_already_exists_not_editable':
1932
						$status = $status_intro . $error_str . gettext("Record exists but is not editable.");
1933
						break;
1934
					case 'record_already_exists_remove_first':
1935
						$status = $status_intro . $error_str . gettext("Record exists and must be removed before adding.");
1936
						break;
1937
					case 'internal_error_updating_zone':
1938
						$status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone.");
1939
						break;
1940
					case 'internal_error_could_not_load_zone':
1941
						$status = $status_intro . $error_str . gettext("A remote server error occurred loading the zone.");
1942
						break;
1943
					case 'internal_error_could_not_update_zone':
1944
						$status = $status_intro . $error_str . gettext("A remote server error occurred updating the zone.");
1945
						break;
1946
					case 'internal_error_could_not_add_record':
1947
						$status = $status_intro . $error_str . gettext("A remote server error occurred adding a new record.");
1948
						break;
1949
					case 'internal_error_could_not_destroy_record ':
1950
						$status = $status_intro . $error_str . gettext("A remote server error occurred removing an existing record.");
1951
						break;
1952
					default:
1953
						break;
1954 9a3ec9a5 frank
					}
1955
				default:
1956
					break;
1957 1fa2f630 Erik Kristensen
			}
1958 916d683e surrural
1959 1e0b1727 Phil Davis
			if ($successful_update == true) {
1960 4a6bb2ff Scott Ullrich
				/* Write WAN IP to cache file */
1961 22de7804 Bill Marquette
				$wan_ip = $this->_checkIP();
1962 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == false && $wan_ip > 0) {
1963 53842a6c jim-p
					$currentTime = time();
1964 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));
1965
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile, $wan_ip));
1966 d51cdd48 Renato Botelho
					@file_put_contents($this->_cacheFile, "{$wan_ip}|{$currentTime}");
1967 1e0b1727 Phil Davis
				} else {
1968 dd575ea4 Ermal
					@unlink($this->_cacheFile);
1969 1e0b1727 Phil Davis
				}
1970 d7e6f573 Daniel Becker
				if ($this->_useIPv6 == true && $wan_ip > 0) {
1971 b4025ccd Daniel Becker
					$currentTime = time();
1972 1579e70f Phil Davis
					notify_all_remote(sprintf(gettext('DynDNS updated IPv6 Address on %1$s (%2$s) to %3$s'), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
1973 9557ca30 Phil Davis
					log_error(sprintf(gettext('phpDynDNS: updating cache file %1$s: %2$s'), $this->_cacheFile_v6, $wan_ip));
1974 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile_v6, "{$wan_ip}|{$currentTime}");
1975 1e0b1727 Phil Davis
				} else {
1976 d7e6f573 Daniel Becker
					@unlink($this->_cacheFile_v6);
1977 1e0b1727 Phil Davis
				}
1978 4a6bb2ff Scott Ullrich
			}
1979 1fa2f630 Erik Kristensen
			$this->status = $status;
1980
			log_error($status);
1981
		}
1982
1983
		/*
1984
		 * Private Function (added 12 July 05) [beta]
1985
		 *   Return Error, Set Last Error, and Die.
1986
		 */
1987
		function _error($errorNumber = '1') {
1988 9557ca30 Phil Davis
			$err_str = 'phpDynDNS: (' . gettext('ERROR!') . ') ';
1989
			$err_str_r53 = 'Route 53: (' . gettext('Error') . ') ';
1990 1fa2f630 Erik Kristensen
			switch ($errorNumber) {
1991
				case 0:
1992
					break;
1993
				case 2:
1994 9557ca30 Phil Davis
					$error = $err_str . gettext('No Dynamic DNS Service provider was selected.');
1995 1fa2f630 Erik Kristensen
					break;
1996
				case 3:
1997 9557ca30 Phil Davis
					$error = $err_str . gettext('No Username Provided.');
1998 1fa2f630 Erik Kristensen
					break;
1999
				case 4:
2000 9557ca30 Phil Davis
					$error = $err_str . gettext('No Password Provided.');
2001 1fa2f630 Erik Kristensen
					break;
2002
				case 5:
2003 9557ca30 Phil Davis
					$error = $err_str . gettext('No Hostname Provided.');
2004 1fa2f630 Erik Kristensen
					break;
2005
				case 6:
2006 9557ca30 Phil Davis
					$error = $err_str . gettext('The Dynamic DNS Service provided is not yet supported.');
2007 1fa2f630 Erik Kristensen
					break;
2008 9b8dc821 Scott Ullrich
				case 7:
2009 9557ca30 Phil Davis
					$error = $err_str . gettext('No Update URL Provided.');
2010 9b8dc821 Scott Ullrich
					break;
2011 0c7bb880 Phil Davis
				case 8:
2012 9557ca30 Phil Davis
					$status = $err_str_r53 . gettext("Invalid ZoneID");
2013 cd132e86 Edson Brandi
					break;
2014 0c7bb880 Phil Davis
				case 9:
2015 9557ca30 Phil Davis
					$status = $err_str_r53 . gettext("Invalid TTL");
2016 1e0b1727 Phil Davis
					break;
2017 1fa2f630 Erik Kristensen
				case 10:
2018 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);
2019 1fa2f630 Erik Kristensen
					break;
2020
				default:
2021 9557ca30 Phil Davis
					$error = $err_str . gettext('Unknown Response.');
2022 9b8dc821 Scott Ullrich
					/* FIXME: $data isn't in scope here */
2023
					/* $this->_debug($data); */
2024 1fa2f630 Erik Kristensen
					break;
2025
			}
2026
			$this->lastError = $error;
2027
			log_error($error);
2028
		}
2029
2030
		/*
2031
		 * Private Function (added 12 July 05) [beta]
2032
		 *   - Detect whether or not IP needs to be updated.
2033 5775f324 Chris Buechler
		 *      | Written Specifically for pfSense (https://www.pfsense.org) may
2034 1fa2f630 Erik Kristensen
		 *      | work with other systems. pfSense base is FreeBSD.
2035
		 */
2036
		function _detectChange() {
2037 dceff62e Ermal
			global $debug;
2038
2039 1e0b1727 Phil Davis
			if ($debug) {
2040 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _detectChange() starting.'), $this->_dnsService, $this->_FQDN));
2041 1e0b1727 Phil Davis
			}
2042
2043 1fa2f630 Erik Kristensen
			$currentTime = time();
2044
2045 22de7804 Bill Marquette
			$wan_ip = $this->_checkIP();
2046 dd575ea4 Ermal
			if ($wan_ip == 0) {
2047 9557ca30 Phil Davis
				log_error(sprintf(gettext("Dynamic Dns (%s): Current WAN IP could not be determined, skipping update process."), $this->_FQDN));
2048 193ee786 Ermal
				return false;
2049 dd575ea4 Ermal
			}
2050 9557ca30 Phil Davis
			$log_error = sprintf(gettext('Dynamic Dns (%1$s): Current WAN IP: %2$s'), $this->_FQDN, $wan_ip) . " ";
2051 1fa2f630 Erik Kristensen
2052 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
2053
				if (file_exists($this->_cacheFile_v6)) {
2054
					$contents = file_get_contents($this->_cacheFile_v6);
2055 086cf944 Phil Davis
					list($cacheIP, $cacheTime) = explode('|', $contents);
2056 d7e6f573 Daniel Becker
					$this->_debug($cacheIP.'/'.$cacheTime);
2057
					$initial = false;
2058 9557ca30 Phil Davis
					$log_error .= sprintf(gettext("Cached IPv6: %s"), $cacheIP);
2059 d7e6f573 Daniel Becker
				} else {
2060
					$cacheIP = '::';
2061 b4319c50 Daniel Becker
					@file_put_contents($this->_cacheFile, "::|{$currentTime}");
2062 d7e6f573 Daniel Becker
					$cacheTime = $currentTime;
2063
					$initial = true;
2064 9557ca30 Phil Davis
					$log_error .= gettext("No Cached IPv6 found.");
2065 d7e6f573 Daniel Becker
				}
2066 1fa2f630 Erik Kristensen
			} else {
2067 d7e6f573 Daniel Becker
				if (file_exists($this->_cacheFile)) {
2068
					$contents = file_get_contents($this->_cacheFile);
2069 d51cdd48 Renato Botelho
					list($cacheIP, $cacheTime) = explode('|', $contents);
2070 d7e6f573 Daniel Becker
					$this->_debug($cacheIP.'/'.$cacheTime);
2071
					$initial = false;
2072 9557ca30 Phil Davis
					$log_error .= sprintf(gettext("Cached IP: %s"), $cacheIP);
2073 d7e6f573 Daniel Becker
				} else {
2074
					$cacheIP = '0.0.0.0';
2075 d51cdd48 Renato Botelho
					@file_put_contents($this->_cacheFile, "0.0.0.0|{$currentTime}");
2076 d7e6f573 Daniel Becker
					$cacheTime = $currentTime;
2077
					$initial = true;
2078 9557ca30 Phil Davis
					$log_error .= gettext("No Cached IP found.");
2079 d7e6f573 Daniel Becker
				}
2080 1fa2f630 Erik Kristensen
			}
2081 1e0b1727 Phil Davis
			if ($this->_dnsVerboseLog) {
2082 87b91672 Phil Davis
				log_error($log_error);
2083 1e0b1727 Phil Davis
			}
2084 1fa2f630 Erik Kristensen
2085 f5e293e6 Phil Davis
			// Convert seconds = days * hr/day * min/hr * sec/min
2086
			$maxCacheAgeSecs = $this->_dnsMaxCacheAgeDays * 24 * 60 * 60;
2087 1fa2f630 Erik Kristensen
2088 e24b26e9 Scott Ullrich
			$needs_updating = FALSE;
2089 4494cf6a Chris Buechler
			/* lets determine if the item needs updating */
2090 a255e1f7 Scott Ullrich
			if ($cacheIP != $wan_ip) {
2091 eb346556 Ermal Lu?i
				$needs_updating = true;
2092 9557ca30 Phil Davis
				$update_reason = gettext("Dynamic Dns: cacheIP != wan_ip. Updating.") . " ";
2093
				$update_reason .= sprintf(gettext('Cached IP: %1$s WAN IP: %2$s'), $cacheIP, $wan_ip) . " ";
2094 a255e1f7 Scott Ullrich
			}
2095 f5e293e6 Phil Davis
			if (($currentTime - $cacheTime) > $maxCacheAgeSecs) {
2096 c3c3e03b Ermal
				$needs_updating = true;
2097 0333f968 Phil Davis
				$this->_forceUpdateNeeded = true;
2098 9557ca30 Phil Davis
				$update_reason = sprintf(gettext("Dynamic Dns: More than %s days. Updating."), $this->_dnsMaxCacheAgeDays);
2099
				$update_reason .= " {$currentTime} - {$cacheTime} > {$maxCacheAgeSecs} ";
2100 a255e1f7 Scott Ullrich
			}
2101 eb346556 Ermal Lu?i
			if ($initial == true) {
2102
				$needs_updating = true;
2103 9557ca30 Phil Davis
				$update_reason .= gettext("Initial update.");
2104 a255e1f7 Scott Ullrich
			}
2105 eb346556 Ermal Lu?i
2106 a255e1f7 Scott Ullrich
			/*   finally if we need updating then store the
2107
			 *   new cache value and return true
2108 0c7bb880 Phil Davis
			 */
2109 eb346556 Ermal Lu?i
			if ($needs_updating == true) {
2110 086cf944 Phil Davis
				if ($this->_dnsVerboseLog) {
2111 6635aa0f jim-p
					log_error("DynDns ({$this->_FQDN}): {$update_reason}");
2112 086cf944 Phil Davis
				}
2113 eb346556 Ermal Lu?i
				return true;
2114 1fa2f630 Erik Kristensen
			}
2115 eb346556 Ermal Lu?i
2116 1e0b1727 Phil Davis
			return false;
2117 1fa2f630 Erik Kristensen
		}
2118
2119
		/*
2120 0c7bb880 Phil Davis
		 * Private Function (added 16 July 05) [beta]
2121 1fa2f630 Erik Kristensen
		 *   - Writes debug information to a file.
2122
		 *   - This function is only called when a unknown response
2123
		 *   - status is returned from a DynDNS service provider.
2124
		 */
2125 6a45171d Ermal
		function _debug($data) {
2126
			global $g;
2127
2128 1e0b1727 Phil Davis
			if (!$g['debug']) {
2129 6a45171d Ermal
				return;
2130 1e0b1727 Phil Davis
			}
2131 bb9ccd63 bcyrill
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data."\n";
2132 1fa2f630 Erik Kristensen
			$file = fopen($this->_debugFile, 'a');
2133
			fwrite($file, $string);
2134
			fclose($file);
2135
		}
2136 22de7804 Bill Marquette
		function _checkIP() {
2137 dceff62e Ermal
			global $debug;
2138 22de7804 Bill Marquette
2139 1e0b1727 Phil Davis
			if ($debug) {
2140 9557ca30 Phil Davis
				log_error(sprintf(gettext('Dynamic DNS %1$s (%2$s): _checkIP() starting.'), $this->_dnsService, $this->_FQDN));
2141 1e0b1727 Phil Davis
			}
2142 22de7804 Bill Marquette
2143 d7e6f573 Daniel Becker
			if ($this->_useIPv6 == true) {
2144 d20a3d08 Chris Buechler
				$ip_address = get_interface_ipv6($this->_if);
2145 1e0b1727 Phil Davis
				if (!is_ipaddrv6($ip_address)) {
2146 d7e6f573 Daniel Becker
					return 0;
2147 1e0b1727 Phil Davis
				}
2148 d7e6f573 Daniel Becker
			} else {
2149 d20a3d08 Chris Buechler
				$ip_address = get_interface_ip($this->_if);
2150 1e0b1727 Phil Davis
				if (!is_ipaddr($ip_address)) {
2151 d7e6f573 Daniel Becker
					return 0;
2152 1e0b1727 Phil Davis
				}
2153 d7e6f573 Daniel Becker
			}
2154
			if ($this->_useIPv6 == false && is_private_ip($ip_address)) {
2155 1b665090 Ermal Lu?i
				$hosttocheck = "checkip.dyndns.org";
2156 83ae8103 Ermal
				$try = 0;
2157
				while ($try < 3) {
2158
					$checkip = gethostbyname($hosttocheck);
2159 1e0b1727 Phil Davis
					if (is_ipaddr($checkip)) {
2160 83ae8103 Ermal
						break;
2161 1e0b1727 Phil Davis
					}
2162 83ae8103 Ermal
					$try++;
2163
				}
2164
				if ($try >= 3) {
2165 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));
2166 dd575ea4 Ermal
					return 0;
2167 83ae8103 Ermal
				}
2168 7ae7a972 Ermal Lu?i
				$ip_ch = curl_init("http://{$checkip}");
2169
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
2170
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
2171 e1eee3d2 Renato Botelho
				curl_setopt($ip_ch, CURLOPT_INTERFACE, 'host!' . $ip_address);
2172 83ae8103 Ermal
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
2173 93b8df2a Ermal
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
2174 cd8f7eee Florian Asche
				if ($this->_useIPv6 == false) {
2175
					curl_setopt($ip_ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
2176 7dc42e4a Florian Asche
				}
2177 7ae7a972 Ermal Lu?i
				$ip_result_page = curl_exec($ip_ch);
2178
				curl_close($ip_ch);
2179
				$ip_result_decoded = urldecode($ip_result_page);
2180 c3c3e03b Ermal
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
2181 7ae7a972 Ermal Lu?i
				$ip_address = trim($matches[1]);
2182 87b91672 Phil Davis
				if (is_ipaddr($ip_address)) {
2183 1e0b1727 Phil Davis
					if ($this->_dnsVerboseLog) {
2184 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));
2185 1e0b1727 Phil Davis
					}
2186 87b91672 Phil Davis
				} else {
2187 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));
2188 c749ef62 Ermal
					return 0;
2189
				}
2190 87b91672 Phil Davis
			} else {
2191 1e0b1727 Phil Davis
				if ($this->_dnsVerboseLog) {
2192 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));
2193 1e0b1727 Phil Davis
				}
2194 87b91672 Phil Davis
			}
2195 fffbfef0 Matt Corallo
			$this->_dnsIP = $ip_address;
2196
2197 22de7804 Bill Marquette
			return $ip_address;
2198
		}
2199 1fa2f630 Erik Kristensen
2200
	}
2201
2202 aa7c49b9 Ermal
?>