2010-11-01 Sancho Lerena <slerena@artica.es>

* unix/tentacle_client: Updated tentacle client to 0.30 version,
        with support for HTTP proxies.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3486 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2010-11-01 14:32:40 +00:00
parent 7fbc78e892
commit 411bf82dbc
2 changed files with 118 additions and 13 deletions

View File

@ -1,3 +1,8 @@
2010-11-01 Sancho Lerena <slerena@artica.es>
* unix/tentacle_client: Updated tentacle client to 0.30 version,
with support for HTTP proxies.
2010-10-29 Sancho Lerena <slerena@artica.es>
* win32/bin/util/mibs: Added default mibs for the small snmpagent tool.

View File

@ -1,9 +1,8 @@
#!/usr/bin/perl
################################################################################
#
# Copyright (c) 2007-2008 Ramon Novoa <rnovoa@artica.es>
# Copyright (c) 2007-2010 Artica Soluciones Tecnologicas S.L.
# Copyright (c) 2007-2008 Artica Soluciones Tecnologicas S.L.
#
# tentacle_client.pl Tentacle Client. See http://www.openideas.info/wiki for
# protocol description.
@ -27,7 +26,7 @@ tentacle_client - Tentacle Client
=head1 VERSION
Version 0.2.0
Version 0.3.0
=head1 USAGE
@ -60,7 +59,7 @@ use IO::Select;
use IO::Socket::INET;
# Program version
our $VERSION = '0.2.0';
our $VERSION = '0.3.0';
# Server address
my $t_address = '127.0.0.1';
@ -77,6 +76,18 @@ my $t_port = 41121;
# Do not output error messages, 1 enabled, 0 disabled
my $t_quiet = 0;
# Proxy address
my $t_proxy_address = '';
# Proxy user
my $t_proxy_user = '';
# Proxy password
my $t_proxy_pass = '';
# Proxy port
my $t_proxy_port = 0;
# Server password
my $t_pwd = '';
@ -132,7 +143,8 @@ sub print_help {
print ("\t-t time\t\tTime-out for network operations in seconds (default ${t_timeout}s).\n");
print ("\t-v\t\tBe verbose.\n");
print ("\t-w\t\tPrompt for OpenSSL private key password.\n");
print ("\t-x pwd\t\tServer password.\n\n");
print ("\t-x pwd\t\tServer password.\n");
print ("\t-y proxy\tProxy server string (user:password\@address:port).\n\n");
}
################################################################################
@ -144,7 +156,7 @@ sub parse_options {
my $tmp;
# Get options
if (getopts ('a:ce:f:ghk:p:qr:t:vwx:', \%opts) == 0 || defined ($opts{'h'})) {
if (getopts ('a:ce:f:ghk:p:qr:t:vwx:y:', \%opts) == 0 || defined ($opts{'h'})) {
print_help ();
exit 1;
}
@ -152,7 +164,7 @@ sub parse_options {
# Address
if (defined ($opts{'a'})) {
$t_address = $opts{'a'};
if ($t_address !~ /^[a-zA-Z\.]+$/ && ($t_address !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
if ($t_address !~ /^[a-zA-Z\.][a-zA-Z0-9\.]+$/ && ($t_address !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
|| $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255
|| $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255)) {
error ("Address $t_address is not valid.");
@ -258,10 +270,24 @@ sub parse_options {
$t_ssl_pwd = ask_passwd ("Enter private key file password: ", "Enter private key file password again for confirmation: ");
}
# Server password
# Server password
if (defined ($opts{'x'})) {
$t_pwd = $opts{'x'};
}
# Proxy server
if (defined ($opts{'y'})) {
if ($opts{'y'} !~ /^((.*):(.*)@){0,1}(\S+):(\d+)$/) {
error ("Invalid proxy string: " . $opts{'y'});
}
($t_proxy_user, $t_proxy_pass, $t_proxy_address, $t_proxy_port) = ($2, $3, $4, $5);
$t_proxy_user = '' unless defined ($t_proxy_user);
$t_proxy_pass = '' unless defined ($t_proxy_pass);
if ($t_proxy_port < 1 || $t_proxy_port > 65535) {
error ("Proxy port $t_proxy_port is not valid.");
}
}
}
################################################################################
@ -271,12 +297,10 @@ sub parse_options {
sub start_client {
# Connect to server
# Note: "Type => SOCK_STREAM" should be clearly defined for Solaris zone.
$t_socket = IO::Socket::INET->new (
PeerAddr => $t_address,
PeerAddr => $t_address,
PeerPort => $t_port,
Type => SOCK_STREAM,
);
);
if (! defined ($t_socket)) {
error ("Cannot connect to $t_address on port $t_port: $!.");
@ -289,6 +313,48 @@ sub start_client {
print_log ("Connected to $t_address port $t_port");
}
################################################################################
## SUB start_client_proxy
## Open the server socket. Connects to the Tentacle server through an HTTP proxy.
################################################################################
sub start_client_proxy {
# Connect to proxy
$t_socket = IO::Socket::INET->new (
PeerAddr => $t_proxy_address,
PeerPort => $t_proxy_port,
);
if (! defined ($t_socket)) {
error ("Cannot connect to proxy server $t_proxy_address on port $t_proxy_port: $!.");
}
# Add server socket to select queue
$t_select = IO::Select->new ();
$t_select->add ($t_socket);
print_log ("Connected to proxy server $t_proxy_address port $t_proxy_port");
# Try to CONNECT to the Tentacle server
send_data ("CONNECT " . $t_address . ":" . $t_port . " HTTP/1.0\r\n");
# Authenticate to the proxy
if ($t_proxy_user ne '') {
send_data ("Proxy-Authorization: Basic " . base64 ($t_proxy_user . ":" . $t_proxy_pass) . "\r\n");
}
send_data ("\r\n");
# Check for an HTTP 200 response
my $response = recv_data ($t_block_size);
if ($response !~ m/HTTP.* 200 /) {
my $error = (split (/\r\n/, $response))[0];
error ("CONNECT error: $error");
}
print_log ("Connected to $t_address port $t_port");
}
################################################################################
## SUB stop_client
## Close the server socket.
@ -361,6 +427,36 @@ sub auth_pwd {
}
}
################################################################################
## SUB base64
## Returns the base 64 encoding of a string.
################################################################################
my @alphabet = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/');
sub base64 {
my $str = shift;
my $str64;
# Pre-processing
my $msg = unpack ("B*", pack ("A*", $str));
my $bit_len = length ($msg);
# Process the message in successive 24-bit chunks
for (my $i = 0; $i < $bit_len; $i += 24) {
my $chunk_len = length (substr ($msg, $i, 24));
$str64 .= $alphabet[ord (pack ("B8", "00" . substr ($msg, $i, 6)))];
$str64 .= $alphabet[ord (pack ("B8", "00" . substr ($msg, $i+6, 6)))];
$str64 .= ($chunk_len <= 12) ? "=" : $alphabet[ord (pack ("B8", "00" . substr ($msg, $i+12, 6)))];
$str64 .= ($chunk_len <= 18) ? "=" : $alphabet[ord (pack ("B8", "00" . substr ($msg, $i+18, 6)))];
}
return $str64;
}
################################################################################
## SUB recv_file
## Receive a file from the server
@ -674,7 +770,11 @@ if ($t_recv == 0 && $#ARGV == -1) {
}
# Connect to the server
start_client ();
if ($t_proxy_address eq '') {
start_client ();
} else {
start_client_proxy ();
}
# Start SSL
if ($t_ssl == 1) {