#!/usr/bin/perl ################################################################################################################ #Copyright 2004 by Christopher Andrew Hotchkiss # # # #This program is distributed without warrenty for anything # #under the GNU Public License v2.0. # # # #This program is designed to do bulk updates of the post227 # #workstations # ################################################################################################################ #Usage: # # # # netexec [add|clear|run|file] group="b2,b3,..." ["command"|file path] [destination file|path] # # # # group name can be specified in two ways # # direct hostname resolutions "home" "home.post227.org" # # or # # as a chain that needs to bounce from box to box "home.post227.org->b2->b3" # ################################################################################################################ use strict; use warnings; use Cwd; use Frontier::Client; use MIME::Base64; ##################### #Parse Cmd Arguments# ##################### my $group = $ARGV[1]; $group =~ /group=(.*)/; my @comps = split(',', $1); foreach my $comp (@comps){ #Forward if the comp is indicated as a relay if($comp =~ /^(.*?)->(.*)/){ if($ARGV[0] eq "file"){ open(FH, $ARGV[2]) or die "$!"; my $file; while(){ $file .= $_; } close(FH); $file = encode_base64($file); &forward( $1, $ARGV[0], "group=\"$2\"", $file, $ARGV[3]); } else{ &forward( $1, $ARGV[0], "group=\"$2\"", $ARGV[2], $ARGV[3]); } } elsif($ARGV[0] eq "add"){ &add($comp, $ARGV[2]); } elsif($ARGV[0] eq "clear"){ &clear($comp); } elsif($ARGV[0] eq "run"){ &run($comp); } elsif($ARGV[0] eq "file"){ &file($comp, $ARGV[2], $ARGV[3]); } } ##### #Add# ##### sub add { my ($host, $cmd) = @_; my $server = Frontier::Client->new(url => "http://".$host.":8080/RPC2"); my $result = $server->call('add', $cmd); } ####### #Clear# ####### sub clear { my ($host) = @_; my $server = Frontier::Client->new(url => "http://".$host.":8080/RPC2"); my $result = $server->call('clear'); } ##### #Run# ##### sub run { my ($host) = @_; my $server = Frontier::Client->new(url => "http://".$host.":8080/RPC2"); my $result = $server->call('run'); my $output = $result->{'good'}; print $output; } ######### #Forward# ######### sub forward { my ( $host, $type, $path, $cmd, $dest) = @_; my $server = Frontier::Client->new(url => "http://".$host.":8080/RPC2"); my $result = $server->call('forward', $type, $path, $cmd, $dest); } ###### #File# ###### sub file { my ($host, $filepath, $destination) = @_; my $server = Frontier::Client->new(url => "http://".$host.":8080/RPC2"); open(FH, $filepath) or die "$!"; my $file; while(){ $file .= $_; } close(FH); #Encode in XML safe form $file = encode_base64($file); my $result = $server->call('file', $file, $destination); }