pisg.pl 60 KB

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