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 |
|
|
|
35 |
|
|
use strict; |
36 |
|
|
use warnings; |
37 |
|
|
|
38 |
|
|
use Data::Dumper; |
39 |
|
|
#use Shell::SSH; |
40 |
|
|
use lib '.'; |
41 |
|
|
use Shell::SSH qw( echo hostname ); |
42 |
|
|
|
43 |
|
|
# defaults: |
44 |
|
|
# - method=ssh, options=proxy_enabled=0 |
45 |
|
|
# - uses defaults proxy if proxy_enabled=1 and proxy_host is empty |
46 |
|
|
my $command = Shell::SSH->new( |
47 |
|
|
#method => 'ssh', |
48 |
|
|
#target => 'test@webpla.net', |
49 |
|
|
target => 'test@netfrag.org', |
50 |
|
|
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 |
|
|
$command->hostname(); |
72 |
|
|
$command->echo("Hello World!"); |
73 |
|
|
|
74 |
|
|
sub recieve_callback { |
75 |
|
|
my $output_block = shift; |
76 |
|
|
#print "output: ", $output_block; |
77 |
|
|
print $output_block; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
$command->disconnect(); |
81 |
|
|
|
82 |
|
|
#print "ready.", "\n"; |