#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/catan cmd/catan:@ugcs.caltech.edu/user/catan.whuang # # 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_CATEGORY'}; $CAT =~ s-zephyr/message-zephyr/MESSAGE-gi; print STDERR "incoming message from category: $CAT\n"; $ENC= $ENV{'GALE_ENCRYPTED'}; $SIGN= $ENV{'GALE_SIGNED'}; $HOME= $ENV{'HOME'}; $GALE= $HOME . "/.gale/"; $LOGDIR= $HOME . "/gale/"; $USER= $ENV{'USER'}; $FTIME= $ENV{'GALE_TIME_ID_TIME'}; @MESSAGE = <>; print STDERR "$CAT\n"; my @cats = split(":",$CAT); my (@cmdcats, @botcats, @othercats) = ((),(),()); my $singlecat; foreach $singlecat (@cats) { if ($singlecat =~ /^bot\//) { push(@botcats,$singlecat); } elsif ($singlecat eq '@ugcs.caltech.edu/user/catan.whuang/') { push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\//) { push(@cmdcats,$singlecat); } else { push(@othercats,$singlecat); } } foreach $singlecat (@cmdcats) { my $outstring; my $personal; if ($singlecat eq '@ugcs.caltech.edu/user/catan.whuang/') { $personal = 1; $outstring = (@othercats == ()) ? "| gsend $SIGN" : "| gsend $SIGN -c ".join(':',@othercats); } else { $personal = 0; $outstring = (@othercats == ()) ? "| gsend -c bot/catan" : "| gsend -c bot/catan:".join(':',@othercats); } if (join('',@MESSAGE) =~ /^\s*help\s*$/ and 0) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; Catan Bot version 0.0 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Still under development. Sorry, no documentation yet. End of Help Message } else { if ($personal == 0) { @MESSAGE = (); $MESSAGE[0] = <<'End of Message'; Sorry, no commands read from cmd/catan yet. Send private puffs to catan.whuang@ugcs.caltech.edu. End of Message } else { my $catandir = '/mnt/whuang/ufs/whuang/whuang/prog/gale/catan/'; my $prog = "$catandir/command $SIGN"; if (-e "$catandir/data/command.in") { @MESSAGE = (); $MESSAGE[0] = <<"End of Message"; Sorry, the Catan Bot is in the middle of executing another command. Please try again later. End of Message } else { open (CMD, ">$catandir/data/command.in"); print CMD @MESSAGE; close (CMD); open (CMD, "$prog < $catandir/data/command.in |"); @MESSAGE = ; close (CMD); unlink("$catandir/data/command.in"); } } } $ENV{'GALE_FROM'}= 'The Gale Catan Bot'; $ENV{'GALE_ID'}= 'catan.whuang@ugcs.caltech.edu'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); }