#!/afs/athena/contrib/perl5/p #$Id: webznol,v 1.24 2008/06/01 16:41:03 jdaniel Exp $ $^W=1; sub usage { return <&1`; print $status; # if there was an error then exit the loop if ($status =~ m/zctl \(subscribe\):.*/ || $status =~ m/zpunt:.*/) { #actual error messages: #zctl (subscribe): No such file or directory while finding WindowGram port #zpunt: Can't find windowgram port $brokeout = 1; last; } } print ($brokeout ? "...failed\n" : "...done\n") if $verbose; } use HTTP::Request::Common; require LWP::UserAgent; $SERVER = "webzephyr.mit.edu"; $SERVER .= ":8001" if ($0 =~ m/-test/); # test port while (@ARGV) { if (substr($ARGV[0],0,1) ne "-") { last; } else { $arg = shift @ARGV; if ($arg eq "-q") { $quiet = "t"; } elsif ($arg eq "-l") { $listonly = "t"; } elsif ($arg eq "-u") { $un = "un"; } elsif ($arg eq "-a") { $all = 1; } elsif ($arg eq "-n") { $except = 1; $all = 1; } elsif ($arg eq "-v") { $verbose = 1; } elsif ($arg eq "-f") { $file = shift @ARGV; } elsif ($arg eq "-last") { $last = 1; } elsif ($arg eq "-help") { print &usage(); exit; } else { print STDERR "unrecognized option $arg\n"; die &usage(); } } } $file ||= "$ENV{HOME}/.anyone.web".($except ? "not" : ""); if ($all && !$except) { } elsif (@ARGV) { @users = @ARGV; } elsif (open (ANYONE, "<$file")) { @users = ; close ANYONE; } else { print STDERR "Couldn't open $file\n\n"; die &usage(); } $un ||= ""; $verbose ||= 0; if (!$listonly) { print "Trying to ${un}subscribe to login notices\n" if $verbose; if ($all) { $status = system("zctl ${un}sub webzephyr \\* \@ATHENA.MIT.EDU"); &sub_users("zpunt",@users) if $except; } else { &sub_users("zctl ${un}sub", @users) } } if (!$quiet) { $users = $except ? "" : "@users"; $users =~ s/\s+/ /g; print "looking up names...\n" if $verbose; $ua = new LWP::UserAgent; $ua->timeout(10); #$url = HTTP::Request->new( $resp = $ua->request(POST "http://$SERVER/znol.pl", [ people => "$users", noheaders => 't', verbose => $verbose, type => ($all ? 'all' : 'names'), show => ($last ? 'last' : 'current') ]); if ($resp->is_error) { die "Unable to reach server\n"; } elsif ($except) { LINE: foreach $line (split /\n/, $resp->content) { foreach $user (@users) { next LINE if $line =~ m/^$user\s/; } print "$line\n"; } } else { print $resp->content(); } }