Project

General

Profile

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