pisg.pl 52 KB

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