pisg.pl 55 KB

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