pisg.pl 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  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. return $str;
  640. }
  641. sub html
  642. {
  643. my $html = shift;
  644. print OUTPUT $html . "\n";
  645. }
  646. sub template_text
  647. {
  648. # This function is for the homemade template system. It receives a name
  649. # of a template and a hash with the fields in the template to update to
  650. # its corresponding value
  651. my $template = shift;
  652. my %hash = @_;
  653. my $text;
  654. if (!$T{$conf->{lang}}{$template}) {
  655. # Fall back to English if the language template doesn't exist
  656. $text = $T{EN}{$template};
  657. }
  658. $text = $T{$conf->{lang}}{$template};
  659. if (!$text) {
  660. die("No such template $template\n");
  661. }
  662. foreach my $key (sort keys %hash) {
  663. $text =~ s/\[:$key\]/$hash{$key}/;
  664. $text =~ s/ü/&uuml;/g;
  665. $text =~ s/ö/&ouml;/g;
  666. $text =~ s/ä/&auml;/g;
  667. $text =~ s/ß/&szlig;/g;
  668. $text =~ s/å/&aring;/g;
  669. $text =~ s/æ/&aelig;/g;
  670. $text =~ s/ø/&oslash;/g;
  671. }
  672. return $text;
  673. }
  674. sub replace_links
  675. {
  676. # Sub to replace urls and e-mail addys to links
  677. my $str = shift;
  678. my $nick = shift;
  679. if ($nick) {
  680. $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;
  681. $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;
  682. } else {
  683. $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;
  684. $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;
  685. }
  686. return $str;
  687. }
  688. sub debug
  689. {
  690. if ($conf->{debug}) {
  691. my $debugline = $_[0] . "\n";
  692. print DEBUG $debugline;
  693. }
  694. }
  695. sub find_alias
  696. {
  697. my $nick = shift;
  698. foreach (keys %alias) {
  699. return $_ if (grep /^\Q$nick\E$/i, @{$alias{$_}});
  700. if (grep /\*/, @{$alias{$_}}) {
  701. foreach my $alias (@{$alias{$_}}) {
  702. return $_ if ($nick =~ /^$alias$/);
  703. }
  704. }
  705. }
  706. return $nick;
  707. }
  708. sub create_html
  709. {
  710. # This is where all subroutines get executed, you can actually design
  711. # your own layout here, the lines should be self-explainable
  712. print "Now generating HTML($conf->{outputfile})...\n";
  713. open (OUTPUT, "> $conf->{outputfile}") or die("$0: Unable to open outputfile($conf->{outputfile}): $!\n");
  714. htmlheader();
  715. pageheader();
  716. activetimes();
  717. activenicks();
  718. headline(template_text('bignumtopic'));
  719. html("<table width=\"614\">\n"); # Needed for sections
  720. questions();
  721. loudpeople();
  722. shoutpeople();
  723. slap();
  724. mostsmiles();
  725. mostsad();
  726. longlines();
  727. shortlines();
  728. html("</table>"); # Needed for sections
  729. mostusedword();
  730. mostreferenced();
  731. headline(template_text('othernumtopic'));
  732. html("<table width=\"614\">\n"); # Needed for sections
  733. gotkicks();
  734. mostkicks();
  735. mostop();
  736. mostmonologues();
  737. mostjoins();
  738. mostfoul();
  739. html("</table>"); # Needed for sections
  740. headline(template_text('latesttopic'));
  741. html("<table width=\"614\">\n"); # Needed for sections
  742. lasttopics();
  743. html("</table>"); # Needed for sections
  744. my %hash = ( lines => $lines );
  745. html(template_text('totallines', %hash) . "<br><br>");
  746. htmlfooter();
  747. close(OUTPUT);
  748. }
  749. sub activetimes
  750. {
  751. # The most actives times on the channel
  752. my (%output, $tbgcolor);
  753. &headline(template_text('activetimestopic'));
  754. my @toptime = sort { $times{$b} <=> $times{$a} } keys %times;
  755. my $highest_value = $times{$toptime[0]};
  756. my @now = localtime($timestamp);
  757. my $image;
  758. for my $hour (sort keys %times) {
  759. debug("Time: $hour => ". $times{$hour});
  760. if ($toptime[0] == $hour) {
  761. $image = $conf->{pic2};
  762. } else {
  763. $image = $conf->{pic1};
  764. }
  765. my $size = ($times{$hour} / $highest_value) * 100;
  766. my $percent = ($times{$hour} / $lines) * 100;
  767. $percent =~ s/(\.\d)\d+/$1/;
  768. if ($conf->{timeoffset} =~ /\+(\d+)/) {
  769. # We must plus some hours to the time
  770. $hour += $1;
  771. $hour = $hour % 24;
  772. if ($hour < 10) { $hour = "0" . $hour; }
  773. } elsif ($conf->{timeoffset} =~ /-(\d+)/) {
  774. # We must remove some hours from the time
  775. $hour -= $1;
  776. $hour = $hour % 24;
  777. if ($hour < 10) { $hour = "0" . $hour; }
  778. }
  779. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br><img src=\"$image\" width=\"15\" height=\"$size\" alt=\"$percent\"></td>\n";
  780. }
  781. html("<table border=\"0\" width=\"614\"><tr>\n");
  782. for ($b = 0; $b < 24; $b++) {
  783. if ($b < 10) { $a = "0" . $b; } else { $a = $b; }
  784. if (!defined($output{$a}) || $output{$a} eq "") {
  785. html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  786. } else {
  787. html($output{$a});
  788. }
  789. }
  790. html("</tr><tr>");
  791. for ($b = 0; $b < 24; $b++) {
  792. if ($now[2] == $b) { $tbgcolor = "\#AAAAAA"; } else { $tbgcolor = "\#CCCCCC"; }
  793. html("<td bgcolor=\"$tbgcolor\" align=\"center\" class=\"small\">$b</td>");
  794. }
  795. html("</tr></table>");
  796. }
  797. sub activenicks
  798. {
  799. # The most active nicks (those who wrote most lines)
  800. headline(template_text('activenickstopic'));
  801. html("<table border=\"0\" width=\"614\"><tr>");
  802. 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>");
  803. if (%userpics) {
  804. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('userpic') ."</b></td>");
  805. }
  806. html("</tr>");
  807. my @active = sort { $line{$b} <=> $line{$a} } keys %line;
  808. if ($conf->{activenicks} > $nicks) {
  809. $conf->{activenicks} = $nicks;
  810. print "Note: There was less nicks in the logfile than your specificied there to be in most active nicks...\n";
  811. }
  812. my ($nick, $visiblenick, $randomline);
  813. my $i = 1;
  814. for (my $c = 0; $c < $conf->{activenicks}; $c++) {
  815. $nick = $active[$c];
  816. $visiblenick = $active[$c];
  817. if (!$longlines{$nick}) {
  818. $randomline = "";
  819. } else {
  820. my $rand = rand($longlines{$nick});
  821. $randomline = $sayings{$nick}[$rand];
  822. }
  823. # Convert URLs and e-mail addys to links
  824. $randomline = replace_links($randomline);
  825. # Add a link to the nick if there is any
  826. if ($userlinks{$nick}) {
  827. $visiblenick = replace_links($userlinks{$nick}, $nick);
  828. }
  829. my $h = $conf->{hicell};
  830. $h =~ s/^#//;
  831. $h = hex $h;
  832. my $h2 = $conf->{hicell2};
  833. $h2 =~ s/^#//;
  834. $h2 = hex $h2;
  835. my $f_b = $h & 0xff;
  836. my $f_g = ($h & 0xff00) >> 8;
  837. my $f_r = ($h & 0xff0000) >> 16;
  838. my $t_b = $h2 & 0xff;
  839. my $t_g = ($h2 & 0xff00) >> 8;
  840. my $t_r = ($h2 & 0xff0000) >> 16;
  841. my $col_b = sprintf "%0.2x", abs int(((($t_b - $f_b) / $conf->{activenicks}) * +$c) + $f_b);
  842. my $col_g = sprintf "%0.2x", abs int(((($t_g - $f_g) / $conf->{activenicks}) * +$c) + $f_g);
  843. my $col_r = sprintf "%0.2x", abs int(((($t_r - $f_r) / $conf->{activenicks}) * +$c) + $f_r);
  844. html("<tr><td bgcolor=\"$conf->{rankc}\" align=\"left\">");
  845. my $line = $line{$nick};
  846. 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\">");
  847. html("\"$randomline\"</td>");
  848. if ($userpics{$nick}) {
  849. html("<td bgcolor=\"#$col_r$col_g$col_b\" align=\"center\"><img valign=\"middle\" src=\"$conf->{imagepath}$userpics{$nick}\"></td>");
  850. }
  851. html("</tr>");
  852. $i++;
  853. }
  854. html("</table><br>");
  855. # Almost as active nicks ('These didn't make it to the top..')
  856. my $nickstoshow = $conf->{activenicks} + $conf->{activenicks2};
  857. unless ($nickstoshow > $nicks) {
  858. html("<br><b><i>" . template_text('nottop') . "</i></b><table><tr>");
  859. for (my $c = $conf->{activenicks}; $c < $nickstoshow; $c++) {
  860. unless ($c % 5) { unless ($c == $conf->{activenicks}) { html("</tr><tr>"); } }
  861. html("<td bgcolor=\"$conf->{rankc}\" class=\"small\">");
  862. my $nick = $active[$c];
  863. my $lines = $line{$nick};
  864. html("$nick ($lines)</td>");
  865. }
  866. html("</table>");
  867. }
  868. }
  869. sub mostusedword
  870. {
  871. # Lao the infamous word usage statistics
  872. my %usages;
  873. foreach my $word (sort keys %wordcount) {
  874. next if exists $line{$word};
  875. $usages{$word} = $wordcount{$word};
  876. }
  877. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  878. if (@popular) {
  879. &headline(template_text('mostwordstopic'));
  880. html("<table border=\"0\" width=\"614\"><tr>");
  881. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('word') . "</b></td>");
  882. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  883. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  884. for(my $i = 0; $i < 10; $i++) {
  885. last unless $i < $#popular;
  886. my $a = $i + 1;
  887. my $popular = $popular[$i];
  888. my $wordcount = $wordcount{$popular[$i]};
  889. my $lastused = $lastused{$popular[$i]};
  890. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  891. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  892. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  893. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  894. html("</tr>");
  895. }
  896. html("</table>");
  897. }
  898. }
  899. sub mostreferenced
  900. {
  901. my %usages;
  902. foreach my $word (sort keys %wordcount) {
  903. next unless exists $line{$word};
  904. $usages{$word} = $wordcount{$word};
  905. }
  906. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  907. if (@popular) {
  908. &headline(template_text('referencetopic'));
  909. html("<table border=\"0\" width=\"614\"><tr>");
  910. html("<td>&nbsp;</td><td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('nick') . "</b></td>");
  911. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('numberuses') . "</b></td>");
  912. html("<td bgcolor=\"$conf->{tdtop}\"><b>" . template_text('lastused') . "</b></td>");
  913. for(my $i = 0; $i < 5; $i++) {
  914. last unless $i < $#popular;
  915. my $a = $i + 1;
  916. my $popular = $popular[$i];
  917. my $wordcount = $wordcount{$popular[$i]};
  918. my $lastused = $lastused{$popular[$i]};
  919. html("<tr><td bgcolor=\"$conf->{rankc}\"><b>$a</b>");
  920. html("<td bgcolor=\"$conf->{hicell}\">$popular</td>");
  921. html("<td bgcolor=\"$conf->{hicell}\">$wordcount</td>");
  922. html("<td bgcolor=\"$conf->{hicell}\">$lastused</td>");
  923. html("</tr>");
  924. }
  925. html("</table>");
  926. }
  927. }
  928. sub questions
  929. {
  930. # Persons who asked the most questions
  931. foreach my $nick (sort keys %question) {
  932. if ($line{$nick} > 100) {
  933. $qpercent{$nick} = ($question{$nick} / $line{$nick}) * 100;
  934. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  935. }
  936. }
  937. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  938. if (@question) {
  939. my %hash = (
  940. nick => $question[0],
  941. per => $qpercent{$question[0]}
  942. );
  943. my $text = template_text('question1', %hash);
  944. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  945. if (@question >= 2) {
  946. my %hash = (
  947. nick => $question[1],
  948. per => $qpercent{$question[1]}
  949. );
  950. my $text = template_text('question2', %hash);
  951. html("<br><span class=\"small\">$text</span>");
  952. }
  953. html("</td></tr>");
  954. } else {
  955. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('question3') . "</td></tr>");
  956. }
  957. }
  958. sub loudpeople
  959. {
  960. # The ones who speak LOUDLY!
  961. foreach my $nick (sort keys %loud) {
  962. if ($line{$nick} > 100) {
  963. $lpercent{$nick} = ($loud{$nick} / $line{$nick}) * 100;
  964. $lpercent{$nick} =~ s/(\.\d)\d+/$1/;
  965. }
  966. }
  967. my @loud = sort { $lpercent{$b} <=> $lpercent{$a} } keys %lpercent;
  968. if (@loud) {
  969. my %hash = (
  970. nick => $loud[0],
  971. per => $lpercent{$loud[0]}
  972. );
  973. my $text = template_text('loud1', %hash);
  974. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  975. if (@loud >= 2) {
  976. my %hash = (
  977. nick => $loud[1],
  978. per => $lpercent{$loud[1]}
  979. );
  980. my $text = template_text('loud2', %hash);
  981. html("<br><span class=\"small\">$text</span>");
  982. }
  983. html("</td></tr>");
  984. } else {
  985. my $text = template_text('loud3');
  986. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  987. }
  988. }
  989. sub shoutpeople
  990. {
  991. # The ones who speak SHOUTED!
  992. foreach my $nick (sort keys %shout) {
  993. if ($line{$nick} > 100) {
  994. $spercent{$nick} = ($shout{$nick} / $line{$nick}) * 100;
  995. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  996. }
  997. }
  998. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  999. if (@shout) {
  1000. my %hash = (
  1001. nick => $shout[0],
  1002. per => $spercent{$shout[0]}
  1003. );
  1004. my $text = template_text('shout1', %hash);
  1005. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1006. if (@shout >= 2) {
  1007. my %hash = (
  1008. nick => $shout[1],
  1009. per => $spercent{$shout[1]}
  1010. );
  1011. my $text = template_text('shout2', %hash);
  1012. html("<br><span class=\"small\">$text</span>");
  1013. }
  1014. html("</td></tr>");
  1015. } else {
  1016. my $text = template_text('shout3');
  1017. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1018. }
  1019. }
  1020. sub slap
  1021. {
  1022. my @slaps;
  1023. # They slapped around
  1024. foreach my $nick (sort keys %slap) {
  1025. @slaps = sort { $slap{$b} <=> $slap{$a} } keys %slap;
  1026. }
  1027. if(@slaps) {
  1028. my %hash = (
  1029. nick => $slaps[0],
  1030. slaps => $slap{$slaps[0]}
  1031. );
  1032. my $text = template_text('slap1', %hash);
  1033. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1034. if (@slaps >= 2) {
  1035. my %hash = (
  1036. nick => $slaps[1],
  1037. slaps => $slap{$slaps[1]}
  1038. );
  1039. my $text = template_text('slap2', %hash);
  1040. html("<br><span class=\"small\">$text</span>");
  1041. }
  1042. html("</td></tr>");
  1043. } else {
  1044. my $text = template_text('slap3');
  1045. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1046. }
  1047. # They got slapped
  1048. foreach my $nick (sort keys %slapped) {
  1049. @slaps = sort { $slapped{$b} <=> $slapped{$a} } keys %slapped;
  1050. }
  1051. if(@slaps) {
  1052. my %hash = (
  1053. nick => $slaps[0],
  1054. slaps => $slapped{$slaps[0]}
  1055. );
  1056. my $text = template_text('slapped1', %hash);
  1057. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1058. if (@slaps >= 2) {
  1059. my %hash = (
  1060. nick => $slaps[1],
  1061. slaps => $slapped{$slaps[1]}
  1062. );
  1063. my $text = template_text('slapped2', %hash);
  1064. html("<br><span class=\"small\">$text</span>");
  1065. }
  1066. html("</td></tr>");
  1067. } else {
  1068. my $text = template_text('slapped3');
  1069. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1070. }
  1071. }
  1072. sub gotkicks
  1073. {
  1074. # The persons who got kicked the most
  1075. my @gotkick = sort { $gotkick{$b} <=> $gotkick{$a} } keys %gotkick;
  1076. if (@gotkick) {
  1077. my %hash = (
  1078. nick => $gotkick[0],
  1079. kicks => $gotkick{$gotkick[0]}
  1080. );
  1081. my $text = template_text('gotkick1', %hash);
  1082. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1083. if (@gotkick >= 2) {
  1084. my %hash = (
  1085. nick => $gotkick[1],
  1086. kicks => $gotkick{$gotkick[1]}
  1087. );
  1088. my $text = template_text('gotkick2', %hash);
  1089. html("<br><span class=\"small\">$text</span>");
  1090. }
  1091. html("</td></tr>");
  1092. }
  1093. }
  1094. sub mostjoins
  1095. {
  1096. my @joins = sort { $joins{$b} <=> $joins{$a} } keys %joins;
  1097. if (@joins) {
  1098. my %hash = (
  1099. nick => $joins[0],
  1100. joins => $joins{$joins[0]}
  1101. );
  1102. my $text = template_text('joins', %hash);
  1103. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1104. }
  1105. }
  1106. sub mostkicks
  1107. {
  1108. # The person who got kicked the most
  1109. my @kicked = sort { $kicked{$b} <=> $kicked{$a} } keys %kicked;
  1110. if (@kicked) {
  1111. my %hash = (
  1112. nick => $kicked[0],
  1113. kicked => $kicked{$kicked[0]}
  1114. );
  1115. my $text = template_text('kick1', %hash);
  1116. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1117. if (@kicked >= 2) {
  1118. my %hash = (
  1119. oldnick => $kicked[0],
  1120. nick => $kicked[1],
  1121. kicked => $kicked{$kicked[1]}
  1122. );
  1123. my $text = template_text('kick2', %hash);
  1124. html("<br><span class=\"small\">$text</span>");
  1125. }
  1126. html("</td></tr>");
  1127. } else {
  1128. my $text = template_text('kick3');
  1129. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1130. }
  1131. }
  1132. sub mostmonologues
  1133. {
  1134. # The person who had the most monologues (speaking to himself)
  1135. my @monologue = sort { $monologue{$b} <=> $monologue{$a} } keys %monologue;
  1136. if (@monologue) {
  1137. my %hash = (
  1138. nick => $monologue[0],
  1139. monos => $monologue{$monologue[0]}
  1140. );
  1141. my $text = template_text('mono1', %hash);
  1142. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1143. if (@monologue >= 2) {
  1144. my %hash = (
  1145. nick => $monologue[1],
  1146. monos => $monologue{$monologue[1]}
  1147. );
  1148. my $text = template_text('mono2', %hash);
  1149. if ($monologue{$monologue[1]} == 1 && $conf->{lang} eq 'EN') {
  1150. $text = substr $text, 0, -1;
  1151. }
  1152. html("<br><span class=\"small\">$text</span>");
  1153. }
  1154. html("</td></tr>");
  1155. }
  1156. }
  1157. sub longlines
  1158. {
  1159. my %len;
  1160. # The person(s) who wrote the longest lines
  1161. foreach my $nick (sort keys %length) {
  1162. if ($line{$nick} > 100) {
  1163. $len{$nick} = $length{$nick} / $line{$nick};
  1164. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1165. }
  1166. }
  1167. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  1168. my $all_lines = $normals + $actions;
  1169. my $totalaverage;
  1170. if ($all_lines > 0) {
  1171. $totalaverage = $totallength / $all_lines;
  1172. $totalaverage =~ s/(\.\d)\d+/$1/;
  1173. }
  1174. if (@len) {
  1175. my %hash = (
  1176. nick => $len[0],
  1177. letters => $len{$len[0]}
  1178. );
  1179. my $text = template_text('long1', %hash);
  1180. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1181. if (@len >= 2) {
  1182. %hash = (
  1183. channel => $conf->{channel},
  1184. avg => $totalaverage
  1185. );
  1186. $text = template_text('long2', %hash);
  1187. html("<span class=\"small\">$text</span></td></tr>");
  1188. }
  1189. }
  1190. }
  1191. sub shortlines
  1192. {
  1193. # This sub should be combined with the longlines sub at some point.. it
  1194. # does basically the same thing.
  1195. my %len;
  1196. # The person(s) who wrote the shortest lines
  1197. foreach my $nick (sort keys %length) {
  1198. if ($line{$nick} > 5) {
  1199. $len{$nick} = $length{$nick} / $line{$nick};
  1200. $len{$nick} =~ s/(\.\d)\d+/$1/;
  1201. }
  1202. }
  1203. my @len = sort { $len{$a} <=> $len{$b} } keys %len;
  1204. if (@len) {
  1205. my %hash = (
  1206. nick => $len[0],
  1207. letters => $len{$len[0]}
  1208. );
  1209. my $text = template_text('short1', %hash);
  1210. html("<tr><td bgcolor=\"$conf->{hicell}\">$text<br>");
  1211. if (@len >= 2) {
  1212. %hash = (
  1213. nick => $len[1],
  1214. letters => $len{$len[1]}
  1215. );
  1216. $text = template_text('short2', %hash);
  1217. html("<span class=\"small\">$text</span></td></tr>");
  1218. }
  1219. }
  1220. }
  1221. sub mostfoul
  1222. {
  1223. my %spercent;
  1224. foreach my $nick (sort keys %foul) {
  1225. if ($line{$nick} > 15) {
  1226. $spercent{$nick} = ($foul{$nick} / $line{$nick}) * 100;
  1227. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1228. }
  1229. }
  1230. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1231. if (@foul) {
  1232. my %hash = (
  1233. nick => $foul[0],
  1234. per => $spercent{$foul[0]}
  1235. );
  1236. my $text = template_text('foul1', %hash);
  1237. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1238. if (@foul >= 2) {
  1239. my %hash = (
  1240. nick => $foul[1],
  1241. per => $spercent{$foul[1]}
  1242. );
  1243. my $text = template_text('foul2', %hash);
  1244. html("<br><span class=\"small\">$text</span>");
  1245. }
  1246. html("</td></tr>");
  1247. } else {
  1248. my %hash = (
  1249. channel => $conf->{channel}
  1250. );
  1251. my $text = template_text('foul3', %hash);
  1252. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1253. }
  1254. }
  1255. sub mostsad
  1256. {
  1257. my %spercent;
  1258. foreach my $nick (sort keys %sadface) {
  1259. if ($line{$nick} > 100) {
  1260. $spercent{$nick} = ($sadface{$nick} / $line{$nick}) * 100;
  1261. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1262. }
  1263. }
  1264. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1265. if (@sadface) {
  1266. my %hash = (
  1267. nick => $sadface[0],
  1268. per => $spercent{$sadface[0]}
  1269. );
  1270. my $text = template_text('sad1', %hash);
  1271. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1272. if (@sadface >= 2) {
  1273. my %hash = (
  1274. nick => $sadface[1],
  1275. per => $spercent{$sadface[1]}
  1276. );
  1277. my $text = template_text('sad2', %hash);
  1278. html("<br><span class=\"small\">$text</span>");
  1279. }
  1280. html("</td></tr>");
  1281. } else {
  1282. my %hash = (
  1283. channel => $conf->{channel}
  1284. );
  1285. my $text = template_text('sad3', %hash);
  1286. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1287. }
  1288. }
  1289. sub mostop
  1290. {
  1291. my @ops = sort { $gaveop{$b} <=> $gaveop{$a} } keys %gaveop;
  1292. my @deops = sort { $tookop{$b} <=> $tookop{$a} } keys %tookop;
  1293. if (@ops) {
  1294. my %hash = (
  1295. nick => $ops[0],
  1296. ops => $gaveop{$ops[0]}
  1297. );
  1298. my $text = template_text('mostop1', %hash);
  1299. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1300. if (@ops >= 2) {
  1301. my %hash = (
  1302. nick => $ops[1],
  1303. ops => $gaveop{$ops[1]}
  1304. );
  1305. my $text = template_text('mostop2', %hash);
  1306. html("<br><span class=\"small\">$text</span>");
  1307. }
  1308. html("</td></tr>");
  1309. } else {
  1310. my %hash = ( channel => $conf->{channel} );
  1311. my $text = template_text('mostop3', %hash);
  1312. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1313. }
  1314. if (@deops) {
  1315. my %hash = (
  1316. channel => $conf->{channel},
  1317. nick => $deops[0],
  1318. deops => $tookop{$deops[0]}
  1319. );
  1320. my $text = template_text('mostdeop1', %hash);
  1321. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1322. if (@deops >= 2) {
  1323. my %hash = (
  1324. nick => $deops[1],
  1325. deops => $tookop{$deops[1]}
  1326. );
  1327. my $text = template_text('mostdeop2', %hash);
  1328. html("<br><span class=\"small\">$text</span>");
  1329. }
  1330. html("</td></tr>");
  1331. } else {
  1332. my %hash = ( channel => $conf->{channel} );
  1333. my $text = template_text('mostdeop3', %hash);
  1334. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1335. }
  1336. }
  1337. sub mostsmiles
  1338. {
  1339. # The person(s) who smiled the most :-)
  1340. my %spercent;
  1341. foreach my $nick (sort keys %smile) {
  1342. if ($line{$nick} > 100) {
  1343. $spercent{$nick} = ($smile{$nick} / $line{$nick}) * 100;
  1344. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1345. }
  1346. }
  1347. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1348. if (@smiles) {
  1349. my %hash = (
  1350. nick => $smiles[0],
  1351. per => $spercent{$smiles[0]}
  1352. );
  1353. my $text = template_text('smiles1', %hash);
  1354. html("<tr><td bgcolor=\"$conf->{hicell}\">$text");
  1355. if (@smiles >= 2) {
  1356. my %hash = (
  1357. nick => $smiles[1],
  1358. per => $spercent{$smiles[1]}
  1359. );
  1360. my $text = template_text('smiles2', %hash);
  1361. html("<br><span class=\"small\">$text</span>");
  1362. }
  1363. html("</td></tr>");
  1364. } else {
  1365. my %hash = (
  1366. channel => $conf->{channel}
  1367. );
  1368. my $text = template_text('smiles3', %hash);
  1369. html("<tr><td bgcolor=\"$conf->{hicell}\">$text</td></tr>");
  1370. }
  1371. }
  1372. sub lasttopics
  1373. {
  1374. debug("Total number of topics: ". scalar @topics);
  1375. if (@topics) {
  1376. my $ltopic = @topics - 1;
  1377. my $tlimit = 0;
  1378. $conf->{topichistory} -= 1;
  1379. if ($ltopic > $conf->{topichistory}) { $tlimit = $ltopic - $conf->{topichistory}; }
  1380. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1381. $topics[$i]{"topic"} = replace_links($topics[$i]{"topic"});
  1382. my $topic = $topics[$i]{topic};
  1383. my $nick = $topics[$i]{nick};
  1384. my $hour = $topics[$i]{hour};
  1385. my $min = $topics[$i]{min};
  1386. html("<tr><td bgcolor=\"$conf->{hicell}\"><i>$topic</i></td>");
  1387. html("<td bgcolor=\"$conf->{hicell}\">By <b>$nick</b> at <b>$hour:$min</b></td></tr>");
  1388. }
  1389. } else {
  1390. html("<tr><td bgcolor=\"$conf->{hicell}\">" . template_text('notopic') ."</td></tr>");
  1391. }
  1392. }
  1393. # Some HTML subs
  1394. sub htmlheader
  1395. {
  1396. print OUTPUT <<HTML;
  1397. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  1398. <html>
  1399. <head>
  1400. <title>$conf->{channel} @ $conf->{network} channel statistics</title>
  1401. <style type="text/css">
  1402. a { text-decoration: none }
  1403. a:link { color: $conf->{link}; }
  1404. a:visited { color: $conf->{vlink}; }
  1405. a:hover { text-decoration: underline; color: $conf->{hlink} }
  1406. body {
  1407. background-color: $conf->{bgcolor};
  1408. font-family: verdana, arial, sans-serif;
  1409. font-size: 13px;
  1410. color: $conf->{text};
  1411. }
  1412. td {
  1413. font-family: verdana, arial, sans-serif;
  1414. font-size: 13px;
  1415. color: $conf->{tdcolor};
  1416. }
  1417. .title {
  1418. font-family: tahoma, arial, sans-serif;
  1419. font-size: 16px;
  1420. font-weight: bold;
  1421. }
  1422. .headline { color: $conf->{hcolor}; }
  1423. .small { font-family: verdana, arial, sans-serif; font-size: 10px; }
  1424. .asmall { font-family: arial narrow, sans-serif; font-size: 10px }
  1425. </style></head>
  1426. <body>
  1427. <div align="center">
  1428. HTML
  1429. my %hash = (
  1430. channel => $conf->{channel},
  1431. network => $conf->{network},
  1432. maintainer => $conf->{maintainer},
  1433. time => $time,
  1434. days => $days,
  1435. nicks => $nicks,
  1436. channel => $conf->{channel}
  1437. );
  1438. print OUTPUT "<span class=\"title\">" . template_text('pagetitle1', %hash) . "</span><br>";
  1439. print OUTPUT "<br>" . template_text('pagetitle2', %hash) . "<br>";
  1440. print OUTPUT template_text('pagetitle3', %hash) . "<br><br>";
  1441. }
  1442. sub htmlfooter
  1443. {
  1444. print OUTPUT <<HTML;
  1445. <span class="small">
  1446. 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>
  1447. pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten "LostStar" Brix Pedersen</a> and others<br>
  1448. Stats generated in $processtime
  1449. </span>
  1450. </div>
  1451. </body>
  1452. </html>
  1453. HTML
  1454. }
  1455. sub headline
  1456. {
  1457. my ($title) = @_;
  1458. print OUTPUT <<HTML;
  1459. <br>
  1460. <table width="610" cellpadding="1" cellspacing="0" border="0">
  1461. <tr>
  1462. <td bgcolor="$conf->{headline}">
  1463. <table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">
  1464. <tr>
  1465. <td bgcolor="$conf->{hbgcolor}" class="text10">
  1466. <div align="center" class="headline"><b>$title</b></div>
  1467. </td>
  1468. </tr>
  1469. </table>
  1470. </td>
  1471. </tr>
  1472. </table>
  1473. HTML
  1474. }
  1475. sub pageheader
  1476. {
  1477. if ($conf->{pagehead} ne 'none') {
  1478. open(PAGEHEAD, $conf->{pagehead}) or die("$0: Unable to open $conf->{pagehead} for reading: $!\n");
  1479. while (<PAGEHEAD>) {
  1480. html($_);
  1481. }
  1482. }
  1483. }
  1484. sub close_debug
  1485. {
  1486. if ($conf->{debug}) {
  1487. close(DEBUG) or print STDERR "$0: Cannot close debugfile($conf->{debugfile}): $!\n";
  1488. }
  1489. }
  1490. sub get_cmdlineoptions
  1491. {
  1492. my $tmp;
  1493. # Commandline options
  1494. my ($channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  1495. my $usage = <<END_USAGE;
  1496. Usage: pisg.pl [-c channel] [-l logfile] [-o outputfile] [-m
  1497. maintainer] [-f format] [-n network] [-d logdir] [-a aliasfile]
  1498. [-i ignorefile] [-h]
  1499. -ch --channel=xxx : Set channel name
  1500. -l --logfile=xxx : Log file to parse
  1501. -o --outfile=xxx : Name of html file to create
  1502. -m --maintainer=xxx : Channel/statistics maintainer
  1503. -f --format=xxx : Logfile format [see FORMATS file]
  1504. -n --network=xxx : IRC Network this channel is on.
  1505. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  1506. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  1507. Only works with --dir
  1508. -co --configfile=xxx : Config file
  1509. -h --help : Output this message and exit (-? also works).
  1510. Example:
  1511. \$ pisg.pl -n IRCnet -f xchat -o suid.html -c \\#channel -l logfile.log
  1512. As always, all options may also be defined by editing the source and calling
  1513. pisg without arguments.
  1514. END_USAGE
  1515. if (GetOptions('channel=s' => \$channel,
  1516. 'logfile=s' => \$logfile,
  1517. 'format=s' => \$format,
  1518. 'network=s' => \$network,
  1519. 'maintainer=s' => \$maintainer,
  1520. 'outfile=s' => \$outputfile,
  1521. 'dir=s' => \$logdir,
  1522. 'prefix=s' => \$prefix,
  1523. 'ignorefile=s' => \$tmp,
  1524. 'aliasfile=s' => \$tmp,
  1525. 'configfile=s' => \$configfile,
  1526. 'help|?' => \$help
  1527. ) == 0 or $help) {
  1528. die($usage);
  1529. }
  1530. if (@ARGV) {
  1531. if ($ARGV[0]) { $conf->{channel} = $ARGV[0]; }
  1532. if ($ARGV[1]) { $conf->{logfile} = $ARGV[1]; }
  1533. if ($ARGV[2]) { $conf->{outputfile} = $ARGV[2]; }
  1534. if ($ARGV[3]) { $conf->{maintainer} = $ARGV[3]; }
  1535. }
  1536. if ($tmp) {
  1537. die("The aliasfile and ignorefile has been obsoleted by the new
  1538. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  1539. }
  1540. if ($channel) {
  1541. $conf->{channel} = $channel;
  1542. $conf->{cmdl}{channel} = 1;
  1543. }
  1544. if ($logfile) {
  1545. $conf->{logfile} = $logfile;
  1546. $conf->{cmdl}{logfile} = 1;
  1547. }
  1548. if ($format) {
  1549. $conf->{format} = $format;
  1550. $conf->{cmdl}{format} = 1;
  1551. }
  1552. if ($network) {
  1553. $conf->{network} = $network;
  1554. $conf->{cmdl}{network} = 1;
  1555. }
  1556. if ($maintainer) {
  1557. $conf->{maintainer} = $maintainer;
  1558. $conf->{cmdl}{maintainer} = 1;
  1559. }
  1560. if ($outputfile) {
  1561. $conf->{outputfile} = $outputfile;
  1562. $conf->{cmdl}{outputfile} = 1;
  1563. }
  1564. if ($logdir) {
  1565. $conf->{logdir} = $logdir;
  1566. $conf->{cmdl}{logdir} = 1;
  1567. }
  1568. if ($prefix) {
  1569. $conf->{prefix} = $prefix;
  1570. $conf->{cmdl}{prefix} = 1;
  1571. }
  1572. if ($configfile) {
  1573. $conf->{configfile} = $configfile;
  1574. $conf->{cmdl}{configfile} = 1;
  1575. }
  1576. }
  1577. sub get_language_templates
  1578. {
  1579. use FindBin;
  1580. open(FILE, $conf->{langfile}) or open (FILE, $FindBin::Bin . "/$conf->{langfile}") or die("$0: Unable to open language file($conf->{langfile}): $!\n");
  1581. my $current_lang;
  1582. while (<FILE>)
  1583. {
  1584. my $line = $_;
  1585. next if /^#/;
  1586. if ($line =~ /<lang name=\"([^"]+)\">/) {
  1587. # Found start tag, setting the current language
  1588. $current_lang = "$1";
  1589. }
  1590. elsif ($line =~ /<\/lang>/) {
  1591. # Found end tag, resetting the current language
  1592. $current_lang = '';
  1593. }
  1594. elsif ($line =~ /(\w+)\s+=\s+"(.*)"\s*$/ && $current_lang ne '') {
  1595. $T{$current_lang}{$1} = $2;
  1596. }
  1597. }
  1598. close(FILE);
  1599. print "Using language template: $conf->{lang}\n\n" if ($conf->{lang} ne 'EN');
  1600. }
  1601. &main(); # Run the script