From 2f5198c9c915eba865663623fecc7970730efc08 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Aug 2017 08:55:39 +0100 Subject: tidy --- INF/ILO2.pm | 320 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 148 insertions(+), 172 deletions(-) diff --git a/INF/ILO2.pm b/INF/ILO2.pm index 6082336..aeff411 100644 --- a/INF/ILO2.pm +++ b/INF/ILO2.pm @@ -20,13 +20,12 @@ use JSON::PP; use MIME::Base64 qw( encode_base64 ); -sub b64($) -{ -my $ret=shift; -$ret=encode_base64($ret); -$ret =~ s/[\n\s\r]//g; +sub b64($) { + my $ret = shift; + $ret = encode_base64($ret); + $ret =~ s/[\n\s\r]//g; -return $ret; + return $ret; } sub read_file($) { @@ -85,8 +84,7 @@ sub proxy($$$) { if ( $req->uri->as_string =~ /^\/html\/rc.*\.jar/ ) { $res->header( 'Content-type' => 'application/x-ms-application' ); - $res->add_content( - read_file('/usr/local/share/inf/ilo/rc175p08.jar') ); + $res->add_content( read_file('/usr/local/share/inf/ilo/rc175p08.jar') ); $res->code(200); return; @@ -102,57 +100,18 @@ sub proxy($$$) { return; } - print "Another url...". $req->uri->as_string."\n"; - - die "meh"; - -# -# my $proxy_req = -# HTTP::Request->new( $req->method, $self->{ilo_url} . $req->uri->as_string, -# [], $req->content ); -# -# $proxy_req->header( 'cookie' => 'sessionKey=' . $self->{stoken} ); -# -# my $proxy_res = $self->{ua}->request($proxy_req); -# -# unless ( $proxy_res->is_success ) { -# print STDERR "request failed - did not get 200\n"; -# } -# -# print "URI:", $req->uri->as_string, " code ", $proxy_res->code, " type ", -# $proxy_res->header('Content-type'), "\n"; -# -# $res->code( $proxy_res->code ); -# $res->header( 'Content-type' => $proxy_res->header('Content-type') ); -# -# my $content = $proxy_res->content; -# -# if ( $req->uri->as_string =~ /^\/json\/rc_info/ ) { -# -# my $local_port = int( rand(30000) ) + 30000; -# -# $content =~ s/"rc_port":(\d+),/"rc_port":$local_port,/; -# push @{ $self->{to_kill} }, -# 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 ); -# -# } -# -# $res->add_content($content); -# + print "Another url..." . $req->uri->as_string . "\n"; + + die "meh"; + } sub login($) { my $self = shift; - $self->{stoken} = undef; - $self->{skey} = undef; - $self->{sindex} = undef; + $self->{stoken} = undef; + $self->{skey} = undef; + $self->{sindex} = undef; my $get = GET( $self->{ilo_url} . '/login.htm' ); @@ -166,27 +125,32 @@ sub login($) { return -1; } - my $content=$res->content; + my $content = $res->content; - return -1 unless $content =~ /sessionkey="([A-Z0-9]+)"/ ; + return -1 unless $content =~ /sessionkey="([A-Z0-9]+)"/; - $self->{skey}=$1; + $self->{skey} = $1; - print"skey=".$self->{skey}."\n"; + #print "skey=" . $self->{skey} . "\n"; - return -1 unless $content =~ /sessionindex="([0-9]+)"/ ; + return -1 unless $content =~ /sessionindex="([0-9]+)"/; - $self->{sindex}=$1; - print"sindex=".$self->{sindex}."\n"; + $self->{sindex} = $1; + #print "sindex=" . $self->{sindex} . "\n"; - $self->{slogin}="hp-iLO-Login=".$self->{sindex}.":".b64($self->{user}) . ":" . b64($self->{password}).":".$self->{skey}; + $self->{slogin} = + "hp-iLO-Login=" + . $self->{sindex} . ":" + . b64( $self->{user} ) . ":" + . b64( $self->{password} ) . ":" + . $self->{skey}; - print "Session login ".$self->{slogin}."\n"; + #print "Session login " . $self->{slogin} . "\n"; $get = GET( $self->{ilo_url} . '/index.htm' ); - $get->header( 'cookie' => $self->{slogin} ); - $get->header( 'Referer' => $self->{ilo_url} . '/login.htm' ); + $get->header( 'cookie' => $self->{slogin} ); + $get->header( 'Referer' => $self->{ilo_url} . '/login.htm' ); $res = $self->{ua}->request($get); @@ -198,28 +162,36 @@ sub login($) { return -1; } - my $content=$res->content; + my $content = $res->content; + + unless ( $content =~ /ie_index.htm/ ) { + print STDERR "Unhappy with reply from login\n"; - return -1 unless $content =~ /ie_index.htm/; + return -1; + } - $self->{stoken}='hp-iLO-Session='.$self->{sindex}.':::'.$self->{skey}.';'.$self->{slogin}; + $self->{stoken} = + 'hp-iLO-Session=' + . $self->{sindex} . ':::' + . $self->{skey} . ';' + . $self->{slogin}; - print "Session token ".$self->{stoken}."\n"; + #print "ILO Session token " . $self->{stoken} . "\n"; + # + print "ILO2 login successful\n"; return 0; } sub view($) { - my $self = shift; $self->login() unless defined $self->{stoken}; - my $get = GET( $self->{ilo_url} . '/drc2fram.htm?restart=0' ); - $get->header( 'cookie' => $self->{stoken} ); + $get->header( 'cookie' => $self->{stoken} ); my $res = $self->{ua}->request($get); @@ -231,56 +203,59 @@ sub view($) { unless ( $content =~ /com.hp.ilo2.remcons.remcons.class/ ) { print STDERR "returned html doesn't look right\n"; + print Dumper($content); return -1; } - my $things={}; - - - for my $thing ( qw( consoleWidth consoleHeight info1 info2 info3 info4 info5 info6 infomp infoscp info7 info8 slot_number info0 irc_fullscreen rcseize_timeout infoa infob infoc infod infom infomm infok infosc infocc infoae infomu infoms infon infoo infoscp infopriv)) -{ - - - return -1 unless $content =~ /${thing}=([^;]*);/; - - $things->{$thing}=$1; - $things->{$thing} =~ s/[\\"']//g ; -} - - -my $local_port = int( rand(30000) ) + 30000; + my $things = {}; - push @{ $self->{to_kill} }, setup_port_proxy( $local_port, $self->{host}, $things->{info6} ); + for my $thing ( + qw( consoleWidth consoleHeight info1 info2 info3 info4 info5 info6 infomp infoscp info7 info8 slot_number info0 irc_fullscreen rcseize_timeout infoa infob infoc infod infom infomm infok infosc infocc infoae infomu infoms infon infoo infoscp infopriv) + ) + { -$things->{info6}=$local_port; -$things->{consoleWidth}=1024; -$things->{consoleHeight}=768; + return -1 unless $content =~ /${thing}=([^;]*);/; + $things->{$thing} = $1; + $things->{$thing} =~ s/[\\"']//g; + } -my $document=''."\n"; - -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''; + my $local_port = int( rand(30000) ) + 30000; + push @{ $self->{to_kill} }, + setup_port_proxy( $local_port, $self->{host}, $things->{info6} ); + + $things->{info6} = $local_port; + $things->{consoleWidth} = 1024; + $things->{consoleHeight} = 768; + + my $document = +'' . "\n"; + + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= + '' . "\n"; + $document .= '' . "\n"; + $document .= '' . "\n"; + $document .= ''; $document = "" . $document . ""; -print Dumper($document); + print Dumper($document); $self->{java_html} = $document; @@ -301,9 +276,9 @@ print Dumper($document); $SIG{TERM} = sub { kill 'TERM', ( @{ $self->{to_kill} } ); die; }; system( -# "strace","-f","-o","t2","-s","8192", -# "/bin/appletviewer", - "appletviewer", + # "strace","-f","-o","t2","-s","8192", + # "/bin/appletviewer", + "appletviewer", "-J-Djava.security.manager", "-J-Djava.security.policy=/usr/local/share/inf/ilo/mypolicy", "-J-Djavax.net.ssl.trustStore=/usr/local/share/inf/ilo/server.jks", @@ -313,16 +288,14 @@ print Dumper($document); kill 'TERM', ( @{ $self->{to_kill} } ); } - sub media($) { my $self = shift; $self->login() unless defined $self->{stoken}; - my $get = GET( $self->{ilo_url} . '/vtd028.htm' ); - $get->header( 'cookie' => $self->{stoken} ); + $get->header( 'cookie' => $self->{stoken} ); my $res = $self->{ua}->request($get); @@ -334,43 +307,46 @@ sub media($) { unless ( $content =~ /com.hp.ilo2.virtdevs.virtdevs.class/ ) { print STDERR "returned html doesn't look right\n"; + print Dumper($content); return -1; } - my $things={}; - - - for my $thing ( qw( info0v info1v usbcfg serverName dp)) -{ - - - return -1 unless $content =~ /${thing}=([^;]*);/; - - $things->{$thing}=$1; - $things->{$thing} =~ s/[\\"']//g ; -} - + my $things = {}; -my $local_port = int( rand(30000) ) + 30000; + for my $thing (qw( info0v info1v usbcfg serverName dp)) { - push @{ $self->{to_kill} }, setup_port_proxy( $local_port, $self->{host}, $things->{info1v} ); - -$things->{info1v}=$local_port; + return -1 unless $content =~ /${thing}=([^;]*);/; + $things->{$thing} = $1; + $things->{$thing} =~ s/[\\"']//g; + } -my $document=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n"; -$document .=''."\n" if $things->{dp} != 0; -$document .=''; + my $local_port = int( rand(30000) ) + 30000; + push @{ $self->{to_kill} }, + setup_port_proxy( $local_port, $self->{host}, $things->{info1v} ); + + $things->{info1v} = $local_port; + + my $document = +'' + . "\n"; + $document .= '' . "\n"; + $document .= + '' . "\n"; + $document .= + '' . "\n"; + $document .= + '' . "\n"; + $document .= + '' . "\n"; + $document .= '' . "\n" + if $things->{dp} != 0; + $document .= ''; $document = "" . $document . ""; -print Dumper($document); + print Dumper($document); $self->{java_html} = $document; @@ -391,9 +367,9 @@ print Dumper($document); $SIG{TERM} = sub { kill 'TERM', ( @{ $self->{to_kill} } ); die; }; system( -# "strace","-f","-o","t2","-s","8192", -# "/bin/appletviewer", - "appletviewer", + # "strace","-f","-o","t2","-s","8192", + # "/bin/appletviewer", + "appletviewer", "-J-Djava.security.manager", "-J-Djava.security.policy=/usr/local/share/inf/ilo/myvtdpolicy", "-J-Djavax.net.ssl.trustStore=/usr/local/share/inf/ilo/server.jks", @@ -408,7 +384,7 @@ sub get_host_power($) { $self->login() unless defined $self->{stoken}; - my $get = GET( $self->{ilo_url}. '/dvirtpwr.htm' ); + my $get = GET( $self->{ilo_url} . '/dvirtpwr.htm' ); $get->header( 'cookie' => $self->{stoken} ); @@ -419,26 +395,25 @@ sub get_host_power($) { return 0; } - my $content=$res->content; + my $content = $res->content; - return 0 unless $content =~ /serverPower="([A-Z0-9]+)"/ ; + return 0 unless $content =~ /serverPower="([A-Z0-9]+)"/; - my $state=$1; + my $state = $1; -$state="OFF" if $state eq 'STANDBY'; + $state = "OFF" if $state eq 'STANDBY'; - print "Server Power is $state\n"; + print "Server Power is $state\n"; -return $state; + return $state; } sub set_host_power($$$) { - my ( $self, $thing,$other_thing ) = @_; - + my ( $self, $thing, $other_thing ) = @_; $self->login() unless defined $self->{stoken}; - my $get = GET( $self->{ilo_url}. '/dvirtpwr.htm' ); + my $get = GET( $self->{ilo_url} . '/dvirtpwr.htm' ); $get->header( 'cookie' => $self->{stoken} ); my $res = $self->{ua}->request($get); @@ -448,19 +423,19 @@ sub set_host_power($$$) { return 0; } -#cold Cold+Boot -#warn Reset -#hold Press+and+Hold -#press Momentary+Press + #cold Cold+Boot + #warn Reset + #hold Press+and+Hold + #press Momentary+Press + my $content = $res->content; - my $content=$res->content; - - return -1 unless $content =~ /signature="([A-Z0-9]+)"/ ; + return -1 unless $content =~ /signature="([A-Z0-9]+)"/; - $self->{signature}=$1; + $self->{signature} = $1; - my $form_content='signature='.$self->{signature}.'&'.$thing.'='.$other_thing; + my $form_content = + 'signature=' . $self->{signature} . '&' . $thing . '=' . $other_thing; print "form_content=$form_content\n"; @@ -482,18 +457,18 @@ sub set_host_power($$$) { sub cold_boot($) { my $self = shift; - return $self->set_host_power('cold','Cold+Boot'); + return $self->set_host_power( 'cold', 'Cold+Boot' ); } sub reset($) { my $self = shift; - return $self->set_host_power('warm','Reset'); + return $self->set_host_power( 'warm', 'Reset' ); } sub off($) { my $self = shift; if ( $self->get_host_power =~ /ON/i ) { - return $self->set_host_power('hold','Press+and+Hold'); + return $self->set_host_power( 'hold', 'Press+and+Hold' ); } return 1; } @@ -501,7 +476,7 @@ sub off($) { sub on($) { my $self = shift; if ( $self->get_host_power =~ /OFF/i ) { - return $self->set_host_power('press','Momentary+Press'); + return $self->set_host_power( 'press', 'Momentary+Press' ); } return 1; } @@ -561,11 +536,12 @@ sub new ($;$) { my ( $class, $parm ) = @_; my $self; - $self->{ua} = my $ua = LWP::UserAgent->new; $self->{host} = $parm->{host} || "127.0.0.1"; + print "ILO2 instansiated for host " . $self->{host} . "\n"; + $self->{user} = $parm->{user} || "Administrator"; $self->{password} = $parm->{password} || ""; @@ -588,7 +564,7 @@ sub new ($;$) { port => $local_port, daemon_class => 'HTTP::Daemon::SSL', daemon_args => [ - LocalAddr => '127.0.0.1', + LocalAddr => '127.0.0.1', SSL_key_file => '/usr/local/share/inf/ilo/server.key', SSL_cert_file => '/usr/local/share/inf/ilo/server.crt', ], @@ -605,7 +581,7 @@ sub new ($;$) { } ); - $self->{stoken} = undef; + $self->{stoken} = undef; $self->{to_kill} = []; return bless $self, $class; -- cgit v1.2.3