Project

General

Profile

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