Project

General

Profile

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