pisg.pl 52 KB

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