Project

General

Profile

Download (28.7 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) -- incomplete checking!
13
	 *    - DynS (dyns.org)
14
	 *    - ZoneEdit (zoneedit.com)
15
	 *    - FreeDNS (freedns.afraid.org)
16
	 *    - Loopia (loopia.se)
17
	 *    - StaticCling (staticcling.org)
18
	 * +----------------------------------------------------+
19
	 *  Requirements:
20
	 *    - PHP version 4.0.2 or higher with CURL Library
21
	 * +----------------------------------------------------+
22
	 *  Public Functions
23
	 *    - updatedns()
24
	 *
25
	 *  Private Functions
26
	 *    - _update()
27
	 *    - _checkStatus()
28
	 *    - _error()
29
	 *    - _detectChange()
30
	 *    - _debug()
31
	 * +----------------------------------------------------+
32
	 *  DynDNS Dynamic - Last Tested: 12 July 2005
33
	 *  DynDNS Static  - Last Tested: NEVER
34
	 *  DynDNS Custom  - Last Tested: NEVER
35
	 *  No-IP          - Last Tested: 12 July 2005
36
	 *  HN.org         - Last Tested: 12 July 2005
37
	 *  EasyDNS        - Last Tested: NEVER
38
	 *  DHS            - Last Tested: 12 July 2005
39
	 *  ZoneEdit       - Last Tested: NEVER
40
	 *  Dyns           - Last Tested: NEVER
41
	 *  ODS            - Last Tested: 02 August 2005
42
	 *  FreeDNS        - Last Tested: NEVER
43
	 *  Loopia         - Last Tested: NEVER
44
	 *  StaticCling    - Last Tested: 27 April 2006
45
	 * +====================================================+
46
	 *
47
	 * @author 	E.Kristensen
48
	 * @link    	http://www.idylldesigns.com/projects/phpdns/
49
	 * @version 	0.8
50
	 * @updated	13 October 05 at 21:02:42 GMT
51
	 *
52
	 */
53

    
54
	class updatedns {
55
		var $_cacheFile = '/cf/conf/dyndns.cache';
56
		var $_debugFile = '/var/etc/dyndns.debug';
57
		var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
58
		var $_errorVerbosity = 0;
59
		var $_dnsService;
60
		var $_dnsUser;
61
		var $_dnsPass;
62
		var $_dnsHost;
63
		var $_dnsIP;
64
		var $_dnsWildcard;
65
		var $_dnsMX;
66
		var $_dnsBackMX;
67
		var $_dnsWanip;
68
		var $_dnsServer;
69
		var $_dnsPort;
70
		var $_dnsUpdateURL;
71
		var $status;
72
		var $_debugID;
73
		
74
		/* 
75
		 * Public Constructor Function (added 12 July 05) [beta]
76
		 *   - Gets the dice rolling for the update. 
77
		 */
78
		function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
79
				    $dnsWildcard = 'OFF', $dnsMX = '', $dnsBackMX = '', $dnsWanip = '',
80
				    $dnsServer = '', $dnsPort = '', $dnsUpdateURL = '') {
81
			
82
			global $config;
83
			
84
			log_error("DynDns: updatedns() starting");
85
			
86
			if (!$dnsService) $this->_error(2);
87
			if (!($dnsService == 'freedns')) {
88

    
89
				/* all services except freedns use these */
90

    
91
				if (!$dnsUser) $this->_error(3);
92
				if (!$dnsPass) $this->_error(4);
93
				if (!$dnsHost) $this->_error(5);
94
			} else {
95

    
96
				/* freedns needs this */
97

    
98
				if (!$dnsHost) $this->_error(5);
99
			}
100
			
101
			$this->_dnsService = strtolower($dnsService);
102
			$this->_dnsUser = $dnsUser;
103
			$this->_dnsPass = $dnsPass;
104
			$this->_dnsHost = $dnsHost;
105
			$this->_dnsWanip = $dnsWanip;
106
			$this->_dnsServer = $dnsServer;
107
			$this->_dnsPort = $dnsPort;
108
			$this->_dnsWildcard = $dnsWildcard;
109
			$this->_dnsMX = $dnsMX;
110
			
111
			if(!$wan_ip) 
112
				$wan_ip = get_current_wan_address();
113
				
114
			$this->_dnsIP = $wan_ip;
115
			$this->_debugID = rand(1000000, 9999999);
116
			
117
			if ($this->_detectChange() == FALSE) {
118
				$this->_error(10);
119
			} else {
120
				if ($this->_dnsService == 'dyndns' ||
121
					$this->_dnsService == 'dyndns-static' ||
122
					$this->_dnsService == 'dyndns-custom' ||
123
					$this->_dnsService == 'dhs' ||
124
					$this->_dnsService == 'noip' ||
125
					$this->_dnsService == 'easydns' ||
126
					$this->_dnsService == 'hn' ||
127
					$this->_dnsService == 'zoneedit' ||
128
					$this->_dnsService == 'dyns' ||
129
					$this->_dnsService == 'ods' ||
130
					$this->_dnsService == 'freedns' ||
131
					$this->_dnsService == 'loopia' ||
132
					$this->_dnsService == 'staticcling')
133
				{
134
					$this->_update();
135
				} else {
136
					$this->_error(6);
137
				}
138
			}					
139
		}
140
			
141
		/*
142
		 * Private Function (added 12 July 05) [beta]
143
		 *   Send Update To Selected Service.
144
		 */
145
		function _update() {
146
		
147
			log_error("DynDns: DynDns _update() starting.");
148
		
149
			if ($this->_dnsService != 'ods') {
150
				$ch = curl_init();
151
				curl_setopt($ch, CURLOPT_HEADER, 0);
152
				curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
153
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
154
			}
155

    
156
			switch ($this->_dnsService) {
157
				case 'dyndns':
158
					$needsIP = FALSE;
159
					log_error("DynDns: DynDns _update() starting. Dynamic");
160
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
161
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
162
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
163
					$server = "https://members.dyndns.org/nic/update";
164
					$port = "";
165
					if($this->_dnsServer)
166
						$server = $this->_dnsServer;
167
					if($this->_dnsPort)
168
						$port = ":" . $this->_dnsPort;
169
					curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP.'&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
170
					$data = curl_exec($ch);
171
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
172
					curl_close($ch);
173
					$this->_checkStatus($data);
174
					break;
175
				case 'dyndns-static':
176
					$needsIP = FALSE;
177
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
178
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
179
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
180
					$server = "https://members.dyndns.org/nic/update";
181
					$port = "";
182
					if($this->_dnsServer)
183
						$server = $this->_dnsServer;
184
					if($this->_dnsPort)
185
						$port = ":" . $this->_dnsPort;
186
					curl_setopt($ch, CURLOPT_URL, $server.$port.'?system=statdns&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
187
					$data = curl_exec($ch);
188
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
189
					curl_close($ch);
190
					$this->_checkStatus($data);
191
					break;
192
				case 'dyndns-custom':
193
					$needsIP = FALSE;
194
					if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
195
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
196
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
197
					$server = "https://members.dyndns.org/nic/update";
198
					$port = "";
199
					if($this->_dnsServer)
200
						$server = $this->_dnsServer;
201
					if($this->_dnsPort)
202
						$port = ":" . $this->_dnsPort;					
203
					curl_setopt($ch, CURLOPT_URL, $server.$port.'?system=custom&hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP.'&wildcard='.$this->_dnsWildcard.'&mx='.$this->_dnsMX.'&backmx=NO');
204
					$data = curl_exec($ch);
205
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
206
					curl_close($ch);
207
					$this->_checkStatus($data);
208
					break;
209
				case 'dhs':
210
					$needsIP = TRUE;
211
					$post_data['hostscmd'] = 'edit';
212
					$post_data['hostscmdstage'] = '2';
213
					$post_data['type'] = '4';
214
					$post_data['updatetype'] = 'Online';
215
					$post_data['mx'] = $this->_dnsMX;
216
					$post_data['mx2'] = '';
217
					$post_data['txt'] = '';
218
					$post_data['offline_url'] = '';
219
					$post_data['cloak'] = 'Y';
220
					$post_data['cloak_title'] = '';
221
					$post_data['ip'] = $this->_dnsIP;
222
					$post_data['domain'] = 'dyn.dhs.org';
223
					$post_data['hostname'] = $this->_dnsHost;
224
					$post_data['submit'] = 'Update';
225
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
226
					$server = "https://members.dhs.org/nic/hosts";
227
					$port = "";
228
					if($this->_dnsServer)
229
						$server = $this->_dnsServer;
230
					if($this->_dnsPort)
231
						$port = ":" . $this->_dnsPort;					
232
					curl_setopt($ch, CURLOPT_URL, '{$server}{$port}');
233
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
234
					curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
235
					$data = curl_exec($ch);
236
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
237
					curl_close($ch);
238
					$this->_checkStatus($data);
239
					break;
240
				case 'noip':
241
					$needsIP = TRUE;
242
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
243
					$server = "http://dynupdate.no-ip.com/ducupdate.php";
244
					$port = "";
245
					if($this->_dnsServer)
246
						$server = $this->_dnsServer;
247
					if($this->_dnsPort)
248
						$port = ":" . $this->_dnsPort;
249
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . $this->_dnsUser . '&pass=' . $this->_dnsPass . '&hostname=' . $this->_dnsHost.'&ip=' . $this->_dnsIP);
250
					$data = curl_exec($ch);
251
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
252
					curl_close($ch);
253
					$this->_checkStatus($data);
254
					break;
255
				case 'easydns':
256
					$needsIP = TRUE;
257
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
258
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
259
					$server = "http://members.easydns.com/dyn/dyndns.php";
260
					$port = "";
261
					if($this->_dnsServer)
262
						$server = $this->_dnsServer;
263
					if($this->_dnsPort)
264
						$port = ":" . $this->_dnsPort;
265
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
266
					$data = curl_exec($ch);
267
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
268
					curl_close($ch);
269
					$this->_checkStatus($data);
270
					break;
271
				case 'hn':
272
					$needsIP = TRUE;
273
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
274
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
275
					$server = "http://dup.hn.org/vanity/update";
276
					$port = "";
277
					if($this->_dnsServer)
278
						$server = $this->_dnsServer;
279
					if($this->_dnsPort)
280
						$port = ":" . $this->_dnsPort;
281
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
282
					$data = curl_exec($ch);
283
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
284
					curl_close($ch);
285
					$this->_checkStatus($data);
286
					break;
287
				case 'zoneedit':
288
					$needsIP = FALSE;
289
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
290
					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
291
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
292

    
293
					$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
294
					$port = "";
295
					if($this->_dnsServer)
296
						$server = $this->_dnsServer;
297
					if($this->_dnsPort)
298
						$port = ":" . $this->_dnsPort;
299
					curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
300

    
301
					$data = curl_exec($ch);
302
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
303
					curl_close($ch);
304
					$this->_checkStatus($data);
305
					break;
306
				case 'dyns':
307
					$needsIP = FALSE;
308
					$server = "http://www.dyns.cx/postscript011.php";
309
					$port = "";
310
					if($this->_dnsServer)
311
						$server = $this->_dnsServer;
312
					if($this->_dnsPort)
313
						$port = ":" . $this->_dnsPort;					
314
					curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . $this->_dnsUser . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
315
					$data = curl_exec($ch);
316
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
317
					curl_close($ch);
318
					$this->_checkStatus($data);
319
					break;
320
				case 'ods':
321
					$needsIP = FALSE;
322
					$misc_errno = 0;
323
					$misc_error = "";
324
					$server = "ods.org";
325
					$port = "";
326
					if($this->_dnsServer)
327
						$server = $this->_dnsServer;
328
					if($this->_dnsPort)
329
						$port = ":" . $this->_dnsPort;						
330
					$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
331
					/* Check that we have connected */
332
					if (!$this->con['socket']) {
333
						print "error! could not connect.";
334
						break;
335
					}
336
					/* Here is the loop. Read the incoming data (from the socket connection) */
337
					while (!feof($this->con['socket'])) {
338
						$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
339
						$code = substr($this->con['buffer']['all'], 0, 3);
340
						sleep(1);
341
						switch($code) {
342
							case 100:
343
								fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
344
								break;
345
							case 225:
346
								fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
347
								break;
348
							case 901:
349
								fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
350
								break;
351
							case 795:
352
								fputs($this->con['socket'], "QUIT\n");
353
								break;
354
						}
355
					}
356
					$this->_checkStatus($code);
357
					break;
358
				case 'freedns':
359
					$needIP = FALSE;
360
					curl_setopt($ch, CURLOPT_URL, 'http://freedns.afraid.org/dynamic/update.php?'.$this->_dnsHost);
361
					$data = curl_exec($ch);
362
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
363
					curl_close($ch);
364
					$this->_checkStatus($data);
365
					break;
366
				case 'loopia':
367
					$needsIP = TRUE;
368
					curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
369
					curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
370
					curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
371
					$data = curl_exec($ch);
372
					if (@curl_error($ch)) log_error("Curl error occurred: " . curl_error($ch));
373
					curl_close($ch);
374
					$this->_checkStatus($data);
375
					break;
376
                                case 'staticcling':
377
                                        $needsIP = FALSE;
378
                                        curl_setopt($ch, CURLOPT_URL, 'http://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
379
                                        $data = curl_exec($ch);
380
                                        if (@curl_error($ch)) log_error("Curl error occured: " . curl_error($ch));
381
                                        curl_close($ch);
382
                                        $this->_checkStatus($data);
383
                                        break;
384
				default:
385
					break;
386
			}
387
		}
388

    
389
		/*
390
		 * Private Function (added 12 July 2005) [beta]
391
		 *   Retrieve Update Status
392
		 */
393
		function _checkStatus($data) {
394
			log_error("DynDns: DynDns _checkStatus() starting.");
395
			log_error("DynDns: Current Service: {$this->_dnsService}");
396
			$successful_update = false;
397
			switch ($this->_dnsService) {
398
				case 'dyndns':
399
					if (preg_match('/notfqdn/i', $data)) {
400
						$status = "phpDynDNS: (Error) Not A FQDN!";
401
					} else if (preg_match('/nochg/i', $data)) {
402
						$status = "phpDynDNS: (Success) No Change In IP Address";
403
						$successful_update = true;
404
					} else if (preg_match('/good/i', $data)) {
405
						$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
406
						$successful_update = true;
407
					} else if (preg_match('/noauth/i', $data)) {
408
						$status = "phpDynDNS: (Error) User Authorization Failed";
409
					} else {
410
						$status = "phpDynDNS: (Unknown Response)";
411
						log_error("phpDynDNS: PAYLOAD: {$data}");
412
						$this->_debug($data);
413
					}
414
					break;
415
				case 'dyndns-static':
416
					if (preg_match('/notfqdn/i', $data)) {
417
						$status = "phpDynDNS: (Error) Not A FQDN!";
418
					} else if (preg_match('/nochg/i', $data)) {
419
						$status = "phpDynDNS: (Success) No Change In IP Address";
420
						$successful_update = true;
421
					} else if (preg_match('/good/i', $data)) {
422
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
423
						$successful_update = true;
424
					} else if (preg_match('/noauth/i', $data)) {
425
						$status = "phpDynDNS: (Error) User Authorization Failed";
426
					} else {
427
						$status = "phpDynDNS: (Unknown Response)";
428
						log_error("phpDynDNS: PAYLOAD: {$data}");
429
						$this->_debug($data);
430
					}
431
					break;
432
				case 'dyndns-custom':
433
					if (preg_match('/notfqdn/i', $data)) {
434
						$status = "phpDynDNS: (Error) Not A FQDN!";
435
					} else if (preg_match('/nochg/i', $data)) {
436
						$status = "phpDynDNS: (Success) No Change In IP Address";
437
						$successful_update = true;
438
					} else if (preg_match('/good/i', $data)) {
439
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
440
						$successful_update = true;
441
					} else if (preg_match('/noauth/i', $data)) {
442
						$status = "phpDynDNS: (Error) User Authorization Failed";
443
					} else {
444
						$status = "phpDynDNS: (Unknown Response)";
445
						log_error("phpDynDNS: PAYLOAD: {$data}");
446
						$this->_debug($data);
447
					}
448
					break;
449
				case 'dhs':
450
					break;
451
				case 'noip':
452
					list($ip,$code) = split(":",$data);
453
					switch ($code) {
454
						case 0:
455
							$status = "phpDynDNS: (Success) IP address is current, no update performed.";
456
							$successful_update = true;
457
							break;
458
						case 1:
459
							$status = "phpDynDNS: (Success) DNS hostname update successful.";
460
							$successful_update = true;
461
							break;
462
						case 2:
463
							$status = "phpDynDNS: (Error) Hostname supplied does not exist.";
464
							break;
465
						case 3:
466
							$status = "phpDynDNS: (Error) Invalid Username.";
467
							break;
468
						case 4:
469
							$status = "phpDynDNS: (Error) Invalid Password.";
470
							break;
471
						case 5:
472
							$status = "phpDynDNS: (Error) To many updates sent.";
473
							break;
474
						case 6:
475
							$status = "phpDynDNS: (Error) Account disabled due to violation of No-IP terms of service.";
476
							break;
477
						case 7:
478
							$status = "phpDynDNS: (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
479
							break;
480
						case 8:
481
							$status = "phpDynDNS: (Error) Disabled / Locked Hostname.";
482
							break;
483
						case 9:
484
							$status = "phpDynDNS: (Error) Host updated is configured as a web redirect and no update was performed.";
485
							break;
486
						case 10:
487
							$status = "phpDynDNS: (Error) Group supplied does not exist.";
488
							break;
489
						case 11:
490
							$status = "phpDynDNS: (Success) DNS group update is successful.";
491
							$successful_update = true;
492
							break;
493
						case 12:
494
							$status = "phpDynDNS: (Success) DNS group is current, no update performed.";
495
							$successful_update = true;
496
							break;
497
						case 13:
498
							$status = "phpDynDNS: (Error) Update client support not available for supplied hostname or group.";
499
							break;
500
						case 14:
501
							$status = "phpDynDNS: (Error) Hostname supplied does not have offline settings configured.";
502
							break;
503
						case 99:
504
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
505
							break;
506
						case 100:
507
							$status = "phpDynDNS: (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
508
							break;
509
						default:
510
							$status = "phpDynDNS: (Unknown Response)";
511
							$this->_debug("Unknown Response: ".$data);
512
							break;
513
					}
514
					break;
515
				case 'easydns':
516
					if (preg_match('/NOACCESS/i', $data)) {
517
						$status = "phpDynDNS: (Error) Authentication Failed: Username and/or Password was Incorrect.";
518
					} else if (preg_match('/NOSERVICE/i', $data)) {
519
						$status = "phpDynDNS: (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
520
					} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
521
						$status = "phpDynDNS: (Error) Illegal Input: Self-Explantory";
522
					} else if (preg_match('/TOOSOON/i', $data)) {
523
						$status = "phpDynDNS: (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
524
					} else if (preg_match('/NOERROR/i', $data)) {
525
						$status = "phpDynDNS: (Success) IP Updated Successfully!";
526
						$successful_update = true;
527
					} else {
528
						$status = "phpDynDNS: (Unknown Response)";
529
						log_error("phpDynDNS: PAYLOAD: {$data}");
530
						$this->_debug($data);
531
					}
532
					break;
533
				case 'hn':
534
					/* FIXME: add checks */
535
					break;
536
				case 'zoneedit':
537
					if (preg_match('/799/i', $data)) {
538
						$status = "phpDynDNS: (Error 799) Update Failed!";				
539
					} else if (preg_match('/700/i', $data)) {
540
						$status = "phpDynDNS: (Error 700) Update Failed!";
541
					} else if (preg_match('/200/i', $data)) {
542
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
543
						$successful_update = true;
544
					} else if (preg_match('/201/i', $data)) {
545
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
546
						$successful_update = true;						
547
					} else {
548
						$status = "phpDynDNS: (Unknown Response)";
549
						log_error("phpDynDNS: PAYLOAD: {$data}");
550
						$this->_debug($data);
551
					}
552
					break;
553
				case 'dyns':
554
					if (preg_match("/400/i", $data)) {
555
						$status = "phpDynDNS: (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
556
					} else if (preg_match('/402/i', $data)) {
557
						$status = "phpDynDNS: (Error) Update Too Soon - You have tried updating to quickly since last change.";
558
					} else if (preg_match('/403/i', $data)) {
559
						$status = "phpDynDNS: (Error) Database Error - There was a server-sided database error.";
560
					} else if (preg_match('/405/i', $data)) {
561
						$status = "phpDynDNS: (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
562
					} else if (preg_match('/200/i', $data)) {
563
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
564
						$successful_update = true;
565
					} else {
566
						$status = "phpDynDNS: (Unknown Response)";
567
						log_error("phpDynDNS: PAYLOAD: {$data}");
568
						$this->_debug($data);
569
					}
570
					break;
571
				case 'ods':
572
					if (preg_match("/299/i", $data)) {
573
						$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
574
						$successful_update = true;
575
					} else {
576
						$status = "phpDynDNS: (Unknown Response)";
577
						log_error("phpDynDNS: PAYLOAD: {$data}");
578
						$this->_debug($data);
579
					}
580
					break;
581
				case 'freedns':
582
					if (preg_match("/has not changed./i", $data)) {
583
						$status = "phpDynDNS: (Success) No Change In IP Address";
584
						$successful_update = true;
585
					} else if (preg_match("/Updated/i", $data)) {
586
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
587
						$successful_update = true;
588
					} else {
589
						$status = "phpDynDNS: (Unknown Response)";
590
						log_error("phpDynDNS: PAYLOAD: {$data}");
591
						$this->_debug($data);
592
					} 
593
					break;
594
				case 'loopia':
595
					if (preg_match("/nochg/i", $data)) {
596
						$status = "phpDynDNS: (Success) No Change In IP Address";
597
						$successful_update = true;
598
					} else if (preg_match("/good/i", $data)) {
599
						$status = "phpDynDNS: (Success) IP Address Changed Successfully!";
600
						$successful_update = true;
601
					} else if (preg_match('/badauth/i', $data)) {
602
						$status = "phpDynDNS: (Error) User Authorization Failed";
603
					} else {
604
						$status = "phpDynDNS: (Unknown Response)";
605
						log_error("phpDynDNS: PAYLOAD: {$data}");
606
						$this->_debug($data);
607
					}
608
					break;
609
                                case 'staticcling':
610
                                        if (preg_match("/invalid ip/i", $data)) {
611
                                                $status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
612
                                        } else if (preg_match('/required info missing/i', $data)) {
613
                                                $status = "phpDynDNS: (Error) Bad Request - Required parameters were not provided.";
614
                                        } else if (preg_match('/invalid characters/i', $data)) {
615
                                                $status = "phpDynDNS: (Error) Bad Request - Illegal characters in either the username or the password.";
616
                                        } else if (preg_match('/bad password/i', $data)) {
617
                                                $status = "phpDynDNS: (Error) Invalid password.";
618
                                        } else if (preg_match('/account locked/i', $data)) {
619
                                                $status = "phpDynDNS: (Error) This account has been administratively locked.";
620
                                        } else if (preg_match('/update too frequent/i', $data)) {
621
                                                $status = "phpDynDNS: (Error) Updating too frequently.";
622
                                        } else if (preg_match('/DB error/i', $data)) {
623
                                                $status = "phpDynDNS: (Error) Server side error.";
624
                                        } else if (preg_match('/success/i', $data)) {
625
                                                $status = "phpDynDNS: (Success) IP Address Updated Successfully!";
626
                                                $successful_update = true;
627
                                        } else {
628
                                                $status = "phpDynDNS: (Unknown Response)";
629
                                                log_error("phpDynDNS: PAYLOAD: {$data}");
630
                                                $this->_debug($data);
631
                                        }
632
                                        break;
633
			}
634
			
635
			if($successful_update == true) {
636
				/* Write WAN IP to cache file */
637
				$wan_ip = get_current_wan_address();
638
				$currentTime = time();				  
639
				log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
640
				conf_mount_rw();
641
				$file = fopen($this->_cacheFile, 'w');
642
				fwrite($file, $wan_ip.':'.$currentTime);
643
				fclose($file);
644
				conf_mount_ro();
645
			}
646
			$this->status = $status;
647
			log_error($status);
648
		}
649

    
650
		/*
651
		 * Private Function (added 12 July 05) [beta]
652
		 *   Return Error, Set Last Error, and Die.
653
		 */
654
		function _error($errorNumber = '1') {
655
			switch ($errorNumber) {
656
				case 0:
657
					break;
658
				case 2:
659
					$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
660
					break;
661
				case 3:
662
					$error = 'phpDynDNS: (ERROR!) No Username Provided.';
663
					break;
664
				case 4:
665
					$error = 'phpDynDNS: (ERROR!) No Password Provided.';
666
					break;
667
				case 5:
668
					$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
669
					break;
670
				case 6:
671
					$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
672
					break;
673
				case 7:
674
					$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
675
					break;
676
				case 10:
677
					$error = 'phpDynDNS: No Change In My IP Address and/or 25 Days Has Not Past. Not Updating Dynamic DNS Entry.';
678
					break;
679
				default:
680
					$error = "phpDynDNS: (ERROR!) Unknown Response.";
681
					/* FIXME: $data isn't in scope here */
682
					/* $this->_debug($data); */
683
					break;
684
			}
685
			$this->lastError = $error;
686
			log_error($error);
687
		}
688

    
689
		/*
690
		 * Private Function (added 12 July 05) [beta]
691
		 *   - Detect whether or not IP needs to be updated.
692
		 *      | Written Specifically for pfSense (pfsense.com) may
693
		 *      | work with other systems. pfSense base is FreeBSD.
694
		 */
695
		function _detectChange() {
696
			
697
			log_error("DynDns: _detectChange() starting.");
698
		
699
			$currentTime = time();
700

    
701
			$wan_ip = get_current_wan_address();
702
			$this->_dnsIP = $wan_ip;
703
			log_error("DynDns: Current WAN IP: {$wan_ip}");
704

    
705
			if (file_exists($this->_cacheFile)) {
706
				if(file_exists($this->_cacheFile))
707
					$contents = file_get_contents($this->_cacheFile);
708
				else
709
					$contents = "";
710
				list($cacheIP,$cacheTime) = split(':', $contents);
711
				$this->_debug($cacheIP.'/'.$cacheTime);
712
				$initial = false;
713
				log_error("DynDns: Cached IP: {$cacheIP}");
714
			} else {
715
				conf_mount_rw();
716
				$file = fopen($this->_cacheFile, 'w');
717
				fwrite($file, '0.0.0.0:'.$currentTime);
718
				fclose($file);
719
				conf_mount_ro();
720
				$cacheIP = '0.0.0.0';
721
				$cacheTime = $currentTime;
722
				$initial = true;
723
				log_error("DynDns: No Cached IP found.");
724
			}
725

    
726
			/*   use 2419200 for dyndns, dhs, easydns, noip, hn
727
			 *   zoneedit, dyns, ods
728
			 */
729
			$time = '2160000';
730

    
731
			$needs_updating = FALSE;
732
			/* lets deterimine if the item needs updating */
733
			if ($cacheIP != $wan_ip) {
734
				$needs_updating = TRUE;
735
				log_error("DynDns: cacheIP != wan_ip.  Updating.");
736
			}
737
			$update_reason = "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
738
			if (($currentTime - $cacheTime) > $time ) {
739
				$needs_updating = TRUE;
740
				log_error("DynDns: More than 25 days.  Updating.");
741
			}
742
			$update_reason .= "{$currentTime} - {$cacheTime} > {$time} ";
743
			if ($initial == TRUE) {
744
				$needs_updating = TRUE;
745
				$update_reason .= "Inital update. ";
746
				log_error("DynDns: Initial run.   Updating.");
747
			}
748
			/*   finally if we need updating then store the
749
			 *   new cache value and return true
750
                         */
751
			if($needs_updating == TRUE) {
752
				return TRUE;
753
			} else {
754
				return FALSE;			
755
			}
756
			
757
			log_error("DynDns debug information: {$update_reason}");
758
			
759
		}
760

    
761
		/*
762
		 * Private Funcation (added 16 July 05) [beta]
763
		 *   - Writes debug information to a file.
764
		 *   - This function is only called when a unknown response
765
		 *   - status is returned from a DynDNS service provider.
766
		 */
767
		function _debug ($data) {
768
			$string = date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data.'\n';
769
			conf_mount_rw();
770
			$file = fopen($this->_debugFile, 'a');
771
			fwrite($file, $string);
772
			fclose($file);
773
			conf_mount_ro();
774
		}
775

    
776
	}
777

    
778
?>
(6-6/27)