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 $REVISION/;
43 $REVISION = '$LastChangedRevision$';
48 $VERSION =~ s/^\D*(\d+).*/r$1/;
54 print STDERR $/, __FILE__, ': $Id$' if ($::DEBUG);
57 read_config (get_config ('config') ? get_config ('config') : 'config');
58 read_config (scalar get_config ('theme')) if (get_config ('theme'));
60 my $output = get_config ('output');
63 $output = "reports/onis.html";
66 foreach ('Core', get_config ('plugin'))
68 my $module = ucfirst (lc ($_));
69 require "Onis/Plugins/$module.pm";
72 if (!get_config ('input'))
76 Usage: $0 [options] <logfile> [logfile logfile ..]
79 --config Specify alternate config file
80 --output <file> Defines the file to write the HTML to.
81 --overwrite <bool> Overwrites files without prompting.
82 --channel <channel> Defines the channel's name.
83 --logtype <type> Defines the logfile's type.
84 See 'config' for a complete list.
85 --user <name> Define's the generator's name.
87 For a full list of all options please read the ``config'' file.
95 if (get_config ('overwrite'))
97 my $tmp = lc (get_config ('overwrite'));
98 if ($tmp eq 'true' or $tmp eq 'yes' or $tmp eq 'on')
106 print STDERR <<MESSAGE;
108 WARNING: The output file ``$output'' already exists
110 You can set the ``overwrite'' option in the config
111 file to disable this dialog.
114 print STDERR 'Are you sure you want to overwrite it? [Y|n] ';
115 my $answer = <STDIN>;
116 exit (1) if ($answer =~ m/n/i);
120 my $logtype = 'Eggdrop';
121 if (get_config ('logtype'))
123 $logtype = ucfirst (lc (get_config ('logtype')));
126 require "Onis/Parser/$logtype.pm";
127 require Onis::Parser::Persistent;
128 require Onis::Data::Persistent;
129 import Onis::Parser (qw(parse last_date));
130 import Onis::Parser::Persistent (qw(newfile));
131 import Onis::Data::Persistent ();
133 $FileInfo = Onis::Data::Persistent->new ('FileInfo', 'inode', qw(mtime));
135 if (get_config ('purge_logs'))
137 my $temp = lc (get_config ('purge_logs'));
138 if (($temp eq 'truncate') or ($temp eq 'shorten'))
142 elsif (($temp eq 'delete') or ($temp eq 'remove')
149 for (get_config ('input'))
159 ($inode, $size, $mtime) = (stat ($file))[1,7,9];
161 print STDERR $/, $/, __FILE__, " --- New File ``$file'' ---" if ($::DEBUG & 0x200);
163 if (!defined ($mtime))
165 print STDERR $/, __FILE__, ": Unable to stat file ``$file''";
170 my ($old_mtime) = $FileInfo->get ($inode);
172 print STDERR $/, __FILE__, ": ``$file'': " if ($::DEBUG & 0x200);
174 if (defined ($old_mtime))
176 if ($old_mtime == $mtime)
178 print STDERR "File did not change. Skipping." if ($::DEBUG & 0x200);
181 elsif ($old_mtime < $mtime)
183 print STDERR "File changed. Reading it again." if ($::DEBUG & 0x200);
187 print STDERR "File ``$file'' is older than expected. There might be a problem!";
192 print STDERR "File appears to be new. Reading it." if ($::DEBUG & 0x200);
194 $FileInfo->put ($inode, $mtime);
198 if ($PURGE_LOGS == 1)
200 unless (open ($logfile, '+< ' . $file))
202 print STDERR $/, __FILE__, ": Unable to open file ``$file'': $!";
208 unless (open ($logfile, '< ' . $file))
210 print STDERR $/, __FILE__, ": Unable to open file ``$file'': $!";
217 unless (flock ($logfile, LOCK_EX))
219 print STDERR $/, __FILE__, ": Unable to get an exclusive lock for file ``$file'': $!";
226 unless (flock ($logfile, LOCK_SH))
228 print STDERR $/, __FILE__, ": Unable to get a shared lock for file ``$file'': $!";
234 newfile ($FileInfo->{$inode});
238 $status = parse ($_);
242 # 2 == unable to parse
244 # 4 == don't have date
248 print STDERR $/, __FILE__, ": Rewinding file ``$file''" if ($::DEBUG & 0x200);
249 seek ($logfile, 0, 0);
252 elsif (($status == 1) or ($status == 2)
255 $position = tell ($logfile);
263 print STDERR $/, __FILE__, ": Parser returned unknown status code: ``$status''";
267 if ($PURGE_LOGS and (($status == 1)
271 if (($PURGE_LOGS > 1)
272 #and (($position + 1) >= $size)
276 print STDERR $/, __FILE__, ": Deleting empty file ``$file''" if ($::DEBUG & 0x200);
281 unless (unlink ($file))
283 print STDERR $/, __FILE__, ": Unable to delete empty file ``$file'': $!";
285 delete ($FileInfo->{$inode});
289 print STDERR $/, __FILE__, ": Won't delete ``$file''. Set it to writeable first!";
294 seek ($logfile, 0, 0);
295 if (truncate ($logfile, 0))
297 print $logfile &last_date ();
298 print STDERR $/, __FILE__, ": Truncated ``$file''" if ($::DEBUG & 0x200);
302 print STDERR $/, __FILE__, ": Couldn't truncate file ``$file'': $!";
314 require Onis::Data::Core;
316 import Onis::Data::Core qw#print_output#;
317 import Onis::Html qw#open_file close_file#;
319 if (open_file ($output))
326 # Fail and make noise! ;)
327 print STDERR <<MESSAGE;
329 ERROR: Unable to open output file
331 The output file ``$output'' could not be opened. Please make sure to set
332 the permissions right and try again.
342 print $/ if ($::DEBUG);