Project

General

Profile

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