2 ##########################################################################
3 # onis 0.7.2 2005-01-21 #
4 #---=============--------------------------------------------------------#
6 # Purpose: Generating statistics #
7 # Input: IRC-Logfiles #
8 # Output: One HTML file #
9 # Version: 0.7.2 (unstable) #
11 # Homepage: http://verplant.org/onis/ #
12 # Authors: Florian octo Forster <octo@verplant.org> #
13 # Contributions are listed in THANKS #
14 ##########################################################################
18 if ($0 =~ m#^(.*)[/\\]#) { chdir ($1); }
20 unshift (@INC, 'lib');
22 # 0x0010 Language (make not-translated lines red/yellow)
23 # 0x0020 Parser (dropped lines)
24 # 0x0040 Parser (time information)
25 # 0x0100 Data::Core (host unsharp)
26 # 0x0200 Data::Persistent
27 # 0x0400 Data::Core (dump incoming data to stderr)
28 # 0x0800 Data::Core (initializing)
36 use Onis::Config qw/get_config parse_argv read_config/;
37 use File::Basename qw/dirname/;
40 use vars qw/$VERSION/;
47 print STDERR $/, __FILE__, ': $Id: onis,v 1.18 2005/01/21 18:59:59 octo Exp $' if ($::DEBUG);
50 read_config (get_config ('config') ? get_config ('config') : 'config');
51 read_config (scalar get_config ('theme')) if (get_config ('theme'));
53 my $output = get_config ('output');
56 $output = "reports/onis.html";
59 foreach ('Core', get_config ('plugin'))
61 my $module = ucfirst (lc ($_));
62 require "Onis/Plugins/$module.pm";
65 if (!get_config ('input'))
69 Usage: $0 [options] <logfile> [logfile logfile ..]
72 --config Specify alternate config file
73 --output <file> Defines the file to write the HTML to.
74 --overwrite <bool> Overwrites files without prompting.
75 --channel <channel> Defines the channel's name.
76 --logtype <type> Defines the logfile's type.
77 See 'config' for a complete list.
78 --user <name> Define's the generator's name.
80 For a full list of all options please read the ``config'' file.
88 if (get_config ('overwrite'))
90 my $tmp = lc (get_config ('overwrite'));
91 if ($tmp eq 'true' or $tmp eq 'yes' or $tmp eq 'on')
99 print STDERR <<MESSAGE;
101 WARNING: The output file ``$output'' already exists
103 You can set the ``overwrite'' option in the config
104 file to disable this dialog.
107 print STDERR 'Are you sure you want to overwrite it? [Y|n] ';
108 my $answer = <STDIN>;
109 exit (1) if ($answer =~ m/n/i);
113 my $logtype = 'Eggdrop';
114 if (get_config ('logtype'))
116 $logtype = ucfirst (lc (get_config ('logtype')));
119 require "Onis/Parser/$logtype.pm";
120 require Onis::Parser::Persistent;
121 require Onis::Data::Persistent;
122 import Onis::Parser qw/parse last_date/;
123 import Onis::Parser::Persistent qw#newfile#;
124 import Onis::Data::Persistent qw#init#;
126 $FILEINFO = init ('$FILEINFO', 'hash');
128 if (get_config ('purge_logs'))
130 my $temp = lc (get_config ('purge_logs'));
131 if (($temp eq 'truncate') or ($temp eq 'shorten'))
135 elsif (($temp eq 'delete') or ($temp eq 'remove')
142 for (get_config ('input'))
152 ($inode, $size, $mtime) = (stat ($file))[1,7,9];
154 print STDERR $/, $/, __FILE__, " --- New File ``$file'' ---" if ($::DEBUG & 0x200);
156 if (!defined ($mtime))
158 print STDERR $/, __FILE__, ": Unable to stat file ``$file''";
163 print STDERR $/, __FILE__, ": ``$file'': " if ($::DEBUG & 0x200);
164 if (defined ($FILEINFO->{$inode}{'mtime'}))
166 if ($FILEINFO->{$inode}{'mtime'} == $mtime)
168 print STDERR "File did not change. Skipping." if ($::DEBUG & 0x200);
171 elsif ($FILEINFO->{$inode}{'mtime'} < $mtime)
173 print STDERR "File changed. Reading it again." if ($::DEBUG & 0x200);
177 print STDERR "File ``$file'' is older than expected. There might be a problem!";
182 print STDERR "File appears to be new. Reading it." if ($::DEBUG & 0x200);
184 $FILEINFO->{$inode}{'mtime'} = $mtime;
188 if ($PURGE_LOGS == 1)
190 unless (open ($logfile, '+< ' . $file))
192 print STDERR $/, __FILE__, ": Unable to open file ``$file'': $!";
198 unless (open ($logfile, '< ' . $file))
200 print STDERR $/, __FILE__, ": Unable to open file ``$file'': $!";
207 unless (flock ($logfile, LOCK_EX))
209 print STDERR $/, __FILE__, ": Unable to get an exclusive lock for file ``$file'': $!";
216 unless (flock ($logfile, LOCK_SH))
218 print STDERR $/, __FILE__, ": Unable to get a shared lock for file ``$file'': $!";
224 newfile ($FILEINFO->{$inode});
228 $status = parse ($_);
232 # 2 == unable to parse
234 # 4 == don't have date
238 print STDERR $/, __FILE__, ": Rewinding file ``$file''" if ($::DEBUG & 0x200);
239 seek ($logfile, 0, 0);
242 elsif (($status == 1) or ($status == 2)
245 $position = tell ($logfile);
253 print STDERR $/, __FILE__, ": Parser returned unknown status code: ``$status''";
257 if ($PURGE_LOGS and (($status == 1)
261 if (($PURGE_LOGS > 1)
262 #and (($position + 1) >= $size)
266 print STDERR $/, __FILE__, ": Deleting empty file ``$file''" if ($::DEBUG & 0x200);
271 unless (unlink ($file))
273 print STDERR $/, __FILE__, ": Unable to delete empty file ``$file'': $!";
275 delete ($FILEINFO->{$inode});
279 print STDERR $/, __FILE__, ": Won't delete ``$file''. Set it to writeable first!";
284 seek ($logfile, 0, 0);
285 if (truncate ($logfile, 0))
287 print $logfile &last_date ();
288 print STDERR $/, __FILE__, ": Truncated ``$file''" if ($::DEBUG & 0x200);
292 print STDERR $/, __FILE__, ": Couldn't truncate file ``$file'': $!";
304 require Onis::Data::Core;
306 import Onis::Data::Core qw#print_output#;
307 import Onis::Html qw#open_file close_file#;
309 if (open_file ($output))
316 # Fail and make noise! ;)
317 print STDERR <<MESSAGE;
319 ERROR: Unable to open output file
321 The output file ``$output'' could not be opened. Please make sure to set
322 the permissions right and try again.
332 print $/ if ($::DEBUG);