Project

General

Profile

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