4
0

pisg.pl 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. # pisg - Perl IRC Statistics Generator
  5. #
  6. # Copyright (C) 2001 <Morten 'LostStar' Brix Pedersen> - morten@wtf.dk
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. my $config;
  22. # Values that _MUST_ be set below (unless you pass them on commandline)
  23. $config->{channel} = "#channel"; # The name of your channel.
  24. $config->{logfile} = "channel.log"; # The exact filename of the logfile
  25. $config->{format} = "mIRC"; # logfile format. see FORMATS file
  26. $config->{network} = "SomeIRCNet"; # Network the channels is using.
  27. $config->{outputfile} = "index.html"; # The name of the html file to be generated
  28. $config->{maintainer} = "MAINTAINER"; # The maintainer or bot which makes the logfile
  29. $config->{pagehead} = "none"; # Some 'page header' file which you want to
  30. # include in top of the stats
  31. $config->{configfile} = "pisg.cfg"; # Path to config file (aliases, ignores,
  32. # pics and more, see pisg.cfg for examples)
  33. $config->{imagepath} = ""; # If your user pictures is located
  34. # some special directory, set the path here.
  35. $config->{logdir} = ""; # If you specify a path to a dir here, then
  36. # pisg will take that dir, and parse ALL
  37. # logfiles in it, and create 1 HTML file
  38. # from it
  39. $config->{lang} = 'EN'; # Language to use:
  40. # EN | DE | DK | FR | ES | PL
  41. $config->{langfile} = 'lang.txt'; # Name of language file
  42. $config->{prefix} = ""; # If you specify a string here and have $logdir
  43. # set, then only those files starting with
  44. # $prefix in $logdir will be read.
  45. # Here you can set the colors for your stats page..
  46. $config->{bgcolor} = "#dedeee"; # Background color of the page
  47. $config->{text} = "black"; # Normal text color
  48. $config->{hbgcolor} = "#666699"; # Background color in headlines
  49. $config->{hcolor} = "white"; # Text color in headline
  50. $config->{hicell} = "#BABADD"; # Background color in highlighted cells
  51. $config->{hicell2} = "#CCCCCC"; # Background color in highlighted cells
  52. $config->{tdcolor} = "black"; # Color of text in tables
  53. $config->{tdtop} = "#C8C8DD"; # Top color in some tables.
  54. $config->{link} = "#0b407a"; # Color of links
  55. $config->{vlink} = "#0b407a"; # Color of visited links
  56. $config->{hlink} = "#0b407a"; # Color of hovered links
  57. $config->{headline} = "#000000"; # Border color of headlines
  58. $config->{rankc} = "#CCCCCC"; # Colors of 'ranks' (1,2,3,4)
  59. $config->{pic1} = "pipe-blue.png"; # Bar-graphic-file for normal times
  60. $config->{pic2} = "pipe-purple.png"; # Bar-graphic-file for top-times
  61. # Other things that you might set, but not everyone cares about them
  62. $config->{minquote} = "25"; # Minimal value of letters for a random quote
  63. $config->{maxquote} = "65"; # Maximum value of letters for a random quote
  64. $config->{wordlength} = "5"; # The minimum number of chars an interesting
  65. # word may be (in 'most referenced words')
  66. $config->{activenicks} = "25"; # Number of nicks to show in the 'top 25'
  67. $config->{activenicks2} = "30"; # Nicks to show in 'these didnt make it...'
  68. $config->{topichistory} = "3"; # How many topics to show in 'latest topics'
  69. $config->{nicktracking} = 0; # Track nickchanges and create aliases (can
  70. # be slow, so it's disabled by default)
  71. $config->{timeoffset} = "+0"; # A time offset on the stats page - if your
  72. # country has a different timezone than the
  73. # machine where the stats are being
  74. # generated, then for example do +1
  75. # to add 1 hour to the time
  76. # You shouldn't care about anything below this point
  77. $config->{debug} = 0; # 0 = Debugging off, 1 = Debugging on
  78. $config->{debugfile} = "debug.log"; # Path to debug file(must be set if $debug == 1)
  79. $config->{version} = "v0.18-cvs";
  80. my ($lines, $kicked, $gotkicked, $smile, $longlines, $time, $timestamp, %alias,
  81. $normalline, $actionline, $thirdline, @ignore, $line, $processtime, @topics,
  82. %monologue, %kicked, %gotkick, %line, %length, %qpercent, %lpercent, %sadface,
  83. %smile, $nicks, %longlines, %mono, %times, %question, %loud, $totallength,
  84. %gaveop, %tookop, %joins, %actions, %sayings, %wordcount, %lastused, %gotban,
  85. %setban, %foul, $days, $oldtime, $lastline, $actions, $normals, %userpics,
  86. %userlinks, %T, $repeated, $lastnormal);
  87. sub main
  88. {
  89. init_config(); # Init config. (Aliases, ignores, other options etc.)
  90. init_pisg(); # Init commandline arguments and other things
  91. init_lineformats(); # Attempt to set line formats in compliance with user specification (--format)
  92. init_debug(); # Init the debugging file
  93. if ($config->{logdir}) {
  94. parse_dir(); # Run through all logfiles in dir
  95. } else {
  96. parse_file($config->{logfile}); # Run through the whole logfile
  97. }
  98. create_html(); # Create the HTML
  99. # (look here if you want to remove some of the
  100. # stats which you don't care about)
  101. close_debug(); # Close the debugging file
  102. print "\nFile was parsed succesfully in $processtime on $time.\n";
  103. }
  104. sub init_pisg
  105. {
  106. print "pisg $config->{version} - Perl IRC Statistics Generator\n\n";
  107. get_cmdlineoptions();
  108. get_language_templates();
  109. $timestamp = time;
  110. if ($config->{timeoffset} =~ /\+(\d+)/) {
  111. # We must plus some hours to the time
  112. $timestamp += 3600 * $1; # 3600 seconds per hour
  113. } elsif ($config->{timeoffset} =~ /-(\d+)/) {
  114. # We must remove some hours from the time
  115. $timestamp -= 3600 * $1; # 3600 seconds per hour
  116. }
  117. # Set useful values.
  118. $days = 1;
  119. $oldtime = "00";
  120. $lastline = "";
  121. $actions = "0";
  122. $normals = "0";
  123. $time = localtime($timestamp);
  124. $repeated = 0;
  125. $lastnormal = "";
  126. # Add trailing slash when it's not there..
  127. if (substr($config->{imagepath}, -1) ne '/') {
  128. $config->{imagepath} =~ s/(.*)/$1\//;
  129. }
  130. print "Statistics for channel $config->{channel} \@ $config->{network} by $config->{maintainer}\n\n";
  131. }
  132. sub init_lineformats {
  133. # These are the regular expressions which matches the lines in the logfile,
  134. # and looks different if it's xchat, mIRC or whatever.
  135. # If you want to add support for a new format - you first have to add the
  136. # regex here, and then you also have to modify the parse subroutines called
  137. # 'parse_normalline()', 'parse_actionline()' and 'parse_thirdline()'
  138. if ($config->{format} eq 'xchat') {
  139. $normalline = '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)';
  140. $actionline = '^(\d+):\d+:\d+ \*\s+(\S+) (.*)';
  141. $thirdline = '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)';
  142. } elsif ($config->{format} eq 'mIRC') {
  143. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  144. $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
  145. $thirdline = '^\[(\d+):(\d+)\] \*\*\* (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
  146. } elsif ($config->{format} eq 'eggdrop') {
  147. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  148. $actionline = '^\[(\d+):\d+\] Action: (\S+) (.*)';
  149. $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)';
  150. } elsif ($config->{format} eq 'bxlog') {
  151. $normalline = '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)';
  152. $actionline = '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)';
  153. $thirdline = '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)';
  154. } elsif ($config->{format} eq 'grufti') {
  155. $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  156. $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
  157. $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
  158. } else {
  159. die("Logfile format not supported, check \$config->{format} setting.\n");
  160. }
  161. }
  162. sub init_config
  163. {
  164. if (open(CONFIG, $config->{configfile})) {
  165. my $lineno = 0;
  166. while (<CONFIG>)
  167. {
  168. $lineno++;
  169. my $line = $_;
  170. next if /^#/;
  171. if ($line =~ /<user.*>/) {
  172. my $nick;
  173. if ($line =~ /nick="([^"]+)"/) {
  174. $nick = $1;
  175. } else {
  176. print STDERR "Warning: no nick specified in $config->{configfile} on line $lineno\n";
  177. next;
  178. }
  179. if ($line =~ /alias="([^"]+)"/) {
  180. my @thisalias = split(/\s+/, $1);
  181. push(@{ $alias{$nick} }, @thisalias);
  182. }
  183. if ($line =~ /pic="([^"]+)"/) {
  184. $userpics{$nick} = $1;
  185. }
  186. if ($line =~ /link="([^"]+)"/) {
  187. $userlinks{$nick} = $1;
  188. }
  189. if ($line =~ /ignore="Y"/i) {
  190. push(@ignore, $nick);
  191. }
  192. } elsif ($line =~ /<settings(.*)>/) {
  193. my $settings = $1;
  194. while ($settings =~ s/[ \t]([^=]+)=["']([^"']*)["']//) {
  195. $config->{$1} = $2;
  196. debug("Conf: $1 = $2");
  197. }
  198. }
  199. }
  200. close(CONFIG);
  201. }
  202. }
  203. sub init_debug
  204. {
  205. if ($config->{debug}) {
  206. print "[ Debugging => $config->{debugfile} ]\n";
  207. open(DEBUG,"> $config->{debugfile}") or print STDERR "$0: Unable to open debug
  208. file($config->{debugfile}): $!\n";
  209. debug("*** pisg debug file for $config->{logfile}\n");
  210. }
  211. }
  212. sub parse_dir
  213. {
  214. print "Going into $config->{logdir} and parsing all files there...\n\n";
  215. my $files = `ls $config->{logdir}`;
  216. my @filesarray = split(/\n/, $files);
  217. # Add trailing slash when it's not there..
  218. if (substr($config->{logdir}, -1) ne '/') {
  219. $config->{logdir} =~ s/(.*)/$1\//;
  220. }
  221. foreach my $file (@filesarray) {
  222. if ($config->{prefix} eq "" || $file =~ /^$config->{prefix}/) {
  223. $file = $config->{prefix} . $file;
  224. parse_file($file);
  225. }
  226. }
  227. }
  228. sub parse_file
  229. {
  230. my $file = shift;
  231. # This parses the file..
  232. print "Analyzing log($file) in '$config->{format}' format...\n";
  233. if ($file =~ /.bz$/ || $file =~ /.bz2$/) {
  234. open (LOGFILE, "bunzip2 -c $file |") or die("$0: Unable to open logfile($file): $!\n");
  235. } elsif ($file =~ /.gz$/) {
  236. open (LOGFILE, "gunzip -c $file |") or die("$0: Unable to open logfile($file): $!\n");
  237. } else {
  238. open (LOGFILE, $file) or die("$0: Unable to open logfile($file): $!\n");
  239. }
  240. while($line = <LOGFILE>) {
  241. $lines++; # Increment number of lines.
  242. $line = strip_mirccodes($line);
  243. my $hashref;
  244. # Match normal lines.
  245. if ($hashref = parse_normalline($line)) {
  246. my ($hour, $nick, $saying, $i);
  247. for ($i = 0; $i <= $repeated; $i++) {
  248. if ($i > 0) {
  249. $hashref = parse_normalline($lastnormal);
  250. $lines++; #Increment number of lines for repeated lines
  251. }
  252. $hour = $hashref->{hour};
  253. $nick = find_alias($hashref->{nick});
  254. $saying = $hashref->{saying};
  255. # Timestamp collecting
  256. $times{$hour}++;
  257. unless (grep /^\Q$nick\E$/i, @ignore) {
  258. $normals++;
  259. $line{$nick}++;
  260. # Count up monologues
  261. if ($lastline eq $nick) {
  262. $mono{$nick}++;
  263. if ($mono{$nick} == "5") {
  264. $monologue{$nick}++;
  265. $mono{$nick} = 0;
  266. }
  267. } else {
  268. $mono{$nick} = 0;
  269. }
  270. $lastline = $nick;
  271. my $l = length($saying);
  272. if ($l > $config->{minquote} && $l < $config->{maxquote}) {
  273. # Creates $hash{nick}[n] - a hash of an array.
  274. push (@{ $sayings{$nick} }, htmlentities($saying));
  275. $longlines{$nick}++;
  276. }
  277. $question{$nick}++
  278. if ($saying =~ /\?/);
  279. $loud{$nick}++
  280. if ($saying =~ /!/);
  281. $foul{$nick}++
  282. if ($saying =~ /ass|fuck|bitch|shit|scheisse|scheiße|kacke|arsch|ficker|ficken|schlampe/);
  283. # Who smiles the most?
  284. # A regex matching al lot of smilies
  285. $smile{$nick}++
  286. if ($saying =~ /[8;:=][ ^-o]?[)pPD}\]>]/);
  287. $sadface{$nick}++
  288. if ($saying =~ /[8;:=][ ^-]?[\(\[\\\/{]/);
  289. # Don't count http:// as a :/ face
  290. $sadface{$nick}--
  291. if ($saying =~ /\w+:\/\//);
  292. foreach my $word (split(/[\s,!?.:;)(]+/, $saying)) {
  293. # remove uninteresting words
  294. next unless (length($word) > $config->{wordlength});
  295. # ignore contractions
  296. next if ($word =~ m/'..?$/);
  297. $wordcount{htmlentities($word)}++ unless (grep /^\Q$word\E$/i, @ignore);
  298. $lastused{htmlentities($word)} = $nick;
  299. }
  300. $length{$nick} += $l;
  301. $totallength += $l;
  302. }
  303. }
  304. $lastnormal = $line;
  305. $repeated = 0;
  306. }
  307. # Match action lines.
  308. elsif ($hashref = parse_actionline($line)) {
  309. my ($hour, $nick, $saying);
  310. $hour = $hashref->{hour};
  311. $nick = find_alias($hashref->{nick});
  312. $saying = $hashref->{saying};
  313. # Timestamp collecting
  314. $times{$hour}++;
  315. unless (grep /^\Q$nick\E$/i, @ignore) {
  316. $actions++;
  317. $line{$nick}++;
  318. my $len = length($saying);
  319. $length{$nick} += $len;
  320. $totallength += $len;
  321. }
  322. }
  323. # Match *** lines.
  324. elsif (($hashref = parse_thirdline($line)) && $hashref->{nick}) {
  325. my ($hour, $min, $nick, $kicker, $newtopic, $newmode, $newjoin, $newnick);
  326. $hour = $hashref->{hour};
  327. $min = $hashref->{min};
  328. $nick = find_alias($hashref->{nick});
  329. $kicker = $hashref->{kicker};
  330. $newtopic = $hashref->{newtopic};
  331. $newmode = $hashref->{newmode};
  332. $newjoin = $hashref->{newjoin};
  333. $newnick = $hashref->{newnick};
  334. # Timestamp collecting
  335. $times{$hour}++;
  336. unless (grep /^\Q$nick\E$/i, @ignore) {
  337. if (defined($kicker)) {
  338. unless (grep /^\Q$kicker\E$/i, @ignore) {
  339. $gotkick{$nick}++;
  340. $kicked{$kicker}++;
  341. }
  342. } elsif (defined($newtopic)) {
  343. my $tcount = @topics;
  344. $topics[$tcount]{topic} = htmlentities($newtopic);
  345. $topics[$tcount]{nick} = $nick;
  346. $topics[$tcount]{hour} = $hour;
  347. $topics[$tcount]{min} = $min;
  348. # Strip off the quotes (')
  349. $topics[$tcount]{topic} =~ s/^\'(.*)\'$/$1/;
  350. } elsif (defined($newmode)) {
  351. my @opchange = opchanges($newmode);
  352. unless (exists $gaveop{$nick}) { $gaveop{$nick} = 0 }
  353. $gaveop{$nick} += $opchange[0] if $opchange[0];
  354. $tookop{$nick} += $opchange[1] if $opchange[1];
  355. } elsif (defined($newjoin)) {
  356. $joins{$nick}++;
  357. } elsif (defined($newnick) && ($config->{nicktracking} == 1)) {
  358. if (find_alias($newnick) eq $newnick) {
  359. if (defined($alias{$nick}) && !defined($alias{$newnick})) {
  360. push (@{$alias{$nick}}, $newnick);
  361. } elsif (defined($alias{$newnick}) && !defined($alias{$nick})) {
  362. push (@{$alias{$newnick}}, $nick);
  363. } elsif ($nick =~ /Guest/) {
  364. push (@{$alias{$newnick}}, ($newnick, $nick));
  365. } else {
  366. push (@{$alias{$nick}}, ($nick, $newnick));
  367. }
  368. }
  369. }
  370. }
  371. if ($hour < $oldtime) { $days++ }
  372. $oldtime = $hour;
  373. }
  374. }
  375. close(LOGFILE);
  376. my ($sec,$min,$hour) = gmtime(time - $^T);
  377. $processtime = sprintf("%02d hours, %02d minutes and %02d seconds", $hour, $min, $sec);
  378. $nicks = scalar keys %line;
  379. print "Finished analyzing log, $days days total.\n";
  380. }
  381. # Here is the 3 parse sub routines, their function is to return a hash with
  382. # the elements in the line. This is where we add the format dependent stuff.
  383. sub parse_normalline
  384. {
  385. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  386. my $line = shift;
  387. my %hash;
  388. if ($line =~ /$normalline/) {
  389. debug("[$lines] Normal: $1 $2 $3");
  390. if (($config->{format} eq 'mIRC') || ($config->{format} eq 'xchat') || ($config->{format} eq
  391. 'eggdrop') || ($config->{format} eq 'bxlog') || ($config->{format} eq 'grufti')) {
  392. $hash{hour} = $1;
  393. $hash{nick} = $2;
  394. $hash{saying} = $3;
  395. } else {
  396. die("Format not supported?!\n");
  397. }
  398. return \%hash;
  399. } else {
  400. return;
  401. }
  402. }
  403. sub parse_actionline
  404. {
  405. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  406. my $line = shift;
  407. my %hash;
  408. if ($line =~ /$actionline/) {
  409. debug("[$lines] Action: $1 $2 $3");
  410. if (($config->{format} eq 'mIRC') || ($config->{format} eq 'xchat') || ($config->{format} eq
  411. 'eggdrop') || $config->{format} eq 'bxlog' || ($config->{format} eq 'grufti')) {
  412. $hash{hour} = $1;
  413. $hash{nick} = $2;
  414. $hash{saying} = $3;
  415. } else {
  416. die("Format not supported?!\n");
  417. }
  418. return \%hash;
  419. } else {
  420. return;
  421. }
  422. }
  423. sub parse_thirdline
  424. {
  425. # Parses the 'third' line - (the third line is everything else, like
  426. # topic changes, mode changes, kicks, etc.)
  427. # parse_thirdline() have to return a hash with the following keys, for
  428. # every format:
  429. # hour - the hour we're in (for timestamp loggin)
  430. # min - the minute we're in (for timestamp loggin)
  431. # nick - the nick
  432. # kicker - the nick which were kicked (if any)
  433. # newtopic - the new topic (if any)
  434. # newmode - a deop or an op, must be '+o' or '-o'
  435. # newjoin - a new nick which has joined the channel
  436. # newnick - a person has changed nick and this is the new nick
  437. my $line = shift;
  438. my %hash;
  439. if ($line =~ /$thirdline/) {
  440. if ($7) {
  441. debug("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
  442. } elsif ($5) {
  443. debug("[$lines] ***: $1 $2 $3 $4 $5 $6");
  444. } else {
  445. debug("[$lines] ***: $1 $2 $3 $4");
  446. }
  447. if ($config->{format} eq 'mIRC') {
  448. $hash{hour} = $1;
  449. $hash{min} = $2;
  450. $hash{nick} = $3;
  451. if (($4.$5) eq 'waskicked') {
  452. $hash{kicker} = $7;
  453. } elsif (($4.$5) eq 'changestopic') {
  454. $hash{newtopic} = "$7 $8";
  455. } elsif (($4.$5) eq 'setsmode:') {
  456. $hash{newmode} = $6;
  457. } elsif (($4.$5) eq 'hasjoined') {
  458. $hash{newjoin} = $3;
  459. } elsif (($4.$5) eq 'nowknown') {
  460. $hash{newnick} = $8;
  461. }
  462. } elsif ($config->{format} eq 'xchat') {
  463. $hash{hour} = $1;
  464. $hash{min} = $2;
  465. $hash{nick} = $3;
  466. if (($4.$5) eq 'haskicked') {
  467. $hash{kicker} = $3;
  468. $hash{nick} = $6;
  469. } elsif (($4.$5) eq 'haschanged') {
  470. $hash{newtopic} = $9;
  471. } elsif (($4.$5) eq 'giveschannel') {
  472. $hash{newmode} = '+o';
  473. } elsif (($4.$5) eq 'removeschannel') {
  474. $hash{newmode} = '-o';
  475. } elsif (($5.$6) eq 'hasjoined') {
  476. $hash{newjoin} = $1;
  477. } elsif (($5.$6) eq 'nowknown') {
  478. $hash{newnick} = $8;
  479. }
  480. } elsif ($config->{format} eq 'eggdrop') {
  481. $hash{hour} = $1;
  482. $hash{min} = $2;
  483. $hash{nick} = $3;
  484. if (($4.$5) eq 'kickedfrom') {
  485. $7 =~ /^ by ([\S]+):.*/;
  486. $hash{kicker} = $1;
  487. } elsif ($3 eq 'Topic') {
  488. $7 =~ /^ by ([\S]+)![\S]+: (.*)/;
  489. $hash{nick} = $1;
  490. $hash{newtopic} = $2;
  491. } elsif (($4.$5) eq 'modechange') {
  492. $hash{newmode} = $6;
  493. $7 =~ /^ .+ by ([\S]+)!.*/;
  494. $hash{nick} = $1;
  495. $hash{newmode} =~ s/^\'//;
  496. } elsif ($5 eq 'joined') {
  497. $hash{newjoin} = $3;
  498. } elsif (($3.$4) eq 'Nickchange:') {
  499. $hash{nick} = $5;
  500. $7 =~ /([\S]+)/;
  501. $hash{newnick} = $1;
  502. } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
  503. $repeated = $6;
  504. }
  505. } elsif ($config->{format} eq 'bxlog') {
  506. $hash{hour} = $1;
  507. $hash{min} = $2;
  508. if ($3 eq '<') {
  509. if ($4 =~ /^([^!]+)!([\S+]) was kicked off (\S+) by ([^!]+)!(\S+) \(([^)]+)\)$/) {
  510. $hash{kicker} = $4;
  511. $hash{nick} = $1;
  512. }
  513. } elsif ($3 eq '>') {
  514. if ($4 =~ /^([^!])+!(\S+) has joined (\S+)$/) {
  515. $hash{nick} = $1;
  516. $hash{newjoin} = $1;
  517. }
  518. } elsif ($3 eq '@') {
  519. if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
  520. $hash{nick} = $1;
  521. $hash{newtopic} = $2;
  522. } elsif ($4 =~ /^mode (\S+) \[([+-]o)\S* (\S+)[^\]]*\] by ([^!]+)!(\S+)$/) {
  523. $hash{newmode} = $2;
  524. $hash{nick} = $4;
  525. }
  526. } elsif ($3 eq '!') {
  527. if ($4 =~ /^(\S+) is known as (\S+)$/) {
  528. $hash{nick} = $1;
  529. $hash{newnick} = $2;
  530. }
  531. }
  532. } elsif ($config->{format} eq 'grufti') {
  533. $hash{hour} = $1;
  534. $hash{min} = $2;
  535. $hash{nick} = $3;
  536. if ($5 eq 'kicked') {
  537. $hash{kicker} = $3;
  538. $hash{nick} = $6;
  539. } elsif (($4.$5) eq 'haschanged') {
  540. $hash{newtopic} = $9;
  541. } elsif (($4.$5) eq 'modechange') {
  542. $hash{newmode} = substr($6, 1);
  543. $hash{nick} = substr($9, 1);
  544. } elsif ($5 eq 'joined') {
  545. $hash{newjoin} = $1;
  546. } elsif (($3.$4) eq 'Nickchange') {
  547. $hash{nick} = $7;
  548. $hash{newnick} = $9;
  549. }
  550. } else {
  551. die("Format not supported?!\n");
  552. }
  553. return \%hash;
  554. } else {
  555. return;
  556. }
  557. }
  558. sub opchanges
  559. {
  560. my @modes = split(//, $_[0]);
  561. my ($mode,$plus) = ("",0);
  562. my ($gaveop,$tookop) = (0,0);
  563. foreach (@modes) {
  564. if (/^\+$/) { $plus = 1; next; }
  565. elsif (/^-$/) { $plus = 0; next; }
  566. else { next unless /^o$/ }
  567. if ($plus) { $gaveop++ } else { $tookop++ }
  568. }
  569. my @out = ($gaveop,$tookop);
  570. return @out;
  571. }
  572. sub strip_mirccodes
  573. {
  574. my $line = shift;
  575. my $boldcode = chr(2);
  576. my $colorcode = chr(3);
  577. my $plaincode = chr(15);
  578. my $reversecode = chr(22);
  579. my $underlinecode = chr(31);
  580. # Strip mIRC color codes
  581. $line =~ s/$colorcode\d{1,2},\d{1,2}//g;
  582. $line =~ s/$colorcode\d{0,2}//g;
  583. # Strip mIRC bold, plain, reverse and underline codes
  584. $line =~ s/[$boldcode$underlinecode$reversecode$plaincode]//g;
  585. return $line;
  586. }
  587. sub htmlentities
  588. {
  589. my $str = shift;
  590. $str =~ s/\&/\&amp;/g;
  591. $str =~ s/\</\&lt;/g;
  592. $str =~ s/\>/\&gt;/g;
  593. return $str;
  594. }
  595. sub html
  596. {
  597. my $html = shift;
  598. print OUTPUT $html . "\n";
  599. }
  600. sub template_text
  601. {
  602. # This function is for the homemade template system. It receives a name
  603. # of a template and a hash with the fields in the template to update to
  604. # its corresponding value
  605. my $template = shift;
  606. my %hash = @_;
  607. my $text;
  608. if (!$T{$config->{lang}}{$template}) {
  609. # Fall back to English if the language template doesn't exist
  610. $text = $T{EN}{$template};
  611. }
  612. $text = $T{$config->{lang}}{$template};
  613. if (!$text) {
  614. die("No such template $template\n");
  615. }
  616. foreach my $key (sort keys %hash) {
  617. $text =~ s/\[:$key\]/$hash{$key}/;
  618. $text =~ s/ü/&uuml;/g;
  619. $text =~ s/ö/&ouml;/g;
  620. $text =~ s/ä/&auml;/g;
  621. $text =~ s/ß/&szlig;/g;
  622. $text =~ s/å/&aring;/g;
  623. $text =~ s/æ/&aelig;/g;
  624. $text =~ s/ø/&oslash;/g;
  625. }
  626. return $text;
  627. }
  628. sub replace_links
  629. {
  630. # Sub to replace urls and e-mail addys to links
  631. my $str = shift;
  632. my $nick = shift;
  633. if ($nick) {
  634. $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;
  635. $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;
  636. } else {
  637. $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;
  638. $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;
  639. }
  640. return $str;
  641. }
  642. sub debug
  643. {
  644. if ($config->{debug}) {
  645. my $debugline = $_[0] . "\n";
  646. print DEBUG $debugline;
  647. }
  648. }
  649. sub find_alias
  650. {
  651. my $nick = shift;
  652. foreach (keys %alias) {
  653. return $_ if (grep /^\Q$nick\E$/i, @{$alias{$_}});
  654. }
  655. return $nick;
  656. }
  657. sub create_html
  658. {
  659. # This is where all subroutines get executed, you can actually design
  660. # your own layout here, the lines should be self-explainable
  661. print "Now generating HTML($config->{outputfile})...\n";
  662. open (OUTPUT, "> $config->{outputfile}") or die("$0: Unable to open outputfile($config->{outputfile}): $!\n");
  663. htmlheader();
  664. pageheader();
  665. activetimes();
  666. activenicks();
  667. headline(template_text('bignumtopic'));
  668. html("<table width=\"614\">\n"); # Needed for sections
  669. questions();
  670. loudpeople();
  671. mostsmiles();
  672. mostsad();
  673. longlines();
  674. shortlines();
  675. html("</table>"); # Needed for sections
  676. mostusedword();
  677. mostreferenced();
  678. headline(template_text('othernumtopic'));
  679. html("<table width=\"614\">\n"); # Needed for sections
  680. gotkicks();
  681. mostkicks();
  682. mostop();
  683. mostmonologues();
  684. mostjoins();
  685. mostfoul();
  686. html("</table>"); # Needed for sections
  687. headline(template_text('latesttopic'));
  688. html("<table width=\"614\">\n"); # Needed for sections
  689. lasttopics();
  690. html("</table>"); # Needed for sections
  691. my %hash = ( lines => $lines );
  692. html(template_text('totallines', %hash) . "<br><br>");
  693. htmlfooter();
  694. close(OUTPUT);
  695. }
  696. sub activetimes
  697. {
  698. # The most actives times on the channel
  699. my (%output, $tbgcolor);
  700. &headline(template_text('activetimestopic'));
  701. my @toptime = sort { $times{$b} <=> $times{$a} } keys %times;
  702. my $highest_value = $times{$toptime[0]};
  703. my @now = localtime($timestamp);
  704. my $image;
  705. for my $hour (sort keys %times) {
  706. debug("Time: $hour => ". $times{$hour});
  707. if ($toptime[0] == $hour) {
  708. $image = $config->{pic2};
  709. } else {
  710. $image = $config->{pic1};
  711. }
  712. my $size = ($times{$hour} / $highest_value) * 100;
  713. my $percent = ($times{$hour} / $lines) * 100;
  714. $percent =~ s/(\.\d)\d+/$1/;
  715. if ($config->{timeoffset} =~ /\+(\d+)/) {
  716. # We must plus some hours to the time
  717. $hour += $1;
  718. $hour = $hour % 24;
  719. if ($hour < 10) { $hour = "0" . $hour; }
  720. } elsif ($config->{timeoffset} =~ /-(\d+)/) {
  721. # We must remove some hours from the time
  722. $hour -= $1;
  723. $hour = $hour % 24;
  724. if ($hour < 10) { $hour = "0" . $hour; }
  725. }
  726. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  727. }
  728. html("<table border=\"0\" width=\"614\"><tr>\n");
  729. for ($b = 0; $b < 24; $b++) {
  730. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  731. if (!defined($output{$a}) || $output{$a} eq "") {
  732. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  733. } else {
  734. html($output{$a});
  735. }
  736. }
  737. html("</tr><tr>");
  738. for ($b = 0; $b < 24; $b++) {
  739. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  740. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  741. }
  742. html("</tr></table>");
  743. }
  744. sub activenicks
  745. {
  746. # The most active nicks (those who wrote most lines)
  747. headline(template_text('activenickstopic'));
  748. html("<table border=\"0\" width=\"614\"><tr>");
  749. html("<td>&nbsp;</td><td bgcolor=\"$config->{tdtop}\"><b>" . template_text('nick') . "</b></td><td bgcolor=\"$config->{tdtop}\"><b>" . template_text('numberlines') ."</b></td><td bgcolor=\"$config->{tdtop}\"><b>". template_text('randquote') ."</b></td>");
  750. if (%userpics) {
  751. html("<td bgcolor=\"$config->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  752. }
  753. html("</tr>");
  754. my @active = sort { $line{$b} <=> $line{$a} } keys %line;
  755. if ($config->{activenicks} > $nicks) {
  756. $config->{activenicks} = $nicks;
  757. print "Note: There was less nicks in the logfile than your specificied there to be in most active nicks...\n";
  758. }
  759. my ($nick, $visiblenick, $randomline);
  760. my $i = 1;
  761. for (my $c = 0; $c < $config->{activenicks}; $c++) {
  762. $nick = $active[$c];
  763. $visiblenick = $active[$c];
  764. if (!$longlines{$nick}) {
  765. $randomline = "";
  766. } else {
  767. my $rand = rand($longlines{$nick});
  768. $randomline = $sayings{$nick}[$rand];
  769. }
  770. # Convert URLs and e-mail addys to links
  771. $randomline = replace_links($randomline);
  772. # Add a link to the nick if there is any
  773. if ($userlinks{$nick}) {
  774. $visiblenick = replace_links($userlinks{$nick}, $nick);
  775. }
  776. my $h = $config->{hicell};
  777. $h =~ s/^#//;
  778. $h = hex $h;
  779. my $h2 = $config->{hicell2};
  780. $h2 =~ s/^#//;
  781. $h2 = hex $h2;
  782. my $f_b = $h & 0xff;
  783. my $f_g = ($h & 0xff00) >> 8;
  784. my $f_r = ($h & 0xff0000) >> 16;
  785. my $t_b = $h2 & 0xff;
  786. my $t_g = ($h2 & 0xff00) >> 8;
  787. my $t_r = ($h2 & 0xff0000) >> 16;
  788. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $config->{activenicks}) * +$c) + $f_b);
  789. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $config->{activenicks}) * +$c) + $f_g);
  790. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $config->{activenicks}) * +$c) + $f_r);
  791. html("<tr><td bgcolor=\"$config->{rankc}\" align=\"left\">");
  792. my $line = $line{$nick};
  793. 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\">");
  794. html("\"$randomline\"</td>");
  795. if ($userpics{$nick}) {
  796. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$config->{imagepath}$userpics{$nick}\"></td>");
  797. }
  798. html("</tr>");
  799. $i++;
  800. }
  801. html("</table><br>");
  802. # Almost as active nicks ('These didn't make it to the top..')
  803. my $nickstoshow = $config->{activenicks} + $config->{activenicks2};
  804. unless ($nickstoshow > $nicks) {
  805. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  806. for (my $c = $config->{activenicks}; $c < $nickstoshow; $c++) {
  807. unless ($c % 5) { unless ($c == $config->{activenicks}) { html("</tr><tr>"); } }
  808. html("<td bgcolor=\"$config->{rankc}\" class=\"small\">");
  809. my $nick = $active[$c];
  810. my $lines = $line{$nick};
  811. html("$nick ($lines)</td>");
  812. }
  813. html("</table>");
  814. }
  815. }
  816. sub mostusedword
  817. {
  818. # Lao the infamous word usage statistics
  819. my %usages;
  820. foreach my $word (sort keys %wordcount) {
  821. next if exists $line{$word};
  822. $usages{$word} = $wordcount{$word};
  823. }
  824. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  825. if (@popular) {
  826. &headline(template_text('mostwordstopic'));
  827. html("<table border=\"0\" width=\"614\"><tr>");
  828. html("<td>&nbsp;</td><td bgcolor=\"$config->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  829. html("<td bgcolor=\"$config->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  830. html("<td bgcolor=\"$config->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  831. for(my $i = 0; $i < 10; $i++) {
  832. last unless $i < $#popular;
  833. my $a = $i + 1;
  834. my $popular = $popular[$i];
  835. my $wordcount = $wordcount{$popular[$i]};
  836. my $lastused = $lastused{$popular[$i]};
  837. html("<tr><td bgcolor=\"$config->{rankc}\"><b>$a</b>");
  838. html("<td bgcolor=\"$config->{hicell}\">$popular</td>");
  839. html("<td bgcolor=\"$config->{hicell}\">$wordcount</td>");
  840. html("<td bgcolor=\"$config->{hicell}\">$lastused</td>");
  841. html("</tr>");
  842. }
  843. html("</table>");
  844. }
  845. }
  846. sub mostreferenced
  847. {
  848. my %usages;
  849. foreach my $word (sort keys %wordcount) {
  850. next unless exists $line{$word};
  851. $usages{$word} = $wordcount{$word};
  852. }
  853. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  854. if (@popular) {
  855. &headline(template_text('referencetopic'));
  856. html("<table border=\"0\" width=\"614\"><tr>");
  857. html("<td>&nbsp;</td><td bgcolor=\"$config->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  858. html("<td bgcolor=\"$config->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  859. html("<td bgcolor=\"$config->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  860. for(my $i = 0; $i < 5; $i++) {
  861. last unless $i < $#popular;
  862. my $a = $i + 1;
  863. my $popular = $popular[$i];
  864. my $wordcount = $wordcount{$popular[$i]};
  865. my $lastused = $lastused{$popular[$i]};
  866. html("<tr><td bgcolor=\"$config->{rankc}\"><b>$a</b>");
  867. html("<td bgcolor=\"$config->{hicell}\">$popular</td>");
  868. html("<td bgcolor=\"$config->{hicell}\">$wordcount</td>");
  869. html("<td bgcolor=\"$config->{hicell}\">$lastused</td>");
  870. html("</tr>");
  871. }
  872. html("</table>");
  873. }
  874. }
  875. sub questions
  876. {
  877. # Persons who asked the most questions
  878. foreach my $nick (sort keys %question) {
  879. if ($line{$nick} > 100) {
  880. $qpercent{$nick} = ($question{$nick} / $line{$nick}) * 100;
  881. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  882. }
  883. }
  884. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  885. if (@question) {
  886. my %hash = (
  887. nick => $question[0],
  888. per => $qpercent{$question[0]}
  889. );
  890. my $text = template_text('question1', %hash);
  891. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  892. if (@question >= 2) {
  893. my %hash = (
  894. nick => $question[1],
  895. per => $qpercent{$question[1]}
  896. );
  897. my $text = template_text('question2', %hash);
  898. html("<br><span class=\"small\">$text</span>");
  899. }
  900. html("</td></tr>");
  901. } else {
  902. html("<tr><td bgcolor=\"$config->{hicell}\">" . template_text('question3') . "</td></tr>");
  903. }
  904. }
  905. sub loudpeople
  906. {
  907. # The ones who speak LOUDLY!
  908. foreach my $nick (sort keys %loud) {
  909. if ($line{$nick} > 100) {
  910. $lpercent{$nick} = ($loud{$nick} / $line{$nick}) * 100;
  911. $lpercent{$nick} =~ s/(\.\d)\d+/$1/;
  912. }
  913. }
  914. my @loud = sort { $lpercent{$b} <=> $lpercent{$a} } keys %lpercent;
  915. if (@loud) {
  916. my %hash = (
  917. nick => $loud[0],
  918. per => $lpercent{$loud[0]}
  919. );
  920. my $text = template_text('loud1', %hash);
  921. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  922. if (@loud >= 2) {
  923. my %hash = (
  924. nick => $loud[1],
  925. per => $lpercent{$loud[1]}
  926. );
  927. my $text = template_text('loud2', %hash);
  928. html("<br><span class=\"small\">$text</span>");
  929. }
  930. html("</td></tr>");
  931. } else {
  932. my $text = template_text('loud3');
  933. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  934. }
  935. }
  936. sub gotkicks
  937. {
  938. # The persons who got kicked the most
  939. my @gotkick = sort { $gotkick{$b} <=> $gotkick{$a} } keys %gotkick;
  940. if (@gotkick) {
  941. my %hash = (
  942. nick => $gotkick[0],
  943. kicks => $gotkick{$gotkick[0]}
  944. );
  945. my $text = template_text('gotkick1', %hash);
  946. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  947. if (@gotkick >= 2) {
  948. my %hash = (
  949. nick => $gotkick[1],
  950. kicks => $gotkick{$gotkick[1]}
  951. );
  952. my $text = template_text('gotkick2', %hash);
  953. html("<br><span class=\"small\">$text</span>");
  954. }
  955. html("</td></tr>");
  956. }
  957. }
  958. sub mostjoins
  959. {
  960. my @joins = sort { $joins{$b} <=> $joins{$a} } keys %joins;
  961. if (@joins) {
  962. my %hash = (
  963. nick => $joins[0],
  964. joins => $joins{$joins[0]}
  965. );
  966. my $text = template_text('joins', %hash);
  967. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  968. }
  969. }
  970. sub mostkicks
  971. {
  972. # The person who got kicked the most
  973. my @kicked = sort { $kicked{$b} <=> $kicked{$a} } keys %kicked;
  974. if (@kicked) {
  975. my %hash = (
  976. nick => $kicked[0],
  977. kicked => $kicked{$kicked[0]}
  978. );
  979. my $text = template_text('kick1', %hash);
  980. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  981. if (@kicked >= 2) {
  982. my %hash = (
  983. oldnick => $kicked[0],
  984. nick => $kicked[1],
  985. kicked => $kicked{$kicked[1]}
  986. );
  987. my $text = template_text('kick2', %hash);
  988. html("<br><span class=\"small\">$text</span>");
  989. }
  990. html("</td></tr>");
  991. } else {
  992. my $text = template_text('kick3');
  993. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  994. }
  995. }
  996. sub mostmonologues
  997. {
  998. # The person who had the most monologues (speaking to himself)
  999. my @monologue = sort { $monologue{$b} <=> $monologue{$a} } keys %monologue;
  1000. if (@monologue) {
  1001. my %hash = (
  1002. nick => $monologue[0],
  1003. monos => $monologue{$monologue[0]}
  1004. );
  1005. my $text = template_text('mono1', %hash);
  1006. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1007. if (@monologue >= 2) {
  1008. my %hash = (
  1009. nick => $monologue[1],
  1010. monos => $monologue{$monologue[1]}
  1011. );
  1012. my $text = template_text('mono2', %hash);
  1013. if ($monologue{$monologue[1]} == 1 && $config->{lang} eq 'EN') {
  1014. $text = substr $text, 0, -1;
  1015. }
  1016. html("<br><span class=\"small\">$text</span>");
  1017. }
  1018. html("</td></tr>");
  1019. }
  1020. }
  1021. sub longlines
  1022. {
  1023. my %len;
  1024. # The person(s) who wrote the longest lines
  1025. foreach my $nick (sort keys %length) {
  1026. if ($line{$nick} > 100) {
  1027. $len{$nick} = $length{$nick} / $line{$nick};
  1028. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1029. }
  1030. }
  1031. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1032. my $all_lines = $normals + $actions;
  1033. my $totalaverage;
  1034. if ($all_lines > 0) {
  1035. $totalaverage = $totallength / $all_lines;
  1036. $totalaverage =~ s/(\.\d)\d+/$1/;
  1037. }
  1038. if (@len) {
  1039. my %hash = (
  1040. nick => $len[0],
  1041. letters => $len{$len[0]}
  1042. );
  1043. my $text = template_text('long1', %hash);
  1044. html("<tr><td bgcolor=\"$config->{hicell}\">$text<br>");
  1045. if (@len >= 2) {
  1046. %hash = (
  1047. channel => $config->{channel},
  1048. avg => $totalaverage
  1049. );
  1050. $text = template_text('long2', %hash);
  1051. html("<span class=\"small\">$text</span></td></tr>");
  1052. }
  1053. }
  1054. }
  1055. sub shortlines
  1056. {
  1057. # This sub should be combined with the longlines sub at some point.. it
  1058. # does basically the same thing.
  1059. my %len;
  1060. # The person(s) who wrote the shortest lines
  1061. foreach my $nick (sort keys %length) {
  1062. if ($line{$nick} > 5) {
  1063. $len{$nick} = $length{$nick} / $line{$nick};
  1064. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1065. }
  1066. }
  1067. my @len = sort { $len{$a} <=> $len{$b} } keys %len;
  1068. if (@len) {
  1069. my %hash = (
  1070. nick => $len[0],
  1071. letters => $len{$len[0]}
  1072. );
  1073. my $text = template_text('short1', %hash);
  1074. html("<tr><td bgcolor=\"$config->{hicell}\">$text<br>");
  1075. if (@len >= 2) {
  1076. %hash = (
  1077. nick => $len[1],
  1078. letters => $len{$len[1]}
  1079. );
  1080. $text = template_text('short2', %hash);
  1081. html("<span class=\"small\">$text</span></td></tr>");
  1082. }
  1083. }
  1084. }
  1085. sub mostfoul
  1086. {
  1087. my %spercent;
  1088. foreach my $nick (sort keys %foul) {
  1089. if ($line{$nick} > 15) {
  1090. $spercent{$nick} = ($foul{$nick} / $line{$nick}) * 100;
  1091. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1092. }
  1093. }
  1094. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1095. if (@foul) {
  1096. my %hash = (
  1097. nick => $foul[0],
  1098. per => $spercent{$foul[0]}
  1099. );
  1100. my $text = template_text('foul1', %hash);
  1101. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1102. if (@foul >= 2) {
  1103. my %hash = (
  1104. nick => $foul[1],
  1105. per => $spercent{$foul[1]}
  1106. );
  1107. my $text = template_text('foul2', %hash);
  1108. html("<br><span class=\"small\">$text</span>");
  1109. }
  1110. html("</td></tr>");
  1111. } else {
  1112. my %hash = (
  1113. channel => $config->{channel}
  1114. );
  1115. my $text = template_text('foul3', %hash);
  1116. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  1117. }
  1118. }
  1119. sub mostsad
  1120. {
  1121. my %spercent;
  1122. foreach my $nick (sort keys %sadface) {
  1123. if ($line{$nick} > 100) {
  1124. $spercent{$nick} = ($sadface{$nick} / $line{$nick}) * 100;
  1125. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1126. }
  1127. }
  1128. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1129. if (@sadface) {
  1130. my %hash = (
  1131. nick => $sadface[0],
  1132. per => $spercent{$sadface[0]}
  1133. );
  1134. my $text = template_text('sad1', %hash);
  1135. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1136. if (@sadface >= 2) {
  1137. my %hash = (
  1138. nick => $sadface[1],
  1139. per => $spercent{$sadface[1]}
  1140. );
  1141. my $text = template_text('sad2', %hash);
  1142. html("<br><span class=\"small\">$text</span>");
  1143. }
  1144. html("</td></tr>");
  1145. } else {
  1146. my %hash = (
  1147. channel => $config->{channel}
  1148. );
  1149. my $text = template_text('sad3', %hash);
  1150. html("<tr><td bgcolor=\"$config->{hicell}\">$config->text</td></tr>");
  1151. }
  1152. }
  1153. sub mostop
  1154. {
  1155. my @ops = sort { $gaveop{$b} <=> $gaveop{$a} } keys %gaveop;
  1156. my @deops = sort { $tookop{$b} <=> $tookop{$a} } keys %tookop;
  1157. if (@ops) {
  1158. my %hash = (
  1159. nick => $ops[0],
  1160. ops => $gaveop{$ops[0]}
  1161. );
  1162. my $text = template_text('mostop1', %hash);
  1163. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1164. if (@ops >= 2) {
  1165. my %hash = (
  1166. nick => $ops[1],
  1167. ops => $gaveop{$ops[1]}
  1168. );
  1169. my $text = template_text('mostop2', %hash);
  1170. html("<br><span class=\"small\">$text</span>");
  1171. }
  1172. html("</td></tr>");
  1173. } else {
  1174. my %hash = ( channel => $config->{channel} );
  1175. my $text = template_text('mostop3', %hash);
  1176. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  1177. }
  1178. if (@deops) {
  1179. my %hash = (
  1180. channel => $config->{channel},
  1181. nick => $deops[0],
  1182. deops => $tookop{$deops[0]}
  1183. );
  1184. my $text = template_text('mostdeop1', %hash);
  1185. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1186. if (@deops >= 2) {
  1187. my %hash = (
  1188. nick => $deops[1],
  1189. deops => $tookop{$deops[1]}
  1190. );
  1191. my $text = template_text('mostdeop2', %hash);
  1192. html("<br><span class=\"small\">$text</span>");
  1193. }
  1194. html("</td></tr>");
  1195. } else {
  1196. my %hash = ( channel => $config->{channel} );
  1197. my $text = template_text('mostdeop3', %hash);
  1198. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1199. }
  1200. }
  1201. sub mostsmiles
  1202. {
  1203. # The person(s) who smiled the most :-)
  1204. my %spercent;
  1205. foreach my $nick (sort keys %smile) {
  1206. if ($line{$nick} > 100) {
  1207. $spercent{$nick} = ($smile{$nick} / $line{$nick}) * 100;
  1208. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1209. }
  1210. }
  1211. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1212. if (@smiles) {
  1213. my %hash = (
  1214. nick => $smiles[0],
  1215. per => $spercent{$smiles[0]}
  1216. );
  1217. my $text = template_text('smiles1', %hash);
  1218. html("<tr><td bgcolor=\"$config->{hicell}\">$text");
  1219. if (@smiles >= 2) {
  1220. my %hash = (
  1221. nick => $smiles[1],
  1222. per => $spercent{$smiles[1]}
  1223. );
  1224. my $text = template_text('smiles2', %hash);
  1225. html("<br><span class=\"small\">$text</span>");
  1226. }
  1227. html("</td></tr>");
  1228. } else {
  1229. my %hash = (
  1230. channel => $config->{channel}
  1231. );
  1232. my $text = template_text('smiles3', %hash);
  1233. html("<tr><td bgcolor=\"$config->{hicell}\">$text</td></tr>");
  1234. }
  1235. }
  1236. sub lasttopics
  1237. {
  1238. debug("Total number of topics: ". scalar @topics);
  1239. if (@topics) {
  1240. my $ltopic = @topics - 1;
  1241. my $tlimit = 0;
  1242. $config->{topichistory} -= 1;
  1243. if ($ltopic > $config->{topichistory}) { $tlimit = $ltopic - $config->{topichistory}; }
  1244. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1245. $topics[$i]{"topic"} = replace_links($topics[$i]{"topic"});
  1246. my $topic = $topics[$i]{topic};
  1247. my $nick = $topics[$i]{nick};
  1248. my $hour = $topics[$i]{hour};
  1249. my $min = $topics[$i]{min};
  1250. html("<tr><td bgcolor=\"$config->{hicell}\"><i>$topic</i></td>");
  1251. html("<td bgcolor=\"$config->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1252. }
  1253. } else {
  1254. html("<tr><td bgcolor=\"$config->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1255. }
  1256. }
  1257. # Some HTML subs
  1258. sub htmlheader
  1259. {
  1260. print OUTPUT <<HTML;
  1261. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1262. <html>
  1263. <head>
  1264. <title>$config->{channel} @ $config->{network} channel statistics</title>
  1265. <style type="text/css">
  1266. a { text-decoration: none }
  1267. a:link { color: $config->{link}; }
  1268. a:visited { color: $config->{vlink}; }
  1269. a:hover { text-decoration: underline; color: $config->{hlink} }
  1270. body {
  1271. background-color: $config->{bgcolor};
  1272. font-family: verdana, arial, sans-serif;
  1273. font-size: 13px;
  1274. color: $config->{text};
  1275. }
  1276. td {
  1277. font-family: verdana, arial, sans-serif;
  1278. font-size: 13px;
  1279. color: $config->{tdcolor};
  1280. }
  1281. .title {
  1282. font-family: tahoma, arial, sans-serif;
  1283. font-size: 16px;
  1284. font-weight: bold;
  1285. }
  1286. .headline { color: $config->{hcolor}; }
  1287. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1288. .asmall { font-family: arial narrow, sans-serif; font-size: 10px }
  1289. </style></head>
  1290. <body>
  1291. <div align="center">
  1292. HTML
  1293. my %hash = (
  1294. channel => $config->{channel},
  1295. network => $config->{network},
  1296. maintainer => $config->{maintainer},
  1297. time => $time,
  1298. days => $days,
  1299. nicks => $nicks,
  1300. channel => $config->{channel}
  1301. );
  1302. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1303. print OUTPUT "<br>" . template_text('pagetitle2', %hash) . "<br>";
  1304. print OUTPUT template_text('pagetitle3', %hash) . "<br><br>";
  1305. }
  1306. sub htmlfooter
  1307. {
  1308. print OUTPUT <<HTML;
  1309. <span class="small">
  1310. Stats generated by <a href="http://www.wtf.dk/hp/index.php?page=pisg" title="Go to the pisg homepage">pisg</a> $config->{version}<br>
  1311. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1312. Stats generated in $processtime
  1313. </span>
  1314. </div>
  1315. </body>
  1316. </html>
  1317. HTML
  1318. }
  1319. sub headline
  1320. {
  1321. my ($title) = @_;
  1322. print OUTPUT <<HTML;
  1323. <br>
  1324. <table width="610" cellpadding="1" cellspacing="0" border="0">
  1325. <tr>
  1326. <td bgcolor="$config->{headline}">
  1327. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1328. <tr>
  1329. <td bgcolor="$config->{hbgcolor}" class="text10">
  1330. <div align="center" class="headline"><b>$title</b></div>
  1331. </td>
  1332. </tr>
  1333. </table>
  1334. </td>
  1335. </tr>
  1336. </table>
  1337. HTML
  1338. }
  1339. sub pageheader
  1340. {
  1341. if ($config->{pagehead} ne 'none') {
  1342. open(PAGEHEAD, $config->{pagehead}) or die("$0: Unable to open $config->{pagehead} for reading: $!\n");
  1343. while (<PAGEHEAD>) {
  1344. html($_);
  1345. }
  1346. }
  1347. }
  1348. sub close_debug
  1349. {
  1350. if ($config->{debug}) {
  1351. close(DEBUG) or print STDERR "$0: Cannot close debugfile($config->{debugfile}): $!\n";
  1352. }
  1353. }
  1354. sub get_cmdlineoptions
  1355. {
  1356. my $tmp;
  1357. # Commandline options
  1358. my $help;
  1359. my $usage = <<END_USAGE;
  1360. Usage: pisg.pl [-c channel] [-l logfile] [-o outputfile] [-m
  1361. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1362. [-i ignorefile] [-h]
  1363. -c --channel=xxx : Set channel name
  1364. -l --logfile=xxx : Log file to parse
  1365. -o --outfile=xxx : Name of html file to create
  1366. -m --maintainer=xxx : Channel/statistics maintainer
  1367. -f --format=xxx : Logfile format [see FORMATS file]
  1368. -n --network=xxx : IRC Network this channel is on.
  1369. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1370. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1371. Only works with --dir
  1372. -u --configfile=xxx : Config file
  1373. -h --help : Output this message and exit (-? also works).
  1374. Example:
  1375. \$ pisg.pl -n IRCnet -f xchat -o suid.html -c \\#channel -l logfile.log
  1376. As always, all options may also be defined by editing the source and calling
  1377. pisg without arguments.
  1378. END_USAGE
  1379. if (GetOptions('channel=s' => \$config->{channel},
  1380. 'logfile=s' => \$config->{logfile},
  1381. 'format=s' => \$config->{format},
  1382. 'network=s' => \$config->{network},
  1383. 'maintainer=s' => \$config->{maintainer},
  1384. 'outfile=s' => \$config->{outputfile},
  1385. 'dir=s' => \$config->{logdir},
  1386. 'prefix=s' => \$config->{prefix},
  1387. 'ignorefile=s' => \$tmp,
  1388. 'aliasfile=s' => \$tmp,
  1389. 'configfile=s' => \$config->{configfile},
  1390. 'help|?' => \$help
  1391. ) == 0 or $help) {
  1392. die($usage);
  1393. }
  1394. if (@ARGV) {
  1395. if ($ARGV[0]) { $config->{channel} = $ARGV[0]; }
  1396. if ($ARGV[1]) { $config->{logfile} = $ARGV[1]; }
  1397. if ($ARGV[2]) { $config->{outputfile} = $ARGV[2]; }
  1398. if ($ARGV[3]) { $config->{maintainer} = $ARGV[3]; }
  1399. }
  1400. if ($tmp) {
  1401. die("The aliasfile and ignorefile has been obsoleted by the new
  1402. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1403. }
  1404. }
  1405. sub get_language_templates
  1406. {
  1407. use FindBin;
  1408. open(FILE, $config->{langfile}) or open (FILE, $FindBin::Bin . "/$config->{langfile}") or die("$0: Unable to open language file($config->{langfile}): $!\n");
  1409. my $current_lang;
  1410. while (<FILE>)
  1411. {
  1412. my $line = $_;
  1413. next if /^#/;
  1414. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1415. # Found start tag, setting the current language
  1416. $current_lang = "$1";
  1417. }
  1418. elsif ($line =~ /<\/lang>/) {
  1419. # Found end tag, resetting the current language
  1420. $current_lang = '';
  1421. }
  1422. elsif ($line =~ /(\w+) = "(.*)"$/ && $current_lang ne '') {
  1423. $T{$current_lang}{$1} = $2;
  1424. }
  1425. }
  1426. close(FILE);
  1427. print "Using language template: $config->{lang}\n\n" if ($config->{lang} ne 'EN');
  1428. }
  1429. &main(); # Run the script