pisg.pl 58 KB

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