| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936 |
- #!/usr/bin/perl -w
- use strict;
- use Getopt::Long;
- # pisg - Perl IRC Statistics Generator
- #
- # Copyright (C) 2001 <Morten 'LostStar' Brix Pedersen> - morten@wtf.dk
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- my $config;
- my $words;
- # Values that _MUST_ be set below (unless you pass them on commandline)
- $conf->{channel} = "#channel"; # The name of your channel.
- $conf->{logfile} = "channel.log"; # The exact filename of the logfile
- $conf->{format} = "mIRC"; # logfile format. see FORMATS file
- $conf->{network} = "SomeIRCNet"; # Network the channels is using.
- $conf->{outputfile} = "index.html"; # The name of the html file to be generated
- $conf->{maintainer} = "MAINTAINER"; # The maintainer or bot which makes the logfile
- $conf->{pagehead} = "none"; # Some 'page header' file which you want to
- # include in top of the stats
- $conf->{configfile} = "pisg.cfg"; # Path to config file (aliases, ignores,
- # pics and more, see pisg.cfg for examples)
- $conf->{imagepath} = ""; # If your user pictures is located
- # some special directory, set the path here.
- $conf->{logdir} = ""; # If you specify a path to a dir here, then
- # pisg will take that dir, and parse ALL
- # logfiles in it, and create 1 HTML file
- # from it
- $conf->{lang} = 'EN'; # Language to use:
- # EN | DE | DK | FR | ES | PL
- $conf->{langfile} = 'lang.txt'; # Name of language file
- $conf->{prefix} = ""; # If you specify a string here and have $logdir
- # set, then only those files starting with
- # $prefix in $logdir will be read.
- # Here you can set the colors for your stats page..
- $conf->{bgcolor} = "#dedeee"; # Background color of the page
- $conf->{text} = "black"; # Normal text color
- $conf->{hbgcolor} = "#666699"; # Background color in headlines
- $conf->{hcolor} = "white"; # Text color in headline
- $conf->{hicell} = "#BABADD"; # Background color in highlighted cells
- $conf->{hicell2} = "#CCCCCC"; # Background color in highlighted cells
- $conf->{tdcolor} = "black"; # Color of text in tables
- $conf->{tdtop} = "#C8C8DD"; # Top color in some tables.
- $conf->{link} = "#0b407a"; # Color of links
- $conf->{vlink} = "#0b407a"; # Color of visited links
- $conf->{hlink} = "#0b407a"; # Color of hovered links
- $conf->{headline} = "#000000"; # Border color of headlines
- $conf->{rankc} = "#CCCCCC"; # Colors of 'ranks' (1,2,3,4)
- $conf->{pic1} = "pipe-blue.png"; # Bar-graphic-file for normal times
- $conf->{pic2} = "pipe-purple.png"; # Bar-graphic-file for top-times
- # Other things that you might set, but not everyone cares about them
- $conf->{minquote} = "25"; # Minimal value of letters for a random quote
- $conf->{maxquote} = "65"; # Maximum value of letters for a random quote
- $conf->{wordlength} = "5"; # The minimum number of chars an interesting
- # word may be (in 'most referenced words')
- $conf->{activenicks} = "25"; # Number of nicks to show in the 'top 25'
- $conf->{activenicks2} = "30"; # Nicks to show in 'these didnt make it...'
- $conf->{topichistory} = "3"; # How many topics to show in 'latest topics'
- $conf->{nicktracking} = 0; # Track nickchanges and create aliases (can
- # be slow, so it's disabled by default)
- $conf->{timeoffset} = "+0"; # A time offset on the stats page - if your
- # country has a different timezone than the
- # machine where the stats are being
- # generated, then for example do +1
- # to add 1 hour to the time
- $words->{foul} = "ass fuck bitch shit scheisse scheiße kacke arsch ficker ficken schlampe"; # If not set in pisg.cfg set your Foulwords here.
- # You shouldn't care about anything below this point
- $conf->{debug} = 0; # 0 = Debugging off, 1 = Debugging on
- $conf->{debugfile} = "debug.log"; # Path to debug file(must be set if $debug == 1)
- $conf->{version} = "v0.18-cvs";
- my ($lines, $kicked, $gotkicked, $smile, $longlines, $time, $timestamp, %alias,
- $normalline, $actionline, $thirdline, @ignore, $line, $processtime, @topics,
- %monologue, %kicked, %gotkick, %line, %length, %qpercent, %lpercent, %sadface,
- %smile, $nicks, %longlines, %mono, %times, %question, %loud, $totallength,
- %gaveop, %tookop, %joins, %actions, %sayings, %wordcount, %lastused, %gotban,
- %setban, %foul, $days, $oldtime, $lastline, $actions, $normals, %userpics,
- %userlinks, %T, $repeated, $lastnormal, $foulwords);
- sub main
- {
- print "pisg $conf->{version} - Perl IRC Statistics Generator\n\n";
- init_config(); # Init config. (Aliases, ignores, other options etc.)
- init_words(); # Init words. (Foulwords etc)
- init_pisg(); # Init commandline arguments and other things
- init_lineformats(); # Attempt to set line formats in compliance with user specification (--format)
- init_debug(); # Init the debugging file
- if ($conf->{logdir}) {
- parse_dir(); # Run through all logfiles in dir
- } else {
- parse_file($conf->{logfile}); # Run through the whole logfile
- }
- create_html(); # Create the HTML
- # (look here if you want to remove some of the
- # stats which you don't care about)
- close_debug(); # Close the debugging file
- print "\nFile was parsed succesfully in $processtime on $time.\n";
- }
- sub init_pisg
- {
- get_language_templates();
- $timestamp = time;
- if ($conf->{timeoffset} =~ /\+(\d+)/) {
- # We must plus some hours to the time
- $timestamp += 3600 * $1; # 3600 seconds per hour
- } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
- # We must remove some hours from the time
- $timestamp -= 3600 * $1; # 3600 seconds per hour
- }
- # Set useful values.
- $days = 1;
- $oldtime = "00";
- $lastline = "";
- $actions = "0";
- $normals = "0";
- $time = localtime($timestamp);
- $repeated = 0;
- $lastnormal = "";
- # Add trailing slash when it's not there..
- if (substr($conf->{imagepath}, -1) ne '/') {
- $conf->{imagepath} =~ s/(.*)/$1\//;
- }
- print "Statistics for channel $conf->{channel} \@ $conf->{network} by $conf->{maintainer}\n\n";
- }
- sub init_lineformats {
- # These are the regular expressions which matches the lines in the logfile,
- # and looks different if it's xchat, mIRC or whatever.
- # If you want to add support for a new format - you first have to add the
- # regex here, and then you also have to modify the parse subroutines called
- # 'parse_normalline()', 'parse_actionline()' and 'parse_thirdline()'
- if ($conf->{format} eq 'xchat') {
- $normalline = '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)';
- $actionline = '^(\d+):\d+:\d+ \*\s+(\S+) (.*)';
- $thirdline = '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)';
- } elsif ($conf->{format} eq 'mIRC') {
- $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
- $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
- $thirdline = '^\[(\d+):(\d+)\] \*\*\* (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
- } elsif ($conf->{format} eq 'eggdrop') {
- $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
- $actionline = '^\[(\d+):\d+\] Action: (\S+) (.*)';
- $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)';
- } elsif ($conf->{format} eq 'bxlog') {
- $normalline = '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)';
- $actionline = '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)';
- $thirdline = '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)';
- } elsif ($conf->{format} eq 'grufti') {
- $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
- $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
- $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
- } else {
- die("Logfile format not supported, check \$conf->{format} setting.\n");
- }
- }
- sub init_config
- {
- get_cmdlineoptions();
- if (open(CONFIG, $conf->{configfile})) {
- print "Using config file: $conf->{configfile}\n";
- my $lineno = 0;
- while (<CONFIG>)
- {
- $lineno++;
- my $line = $_;
- next if /^#/;
- if ($line =~ /<user.*>/) {
- my $nick;
- if ($line =~ /nick="([^"]+)"/) {
- $nick = $1;
- } else {
- print STDERR "Warning: no nick specified in $conf->{configfile} on line $lineno\n";
- next;
- }
- if ($line =~ /alias="([^"]+)"/) {
- my @thisalias = split(/\s+/, $1);
- foreach (@thisalias) {
- $_ =~ s/\*/\.\*/g;
- }
- push(@{ $alias{$nick} }, @thisalias);
- }
- if ($line =~ /pic="([^"]+)"/) {
- $userpics{$nick} = $1;
- }
- if ($line =~ /link="([^"]+)"/) {
- $userlinks{$nick} = $1;
- }
- if ($line =~ /ignore="Y"/i) {
- push(@ignore, $nick);
- }
- } elsif ($line =~ /<set(.*)>/) {
- my $settings = $1;
- while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
- my $var = lc($1); # Make the string lowercase
- unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
- $conf->{$var} = $2;
- }
- debug("Conf: $var = $2");
- }
- } elsif ($line =~ /<words(.*)>/) {
- my $settings = $1;
- while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
- $words->{$1} = $2;
- debug("Words: $1 = $2");
- }
- }
- }
- close(CONFIG);
- }
- }
- sub init_words {
- my (@words, $i);
- if($words->{foul}) {
- @words = split(/\ /, $words->{foul});
- $i = 0;
- foreach (@words) {
- if($foulwords) {
- $foulwords = $foulwords . "\|" . $words[$i];
- } else {
- $foulwords = $foulwords . $words[$i];
- }
- $i++;
- }
- }
- }
- sub init_debug
- {
- if ($conf->{debug}) {
- print "[ Debugging => $conf->{debugfile} ]\n";
- open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
- file($conf->{debugfile}): $!\n";
- debug("*** pisg debug file for $conf->{logfile}\n");
- }
- }
- sub parse_dir
- {
- print "Going into $conf->{logdir} and parsing all files there...\n\n";
- my @filesarray;
- opendir(LOGDIR, $conf->{logdir}) || die("can't opendir $conf->{logdir}: $!");
- unless (@filesarray = readdir(LOGDIR)) {
- die("No files in $conf->{logdir}!");
- }
- close(LOGDIR);
- # Add trailing slash when it's not there..
- if (substr($conf->{logdir}, -1) ne '/') {
- $conf->{logdir} =~ s/(.*)/$1\//;
- }
- foreach my $file (@filesarray) {
- $file = $conf->{logdir} . $file;
- parse_file($file);
- }
- }
- sub parse_file
- {
- my $file = shift;
- # This parses the file..
- print "Analyzing log($file) in '$conf->{format}' format...\n";
- if ($file =~ /.bz$/ || $file =~ /.bz2$/) {
- open (LOGFILE, "bunzip2 -c $file |") or die("$0: Unable to open logfile($file): $!\n");
- } elsif ($file =~ /.gz$/) {
- open (LOGFILE, "gunzip -c $file |") or die("$0: Unable to open logfile($file): $!\n");
- } else {
- open (LOGFILE, $file) or die("$0: Unable to open logfile($file): $!\n");
- }
- while($line = <LOGFILE>) {
- $lines++; # Increment number of lines.
- $line = strip_mirccodes($line);
- my $hashref;
- # Match normal lines.
- if ($hashref = parse_normalline($line)) {
- my ($hour, $nick, $saying, $i);
- for ($i = 0; $i <= $repeated; $i++) {
- if ($i > 0) {
- $hashref = parse_normalline($lastnormal);
- $lines++; #Increment number of lines for repeated lines
- }
- $hour = $hashref->{hour};
- $nick = find_alias($hashref->{nick});
- $saying = $hashref->{saying};
- # Timestamp collecting
- $times{$hour}++;
- unless (grep /^\Q$nick\E$/i, @ignore) {
- $normals++;
- $line{$nick}++;
- # Count up monologues
- if ($lastline eq $nick) {
- $mono{$nick}++;
- if ($mono{$nick} == "5") {
- $monologue{$nick}++;
- $mono{$nick} = 0;
- }
- } else {
- $mono{$nick} = 0;
- }
- $lastline = $nick;
- my $l = length($saying);
- if ($l > $conf->{minquote} && $l < $conf->{maxquote}) {
- # Creates $hash{nick}[n] - a hash of an array.
- push (@{ $sayings{$nick} }, htmlentities($saying));
- $longlines{$nick}++;
- }
- $question{$nick}++
- if ($saying =~ /\?/);
- $loud{$nick}++
- if ($saying =~ /!/);
- $foul{$nick}++
- if ($saying =~ /$foulwords/);
- # Who smiles the most?
- # A regex matching al lot of smilies
- $smile{$nick}++
- if ($saying =~ /[8;:=][ ^-o]?[)pPD}\]>]/);
- $sadface{$nick}++
- if ($saying =~ /[8;:=][ ^-]?[\(\[\\\/{]/);
- # Don't count http:// as a :/ face
- $sadface{$nick}--
- if ($saying =~ /\w+:\/\//);
- foreach my $word (split(/[\s,!?.:;)(]+/, $saying)) {
- # remove uninteresting words
- next unless (length($word) > $conf->{wordlength});
- # ignore contractions
- next if ($word =~ m/'..?$/);
- $wordcount{htmlentities($word)}++ unless (grep /^\Q$word\E$/i, @ignore);
- $lastused{htmlentities($word)} = $nick;
- }
- $length{$nick} += $l;
- $totallength += $l;
- }
- }
- $lastnormal = $line;
- $repeated = 0;
- }
- # Match action lines.
- elsif ($hashref = parse_actionline($line)) {
- my ($hour, $nick, $saying);
- $hour = $hashref->{hour};
- $nick = find_alias($hashref->{nick});
- $saying = $hashref->{saying};
- # Timestamp collecting
- $times{$hour}++;
- unless (grep /^\Q$nick\E$/i, @ignore) {
- $actions++;
- $line{$nick}++;
- my $len = length($saying);
- $length{$nick} += $len;
- $totallength += $len;
- }
- }
- # Match *** lines.
- elsif (($hashref = parse_thirdline($line)) && $hashref->{nick}) {
- my ($hour, $min, $nick, $kicker, $newtopic, $newmode, $newjoin, $newnick);
- $hour = $hashref->{hour};
- $min = $hashref->{min};
- $nick = find_alias($hashref->{nick});
- $kicker = $hashref->{kicker};
- $newtopic = $hashref->{newtopic};
- $newmode = $hashref->{newmode};
- $newjoin = $hashref->{newjoin};
- $newnick = $hashref->{newnick};
- # Timestamp collecting
- $times{$hour}++;
- unless (grep /^\Q$nick\E$/i, @ignore) {
- if (defined($kicker)) {
- unless (grep /^\Q$kicker\E$/i, @ignore) {
- $gotkick{$nick}++;
- $kicked{$kicker}++;
- }
- } elsif (defined($newtopic)) {
- my $tcount = @topics;
- $topics[$tcount]{topic} = htmlentities($newtopic);
- $topics[$tcount]{nick} = $nick;
- $topics[$tcount]{hour} = $hour;
- $topics[$tcount]{min} = $min;
- # Strip off the quotes (')
- $topics[$tcount]{topic} =~ s/^\'(.*)\'$/$1/;
- } elsif (defined($newmode)) {
- my @opchange = opchanges($newmode);
- unless (exists $gaveop{$nick}) { $gaveop{$nick} = 0 }
- $gaveop{$nick} += $opchange[0] if $opchange[0];
- $tookop{$nick} += $opchange[1] if $opchange[1];
- } elsif (defined($newjoin)) {
- $joins{$nick}++;
- } elsif (defined($newnick) && ($conf->{nicktracking} == 1)) {
- if (find_alias($newnick) eq $newnick) {
- if (defined($alias{$nick}) && !defined($alias{$newnick})) {
- push (@{$alias{$nick}}, $newnick);
- } elsif (defined($alias{$newnick}) && !defined($alias{$nick})) {
- push (@{$alias{$newnick}}, $nick);
- } elsif ($nick =~ /Guest/) {
- push (@{$alias{$newnick}}, ($newnick, $nick));
- } else {
- push (@{$alias{$nick}}, ($nick, $newnick));
- }
- }
- }
- }
- if ($hour < $oldtime) { $days++ }
- $oldtime = $hour;
- }
- }
- close(LOGFILE);
- my ($sec,$min,$hour) = gmtime(time - $^T);
- $processtime = sprintf("%02d hours, %02d minutes and %02d seconds", $hour, $min, $sec);
- $nicks = scalar keys %line;
- print "Finished analyzing log, $days days total.\n";
- }
- # Here is the 3 parse sub routines, their function is to return a hash with
- # the elements in the line. This is where we add the format dependent stuff.
- sub parse_normalline
- {
- # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
- my $line = shift;
- my %hash;
- if ($line =~ /$normalline/) {
- debug("[$lines] Normal: $1 $2 $3");
- if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
- 'eggdrop') || ($conf->{format} eq 'bxlog') || ($conf->{format} eq 'grufti')) {
- $hash{hour} = $1;
- $hash{nick} = $2;
- $hash{saying} = $3;
- } else {
- die("Format not supported?!\n");
- }
- return \%hash;
- } else {
- return;
- }
- }
- sub parse_actionline
- {
- # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
- my $line = shift;
- my %hash;
- if ($line =~ /$actionline/) {
- debug("[$lines] Action: $1 $2 $3");
- if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
- 'eggdrop') || $conf->{format} eq 'bxlog' || ($conf->{format} eq 'grufti')) {
- $hash{hour} = $1;
- $hash{nick} = $2;
- $hash{saying} = $3;
- } else {
- die("Format not supported?!\n");
- }
- return \%hash;
- } else {
- return;
- }
- }
- sub parse_thirdline
- {
- # Parses the 'third' line - (the third line is everything else, like
- # topic changes, mode changes, kicks, etc.)
- # parse_thirdline() have to return a hash with the following keys, for
- # every format:
- # hour - the hour we're in (for timestamp loggin)
- # min - the minute we're in (for timestamp loggin)
- # nick - the nick
- # kicker - the nick which were kicked (if any)
- # newtopic - the new topic (if any)
- # newmode - a deop or an op, must be '+o' or '-o'
- # newjoin - a new nick which has joined the channel
- # newnick - a person has changed nick and this is the new nick
- my $line = shift;
- my %hash;
- if ($line =~ /$thirdline/) {
- if ($7) {
- debug("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
- } elsif ($5) {
- debug("[$lines] ***: $1 $2 $3 $4 $5 $6");
- } else {
- debug("[$lines] ***: $1 $2 $3 $4");
- }
- if ($conf->{format} eq 'mIRC') {
- $hash{hour} = $1;
- $hash{min} = $2;
- $hash{nick} = $3;
- if (($4.$5) eq 'waskicked') {
- $hash{kicker} = $7;
- } elsif (($4.$5) eq 'changestopic') {
- $hash{newtopic} = "$7 $8";
- } elsif (($4.$5) eq 'setsmode:') {
- $hash{newmode} = $6;
- } elsif (($4.$5) eq 'hasjoined') {
- $hash{newjoin} = $3;
- } elsif (($4.$5) eq 'nowknown') {
- $hash{newnick} = $8;
- }
- } elsif ($conf->{format} eq 'xchat') {
- $hash{hour} = $1;
- $hash{min} = $2;
- $hash{nick} = $3;
- if (($4.$5) eq 'haskicked') {
- $hash{kicker} = $3;
- $hash{nick} = $6;
- } elsif (($4.$5) eq 'haschanged') {
- $hash{newtopic} = $9;
- } elsif (($4.$5) eq 'giveschannel') {
- $hash{newmode} = '+o';
- } elsif (($4.$5) eq 'removeschannel') {
- $hash{newmode} = '-o';
- } elsif (($5.$6) eq 'hasjoined') {
- $hash{newjoin} = $1;
- } elsif (($5.$6) eq 'nowknown') {
- $hash{newnick} = $8;
- }
- } elsif ($conf->{format} eq 'eggdrop') {
- $hash{hour} = $1;
- $hash{min} = $2;
- $hash{nick} = $3;
- if (($4.$5) eq 'kickedfrom') {
- $7 =~ /^ by ([\S]+):.*/;
- $hash{kicker} = $1;
- } elsif ($3 eq 'Topic') {
- $7 =~ /^ by ([\S]+)![\S]+: (.*)/;
- $hash{nick} = $1;
- $hash{newtopic} = $2;
- } elsif (($4.$5) eq 'modechange') {
- $hash{newmode} = $6;
- $7 =~ /^ .+ by ([\S]+)!.*/;
- $hash{nick} = $1;
- $hash{newmode} =~ s/^\'//;
- } elsif ($5 eq 'joined') {
- $hash{newjoin} = $3;
- } elsif (($3.$4) eq 'Nickchange:') {
- $hash{nick} = $5;
- $7 =~ /([\S]+)/;
- $hash{newnick} = $1;
- } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
- $repeated = $6;
- }
- } elsif ($conf->{format} eq 'bxlog') {
- $hash{hour} = $1;
- $hash{min} = $2;
- if ($3 eq '<') {
- if ($4 =~ /^([^!]+)!([\S+]) was kicked off (\S+) by ([^!]+)!(\S+) \(([^)]+)\)$/) {
- $hash{kicker} = $4;
- $hash{nick} = $1;
- }
- } elsif ($3 eq '>') {
- if ($4 =~ /^([^!])+!(\S+) has joined (\S+)$/) {
- $hash{nick} = $1;
- $hash{newjoin} = $1;
- }
- } elsif ($3 eq '@') {
- if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
- $hash{nick} = $1;
- $hash{newtopic} = $2;
- } elsif ($4 =~ /^mode (\S+) \[([+-]o)\S* (\S+)[^\]]*\] by ([^!]+)!(\S+)$/) {
- $hash{newmode} = $2;
- $hash{nick} = $4;
- }
- } elsif ($3 eq '!') {
- if ($4 =~ /^(\S+) is known as (\S+)$/) {
- $hash{nick} = $1;
- $hash{newnick} = $2;
- }
- }
- } elsif ($conf->{format} eq 'grufti') {
- $hash{hour} = $1;
- $hash{min} = $2;
- $hash{nick} = $3;
- if ($5 eq 'kicked') {
- $hash{kicker} = $3;
- $hash{nick} = $6;
- } elsif (($4.$5) eq 'haschanged') {
- $hash{newtopic} = $9;
- } elsif (($4.$5) eq 'modechange') {
- my $mode = $6;
- my $kicker = $9;
- if($mode =~ /([+-]o[ov])(\S+)(.*)/) {
- my $modes = $1.$2;
- $modes =~ s/v//g;
- $hash{newmode} = $modes;
- if($kicker =~ /(.*)' by (\S+)/) {
- $hash{nick} = $2;
- }
- } else {
- $hash{newmode} = substr($6, 1);
- $hash{nick} = substr($9, 1);
- }
- } elsif ($5 eq 'joined') {
- $hash{newjoin} = $1;
- } elsif (($3.$4) eq 'Nickchange') {
- $hash{nick} = $7;
- $hash{newnick} = $9;
- }
- } else {
- die("Format not supported?!\n");
- }
- return \%hash;
- } else {
- return;
- }
- }
- sub opchanges
- {
- my @modes = split(//, $_[0]);
- my ($mode,$plus) = ("",0);
- my ($gaveop,$tookop) = (0,0);
- foreach (@modes) {
- if (/^\+$/) { $plus = 1; next; }
- elsif (/^-$/) { $plus = 0; next; }
- else { next unless /^o$/ }
- if ($plus) { $gaveop++ } else { $tookop++ }
- }
- my @out = ($gaveop,$tookop);
- return @out;
- }
- sub strip_mirccodes
- {
- my $line = shift;
- my $boldcode = chr(2);
- my $colorcode = chr(3);
- my $plaincode = chr(15);
- my $reversecode = chr(22);
- my $underlinecode = chr(31);
- # Strip mIRC color codes
- $line =~ s/$colorcode\d{1,2},\d{1,2}//g;
- $line =~ s/$colorcode\d{0,2}//g;
- # Strip mIRC bold, plain, reverse and underline codes
- $line =~ s/[$boldcode$underlinecode$reversecode$plaincode]//g;
- return $line;
- }
- sub htmlentities
- {
- my $str = shift;
- $str =~ s/\&/\&/g;
- $str =~ s/\</\</g;
- $str =~ s/\>/\>/g;
- return $str;
- }
- sub html
- {
- my $html = shift;
- print OUTPUT $html . "\n";
- }
- sub template_text
- {
- # This function is for the homemade template system. It receives a name
- # of a template and a hash with the fields in the template to update to
- # its corresponding value
- my $template = shift;
- my %hash = @_;
- my $text;
- if (!$T{$conf->{lang}}{$template}) {
- # Fall back to English if the language template doesn't exist
- $text = $T{EN}{$template};
- }
- $text = $T{$conf->{lang}}{$template};
- if (!$text) {
- die("No such template $template\n");
- }
- foreach my $key (sort keys %hash) {
- $text =~ s/\[:$key\]/$hash{$key}/;
- $text =~ s/ü/ü/g;
- $text =~ s/ö/ö/g;
- $text =~ s/ä/ä/g;
- $text =~ s/ß/ß/g;
- $text =~ s/å/å/g;
- $text =~ s/æ/æ/g;
- $text =~ s/ø/ø/g;
- }
- return $text;
- }
- sub replace_links
- {
- # Sub to replace urls and e-mail addys to links
- my $str = shift;
- my $nick = shift;
- if ($nick) {
- $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$nick<\/a>/g;
- $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $nick">$nick<\/a>/g;
- } else {
- $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$1$2<\/a>/g;
- $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
- }
- return $str;
- }
- sub debug
- {
- if ($conf->{debug}) {
- my $debugline = $_[0] . "\n";
- print DEBUG $debugline;
- }
- }
- sub find_alias
- {
- my $nick = shift;
- foreach (keys %alias) {
- return $_ if (grep /^\Q$nick\E$/i, @{$alias{$_}});
- if (grep /\*/, @{$alias{$_}}) {
- foreach my $alias (@{$alias{$_}}) {
- return $_ if ($nick =~ /^$alias$/);
- }
- }
- }
- return $nick;
- }
- sub create_html
- {
- # This is where all subroutines get executed, you can actually design
- # your own layout here, the lines should be self-explainable
- print "Now generating HTML($conf->{outputfile})...\n";
- open (OUTPUT, "> $conf->{outputfile}") or die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
- htmlheader();
- pageheader();
- activetimes();
- activenicks();
- headline(template_text('bignumtopic'));
- html("<table width=\"614\">\n"); # Needed for sections
- questions();
- loudpeople();
- mostsmiles();
- mostsad();
- longlines();
- shortlines();
- html("</table>"); # Needed for sections
- mostusedword();
- mostreferenced();
- headline(template_text('othernumtopic'));
- html("<table width=\"614\">\n"); # Needed for sections
- gotkicks();
- mostkicks();
- mostop();
- mostmonologues();
- mostjoins();
- mostfoul();
- html("</table>"); # Needed for sections
- headline(template_text('latesttopic'));
- html("<table width=\"614\">\n"); # Needed for sections
- lasttopics();
- html("</table>"); # Needed for sections
- my %hash = ( lines => $lines );
- html(template_text('totallines', %hash) . "<br><br>");
- htmlfooter();
- close(OUTPUT);
- }
- sub activetimes
- {
- # The most actives times on the channel
- my (%output, $tbgcolor);
- &headline(template_text('activetimestopic'));
- my @toptime = sort { $times{$b} <=> $times{$a} } keys %times;
- my $highest_value = $times{$toptime[0]};
- my @now = localtime($timestamp);
- my $image;
- for my $hour (sort keys %times) {
- debug("Time: $hour => ". $times{$hour});
- if ($toptime[0] == $hour) {
- $image = $conf->{pic2};
- } else {
- $image = $conf->{pic1};
- }
- my $size = ($times{$hour} / $highest_value) * 100;
- my $percent = ($times{$hour} / $lines) * 100;
- $percent =~ s/(\.\d)\d+/$1/;
- if ($conf->{timeoffset} =~ /\+(\d+)/) {
- # We must plus some hours to the time
- $hour += $1;
- $hour = $hour % 24;
- if ($hour < 10) { $hour = "0" . $hour; }
- } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
- # We must remove some hours from the time
- $hour -= $1;
- $hour = $hour % 24;
- if ($hour < 10) { $hour = "0" . $hour; }
- }
- $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
- }
- html("<table border=\"0\" width=\"614\"><tr>\n");
- for ($b = 0; $b < 24; $b++) {
- if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
- if (!defined($output{$a}) || $output{$a} eq "") {
- html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
- } else {
- html($output{$a});
- }
- }
- html("</tr><tr>");
- for ($b = 0; $b < 24; $b++) {
- if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
- html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
- }
- html("</tr></table>");
- }
- sub activenicks
- {
- # The most active nicks (those who wrote most lines)
- headline(template_text('activenickstopic'));
- html("<table border=\"0\" width=\"614\"><tr>");
- html("<td> </td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberlines') ."</b></td><td bgcolor=\"$conf->{tdtop}\"><b>". template_text('randquote') ."</b></td>");
- if (%userpics) {
- html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
- }
- html("</tr>");
- my @active = sort { $line{$b} <=> $line{$a} } keys %line;
- if ($conf->{activenicks} > $nicks) {
- $conf->{activenicks} = $nicks;
- print "Note: There was less nicks in the logfile than your specificied there to be in most active nicks...\n";
- }
- my ($nick, $visiblenick, $randomline);
- my $i = 1;
- for (my $c = 0; $c < $conf->{activenicks}; $c++) {
- $nick = $active[$c];
- $visiblenick = $active[$c];
- if (!$longlines{$nick}) {
- $randomline = "";
- } else {
- my $rand = rand($longlines{$nick});
- $randomline = $sayings{$nick}[$rand];
- }
- # Convert URLs and e-mail addys to links
- $randomline = replace_links($randomline);
- # Add a link to the nick if there is any
- if ($userlinks{$nick}) {
- $visiblenick = replace_links($userlinks{$nick}, $nick);
- }
- my $h = $conf->{hicell};
- $h =~ s/^#//;
- $h = hex $h;
- my $h2 = $conf->{hicell2};
- $h2 =~ s/^#//;
- $h2 = hex $h2;
- my $f_b = $h & 0xff;
- my $f_g = ($h & 0xff00) >> 8;
- my $f_r = ($h & 0xff0000) >> 16;
- my $t_b = $h2 & 0xff;
- my $t_g = ($h2 & 0xff00) >> 8;
- my $t_r = ($h2 & 0xff0000) >> 16;
- my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
- my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
- my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
- html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
- my $line = $line{$nick};
- html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td><td bgcolor=\"#$col_r$col_g$col_b\">$line</td><td bgcolor=\"#$col_r$col_g$col_b\">");
- html("\"$randomline\"</td>");
- if ($userpics{$nick}) {
- html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$userpics{$nick}\"></td>");
- }
- html("</tr>");
- $i++;
- }
- html("</table><br>");
- # Almost as active nicks ('These didn't make it to the top..')
- my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
- unless ($nickstoshow > $nicks) {
- html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
- for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
- unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
- html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
- my $nick = $active[$c];
- my $lines = $line{$nick};
- html("$nick ($lines)</td>");
- }
- html("</table>");
- }
- }
- sub mostusedword
- {
- # Lao the infamous word usage statistics
- my %usages;
- foreach my $word (sort keys %wordcount) {
- next if exists $line{$word};
- $usages{$word} = $wordcount{$word};
- }
- my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
- if (@popular) {
- &headline(template_text('mostwordstopic'));
- html("<table border=\"0\" width=\"614\"><tr>");
- html("<td> </td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
- html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
- html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
- for(my $i = 0; $i < 10; $i++) {
- last unless $i < $#popular;
- my $a = $i + 1;
- my $popular = $popular[$i];
- my $wordcount = $wordcount{$popular[$i]};
- my $lastused = $lastused{$popular[$i]};
- html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
- html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
- html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
- html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
- html("</tr>");
- }
- html("</table>");
- }
- }
- sub mostreferenced
- {
- my %usages;
- foreach my $word (sort keys %wordcount) {
- next unless exists $line{$word};
- $usages{$word} = $wordcount{$word};
- }
- my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
- if (@popular) {
- &headline(template_text('referencetopic'));
- html("<table border=\"0\" width=\"614\"><tr>");
- html("<td> </td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
- html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
- html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
- for(my $i = 0; $i < 5; $i++) {
- last unless $i < $#popular;
- my $a = $i + 1;
- my $popular = $popular[$i];
- my $wordcount = $wordcount{$popular[$i]};
- my $lastused = $lastused{$popular[$i]};
- html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
- html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
- html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
- html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
- html("</tr>");
- }
- html("</table>");
- }
- }
- sub questions
- {
- # Persons who asked the most questions
- foreach my $nick (sort keys %question) {
- if ($line{$nick} > 100) {
- $qpercent{$nick} = ($question{$nick} / $line{$nick}) * 100;
- $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
- if (@question) {
- my %hash = (
- nick => $question[0],
- per => $qpercent{$question[0]}
- );
- my $text = template_text('question1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@question >= 2) {
- my %hash = (
- nick => $question[1],
- per => $qpercent{$question[1]}
- );
- my $text = template_text('question2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
- }
- }
- sub loudpeople
- {
- # The ones who speak LOUDLY!
- foreach my $nick (sort keys %loud) {
- if ($line{$nick} > 100) {
- $lpercent{$nick} = ($loud{$nick} / $line{$nick}) * 100;
- $lpercent{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @loud = sort { $lpercent{$b} <=> $lpercent{$a} } keys %lpercent;
- if (@loud) {
- my %hash = (
- nick => $loud[0],
- per => $lpercent{$loud[0]}
- );
- my $text = template_text('loud1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@loud >= 2) {
- my %hash = (
- nick => $loud[1],
- per => $lpercent{$loud[1]}
- );
- my $text = template_text('loud2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my $text = template_text('loud3');
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- }
- sub gotkicks
- {
- # The persons who got kicked the most
- my @gotkick = sort { $gotkick{$b} <=> $gotkick{$a} } keys %gotkick;
- if (@gotkick) {
- my %hash = (
- nick => $gotkick[0],
- kicks => $gotkick{$gotkick[0]}
- );
- my $text = template_text('gotkick1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@gotkick >= 2) {
- my %hash = (
- nick => $gotkick[1],
- kicks => $gotkick{$gotkick[1]}
- );
- my $text = template_text('gotkick2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- }
- }
- sub mostjoins
- {
- my @joins = sort { $joins{$b} <=> $joins{$a} } keys %joins;
- if (@joins) {
- my %hash = (
- nick => $joins[0],
- joins => $joins{$joins[0]}
- );
- my $text = template_text('joins', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- }
- sub mostkicks
- {
- # The person who got kicked the most
- my @kicked = sort { $kicked{$b} <=> $kicked{$a} } keys %kicked;
- if (@kicked) {
- my %hash = (
- nick => $kicked[0],
- kicked => $kicked{$kicked[0]}
- );
- my $text = template_text('kick1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@kicked >= 2) {
- my %hash = (
- oldnick => $kicked[0],
- nick => $kicked[1],
- kicked => $kicked{$kicked[1]}
- );
- my $text = template_text('kick2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my $text = template_text('kick3');
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- }
- sub mostmonologues
- {
- # The person who had the most monologues (speaking to himself)
- my @monologue = sort { $monologue{$b} <=> $monologue{$a} } keys %monologue;
- if (@monologue) {
- my %hash = (
- nick => $monologue[0],
- monos => $monologue{$monologue[0]}
- );
- my $text = template_text('mono1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@monologue >= 2) {
- my %hash = (
- nick => $monologue[1],
- monos => $monologue{$monologue[1]}
- );
- my $text = template_text('mono2', %hash);
- if ($monologue{$monologue[1]} == 1 && $conf->{lang} eq 'EN') {
- $text = substr $text, 0, -1;
- }
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- }
- }
- sub longlines
- {
- my %len;
- # The person(s) who wrote the longest lines
- foreach my $nick (sort keys %length) {
- if ($line{$nick} > 100) {
- $len{$nick} = $length{$nick} / $line{$nick};
- $len{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @len = sort { $len{$b} <=> $len{$a} } keys %len;
- my $all_lines = $normals + $actions;
- my $totalaverage;
- if ($all_lines > 0) {
- $totalaverage = $totallength / $all_lines;
- $totalaverage =~ s/(\.\d)\d+/$1/;
- }
- if (@len) {
- my %hash = (
- nick => $len[0],
- letters => $len{$len[0]}
- );
- my $text = template_text('long1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
- if (@len >= 2) {
- %hash = (
- channel => $conf->{channel},
- avg => $totalaverage
- );
- $text = template_text('long2', %hash);
- html("<span class=\"small\">$text</span></td></tr>");
- }
- }
- }
- sub shortlines
- {
- # This sub should be combined with the longlines sub at some point.. it
- # does basically the same thing.
- my %len;
- # The person(s) who wrote the shortest lines
- foreach my $nick (sort keys %length) {
- if ($line{$nick} > 5) {
- $len{$nick} = $length{$nick} / $line{$nick};
- $len{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @len = sort { $len{$a} <=> $len{$b} } keys %len;
- if (@len) {
- my %hash = (
- nick => $len[0],
- letters => $len{$len[0]}
- );
- my $text = template_text('short1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
- if (@len >= 2) {
- %hash = (
- nick => $len[1],
- letters => $len{$len[1]}
- );
- $text = template_text('short2', %hash);
- html("<span class=\"small\">$text</span></td></tr>");
- }
- }
- }
- sub mostfoul
- {
- my %spercent;
- foreach my $nick (sort keys %foul) {
- if ($line{$nick} > 15) {
- $spercent{$nick} = ($foul{$nick} / $line{$nick}) * 100;
- $spercent{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
- if (@foul) {
- my %hash = (
- nick => $foul[0],
- per => $spercent{$foul[0]}
- );
- my $text = template_text('foul1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@foul >= 2) {
- my %hash = (
- nick => $foul[1],
- per => $spercent{$foul[1]}
- );
- my $text = template_text('foul2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my %hash = (
- channel => $conf->{channel}
- );
- my $text = template_text('foul3', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- }
- sub mostsad
- {
- my %spercent;
- foreach my $nick (sort keys %sadface) {
- if ($line{$nick} > 100) {
- $spercent{$nick} = ($sadface{$nick} / $line{$nick}) * 100;
- $spercent{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
- if (@sadface) {
- my %hash = (
- nick => $sadface[0],
- per => $spercent{$sadface[0]}
- );
- my $text = template_text('sad1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@sadface >= 2) {
- my %hash = (
- nick => $sadface[1],
- per => $spercent{$sadface[1]}
- );
- my $text = template_text('sad2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my %hash = (
- channel => $conf->{channel}
- );
- my $text = template_text('sad3', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$conf->text</td></tr>");
- }
- }
- sub mostop
- {
- my @ops = sort { $gaveop{$b} <=> $gaveop{$a} } keys %gaveop;
- my @deops = sort { $tookop{$b} <=> $tookop{$a} } keys %tookop;
- if (@ops) {
- my %hash = (
- nick => $ops[0],
- ops => $gaveop{$ops[0]}
- );
- my $text = template_text('mostop1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@ops >= 2) {
- my %hash = (
- nick => $ops[1],
- ops => $gaveop{$ops[1]}
- );
- my $text = template_text('mostop2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my %hash = ( channel => $conf->{channel} );
- my $text = template_text('mostop3', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- if (@deops) {
- my %hash = (
- channel => $conf->{channel},
- nick => $deops[0],
- deops => $tookop{$deops[0]}
- );
- my $text = template_text('mostdeop1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@deops >= 2) {
- my %hash = (
- nick => $deops[1],
- deops => $tookop{$deops[1]}
- );
- my $text = template_text('mostdeop2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my %hash = ( channel => $conf->{channel} );
- my $text = template_text('mostdeop3', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- }
- }
- sub mostsmiles
- {
- # The person(s) who smiled the most :-)
- my %spercent;
- foreach my $nick (sort keys %smile) {
- if ($line{$nick} > 100) {
- $spercent{$nick} = ($smile{$nick} / $line{$nick}) * 100;
- $spercent{$nick} =~ s/(\.\d)\d+/$1/;
- }
- }
- my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
- if (@smiles) {
- my %hash = (
- nick => $smiles[0],
- per => $spercent{$smiles[0]}
- );
- my $text = template_text('smiles1', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
- if (@smiles >= 2) {
- my %hash = (
- nick => $smiles[1],
- per => $spercent{$smiles[1]}
- );
- my $text = template_text('smiles2', %hash);
- html("<br><span class=\"small\">$text</span>");
- }
- html("</td></tr>");
- } else {
- my %hash = (
- channel => $conf->{channel}
- );
- my $text = template_text('smiles3', %hash);
- html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
- }
- }
- sub lasttopics
- {
- debug("Total number of topics: ". scalar @topics);
- if (@topics) {
- my $ltopic = @topics - 1;
- my $tlimit = 0;
- $conf->{topichistory} -= 1;
- if ($ltopic > $conf->{topichistory}) { $tlimit = $ltopic - $conf->{topichistory}; }
- for (my $i = $ltopic; $i >= $tlimit; $i--) {
- $topics[$i]{"topic"} = replace_links($topics[$i]{"topic"});
- my $topic = $topics[$i]{topic};
- my $nick = $topics[$i]{nick};
- my $hour = $topics[$i]{hour};
- my $min = $topics[$i]{min};
- html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
- html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
- }
- } else {
- html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
- }
- }
- # Some HTML subs
- sub htmlheader
- {
- print OUTPUT <<HTML;
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>$conf->{channel} @ $conf->{network} channel statistics</title>
- <style type="text/css">
- a { text-decoration: none }
- a:link { color: $conf->{link}; }
- a:visited { color: $conf->{vlink}; }
- a:hover { text-decoration: underline; color: $conf->{hlink} }
- body {
- background-color: $conf->{bgcolor};
- font-family: verdana, arial, sans-serif;
- font-size: 13px;
- color: $conf->{text};
- }
- td {
- font-family: verdana, arial, sans-serif;
- font-size: 13px;
- color: $conf->{tdcolor};
- }
- .title {
- font-family: tahoma, arial, sans-serif;
- font-size: 16px;
- font-weight: bold;
- }
- .headline { color: $conf->{hcolor}; }
- .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
- .asmall { font-family: arial narrow, sans-serif; font-size: 10px }
- </style></head>
- <body>
- <div align="center">
- HTML
- my %hash = (
- channel => $conf->{channel},
- network => $conf->{network},
- maintainer => $conf->{maintainer},
- time => $time,
- days => $days,
- nicks => $nicks,
- channel => $conf->{channel}
- );
- print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
- print OUTPUT "<br>" . template_text('pagetitle2', %hash) . "<br>";
- print OUTPUT template_text('pagetitle3', %hash) . "<br><br>";
- }
- sub htmlfooter
- {
- print OUTPUT <<HTML;
- <span class="small">
- Stats generated by <a href="http://www.wtf.dk/hp/index.php?page=pisg" title="Go to the pisg homepage">pisg</a> $conf->{version}<br>
- pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
- Stats generated in $processtime
- </span>
- </div>
- </body>
- </html>
- HTML
- }
- sub headline
- {
- my ($title) = @_;
- print OUTPUT <<HTML;
- <br>
- <table width="610" cellpadding="1" cellspacing="0" border="0">
- <tr>
- <td bgcolor="$conf->{headline}">
- <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
- <tr>
- <td bgcolor="$conf->{hbgcolor}" class="text10">
- <div align="center" class="headline"><b>$title</b></div>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- HTML
- }
- sub pageheader
- {
- if ($conf->{pagehead} ne 'none') {
- open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
- while (<PAGEHEAD>) {
- html($_);
- }
- }
- }
- sub close_debug
- {
- if ($conf->{debug}) {
- close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
- }
- }
- sub get_cmdlineoptions
- {
- my $tmp;
- # Commandline options
- my ($channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
- my $usage = <<END_USAGE;
- Usage: pisg.pl [-c channel] [-l logfile] [-o outputfile] [-m
- maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
- [-i ignorefile] [-h]
- -ch --channel=xxx : Set channel name
- -l --logfile=xxx : Log file to parse
- -o --outfile=xxx : Name of html file to create
- -m --maintainer=xxx : Channel/statistics maintainer
- -f --format=xxx : Logfile format [see FORMATS file]
- -n --network=xxx : IRC Network this channel is on.
- -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
- -p --prefix=xxx : Analyse only files starting with xxx in dir.
- Only works with --dir
- -co --configfile=xxx : Config file
- -h --help : Output this message and exit (-? also works).
- Example:
- \$ pisg.pl -n IRCnet -f xchat -o suid.html -c \\#channel -l logfile.log
- As always, all options may also be defined by editing the source and calling
- pisg without arguments.
- END_USAGE
- if (GetOptions('channel=s' => \$channel,
- 'logfile=s' => \$logfile,
- 'format=s' => \$format,
- 'network=s' => \$network,
- 'maintainer=s' => \$maintainer,
- 'outfile=s' => \$outputfile,
- 'dir=s' => \$logdir,
- 'prefix=s' => \$prefix,
- 'ignorefile=s' => \$tmp,
- 'aliasfile=s' => \$tmp,
- 'configfile=s' => \$configfile,
- 'help|?' => \$help
- ) == 0 or $help) {
- die($usage);
- }
- if (@ARGV) {
- if ($ARGV[0]) { $conf->{channel} = $ARGV[0]; }
- if ($ARGV[1]) { $conf->{logfile} = $ARGV[1]; }
- if ($ARGV[2]) { $conf->{outputfile} = $ARGV[2]; }
- if ($ARGV[3]) { $conf->{maintainer} = $ARGV[3]; }
- }
- if ($tmp) {
- die("The aliasfile and ignorefile has been obsoleted by the new
- pisg.cfg, please use that instead [look in pisg.cfg]\n");
- }
- if ($channel) {
- $conf->{channel} = $channel;
- $conf->{cmdl}{channel} = 1;
- }
- if ($logfile) {
- $conf->{logfile} = $logfile;
- $conf->{cmdl}{logfile} = 1;
- }
- if ($format) {
- $conf->{format} = $format;
- $conf->{cmdl}{format} = 1;
- }
- if ($network) {
- $conf->{network} = $network;
- $conf->{cmdl}{network} = 1;
- }
- if ($maintainer) {
- $conf->{maintainer} = $maintainer;
- $conf->{cmdl}{maintainer} = 1;
- }
- if ($outputfile) {
- $conf->{outputfile} = $outputfile;
- $conf->{cmdl}{outputfile} = 1;
- }
- if ($logdir) {
- $conf->{logdir} = $logdir;
- $conf->{cmdl}{logdir} = 1;
- }
- if ($prefix) {
- $conf->{prefix} = $prefix;
- $conf->{cmdl}{prefix} = 1;
- }
- if ($configfile) {
- $conf->{configfile} = $configfile;
- $conf->{cmdl}{configfile} = 1;
- }
- }
- sub get_language_templates
- {
- use FindBin;
- open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
- my $current_lang;
- while (<FILE>)
- {
- my $line = $_;
- next if /^#/;
- if ($line =~ /<lang name=\"([^"]+)\">/) {
- # Found start tag, setting the current language
- $current_lang = "$1";
- }
- elsif ($line =~ /<\/lang>/) {
- # Found end tag, resetting the current language
- $current_lang = '';
- }
-
- elsif ($line =~ /(\w+) = "(.*)"$/ && $current_lang ne '') {
- $T{$current_lang}{$1} = $2;
- }
- }
- close(FILE);
- print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
- }
-
- &main(); # Run the script
|