diff options
author | Your Name <you@example.com> | 2017-10-14 09:52:12 +0100 |
---|---|---|
committer | Your Name <you@example.com> | 2017-10-14 09:52:29 +0100 |
commit | b6baba7c32afc92809b6b2fb718a0b749bec0ad8 (patch) | |
tree | 6be1de7c3c07bf050fd82fb508f2546d7b089644 | |
parent | e9b198605b259c03615899784d914cf2d86f78dc (diff) | |
download | inf-b6baba7c32afc92809b6b2fb718a0b749bec0ad8.tar.gz inf-b6baba7c32afc92809b6b2fb718a0b749bec0ad8.tar.bz2 inf-b6baba7c32afc92809b6b2fb718a0b749bec0ad8.zip |
proxy support for ilo
-rw-r--r-- | INF/ILO.pm | 84 |
1 files changed, 67 insertions, 17 deletions
@@ -30,34 +30,77 @@ sub read_file($) { return $guts; } -sub setup_port_proxy($$$) { - my ( $local_port, $remote_host, $remote_port ) = @_; +#sub setup_port_proxy($$$) { +# my ( $local_port, $remote_host, $remote_port ) = @_; +# +# my $child = fork(); +# +# print STDERR "balance ", +# join( +# ' ', +# ( +# "balance", "-d", "-f", "127.0.0.1", $local_port, +# $remote_host . ":" . $remote_port +# ) +# ), +# "\n"; +# +# if ( $child == 0 ) { +# +# exec( "balance", "-d", "-f", "-b", "127.0.0.1", $local_port, +# $remote_host . ":" . $remote_port ); +# print STDERR "failed to start port proxy"; +# sleep(10000); +# } +# +# print "Setup proxy $local_port -> $remote_host:$remote_port\n"; +# +# return $child; +#} +# + +sub setup_port_proxy($$$$) { + my ( $self, $local_port, $remote_host, $remote_port ) = @_; my $child = fork(); - print STDERR "balance ", - join( - ' ', - ( - "balance", "-d", "-f", "127.0.0.1", $local_port, - $remote_host . ":" . $remote_port - ) - ), - "\n"; + my $cmd = [ + "balance", "-d", "-f", "-b", "127.0.0.1", $local_port, + $remote_host . ":" . $remote_port + ]; + + print STDERR "PROXY CMD: " . join( ' ', @$cmd ) . "\n"; if ( $child == 0 ) { - exec( "balance", "-d", "-f", "-b", "127.0.0.1", $local_port, - $remote_host . ":" . $remote_port ); + if ( defined $self->{proxy_host} ) { + my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.cnf' ); + + select( ( select($tmp), $| = 1 )[0] ); + + print $tmp "server = 127.0.0.1\n"; + print $tmp "server_port = " . $self->{proxy_port} . "\n"; + print $tmp "local = 127.0.0.0/255.0.0.0\n"; + + $ENV{'LD_PRELOAD'} = 'libtsocks.so'; + $ENV{'TSOCKS_CONF_FILE'} = $tmp->filename; + + print "Filename is $tmp->filename\n"; + } + + exec(@$cmd); print STDERR "failed to start port proxy"; sleep(10000); } + sleep(4); + print "Setup proxy $local_port -> $remote_host:$remote_port\n"; return $child; } + sub proxy($$$) { my ( $self, $req, $res ) = @_; @@ -107,13 +150,13 @@ sub proxy($$$) { $content =~ s/"rc_port":(\d+),/"rc_port":$local_port,/; push @{ $self->{to_kill} }, - setup_port_proxy( $local_port, $self->{host}, $1 ); + $self->setup_port_proxy( $local_port, $self->{host}, $1 ); $local_port = int( rand(30000) ) + 30000; $content =~ s/"vm_port":(\d+),/"vm_port":$local_port,/; push @{ $self->{to_kill} }, - setup_port_proxy( $local_port, $self->{host}, $1 ); + $self->setup_port_proxy( $local_port, $self->{host}, $1 ); } @@ -365,9 +408,16 @@ sub new ($;$) { verify_hostname => 0, ); - my + if ( defined $parm->{proxy_host} ) { + $self->{ua}->proxy( [qw(http https)] => "socks://" + . $parm->{proxy_host} . ":" + . $parm->{proxy_port} ); + $self->{proxy_host} = $parm->{proxy_host}; + $self->{proxy_port} = $parm->{proxy_port}; + } + - $local_port = int( rand(30000) ) + 30000; + my $local_port = int( rand(30000) ) + 30000; $self->{proxy_url} = 'https://127.0.0.1:' . $local_port; |