pisg.pl 55 KB

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