pisg.pl 54 KB

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