From ef393874b4df287089d07f8d49d91972e0c5ca18 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 10 May 2019 22:48:36 +0100 Subject: supermicro support --- INF.pm | 3 + INF/SuperMicro.pm | 344 +++++++++++++++++++++ Makefile | 12 + supermicro/SharedLibrary32.dll | Bin 0 -> 176128 bytes supermicro/SharedLibrary64.dll | Bin 0 -> 205824 bytes supermicro/iKVM32.dll | Bin 0 -> 294400 bytes supermicro/iKVM64.dll | Bin 0 -> 252928 bytes supermicro/iKVM__V1.69.25.0x0.jar | Bin 0 -> 3124210 bytes supermicro/libSharedLibrary32.so | Bin 0 -> 243584 bytes supermicro/libSharedLibrary64.so | Bin 0 -> 261688 bytes supermicro/libiKVM32.so | Bin 0 -> 184768 bytes supermicro/libiKVM64.so | Bin 0 -> 203144 bytes supermicro/orig/iKVM__V1.69.25.0x0.jar.pack.gz | Bin 0 -> 2952700 bytes .../orig/liblinux_x86_64__V1.0.8.jar.pack.gz | Bin 0 -> 169304 bytes supermicro/orig/liblinux_x86__V1.0.8.jar.pack.gz | Bin 0 -> 159339 bytes supermicro/orig/libwin_x86_64__V1.0.8.jar.pack.gz | Bin 0 -> 221079 bytes supermicro/orig/libwin_x86__V1.0.8.jar.pack.gz | Bin 0 -> 216921 bytes 17 files changed, 359 insertions(+) create mode 100644 INF/SuperMicro.pm create mode 100644 supermicro/SharedLibrary32.dll create mode 100644 supermicro/SharedLibrary64.dll create mode 100644 supermicro/iKVM32.dll create mode 100644 supermicro/iKVM64.dll create mode 100644 supermicro/iKVM__V1.69.25.0x0.jar create mode 100644 supermicro/libSharedLibrary32.so create mode 100644 supermicro/libSharedLibrary64.so create mode 100644 supermicro/libiKVM32.so create mode 100644 supermicro/libiKVM64.so create mode 100644 supermicro/orig/iKVM__V1.69.25.0x0.jar.pack.gz create mode 100644 supermicro/orig/liblinux_x86_64__V1.0.8.jar.pack.gz create mode 100644 supermicro/orig/liblinux_x86__V1.0.8.jar.pack.gz create mode 100644 supermicro/orig/libwin_x86_64__V1.0.8.jar.pack.gz create mode 100644 supermicro/orig/libwin_x86__V1.0.8.jar.pack.gz diff --git a/INF.pm b/INF.pm index 962b15a..556a546 100644 --- a/INF.pm +++ b/INF.pm @@ -3,6 +3,7 @@ use INF::APC; use INF::DSRx020; use INF::ILO; use INF::ILO2; +use INF::SuperMicro; #$infs = [ @@ -31,6 +32,8 @@ sub new ($;$) { } elsif ( $inf->{inf_type} eq 'apc' ) { return INF::APC->new($inf); + } elsif ( $inf->{inf_type} eq 'supermicro' ) { + return INF::SuperMicro->new($inf); } elsif ( $inf->{inf_type} eq 'ilo' ) { return INF::ILO->new($inf); } elsif ( $inf->{inf_type} eq 'ilo2' ) { diff --git a/INF/SuperMicro.pm b/INF/SuperMicro.pm new file mode 100644 index 0000000..68927c7 --- /dev/null +++ b/INF/SuperMicro.pm @@ -0,0 +1,344 @@ +#!/usr/bin/env perl + +IO::Socket::SSL::set_ctx_defaults( SSL_verify_mode => SSL_VERIFY_NONE ); + +package INF::SuperMicro; + +use HTTP::Status; +use HTTP::Cookies; + +use IO::Socket::SSL qw(); +use HTML::TreeBuilder; +use HTTP::Request::Common; +use LWP::UserAgent; +use URI::Escape; +use File::Temp qw/ tempfile tempdir /; +use XML::Simple; +use Data::Dumper; +use JSON::PP; + +my $prefix = "/usr/local/share/inf/supermicro/"; + +my $jars = [ $prefix . "iKVM__V1.69.25.0x0.jar" ]; + +sub login($) { + my $self = shift; + + my $post = POST( $self->{bmc_url} . '/cgi/login.cgi' ); + my $form_content = + 'name=' . $self->{user} . '&' . 'pwd=' . $self->{password}; + + $post->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); + $post->header( 'Content-Length' => length($form_content) ); + $post->content($form_content); + + my $res = $self->{ua}->request($post); + + unless ( $res->is_success ) { + print STDERR "Login failed - did not get 200\n"; + + print Dumper($res); + + $self->{logged_in} = undef; + return -1; + } + + $self->{logged_in} = 1; + + #my $json = decode_json( $res->content ); + + #$self->{skey} = $json->{session_key}; + + #print "Session key ".$self->{skey}."\n"; + + return 0; +} + +sub view($) { + my $self = shift; + + $self->login() unless defined $self->{logged_in}; + + my $get = GET( $self->{bmc_url} + . '/cgi/url_redirect.cgi?url_name=ikvm&url_type=jwsk' ); + + my $res = $self->{ua}->request($get); + + unless ( $res->is_success ) { + print STDERR "JWSK frequest failed - did not get 200\n"; + return -1; + } + + my $xml = new XML::Simple; + + my $c = $res->content; + + $c =~ s/^[\s\n\r]+//s; + + my $data = $xml->XMLin($c); + + return undef unless defined $data->{'application-desc'}; + + my $args = $data->{'application-desc'}->{'argument'}; + + return undef unless defined $args; + + mkdir $ENV{HOME} . "/.supermicro_kvm"; + chdir $ENV{HOME} . "/.supermicro_kvm"; + + my $cp = join( ':', @$jars ); + + if ( $self->{proxy_host} ) { + system( + "echo", + "java", + "-Djava.net.preferIPv4Stack=true", + "-Djava.net.useSystemProxies=false", + "-DsocksProxyVersion=4", + "-DsocksProxySet=true", + "-DsocksProxyHost=" . $self->{proxy_host}, + "-DsocksProxyPort=" . $self->{proxy_port}, + "-cp", + $cp, + "-Djava.library.path=" . $prefix, + "tw.com.aten.ikvm.KVMMain", + @$args + ); + system( + "java", + "-Djava.net.preferIPv4Stack=true", + "-Djava.net.useSystemProxies=false", + "-DsocksProxyVersion=4", + "-DsocksProxySet=true", + "-DsocksProxyHost=" . $self->{proxy_host}, + "-DsocksProxyPort=" . $self->{proxy_port}, + "-cp", + $cp, + "-Djava.library.path=" . $prefix, + "tw.com.aten.ikvm.KVMMain", + @$args + ); + + } + else { + system( "java", "-cp", $cp, "-Djava.library.path=" . $prefix, + "tw.com.aten.ikvm.KVMMain", @$args ); + } + +} + +# +# unless ( $content =~ /Netscape'\) {(.*)}[\s\n]*else if/s ) { +# print STDERR "returned html doesn't look right\n"; +# return -1; +# } +# +# $content = $1; +# +# #$content=~ s/document.writeln\("(.*)"\);$/\1/m; +# $content =~ s/^\s*document.writeln\("(.*)"\);\s*$/\1/mg; +# $content =~ s/\\//g; +# +# $content =~ s/RCINFO1=.*$/RCINFO1="$self->{skey}"/m; +# $content =~ s/RCINFO6=.*$/RCINFO6="17990"/m; +# $content =~ s/RCINFOLANG=.*$/RCINFOLANG="en"/m; +# $content =~ s%(archive=)(/.*)$%\1$self->{proxy_url}\2%m; +# +# $content = "" . $content . ""; +# +# $self->{java_html} = $content; +# +# my $webserver_pid = fork(); +# +# if ( $webserver_pid == 0 ) { +# $SIG{INT} = sub { kill 'KILL', ( @{ $self->{to_kill} } ); die; }; +# $SIG{TERM} = sub { kill 'KILL', ( @{ $self->{to_kill} } ); die; }; +# +# $self->{server}->start; +# print STDERR "failed to web server"; +# sleep(100000); +# } +# +# push @{ $self->{to_kill} }, $webserver_pid; +# +# $SIG{INT} = sub { kill 'INT', ( @{ $self->{to_kill} } ); die; }; +# $SIG{TERM} = sub { kill 'TERM', ( @{ $self->{to_kill} } ); die; }; +# +# system( +# "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", +# $self->{proxy_url} . "/html/java_irc.html" +# ); +# +# kill 'TERM', ( @{ $self->{to_kill} } ); +#} +# +sub get_host_power($) { + my ($self) = @_; + + $self->login() unless defined $self->{logged_in}; + + my $post = POST( $self->{bmc_url} . '/cgi/ipmi.cgi' ); + my $form_content = 'op=POWER_INFO.XML&r=(0%2C0)'; + + $post->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); + $post->header( 'Content-Length' => length($form_content) ); + $post->content($form_content); + + my $res = $self->{ua}->request($post); + + unless ( $res->is_success ) { + print STDERR " get host power - did not get 200\n"; + return undef; + } + + my $xml = new XML::Simple; + + my $c = $res->content; + + $c =~ s/^[\s\n\r]+//s; + + my $data = $xml->XMLin($c); + + return undef unless defined $data->{'POWER_INFO'}; + return undef unless defined $data->{'POWER_INFO'}->{'POWER'}; + return undef unless defined $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; + + return $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; +} + +sub set_host_power($$) { + my ( $self, $what ) = @_; + + $self->login() unless defined $self->{logged_in}; + + my $post = POST( $self->{bmc_url} . '/cgi/ipmi.cgi' ); + my $form_content = 'op=POWER_INFO.XML&r=(1%2C' . $what . ')'; + + $post->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); + $post->header( 'Content-Length' => length($form_content) ); + $post->content($form_content); + + my $res = $self->{ua}->request($post); + + unless ( $res->is_success ) { + print STDERR " get host power - did not get 200\n"; + return 0; + } + + my $xml = new XML::Simple; + + my $c = $res->content; + + $c =~ s/^[\s\n\r]+//s; + + my $data = $xml->XMLin($c); + + return 0 unless defined $data->{'POWER_INFO'}; + return 0 unless defined $data->{'POWER_INFO'}->{'POWER'}; + return 0 unless defined $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; + + return 1; +} + +sub reset($) { + my $self = shift; + return $self->set_host_power('0'); +} + +sub port_off($) { + my $self = shift; + return $self->set_host_power('1'); +} + +sub orderly_shutdown($) { + my $self = shift; + return $self->set_host_power('2'); +} + +sub port_on($) { + my $self = shift; + return $self->set_host_power('3'); +} + +sub port_cycle($) { + my $self = shift; + return $self->set_host_power('5'); +} + +sub port_state_get($$) { + my $self = shift; + return $self->get_host_power(); +} + +sub port_name_get($$) { + my $self = shift; + return $self->{name}; +} + +sub name_get($) { + my $self = shift; + return $self->{name}; +} + +sub pdu_load_get($) { + return "N/A"; +} + +sub psu_status($) { + return "N/A"; +} + +sub port_count($) { + return 1; +} + +sub port_id_get_by_number($$) { + return "K0"; +} + +sub logout($) { + my $self = shift; +} + +sub new ($;$) { + my ( $class, $parm ) = @_; + my $self; + + $self->{ua} = my $ua = LWP::UserAgent->new; + $self->{cookie_jar} = HTTP::Cookies->new(); + $self->{ua}->cookie_jar( $self->{cookie_jar} ); + + $self->{host} = $parm->{host} || "127.0.0.1"; + + $self->{user} = $parm->{user} || "ADMIN"; + $self->{password} = $parm->{password} || "ADMIN"; + + $self->{name} = $parm->{name} || $self->{host}; + + $self->{bmc_url} = $parm->{bmc_url} + || 'https://' . $self->{host}; + + $self->{ua}->ssl_opts( + SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, + verify_hostname => 0, + ); + + 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}; + } + + $self->{logged_in} = undef; + + return bless $self, $class; + +} + +1; + diff --git a/Makefile b/Makefile index 307448d..3da1407 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ install: mkdir -p /usr/local/share/inf/HTTP/Server mkdir -p /usr/local/share/inf/avocent mkdir -p /usr/local/share/inf/ilo + mkdir -p /usr/local/share/inf/supermicro install -m 755 inf.pl /usr/local/bin/inf install -m 644 HTTP/Server/Brick.pm /usr/local/share/inf/HTTP/Server/ install -m 644 INF.pm /usr/local/share/inf/ @@ -12,6 +13,7 @@ install: install -m 644 INF/DSRx020.pm /usr/local/share/inf/INF install -m 644 INF/ILO.pm /usr/local/share/inf/INF install -m 644 INF/ILO2.pm /usr/local/share/inf/INF + install -m 644 INF/SuperMicro.pm /usr/local/share/inf/INF install -m 644 mibs/PowerNet-MIB.mib /usr/local/share/inf/mibs/ install -m 644 mibs/RFC1155-SMI.mib /usr/local/share/inf/mibs/ install -m 644 mibs/RFC-1212.mib /usr/local/share/inf/mibs/ @@ -39,3 +41,13 @@ install: install -m 644 ilo/server.crt /usr/local/share/inf/ilo/ install -m 644 ilo/server.jks /usr/local/share/inf/ilo/ install -m 644 ilo/server.key /usr/local/share/inf/ilo/ + install -m 644 supermicro/iKVM32.dll /usr/local/share/inf/supermicro/ + install -m 644 supermicro/iKVM64.dll /usr/local/share/inf/supermicro/ + install -m 644 supermicro/iKVM__V1.69.25.0x0.jar /usr/local/share/inf/supermicro/ + install -m 644 supermicro/libiKVM32.so /usr/local/share/inf/supermicro/ + install -m 644 supermicro/libiKVM64.so /usr/local/share/inf/supermicro/ + install -m 644 supermicro/libSharedLibrary32.so /usr/local/share/inf/supermicro/ + install -m 644 supermicro/libSharedLibrary64.so /usr/local/share/inf/supermicro/ + install -m 644 supermicro/SharedLibrary32.dll /usr/local/share/inf/supermicro/ + install -m 644 supermicro/SharedLibrary64.dll /usr/local/share/inf/supermicro/ + diff --git a/supermicro/SharedLibrary32.dll b/supermicro/SharedLibrary32.dll new file mode 100644 index 0000000..a2a5f56 Binary files /dev/null and b/supermicro/SharedLibrary32.dll differ diff --git a/supermicro/SharedLibrary64.dll b/supermicro/SharedLibrary64.dll new file mode 100644 index 0000000..2c0eab3 Binary files /dev/null and b/supermicro/SharedLibrary64.dll differ diff --git a/supermicro/iKVM32.dll b/supermicro/iKVM32.dll new file mode 100644 index 0000000..288c226 Binary files /dev/null and b/supermicro/iKVM32.dll differ diff --git a/supermicro/iKVM64.dll b/supermicro/iKVM64.dll new file mode 100644 index 0000000..10f7f37 Binary files /dev/null and b/supermicro/iKVM64.dll differ diff --git a/supermicro/iKVM__V1.69.25.0x0.jar b/supermicro/iKVM__V1.69.25.0x0.jar new file mode 100644 index 0000000..3b3e326 Binary files /dev/null and b/supermicro/iKVM__V1.69.25.0x0.jar differ diff --git a/supermicro/libSharedLibrary32.so b/supermicro/libSharedLibrary32.so new file mode 100644 index 0000000..9c517f8 Binary files /dev/null and b/supermicro/libSharedLibrary32.so differ diff --git a/supermicro/libSharedLibrary64.so b/supermicro/libSharedLibrary64.so new file mode 100644 index 0000000..4ded62e Binary files /dev/null and b/supermicro/libSharedLibrary64.so differ diff --git a/supermicro/libiKVM32.so b/supermicro/libiKVM32.so new file mode 100644 index 0000000..96b90d7 Binary files /dev/null and b/supermicro/libiKVM32.so differ diff --git a/supermicro/libiKVM64.so b/supermicro/libiKVM64.so new file mode 100644 index 0000000..caf5c54 Binary files /dev/null and b/supermicro/libiKVM64.so differ diff --git a/supermicro/orig/iKVM__V1.69.25.0x0.jar.pack.gz b/supermicro/orig/iKVM__V1.69.25.0x0.jar.pack.gz new file mode 100644 index 0000000..a375e2e Binary files /dev/null and b/supermicro/orig/iKVM__V1.69.25.0x0.jar.pack.gz differ diff --git a/supermicro/orig/liblinux_x86_64__V1.0.8.jar.pack.gz b/supermicro/orig/liblinux_x86_64__V1.0.8.jar.pack.gz new file mode 100644 index 0000000..6255470 Binary files /dev/null and b/supermicro/orig/liblinux_x86_64__V1.0.8.jar.pack.gz differ diff --git a/supermicro/orig/liblinux_x86__V1.0.8.jar.pack.gz b/supermicro/orig/liblinux_x86__V1.0.8.jar.pack.gz new file mode 100644 index 0000000..13586e5 Binary files /dev/null and b/supermicro/orig/liblinux_x86__V1.0.8.jar.pack.gz differ diff --git a/supermicro/orig/libwin_x86_64__V1.0.8.jar.pack.gz b/supermicro/orig/libwin_x86_64__V1.0.8.jar.pack.gz new file mode 100644 index 0000000..a5c1c10 Binary files /dev/null and b/supermicro/orig/libwin_x86_64__V1.0.8.jar.pack.gz differ diff --git a/supermicro/orig/libwin_x86__V1.0.8.jar.pack.gz b/supermicro/orig/libwin_x86__V1.0.8.jar.pack.gz new file mode 100644 index 0000000..6a6ed40 Binary files /dev/null and b/supermicro/orig/libwin_x86__V1.0.8.jar.pack.gz differ -- cgit v1.2.3