scripts/mcbot.cgi
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 26 Feb 2010 01:42:46 +0100
changeset 49 59b09b0aeb96
parent 33 56571d34d754
permissions -rwxr-xr-x
safe_strncpy replaces the insecure strncpy function strncpy copies up to n bytes and does not terminate it, except the null byte is in the first n bytes... committer: Markus Bröker <mbroeker@largo.homelinux.org>

#!/usr/bin/perl -W

use strict;

my $line;
my $a;
my $b;

print "CONTENT-TYPE: text/html\n\n";

print "<html>\n\t<head>\n\t\t<title>Factoids</title>\n\t</head>\n<body>\n";
open(FD, "dbtool -l |") or die("Cannot open file");

foreach $line(<FD>) {
	($a, $b) = split(/:/, $line, 2);
	$a =~ s/^[\t ]+//;					# skip blanks
	$b =~ s/^[\t ]+//;					# skip blanks
	$b =~ s/[\n]+//;					# for html source :)

    if ( $b && !($a =~ /mcbot/)) {
        if($b =~ /^http/ ) {
            print "$a - <a href=\"$b\">$b</a><br>";
        } else {
            print "$a - $b<br>";
        }
    }
}

print "\n<br>$a\n";

print "</body></html>\n";
close(FD);