--- /dev/null
+#!/usr/bin/perl
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use CGI;
+use Net::DNS;
+use FindBin;
+use Cwd qw( abs_path );
+
+$| = 1;
+my $q = new CGI();
+
+my $log_dir = $FindBin::RealBin . "/../log";
+unless ( -d $log_dir ) {
+ die "Logverzeichnis '" . $log_dir . "' nicht gefunden.\n";
+}
+$log_dir = abs_path($log_dir);
+my $logfile = $log_dir . "/set.log";
+my $errorlog = $log_dir . "/set.error.log";
+
+my $account = $q->param('account') || '';
+my $passwd = $q->param('passwd') || '';
+my $host = $q->param('host') || '';
+my $do_mx = $q->param('do_mx');
+my $do_wildcard = $q->param('do_wildcard');
+my $output_type = $q->param('output_type');
+my $test = $q->param('test');
+my $ttl = $q->param('ttl') || 120;
+
+my $success = ( $account eq 'uhu' and $passwd eq 'banane' and $host eq 'home.dyn.brehm-online.com' ) ? 1 : 0;
+my $reason = 'Ungültige Angaben.';
+
+my $ip = $ENV{'REMOTE_ADDR'};
+unless ( $ip ) {
+ $success = 0;
+ $reason = 'Wurde nicht als CGI-Anwendung gestartet.';
+}
+
+my $title = 'Dyn-DNS-Eintrag';
+
+if ( $success and not $test ) {
+
+ my $domain = 'dyn.brehm-online.com';
+ my $update = Net::DNS::Update->new($domain);
+ $update->push( 'update' => rr_del( $host ) );
+ $update->push( 'update' => rr_add( $host . ". " . $ttl . " A " . $ip ) );
+ #$update->push( 'update' => rr_add( '*.' . $host . ". " . $ttl . " A " . $ip ) ) if $do_wildcard;
+ #$update->push( 'update' => rr_add( $host . ". " . $ttl . " MX 10 " . $host . "." ) ) if $do_mx;
+
+ my $res = Net::DNS::Resolver->new;
+ $res->nameservers('127.0.0.1');
+
+ my $reply = $res->send($update);
+
+ # Did it work?
+ if ($reply) {
+ unless ($reply->header->rcode eq 'NOERROR') {
+ $reason = 'Update fehlgeschlagen: ' . $reply->header->rcode;
+ $success = 0;
+ }
+ } else {
+ $reason = 'Update fehlgeschlagen: ' . $reply->errorstring;
+ $success = 0;
+ }
+
+}
+
+print $q->header(
+ '-type' => 'text/html',
+ '-expires' => '-1h',
+ '-charset' => 'utf-8',
+);
+
+print $q->start_html(
+ '-title' => $title,
+ '-author' => 'frank@brehm-online.com',
+ '-meta' => {
+ 'copyright' => 'copyright 2008 Frank Brehm'
+ },
+ '-style' => {
+ 'src'=>'/styles/style1.css'
+ },
+ '-BGCOLOR' => 'white',
+ '-TEXT' => 'navy',
+);
+
+print $q->h1($title) . "\n";
+if ( $success ) {
+ print $q->h2( sprintf( "Die Anmeldung von Host '%s' mit der IP '%s' war ERFOLGREICH.", $host, $ip ) ) . "\n";
+}
+else {
+ print $q->h2( "Die Anmeldung war NICHT erfolgreich." ) . "\n";
+ print $q->dl( $q->dt( $q->b( "Grund:" ) ) . "\n" . $q->dd($reason) . "\n" ) . "\n";
+}
+
+if ( $success ) {
+ if ( open LOG, ">>", $logfile ) {
+ printf LOG "[%s]: Host '%s' mit IP '%s' für '%s' angemeldet.\n", scalar(localtime()), $host, $ip, $account;
+ close LOG;
+ }
+ else {
+ warn "Konnte Log '" . $logfile . "' nicht zum Schreiben oeffnen: " . $!;
+ }
+}
+elsif ( $ip ) {
+ if ( open LOG, ">>", $errorlog ) {
+ printf LOG "[%s]: Remote Host '%s' mit Fehlern: Host '%s', Account '%s', Passwort '%s', Grund '%s'.\n", scalar(localtime()), $ip, $host, $account, $passwd, $reason;
+ close LOG;
+ }
+ else {
+ warn "Konnte Log '" . $errorlog . "' nicht zum Schreiben oeffnen: " . $!;
+ }
+}
+
+print $q->end_html() . "\n";