# $Id: hitcount.pl,v 1.3.2.2 2002/03/05 18:19:28 shrike Exp shrike $
use strict;
use vars qw($VERSION %IRSSI);
my @rev = split(/ /, '$Revision: 1.4 $n');
$VERSION = "1.4";
%IRSSI = (
authors => 'Riku "Shrike" Lindblad',
contact => 'shrike\@addiktit.net, Shrike on IRCNet/QNet/EFNet/DALNet',
name => 'hitcount',
description => 'Add a apache page hitcounter to statusbar',
sbitems => 'hitcount',
license => 'Free',
changed => '$Date: 2017/03/07 $ ',
);
# Changelog:
#
# Revision 1.4 2017/03/07 bw1
# bug fix
#
# Revision 1.3.2.2 2002/03/05 18:19:28 shrike
# Added use vars qw($VERSION %IRSSI);
#
# Revision 1.3.2.1 2002/03/05 18:04:01 shrike
# Damnit, left default refresh to a debug value...
#
# Revision 1.3.1.1 2002/03/05 17:59:47 shrike
# Forgot to turn off debugging...
#
# Revision 1.3 2002/03/05 17:57:04 shrike
# Added use strict
# .. which finally cleared up last of the bugs from the code (hopefully)
# Next on TODO: get the item colors from theme and more configuration options.
#
# Revision 1.2 2002/03/05 17:27:15 shrike
# Added standard script headers (http://juerd.nl/irssi/headers.html)
# Removed call to Irssi::statusbars_recreate_items();
# And a bit of polishing here and there..
# The first two updates bug, need to fix that.
#
# To install, you also need to put
# hitcount = { };
# into your statusbar code in irssi config
#
# sets:
# /SET hitcount_regexp - A regexp that identifies your homepage
# /SET hitcount_refresh - Refresh rate
# /SET hitcount_access_log - webserver access log
# TODO:
# Add ignore regexp, to prevent f.ex. css-files from increasing counter
use Irssi::TextUI;
# Debug level - higher levels print out more crap
my $debug_level = 0;
# current hitcount
my ($total_hitcount, $my_hitcount) = (0,0);
# change prefixes
my ($my_prefix, $total_prefix) = ("","");
# change from last update
my ($my_change, $total_change) = (0,0);
# hitcount on last update
my ($last_total_hitcount, $last_my_hitcount, $last_refresh) = (0,0,0);
# set default variables
my ($filename, $regexp, $refresh) = ("/var/log/httpd/access.log", "/", 60);
# marker for the refresh
my $refresh_tag;
# read the access_log and count rows, regexp matches
sub get_hitcount {
my $filename = Irssi::settings_get_str('hitcount_access_log');
my $regexp = Irssi::settings_get_str('hitcount_regexp');
Irssi::print("Finding match for \"$regexp\"", MSGLEVEL_CLIENTERROR) if($debug_level > 2);
($total_hitcount, $my_hitcount) = (0,0);
# Go through the access log and count matches to the given regexp
if(open STUFF, "<", $filename) {
while (