pisg.pl 51 KB

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