#!/usr/ug/bin/perl5 # # sample use: # gsub -akf /home/whuang/prog/gale/hot + # # by Wei-Hwa Huang (whuang@ugcs.caltech.edu) # sections of code stolen from jtr@ugcs.caltech.edu use strict; use POSIX qw(strftime); # gale info use vars qw($FROM $ENC $CAT $SIGN $TIME @MESSAGE $NEWCAT $FTIME); # misc use vars qw($GALE $HOME $LOGDIR $USER %LOGGEDTO); $FROM= $ENV{'HEADER_FROM'}; $TIME= $ENV{'HEADER_TIME'}; $CAT= $ENV{'GALE_TO'}; $CAT =~ s-zephyr/message-zephyr/MESSAGE-gi; print STDERR "incoming message from category: $CAT\n"; $CAT =~ s/\@ofb\.net$//; $ENC= $ENV{'GALE_ENCRYPTED'}; $SIGN= $ENV{'GALE_FROM'}; $HOME= $ENV{'HOME'}; $GALE= $HOME . "/.gale/"; $LOGDIR= $HOME . "/gale/"; $USER= $ENV{'USER'}; $FTIME= $ENV{'GALE_TIME_ID_TIME'}; @MESSAGE = <>; sub getFragments { my($fragname)= @_; my($curfrag, $counter, @frags)= ($fragname, 1, ()); while (defined($ENV{$curfrag})) { push(@frags, $ENV{$curfrag}); $curfrag= $fragname . "_" . ++$counter; } return @frags; } my @KEYWORDS= &getFragments('GALE_TEXT_MESSAGE_KEYWORD'); foreach (@KEYWORDS) { if (/\/nostat/) { die "/nostat, will not stat.\n" ; } } my $CTIME = `date +%s`; chop $CTIME; my @cats = split(":",$CAT); my %catlist = (); my %namelist = (); # add my own cats to catlist. my $ct; foreach $ct (@cats) { # filter out categories here. next if ($ct =~ /^\@/); next if ($ct =~ /^\//); next if ($ct =~ /^\./); next if ($ct =~ /^gate/); next if ($ct =~ /^whuang/); next if ($ct =~ /^\_gale/); $ct =~ s/\//\./g; my @ar = (); if ($catlist{$ct} == 0) { $catlist{$ct} = \@ar; } push(@{$catlist{$ct}},"$CTIME $SIGN"); # print "Data is $CTIME $SIGN\n"; } # add the old cats to catlist. if (-e "/home/whuang/gale/stats") { open(FHAND,"; chomp(@data); my $line; my $lastline = ""; foreach $line (@data) { next if ($line eq $lastline); my @temp = split(' ',$line); my $tm = $temp[0]; my $frm = ($#temp == 2)? $temp[1] : 'Nobody'; my $ct = ($#temp == 2)? $temp[2] : $temp[1]; if ($CTIME - $tm <= (360000)) { # 100 hours my @ar = (); if ($catlist{$ct} == 0) { $catlist{$ct} = \@ar; } push(@{$catlist{$ct}},"$tm $frm"); } $lastline = $line; } close(FHAND); } # write the new cats to catlist. sub numic { $a =~ /^(.*) /; my $aval = $1; $b =~ /^(.*) /; my $bval = $1; return($aval <=> $bval); } foreach $ct (keys %catlist) { @{$catlist{$ct}} = sort numic @{$catlist{$ct}}; } open(FHAND,">/home/whuang/gale/stats"); my $tm; foreach $ct (keys %catlist) { next if ($ct =~ /^bot\./); foreach $tm (@{$catlist{$ct}}) { print FHAND "$tm $ct\n"; # print STDERR "Writing: $tm $ct\n"; } } close(FHAND); my (@cmdcats, @botcats, @othercats) = ((),(),()); my $singlecat; foreach $singlecat (@cats) { if ($singlecat =~ /^bot\//) { print STDERR "botcat $singlecat\n"; push(@botcats,$singlecat); } elsif ($singlecat eq '@ugcs.caltech.edu/user/hot.whuang/') { print STDERR "cmdcat $singlecat\n"; push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\/hot$/) { print STDERR "cmdcat $singlecat\n"; push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\.hot$/) { print STDERR "cmdcat $singlecat\n"; push(@cmdcats,$singlecat); } else { print STDERR "othercat $singlecat\n"; push(@othercats,$singlecat); } } foreach $singlecat (@cmdcats) { my $outstring; if ($singlecat eq '@ugcs.caltech.edu/user/hot.whuang/') { $outstring = (@othercats == ()) ? "| /usr/contrib/bin/gsend $SIGN" : "| /usr/contrib/bin/gsend $SIGN -c ".join(':',@othercats); } else { $outstring = (@othercats == ()) ? "| /usr/contrib/bin/gsend -c bot.hot" : "| /usr/contrib/bin/gsend -c bot.hot:".join(':',@othercats); $outstring += " /nolog"; } if (join('',@MESSAGE) =~ /^\s*help\s*$/) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; hot version 1.3 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Wei-Hwa's implementation of a statbot. Privately: Send a private puff to hot.whuang@ugcs.caltech.edu Publically: Send a puff to cmd/hot. The bot will respond in bot/hot, along with any non-bot/ crosspuffed categories. If the puff is "help", you'll see this message; otherwise you'll just get the stats. Known Bugs: All slashes in category names are treated as dots. End of Help Message $ENV{'GALE_FROM'}= 'Bean Counter'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); } else { eval(`cat /home/whuang/prog/gale/hotpout`); } }