Project

General

Profile

Download (20.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
	/*
3
	 * PHP.updateDNS (pfSense version)
4
	 *
5
	 * +====================================================+
6
	 *  Services Supported:
7
	 *    - DynDns (dyndns.org) [dynamic, static, custom)
8
	 *    - DHSDns (dhs.org)
9
	 *    - No-IP (no-ip.com)
10
	 *    - EasyDNS (easydns.com)
11
	 *    - DHS (www.dhs.org)
12
	 *    - HN (hn.org)
13
	 *    - DynS (dyns.org)
14
	 *    - ZoneEdit (zoneedit.com)
15
	 * +----------------------------------------------------+
16
	 *  Requirements:
17
	 *    - PHP version 4.0.2 or higher with CURL Library
18
	 * +----------------------------------------------------+
19
	 *  Public Functions
20
	 *    - updatedns()
21
	 *
22
	 *  Private Functions
23
	 *    - _update()
24
	 *    - _checkStatus()
25
	 *    - _error()
26
	 *    - _detectChange()
27
	 *    - _debug()
28
	 * +----------------------------------------------------+
29
	 *  DynDNS Dynamic - Last Tested: 12 July 2005
30
	 *  DynDNS Static  - Last Tested: NEVER
31
	 *  DynDNS Custom  - Last Tested: NEVER
32
	 *  No-IP          - Last Tested: 12 July 2005
33
	 *  HN.org         - Last Tested: 12 July 2005
34
	 *  EasyDNS        - Last Tested: NEVER
35
	 *  DHS            - Last Tested: 12 July 2005
36
	 *  ZoneEdit       - Last Tested: NEVER
37
	 *  Dyns           - Last Tested: NEVER
38
	 *  ODS            - Last Tested: 02 August 2005
39
	 * +====================================================+
40
	 *
41
	 * @author 	E.Kristensen
42
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
43
	 * @version 	0.8
44
	 * @updated	13 October 05 at 21:02:42 GMT
45
	 *
46
	 */
47

    
48
	class updatedns {
49
		var $_cacheFile = '/cf/conf/dyndns.cache';
50
		var $_debugFile = '/var/etc/dyndns.debug';
51
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
52
		var $_errorVerbosity = 0;
53
		var $_dnsService;
54
		var $_dnsUser;
55
		var $_dnsPass;
56
		var $_dnsHost;
57
		var $_dnsIP;
58
		var $_dnsWildcard;
59
		var $_dnsMX;
60
		var $_dnsBackMX;
61
		var $status;
62
		var $_debugID;
63

    
64
		/* 
65
		 * Public Constructor Function (added 12 July 05) [beta]
66
		 *   - Gets the dice rolling for the update. 
67
		 */
68
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '', $dnsWildcard = 'OFF', $dnsMX = '', $dnsBackMX = '') {
69
			global $config;
70

    
71
			log_error("DynDns: updatedns() starting");
72

    
73
			if (!$dnsService) $this->_error(2);
74
			if (!$dnsUser) $this->_error(3);
75
			if (!$dnsPass) $this->_error(4);
76
			if (!$dnsHost) $this->_error(5);
77

    
78
			$this->_dnsService = strtolower($dnsService);
79
			$this->_dnsUser = $dnsUser;
80
			$this->_dnsPass = $dnsPass;
81
			$this->_dnsHost = $dnsHost;
82
			$this->_dnsIP = $dnsIP;
83
			$this->_debugID = rand(1000000, 9999999);
84

    
85
			if ($this->_detectChange() == FALSE) {
86
				$this->_error(10);
87
			} else {
88
				if ($this->_dnsService == 'dyndns' ||
89
					$this->_dnsService == 'dyndns-static' ||
90
					$this->_dnsService == 'dyndns-custom' ||
91
					$this->_dnsService == 'dhs' ||
92
					$this->_dnsService == 'noip' ||
93
					$this->_dnsService == 'easydns' ||
94
					$this->_dnsService == 'hn' ||
95
					$this->_dnsService == 'zoneedit' ||
96
					$this->_dnsService == 'dyns' ||
97
					$this->_dnsService == 'ods')
98
				{
99
					$this->_update();
100
				} else {
101
					$this->_error(6);
102
				}
103
			}
104

    
105
		}
106

    
107
		/*
108
		 * Private Function (added 12 July 05) [beta]
109
		 *   Send Update To Selected Service.
110
		 */
111
		function _update() {
112
		
113
			log_error("DynDns: DynDns _update() starting.");
114
		
115
			if ($this->_dnsService != 'ods') {
116
				$ch = curl_init();
117
				curl_setopt($ch, CURLOPT_HEADER, 0);
118
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
119
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
120
			}
121

    
122
			switch ($this->_dnsService) {
123
				case 'dyndns':
124
					$needsIP = FALSE;
125
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
126
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
127
					curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
128
					$data = curl_exec($ch);
129
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
130
					curl_close($ch);
131
					$this->_checkStatus($data);
132
					break;
133
				case 'dyndns-static':
134
					$needsIP = FALSE;
135
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
136
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
137
					curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=statdns&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
138
					$data = curl_exec($ch);
139
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
140
					curl_close($ch);
141
					$this->_checkStatus($data);
142
					break;
143
				case 'dyndns-custom':
144
					$needsIP = FALSE;
145
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
146
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
147
					curl_setopt($ch, CURLOPT_URL, 'https://members.dyndns.org/nic/update?system=custom&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
148
					$data = curl_exec($ch);
149
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
150
					curl_close($ch);
151
					$this->_checkStatus($data);
152
					break;
153
				case 'dhs':
154
					$needsIP = TRUE;
155
					$post_data['hostscmd'] = 'edit';
156
					$post_data['hostscmdstage'] = '2';
157
					$post_data['type'] = '4';
158
					$post_data['updatetype'] = 'Online';
159
					$post_data['mx'] = $this->_dnsMX;
160
					$post_data['mx2'] = '';
161
					$post_data['txt'] = '';
162
					$post_data['offline_url'] = '';
163
					$post_data['cloak'] = 'Y';
164
					$post_data['cloak_title'] = '';
165
					$post_data['ip'] = $this->_dnsIP;
166
					$post_data['domain'] = 'dyn.dhs.org';
167
					$post_data['hostname'] = $this->_dnsHost;
168
					$post_data['submit'] = 'Update';
169
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
170
					curl_setopt($ch, CURLOPT_URL, 'https://members.dhs.org/nic/hosts');
171
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
172
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
173
					$data = curl_exec($ch);
174
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
175
					curl_close($ch);
176
					$this->_checkStatus($data);
177
					break;
178
				case 'noip':
179
					$needsIP = TRUE;
180
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
181
					curl_setopt($ch, CURLOPT_URL, 'http://dynupdate.no-ip.com/dns?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&hostname='.$this->_dnsHost.'&ip='.$this->_dnsIP);
182
					$data = curl_exec($ch);
183
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
184
					curl_close($ch);
185
					$this->_checkStatus($data);
186
					break;
187
				case 'easydns':
188
					$needsIP = TRUE;
189
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
190
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
191
					curl_setopt($ch, CURLOPT_URL, 'http://members.easydns.com/dyn/dyndns.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx='.$this->_dnsBackMX);
192
					$data = curl_exec($ch);
193
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
194
					curl_close($ch);
195
					$this->_checkStatus($data);
196
					break;
197
				case 'hn':
198
					$needsIP = TRUE;
199
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
200
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
201
					curl_setopt($ch, CURLOPT_URL, 'http://dup.hn.org/vanity/update?ver=1&IP='.$this->_dnsIP);
202
					$data = curl_exec($ch);
203
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
204
					curl_close($ch);
205
					$this->_checkStatus($data);
206
					break;
207
				case 'zoneedit':
208
					$needsIP = FALSE;
209
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
210
					curl_setopt($ch, CURLOPT_URL, 'https://dynamic.zoneedit.com/auth/dynamic.html?host='.$this->_dnsHost.'&dnsto='.$this->_dnsIP);
211
					$data = curl_exec($ch);
212
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
213
					curl_close($ch);
214
					$this->_checkStatus($data);
215
					break;
216
				case 'dyns':
217
					$needsIP = FALSE;
218
					curl_setopt($ch, CURLOPT_URL, 'http://www.dyns.cx/postscript011.php?username='.$this->_dnsUser.'&password='.$this->_dnsPass.'&host='.$this->_dnsHost);
219
					$data = curl_exec($ch);
220
					if (@curl_error($ch)) log_error("Curl errror occured: " . curl_error($ch));
221
					curl_close($ch);
222
					$this->_checkStatus($data);
223
					break;
224
				case 'ods':
225
					$needsIP = FALSE;
226
					$this->con['socket'] = fsockopen("ods.org", "7070", $misc_errno, $misc_error, 30);
227
					/* Check that we have connected */
228
					if (!$this->con['socket']) {
229
						print "error! could not connect.";
230
						break;
231
					}
232
					/* Here is the loop. Read the incoming data (from the socket connection) */
233
					while (!feof($this->con['socket'])) {
234
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
235
						$code = substr($this->con['buffer']['all'], 0, 3);
236
						sleep(1);
237
						switch($code) {
238
							case 100:
239
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
240
								break;
241
							case 225:
242
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
243
								break;
244
							case 901:
245
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
246
								break;
247
							case 795:
248
								fputs($this->con['socket'], "QUIT\n");
249
								break;
250
						}
251
					}
252
					$this->_checkStatus($code);
253
					break;
254
				default:
255
					break;
256
			}
257
		}
258

    
259
		/*
260
		 * Private Function (added 12 July 2005) [beta]
261
		 *   Retrieve Update Status
262
		 */
263
		function _checkStatus($data) {
264
			log_error("DynDns: DynDns _checkStatus() starting.");
265
			log_error("DynDns: Current Service: {$this->_dnsService}");
266
			$successful_update = false;
267
			switch ($this->_dnsService) {
268
				case 'dyndns':
269
					if (preg_match('/notfqdn/i', $data)) {
270
						$status = "phpDynDNS: (Error) Not A FQDN!";
271
					} else if (preg_match('/nochg/i', $data)) {
272
						$status = "phpDynDNS: (Success) No Change In IP Address";
273
						$successful_update = true;
274
					} else if (preg_match('/good/i', $data)) {
275
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
276
						$successful_update = true;
277
					} else if (preg_match('/noauth/i', $data)) {
278
						$status = "phpDynDNS: (Error) User Authorization Failed";
279
					} else {
280
						$status = "phpDynDNS: (Unknown Response)";
281
						log_error("phpDynDNS: PAYLOAD: {$data}");
282
						$this->_debug($data);
283
					}
284
					break;
285
				case 'dyndns-static':
286
					if (preg_match('/notfqdn/i', $data)) {
287
						$status = "phpDynDNS: (Error) Not A FQDN!";
288
					} else if (preg_match('/nochg/i', $data)) {
289
						$status = "phpDynDNS: (Success) No Change In IP Address";
290
					} else if (preg_match('/good/i', $data)) {
291
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
292
						$successful_update = true;
293
					} else if (preg_match('/noauth/i', $data)) {
294
						$status = "phpDynDNS: (Error) User Authorization Failed";
295
					} else {
296
						$status = "phpDynDNS: (Unknown Response)";
297
						log_error("phpDynDNS: PAYLOAD: {$data}");
298
						$this->_debug($data);
299
					}
300
					break;
301
				case 'dyndns-custom':
302
					if (preg_match('/notfqdn/i', $data)) {
303
						$status = "phpDynDNS: (Error) Not A FQDN!";
304
					} else if (preg_match('/nochg/i', $data)) {
305
						$status = "phpDynDNS: (Success) No Change In IP Address";
306
					} else if (preg_match('/good/i', $data)) {
307
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
308
						$successful_update = true;
309
					} else if (preg_match('/noauth/i', $data)) {
310
						$status = "phpDynDNS: (Error) User Authorization Failed";
311
					} else {
312
						$status = "phpDynDNS: (Unknown Response)";
313
						log_error("phpDynDNS: PAYLOAD: {$data}");
314
						$this->_debug($data);
315
					}
316
					break;
317
				case 'dhs':
318
					break;
319
				case 'noip':
320
					list($ip,$code) = split(":",$data);
321
					switch ($code) {
322
						case 0:
323
							$status = "phpDynDNS: (Success) IP address is current, no update performed.";
324
							$successful_update = true;
325
							break;
326
						case 1:
327
							$status = "phpDynDNS: (Success) DNS hostname update successful.";
328
							$successful_update = true;
329
							break;
330
						case 2:
331
							$status = "phpDynDNS: (Error) Hostname supplied does not exist.";
332
							break;
333
						case 3:
334
							$status = "phpDynDNS: (Error) Invalid Username.";
335
							break;
336
						case 4:
337
							$status = "phpDynDNS: (Error) Invalid Password.";
338
							break;
339
						case 5:
340
							$status = "phpDynDNS: (Error) To many updates sent.";
341
							break;
342
						case 6:
343
							$status = "phpDynDNS: (Error) Account disabled due to violation of No-IP terms of service.";
344
							break;
345
						case 7:
346
							$status = "phpDynDNS: (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
347
							break;
348
						case 8:
349
							$status = "phpDynDNS: (Error) Disabled / Locked Hostname.";
350
							break;
351
						case 9:
352
							$status = "phpDynDNS: (Error) Host updated is configured as a web redirect and no update was performed.";
353
							break;
354
						case 10:
355
							$status = "phpDynDNS: (Error) Group supplied does not exist.";
356
							break;
357
						case 11:
358
							$status = "phpDynDNS: (Success) DNS group update is successful.";
359
							$successful_update = true;
360
							break;
361
						case 12:
362
							$status = "phpDynDNS: (Success) DNS group is current, no update performed.";
363
							$successful_update = true;
364
							break;
365
						case 13:
366
							$status = "phpDynDNS: (Error) Update client support not available for supplied hostname or group.";
367
							break;
368
						case 14:
369
							$status = "phpDynDNS: (Error) Hostname supplied does not have offline settings configured.";
370
							break;
371
						case 99:
372
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
373
							break;
374
						case 100:
375
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
376
							break;
377
						default:
378
							$status = "phpDynDNS: (Unknown Response)";
379
							$this->_debug("Unknown Response: ".$data);
380
							break;
381
					}
382
					break;
383
				case 'easydns':
384
					if (preg_match('/NOACCESS/i', $data)) {
385
						$status = "phpDynDNS: (Error) Authentication Failed: Username and/or Password was Incorrect.";
386
					} else if (preg_match('/NOSERVICE/i', $data)) {
387
						$status = "phpDynDNS: (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
388
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
389
						$status = "phpDynDNS: (Error) Illegal Input: Self-Explantory";
390
					} else if (preg_match('/TOOSOON/i', $data)) {
391
						$status = "phpDynDNS: (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
392
					} else if (preg_match('/NOERROR/i', $data)) {
393
						$status = "phpDynDNS: (Success) IP Updated Successfully!";
394
						$successful_update = true;
395
					} else {
396
						$status = "phpDynDNS: (Unknown Response)";
397
						log_error("phpDynDNS: PAYLOAD: {$data}");
398
						$this->_debug($data);
399
					}
400
					break;
401
				case 'hn':
402
					break;
403
				case 'zoneedit':
404
					if (preg_match('/799/i', $data)) {
405
						$status = "phpDynDNS: (Error 799) Update Failed!";				
406
					} else if (preg_match('/700/i', $data)) {
407
						$status = "phpDynDNS: (Error 700) Update Failed!";
408
					} else if (preg_match('/200/i', $data)) {
409
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
410
						$successful_update = true;
411
					} else if (preg_match('/201/i', $data)) {
412
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
413
						$successful_update = true;						
414
					} else {
415
						$status = "phpDynDNS: (Unknown Response)";
416
						log_error("phpDynDNS: PAYLOAD: {$data}");
417
						$this->_debug($data);
418
					}
419
					break;
420
				case 'dyns':
421
					if (preg_match("/400/i", $data)) {
422
						$status = "phpDynDNS: (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
423
					} else if (preg_match('/402/i', $data)) {
424
						$status = "phpDynDNS: (Error) Update Too Soon - You have tried updating to quickly since last change.";
425
					} else if (preg_match('/403/i', $data)) {
426
						$status = "phpDynDNS: (Error) Database Error - There was a server-sided database error.";
427
					} else if (preg_match('/405/i', $data)) {
428
						$status = "phpDynDNS: (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
429
					} else if (preg_match('/200/i', $data)) {
430
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
431
						$successful_update = true;
432
					} else {
433
						$status = "phpDynDNS: (Unknown Response)";
434
						log_error("phpDynDNS: PAYLOAD: {$data}");
435
						$this->_debug($data);
436
					}
437
					break;
438
				case 'ods':
439
					if (preg_match("/299/i", $data)) {
440
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
441
						$successful_update = true;
442
					} else {
443
						$status = "phpDynDNS: (Unknown Response)";
444
						log_error("phpDynDNS: PAYLOAD: {$data}");
445
						$this->_debug($data);
446
					}
447
					break;
448
			}
449
			
450
			if($successful_update == true) {
451
				/* Write WAN IP to cache file */
452
				$wan_ip = get_current_wan_address();
453
				$currentTime = time();				  
454
				log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
455
				conf_mount_rw();
456
				$file = fopen($this->_cacheFile, 'w');
457
				fwrite($file, $wan_ip.':'.$currentTime);
458
				fclose($file);
459
				conf_mount_ro();
460
			}
461
			$this->status = $status;
462
			log_error($status);
463
		}
464

    
465
		/*
466
		 * Private Function (added 12 July 05) [beta]
467
		 *   Return Error, Set Last Error, and Die.
468
		 */
469
		function _error($errorNumber = '1') {
470
			switch ($errorNumber) {
471
				case 0:
472
					break;
473
				case 2:
474
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
475
					break;
476
				case 3:
477
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
478
					break;
479
				case 4:
480
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
481
					break;
482
				case 5:
483
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
484
					break;
485
				case 6:
486
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
487
					break;
488
				case 10:
489
					$error = 'phpDynDNS: No Change In My IP Address and/or 25 Days Has Not Past. Not Updating Dynamic DNS Entry.';
490
					break;
491
				default:
492
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
493
					$this->_debug($data);
494
					break;
495
			}
496
			$this->lastError = $error;
497
			log_error($error);
498
		}
499

    
500
		/*
501
		 * Private Function (added 12 July 05) [beta]
502
		 *   - Detect whether or not IP needs to be updated.
503
		 *      | Written Specifically for pfSense (pfsense.com) may
504
		 *      | work with other systems. pfSense base is FreeBSD.
505
		 */
506
		function _detectChange() {
507
			
508
			log_error("DynDns: _detectChange() starting.");
509
		
510
			$currentTime = time();
511

    
512
			$wan_ip = get_current_wan_address();
513
			$this->_dnsIP = $wan_ip;
514
			log_error("DynDns: Current WAN IP: {$wan_ip}");
515

    
516
			if (file_exists($this->_cacheFile)) {
517
				if(file_exists($this->_cacheFile))
518
					$contents = file_get_contents($this->_cacheFile);
519
				else
520
					$contents = "";
521
				list($cacheIP,$cacheTime) = split(':', $contents);
522
				$this->_debug($cacheIP.'/'.$cacheTime);
523
				$initial = false;
524
				log_error("DynDns: Cached IP: {$cacheIP}");
525
			} else {
526
				conf_mount_rw();
527
				$file = fopen($this->_cacheFile, 'w');
528
				fwrite($file, '0.0.0.0:'.$currentTime);
529
				fclose($file);
530
				conf_mount_ro();
531
				$cacheIP = '0.0.0.0';
532
				$cacheTime = $currentTime;
533
				$initial = true;
534
				log_error("DynDns: No Cached IP found.");
535
			}
536

    
537
			/*   use 2419200 for dyndns, dhs, easydns, noip, hn
538
			 *   zoneedit, dyns, ods
539
			 */
540
			$time = '2160000';
541

    
542
			$needs_updating = FALSE;
543
			/* lets deterimine if the item needs updating */
544
			if ($cacheIP != $wan_ip) {
545
				$needs_updating = TRUE;
546
				log_error("DynDns: cacheIP != wan_ip.  Updating.");
547
			}
548
			$update_reason = "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
549
			if (($currentTime - $cacheTime) > $time ) {
550
				$needs_updating = TRUE;
551
				log_error("DynDns: More than 25 days.  Updating.");
552
			}
553
			$update_reason .= "{$currentTime} - {$cacheTime} > {$time} ";
554
			if ($initial == TRUE) {
555
				$needs_updating = TRUE;
556
				$update_reason .= "Inital update. ";
557
				log_error("DynDns: Initial run.   Updating.");
558
			}
559
			/*   finally if we need updating then store the
560
			 *   new cache value and return true
561
                         */
562
			if($needs_updating == TRUE) {
563
				return TRUE;
564
			} else {
565
				return FALSE;			
566
			}
567
			
568
			log_error("DynDns debug information: {$update_reason}");
569
			
570
		}
571

    
572
		/*
573
		 * Private Funcation (added 16 July 05) [beta]
574
		 *   - Writes debug information to a file.
575
		 *   - This function is only called when a unknown response
576
		 *   - status is returned from a DynDNS service provider.
577
		 */
578
		function _debug ($data) {
579
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data.'\n';
580
			conf_mount_rw();
581
			$file = fopen($this->_debugFile, 'a');
582
			fwrite($file, $string);
583
			fclose($file);
584
			conf_mount_ro();
585
		}
586

    
587
	}
588

    
589
?>
(6-6/27)