pisg.pl 53 KB

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