Project

General

Profile

Download (36.4 KB) Statistics
| Branch: | Tag: | Revision:
1 d237be68 Scott Ullrich
<?php
2 1fa2f630 Erik Kristensen
	/*
3
	 * PHP.updateDNS (pfSense version)
4
	 *
5
	 * +====================================================+
6
	 *  Services Supported:
7 9b8dc821 Scott Ullrich
	 *    - DynDns (dyndns.org) [dynamic, static, custom]
8 1fa2f630 Erik Kristensen
	 *    - 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 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
23
	 *  Requirements:
24
	 *    - PHP version 4.0.2 or higher with CURL Library
25
	 * +----------------------------------------------------+
26
	 *  Public Functions
27
	 *    - updatedns()
28
	 *
29
	 *  Private Functions
30
	 *    - _update()
31
	 *    - _checkStatus()
32
	 *    - _error()
33
	 *    - _detectChange()
34
	 *    - _debug()
35 22de7804 Bill Marquette
	 *    - _checkIP()
36 1fa2f630 Erik Kristensen
	 * +----------------------------------------------------+
37
	 *  DynDNS Dynamic - Last Tested: 12 July 2005
38
	 *  DynDNS Static  - Last Tested: NEVER
39
	 *  DynDNS Custom  - Last Tested: NEVER
40 fdcaa527 Ermal Luçi
	 *  No-IP          - Last Tested: 20 July 2008
41 1fa2f630 Erik Kristensen
	 *  HN.org         - Last Tested: 12 July 2005
42 fdcaa527 Ermal Luçi
	 *  EasyDNS        - Last Tested: 20 July 2008
43 1fa2f630 Erik Kristensen
	 *  DHS            - Last Tested: 12 July 2005
44
	 *  ZoneEdit       - Last Tested: NEVER
45
	 *  Dyns           - Last Tested: NEVER
46 0da417be Erik Kristensen
	 *  ODS            - Last Tested: 02 August 2005
47 62ce9874 gnhb
	 *  FreeDNS        - Last Tested: 23 Feb 2011
48 9b8dc821 Scott Ullrich
	 *  Loopia         - Last Tested: NEVER
49
	 *  StaticCling    - Last Tested: 27 April 2006
50 0a1b0183 Ermal Luçi
	 *  DNSexit	   - Last Tested: 20 July 2008
51 2d78b166 Ermal Luçi
	 *  OpenDNS	   - Last Tested: 4 August 2008
52 18f15f68 jim-p
	 *  Namecheap	   - Last Tested: 31 August 2010
53 8ea77433 Chris Wells
	 *  HE.net         - Last Tested: NEVER
54 1fa2f630 Erik Kristensen
	 * +====================================================+
55
	 *
56 e24b26e9 Scott Ullrich
	 * @author 	E.Kristensen
57 1fa2f630 Erik Kristensen
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
58 0da417be Erik Kristensen
	 * @version 	0.8
59 e24b26e9 Scott Ullrich
	 * @updated	13 October 05 at 21:02:42 GMT
60 1fa2f630 Erik Kristensen
	 *
61 2d78b166 Ermal Luçi
	 * DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Lu?i
62 0a1b0183 Ermal Luçi
	 *
63 1fa2f630 Erik Kristensen
	 */
64
65
	class updatedns {
66 67ee1ec5 Ermal Luçi
		var $_cacheFile;
67
		var $_debugFile;
68 1fa2f630 Erik Kristensen
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
69
		var $_errorVerbosity = 0;
70
		var $_dnsService;
71
		var $_dnsUser;
72
		var $_dnsPass;
73
		var $_dnsHost;
74
		var $_dnsIP;
75 d2cf5c39 Ermal Lu?i
		/* This is needed for support on addresses behind NAT. */
76
		var $_ifIP;
77 1fa2f630 Erik Kristensen
		var $_dnsWildcard;
78
		var $_dnsMX;
79
		var $_dnsBackMX;
80 9b8dc821 Scott Ullrich
		var $_dnsServer;
81
		var $_dnsPort;
82
		var $_dnsUpdateURL;
83 1fa2f630 Erik Kristensen
		var $status;
84
		var $_debugID;
85 67ee1ec5 Ermal Luçi
		var $_if;
86 9b8dc821 Scott Ullrich
		
87 1fa2f630 Erik Kristensen
		/* 
88
		 * Public Constructor Function (added 12 July 05) [beta]
89
		 *   - Gets the dice rolling for the update. 
90
		 */
91 9b8dc821 Scott Ullrich
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
92 21d41faa Ermal Lu?i
				    $dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
93 9bca2575 Ermal Luçi
				    $dnsServer = '', $dnsPort = '', $dnsUpdateURL = '') {
94 9b8dc821 Scott Ullrich
			
95 23e69ae8 Ermal Lu?i
			global $config, $g;
96 9b8dc821 Scott Ullrich
			
97 1ae5c631 Ermal
			$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . ".cache";
98
			$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . ".debug";
99 67ee1ec5 Ermal Luçi
100 1331005d Scott Ullrich
			log_error("DynDns: updatedns() starting");
101 9b8dc821 Scott Ullrich
			
102 1fa2f630 Erik Kristensen
			if (!$dnsService) $this->_error(2);
103 ce6d1106 jim-p
			switch ($dnsService) {
104
			case 'freedns':
105
				if (!$dnsHost) $this->_error(5);
106
				break;
107
			case 'namecheap':
108 9b8dc821 Scott Ullrich
				if (!$dnsPass) $this->_error(4);
109
				if (!$dnsHost) $this->_error(5);
110 ce6d1106 jim-p
				break;
111
			default:
112
				if (!$dnsUser) $this->_error(3);
113
				if (!$dnsPass) $this->_error(4);
114 99295d7b Scott Ullrich
				if (!$dnsHost) $this->_error(5);
115 9b8dc821 Scott Ullrich
			}
116
			
117 1fa2f630 Erik Kristensen
			$this->_dnsService = strtolower($dnsService);
118
			$this->_dnsUser = $dnsUser;
119
			$this->_dnsPass = $dnsPass;
120
			$this->_dnsHost = $dnsHost;
121 9b8dc821 Scott Ullrich
			$this->_dnsServer = $dnsServer;
122
			$this->_dnsPort = $dnsPort;
123
			$this->_dnsWildcard = $dnsWildcard;
124
			$this->_dnsMX = $dnsMX;
125 31b61005 Ermal Luçi
			$this->_if = get_real_interface($dnsIf);
126 d2cf5c39 Ermal Lu?i
			$this->_ifIP = get_interface_ip($dnsIf);
127 07a3b40b sullrich
128
			// Ensure that we where able to lookup the IP
129 52e5285f Ermal
			if(!is_ipaddr($this->_ifIP)) {
130 a17027a6 Ermal
				log_error("There was an error trying to determine the IP for interface - {$dnsIf}({$this->_if}). Probably interface has no ip or is down. Dyndns update not possible for {$dnsService}.");
131
				return;
132
			}
133 07a3b40b sullrich
134 1fa2f630 Erik Kristensen
			$this->_debugID = rand(1000000, 9999999);
135 9b8dc821 Scott Ullrich
			
136 eb346556 Ermal Lu?i
			if ($this->_detectChange() == false) {
137 1fa2f630 Erik Kristensen
				$this->_error(10);
138
			} else {
139 9d96a475 Ermal Lu?i
				switch ($this->_dnsService) {
140
				case 'dnsomatic':
141
				case 'dyndns':
142
				case 'dyndns-static':
143
				case 'dyndns-custom':
144
				case 'dhs':
145
				case 'noip':
146
				case 'easydns':
147
				case 'hn':
148
				case 'zoneedit':
149
				case 'dyns':
150
				case 'ods':
151
				case 'freedns':
152
				case 'loopia':
153
				case 'staticcling':
154
				case 'dnsexit':
155
				case 'opendns':
156 61c30081 jim-p
				case 'namecheap':
157 8ea77433 Chris Wells
				case 'he-net':
158 9d96a475 Ermal Lu?i
					$this->_update();	
159
					break;
160
				default:
161 1fa2f630 Erik Kristensen
					$this->_error(6);
162 9d96a475 Ermal Lu?i
					break;
163 1fa2f630 Erik Kristensen
				}
164 9d96a475 Ermal Lu?i
			}
165 1fa2f630 Erik Kristensen
		}
166 9b8dc821 Scott Ullrich
			
167 1fa2f630 Erik Kristensen
		/*
168
		 * Private Function (added 12 July 05) [beta]
169
		 *   Send Update To Selected Service.
170
		 */
171
		function _update() {
172 1331005d Scott Ullrich
		
173
			log_error("DynDns: DynDns _update() starting.");
174
		
175 1fa2f630 Erik Kristensen
			if ($this->_dnsService != 'ods') {
176
				$ch = curl_init();
177
				curl_setopt($ch, CURLOPT_HEADER, 0);
178
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
179
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
180 d2cf5c39 Ermal Lu?i
				curl_setopt($ch, CURLOPT_INTERFACE, $this->_ifIP);
181 83ae8103 Ermal
				curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Completely empirical
182 1fa2f630 Erik Kristensen
			}
183
184
			switch ($this->_dnsService) {
185
				case 'dyndns':
186
				case 'dyndns-static':
187 52e95286 Ermal
				case 'dyndns-custom':
188 1fa2f630 Erik Kristensen
					$needsIP = FALSE;
189 52e95286 Ermal
					//log_error("DynDns: DynDns _update() starting. Dynamic");
190 9b8dc821 Scott Ullrich
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
191 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
192
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
193 9b8dc821 Scott Ullrich
					$server = "https://members.dyndns.org/nic/update";
194
					$port = "";
195
					if($this->_dnsServer)
196
						$server = $this->_dnsServer;
197
					if($this->_dnsPort)
198
						$port = ":" . $this->_dnsPort;
199 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');
200 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
201 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
202 1fa2f630 Erik Kristensen
					curl_close($ch);
203
					$this->_checkStatus($data);
204
					break;
205
				case 'dhs':
206
					$needsIP = TRUE;
207 a255e1f7 Scott Ullrich
					$post_data['hostscmd'] = 'edit';
208
					$post_data['hostscmdstage'] = '2';
209
					$post_data['type'] = '4';
210
					$post_data['updatetype'] = 'Online';
211
					$post_data['mx'] = $this->_dnsMX;
212
					$post_data['mx2'] = '';
213
					$post_data['txt'] = '';
214
					$post_data['offline_url'] = '';
215
					$post_data['cloak'] = 'Y';
216
					$post_data['cloak_title'] = '';
217
					$post_data['ip'] = $this->_dnsIP;
218
					$post_data['domain'] = 'dyn.dhs.org';
219
					$post_data['hostname'] = $this->_dnsHost;
220
					$post_data['submit'] = 'Update';
221 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
222 9b8dc821 Scott Ullrich
					$server = "https://members.dhs.org/nic/hosts";
223
					$port = "";
224
					if($this->_dnsServer)
225
						$server = $this->_dnsServer;
226
					if($this->_dnsPort)
227
						$port = ":" . $this->_dnsPort;					
228
					curl_setopt($ch, CURLOPT_URL, '{$server}{$port}');
229 1fa2f630 Erik Kristensen
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
230
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
231
					$data = curl_exec($ch);
232 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
233 1fa2f630 Erik Kristensen
					curl_close($ch);
234
					$this->_checkStatus($data);
235
					break;
236
				case 'noip':
237
					$needsIP = TRUE;
238
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
239 c61e56a7 Scott Ullrich
					$server = "http://dynupdate.no-ip.com/ducupdate.php";
240 9b8dc821 Scott Ullrich
					$port = "";
241
					if($this->_dnsServer)
242
						$server = $this->_dnsServer;
243
					if($this->_dnsPort)
244
						$port = ":" . $this->_dnsPort;
245 fdcaa527 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&hostname=' . $this->_dnsHost.'&ip=' . $this->_dnsIP);
246 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
247 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
248 1fa2f630 Erik Kristensen
					curl_close($ch);
249
					$this->_checkStatus($data);
250
					break;
251
				case 'easydns':
252
					$needsIP = TRUE;
253
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
254
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
255 9b8dc821 Scott Ullrich
					$server = "http://members.easydns.com/dyn/dyndns.php";
256
					$port = "";
257
					if($this->_dnsServer)
258
						$server = $this->_dnsServer;
259
					if($this->_dnsPort)
260
						$port = ":" . $this->_dnsPort;
261 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);
262 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
263 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
264 1fa2f630 Erik Kristensen
					curl_close($ch);
265
					$this->_checkStatus($data);
266
					break;
267
				case 'hn':
268
					$needsIP = TRUE;
269
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
270
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
271 9b8dc821 Scott Ullrich
					$server = "http://dup.hn.org/vanity/update";
272
					$port = "";
273
					if($this->_dnsServer)
274
						$server = $this->_dnsServer;
275
					if($this->_dnsPort)
276
						$port = ":" . $this->_dnsPort;
277 cd8f5ccd Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
278 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
279 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
280 1fa2f630 Erik Kristensen
					curl_close($ch);
281
					$this->_checkStatus($data);
282
					break;
283
				case 'zoneedit':
284
					$needsIP = FALSE;
285
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
286 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
287
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
288
289 9b8dc821 Scott Ullrich
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
290
					$port = "";
291
					if($this->_dnsServer)
292
						$server = $this->_dnsServer;
293
					if($this->_dnsPort)
294
						$port = ":" . $this->_dnsPort;
295 89a75ca9 Bill Marquette
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
296
297 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
298 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
299 1fa2f630 Erik Kristensen
					curl_close($ch);
300
					$this->_checkStatus($data);
301
					break;
302
				case 'dyns':
303
					$needsIP = FALSE;
304 9b8dc821 Scott Ullrich
					$server = "http://www.dyns.cx/postscript011.php";
305
					$port = "";
306
					if($this->_dnsServer)
307
						$server = $this->_dnsServer;
308
					if($this->_dnsPort)
309
						$port = ":" . $this->_dnsPort;					
310 fdcaa527 Ermal Luçi
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
311 1fa2f630 Erik Kristensen
					$data = curl_exec($ch);
312 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
313 1fa2f630 Erik Kristensen
					curl_close($ch);
314
					$this->_checkStatus($data);
315
					break;
316
				case 'ods':
317
					$needsIP = FALSE;
318 9b8dc821 Scott Ullrich
					$misc_errno = 0;
319
					$misc_error = "";
320
					$server = "ods.org";
321
					$port = "";
322
					if($this->_dnsServer)
323
						$server = $this->_dnsServer;
324
					if($this->_dnsPort)
325
						$port = ":" . $this->_dnsPort;						
326
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
327 1fa2f630 Erik Kristensen
					/* Check that we have connected */
328
					if (!$this->con['socket']) {
329
						print "error! could not connect.";
330
						break;
331
					}
332
					/* Here is the loop. Read the incoming data (from the socket connection) */
333
					while (!feof($this->con['socket'])) {
334
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
335
						$code = substr($this->con['buffer']['all'], 0, 3);
336
						sleep(1);
337
						switch($code) {
338
							case 100:
339
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
340
								break;
341
							case 225:
342
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
343
								break;
344
							case 901:
345
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
346
								break;
347
							case 795:
348
								fputs($this->con['socket'], "QUIT\n");
349
								break;
350
						}
351
					}
352
					$this->_checkStatus($code);
353
					break;
354 9b8dc821 Scott Ullrich
				case 'freedns':
355
					$needIP = FALSE;
356 d9cc4b24 gnhb
					curl_setopt($ch, CURLOPT_URL, 'http://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
357 9b8dc821 Scott Ullrich
					$data = curl_exec($ch);
358 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
359 9b8dc821 Scott Ullrich
					curl_close($ch);
360
					$this->_checkStatus($data);
361
					break;
362 0a1b0183 Ermal Luçi
				case 'dnsexit':
363
					$needsIP = TRUE;
364 d74b5b8b sullrich
					curl_setopt($ch, CURLOPT_URL, 'http://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
365
					$data = curl_exec($ch);
366
					if (@curl_error($ch)) log_error("Curl error occurred:" . curl_error($ch));
367
					curl_close($ch);
368
					$this->_checkStatus($data);
369 0a1b0183 Ermal Luçi
					break;
370 9b8dc821 Scott Ullrich
				case 'loopia':
371
					$needsIP = TRUE;
372
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
373
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
374 99295d7b Scott Ullrich
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
375 9b8dc821 Scott Ullrich
					$data = curl_exec($ch);
376 f005f8ae Chris Buechler
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
377 9b8dc821 Scott Ullrich
					curl_close($ch);
378
					$this->_checkStatus($data);
379
					break;
380 2d78b166 Ermal Luçi
				case 'opendns':
381
					$needsIP = FALSE;
382
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
383
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
384
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
385 6bccf4ca smos
					$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
386 2d78b166 Ermal Luçi
					$port = "";
387
					if($this->_dnsServer)
388
						$server = $this->_dnsServer;
389
					if($this->_dnsPort)
390
						$port = ":" . $this->_dnsPort;
391
					curl_setopt($ch, CURLOPT_URL, $server .$port);
392
					$data = curl_exec($ch);
393
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
394
					curl_close($ch);
395
					$this->_checkStatus($data);
396
					break;
397
398 d74b5b8b sullrich
				case 'staticcling':
399
					$needsIP = FALSE;
400
					curl_setopt($ch, CURLOPT_URL, 'http://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
401
					$data = curl_exec($ch);
402
					if (@curl_error($ch)) log_error("Curl error occured: " . curl_error($ch));
403
					curl_close($ch);
404
					$this->_checkStatus($data);
405
					break;	                    
406 52e6fdfd Scott Dale
				case 'dnsomatic':
407
					/* Example syntax 
408
						https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
409
					*/
410
					$needsIP = FALSE;
411
					log_error("DNS-O-Matic: DNS update() starting.");
412
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
413
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
414
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
415
					$server = "https://" . $this->_dnsUser . ":" . $this->_dnsPass . "@updates.dnsomatic.com/nic/update?hostname=";
416
					if($this->_dnsServer)
417
						$server = $this->_dnsServer;
418
					if($this->_dnsPort)
419
						$port = ":" . $this->_dnsPort;
420
					curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
421
					$data = curl_exec($ch);
422
					if (@curl_error($ch)) log_error("Request completed. DNS-O-Matic reported: " . curl_error($ch));
423
					curl_close($ch);
424
					$this->_checkStatus($data);
425
					break;
426 61c30081 jim-p
				case 'namecheap':
427
					/* Example:
428
						https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
429
					*/
430
					$needsIP = FALSE;
431
					log_error("Namecheap: DNS update() starting.");
432
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
433
					list($hostname, $domain) = explode(".", $this->_dnsHost, 2);
434
					$server = "https://dynamicdns.park-your-domain.com/update?host={$hostname}&domain={$domain}&password={$this->_dnsPass}&ip={$this->_dnsIP}";
435
					curl_setopt($ch, CURLOPT_URL, $server);
436
					$data = curl_exec($ch);
437
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
438
					curl_close($ch);
439
					$this->_checkStatus($data);
440 8ea77433 Chris Wells
					break;
441
				case 'he-net':
442
					$needsIP = FALSE;
443
					log_error("HE.net: DNS update() starting.");
444
					$server = "https://dyn.dns.he.net/nic/update?";
445
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
446
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsHost . ':' . $this->_dnsPass);
447
					curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost);
448
					$data = curl_exec($ch);
449
					if(@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
450
					curl_close($ch);
451
					$this->_checkStatus($data);
452
					break;
453 1fa2f630 Erik Kristensen
				default:
454
					break;
455
			}
456
		}
457
458
		/*
459
		 * Private Function (added 12 July 2005) [beta]
460
		 *   Retrieve Update Status
461
		 */
462
		function _checkStatus($data) {
463 1331005d Scott Ullrich
			log_error("DynDns: DynDns _checkStatus() starting.");
464 d6fcb946 Scott Ullrich
			log_error("DynDns: Current Service: {$this->_dnsService}");
465 4a6bb2ff Scott Ullrich
			$successful_update = false;
466 1fa2f630 Erik Kristensen
			switch ($this->_dnsService) {
467 52e6fdfd Scott Dale
				case 'dnsomatic':
468
					if (preg_match('/badauth/i', $data)) {
469
						$status = "DNS-O-Matic: The DNS-O-Matic username or password specified are incorrect. No updates will be distributed to services until this is resolved.";
470
					} else if (preg_match('/notfqdn /i', $data)) {
471
						$status = "DNS-O-Matic: The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.";
472
					} else if (preg_match('/nohost/i', $data)) {
473
						$status = "DNS-O-Matic: The hostname passed could not be matched to any services configured. The service field will be blank in the return code.";
474
					} else if (preg_match('/numhost/i', $data)) {
475
						$status = "DNS-O-Matic: You may update up to 20 hosts. numhost is returned if you try to update more than 20 or update a round-robin.";	
476
					} else if (preg_match('/abuse/i', $data)) {
477
						$status = "DNS-O-Matic: The hostname is blocked for update abuse.";
478
					} else if (preg_match('/good/i', $data)) {
479
						$status = "DNS-O-Matic: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
480
						$successful_update = true;
481
					} else if (preg_match('/dnserr/i', $data)) {
482
						$status = "DNS-O-Matic: DNS error encountered. Stop updating for 30 minutes.";
483
					} else {
484
						$status = "DNS-O-Matic: (Unknown Response)";
485
						log_error("DNS-O-Matic: PAYLOAD: {$data}");
486
						$this->_debug($data);
487
					}
488
					break;
489 1fa2f630 Erik Kristensen
				case 'dyndns':
490
					if (preg_match('/notfqdn/i', $data)) {
491
						$status = "phpDynDNS: (Error) Not A FQDN!";
492
					} else if (preg_match('/nochg/i', $data)) {
493
						$status = "phpDynDNS: (Success) No Change In IP Address";
494 0ede1bf7 Scott Ullrich
						$successful_update = true;
495 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
496
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
497 4a6bb2ff Scott Ullrich
						$successful_update = true;
498 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
499
						$status = "phpDynDNS: (Error) User Authorization Failed";
500
					} else {
501
						$status = "phpDynDNS: (Unknown Response)";
502 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
503 1fa2f630 Erik Kristensen
						$this->_debug($data);
504
					}
505
					break;
506
				case 'dyndns-static':
507
					if (preg_match('/notfqdn/i', $data)) {
508
						$status = "phpDynDNS: (Error) Not A FQDN!";
509
					} else if (preg_match('/nochg/i', $data)) {
510
						$status = "phpDynDNS: (Success) No Change In IP Address";
511 9b8dc821 Scott Ullrich
						$successful_update = true;
512 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
513
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
514 4a6bb2ff Scott Ullrich
						$successful_update = true;
515 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
516
						$status = "phpDynDNS: (Error) User Authorization Failed";
517
					} else {
518
						$status = "phpDynDNS: (Unknown Response)";
519 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
520 1fa2f630 Erik Kristensen
						$this->_debug($data);
521
					}
522
					break;
523
				case 'dyndns-custom':
524
					if (preg_match('/notfqdn/i', $data)) {
525
						$status = "phpDynDNS: (Error) Not A FQDN!";
526
					} else if (preg_match('/nochg/i', $data)) {
527
						$status = "phpDynDNS: (Success) No Change In IP Address";
528 9b8dc821 Scott Ullrich
						$successful_update = true;
529 1fa2f630 Erik Kristensen
					} else if (preg_match('/good/i', $data)) {
530
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
531 4a6bb2ff Scott Ullrich
						$successful_update = true;
532 1fa2f630 Erik Kristensen
					} else if (preg_match('/noauth/i', $data)) {
533
						$status = "phpDynDNS: (Error) User Authorization Failed";
534
					} else {
535
						$status = "phpDynDNS: (Unknown Response)";
536 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
537 1fa2f630 Erik Kristensen
						$this->_debug($data);
538
					}
539
					break;
540
				case 'dhs':
541
					break;
542
				case 'noip':
543
					list($ip,$code) = split(":",$data);
544
					switch ($code) {
545
						case 0:
546
							$status = "phpDynDNS: (Success) IP address is current, no update performed.";
547 4a6bb2ff Scott Ullrich
							$successful_update = true;
548 1fa2f630 Erik Kristensen
							break;
549
						case 1:
550
							$status = "phpDynDNS: (Success) DNS hostname update successful.";
551 4a6bb2ff Scott Ullrich
							$successful_update = true;
552 1fa2f630 Erik Kristensen
							break;
553
						case 2:
554
							$status = "phpDynDNS: (Error) Hostname supplied does not exist.";
555
							break;
556
						case 3:
557
							$status = "phpDynDNS: (Error) Invalid Username.";
558
							break;
559
						case 4:
560
							$status = "phpDynDNS: (Error) Invalid Password.";
561
							break;
562
						case 5:
563
							$status = "phpDynDNS: (Error) To many updates sent.";
564
							break;
565
						case 6:
566
							$status = "phpDynDNS: (Error) Account disabled due to violation of No-IP terms of service.";
567
							break;
568
						case 7:
569
							$status = "phpDynDNS: (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
570
							break;
571
						case 8:
572
							$status = "phpDynDNS: (Error) Disabled / Locked Hostname.";
573
							break;
574
						case 9:
575
							$status = "phpDynDNS: (Error) Host updated is configured as a web redirect and no update was performed.";
576
							break;
577
						case 10:
578
							$status = "phpDynDNS: (Error) Group supplied does not exist.";
579
							break;
580
						case 11:
581
							$status = "phpDynDNS: (Success) DNS group update is successful.";
582 4a6bb2ff Scott Ullrich
							$successful_update = true;
583 1fa2f630 Erik Kristensen
							break;
584
						case 12:
585
							$status = "phpDynDNS: (Success) DNS group is current, no update performed.";
586 4a6bb2ff Scott Ullrich
							$successful_update = true;
587 1fa2f630 Erik Kristensen
							break;
588
						case 13:
589
							$status = "phpDynDNS: (Error) Update client support not available for supplied hostname or group.";
590
							break;
591
						case 14:
592
							$status = "phpDynDNS: (Error) Hostname supplied does not have offline settings configured.";
593
							break;
594
						case 99:
595
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
596
							break;
597
						case 100:
598
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
599
							break;
600
						default:
601
							$status = "phpDynDNS: (Unknown Response)";
602 458d80d7 Scott Ullrich
							$this->_debug("Unknown Response: ".$data);
603 1fa2f630 Erik Kristensen
							break;
604
					}
605
					break;
606
				case 'easydns':
607
					if (preg_match('/NOACCESS/i', $data)) {
608
						$status = "phpDynDNS: (Error) Authentication Failed: Username and/or Password was Incorrect.";
609
					} else if (preg_match('/NOSERVICE/i', $data)) {
610
						$status = "phpDynDNS: (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
611
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
612
						$status = "phpDynDNS: (Error) Illegal Input: Self-Explantory";
613
					} else if (preg_match('/TOOSOON/i', $data)) {
614
						$status = "phpDynDNS: (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
615
					} else if (preg_match('/NOERROR/i', $data)) {
616 4a6bb2ff Scott Ullrich
						$status = "phpDynDNS: (Success) IP Updated Successfully!";
617
						$successful_update = true;
618 1fa2f630 Erik Kristensen
					} else {
619
						$status = "phpDynDNS: (Unknown Response)";
620 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
621 1fa2f630 Erik Kristensen
						$this->_debug($data);
622
					}
623
					break;
624
				case 'hn':
625 9b8dc821 Scott Ullrich
					/* FIXME: add checks */
626 1fa2f630 Erik Kristensen
					break;
627
				case 'zoneedit':
628 9b9e5f09 Scott Ullrich
					if (preg_match('/799/i', $data)) {
629
						$status = "phpDynDNS: (Error 799) Update Failed!";				
630 332a3e59 Scott Ullrich
					} else if (preg_match('/700/i', $data)) {
631 9b9e5f09 Scott Ullrich
						$status = "phpDynDNS: (Error 700) Update Failed!";
632
					} else if (preg_match('/200/i', $data)) {
633 1fa2f630 Erik Kristensen
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
634 4a6bb2ff Scott Ullrich
						$successful_update = true;
635 9b9e5f09 Scott Ullrich
					} else if (preg_match('/201/i', $data)) {
636
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
637
						$successful_update = true;						
638 1fa2f630 Erik Kristensen
					} else {
639
						$status = "phpDynDNS: (Unknown Response)";
640 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
641 1fa2f630 Erik Kristensen
						$this->_debug($data);
642
					}
643
					break;
644
				case 'dyns':
645
					if (preg_match("/400/i", $data)) {
646
						$status = "phpDynDNS: (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
647
					} else if (preg_match('/402/i', $data)) {
648
						$status = "phpDynDNS: (Error) Update Too Soon - You have tried updating to quickly since last change.";
649
					} else if (preg_match('/403/i', $data)) {
650
						$status = "phpDynDNS: (Error) Database Error - There was a server-sided database error.";
651
					} else if (preg_match('/405/i', $data)) {
652
						$status = "phpDynDNS: (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
653
					} else if (preg_match('/200/i', $data)) {
654
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
655 4a6bb2ff Scott Ullrich
						$successful_update = true;
656 1fa2f630 Erik Kristensen
					} else {
657
						$status = "phpDynDNS: (Unknown Response)";
658 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
659 1fa2f630 Erik Kristensen
						$this->_debug($data);
660
					}
661
					break;
662
				case 'ods':
663
					if (preg_match("/299/i", $data)) {
664
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
665 4a6bb2ff Scott Ullrich
						$successful_update = true;
666 1fa2f630 Erik Kristensen
					} else {
667
						$status = "phpDynDNS: (Unknown Response)";
668 492d334b Scott Ullrich
						log_error("phpDynDNS: PAYLOAD: {$data}");
669 1fa2f630 Erik Kristensen
						$this->_debug($data);
670
					}
671
					break;
672 9b8dc821 Scott Ullrich
				case 'freedns':
673
					if (preg_match("/has not changed./i", $data)) {
674
						$status = "phpDynDNS: (Success) No Change In IP Address";
675
						$successful_update = true;
676
					} else if (preg_match("/Updated/i", $data)) {
677
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
678
						$successful_update = true;
679
					} else {
680
						$status = "phpDynDNS: (Unknown Response)";
681
						log_error("phpDynDNS: PAYLOAD: {$data}");
682
						$this->_debug($data);
683
					} 
684
					break;
685 0a1b0183 Ermal Luçi
				case 'dnsexit':
686
					if (preg_match("/is the same/i", $data)) {
687
						$status = "phpDynDns: (Success) No Change In IP Address";
688
						$successful_update = true;
689
					} else if (preg_match("/Success/i", $data)) {
690
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
691
						$successful_update = true;
692
					} else {
693
						$status = "phpDynDNS: (Unknown Response)";
694
                                                log_error("phpDynDNS: PAYLOAD: {$data}");
695
                                                $this->_debug($data);
696
					}
697
					break;
698 9b8dc821 Scott Ullrich
				case 'loopia':
699
					if (preg_match("/nochg/i", $data)) {
700
						$status = "phpDynDNS: (Success) No Change In IP Address";
701
						$successful_update = true;
702
					} else if (preg_match("/good/i", $data)) {
703
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
704
						$successful_update = true;
705
					} else if (preg_match('/badauth/i', $data)) {
706
						$status = "phpDynDNS: (Error) User Authorization Failed";
707
					} else {
708
						$status = "phpDynDNS: (Unknown Response)";
709
						log_error("phpDynDNS: PAYLOAD: {$data}");
710
						$this->_debug($data);
711
					}
712
					break;
713 2d78b166 Ermal Luçi
				case 'opendns':
714
					if (preg_match('/badauth/i', $data)) {
715
						$status = "phpDynDNS: (Error) Not a valid username or password!";
716
					} else if (preg_match('/nohost/i', $data)) {
717
						$status = "phpDynDNS: (Error) Hostname you are trying to update does not exist.";
718
						$successful_update = true;
719
					} else if (preg_match('/good/i', $data)) {
720
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
721
						$successful_update = true;
722
					} else if (preg_match('/yours/i', $data)) {
723
						$status = "phpDynDNS: (Error) hostname specified exists, but not under the username specified.";
724
					} else if (preg_match('/abuse/i', $data)) {
725
						$status = "phpDynDns: (Error) Updating to frequently, considered abuse.";
726
					} else {
727
						$status = "phpDynDNS: (Unknown Response)";
728
						log_error("phpDynDNS: PAYLOAD: {$data}");
729
						$this->_debug($data);
730
					}
731
					break;
732 d74b5b8b sullrich
                 case 'staticcling':
733
					if (preg_match("/invalid ip/i", $data)) {
734
					        $status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
735
					} else if (preg_match('/required info missing/i', $data)) {
736
					        $status = "phpDynDNS: (Error) Bad Request - Required parameters were not provided.";
737
					} else if (preg_match('/invalid characters/i', $data)) {
738
					        $status = "phpDynDNS: (Error) Bad Request - Illegal characters in either the username or the password.";
739
					} else if (preg_match('/bad password/i', $data)) {
740
					        $status = "phpDynDNS: (Error) Invalid password.";
741
					} else if (preg_match('/account locked/i', $data)) {
742
					        $status = "phpDynDNS: (Error) This account has been administratively locked.";
743
					} else if (preg_match('/update too frequent/i', $data)) {
744
					        $status = "phpDynDNS: (Error) Updating too frequently.";
745
					} else if (preg_match('/DB error/i', $data)) {
746
					        $status = "phpDynDNS: (Error) Server side error.";
747
					} else if (preg_match('/success/i', $data)) {
748
					        $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
749
					        $successful_update = true;
750
					} else {
751
					        $status = "phpDynDNS: (Unknown Response)";
752
					        log_error("phpDynDNS: PAYLOAD: {$data}");
753
					        $this->_debug($data);
754
					}
755
					break;
756 61c30081 jim-p
				case 'namecheap':
757 18f15f68 jim-p
					$tmp = str_replace("^M", "", $data);
758
					$ncresponse = @xml2array($tmp);
759 61c30081 jim-p
					if (preg_match("/internal server error/i", $data)) {
760
						$status = "phpDynDNS: (Error) Server side error.";
761 18f15f68 jim-p
					} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
762 c305abd5 jim-p
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
763
						$successful_update = true;
764 18f15f68 jim-p
					} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
765
						$status = "phpDynDNS: (Error) " . implode(", ", $ncresponse["interface-response"]["errors"]);
766 c305abd5 jim-p
						$successful_update = true;
767 61c30081 jim-p
					} else {
768
						$status = "phpDynDNS: (Unknown Response)";
769
						log_error("phpDynDNS: PAYLOAD: {$data}");
770
						$this->_debug($data);
771
					}
772
					break;
773 8ea77433 Chris Wells
					
774
				case 'he-net':
775
					if (preg_match("/badip/i", $data)) {
776
					        $status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
777
					} else if (preg_match('/nohost/i', $data)) {
778
					        $status = "phpDynDNS: (Error) Bad Request - A hostname was not provided.";
779
					} else if (preg_match('/badauth/i', $data)) {
780
					        $status = "phpDynDNS: (Error) Invalid username or password.";
781
					} else if (preg_match('/good/i', $data)) {
782
					        $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
783
					        $successful_update = true;
784
					} else if (preg_match('/nochg/i', $data)) {
785
							$status = "phpDynDNS: (Success) No Change In IP Address.";
786
							$successful_update = true;
787
					} else {
788
					        $status = "phpDynDNS: (Unknown Response)";
789
					        log_error("phpDynDNS: PAYLOAD: {$data}");
790
					        $this->_debug($data);
791
					}
792
					break;
793 1fa2f630 Erik Kristensen
			}
794 4a6bb2ff Scott Ullrich
			
795
			if($successful_update == true) {
796
				/* Write WAN IP to cache file */
797 22de7804 Bill Marquette
				$wan_ip = $this->_checkIP();
798 dd575ea4 Ermal
				conf_mount_rw();
799
				if ($wan_ip > 0) {
800 c749ef62 Ermal
					$currentTime = time();				  
801
					log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
802 dd575ea4 Ermal
					@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
803
				} else
804
					@unlink($this->_cacheFile);
805
				conf_mount_ro();
806 4a6bb2ff Scott Ullrich
			}
807 1fa2f630 Erik Kristensen
			$this->status = $status;
808
			log_error($status);
809
		}
810
811
		/*
812
		 * Private Function (added 12 July 05) [beta]
813
		 *   Return Error, Set Last Error, and Die.
814
		 */
815
		function _error($errorNumber = '1') {
816
			switch ($errorNumber) {
817
				case 0:
818
					break;
819
				case 2:
820
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
821
					break;
822
				case 3:
823
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
824
					break;
825
				case 4:
826
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
827
					break;
828
				case 5:
829
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
830
					break;
831
				case 6:
832
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
833
					break;
834 9b8dc821 Scott Ullrich
				case 7:
835
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
836
					break;
837 1fa2f630 Erik Kristensen
				case 10:
838 b99544e8 jim-p
					$error = 'phpDynDNS: No change in my IP address and/or 25 days has not passed. Not updating dynamic DNS entry.';
839 1fa2f630 Erik Kristensen
					break;
840
				default:
841
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
842 9b8dc821 Scott Ullrich
					/* FIXME: $data isn't in scope here */
843
					/* $this->_debug($data); */
844 1fa2f630 Erik Kristensen
					break;
845
			}
846
			$this->lastError = $error;
847
			log_error($error);
848
		}
849
850
		/*
851
		 * Private Function (added 12 July 05) [beta]
852
		 *   - Detect whether or not IP needs to be updated.
853
		 *      | Written Specifically for pfSense (pfsense.com) may
854
		 *      | work with other systems. pfSense base is FreeBSD.
855
		 */
856
		function _detectChange() {
857 1331005d Scott Ullrich
			
858
			log_error("DynDns: _detectChange() starting.");
859
		
860 1fa2f630 Erik Kristensen
			$currentTime = time();
861
862 22de7804 Bill Marquette
			$wan_ip = $this->_checkIP();
863 dd575ea4 Ermal
			if ($wan_ip == 0) {
864
				log_error("DynDns: Current WAN IP could not be determined.");
865
				return true;
866
			}
867 1fa2f630 Erik Kristensen
			$this->_dnsIP = $wan_ip;
868 fc3a37e9 Scott Ullrich
			log_error("DynDns: Current WAN IP: {$wan_ip}");
869 1fa2f630 Erik Kristensen
870
			if (file_exists($this->_cacheFile)) {
871 aa7c49b9 Ermal
				$contents = file_get_contents($this->_cacheFile);
872 1fa2f630 Erik Kristensen
				list($cacheIP,$cacheTime) = split(':', $contents);
873
				$this->_debug($cacheIP.'/'.$cacheTime);
874 003fb312 Scott Ullrich
				$initial = false;
875 d6fcb946 Scott Ullrich
				log_error("DynDns: Cached IP: {$cacheIP}");
876 1fa2f630 Erik Kristensen
			} else {
877 53d366fd Scott Ullrich
				conf_mount_rw();
878 1fa2f630 Erik Kristensen
				$cacheIP = '0.0.0.0';
879 dd575ea4 Ermal
				@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
880
				conf_mount_ro();
881 1fa2f630 Erik Kristensen
				$cacheTime = $currentTime;
882 003fb312 Scott Ullrich
				$initial = true;
883 fc3a37e9 Scott Ullrich
				log_error("DynDns: No Cached IP found.");
884 1fa2f630 Erik Kristensen
			}
885
886 e24b26e9 Scott Ullrich
			/*   use 2419200 for dyndns, dhs, easydns, noip, hn
887
			 *   zoneedit, dyns, ods
888
			 */
889 a9b55504 Scott Ullrich
			$time = '2160000';
890 1fa2f630 Erik Kristensen
891 e24b26e9 Scott Ullrich
			$needs_updating = FALSE;
892 4494cf6a Chris Buechler
			/* lets determine if the item needs updating */
893 a255e1f7 Scott Ullrich
			if ($cacheIP != $wan_ip) {
894 eb346556 Ermal Lu?i
				$needs_updating = true;
895
				$update_reason = "DynDns: cacheIP != wan_ip.  Updating. ";
896
				$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
897 a255e1f7 Scott Ullrich
			}
898
			if (($currentTime - $cacheTime) > $time ) {
899 c3c3e03b Ermal
				$needs_updating = true;
900 eb346556 Ermal Lu?i
				$update_reason = "DynDns: More than 25 days.  Updating. ";
901
				$update_reason .= "{$currentTime} - {$cacheTime} > {$time} ";
902 a255e1f7 Scott Ullrich
			}
903 eb346556 Ermal Lu?i
			if ($initial == true) {
904
				$needs_updating = true;
905 a255e1f7 Scott Ullrich
				$update_reason .= "Inital update. ";
906
			}
907 eb346556 Ermal Lu?i
908 a255e1f7 Scott Ullrich
			/*   finally if we need updating then store the
909
			 *   new cache value and return true
910
                         */
911 eb346556 Ermal Lu?i
			if ($needs_updating == true) {
912
				log_error("DynDns debug information: {$update_reason}");
913
				return true;
914 1fa2f630 Erik Kristensen
			}
915 eb346556 Ermal Lu?i
916
			return false;			
917 1fa2f630 Erik Kristensen
		}
918
919
		/*
920
		 * Private Funcation (added 16 July 05) [beta]
921
		 *   - Writes debug information to a file.
922
		 *   - This function is only called when a unknown response
923
		 *   - status is returned from a DynDNS service provider.
924
		 */
925
		function _debug ($data) {
926 c3c3e03b Ermal
			$string = '\n'.date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data.'\n';
927 53d366fd Scott Ullrich
			conf_mount_rw();
928 1fa2f630 Erik Kristensen
			$file = fopen($this->_debugFile, 'a');
929
			fwrite($file, $string);
930
			fclose($file);
931 53d366fd Scott Ullrich
			conf_mount_ro();
932 1fa2f630 Erik Kristensen
		}
933 22de7804 Bill Marquette
		function _checkIP() {
934
935
			log_error("DynDns: _checkIP() starting.");
936
937 8f1b45aa Ermal Lu?i
			$ip_address = find_interface_ip($this->_if);
938 52e95286 Ermal
			$this->_ifIP = $ip_address;
939 1b665090 Ermal Lu?i
			if (is_private_ip($ip_address)) {
940
				$hosttocheck = "checkip.dyndns.org";
941 83ae8103 Ermal
				$try = 0;
942
				while ($try < 3) {
943
					$checkip = gethostbyname($hosttocheck);
944
					if (is_ipaddr($checkip))
945
						break;
946
					$try++;
947
				}
948
				if ($try >= 3) {
949
					log_error("Dyndns debug information: Could not resolve {$hosttocheck} to ip using interface ip {$ip_address}.");
950 dd575ea4 Ermal
					return 0;
951 83ae8103 Ermal
				}
952 7ae7a972 Ermal Lu?i
				$ip_ch = curl_init("http://{$checkip}");
953
				curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
954
				curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
955 8f1b45aa Ermal Lu?i
				curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
956 83ae8103 Ermal
				curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
957
				curl_setopt($ip_ch, CURLOPT_TIMEOUT, 60);
958 7ae7a972 Ermal Lu?i
				$ip_result_page = curl_exec($ip_ch);
959
				curl_close($ip_ch);
960
				$ip_result_decoded = urldecode($ip_result_page);
961 c3c3e03b Ermal
				preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
962 7ae7a972 Ermal Lu?i
				$ip_address = trim($matches[1]);
963 c749ef62 Ermal
				if (is_ipaddr($ip_address))
964
					log_error("DynDns debug information: {$ip_address} extracted from {$hosttocheck}");
965
				else {
966
					log_error("DynDns debug information: IP address could not be extracted from {$hosttocheck}");
967
					return 0;
968
				}
969 1b665090 Ermal Lu?i
			} else
970
				log_error("DynDns debug information: {$ip_address} extracted from local system.");
971 22de7804 Bill Marquette
972
			return $ip_address;
973
		}
974 1fa2f630 Erik Kristensen
975
	}
976
977 aa7c49b9 Ermal
?>