Leser: 2
![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |
1 2 3 4 5 6
sub ssh_connect { my ($server,$command) = @_; my @lines = qx{$sshbin $server $command}; my $output = join "<br />", @lines; return $output . "<br />"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#!/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~ <option value="$_">$_</option>~ }@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 "<br />", @lines; return $output . "<br />--<br />"; } sub print_html{ my ($options) = @_; print <<EOT; <html> <body> <form name="remotecmd" method="post" action="./remotecmd.cgi/exec_cmd" target="_down"> <table width="812" border="0" align="center"> <tr> <td width="94">Hostname</td> <td width="86"> </td> <td width="610">Command:</td> </tr> <tr> <td><select name="hostlist" id="hostlist"> $options </select></td> <td> </td> <td><input name="command" type="text" id="command" value="uname -a" size="70"></td> </tr> <tr> <td><input type="radio" name="allhosts" value="send2all">Alle Hosts </td> <td> </td> <td> </td> </tr> <tr> <td><input type="submit" name="Submit" value="Absenden"></td> <td><input name="cancel" type="reset" id="cancel" value="Zurücksetzen"></td> <td> </td> </tr> </table> <p> </p> </form> </body> </html> EOT } sub print_output{ my ($out) = @_; print ("$out"); }
1 2 3 4 5 6 7 8 9
if ($send2all eq "send2all") { foreach (@hostlist) { chomp; $output .= $_ . "<br />" . (ssh_connect($_, $command)); } } else { chomp $server; $output = $server . '<br />' . ssh_connect($server, $command); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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") { unlink($error); foreach (@hostlist) { chomp; $output .= $_ . "<br />\n" . (ssh_connect($_, $command)); if ((ssh_connect($_, $command)) eq "<br><hr>") { open(ERRORFILE,">>$error") || die "Kann $error nicht oeffnen!"; our $errormsg = '1'; print ERRORFILE ("<font color=\"FF0000\">Warnung:</font> Kann mich nicht auf <b>$_</b> einloggen.<br>\n"); } } } else { chomp $server; $output = $server . '<br />' . ssh_connect($server, $command); } if ($errormsg == '1') { print ("<;script type=\"text/javascript\"> F1 = window.open(\"$error_rel\", \"Fenster1\", \"width=350,height=400,left=0,top=0\"\)\;</script>\n"); close(ERRORFILE); } return $output; unlink($error); }
1 2 3 4 5 6
my $string1 = 'light'; my $string2 = 'house'; my $string3 = $string1 . $string2; print $string1, " # ", $string2, " # ", $string3, "\n";
1 2 3 4 5 6 7 8
my $string1 = 'light'; my $string2 = 'house'; print $string1, " # ", $string2,"\n"; $string1 .= $string2; print "String1 neu: $string1 # String2: $string2\n";
![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |