| |
Überwachung Ihres DynDNS-Home-Servers
Wenn gelegentliche Ausfälle des heimischen Servers auch zu verschmerzen sind, wird es Ärgerlich bei Betrieb eines eigenen Mailservers.
Da ich bisher kein Tool zur Überwachung meines Home-Servers gefunden habe, habe ich mal Perl misshandelt.
Herrausgekommen ist mein Modul DNS::WatchDynDNSClient
package DNS::WatchDynDNSClient;
###############################################################################
## ##
## Copyright (c) 2004 by Andreas Krueger ##
## ##
## Version 0.02 ##
## ##
## This package is free software; you can redistribute it ##
## and/or modify it under the same terms as Perl itself. ##
## ##
## Copy it as to : ##
## \perdir\site\lib\DNS\WatchDynDNSClient.pm ##
## ##
## Generate Ini-file like this : ##
## UseEntry[0|1]:hostname[yourhost.ourdomain.ext]:username:password: ##
## .mx[yourhost.ourdomain.ext|]:backmx[YES|NO]:wildcard[ON|OFF|NOCHG]: ##
## .offline[YES|NO]:[ProxyServer]:[ProxyPort]:[NoProxyFor] ##
## ##
## Call it like : use DNS::WatchDynDNSClient; ##
## my $ua = DNS::WatchDynDNSClient->new('accounts.ini'); ##
## ##
## Create in your Server-Root an file : server.txt ##
## It must include your DynDNS-Domain-Name Like : yourdomain.dyndns.ws ##
## ##
## The Script reads your ini and will test if the server is online ##
## by get the server.txt with your domain-name. ##
## ##
## If not reachable your server or not exist server.ini or the domain ##
## in server.ini not true, the script connect to dyndns an set the ##
## ip-adress to 169.254.0.1. ##
## Please reconnect an set your adress by any other tool. ##
## ##
## Comment and fixes send to webmaster(at)remote.dyndns.info ##
## ##
## ##
###############################################################################
use strict;
use warnings;
use LWP::UserAgent;
sub checkserver
{
my $account = shift;
my @acc_det=split(/:/,$account);
my $ua = LWP::UserAgent->new;
$ua->agent("DynDNS-Alive/0.02");
$ua->protocols_allowed( [ 'http'] );
$ua->proxy(['http'], 'http://'.$acc_det[8].':'.$acc_det[9].'/');
$ua->no_proxy($acc_det[10]);
my $req = HTTP::Request->new(GET => 'http://'.$acc_det[1].'/server.txt');
$req->content_type('text/plain');
my $res = $ua->request($req);
if ($res->is_success) {
if ($res->content =~ /$acc_det[1]/)
{
# print $res->content, "\n";
print "Account $acc_det[1] ist Erreichbar.\n\n";
if (-e "$acc_det[1].loc") # LOC-File vorhanden ?
{
print "Überwachung wieder freigegeben ...\n";
unlink("$acc_det[1].loc");
}
}
else
{
print "$acc_det[1] ist nicht auf den Server eingerichtet,";
print $res->content, "\n";
if (-e "$acc_det[1].loc") # LOC-File vorhanden ?
{
print " Link Lokal wurde schon gesetzt ...\n";
}
else
{
print " Setze Link Lokal !!";
my $ua = LWP::UserAgent->new;
$ua->agent("DynDNS-Alive/0.02");
$ua->protocols_allowed( [ 'http'] );
$ua->proxy(['http'], 'http://'.$acc_det[8].':'.$acc_det[9].'/');
$ua->no_proxy($acc_det[10]);
my $url= "http://'$acc_det[2]:$acc_det[3]\@members.dyndns.org/nic/
_update?system=dyndns&hostname=$acc_det[1]&myip=169.254.0.1&wildcard=
_$acc_det[6]&mx=$acc_det[4]&backmx=$acc_det[5]&offline=$acc_det[7]";
my $req = HTTP::Request->new(GET => $url);
$req->content_type('text/html');
$req->authorization_basic( $acc_det[2], $acc_det[3] );
my $res = $ua->request($req);
# print $res->as_string, "\n";
# print $res->content, "\n";
open(LOCFile, ">$acc_det[1].loc") || die "Kann Sperrdatei $ nicht erstellen !";
print LOCFile "loc" ;
close(LOCFile);
}
}
}
else {
print "Account $acc_det[1] ist nicht Erreichbar ...";
# print $res->status_line, "\n";
if (-e "$acc_det[1].loc") # LOC-File vorhanden ?
{
print " und schon auf Link Lokal gesetzt ...\n";
}
else
{
print " Setze Link Lokal !!\n";
my $ua = LWP::UserAgent->new;
$ua->agent("DynDNS-Alive/0.02");
$ua->protocols_allowed( [ 'http'] );
$ua->proxy(['http'], 'http://'.$acc_det[8].':'.$acc_det[9].'/');
$ua->no_proxy($acc_det[10]);
my $url= "http://'$acc_det[2]:$acc_det[3]\@members.dyndns.org/nic/
_update?system=dyndns&hostname=$acc_det[1]&myip=169.254.0.1&wildcard=
_$acc_det[6]&mx=$acc_det[4]&backmx=$acc_det[5]&offline=$acc_det[7]";
my $req = HTTP::Request->new(GET => $url);
$req->content_type('text/html');
$req->authorization_basic( $acc_det[2], $acc_det[3] );
my $res = $ua->request($req);
# print $res->as_string, "\n";
# print $res->content, "\n";
open(LOCFile, ">$acc_det[1].loc") || die "Kann Sperrdatei $ nicht erstellen !";
print LOCFile "loc" ;
close(LOCFile);
}
}
}
sub new
{
my $inifile = shift;
# print $inifile, "\n";
open(FILE_IN, "<$inifile") || die "can't open: $!";
my @acc_line = ;
close(FILE_IN);
foreach my $acc_dat (@acc_line)
{
my @acc_det=split(/:/,$acc_dat);
if($acc_det[0] eq "1")
{
print "Account $acc_det[1] wird getestet\n";
checkserver $acc_dat;
}
else
{
print "Account $acc_det[1] ist Inaktiv\n";
}
}
}
1;
|
Der Aufruf erfolgt dann ganz einfach durch folgende Zeilen :
use DNS::WatchDynDNSClient;
my $ua = DNS::WatchDynDNSClient->new('Inidatei');
|
Die INI ist wie folgt aufgebaut :
AK:AE:US:PW:MX:MB:WC:OF:PS:PP:PN
|
und kann beliebig viele Einträge haben.
Die Einträge im Einzelnen ....
| Eintrag | Wert | Erklärung |
| AK | [0|1] | inaktiv | aktiv |
| AE | [text] | DynDNS Domain (yourhost.ourdomain.ext) |
| US | [text] | Benutzername des DynDNS Account |
| PW | [text] | Password des DynDNS Account |
| MX | [text] | Maildomäne (mail.exchanger.ext) |
| MB | [YES|NO] | Maildomäne als Backupeintrag setzen |
| WC | [ON|OFF|NOCHG] | Wildcard im DNS setzen |
| OF | [YES|NO] | Hostname OFF-Line setzen (Bezahl-Account nötig) |
| PS | [text] | Proxy-Server falls nötig (z.B. 63.164.68.106) |
| PP | [text] | Proxy-Server Port (8080) |
| PN | [text] | Kein Proxy für (z.B.: localhost, no) |
Die Testdatei "server.ini" im ROOT des Servers enthällt dann nur noch den/die zu testenden Servernamen :
yourhost.ourdomain.ext
myhost.mydomain.ext
|
und kann beliebig viele Einträge haben.
Stand : 20/05/2004
|
|
|
EventShop, Veranstaltungsplanung, lto Label, lto Etiketten, andreas krueger, andreas krüger, browsercap, berlin, free counter, euro tausch portal, euro münzen, euro muenzen, euro coins, haltestelle, proxy, router, netgear
|
|