Project

General

Profile

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