| 1 |
joko |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# $Id$ |
| 4 |
|
|
|
| 5 |
|
|
=pod |
| 6 |
|
|
|
| 7 |
|
|
sshwrap - a ssh wrapper |
| 8 |
|
|
|
| 9 |
|
|
opens a secure shell connection through a http proxy by using the two fine tools ssh and corkscrew |
| 10 |
|
|
|
| 11 |
|
|
sshwrap utilizes some Perl modules from CPAN together with common UNIX programs to provide |
| 12 |
|
|
a kind of API around the known ssh tools. It started as a standalone solution inside a single Perl script, |
| 13 |
|
|
but now uses IPC::Run and Shell.pm to improve modularization and to provide convenient access and functionality. |
| 14 |
|
|
|
| 15 |
|
|
Another focus is on Linux-/Windows compatibility and - important for this special case - the possibility |
| 16 |
|
|
to enter a password on the command line. (other ssh wrappers dictate to use keyfiles instead) |
| 17 |
|
|
|
| 18 |
|
|
It would be nice to use Net::SSH, Net::SSH::Perl or File::Remote under the hood to dispatch core |
| 19 |
|
|
functions to these modules if needed through some circumstances or explicitly requested. |
| 20 |
|
|
There has been done work going onto this direction, but as i see for now Net::SSH just works with keys |
| 21 |
|
|
and File::Remote is stated to only work on UNIX systems. |
| 22 |
|
|
IPC::Run is compatible since it seems to use Win32::Process under the hood. |
| 23 |
|
|
|
| 24 |
|
|
Links: |
| 25 |
|
|
- ssh: http://openssh.org/ |
| 26 |
|
|
- corkscrew: http://www.agroman.net/corkscrew/ |
| 27 |
|
|
- cygwin: http://www.cygwin.com/ |
| 28 |
|
|
|
| 29 |
|
|
=cut |
| 30 |
|
|
|
| 31 |
|
|
# cvs change history |
| 32 |
|
|
# $Log$ |
| 33 |
|
|
|
| 34 |
|
|
use strict; |
| 35 |
|
|
use warnings; |
| 36 |
|
|
|
| 37 |
|
|
use Data::Dumper; |
| 38 |
|
|
use lib '.'; |
| 39 |
joko |
1.2 |
#use Shell::SSH qw( echo hostname ); |
| 40 |
|
|
use Shell::SSH; |
| 41 |
joko |
1.1 |
|
| 42 |
|
|
# defaults: |
| 43 |
|
|
# - method=ssh, options=proxy_enabled=0 |
| 44 |
|
|
# - uses defaults proxy if proxy_enabled=1 and proxy_host is empty |
| 45 |
|
|
my $command = Shell::SSH->new( |
| 46 |
|
|
#method => 'ssh', |
| 47 |
joko |
1.2 |
#method => './tester.sh', |
| 48 |
|
|
target => 'test@webpla.net', |
| 49 |
|
|
#target => 'test@netfrag.org', |
| 50 |
joko |
1.1 |
args => [], |
| 51 |
|
|
#options => { proxy_enabled => 1, proxy_host => 'your-proxy.com:8080' } , |
| 52 |
|
|
#options => { proxy_enabled => 1 } , |
| 53 |
|
|
response => \&recieve_callback, |
| 54 |
|
|
); |
| 55 |
|
|
|
| 56 |
|
|
# native style - deprecated ;) |
| 57 |
|
|
#$command->run("cat /home/test/test.txt"); |
| 58 |
|
|
#sub ps; |
| 59 |
|
|
#print ps -a; |
| 60 |
|
|
#print echo("abc"); |
| 61 |
|
|
#print Dumper($output); |
| 62 |
|
|
|
| 63 |
|
|
# sym-style |
| 64 |
|
|
#echo("huhu"); |
| 65 |
|
|
#print echo("huhu"); |
| 66 |
|
|
|
| 67 |
|
|
# OO-style |
| 68 |
|
|
# TODO: return values via print "command" (Shell::SSH should block in this case) |
| 69 |
|
|
#print $command->hostname(); |
| 70 |
|
|
#print $command->echo("Hello World!"), "\n"; |
| 71 |
joko |
1.2 |
#print "sleeping...\n"; |
| 72 |
|
|
#sleep 5; |
| 73 |
joko |
1.1 |
$command->hostname(); |
| 74 |
joko |
1.2 |
#$command->echo("Hello World!"); |
| 75 |
joko |
1.1 |
|
| 76 |
|
|
sub recieve_callback { |
| 77 |
|
|
my $output_block = shift; |
| 78 |
joko |
1.2 |
print "output: ", $output_block, "\n"; |
| 79 |
|
|
#print $output_block; |
| 80 |
joko |
1.1 |
} |
| 81 |
|
|
|
| 82 |
joko |
1.2 |
sleep 1; |
| 83 |
|
|
|
| 84 |
|
|
$command->_read_output(); |
| 85 |
|
|
#$command->disconnect(); |
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
|
| 89 |
|
|
print "ready.", "\n"; |
| 90 |
|
|
exit; |
| 91 |
|
|
|
| 92 |
|
|
my $tgt1 = 5; |
| 93 |
|
|
my $tgt2 = 10; |
| 94 |
|
|
|
| 95 |
|
|
my $cnt = 0; |
| 96 |
|
|
while (1) { |
| 97 |
|
|
print ".\n"; |
| 98 |
|
|
sleep(1); |
| 99 |
|
|
if ($cnt == $tgt1) { $command->hostname(); } |
| 100 |
|
|
if ($cnt == $tgt2) { $command->_read_output(); } |
| 101 |
|
|
#$command->_read_output(); |
| 102 |
|
|
$cnt++; |
| 103 |
|
|
} |
| 104 |
joko |
1.1 |
|