Project

General

Profile

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