Server Management - Remote Server Management
cancel
Showing results for 
Search instead for 
Did you mean: 

RIBCL under Linux

Michael Lausch
Occasional Visitor

RIBCL under Linux

How can i send RIBCL commands to the remote insight board II from a unix (linux) server? All i found was a Windows utility which seems not to be available for Linux. Perl/Python scripting is not a problem. So a Specification (which port, which http header, which mime type) of how to send the RIBCL XML file to the board is okay for me.
1 REPLY
Junior Yharte
Trusted Contributor

Re: RIBCL under Linux

I'm not a Perl user myself but I did find some examples that I hope you can use. The port used is still 443, and you will need to establish an SSL connection with the RILOE.

example 1: opening an ssl connection

use Socket;
use Net::SSLeay qw(die_now die_if_ssl_error);

Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();

#
# opens an ssl connection to port 443 of the passed host
#
sub openSSLconnection($)
{
my $host = shift;
my ($ctx, $ssl, $sin, $ip, $nip);

if (not $ip = inet_aton($host))
{
print "$host is a DNS Name, performing lookup\n" if $debug;
$ip = gethostbyname($host) or die "ERROR: Host $hostname not found.\n";
}
$nip = inet_ntoa($ip);
print STDERR "Connecting to $nip:443\n";

$sin = sockaddr_in(443, $ip);
socket (S, &AF_INET, &SOCK_STREAM, 0) or die "ERROR: socket: $!";
connect (S, $sin) or die "connect: $!";

$ctx = Net::SSLeay::CTX_new() or die_now("ERROR: Failed to create SSL_CTX $! ");
Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL);
die_if_ssl_error("ERROR: ssl ctx set options");
$ssl = Net::SSLeay::new($ctx) or die_now("ERROR: Failed to create SSL $!");
Net::SSLeay::set_fd($ssl, fileno(S));
Net::SSLeay::connect($ssl) and die_if_ssl_error("ERROR: ssl connect");
print STDERR 'SSL Connected ';
print 'Using Cipher: ' . Net::SSLeay::get_cipher($ssl) if $debug;
print STDERR "\n\n";

return $ssl;
}

After the connection has been established, the script must send an XML document header as the first line, which will tell the device???s HTTPS webserver that the following content is an XML script. The header must match the header used in the example exactly. After the header has been completely sent, the remainder of the script can be sent. In this example, the script is sent all at once.

example 2: sending the XML header and script body

# usage: sendscript(host, script)
# sends the xmlscript script to host, returns reply
sub sendscript($$)
{
my $host = shift;
my $script = shift;
my ($ssl, $reply, $lastreply, $res, $n);

$ssl = openSSLconnection($host);

# write header
$n = Net::SSLeay::ssl_write_all($ssl, ''."\r\n");
print "Wrote $n\n" if $debug;

# write script
$n = Net::SSLeay::ssl_write_all($ssl, $script);
print "Wrote $n\n$script\n" if $debug;

$reply = "";
$lastreply = "";

READLOOP:
while(1)
{
$n++;
$reply .= $lastreply;
$lastreply = Net::SSLeay::read($ssl);
die_if_ssl_error("ERROR: ssl read");

if($lastreply eq "")
{
sleep(2); # wait 2 sec for more text.
$lastreply = Net::SSLeay::read($ssl);
last READLOOP if($lastreply eq "");
}
print "READ: $lastreply\n" if $debug;
if($lastreply =~ m/STATUS="(0x[0-9A-F]+)"[\s]+MESSAGE='(.*)'[\s]+\/>[\s]*(([\s]|.)*?)<\/RIBCL>/)
{
if($1 eq "0x0000")
{
print STDERR "$3\n" if $3;
}
else
{
print STDERR "ERROR: STATUS: $1, MESSAGE: $2\n";
}
}
}

$reply .= $lastreply;

closeSSLconnection($ssl);

return $reply;
}