#!/usr/bin/perl # # Remote-Cmd F.Luettgens ########################## use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi       = "/cgi-bin/remotecmd/remotecmd.cgi"; my $query     = CGI->new; my @configs   = $query->param; my %params    = $query->Vars; my $hostfile  = "/usr/local/etc/rup"; print $query->header(); chomp(my $sshbin = `which ssh`); open my $hosts, '<', $hostfile or die "Couldnt open $hostfile: $!"; my @hostlist = <$hosts>; close($hosts); foreach (@hostlist) {       s/i$//; } my %map = (       exec_cmd        => \&exec_cmd, ); my $output  = ''; my $options = join "\n", map{ qq~  ~ }@hostlist; my $goto    = $ENV{PATH_INFO};   $goto    =~ s!^/!!; if( exists $map{$goto} ){    $output = $map{$goto}->(\%params);    print_output( $output ); } else{    print_html( $options ); } sub exec_cmd {    my ($paramref) = @_;    my %params   = %$paramref;    my $server   = $params{'hostlist'};    my $command  = $params{'command'};    my $send2all = $params{'allhosts'};    my $output   = '';    if (( $command =~ m/^rm/ ) or ( $command =~ m/^ping/ ) or ( $command =~ m/^login/ ) or ( $command =~ m/^ftp/ ) or ( $command =~ m/^telnet/ ) or ( $command =~ m/^rsh/ )) {        die "Command $command ist nicht erlaubt!";    }    if ($send2all eq "send2all") {        foreach (@hostlist) {               chomp;               $output .= (ssh_connect($_, $command));        }    } else {        chomp $server;        $output = ssh_connect($server, $command);    }    return $output; } sub ssh_connect {    my ($server,$command) = @_;    my @lines = qx{$sshbin -T $server $command};    my $output = join "
", @lines;    return $output . "
--
"; } sub print_html{    my ($options) = @_;    print <
Hostname Command:
Alle Hosts

EOT } sub print_output{    my ($out) = @_;    print ("$out"); }