Project

General

Profile

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