pisg.pl 55 KB

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