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
|
* - DNSexit (dnsexit.com)
|
19
|
* - OpenDNS (opendns.com)
|
20
|
* - Namecheap (namecheap.com)
|
21
|
* - HE.net (dns.he.net)
|
22
|
* - HE.net Tunnelbroker IP update (ipv4.tunnelbroker.net)
|
23
|
* - SelfHost (selfhost.de)
|
24
|
* - Amazon Route 53 (aws.amazon.com)
|
25
|
* - DNS-O-Matic (dnsomatic.com)
|
26
|
* - Custom DDNS (any URL)
|
27
|
* +----------------------------------------------------+
|
28
|
* Requirements:
|
29
|
* - PHP version 4.0.2 or higher with the CURL Library and the PCRE Library
|
30
|
* +----------------------------------------------------+
|
31
|
* Public Functions
|
32
|
* - updatedns()
|
33
|
*
|
34
|
* Private Functions
|
35
|
* - _update()
|
36
|
* - _checkStatus()
|
37
|
* - _error()
|
38
|
* - _detectChange()
|
39
|
* - _debug()
|
40
|
* - _checkIP()
|
41
|
* +----------------------------------------------------+
|
42
|
* DynDNS Dynamic - Last Tested: 12 July 2005
|
43
|
* DynDNS Static - Last Tested: NEVER
|
44
|
* DynDNS Custom - Last Tested: NEVER
|
45
|
* No-IP - Last Tested: 20 July 2008
|
46
|
* HN.org - Last Tested: 12 July 2005
|
47
|
* EasyDNS - Last Tested: 20 July 2008
|
48
|
* DHS - Last Tested: 12 July 2005
|
49
|
* ZoneEdit - Last Tested: NEVER
|
50
|
* Dyns - Last Tested: NEVER
|
51
|
* ODS - Last Tested: 02 August 2005
|
52
|
* FreeDNS - Last Tested: 23 Feb 2011
|
53
|
* Loopia - Last Tested: NEVER
|
54
|
* StaticCling - Last Tested: 27 April 2006
|
55
|
* DNSexit - Last Tested: 20 July 2008
|
56
|
* OpenDNS - Last Tested: 4 August 2008
|
57
|
* Namecheap - Last Tested: 31 August 2010
|
58
|
* HE.net - Last Tested: NEVER
|
59
|
* HE.net Tunnel - Last Tested: 28 June 2011
|
60
|
* SelfHost - Last Tested: 26 December 2011
|
61
|
* Amazon Route 53 - Last tested: 01 April 2012
|
62
|
* DNS-O-Matic - Last Tested: 9 September 2010
|
63
|
* +====================================================+
|
64
|
*
|
65
|
* @author E.Kristensen
|
66
|
* @link http://www.idylldesigns.com/projects/phpdns/
|
67
|
* @version 0.8
|
68
|
* @updated 13 October 05 at 21:02:42 GMT
|
69
|
*
|
70
|
* DNSexit/OpenDNS support and multiwan extension for pfSense by Ermal Luci
|
71
|
* Custom DNS support by Matt Corallo
|
72
|
*
|
73
|
*/
|
74
|
|
75
|
class updatedns {
|
76
|
var $_cacheFile;
|
77
|
var $_debugFile;
|
78
|
var $_UserAgent = 'User-Agent: phpDynDNS/0.7';
|
79
|
var $_errorVerbosity = 0;
|
80
|
var $_dnsService;
|
81
|
var $_dnsUser;
|
82
|
var $_dnsPass;
|
83
|
var $_dnsHost;
|
84
|
var $_dnsIP;
|
85
|
var $_dnsWildcard;
|
86
|
var $_dnsMX;
|
87
|
var $_dnsBackMX;
|
88
|
var $_dnsServer;
|
89
|
var $_dnsPort;
|
90
|
var $_dnsUpdateURL;
|
91
|
var $_dnsZoneID;
|
92
|
var $_dnsTTL;
|
93
|
var $status;
|
94
|
var $_debugID;
|
95
|
var $_if;
|
96
|
var $_dnsResultMatch;
|
97
|
var $_dnsRequestIf;
|
98
|
var $_dnsRequestIfIP;
|
99
|
|
100
|
/*
|
101
|
* Public Constructor Function (added 12 July 05) [beta]
|
102
|
* - Gets the dice rolling for the update.
|
103
|
* - $dnsResultMatch should only be used with $dnsService = 'custom'
|
104
|
* - $dnsResultMatch is parsed for '%IP%', which is the IP the provider was updated to,
|
105
|
* - it is otherwise expected to be exactly identical to what is returned by the Provider.
|
106
|
* - $dnsUser, and $dnsPass indicate HTTP Auth for custom DNS, if they are needed in the URL (GET Variables), include them in $dnsUpdateURL.
|
107
|
* - $For custom requests, $dnsUpdateURL is parsed for '%IP%', which is replaced with the new IP.
|
108
|
*/
|
109
|
function updatedns ($dnsService = '', $dnsHost = '', $dnsUser = '', $dnsPass = '',
|
110
|
$dnsWildcard = 'OFF', $dnsMX = '', $dnsIf = '', $dnsBackMX = '',
|
111
|
$dnsServer = '', $dnsPort = '', $dnsUpdateURL = '', $forceUpdate = false,
|
112
|
$dnsZoneID ='', $dnsTTL='', $dnsResultMatch = '', $dnsRequestIf = '',
|
113
|
$dnsID = '') {
|
114
|
|
115
|
global $config, $g;
|
116
|
|
117
|
$this->_cacheFile = "{$g['conf_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.cache";
|
118
|
$this->_debugFile = "{$g['varetc_path']}/dyndns_{$dnsIf}{$dnsService}" . escapeshellarg($dnsHost) . "{$dnsID}.debug";
|
119
|
|
120
|
log_error("DynDns: updatedns() starting");
|
121
|
|
122
|
$dyndnslck = lock("DDNS".$dnsID, LOCK_EX);
|
123
|
|
124
|
if (!$dnsService) $this->_error(2);
|
125
|
switch ($dnsService) {
|
126
|
case 'freedns':
|
127
|
if (!$dnsHost) $this->_error(5);
|
128
|
break;
|
129
|
case 'namecheap':
|
130
|
if (!$dnsPass) $this->_error(4);
|
131
|
if (!$dnsHost) $this->_error(5);
|
132
|
break;
|
133
|
case 'route53':
|
134
|
if (!$dnsZoneID) $this->_error(8);
|
135
|
if (!$dnsTTL) $this->_error(9);
|
136
|
break;
|
137
|
case 'custom':
|
138
|
if (!$dnsUpdateURL) $this->_error(7);
|
139
|
break;
|
140
|
default:
|
141
|
if (!$dnsUser) $this->_error(3);
|
142
|
if (!$dnsPass) $this->_error(4);
|
143
|
if (!$dnsHost) $this->_error(5);
|
144
|
}
|
145
|
|
146
|
$this->_dnsService = strtolower($dnsService);
|
147
|
$this->_dnsUser = $dnsUser;
|
148
|
$this->_dnsPass = $dnsPass;
|
149
|
$this->_dnsHost = $dnsHost;
|
150
|
$this->_dnsServer = $dnsServer;
|
151
|
$this->_dnsPort = $dnsPort;
|
152
|
$this->_dnsWildcard = $dnsWildcard;
|
153
|
$this->_dnsMX = $dnsMX;
|
154
|
$this->_dnsZoneID = $dnsZoneID;
|
155
|
$this->_dnsTTL = $dnsTTL;
|
156
|
$this->_if = get_failover_interface($dnsIf);
|
157
|
$this->_checkIP();
|
158
|
$this->_dnsUpdateURL = $dnsUpdateURL;
|
159
|
$this->_dnsResultMatch = $dnsResultMatch;
|
160
|
$this->_dnsRequestIf = get_failover_interface($dnsRequestIf);
|
161
|
log_error("DynDNS ({$this->_dnsHost}): running get_failover_interface for {$dnsRequestIf}. found {$this->_dnsRequestIf}");
|
162
|
$this->_dnsRequestIfIP = get_interface_ip($dnsRequestIf);
|
163
|
|
164
|
// Ensure that we where able to lookup the IP
|
165
|
if(!is_ipaddr($this->_dnsIP)) {
|
166
|
log_error("DynDNS ({$this->_dnsHost}) There was an error trying to determine the public IP for interface - {$dnsIf}({$this->_if}). Probably interface is not a WAN interface.");
|
167
|
unlock($dyndnslck);
|
168
|
return;
|
169
|
}
|
170
|
|
171
|
$this->_debugID = rand(1000000, 9999999);
|
172
|
|
173
|
if ($forceUpdate == false && $this->_detectChange() == false) {
|
174
|
$this->_error(10);
|
175
|
} else {
|
176
|
switch ($this->_dnsService) {
|
177
|
case 'dnsomatic':
|
178
|
case 'dyndns':
|
179
|
case 'dyndns-static':
|
180
|
case 'dyndns-custom':
|
181
|
case 'dhs':
|
182
|
case 'noip':
|
183
|
case 'easydns':
|
184
|
case 'hn':
|
185
|
case 'zoneedit':
|
186
|
case 'dyns':
|
187
|
case 'ods':
|
188
|
case 'freedns':
|
189
|
case 'loopia':
|
190
|
case 'staticcling':
|
191
|
case 'dnsexit':
|
192
|
case 'custom':
|
193
|
case 'opendns':
|
194
|
case 'namecheap':
|
195
|
case 'he-net':
|
196
|
case 'selfhost':
|
197
|
case 'he-net-tunnelbroker':
|
198
|
case 'route53':
|
199
|
$this->_update();
|
200
|
break;
|
201
|
default:
|
202
|
$this->_error(6);
|
203
|
break;
|
204
|
}
|
205
|
}
|
206
|
|
207
|
unlock($dyndnslck);
|
208
|
}
|
209
|
|
210
|
/*
|
211
|
* Private Function (added 12 July 05) [beta]
|
212
|
* Send Update To Selected Service.
|
213
|
*/
|
214
|
function _update() {
|
215
|
|
216
|
log_error("DynDNS ({$this->_dnsHost}): DynDns _update() starting.");
|
217
|
|
218
|
if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53 ') {
|
219
|
$ch = curl_init();
|
220
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
221
|
curl_setopt($ch, CURLOPT_USERAGENT, $this->_UserAgent);
|
222
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
223
|
curl_setopt($ch, CURLOPT_INTERFACE, $this->_dnsRequestIfIP);
|
224
|
curl_setopt($ch, CURLOPT_TIMEOUT, 120); // Completely empirical
|
225
|
}
|
226
|
|
227
|
switch ($this->_dnsService) {
|
228
|
case 'dyndns':
|
229
|
case 'dyndns-static':
|
230
|
case 'dyndns-custom':
|
231
|
$needsIP = FALSE;
|
232
|
//log_error("DynDNS ({$this->_dnsHost}) DynDns _update() starting. Dynamic");
|
233
|
if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
|
234
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
235
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
236
|
$server = "https://members.dyndns.org/nic/update";
|
237
|
$port = "";
|
238
|
if($this->_dnsServer)
|
239
|
$server = $this->_dnsServer;
|
240
|
if($this->_dnsPort)
|
241
|
$port = ":" . $this->_dnsPort;
|
242
|
curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
|
243
|
break;
|
244
|
case 'dhs':
|
245
|
$needsIP = TRUE;
|
246
|
$post_data['hostscmd'] = 'edit';
|
247
|
$post_data['hostscmdstage'] = '2';
|
248
|
$post_data['type'] = '4';
|
249
|
$post_data['updatetype'] = 'Online';
|
250
|
$post_data['mx'] = $this->_dnsMX;
|
251
|
$post_data['mx2'] = '';
|
252
|
$post_data['txt'] = '';
|
253
|
$post_data['offline_url'] = '';
|
254
|
$post_data['cloak'] = 'Y';
|
255
|
$post_data['cloak_title'] = '';
|
256
|
$post_data['ip'] = $this->_dnsIP;
|
257
|
$post_data['domain'] = 'dyn.dhs.org';
|
258
|
$post_data['hostname'] = $this->_dnsHost;
|
259
|
$post_data['submit'] = 'Update';
|
260
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
261
|
$server = "https://members.dhs.org/nic/hosts";
|
262
|
$port = "";
|
263
|
if($this->_dnsServer)
|
264
|
$server = $this->_dnsServer;
|
265
|
if($this->_dnsPort)
|
266
|
$port = ":" . $this->_dnsPort;
|
267
|
curl_setopt($ch, CURLOPT_URL, '{$server}{$port}');
|
268
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
269
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
270
|
break;
|
271
|
case 'noip':
|
272
|
$needsIP = TRUE;
|
273
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
274
|
$server = "http://dynupdate.no-ip.com/ducupdate.php";
|
275
|
$port = "";
|
276
|
if($this->_dnsServer)
|
277
|
$server = $this->_dnsServer;
|
278
|
if($this->_dnsPort)
|
279
|
$port = ":" . $this->_dnsPort;
|
280
|
curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&pass=' . urlencode($this->_dnsPass) . '&hostname=' . $this->_dnsHost.'&ip=' . $this->_dnsIP);
|
281
|
break;
|
282
|
case 'easydns':
|
283
|
$needsIP = TRUE;
|
284
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
285
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
286
|
$server = "http://members.easydns.com/dyn/dyndns.php";
|
287
|
$port = "";
|
288
|
if($this->_dnsServer)
|
289
|
$server = $this->_dnsServer;
|
290
|
if($this->_dnsPort)
|
291
|
$port = ":" . $this->_dnsPort;
|
292
|
curl_setopt($ch, CURLOPT_URL, $server . $port . '?hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard=' . $this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=' . $this->_dnsBackMX);
|
293
|
break;
|
294
|
case 'hn':
|
295
|
$needsIP = TRUE;
|
296
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
297
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
298
|
$server = "http://dup.hn.org/vanity/update";
|
299
|
$port = "";
|
300
|
if($this->_dnsServer)
|
301
|
$server = $this->_dnsServer;
|
302
|
if($this->_dnsPort)
|
303
|
$port = ":" . $this->_dnsPort;
|
304
|
curl_setopt($ch, CURLOPT_URL, $server . $port . '?ver=1&IP=' . $this->_dnsIP);
|
305
|
break;
|
306
|
case 'zoneedit':
|
307
|
$needsIP = FALSE;
|
308
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
309
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
310
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
311
|
|
312
|
$server = "https://dynamic.zoneedit.com/auth/dynamic.html";
|
313
|
$port = "";
|
314
|
if($this->_dnsServer)
|
315
|
$server = $this->_dnsServer;
|
316
|
if($this->_dnsPort)
|
317
|
$port = ":" . $this->_dnsPort;
|
318
|
curl_setopt($ch, CURLOPT_URL, "{$server}{$port}?host=" .$this->_dnsHost);
|
319
|
break;
|
320
|
case 'dyns':
|
321
|
$needsIP = FALSE;
|
322
|
$server = "http://www.dyns.cx/postscript011.php";
|
323
|
$port = "";
|
324
|
if($this->_dnsServer)
|
325
|
$server = $this->_dnsServer;
|
326
|
if($this->_dnsPort)
|
327
|
$port = ":" . $this->_dnsPort;
|
328
|
curl_setopt($ch, CURLOPT_URL, $server . $port . '?username=' . urlencode($this->_dnsUser) . '&password=' . $this->_dnsPass . '&host=' . $this->_dnsHost);
|
329
|
break;
|
330
|
case 'ods':
|
331
|
$needsIP = FALSE;
|
332
|
$misc_errno = 0;
|
333
|
$misc_error = "";
|
334
|
$server = "ods.org";
|
335
|
$port = "";
|
336
|
if($this->_dnsServer)
|
337
|
$server = $this->_dnsServer;
|
338
|
if($this->_dnsPort)
|
339
|
$port = ":" . $this->_dnsPort;
|
340
|
$this->con['socket'] = fsockopen("{$server}{$port}", "7070", $misc_errno, $misc_error, 30);
|
341
|
/* Check that we have connected */
|
342
|
if (!$this->con['socket']) {
|
343
|
print "error! could not connect.";
|
344
|
break;
|
345
|
}
|
346
|
/* Here is the loop. Read the incoming data (from the socket connection) */
|
347
|
while (!feof($this->con['socket'])) {
|
348
|
$this->con['buffer']['all'] = trim(fgets($this->con['socket'], 4096));
|
349
|
$code = substr($this->con['buffer']['all'], 0, 3);
|
350
|
sleep(1);
|
351
|
switch($code) {
|
352
|
case 100:
|
353
|
fputs($this->con['socket'], "LOGIN ".$this->_dnsUser." ".$this->_dnsPass."\n");
|
354
|
break;
|
355
|
case 225:
|
356
|
fputs($this->con['socket'], "DELRR ".$this->_dnsHost." A\n");
|
357
|
break;
|
358
|
case 901:
|
359
|
fputs($this->con['socket'], "ADDRR ".$this->_dnsHost." A ".$this->_dnsIP."\n");
|
360
|
break;
|
361
|
case 795:
|
362
|
fputs($this->con['socket'], "QUIT\n");
|
363
|
break;
|
364
|
}
|
365
|
}
|
366
|
$this->_checkStatus(0, $code);
|
367
|
break;
|
368
|
case 'freedns':
|
369
|
$needIP = FALSE;
|
370
|
curl_setopt($ch, CURLOPT_URL, 'http://freedns.afraid.org/dynamic/update.php?' . $this->_dnsPass);
|
371
|
break;
|
372
|
case 'dnsexit':
|
373
|
$needsIP = TRUE;
|
374
|
curl_setopt($ch, CURLOPT_URL, 'http://www.dnsexit.com/RemoteUpdate.sv?login='.$this->_dnsUser. '&password='.$this->_dnsPass.'&host='.$this->_dnsHost.'&myip='.$this->_dnsIP);
|
375
|
break;
|
376
|
case 'loopia':
|
377
|
$needsIP = TRUE;
|
378
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
379
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
380
|
curl_setopt($ch, CURLOPT_URL, 'https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname='.$this->_dnsHost.'&myip='.$this->_dnsIP);
|
381
|
break;
|
382
|
case 'opendns':
|
383
|
$needsIP = FALSE;
|
384
|
if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
|
385
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
386
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
387
|
$server = "https://updates.opendns.com/nic/update?hostname=". $this->_dnsHost;
|
388
|
$port = "";
|
389
|
if($this->_dnsServer)
|
390
|
$server = $this->_dnsServer;
|
391
|
if($this->_dnsPort)
|
392
|
$port = ":" . $this->_dnsPort;
|
393
|
curl_setopt($ch, CURLOPT_URL, $server .$port);
|
394
|
break;
|
395
|
|
396
|
case 'staticcling':
|
397
|
$needsIP = FALSE;
|
398
|
curl_setopt($ch, CURLOPT_URL, 'http://www.staticcling.org/update.html?login='.$this->_dnsUser.'&pass='.$this->_dnsPass);
|
399
|
break;
|
400
|
case 'dnsomatic':
|
401
|
/* Example syntax
|
402
|
https://username:password@updates.dnsomatic.com/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
|
403
|
*/
|
404
|
$needsIP = FALSE;
|
405
|
log_error("DNS-O-Matic: DNS update() starting.");
|
406
|
if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
|
407
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
408
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
409
|
$server = "https://" . $this->_dnsUser . ":" . $this->_dnsPass . "@updates.dnsomatic.com/nic/update?hostname=";
|
410
|
if($this->_dnsServer)
|
411
|
$server = $this->_dnsServer;
|
412
|
if($this->_dnsPort)
|
413
|
$port = ":" . $this->_dnsPort;
|
414
|
curl_setopt($ch, CURLOPT_URL, $server . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NOCHG');
|
415
|
break;
|
416
|
case 'namecheap':
|
417
|
/* Example:
|
418
|
https://dynamicdns.park-your-domain.com/update?host=[host_name]&domain=[domain.com]&password=[domain_password]&ip=[your_ip]
|
419
|
*/
|
420
|
$needsIP = FALSE;
|
421
|
log_error("Namecheap ({$this->_dnsHost}): DNS update() starting.");
|
422
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
423
|
$dparts = explode(".", trim($this->_dnsHost));
|
424
|
$domain_part_count = ($dparts[count($dparts)-1] == "uk") ? 3 : 2;
|
425
|
$domain_offset = count($dparts) - $domain_part_count;
|
426
|
$hostname = implode(".", array_slice($dparts, 0, $domain_offset));
|
427
|
$domain = implode(".", array_slice($dparts, $domain_offset));
|
428
|
$dnspass = trim($this->_dnsPass);
|
429
|
$server = "https://dynamicdns.park-your-domain.com/update?host={$hostname}&domain={$domain}&password={$dnspass}&ip={$this->_dnsIP}";
|
430
|
curl_setopt($ch, CURLOPT_URL, $server);
|
431
|
break;
|
432
|
case 'he-net':
|
433
|
$needsIP = FALSE;
|
434
|
log_error("HE.net ({$this->_dnsHost}): DNS update() starting.");
|
435
|
$server = "https://dyn.dns.he.net/nic/update?";
|
436
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
437
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsHost . ':' . $this->_dnsPass);
|
438
|
curl_setopt($ch, CURLOPT_URL, $server . 'hostname=' . $this->_dnsHost);
|
439
|
break;
|
440
|
case 'he-net-tunnelbroker':
|
441
|
$needsIP = FALSE;
|
442
|
log_error("HE.net Tunnelbroker: DNS update() starting.");
|
443
|
$server = "https://ipv4.tunnelbroker.net/ipv4_end.php?";
|
444
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
445
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser . ':' . $this->_dnsPass);
|
446
|
curl_setopt($ch, CURLOPT_URL, $server . 'tid=' . $this->_dnsHost);
|
447
|
break;
|
448
|
case 'selfhost':
|
449
|
$needsIP = FALSE;
|
450
|
//log_error("SelfHost: DNS update() starting.");
|
451
|
if (isset($this->_dnsWildcard) && $this->_dnsWildcard != "OFF") $this->_dnsWildcard = "ON";
|
452
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
453
|
curl_setopt($ch, CURLOPT_USERPWD, $this->_dnsUser.':'.$this->_dnsPass);
|
454
|
$server = "https://carol.selfhost.de/nic/update";
|
455
|
$port = "";
|
456
|
if($this->_dnsServer)
|
457
|
$server = $this->_dnsServer;
|
458
|
if($this->_dnsPort)
|
459
|
$port = ":" . $this->_dnsPort;
|
460
|
curl_setopt($ch, CURLOPT_URL, $server .$port . '?system=dyndns&hostname=' . $this->_dnsHost . '&myip=' . $this->_dnsIP . '&wildcard='.$this->_dnsWildcard . '&mx=' . $this->_dnsMX . '&backmx=NO');
|
461
|
break;
|
462
|
case 'route53':
|
463
|
log_error("Route53 ({$this->_dnsHost}): DNS update() starting.");
|
464
|
|
465
|
/* Setting Variables */
|
466
|
$hostname = "{$this->_dnsHost}.";
|
467
|
$ZoneID = $this->_dnsZoneID;
|
468
|
$AccessKeyId=$this->_dnsUser;
|
469
|
$SecretAccessKey=$this->_dnsPass;
|
470
|
$NewIP=$this->_dnsIP;
|
471
|
$NewTTL=$this->_dnsTTL;
|
472
|
|
473
|
/* Include Route 53 Library Class */
|
474
|
require_once('/etc/inc/r53.class');
|
475
|
|
476
|
/* Set Amazon AWS Credentials for this record */
|
477
|
$r53 = new Route53($AccessKeyId, $SecretAccessKey);
|
478
|
|
479
|
/* Function to find old values of records in Route 53 */
|
480
|
if(!function_exists('Searchrecords')) {
|
481
|
function SearchRecords($records, $name) {
|
482
|
$result = array();
|
483
|
foreach($records as $record) {
|
484
|
if(strtolower($record['Name']) == strtolower($name)) {
|
485
|
$result [] = $record;
|
486
|
}
|
487
|
}
|
488
|
return ($result) ? $result : false;
|
489
|
}}
|
490
|
|
491
|
$records = $r53->listResourceRecordSets("/hostedzone/$ZoneID");
|
492
|
|
493
|
/* Get IP for your hostname in Route 53 */
|
494
|
if(false !== ($a_result = SearchRecords($records['ResourceRecordSets'], "$hostname"))) {
|
495
|
$OldTTL=$a_result[0][TTL];
|
496
|
$OldIP=$a_result[0][ResourceRecords][0];
|
497
|
} else {
|
498
|
$OldIP="";
|
499
|
}
|
500
|
|
501
|
/* Check if we need update DNS Record */
|
502
|
if ($OldIP !== $NewIP) {
|
503
|
if(!empty($OldIP)) {
|
504
|
/* Your Hostname already exists, deleting and creating it again */
|
505
|
$changes = array();
|
506
|
$changes[] = $r53->prepareChange(DELETE, $hostname, A, $OldTTL, $OldIP);
|
507
|
$changes[] = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
|
508
|
$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
|
509
|
} else {
|
510
|
/* Your Hostname does not exist yet, creating it */
|
511
|
$changes = $r53->prepareChange(CREATE, $hostname, A, $NewTTL, $NewIP);
|
512
|
$result = $r53->changeResourceRecordSets("/hostedzone/$ZoneID", $changes);
|
513
|
}
|
514
|
}
|
515
|
$this->_checkStatus(0, $result);
|
516
|
break;
|
517
|
case 'custom':
|
518
|
log_error("Custom DDNS ({$this->_dnsHost}): DNS update() starting.");
|
519
|
if (strstr($this->dnsUpdateURL, "%IP%")) {$needsIP = TRUE;} else {$needsIP = FALSE;}
|
520
|
if ($this->_dnsUser != '') {
|
521
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
522
|
curl_setopt($ch, CURLOPT_USERPWD, "{$this->_dnsUser}:{$this->_dnsPass}");
|
523
|
}
|
524
|
$server = str_replace("%IP%", $this->_dnsIP, $this->_dnsUpdateURL);
|
525
|
log_error("Sending request to: ".$server);
|
526
|
curl_setopt($ch, CURLOPT_URL, $server);
|
527
|
break;
|
528
|
default:
|
529
|
break;
|
530
|
}
|
531
|
if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53') {
|
532
|
$data = curl_exec($ch);
|
533
|
$this->_checkStatus($ch, $data);
|
534
|
@curl_close($ch);
|
535
|
}
|
536
|
}
|
537
|
|
538
|
/*
|
539
|
* Private Function (added 12 July 2005) [beta]
|
540
|
* Retrieve Update Status
|
541
|
*/
|
542
|
function _checkStatus($ch, $data) {
|
543
|
log_error("DynDNS ({$this->_dnsHost}): DynDns _checkStatus() starting.");
|
544
|
log_error("DynDNS ({$this->_dnsHost}): Current Service: {$this->_dnsService}");
|
545
|
$successful_update = false;
|
546
|
if ($this->_dnsService != 'ods' and $this->_dnsService != 'route53' && @curl_error($ch)) {
|
547
|
$status = "Curl error occurred: " . curl_error($ch);
|
548
|
log_error($status);
|
549
|
$this->status = $status;
|
550
|
return;
|
551
|
}
|
552
|
switch ($this->_dnsService) {
|
553
|
case 'dnsomatic':
|
554
|
if (preg_match('/badauth/i', $data)) {
|
555
|
$status = "DNS-O-Matic ({$this->_dnsHost}): The DNS-O-Matic username or password specified are incorrect. No updates will be distributed to services until this is resolved.";
|
556
|
} else if (preg_match('/notfqdn /i', $data)) {
|
557
|
$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname specified is not a fully-qualified domain name. If no hostnames included, notfqdn will be returned once.";
|
558
|
} else if (preg_match('/nohost/i', $data)) {
|
559
|
$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname passed could not be matched to any services configured. The service field will be blank in the return code.";
|
560
|
} else if (preg_match('/numhost/i', $data)) {
|
561
|
$status = "DNS-O-Matic ({$this->_dnsHost}): You may update up to 20 hosts. numhost is returned if you try to update more than 20 or update a round-robin.";
|
562
|
} else if (preg_match('/abuse/i', $data)) {
|
563
|
$status = "DNS-O-Matic ({$this->_dnsHost}): The hostname is blocked for update abuse.";
|
564
|
} else if (preg_match('/good/i', $data)) {
|
565
|
$status = "DNS-O-Matic ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
|
566
|
$successful_update = true;
|
567
|
} else if (preg_match('/dnserr/i', $data)) {
|
568
|
$status = "DNS-O-Matic ({$this->_dnsHost}): DNS error encountered. Stop updating for 30 minutes.";
|
569
|
} else {
|
570
|
$status = "DNS-O-Matic ({$this->_dnsHost}): (Unknown Response)";
|
571
|
log_error("DNS-O-Matic ({$this->_dnsHost}): PAYLOAD: {$data}");
|
572
|
$this->_debug($data);
|
573
|
}
|
574
|
break;
|
575
|
case 'dyndns':
|
576
|
if (preg_match('/notfqdn/i', $data)) {
|
577
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
|
578
|
} else if (preg_match('/nochg/i', $data)) {
|
579
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
|
580
|
$successful_update = true;
|
581
|
} else if (preg_match('/good/i', $data)) {
|
582
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
|
583
|
$successful_update = true;
|
584
|
} else if (preg_match('/noauth/i', $data)) {
|
585
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
|
586
|
} else {
|
587
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
588
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
589
|
$this->_debug($data);
|
590
|
}
|
591
|
break;
|
592
|
case 'dyndns-static':
|
593
|
if (preg_match('/notfqdn/i', $data)) {
|
594
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
|
595
|
} else if (preg_match('/nochg/i', $data)) {
|
596
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
|
597
|
$successful_update = true;
|
598
|
} else if (preg_match('/good/i', $data)) {
|
599
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
|
600
|
$successful_update = true;
|
601
|
} else if (preg_match('/noauth/i', $data)) {
|
602
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
|
603
|
} else {
|
604
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
605
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
606
|
$this->_debug($data);
|
607
|
}
|
608
|
break;
|
609
|
case 'dyndns-custom':
|
610
|
if (preg_match('/notfqdn/i', $data)) {
|
611
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Not A FQDN!";
|
612
|
} else if (preg_match('/nochg/i', $data)) {
|
613
|
$status = "phpDynDNS: (Success) No Change In IP Address";
|
614
|
$successful_update = true;
|
615
|
} else if (preg_match('/good/i', $data)) {
|
616
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
|
617
|
$successful_update = true;
|
618
|
} else if (preg_match('/noauth/i', $data)) {
|
619
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
|
620
|
} else {
|
621
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
622
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
623
|
$this->_debug($data);
|
624
|
}
|
625
|
break;
|
626
|
case 'dhs':
|
627
|
break;
|
628
|
case 'noip':
|
629
|
list($ip,$code) = explode(":",$data);
|
630
|
switch ($code) {
|
631
|
case 0:
|
632
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP address is current, no update performed.";
|
633
|
$successful_update = true;
|
634
|
break;
|
635
|
case 1:
|
636
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS hostname update successful.";
|
637
|
$successful_update = true;
|
638
|
break;
|
639
|
case 2:
|
640
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not exist.";
|
641
|
break;
|
642
|
case 3:
|
643
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Username.";
|
644
|
break;
|
645
|
case 4:
|
646
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid Password.";
|
647
|
break;
|
648
|
case 5:
|
649
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) To many updates sent.";
|
650
|
break;
|
651
|
case 6:
|
652
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Account disabled due to violation of No-IP terms of service.";
|
653
|
break;
|
654
|
case 7:
|
655
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid IP. IP Address submitted is improperly formatted or is a private IP address or is on a blacklist.";
|
656
|
break;
|
657
|
case 8:
|
658
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Disabled / Locked Hostname.";
|
659
|
break;
|
660
|
case 9:
|
661
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Host updated is configured as a web redirect and no update was performed.";
|
662
|
break;
|
663
|
case 10:
|
664
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Group supplied does not exist.";
|
665
|
break;
|
666
|
case 11:
|
667
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group update is successful.";
|
668
|
$successful_update = true;
|
669
|
break;
|
670
|
case 12:
|
671
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) DNS group is current, no update performed.";
|
672
|
$successful_update = true;
|
673
|
break;
|
674
|
case 13:
|
675
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update client support not available for supplied hostname or group.";
|
676
|
break;
|
677
|
case 14:
|
678
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname supplied does not have offline settings configured.";
|
679
|
break;
|
680
|
case 99:
|
681
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
|
682
|
break;
|
683
|
case 100:
|
684
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Client disabled. Client should exit and not perform any more updates without user intervention.";
|
685
|
break;
|
686
|
default:
|
687
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
688
|
$this->_debug("Unknown Response: ".$data);
|
689
|
break;
|
690
|
}
|
691
|
break;
|
692
|
case 'easydns':
|
693
|
if (preg_match('/NOACCESS/i', $data)) {
|
694
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Authentication Failed: Username and/or Password was Incorrect.";
|
695
|
} else if (preg_match('/NOSERVICE/i', $data)) {
|
696
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) No Service: Dynamic DNS Service has been disabled for this domain.";
|
697
|
} else if (preg_match('/ILLEGAL INPUT/i', $data)) {
|
698
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Illegal Input: Self-Explantory";
|
699
|
} else if (preg_match('/TOOSOON/i', $data)) {
|
700
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Too Soon: Not Enough Time Has Elapsed Since Last Update";
|
701
|
} else if (preg_match('/NOERROR/i', $data)) {
|
702
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Updated Successfully!";
|
703
|
$successful_update = true;
|
704
|
} else {
|
705
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
706
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
707
|
$this->_debug($data);
|
708
|
}
|
709
|
break;
|
710
|
case 'hn':
|
711
|
/* FIXME: add checks */
|
712
|
break;
|
713
|
case 'zoneedit':
|
714
|
if (preg_match('/799/i', $data)) {
|
715
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error 799) Update Failed!";
|
716
|
} else if (preg_match('/700/i', $data)) {
|
717
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error 700) Update Failed!";
|
718
|
} else if (preg_match('/200/i', $data)) {
|
719
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
|
720
|
$successful_update = true;
|
721
|
} else if (preg_match('/201/i', $data)) {
|
722
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
|
723
|
$successful_update = true;
|
724
|
} else {
|
725
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
726
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
727
|
$this->_debug($data);
|
728
|
}
|
729
|
break;
|
730
|
case 'dyns':
|
731
|
if (preg_match("/400/i", $data)) {
|
732
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The URL was malformed. Required parameters were not provided.";
|
733
|
} else if (preg_match('/402/i', $data)) {
|
734
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Update Too Soon - You have tried updating to quickly since last change.";
|
735
|
} else if (preg_match('/403/i', $data)) {
|
736
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Database Error - There was a server-sided database error.";
|
737
|
} else if (preg_match('/405/i', $data)) {
|
738
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname Error - The hostname (".$this->_dnsHost.") doesn't belong to you.";
|
739
|
} else if (preg_match('/200/i', $data)) {
|
740
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
|
741
|
$successful_update = true;
|
742
|
} else {
|
743
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
744
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
745
|
$this->_debug($data);
|
746
|
}
|
747
|
break;
|
748
|
case 'ods':
|
749
|
if (preg_match("/299/i", $data)) {
|
750
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
|
751
|
$successful_update = true;
|
752
|
} else {
|
753
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
754
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
755
|
$this->_debug($data);
|
756
|
}
|
757
|
break;
|
758
|
case 'freedns':
|
759
|
if (preg_match("/has not changed./i", $data)) {
|
760
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
|
761
|
$successful_update = true;
|
762
|
} else if (preg_match("/Updated/i", $data)) {
|
763
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
|
764
|
$successful_update = true;
|
765
|
} else {
|
766
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
767
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
768
|
$this->_debug($data);
|
769
|
}
|
770
|
break;
|
771
|
case 'dnsexit':
|
772
|
if (preg_match("/is the same/i", $data)) {
|
773
|
$status = "phpDynDns ({$this->_dnsHost}): (Success) No Change In IP Address";
|
774
|
$successful_update = true;
|
775
|
} else if (preg_match("/Success/i", $data)) {
|
776
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
|
777
|
$successful_update = true;
|
778
|
} else {
|
779
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
780
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
781
|
$this->_debug($data);
|
782
|
}
|
783
|
break;
|
784
|
case 'loopia':
|
785
|
if (preg_match("/nochg/i", $data)) {
|
786
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) No Change In IP Address";
|
787
|
$successful_update = true;
|
788
|
} else if (preg_match("/good/i", $data)) {
|
789
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully!";
|
790
|
$successful_update = true;
|
791
|
} else if (preg_match('/badauth/i', $data)) {
|
792
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) User Authorization Failed";
|
793
|
} else {
|
794
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
795
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
796
|
$this->_debug($data);
|
797
|
}
|
798
|
break;
|
799
|
case 'opendns':
|
800
|
if (preg_match('/badauth/i', $data)) {
|
801
|
$status = "phpDynDNS({$this->_dnsHost}): (Error) Not a valid username or password!";
|
802
|
} else if (preg_match('/nohost/i', $data)) {
|
803
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Hostname you are trying to update does not exist.";
|
804
|
$successful_update = true;
|
805
|
} else if (preg_match('/good/i', $data)) {
|
806
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
|
807
|
$successful_update = true;
|
808
|
} else if (preg_match('/yours/i', $data)) {
|
809
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) hostname specified exists, but not under the username specified.";
|
810
|
} else if (preg_match('/abuse/i', $data)) {
|
811
|
$status = "phpDynDns ({$this->_dnsHost}): (Error) Updating too frequently, considered abuse.";
|
812
|
} else {
|
813
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
814
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
815
|
$this->_debug($data);
|
816
|
}
|
817
|
break;
|
818
|
case 'staticcling':
|
819
|
if (preg_match("/invalid ip/i", $data)) {
|
820
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - The IP provided was invalid.";
|
821
|
} else if (preg_match('/required info missing/i', $data)) {
|
822
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Required parameters were not provided.";
|
823
|
} else if (preg_match('/invalid characters/i', $data)) {
|
824
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Bad Request - Illegal characters in either the username or the password.";
|
825
|
} else if (preg_match('/bad password/i', $data)) {
|
826
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Invalid password.";
|
827
|
} else if (preg_match('/account locked/i', $data)) {
|
828
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) This account has been administratively locked.";
|
829
|
} else if (preg_match('/update too frequent/i', $data)) {
|
830
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Updating too frequently.";
|
831
|
} else if (preg_match('/DB error/i', $data)) {
|
832
|
$status = "phpDynDNS ({$this->_dnsHost}): (Error) Server side error.";
|
833
|
} else if (preg_match('/success/i', $data)) {
|
834
|
$status = "phpDynDNS ({$this->_dnsHost}): (Success) IP Address Updated Successfully!";
|
835
|
$successful_update = true;
|
836
|
} else {
|
837
|
$status = "phpDynDNS ({$this->_dnsHost}): (Unknown Response)";
|
838
|
log_error("phpDynDNS ({$this->_dnsHost}): PAYLOAD: {$data}");
|
839
|
$this->_debug($data);
|
840
|
}
|
841
|
break;
|
842
|
case 'namecheap':
|
843
|
$tmp = str_replace("^M", "", $data);
|
844
|
$ncresponse = @xml2array($tmp);
|
845
|
if (preg_match("/internal server error/i", $data)) {
|
846
|
$status = "phpDynDNS: (Error) Server side error.";
|
847
|
} else if (preg_match("/request is badly formed/i", $data)) {
|
848
|
$status = "phpDynDNS: (Error) Badly Formed Request (check your settings).";
|
849
|
} else if ($ncresponse['interface-response']['ErrCount'] === "0") {
|
850
|
$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
|
851
|
$successful_update = true;
|
852
|
} else if (is_numeric($ncresponse['interface-response']['ErrCount']) && ($ncresponse['interface-response']['ErrCount'] > 0)) {
|
853
|
$status = "phpDynDNS: (Error) " . implode(", ", $ncresponse["interface-response"]["errors"]);
|
854
|
$successful_update = true;
|
855
|
} else {
|
856
|
$status = "phpDynDNS: (Unknown Response)";
|
857
|
log_error("phpDynDNS: PAYLOAD: {$data}");
|
858
|
$this->_debug($data);
|
859
|
}
|
860
|
break;
|
861
|
|
862
|
case 'he-net':
|
863
|
if (preg_match("/badip/i", $data)) {
|
864
|
$status = "phpDynDNS: (Error) Bad Request - The IP provided was invalid.";
|
865
|
} else if (preg_match('/nohost/i', $data)) {
|
866
|
$status = "phpDynDNS: (Error) Bad Request - A hostname was not provided.";
|
867
|
} else if (preg_match('/badauth/i', $data)) {
|
868
|
$status = "phpDynDNS: (Error) Invalid username or password.";
|
869
|
} else if (preg_match('/good/i', $data)) {
|
870
|
$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
|
871
|
$successful_update = true;
|
872
|
} else if (preg_match('/nochg/i', $data)) {
|
873
|
$status = "phpDynDNS: (Success) No Change In IP Address.";
|
874
|
$successful_update = true;
|
875
|
} else {
|
876
|
$status = "phpDynDNS: (Unknown Response)";
|
877
|
log_error("phpDynDNS: PAYLOAD: {$data}");
|
878
|
$this->_debug($data);
|
879
|
}
|
880
|
break;
|
881
|
case 'he-net-tunnelbroker':
|
882
|
/*
|
883
|
-ERROR: Missing parameter(s).
|
884
|
-ERROR: Invalid API key or password
|
885
|
-ERROR: Tunnel not found
|
886
|
-ERROR: Another tunnel exists for this IP.
|
887
|
-ERROR: This tunnel is already associated with this IP address
|
888
|
+OK: Tunnel endpoint updated to: x.x.x.x
|
889
|
*/
|
890
|
if (preg_match("/Missing parameter/i", $data)) {
|
891
|
$status = "phpDynDNS: (Error) Bad Request - Missing/Invalid Parameters.";
|
892
|
} else if (preg_match('/Tunnel not found/i', $data)) {
|
893
|
$status = "phpDynDNS: (Error) Bad Request - Invalid Tunnel ID.";
|
894
|
} else if (preg_match('/Invalid API key or password/i', $data)) {
|
895
|
$status = "phpDynDNS: (Error) Invalid username or password.";
|
896
|
} else if (preg_match('/OK:/i', $data)) {
|
897
|
$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
|
898
|
$successful_update = true;
|
899
|
} else if (preg_match('/This tunnel is already associated with this IP address/i', $data)) {
|
900
|
$status = "phpDynDNS: (Success) No Change In IP Address.";
|
901
|
$successful_update = true;
|
902
|
} else {
|
903
|
$status = "phpDynDNS: (Unknown Response)";
|
904
|
log_error("phpDynDNS: PAYLOAD: {$data}");
|
905
|
$this->_debug($data);
|
906
|
}
|
907
|
break;
|
908
|
case 'selfhost':
|
909
|
if (preg_match('/notfqdn/i', $data)) {
|
910
|
$status = "phpDynDNS: (Error) Not A FQDN!";
|
911
|
} else if (preg_match('/nochg/i', $data)) {
|
912
|
$status = "phpDynDNS: (Success) No Change In IP Address";
|
913
|
$successful_update = true;
|
914
|
} else if (preg_match('/good/i', $data)) {
|
915
|
$status = "phpDynDNS: (Success) IP Address Changed Successfully! (".$this->_dnsIP.")";
|
916
|
$successful_update = true;
|
917
|
} else if (preg_match('/noauth/i', $data)) {
|
918
|
$status = "phpDynDNS: (Error) User Authorization Failed";
|
919
|
} else {
|
920
|
$status = "phpDynDNS: (Unknown Response)";
|
921
|
log_error("phpDynDNS: PAYLOAD: {$data}");
|
922
|
$this->_debug($data);
|
923
|
}
|
924
|
break;
|
925
|
case 'route53':
|
926
|
$successful_update = true;
|
927
|
break;
|
928
|
case 'custom':
|
929
|
$successful_update = false;
|
930
|
if ($this->_dnsResultMatch == "") {
|
931
|
$successful_update = true;
|
932
|
}else {
|
933
|
$this->_dnsResultMatch = str_replace("%IP%", $this->_dnsIP, $this->_dnsResultMatch);
|
934
|
$matches = preg_split("/(?<!\\\\)\\|/", $this->_dnsResultMatch);
|
935
|
foreach($matches as $match) {
|
936
|
$match= str_replace("\\|", "|", $match);
|
937
|
if(strcmp($match, trim($data, "\t\n\r")) == 0)
|
938
|
$successful_update = true;
|
939
|
}
|
940
|
unset ($matches);
|
941
|
}
|
942
|
if ($successful_update == true)
|
943
|
$status = "phpDynDNS: (Success) IP Address Updated Successfully!";
|
944
|
else
|
945
|
$status = "phpDynDNS: (Error) Result did not match.";
|
946
|
break;
|
947
|
}
|
948
|
|
949
|
if($successful_update == true) {
|
950
|
/* Write WAN IP to cache file */
|
951
|
$wan_ip = $this->_checkIP();
|
952
|
conf_mount_rw();
|
953
|
if ($wan_ip > 0) {
|
954
|
$currentTime = time();
|
955
|
notify_all_remote(sprintf(gettext("DynDNS updated IP Address on %s (%s) to %s"), convert_real_interface_to_friendly_descr($this->_if), $this->_if, $wan_ip));
|
956
|
log_error("phpDynDNS: updating cache file {$this->_cacheFile}: {$wan_ip}");
|
957
|
@file_put_contents($this->_cacheFile, "{$wan_ip}:{$currentTime}");
|
958
|
} else
|
959
|
@unlink($this->_cacheFile);
|
960
|
conf_mount_ro();
|
961
|
}
|
962
|
$this->status = $status;
|
963
|
log_error($status);
|
964
|
}
|
965
|
|
966
|
/*
|
967
|
* Private Function (added 12 July 05) [beta]
|
968
|
* Return Error, Set Last Error, and Die.
|
969
|
*/
|
970
|
function _error($errorNumber = '1') {
|
971
|
switch ($errorNumber) {
|
972
|
case 0:
|
973
|
break;
|
974
|
case 2:
|
975
|
$error = 'phpDynDNS: (ERROR!) No Dynamic DNS Service provider was selected.';
|
976
|
break;
|
977
|
case 3:
|
978
|
$error = 'phpDynDNS: (ERROR!) No Username Provided.';
|
979
|
break;
|
980
|
case 4:
|
981
|
$error = 'phpDynDNS: (ERROR!) No Password Provided.';
|
982
|
break;
|
983
|
case 5:
|
984
|
$error = 'phpDynDNS: (ERROR!) No Hostname Provided.';
|
985
|
break;
|
986
|
case 6:
|
987
|
$error = 'phpDynDNS: (ERROR!) The Dynamic DNS Service provided is not yet supported.';
|
988
|
break;
|
989
|
case 7:
|
990
|
$error = 'phpDynDNS: (ERROR!) No Update URL Provided.';
|
991
|
break;
|
992
|
case 8:
|
993
|
$status = "Route 53: (Error) Invalid ZoneID";
|
994
|
break;
|
995
|
case 9:
|
996
|
$status = "Route 53: (Error) Invalid TTL";
|
997
|
break;
|
998
|
case 10:
|
999
|
$error = 'phpDynDNS: No change in my IP address and/or 25 days has not passed. Not updating dynamic DNS entry.';
|
1000
|
break;
|
1001
|
default:
|
1002
|
$error = "phpDynDNS: (ERROR!) Unknown Response.";
|
1003
|
/* FIXME: $data isn't in scope here */
|
1004
|
/* $this->_debug($data); */
|
1005
|
break;
|
1006
|
}
|
1007
|
$this->lastError = $error;
|
1008
|
log_error($error);
|
1009
|
}
|
1010
|
|
1011
|
/*
|
1012
|
* Private Function (added 12 July 05) [beta]
|
1013
|
* - Detect whether or not IP needs to be updated.
|
1014
|
* | Written Specifically for pfSense (pfsense.com) may
|
1015
|
* | work with other systems. pfSense base is FreeBSD.
|
1016
|
*/
|
1017
|
function _detectChange() {
|
1018
|
global $debug;
|
1019
|
|
1020
|
if ($debug)
|
1021
|
log_error("DynDns ({$this->_dnsHost}): _detectChange() starting.");
|
1022
|
|
1023
|
$currentTime = time();
|
1024
|
|
1025
|
$wan_ip = $this->_checkIP();
|
1026
|
if ($wan_ip == 0) {
|
1027
|
log_error("DynDns ({$this->_dnsHost}): Current WAN IP could not be determined, skipping update process.");
|
1028
|
return false;
|
1029
|
}
|
1030
|
$log_error = "DynDns ({$this->_dnsHost}): Current WAN IP: {$wan_ip} ";
|
1031
|
|
1032
|
if (file_exists($this->_cacheFile)) {
|
1033
|
$contents = file_get_contents($this->_cacheFile);
|
1034
|
list($cacheIP,$cacheTime) = explode(':', $contents);
|
1035
|
$this->_debug($cacheIP.'/'.$cacheTime);
|
1036
|
$initial = false;
|
1037
|
$log_error .= "Cached IP: {$cacheIP} ";
|
1038
|
} else {
|
1039
|
conf_mount_rw();
|
1040
|
$cacheIP = '0.0.0.0';
|
1041
|
@file_put_contents($this->_cacheFile, "0.0.0.0:{$currentTime}");
|
1042
|
conf_mount_ro();
|
1043
|
$cacheTime = $currentTime;
|
1044
|
$initial = true;
|
1045
|
$log_error .= "No Cached IP found.";
|
1046
|
}
|
1047
|
log_error($log_error);
|
1048
|
|
1049
|
/* use 2419200 for dyndns, dhs, easydns, noip, hn
|
1050
|
* zoneedit, dyns, ods
|
1051
|
*/
|
1052
|
$time = '2160000';
|
1053
|
|
1054
|
$needs_updating = FALSE;
|
1055
|
/* lets determine if the item needs updating */
|
1056
|
if ($cacheIP != $wan_ip) {
|
1057
|
$needs_updating = true;
|
1058
|
$update_reason = "DynDns: cacheIP != wan_ip. Updating. ";
|
1059
|
$update_reason .= "Cached IP: {$cacheIP} WAN IP: {$wan_ip} ";
|
1060
|
}
|
1061
|
if (($currentTime - $cacheTime) > $time ) {
|
1062
|
$needs_updating = true;
|
1063
|
$update_reason = "DynDns: More than 25 days. Updating. ";
|
1064
|
$update_reason .= "{$currentTime} - {$cacheTime} > {$time} ";
|
1065
|
}
|
1066
|
if ($initial == true) {
|
1067
|
$needs_updating = true;
|
1068
|
$update_reason .= "Initial update. ";
|
1069
|
}
|
1070
|
|
1071
|
/* finally if we need updating then store the
|
1072
|
* new cache value and return true
|
1073
|
*/
|
1074
|
if ($needs_updating == true) {
|
1075
|
log_error("DynDns debug information ({$this->_dnsHost}): {$update_reason}");
|
1076
|
return true;
|
1077
|
}
|
1078
|
|
1079
|
return false;
|
1080
|
}
|
1081
|
|
1082
|
/*
|
1083
|
* Private Funcation (added 16 July 05) [beta]
|
1084
|
* - Writes debug information to a file.
|
1085
|
* - This function is only called when a unknown response
|
1086
|
* - status is returned from a DynDNS service provider.
|
1087
|
*/
|
1088
|
function _debug ($data) {
|
1089
|
$string = '\n'.date('m-d-y h:i:s').' - ('.$this->_debugID.') - ['.$this->_dnsService.'] - '.$data.'\n';
|
1090
|
conf_mount_rw();
|
1091
|
$file = fopen($this->_debugFile, 'a');
|
1092
|
fwrite($file, $string);
|
1093
|
fclose($file);
|
1094
|
conf_mount_ro();
|
1095
|
}
|
1096
|
function _checkIP() {
|
1097
|
global $debug;
|
1098
|
|
1099
|
if ($debug)
|
1100
|
log_error("DynDns ({$this->_dnsHost}): _checkIP() starting.");
|
1101
|
|
1102
|
$ip_address = find_interface_ip($this->_if);
|
1103
|
if (!is_ipaddr($ip_address))
|
1104
|
return 0;
|
1105
|
if (is_private_ip($ip_address)) {
|
1106
|
$hosttocheck = "checkip.dyndns.org";
|
1107
|
$try = 0;
|
1108
|
while ($try < 3) {
|
1109
|
$checkip = gethostbyname($hosttocheck);
|
1110
|
if (is_ipaddr($checkip))
|
1111
|
break;
|
1112
|
$try++;
|
1113
|
}
|
1114
|
if ($try >= 3) {
|
1115
|
log_error("Dyndns debug information ({$this->_dnsHost}): Could not resolve {$hosttocheck} to ip using interface ip {$ip_address}.");
|
1116
|
return 0;
|
1117
|
}
|
1118
|
$ip_ch = curl_init("http://{$checkip}");
|
1119
|
curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
|
1120
|
curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
1121
|
curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
|
1122
|
curl_setopt($ip_ch, CURLOPT_CONNECTTIMEOUT, '30');
|
1123
|
curl_setopt($ip_ch, CURLOPT_TIMEOUT, 120);
|
1124
|
$ip_result_page = curl_exec($ip_ch);
|
1125
|
curl_close($ip_ch);
|
1126
|
$ip_result_decoded = urldecode($ip_result_page);
|
1127
|
preg_match('/Current IP Address: (.*)<\/body>/', $ip_result_decoded, $matches);
|
1128
|
$ip_address = trim($matches[1]);
|
1129
|
if (is_ipaddr($ip_address))
|
1130
|
log_error("DynDns debug information ({$this->_dnsHost}): {$ip_address} extracted from {$hosttocheck}");
|
1131
|
else {
|
1132
|
log_error("DynDns debug information ({$this->_dnsHost}): IP address could not be extracted from {$hosttocheck}");
|
1133
|
return 0;
|
1134
|
}
|
1135
|
} else
|
1136
|
log_error("DynDns debug information ({$this->_dnsHost}): {$ip_address} extracted from local system.");
|
1137
|
|
1138
|
$this->_dnsIP = $ip_address;
|
1139
|
|
1140
|
return $ip_address;
|
1141
|
}
|
1142
|
|
1143
|
}
|
1144
|
|
1145
|
?>
|