- Change language to:
- Change language to:
The lacking features of v1.2 had been integrated into v1.3, we now support a configuration file not only for the configureable items but also for the listed mirrors. You can now easily define the mirrors and their administrators which should give you much more flexibility. You can see the script down here, included is a sample configuration file with the configureable options. Comments? Please let me know!
#!/usr/bin/perl
###########################################################################
# $Id: check_honeynet.pl,v 1.8 2006/02/20 07:40:25 remko Exp $
###########################################################################
###########################################################################
# Copyright (C) 2005, Remko Lodder <remko @ FreeBSD.org>. All rights reserved.
# Copyright (C) 2006, Remko Lodder <remko @ FreeBSD.org>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS “AS IS” AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
###########################################################################
###########################################################################
# Contributors:
# Ivo Naninck,
# Marc Plaisier,
# Mart van de Wege
#
# Script:
# This is a stand alone script written for honeynet.org. It’s purpose is
# to check the listed mirrors to see which one is outdated and notify
# the administrator of the outdated mirror if needed. This way the
# mirrors will always be within a certain timeframe and can be removed
# if they are too outdated.
#
# Mart van de Wege recently told me that it would be nice to have a
# higher level mail module. I do not want to do so because i think
# this script should be as low level as possible, requiring as less
# modules as possible. Making it easier to run this on various
# machines without needing to install the entire CPAN to function.
#
# Written in colaboration with Lance Spitzner <lance @ honeynet.org>
###########################################################################
use strict;
use warnings;
use Net::SMTP;
use Getopt::Std;
use LWP::Simple;
###########################################################################
# variables. All configurable options are defined below. Please adjust them
# to your need.
###########################################################################
# create two hashes which can be used to read our config variables from the
# configuration file. Devided between configuration items and mirror
# information.
my %CONFIG = ();
my %MIRRORS = ();
# create the option hash, we will use that later to add our option flags.
my %option = ();
# Version, author and script specific behaviour
my $CONFIGFILE = "./honeynet.cf";
my $author = ‘Remko Lodder <remko @ FreeBSD.org>’; # Name of the author, respect the license.
my $name = ‘check_honeynet.pl’; # Our scriptname.
my $version = ‘1.3′; # Our version.
my $honeynet_ctime = time();
###########################################################################
# Do not edit anything below this line unless you know what you are doing.
###########################################################################
# Read the configuration before we will use anything else.
open (CONF, "< $CONFIGFILE") || die "Unable to open $CONFIGFILE: $!\n";
my ($config,$mirrors);
while (<CONF>) {
chomp;
if ( /\[CONFIG\]/ )
{
$config = 1;
$mirrors = 0;
next;
}
if ( /\[MIRRORS\]/ )
{
$config = 0;
$mirrors = 1;
next;
}
s/#.*//;
s/^\s+//;
s/\s+$//;
next unless length;
my ($var, $value) = split(/\s*=\s*/, $_, 2);
if ( $config eq "1" )
{
$CONFIG{$var} = $value;
}
elsif ( $mirrors eq "1" )
{
$MIRRORS{$var} = $value;
}
else
{
print "It seems that your configurationfile is empty, please investigate\n";
}
}
close CONF;
getopts("chpt", \%option);
if ($option{c})
{
if (defined $CONFIG{verbose})
{
writeln("$name: Starting");
writeln("$name: Writing timestamp");
}
create_timestamp($CONFIG{probefile});
if (defined $CONFIG{verbose})
{
writeln("$name: Finishing");
}
}
elsif ($option{p})
{
if (defined $CONFIG{verbose})
{
writeln("$name: Starting");
writeln("$name: Processing mirrors");
}
process_mirrors(%MIRRORS);
if (defined $CONFIG{verbose})
{
writeln("$name: Finishing");
}
}
# test mode, printout information on screen.
elsif ($option{t})
{
$CONFIG{enable_mail} = 0;
writeln("$name: Starting");
writeln("$name: Processing mirrors");
process_mirrors(%MIRRORS);
writeln("$name: Finishing");
}
# People expect a help option, provide it for them.
elsif ($option{h})
{
print_help();
}
# No valid options had been given, fallback to the help
# information.
else
{
print_help();
}
sub print_help
{
writeln("$name");
writeln("Syntax: $name [-c | -h | -p | -t ]\n");
writeln("-c");
writeln(" Create the timestamp for the local machine. This timestamp");
writeln(" can be used to determine when the mirrors were last updated.");
writeln("");
writeln("-h");
writeln(" Print this help information");
writeln("");
writeln("-p");
writeln(" Check the status of the mirrors and report that status.");
writeln("");
writeln("-t");
writeln(" Test mode, do not send emails but print the information on");
writeln(" the screen. This overrides the email settings you might have");
writeln(" set in the file");
writeln("Version: $version");
writeln("Originally written by: $author");
}
sub writeln
{
# Write the string provided in the function
my $message = shift;
print "$message\n";
}
sub create_timestamp
{
my $probefile = shift;
open(F_OUT, "> $probefile");
print F_OUT time();
close F_OUT;
}
sub fetch_data
{
my $source = shift;
my $sourcefile = shift;
my $data = get "${source}${sourcefile}";
if ($data)
{
return $data;
}
else
{
# It seems we encountered an error, give an explaination of what happened
# and exit the program with an error flag raised.
writeln("There were problems fetching the status information from $source");
writeln("We cannot continue right now, the problem will cause the program");
writeln("to exit. Please investigate this.");
exit(1);
}
}
sub process_mirrors
{
my %mirror_time;
my %mirror_list = @_;
for my $target ( sort keys %mirror_list )
{
$mirror_time{$target} = fetch_data($target,$CONFIG{sourcefile});
my $mirror_ctime = $mirror_time{$target};
my $mirror_difftime = $honeynet_ctime - $mirror_ctime;
if ($CONFIG{mirror_difftime} < $CONFIG{timeout} )
{
writeln("OK: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
else
{
# The email option is enabled and we found an outdated mirror
# jump to the email_report function.
if ($CONFIG{enable_mail})
{
email_report($target,$mirror_ctime);
}
# We do not want to send a email, print a warning instead.
else
{
writeln("BAD: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
}
}
}
sub email_report
{
my $target = shift;
my $mirror_ctime = shift;
my $smtp = Net::SMTP->new("$CONFIG{mailhost}", Hello => "$CONFIG{ehlohost}");
$mirror_ctime = scalar localtime($mirror_ctime);
$smtp->to("$MIRRORS{$target}");
$smtp->data();
$smtp->datasend("EHLO $CONFIG{ehlohost}\r\n");
$smtp->datasend("MAIL FROM: <$CONFIG{fromaddr}>\n");
$smtp->datasend("RCPT TO: <$MIRRORS{$target}>\n");
# We need to sleep a little so that all smtp servers can process the email.
# For example: postfix complains about unauthorized pipelining when this is not defined.
sleep(2);
$smtp->datasend("DATA\r\n");
$smtp->datasend("To: <$MIRRORS{$target}>\n");
$smtp->datasend("From: $CONFIG{fromaddr}\n");
$smtp->datasend("Subject: $target seems to be outdated, please investigate\n");
$smtp->datasend("\n\n");
$smtp->datasend("Hello $MIRRORS{$target},\n\n");
$smtp->datasend("You are recieving this email because your mirror ($target) seems to be outdated.\n");
$smtp->datasend("\n");
$smtp->datasend("At this moment it seems that your mirror was last updated on $mirror_ctime.\n");
$smtp->datasend("Could you please check if everything is working as expected?\n\n");
$smtp->datasend("If there is something wrong or you do no longer wish to be a mirror, please notify $CONFIG{honeyadmin}\n\n");
$smtp->datasend("–\n");
$smtp->datasend("Thanks for supporting the efforts of Honeynet\n");
$smtp->datasend("The Honeynet mirror admins\n");
$smtp->dataend();
$smtp->quit;
}
$ cat honeynet.cf
# $Id: honeynet.cf,v 1.3 2006/02/20 08:00:50 remko Exp $
[CONFIG]
# Misc config
source = http://www.honeynet.org
sourcefile = /misc/mirrorprobe.txt
probefile = ./mirrorprobe.txt
# Timeout is one week. (Seconds).
timeout = 604800
verbose = 1
# Mail config
enable_mail = 1
mailhost = caelis.elvandar.org
ehlohost = caelis.elvandar.org
honeyadmin = "Lance Spitzner" <lancename@honeynet.org>
fromaddr = "Remko Lodder" <myname@elvandar.org>
[MIRRORS]
http://www.evilcoder.org = youremail@elvandar.org
http://www.freebsd-nl.org = youremail@elvandar.org
- Change language to:
A couple of new scripts had been added. See them in the latest news and downloads/perl section. For comments please contact me so that i can either update the programs or correct things when they are not OK.
Continue reading »
- Change language to:
After feedback and a little development, 1.2 has seen the light.
#!/usr/bin/perl
###########################################################################
# $Id: check_honeynet-evilcoder.pl,v 1.7 2006/02/10 10:59:51 remko Exp $
###########################################################################
###########################################################################
# Copyright (C) 2005, Remko Lodder <remko at FreeBSD.org>. All rights reserved.
# Copyright (C) 2006, Remko Lodder <remko at FreeBSD.org>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS “AS IS” AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
###########################################################################
###########################################################################
# Contributors:
# Ivo Naninck,
# Marc Plaisier,
# Mart van de Wege
#
# Script:
# This is a stand alone script written for honeynet.org. It’s purpose is
# to check the listed mirrors to see which one is outdated and notify
# the administrator of the outdated mirror if needed. This way the
# mirrors will always be within a certain timeframe and can be removed
# if they are too outdated.
#
# Mart van de Wege recently told me that it would be nice to have a
# higher level mail module. I do not want to do so because i think
# this script should be as low level as possible, requiring as less
# modules as possible. Making it easier to run this on various
# machines without needing to install the entire CPAN to function.
#
# Written in colaboration with Lance Spitzner <lance at honeynet.org>
###########################################################################
use strict;
use warnings;
use Net::SMTP;
use Getopt::Std;
use LWP::Simple;
###########################################################################
# variables. All configurable options are defined below. Please adjust them
# to your need.
###########################################################################
# create the option hash, we will use that later to add our option flags.
my %option = ();
# Online resources (not everything is used yet).
my $source = ‘http://www.honeynet.org’;
my $sourcefile = ‘/path/to/mirrorprobe.txt’;
my $totalpath = "${source}${sourcefile}";
# path to the local mirrorprobe file
my $probefile = ‘/path/to/mirrorprobe.txt’;
# Timeout and current time declaration
my $timeout = 60*60*24*7;
my $honeynet_ctime = time();
# Email settings.
my $enable_mail = 1;
my $mailhost = ‘caelis.elvandar.org’;
my $ehlohost = "$mailhost"; # The EHLO host is the host used
# for greeting the other server.
# You can use the mailhost, or define
# your own.
# Honeynet mirror admins.
my $honeyadmin = ‘"Lance Spitzner" <lancename@honeynet.org>’;
my $fromaddr = ‘"Remko Lodder" <myname@elvandar.org>’; # Change me before production.
# Version, author and script specific behaviour
my $author = ‘Remko Lodder <myname@elvandar.org>’; # Name of the author, respect the license.
my $name = ‘check_honeynet.pl’; # Our scriptname.
my $version = ‘1.2′; # Our version.
my $verbose = 1; # Do we want to have more info when the script runs?
# Example mirror_list.
my %mirror_list = ( ‘http://www.evilcoder.org’ => ‘youremail@elvandar.org’,
‘http://www.freebsd-nl.org’ => ‘youremail@elvandar.org’
);
###########################################################################
# Do not edit anything below this line unless you know what you are doing.
###########################################################################
getopts("chpt", \%option);
if ($option{c})
{
if (defined $verbose)
{
writeln("$name: Starting");
writeln("$name: Writing timestamp");
}
create_timestamp($probefile);
if (defined $verbose)
{
writeln("$name: Finishing");
}
}
elsif ($option{p})
{
if (defined $verbose)
{
writeln("$name: Starting");
writeln("$name: Processing mirrors");
}
process_mirrors(%mirror_list);
if (defined $verbose)
{
writeln("$name: Finishing");
}
}
# test mode, printout information on screen.
elsif ($option{t})
{
my $enable_mail = 0;
writeln("$name: Starting");
writeln("$name: Processing mirrors");
process_mirrors(%mirror_list);
writeln("$name: Finishing");
}
# People expect a help option, provide it for them.
elsif ($option{h})
{
print_help();
}
# No valid options had been given, fallback to the help
# information.
else
{
print_help();
}
sub print_help
{
writeln("$name");
writeln("Syntax: $name [-c | -h | -p | -t ]\n");
writeln("-c");
writeln(" Create the timestamp for the local machine. This timestamp");
writeln(" can be used to determine when the mirrors were last updated.");
writeln("");
writeln("-h");
writeln(" Print this help information");
writeln("");
writeln("-p");
writeln(" Check the status of the mirrors and report that status.");
writeln("");
writeln("-t");
writeln(" Test mode, do not send emails but print the information on");
writeln(" the screen. This overrides the email settings you might have");
writeln(" set in the file");
writeln("Version: $version");
writeln("Originally written by: $author");
}
sub writeln
{
# Write the string provided in the function
my $message = shift;
print "$message\n";
}
sub create_timestamp
{
my $probefile = shift;
open(F_OUT, "> $probefile");
print F_OUT time();
close F_OUT;
}
sub fetch_data
{
my $source = shift;
my $sourcefile = shift;
my $data = get "${source}${sourcefile}";
if ($data)
{
return $data;
}
else
{
# It seems we encountered an error, give an explaination of what happened
# and exit the program with an error flag raised.
writeln("There were problems fetching the status information from $source");
writeln("We cannot continue right now, the problem will cause the program");
writeln("to exit. Please investigate this.");
exit(1);
}
}
sub process_mirrors
{
my %mirror_time;
my %mirror_list = @_;
for my $target ( sort keys %mirror_list )
{
$mirror_time{$target} = fetch_data($target,$sourcefile);
my $mirror_ctime = $mirror_time{$target};
my $mirror_difftime = $honeynet_ctime - $mirror_ctime;
if ($mirror_difftime < $timeout )
{
writeln("OK: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
else
{
# The email option is enabled and we found an outdated mirror
# jump to the email_report function.
if ($enable_mail)
{
email_report($target,$mirror_ctime);
}
# We do not want to send a email, print a warning instead.
else
{
writeln("BAD: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
}
}
}
sub email_report
{
my $target = shift;
my $mirror_ctime = shift;
my $smtp = Net::SMTP->new("$mailhost", Hello => "$ehlohost");
$mirror_ctime = scalar localtime($mirror_ctime);
$smtp->to("$mirror_list{$target}");
$smtp->data();
$smtp->datasend("EHLO $ehlohost\r\n");
$smtp->datasend("MAIL FROM: <$fromaddr>\n");
$smtp->datasend("RCPT TO: <$mirror_list{$target}>\n");
# We need to sleep a little so that all smtp servers can process the email.
# For example: postfix complains about unauthorized pipelining when this is not defined.
sleep(2);
$smtp->datasend("DATA\r\n");
$smtp->datasend("To: <$mirror_list{$target}>\n");
$smtp->datasend("From: $fromaddr\n");
$smtp->datasend("Subject: $target seems to be outdated, please investigate\n");
$smtp->datasend("\n\n");
$smtp->datasend("Hello $mirror_list{$target},\n\n");
$smtp->datasend("You are recieving this email because your mirror ($target) seems to be outdated.\n");
$smtp->datasend("\n");
$smtp->datasend("At this moment it seems that your mirror was last updated on $mirror_ctime.\n");
$smtp->datasend("Could you please check if everything is working as expected?\n\n");
$smtp->datasend("If there is something wrong or you do no longer wish to be a mirror, please notify $honeyadmin\n\n");
$smtp->datasend("–\n");
$smtp->datasend("Thanks for supporting the efforts of Honeynet\n");
$smtp->datasend("The Honeynet mirror admins\n");
$smtp->dataend();
$smtp->quit;
}
- Change language to:
One day it became needed for me to generate the most simple index one could find to index some JPG and MOV files (yes capitals), therefor i wrote the below script (really easy). You can use it with the BSD License ofcourse.
#!/usr/bin/perl T
use CGI;
use warnings;
use diagnostics;
use strict;
my $CGI = new CGI;
my $file;
my $URI = "http://yourdomain/yoururl";
my $path = "/local/path/to/your/images/and/movies";
my $title = "The title of the generated index file";
opendir(DIR, $path);
my @files = grep { /\.JPG|.MOV$/ } readdir(DIR);
closedir(DIR);
print $CGI->header();
print $CGI->start_html("$title");
print $CGI->p({-align=>"center"}, "$title");
print "<table width=’100%’>";
foreach $file (@files) {
print "<tr>";
print "<td align=’center’>";
print $CGI->a({href=>"$URI/$file"},"$file");
print "</td>";
print "</tr>";
}
print "</table>";
print $CGI->end_html();
Continue reading »
- Change language to:
Recently we launched a new site for the FreeBSD Dutch Documentation Project. The URL is http://www.freebsd-nl.org and totally focussed on the Dutch documentation project. We have the doc and www tree available for you. Please look at the navigation bar to browse to them directly.
Continue reading »
- Change language to:
Well, no much updates from me lately. Been busy doing other things, living my life and simply being happy with the love of my life and our child (Luca). This does not mean however that i stopped doing things for the internet, FreeBSD and other resources like Honeynet. I wrote a new script for them and posted it on the site. Please check it out and send me any comments that you might or might not have. It is a very simple script , basically my first custom written application which is not for myself but for others and I kinda liked it, esp. since most of what i wrote was the first time i did things like that.I am still very novice in perl application writing, so again.. please provide feedback!Check_Honeynet -v1.1.pl is located here. Continue reading »
- Change language to:
There is a new version available for the honeynet check script. This script is more advanced and more developed. Licensed under the BSD license, written by remko _at_ FreeBSD dot org.
#!/usr/bin/perl -w
###########################################################################
# $Id: check_honeynet.pl,v 1.1 2006/02/05 20:07:41 remko Exp $
###########################################################################
###########################################################################
# Copyright (C) 2005, Remko Lodder <remko@FreeBSD.org>. All rights reserved.
# Copyright (C) 2006, Remko Lodder <remko@FreeBSD.org>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS “AS IS” AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
###########################################################################
###########################################################################
# This is a stand alone script written for honeynet.org. It’s purpose is
# to check the listed mirrors to see which one is outdated and notify
# the administrator of the outdated mirror if needed. This way the
# mirrors will always be within a certain timeframe and can be removed
# if they are too outdated.
# Written in colaboration with Lance Spitzner <lancename@honeynet.org>
###########################################################################
use strict;
use warnings;
use Net::SMTP;
use Getopt::Std;
use LWP::Simple;
###########################################################################
# variables. All configurable options are defined below. Please adjust them
# to your need.
###########################################################################
# create the option hash, we will use that later to add our option flags.
my %option = ();
# Online resources (not everything is used yet).
my $source = ‘http://www.honeynet.org’;
my $sourcefile = ‘/path/to/mirrorprobe.txt’;
my $totalpath = "${source}${sourcefile}";
# path to the local mirrorprobe file
my $probefile = ‘/path/to/mirrorprobe.txt’;
# Timeout and current time declaration
my $timeout = 60*60*24*7;;
my $honeynet_ctime = time();
# Email settings.
my $enable_mail = 1;
my $mailhost = ‘caelis.elvandar.org’;
my $ehlohost = ‘caelis.elvandar.org’;
# Honeynet mirror admins.
my $honeyadmin = ‘"Lance Spitzner" <lancename@honeynet.org>’;
my $fromaddr = ‘"Remko Lodder" <myname@elvandar.org>’; # Change me before production.
# Version, author and script specific behaviour
my $author = ‘Remko Lodder <myname@elvandar.org’;
my $name = ‘check_honeynet.pl’;
my $version = ‘1.1b’;
my $verbose = 1; # Enable this if you want the
# script to ouput something at all.
# Example mirror_list.
my %mirror_list = ( ‘http://www.evilcoder.org’ => ‘youremail@elvandar.org’,
‘http://www.freebsd-nl.org’ => ‘youremail@elvandar.org’
);
###########################################################################
# Do not edit anything below this line unless you know what you are doing.
###########################################################################
getopts("chp", \%option);
if ($option{c})
{
if (defined $verbose)
{
writeln("$name: Starting");
writeln("$name: Writing timestamp");
}
create_timestamp($probefile);
if (defined $verbose)
{
writeln("$name: Finishing");
}
}
elsif ($option{p})
{
if (defined $verbose)
{
writeln("$name: Starting");
writeln("$name: Processing mirrors");
}
process_mirrors(%mirror_list);
if (defined $verbose)
{
writeln("$name: Finishing");
}
}
# People expect a help option, provide it for them.
elsif ($option{h})
{
print_help();
}
# No valid options had been given, fallback to the help
# information.
else
{
print_help();
}
sub print_help
{
writeln("$name");
writeln("Syntax: $name [-c | -h | -p]\n");
writeln("-c");
writeln(" Create the timestamp for the local machine. This timestamp");
writeln(" can be used to determine when the mirrors were last updated.");
writeln("");
writeln("-h");
writeln(" Print this help information");
writeln("");
writeln("-p");
writeln(" Check the status of the mirrors and report that status.");
writeln("");
writeln("Version: $version");
writeln("Originally written by: $author");
}
sub writeln
{
# Write the string provided in the function
my $message = shift;
print "$message\n";
}
sub create_timestamp
{
my $probefile = shift;
open(F_OUT, "> $probefile");
print F_OUT time();
close F_OUT;
}
sub process_mirrors
{
my %mirror_list = @_;
check_status(%mirror_list);
}
sub fetch_data
{
my $source = shift;
my $sourcefile = shift;
my $data = get "${source}${sourcefile}";
if ($data)
{
return $data;
}
else
{
# It seems we encountered an error, give a explaination of what happened
# and exit the program with an error flag raised.
writeln("There were problems fetching the status information from $source");
writeln("We cannot continue right now, the problem will cause the program");
writeln("to exit. Please investigate this.");
exit(1);
}
}
sub check_status
{
my %mirror_time;
my %mirror_list = @_;
for my $target ( sort keys %mirror_list )
{
$mirror_time{$target} = fetch_data($target,$sourcefile);
my $mirror_ctime = $mirror_time{$target};
my $mirror_difftime = $honeynet_ctime - $mirror_ctime;
if ($mirror_difftime < $timeout )
{
writeln("OK: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
else
{
# The email option is enabled and we found an outdated mirror
# jump to the email_report function.
if ($enable_mail)
{
email_report($target,$mirror_ctime);
}
# We do not want to send a email, print a warning instead.
else
{
writeln("BAD: $target\t\tchanged: ");
print scalar localtime($mirror_ctime);
writeln("");
}
}
}
}
sub email_report
{
my $target = shift;
my $mirror_ctime = shift;
my $smtp = Net::SMTP->new("$mailhost", Hello => "$ehlohost");
$mirror_ctime = scalar localtime($mirror_ctime);
$smtp->to("$mirror_list{$target}");
$smtp->data();
$smtp->datasend("EHLO $ehlohost\r\n");
$smtp->datasend("MAIL FROM: <$fromaddr>\n");
$smtp->datasend("RCPT TO: <$mirror_list{$target}>\n");
# We need to sleep a little so that all smtp servers can process the email.
# For example: postfix complains about unauthorized pipelining when this is not defined.
sleep(2);
$smtp->datasend("DATA\r\n");
$smtp->datasend("To: <$mirror_list{$target}>\n");
$smtp->datasend("From: $fromaddr\n");
$smtp->datasend("Subject: $target seems to be outdated, please investigate\n");
$smtp->datasend("\n\n");
$smtp->datasend("Hello $mirror_list{$target},\n\n");
$smtp->datasend("You are recieving this email because your mirror ($target) seems to be outdated.\n");
$smtp->datasend("\n");
$smtp->datasend("At this moment it seems that your mirror was last updated on $mirror_ctime.\n");
$smtp->datasend("Could you please check if everything is working as expected?\n\n");
$smtp->datasend("If there is something wrong or you do no longer wish to be a mirror, please notify $honeyadmin\n\n");
$smtp->datasend("–\n");
$smtp->datasend("Thanks for supporting the efforts of Honeynet\n");
$smtp->datasend("The honeynet mirror admins\n");
$smtp->dataend();
$smtp->quit;
}

