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