pisg.pl 54 KB

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