]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/setddns.pl
Update translations.
[people/teissler/ipfire-2.x.git] / src / scripts / setddns.pl
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 # $Id: setddns.pl,v 1.4.2.32 2006/02/07 01:29:47 franck78 Exp $
10 #
11
12 #close(STDIN);
13 #close(STDOUT);
14 #close(STDERR);
15
16 use strict;
17 use IO::Socket;
18 use Net::SSLeay;
19
20 require '/var/ipfire/general-functions.pl';
21
22 #Prototypes functions
23 sub encode_base64 ($;$);
24
25 my %settings;
26 my $filename = "${General::swroot}/ddns/config";
27 my $cachefile = "${General::swroot}/ddns/ipcache";
28 my $ipcache = 0;
29 my @current = ();
30
31 if (open(FILE, "$filename")) {
32 @current = <FILE>;
33 close(FILE);
34 unless(@current) {
35 exit 0;
36 }
37 } else {
38 &General::log('Dynamic DNS failure : unable to open config file.');
39 exit 0;
40 }
41
42 &General::readhash("${General::swroot}/ddns/settings", \%settings);
43
44 # ignore monthly update if not in minimize update mode
45 exit 0 if (($settings{'MINIMIZEUPDATES'} ne 'on') && ($ARGV[1] eq '-m'));
46
47 my $ip = &General::GetDyndnsRedIP();
48
49 if ($ip eq "unavailable") {
50 &General::log("Dynamic DNS error: RED/Public IP is unavailable");
51 exit(0);
52 }
53
54 &General::log("Dynamic DNS public router IP is: $ip");
55
56 if ($ARGV[0] eq '-f') {
57 unlink ($cachefile); # next regular calls will try again if this force update fails.
58 } else {
59 open(IPCACHE, "$cachefile");
60 $ipcache = <IPCACHE>;
61 close(IPCACHE);
62 chomp $ipcache;
63 }
64
65 if ($ip ne $ipcache) {
66 my $id = 0;
67 my $success = 0;
68 my $line;
69 my $lines = @current;
70
71 foreach $line (@current) {
72 $id++;
73 chomp($line);
74 my @temp = split(/\,/,$line);
75 unless ($temp[7] ne "on") {
76 $settings{'SERVICE'} = $temp[0];
77 $settings{'HOSTNAME'} = $temp[1];
78 $settings{'DOMAIN'} = $temp[2];
79 $settings{'PROXY'} = $temp[3];
80 $settings{'WILDCARDS'} = $temp[4];
81 $settings{'LOGIN'} = $temp[5];
82 $settings{'PASSWORD'} = $temp[6];
83 $settings{'ENABLED'} = $temp[7];
84
85 #Some connection are very stable (more than 40 days). Finally force
86 #one update / month to avoid account lost
87 #cron call once/week with -f & once/month with -f -m options
88 #minimize update ?
89 if ( ($settings{'MINIMIZEUPDATES'} eq 'on') && ($ARGV[1] ne '-m') ) {
90 if (General::DyndnsServiceSync($ip, $settings{'HOSTNAME'},$settings{'DOMAIN'})) {
91 &General::log ("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} is uptodate [$ip]");
92 $success++;
93 next; # do not update, go to test next service
94 }
95 }
96 if ($settings{'SERVICE'} ne "dns.lightningwirelabs.com") {
97 my @service = split(/\./, "$settings{'SERVICE'}");
98 $settings{'SERVICE'} = "$service[0]";
99 }
100 if ($settings{'SERVICE'} eq 'no-ip') {
101 open(F, ">${General::swroot}/ddns/noipsettings");
102 flock F, 2;
103 print F "PROXY=" . ($settings{'PROXY'} eq 'on' ? "Y\n" : "N\n");
104 print F "PASSWORD=$settings{'PASSWORD'}\n";
105 print F "NAT=N\n";
106 print F "LOGIN=$settings{'LOGIN'}\n";
107 print F "INTERVAL=1\n";
108 if ($settings{'HOSTNAME'} !~ s/$General::noipprefix//) {
109 print F "HOSTNAME=$settings{'HOSTNAME'}\n";
110 print F "GROUP=\n";
111 } else {
112 print F "HOSTNAME=\n";
113 print F "GROUP=$settings{'HOSTNAME'}\n";
114 }
115 print F "DOMAIN=$settings{'DOMAIN'}\n";
116 print F "DEVICE=\n";
117 print F "DAEMON=N\n";
118 close(F);
119
120 my @ddnscommand = ('/usr/bin/noip','-c',"${General::swroot}/ddns/noipsettings",'-i',"$ip");
121
122 my $result = system(@ddnscommand);
123 if ( $result != 0) {
124 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure");
125 } else {
126 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
127 $success++;
128 }
129 }
130
131 elsif ($settings{'SERVICE'} eq 'all-inkl') {
132 my %proxysettings;
133 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
134 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
135 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
136 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
137 }
138
139 my ($out, $response) = Net::SSLeay::get_https("dyndns.kasserver.com", 443, "/", Net::SSLeay::make_headers(
140 'User-Agent' => 'IPFire', 'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}")
141 ));
142
143 # Valid response are 'ok' 'nochange'
144 if ($response =~ m%HTTP/1\.. 200 OK%) {
145 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
146 $success++;
147 } else {
148 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server, check your credentials)");
149 }
150 }
151
152 elsif ($settings{'SERVICE'} eq 'cjb') {
153 # use proxy ?
154 my %proxysettings;
155 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
156 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
157 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
158 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
159 }
160
161 my ($out, $response) = Net::SSLeay::get_http( 'www.cjb.net',
162 80,
163 "/cgi-bin/dynip.cgi?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&ip=$ip",
164 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
165 );
166
167 if ($response =~ m%HTTP/1\.. 200 OK%) {
168 if ( $out !~ m/has been updated to point to/ ) {
169 &General::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : failure (bad password or login)");
170 } else {
171 &General::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : success");
172 $success++;
173 }
174 } else {
175 &General::log("Dynamic DNS ip-update for cjb.net ($settings{'LOGIN'}) : failure (could not connect to server)");
176 }
177 }
178 elsif ($settings{'SERVICE'} eq 'selfhost') {
179 # use proxy ?
180 my %proxysettings;
181 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
182 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
183 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
184 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
185 }
186
187 my ($out, $response) = Net::SSLeay::get_https( 'carol.selfhost.de',
188 443,
189 "/update?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&textmodi=1",
190 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
191 );
192
193 if ($response =~ m%HTTP/1\.. 200 OK%) {
194 if ( $out !~ m/status=(200|204)/ ) {
195 $out =~ s/\n/ /g;
196 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out)");
197 } else {
198 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
199 $success++;
200 }
201 } else {
202 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
203 }
204 }
205 elsif ($settings{'SERVICE'} eq 'dnspark') {
206 # use proxy ?
207 my %proxysettings;
208 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
209 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
210 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
211 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
212 }
213
214 if ($settings{'HOSTNAME'} eq '') {
215 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
216 } else {
217 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
218 }
219
220 my ($out, $response) = Net::SSLeay::get_https( "www.dnspark.net",
221 443,
222 "/api/dynamic/update.php?hostname=$settings{'HOSTDOMAIN'}&ip=$ip",
223 Net::SSLeay::make_headers('User-Agent' => 'IPFire',
224 'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}")
225 )
226 );
227 # Valid response are 'ok' 'nochange'
228 if ($response =~ m%HTTP/1\.. 200 OK%) {
229 if ( $out !~ m/^(ok|nochange)/ ) {
230 $out =~ s/\n/ /g;
231 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
232 } else {
233 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
234 $success++;
235 }
236 } else {
237 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)");
238 }
239 }
240 elsif ($settings{'SERVICE'} eq 'dns.lightningwirelabs.com') {
241 # use proxy ?
242 my %proxysettings;
243 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
244 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
245 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
246 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
247 }
248
249 if ($settings{'HOSTNAME'} eq '') {
250 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
251 } else {
252 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
253 }
254
255 my $authstring;
256 if ($settings{'LOGIN'} eq "token") {
257 $authstring = "token=$settings{'PASSWORD'}";
258 } else {
259 $authstring = "username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}";
260 }
261
262 my $user_agent = &General::MakeUserAgent();
263 my ($out, $response) = Net::SSLeay::get_https("dns.lightningwirelabs.com", 443,
264 "/update?hostname=$settings{'HOSTDOMAIN'}&address4=$ip&$authstring",
265 Net::SSLeay::make_headers('User-Agent' => $user_agent)
266 );
267
268 # Valid response are 'ok' 'nochange'
269 if ($response =~ m%HTTP/1\.. 200 OK%) {
270 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
271 $success++;
272 } else {
273 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials)");
274 }
275 }
276 elsif ($settings{'SERVICE'} eq 'enom') {
277 # use proxy ?
278 my %proxysettings;
279 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
280 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
281 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
282 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
283 }
284 if ($settings{'HOSTNAME'} eq '') {
285 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
286 } else {
287 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
288 }
289
290 my ($out, $response) = Net::SSLeay::get_http( 'dynamic.name-services.com',
291 80,
292 "/interface.asp?Command=SetDNSHost&Zone=$settings{'DOMAIN'}&DomainPassword=$settings{'PASSWORD'}&Address=$ip",
293 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
294 );
295
296 if ($response =~ m%HTTP/1\.. 200 OK%) {
297 #Valid responses from update => ErrCount=0
298 if ( $out !~ m/ErrCount=0/ ) {
299 $out =~ s/(\n|\x0D)/ /g;
300 $out =~ /Err1=([\w ]+) /;
301 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($1)");
302 } else {
303 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
304 $success++;
305 }
306 } else {
307 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
308 }
309 }
310 elsif ($settings{'SERVICE'} eq 'nsupdate') {
311 # Fetch UI configurable values and assemble the host name.
312
313 my $hostName="$settings{'DOMAIN'}";
314 if ($settings{'HOSTNAME'} ne "") {
315 $hostName="$settings{'HOSTNAME'}.$hostName";
316 }
317 my $keyName=$settings{'LOGIN'};
318 my $keySecret=$settings{'PASSWORD'};
319
320 # Use a relatively long TTL value to reduce load on DNS.
321 # Some public Dynamic DNS servers use values around 4 hours,
322 # some use values as low as 60 seconds.
323 # XXX Maybe we could fetch the master value from the server
324 # (not the timed-down version supplied by DNS cache)
325
326 my $timeToLive="3600";
327
328 # Internal setting that can be used to override the DNS server
329 # where the update is applied. It can be of use when testing
330 # against a private DNS server.
331
332 my $masterServer="";
333
334 # Prepare the nsupdate command script to remove and re-add the
335 # updated A record for the domain.
336
337 my $cmdFile="/tmp/nsupdate-$hostName-commands";
338 my $logFile="/tmp/nsupdate-$hostName-result";
339 open(TF, ">$cmdFile");
340 if ($masterServer ne "") {
341 print TF "server $masterServer\n";
342 }
343 if ($keyName ne "" && $keySecret ne "") {
344 print TF "key $keyName $keySecret\n";
345 }
346 print TF "update delete $hostName A\n";
347 print TF "update add $hostName $timeToLive A $ip\n";
348 print TF "send\n";
349 close(TF);
350
351 # Run nsupdate with -v to use TCP instead of UDP because we're
352 # issuing multiple cmds and potentially long keys, and -d to
353 # get diagnostic result output.
354
355 my $result = system("/usr/bin/nsupdate -v -d $cmdFile 2>$logFile");
356 if ($result != 0) {
357 &General::log("Dynamic DNS ip-update for $hostName : failure");
358 open(NSLOG, "$logFile");
359 my @nsLog = <NSLOG>;
360 close(NSLOG);
361 my $logLine;
362 foreach $logLine (@nsLog) {
363 chomp($logLine);
364 if ($logLine ne "") {
365 &General::log("... $logLine");
366 }
367 }
368 } else {
369 &General::log("Dynamic DNS ip-update for $hostName : success");
370 $success++;
371 }
372 unlink $cmdFile, $logFile;
373 }
374 elsif ($settings{'SERVICE'} eq 'freedns') {
375 # use proxy ?
376 my %proxysettings;
377 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
378 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
379 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
380 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
381 }
382
383 my ($out, $response) = Net::SSLeay::get_https( 'freedns.afraid.org',
384 443,
385 "/dynamic/update.php?$settings{'LOGIN'}",
386 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
387 );
388 #Valid responses from service are:
389 #Updated n host(s) <domain>
390 #ERROR: <ip> has not changed.
391 if ($response =~ m%HTTP/1\.. 200 OK%) {
392 #Valid responses from update => ErrCount=0
393 if ( $out !~ m/(^Updated|Address .* has not changed)/ig ) {
394 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out)");
395 } else {
396 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
397 $success++;
398 }
399 } else {
400 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
401 }
402 }
403 elsif ($settings{'SERVICE'} eq 'strato') {
404 # use proxy ?
405 my %proxysettings;
406 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
407 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
408 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
409 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
410 }
411
412 if ($settings{'HOSTNAME'} eq '') {
413 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
414 } else {
415 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
416 }
417
418 my ($out, $response) = Net::SSLeay::get_https( 'dyndns.strato.com',
419 443,
420 "/nic/update?hostname=$settings{'HOSTDOMAIN'}&myip=$ip",
421 Net::SSLeay::make_headers('User-Agent' => 'IPFire',
422 'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}") )
423 );
424
425 if ($response =~ m%HTTP/1\.. 200 OK%) {
426 #Valid responses from update => ErrCount=0
427 if ( $out =~ m/good |nochg /ig) {
428 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
429 $success++;
430 } else {
431 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure1 ($out)");
432 $success++;
433 }
434 } elsif ( $out =~ m/<title>(.*)<\/title>/ig ) {
435 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure2 ($1)");
436 } else {
437 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure3 ($response)");
438 }
439 }
440 elsif ($settings{'SERVICE'} eq 'regfish') {
441 # use proxy ?
442 my %proxysettings;
443 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
444 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
445 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
446 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
447 }
448 my ($out, $response) = Net::SSLeay::get_https( 'dyndns.regfish.de',
449 443,
450 "/?fqdn=$settings{'DOMAIN'}&ipv4=$ip&forcehost=1&authtype=secure&token=$settings{'LOGIN'}",
451 Net::SSLeay::make_headers('User-Agent' => 'Ipfire' )
452 );
453 #Valid responses from service are:
454 #success|100|update succeeded!
455 #success|101|no update needed at this time..
456 if ($response =~ m%HTTP/1\.. 200 OK%) {
457 if ( $out !~ m/(success\|(100|101)\|)/ig ) {
458 &General::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure ($out)");
459 } else {
460 &General::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : success");
461 $success++;
462 }
463 } else {
464 &General::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure (could not connect to server)");
465 }
466 }
467 elsif ($settings{'SERVICE'} eq 'ovh') {
468 my %proxysettings;
469 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
470
471 my $peer = 'www.ovh.com';
472 my $peerport = 80;
473
474 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
475 ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
476 }
477
478 my $sock;
479 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
480 &General::log("Dynamic DNS failure : could not connect to $peer:$peerport: $@");
481 next;
482 }
483
484 if ($settings{'HOSTNAME'} eq '') {
485 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
486 } else {
487 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
488 }
489
490 my ($GET_CMD, $code64);
491 $GET_CMD = "GET http://www.ovh.com/nic/update?system=dyndns&hostname=$settings{'HOSTDOMAIN'}&myip=$ip HTTP/1.1\r\n";
492 $GET_CMD .= "Host: www.ovh.com\r\n";
493 chomp($code64 = encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}"));
494 $GET_CMD .= "Authorization: Basic $code64\r\n";
495 $GET_CMD .= "User-Agent: ipfire\r\n";
496 #$GET_CMD .= "Content-Type: application/x-www-form-urlencoded\r\n";
497 $GET_CMD .= "\r\n";
498 print $sock "$GET_CMD";
499
500 my $out = '';
501 while(<$sock>) {
502 $out .= $_;
503 }
504 close($sock);
505
506 #HTTP response => error (in Title tag) else text response
507 #Valid responses from service:good,nochg (ez-ipupdate like)
508 #Should use ez-ipdate but "system=dyndns" is not present
509 if ( $out =~ m/<Title>(.*)<\/Title>/ig ) {
510 &General::log("Dynamic DNS ovh.com : failure ($1)");
511 }
512 elsif ($out !~ m/good |nochg /ig) {
513 $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
514 my @out = split("\r", $out);
515 &General::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : failure ($out[1])");
516 } else {
517 &General::log("Dynamic DNS ip-update for $settings{'DOMAIN'} : success");
518 $success++;
519 }
520 }
521 elsif ($settings{'SERVICE'} eq 'dtdns') {
522 # use proxy ?
523 my %proxysettings;
524 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
525 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
526 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
527 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
528 }
529
530 if ($settings{'HOSTNAME'} eq '') {
531 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
532 } else {
533 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
534 }
535
536 my ($out, $response) = Net::SSLeay::get_http( 'www.dtdns.com',
537 80,
538 "/api/autodns.cfm?id=$settings{'HOSTDOMAIN'}&pw=$settings{'PASSWORD'}",
539 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
540 );
541 #Valid responses from service are:
542 # now points to
543 #
544 if ($response =~ m%HTTP/1\.. 200 OK%) {
545 if ( $out !~ m/Host .* now points to/ig ) {
546 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
547 } else {
548 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
549 $success++;
550 }
551 } else {
552 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
553 }
554 }
555 #namecheap test
556 elsif ($settings{'SERVICE'} eq 'namecheap') {
557 # use proxy ?
558 my %proxysettings;
559 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
560 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
561 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
562 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
563 }
564
565 my ($out, $response) = Net::SSLeay::get_https( 'dynamicdns.park-your-domain.com',
566 443,
567 "/update?host=$settings{'HOSTNAME'}&domain=$settings{'DOMAIN'}&password=$settings{'PASSWORD'}&ip=$ip",
568 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
569 );
570 #Valid responses from service are:
571 # wait confirmation!!
572 if ($response =~ m%HTTP/1\.. 200 OK%) {
573 if ( $out !~ m/<ErrCount>0<\/ErrCount>/ ) {
574 $out =~ m/<Err1>(.*)<\/Err1>/;
575 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($1)");
576 } else {
577 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
578 $success++;
579 }
580 } else {
581 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure (could not connect to server)");
582 }
583 }
584 #end namecheap test
585 elsif ($settings{'SERVICE'} eq 'dynu') {
586 # use proxy ?
587 my %proxysettings;
588 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
589 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
590 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
591 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
592 }
593
594 if ($settings{'HOSTNAME'} eq '') {
595 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
596 } else {
597 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
598 }
599
600 my ($out, $response) = Net::SSLeay::get_http( 'dynserv.ca',
601 80,
602 "/dyn/dynengine.cgi?func=set&name=$settings{'LOGIN'}&pass=$settings{'PASSWORD'}&ip=$ip&domain=$settings{'DOMAIN'}",
603 Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
604 );
605 #Valid responses from service are:
606 # 02 == Domain already exists, refreshing data for ... => xxx.xxx.xxx.xxx
607 #
608 if ($response =~ m%HTTP/1\.. 200 OK%) {
609 if ( $out !~ m/Domain already exists, refreshing data for/ig ) {
610 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
611 } else {
612 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
613 $success++;
614 }
615 } else {
616 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server)");
617 }
618 }
619 elsif ($settings{'SERVICE'} eq 'udmedia.de') {
620 # use proxy ?
621 my %proxysettings;
622 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
623 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
624 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
625 Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
626 }
627
628 if ($settings{'HOSTNAME'} eq '') {
629 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
630 } else {
631 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
632 }
633
634 my ($out, $response) = Net::SSLeay::get_https( 'www.udmedia.de',
635 443,
636 "/nic/update?myip=$ip&username=$settings{'HOSTDOMAIN'}&password=$settings{'PASSWORD'}",
637 Net::SSLeay::make_headers('User-Agent' => 'IPFire',
638 'Authorization' => 'Basic ' . encode_base64("$settings{'LOGIN'}:$settings{'PASSWORD'}")) );
639
640 # Valid response are 'ok' 'nochange'
641 if ($response =~ m%HTTP/1\.. 200 OK%) {
642 if ( $out !~ m/^(ok|nochg)/ ) {
643 $out =~ s/\n/ /g;
644 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure ($out)");
645 } else {
646 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : success");
647 $success++;
648 }
649 } else {
650 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'} : failure (could not connect to server, check your credentials---$out-$response--)");
651 }
652 }
653 else {
654 if ($settings{'WILDCARDS'} eq 'on') {
655 $settings{'WILDCARDS'} = '-w';
656 } else {
657 $settings{'WILDCARDS'} = '';
658 }
659
660 if (($settings{'SERVICE'} eq 'dyndns-custom' ||
661 $settings{'SERVICE'} eq 'easydns' ||
662 $settings{'SERVICE'} eq 'zoneedit') && $settings{'HOSTNAME'} eq '') {
663 $settings{'HOSTDOMAIN'} = $settings{'DOMAIN'};
664 } else {
665 $settings{'HOSTDOMAIN'} = "$settings{'HOSTNAME'}.$settings{'DOMAIN'}";
666 }
667
668 my @ddnscommand = ('/usr/bin/ez-ipupdate', '-a', "$ip", '-S', "$settings{'SERVICE'}", '-u', "$settings{'LOGIN'}:$settings{'PASSWORD'}", '-h', "$settings{'HOSTDOMAIN'}", "$settings{'WILDCARDS'}", '-q');
669
670 my $result = system(@ddnscommand);
671 if ( $result != 0) {
672 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: failure");
673 } else {
674 &General::log("Dynamic DNS ip-update for $settings{'HOSTDOMAIN'}: success");
675 $success++;
676 }
677 }
678 } else {
679 # If a line is disabled, then we should discount it
680 $lines--;
681 }
682 }
683
684 if ($lines == $success) {
685 open(IPCACHE, ">$cachefile");
686 flock IPCACHE, 2;
687 print IPCACHE $ip;
688 close(IPCACHE);
689 exit 1;
690 }
691
692 }
693 exit 0;
694
695 # Extracted from Base64.pm
696 sub encode_base64 ($;$) {
697 my $res = "";
698 my $eol = $_[1];
699 $eol = "\n" unless defined $eol;
700 pos($_[0]) = 0; # ensure start at the beginning
701 while ($_[0] =~ /(.{1,45})/gs) {
702 $res .= substr(pack('u', $1), 1);
703 chop($res);
704 }
705 $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
706 # fix padding at the end
707 my $padding = (3 - length($_[0]) % 3) % 3;
708 $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
709 # break encoded string into lines of no more than 76 characters each
710 if (length $eol) {
711 $res =~ s/(.{1,76})/$1$eol/g;
712 }
713 $res;
714 }
715
716
717
718 __END__
719 old code for selfhost.de
720
721 my %proxysettings;
722 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
723
724 my $peer = 'carol.selfhost.de';
725 my $peerport = 80;
726
727 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
728 ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
729 }
730
731 my $sock;
732 unless($sock = new IO::Socket::INET (PeerAddr => $peer, PeerPort => $peerport, Proto => 'tcp', Timeout => 5)) {
733 die "Could not connect to $peer:$peerport: $@";
734 return 1;
735 }
736
737 my $GET_CMD;
738 $GET_CMD = "GET https://carol.selfhost.de/update?username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}&myip=$ip&textmodi=1 HTTP/1.1\r\n";
739 $GET_CMD .= "Host: carol.selfhost.de\r\n";
740 $GET_CMD .= "User-Agent: ipfire\r\n";
741 $GET_CMD .= "Connection: close\r\n\r\n";
742 print $sock "$GET_CMD";
743
744 my $out = '';
745 while(<$sock>) {
746 $out .= $_;
747 }
748 close($sock);
749
750 if ( $out !~ m/status=(200|204)/ ) {
751 #cleanup http response...
752 $out =~ s/.+?\015?\012\015?\012//s; # header HTTP
753 my @out = split("\r", $out);
754 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : failure ($out[1])");
755 } else {
756 &General::log("Dynamic DNS ip-update for $settings{'HOSTNAME'}.$settings{'DOMAIN'} : success");
757 $success++;
758 }
759
760
761