Create daily Logs of your public MUCs

Hello,

I created a little Perlscript which creates daily Logs of your public MUCs. Everyone who can read german can see this script in action on my site (https://im.goesberserk.de). This script runs every day at midnight und just fetches all public conversations since last midnight to now from the db. It is tested with Openfire 3.6.x and Debian etch. And here ist the script:

#!/usr/bin/perl -w use DBI;
use Time::Local; my $server = "DBI:mysql:openfire:localhost:3306";
my $user = "db_username";
my $pass = "db_pass";
my $basepath = "path_to_webserver_root";
my $cssfile = "url_to_css_file"; my %monate = ( '00',"januar",'01',"februar",'02',"maerz",'03',"april",'04',"mai",'05',"juni",'06',"juli",'07',"august",'08',"september",'09',"oktober",'10',"november",'11',"dezember" ); my %roomids = ();
my %roomname = ();
my% roomdesc = (); my $dbh = DBI->connect($server, $user, $pass) or die "Kann nicht zur MySQL-Datenbank verbinden"; my $sql = "select roomID,name,naturalName,description from ofMucRoom where publicRoom=1";
my $sth = $dbh->prepare($sql);
$sth->execute(); while(@ergebnis=$sth->fetchrow_array)
{
        $roomids{ $ergebnis[0] } = $ergebnis[1];
        $roomname{ $ergebnis[1] } = $ergebnis[2];
        $roomdesc{ $ergebnis[1] } = $ergebnis[3];
} $sth->finish(); while(my ($key, $value) = each(%roomids))
{
        my $roompath = $basepath.$value."/";
        if(! -d $roompath){
                mkdir($basepath.$value);
        }
        my @timedata = localtime(time);
        my $yearpath = $roompath.($timedata[5]+1900)."/";
        my $time = timelocal(0,0,0,($timedata[3]-1),$timedata[4],$timedata[5]+1900)*1000;
        $sql = "select logTime,nickname,subject,body,sender from ofMucConversationLog where roomID=".$key." and logTime>".$time;
        $sth = $dbh->prepare($sql);
        $sth->execute();
        if($sth->rows > 0){
                my $monthpath = $yearpath.$monate{$timedata[4]}."/";
                if(! -d $yearpath){
                        mkdir($yearpath);
                }
                if(! -d $monthpath){
                        mkdir($monthpath);
                }
                my $filename = $monthpath.($timedata[3]-1).".html";
                my $fileresult = open(FH, "> $filename");
                print FH "<html>\n";
                print FH "<head>\n";
                print FH "<title>".$roomname{$value}.": ".($timedata[3]-1).".".($timedata[4]+1).".".($timedata[5]+1900)."</title>\n";
                print FH "<LINK href=\"$cssfile\" rel=\"stylesheet\" type=\"text/css\">\n";
                print FH "</head>\n";
                print FH "<body>\n";
                print FH "<h1>Chatlog für den Raum ".$roomname{$value}." vom ".($timedata[3]-1).".".($timedata[4]+1).".".($timedata[5]+1900)."</h1>\n";
                print FH "<br>\n";
                print FH "<br>\n";
                print FH "<table class=\"overview\">\n";
                print FH "<tr>\n";
                print FH "<th>Raumname</th><th>".$roomname{$value}."</th>\n";
                print FH "</tr>\n";
                print FH "<tr>\n";
                print FH "<th>Beschreibung</th><th>".$roomdesc{$value}."</th>\n";
                print FH "</tr>\n";
                print FH "<tr>\n";
                print FH "<th>Datum</th><th>".($timedata[3]-1).".".($timedata[4]+1).".".($timedata[5]+1900)."</th>\n";
                print FH "</tr>\n";
                print FH "</table>\n";                 my %nicknames = ();
                my $ccounter = 0;                 print FH "<table class=\"chatlog\">\n";                 while(@result=$sth->fetchrow_array)
                {
                        my @messagetime = localtime($result[0]/1000);                         $result[4] =~ /(.*?)\//;
                        my $jid = $1;
                        if(!exists $nicknames{ $jid }){
                                $nicknames{ $jid } = "nick".$ccounter;
                                $ccounter++;
                        }
                        if(defined($result[3])){
                                print FH "<tr>\n";
                                print FH "<th>$messagetime[2]:$messagetime[1]:$messagetime[0]</th><th><span class=\"$nicknames{$jid}\">$result[1]</span></th><th>$result[3]</th>\n";
                                print FH "</tr>\n";
                        }
                        if(defined($result[2])){
                                print FH "<tr>\n";
                                print FH "<th>$messagetime[2]:$messagetime[1]:$messagetime[0]</th><th colspan=\"2\"><span class=\"$nicknames{$jid}\">$result[1] setzt das Raumthema auf $result[2]</span></th>\n";
                                print FH "</tr>\n";
                        }
                }
                print FH "</table>\n";
                print FH "</body>\n";
                print FH "</html>\n";
                close(FH);
        }
        $sth->finish();
} $dbh->disconnect();

All non-german speakers should edit some parts of the html-output according to their language.