1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | |
---|
5 | use gateway_lib; |
---|
6 | |
---|
7 | use IO::File; |
---|
8 | |
---|
9 | use Getopt::Long; |
---|
10 | |
---|
11 | my $ssh_pubkey; |
---|
12 | my $ssh_privkey; |
---|
13 | my $tunnelip; |
---|
14 | my $peer; |
---|
15 | my @ports; |
---|
16 | my $fedkit_dir= "/usr/local/federation"; |
---|
17 | my $perl = "/usr/bin/perl"; |
---|
18 | my $iface_file; |
---|
19 | my $ssh = "/usr/bin/ssh"; |
---|
20 | my $use_file; |
---|
21 | my $ssh_port=22; |
---|
22 | my %opts = ( |
---|
23 | 'ssh_pubkey=s' => \$ssh_pubkey, |
---|
24 | 'ssh_privkey=s' => \$ssh_privkey, |
---|
25 | 'tunnelip' => \$tunnelip, |
---|
26 | 'peer=s' => \$peer, |
---|
27 | 'port=s', \@ports, |
---|
28 | 'fedkit=s' => \$fedkit_dir, |
---|
29 | 'perl=s' => \$perl, |
---|
30 | 'ssh=s' => \$ssh, |
---|
31 | 'ssh_port=s' => \$ssh_port, |
---|
32 | 'use_file' => \$use_file, |
---|
33 | ); |
---|
34 | |
---|
35 | exit(20) unless GetOptions(%opts); |
---|
36 | |
---|
37 | gateway_lib::read_config(gateway_lib::config_filename(), \%opts) |
---|
38 | if $use_file; |
---|
39 | |
---|
40 | my $tunnelparam = $tunnelip ? '--tunnelip' : ''; |
---|
41 | |
---|
42 | system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/prep_gateway.pl --peer=$peer " . |
---|
43 | "--ssh_pubkey=$ssh_pubkey $tunnelparam"); |
---|
44 | exit(20) if $?; |
---|
45 | |
---|
46 | foreach my $p (@ports) { |
---|
47 | my ($type, $port, $host, $eport) = split(":", $p); |
---|
48 | $eport = $port unless $eport; |
---|
49 | my $fopt = ($type eq 'local' ? "-L" : "-R") . " :$port:$host:$eport"; |
---|
50 | my $cmd = "$ssh -N $fopt -p $ssh_port -o \"StrictHostKeyChecking no\" " . |
---|
51 | "-i $ssh_privkey $peer &"; |
---|
52 | system($cmd); |
---|
53 | die if $?; |
---|
54 | } |
---|
55 | |
---|
56 | exit(0); |
---|
57 | |
---|
58 | =pod |
---|
59 | |
---|
60 | =head1 NAME |
---|
61 | |
---|
62 | B<port_forward.pl> - Do ssh service port forwarding. |
---|
63 | |
---|
64 | =head1 OPTIONS |
---|
65 | |
---|
66 | =over 8 |
---|
67 | |
---|
68 | =item B<fedkit=>I<install_dir> |
---|
69 | |
---|
70 | Directory in which this software is installed. Generally not needed. |
---|
71 | |
---|
72 | =item B<peer=>I<hostname> |
---|
73 | |
---|
74 | The other gateway providing forwarding. |
---|
75 | |
---|
76 | =item B<perl=>I<perl_binary> |
---|
77 | |
---|
78 | Location of the perl binary. Usually unneeded. |
---|
79 | |
---|
80 | =item B<port=>I<port_spec> |
---|
81 | |
---|
82 | Forward the given port. Each port is given as type:lport:host:rport where |
---|
83 | type can be "local" or "remote". These correspont to B<-L> and B<-R> ssh |
---|
84 | port forwarding, respectively. The remaining parameters are exactly as for |
---|
85 | those parameters to ssh. |
---|
86 | |
---|
87 | =item B<ssh=>I<ssh_binary> |
---|
88 | |
---|
89 | The pathname of the ssh binary. Unusally unnecessary. |
---|
90 | |
---|
91 | =item B<ssh_pubkey=>I<keyfile> |
---|
92 | |
---|
93 | A public to install as authorized. |
---|
94 | |
---|
95 | =item B<ssh_privkey=>I<identity_file> |
---|
96 | |
---|
97 | The identity to use for remote access |
---|
98 | |
---|
99 | =item B<tunnelip> |
---|
100 | |
---|
101 | True if the testbed uses the DETER tunnelip extension to provide external |
---|
102 | connectivity information |
---|
103 | |
---|
104 | =item B<use_file> |
---|
105 | |
---|
106 | If given read additional parameters from the file in |
---|
107 | /proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the |
---|
108 | current testbed project and experiment and the hostname is before the first |
---|
109 | dot. The file is option: value. |
---|
110 | |
---|
111 | |
---|
112 | =back |
---|
113 | |
---|
114 | =head1 SYNOPSIS |
---|
115 | |
---|
116 | In addition to providing the key initialization and DETER routing setup for a |
---|
117 | gateway without external access as B<active_config.pl> does, B<forward_port.pl> |
---|
118 | forwards the given ports using ssh. B<forward_port.pl> does not establish low |
---|
119 | level connectivity tunnels. |
---|
120 | |
---|
121 | |
---|
122 | =head1 AUTHORS |
---|
123 | |
---|
124 | Ted Faber <faber@isi.edu> |
---|
125 | |
---|
126 | =cut |
---|