2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCfsp;
|
|
|
|
use strict;
|
2008-01-11 16:53:54 +00:00
|
|
|
use Getopt::Long;
|
2007-11-16 19:47:00 +00:00
|
|
|
use LWP;
|
|
|
|
use HTTP::Cookies;
|
2007-12-11 20:35:07 +00:00
|
|
|
use HTML::Form;
|
2008-01-18 16:27:05 +00:00
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
2008-04-12 14:53:11 +00:00
|
|
|
use xCAT::Usage;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-05-02 19:46:29 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################
|
|
|
|
# Globals
|
|
|
|
##########################################
|
|
|
|
my %cmds = (
|
|
|
|
rpower => {
|
2008-03-13 18:10:30 +00:00
|
|
|
state => ["Power On/Off System", \&state],
|
|
|
|
powercmd => ["Power On/Off System", \&powercmd],
|
|
|
|
powercmd_boot => ["Power On/Off System", \&boot],
|
|
|
|
reset => ["System Reboot", \&reset] },
|
2007-11-16 19:47:00 +00:00
|
|
|
reventlog => {
|
2008-03-13 18:10:30 +00:00
|
|
|
all => ["Error/Event Logs", \&all],
|
|
|
|
all_clear => ["Error/Event Logs", \&all_clear],
|
|
|
|
entries => ["Error/Event Logs", \&entries],
|
|
|
|
clear => ["Error/Event Logs", \&clear] },
|
2008-04-01 14:58:04 +00:00
|
|
|
rspconfig => {
|
2008-03-13 18:10:30 +00:00
|
|
|
memdecfg => ["Memory Deconfiguration", \&memdecfg],
|
|
|
|
decfg => ["Deconfiguration Policies", \&decfg],
|
|
|
|
procdecfg => ["Processor Deconfiguration", \&procdecfg],
|
|
|
|
iocap => ["I/O Adapter Enlarged Capacity", \&iocap],
|
|
|
|
time => ["Time Of Day", \&time],
|
|
|
|
date => ["Time Of Day", \&date],
|
|
|
|
autopower => ["Auto Power Restart", \&autopower],
|
|
|
|
sysdump => ["System Dump", \&sysdump],
|
2009-01-19 08:58:29 +00:00
|
|
|
spdump => ["Service Processor Dump", \&spdump],
|
|
|
|
network => ["Network Configuration", \&netcfg]},
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# FSP command handler through HTTP interface
|
|
|
|
##########################################################################
|
|
|
|
sub handler {
|
|
|
|
|
|
|
|
my $server = shift;
|
|
|
|
my $request = shift;
|
2007-12-06 19:09:54 +00:00
|
|
|
my $exp = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-04-21 12:43:54 +00:00
|
|
|
#####################################
|
|
|
|
# Convert command to correct format
|
|
|
|
#####################################
|
|
|
|
if ( ref($request->{method}) ne "HASH" ) {
|
|
|
|
$request->{method} = [{$request->{method}=>undef}];
|
|
|
|
}
|
|
|
|
#####################################
|
2007-11-16 19:47:00 +00:00
|
|
|
# Process FSP command
|
2008-04-21 12:43:54 +00:00
|
|
|
#####################################
|
|
|
|
my @outhash;
|
2007-12-06 19:09:54 +00:00
|
|
|
my $result = process_cmd( $exp, $request );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-04-21 12:43:54 +00:00
|
|
|
foreach ( @$result ) {
|
|
|
|
my %output;
|
|
|
|
$output{node}->[0]->{name}->[0] = $server;
|
|
|
|
$output{node}->[0]->{data}->[0]->{contents}->[0] = @$_[1];
|
|
|
|
$output{errorcode} = @$_[0];
|
|
|
|
push @outhash, \%output;
|
|
|
|
}
|
|
|
|
#####################################
|
2007-11-16 19:47:00 +00:00
|
|
|
# Disconnect from FSP
|
2008-04-21 12:43:54 +00:00
|
|
|
#####################################
|
2007-12-06 19:09:54 +00:00
|
|
|
xCAT::PPCfsp::disconnect( $exp );
|
2008-04-21 12:43:54 +00:00
|
|
|
return( \@outhash );
|
2008-01-14 15:05:14 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Logon through remote FSP HTTP-interface
|
|
|
|
##########################################################################
|
|
|
|
sub connect {
|
|
|
|
|
2008-05-02 18:10:25 +00:00
|
|
|
my $req = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $server = shift;
|
2008-05-02 18:10:25 +00:00
|
|
|
my $verbose = $req->{verbose};
|
|
|
|
my $timeout = $req->{fsptimeout};
|
2007-12-06 19:09:54 +00:00
|
|
|
my $lwp_log;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-05-02 18:10:25 +00:00
|
|
|
##################################
|
|
|
|
# Use timeout from site table
|
|
|
|
##################################
|
|
|
|
if ( !$timeout ) {
|
|
|
|
$timeout = 30;
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Get userid/password
|
|
|
|
##################################
|
2008-05-02 19:46:29 +00:00
|
|
|
my $cred = $req->{$server}{cred};
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-12-06 19:09:54 +00:00
|
|
|
##################################
|
|
|
|
# Redirect STDERR to variable
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
close STDERR;
|
|
|
|
if ( !open( STDERR, '>', \$lwp_log )) {
|
|
|
|
return( "Unable to redirect STDERR: $!" );
|
|
|
|
}
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Turn on tracing
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
LWP::Debug::level( '+' );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Create cookie
|
|
|
|
##################################
|
|
|
|
my $cookie = HTTP::Cookies->new();
|
|
|
|
$cookie->set_cookie( 0,'asm_session','0','cgi-bin','','443',0,0,3600,0 );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Create UserAgent
|
|
|
|
##################################
|
|
|
|
my $ua = LWP::UserAgent->new();
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Set options
|
|
|
|
##################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=2";
|
|
|
|
$ua->cookie_jar( $cookie );
|
2008-05-02 18:10:25 +00:00
|
|
|
$ua->timeout( $timeout );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Submit logon
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( $url,
|
2008-05-02 19:46:29 +00:00
|
|
|
[ user => @$cred[0],
|
|
|
|
password => @$cred[1],
|
2007-11-16 19:47:00 +00:00
|
|
|
lang => "0",
|
2008-03-13 18:10:30 +00:00
|
|
|
submit => "Log in" ]
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Logon failed
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log.$res->status_line );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# To minimize number of GET/POSTs,
|
|
|
|
# if we successfully logon, we should
|
|
|
|
# get back a valid cookie:
|
|
|
|
# Set-Cookie: asm_session=3038839768778613290
|
|
|
|
#
|
|
|
|
##################################
|
|
|
|
|
|
|
|
if ( $res->as_string =~ /Set-Cookie: asm_session=(\d+)/ ) {
|
|
|
|
##############################
|
|
|
|
# Successful logon....
|
|
|
|
# Return:
|
|
|
|
# UserAgent
|
|
|
|
# Server hostname
|
|
|
|
# UserId
|
2007-12-06 19:09:54 +00:00
|
|
|
# Redirected STDERR/STDOUT
|
2007-11-16 19:47:00 +00:00
|
|
|
##############################
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $ua,
|
2007-11-16 19:47:00 +00:00
|
|
|
$server,
|
2008-05-02 19:46:29 +00:00
|
|
|
@$cred[0],
|
2007-12-06 19:09:54 +00:00
|
|
|
\$lwp_log );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Logon error
|
|
|
|
##############################
|
|
|
|
$res = $ua->get( $url );
|
|
|
|
|
|
|
|
if ( !$res->is_success() ) {
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log.$res->status_line );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Check for specific failures
|
|
|
|
##############################
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content =~ /(Invalid user ID or password|Too many users)/i ) {
|
2008-01-14 15:05:14 +00:00
|
|
|
return( $lwp_log.$1 );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2007-12-06 19:09:54 +00:00
|
|
|
return( $lwp_log."Logon failure" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Logoff through remote FSP HTTP-interface
|
|
|
|
##########################################################################
|
|
|
|
sub disconnect {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $uid = @$exp[2];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# POST Logoff
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi?form=1",
|
|
|
|
[ submit => "Log out" ]
|
|
|
|
);
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Logoff failed
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,"Success"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Execute FSP command
|
|
|
|
##########################################################################
|
|
|
|
sub process_cmd {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $uid = @$exp[2];
|
|
|
|
my $command = $request->{command};
|
2008-04-21 12:43:54 +00:00
|
|
|
my $methods = $request->{method};
|
2007-11-16 19:47:00 +00:00
|
|
|
my %menu = ();
|
2008-04-21 12:43:54 +00:00
|
|
|
my @result;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# We have to expand the main
|
|
|
|
# menu since unfortunately, the
|
|
|
|
# the forms numbers are not the
|
|
|
|
# same across FSP models/firmware
|
|
|
|
# versions.
|
|
|
|
##################################
|
2008-01-11 16:53:54 +00:00
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => "2",
|
|
|
|
e => "1" ]
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Build hash of expanded menus
|
|
|
|
##################################
|
|
|
|
foreach ( split /\n/, $res->content ) {
|
|
|
|
if ( /form=(\d+).*window.status='(.*)'/ ) {
|
|
|
|
$menu{$2} = $1;
|
|
|
|
}
|
|
|
|
}
|
2008-04-21 12:43:54 +00:00
|
|
|
foreach ( keys %$methods ) {
|
|
|
|
##############################
|
|
|
|
# Get form id
|
|
|
|
##############################
|
|
|
|
my $form = $menu{$cmds{$command}{$_}[0]};
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"Cannot find '$cmds{$command}{$_}[0]' menu"] );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Run command
|
|
|
|
##################################
|
|
|
|
my $res = $cmds{$command}{$_}[1]($exp, $request, $form, \%menu);
|
|
|
|
push @result, $res
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-04-21 12:43:54 +00:00
|
|
|
return( \@result );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns current power state
|
|
|
|
##########################################################################
|
|
|
|
sub state {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get current power status
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get power state
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /Current system power state: (.*)<br>/) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,$1] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"unknown"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Powers FSP On/Off
|
|
|
|
##########################################################################
|
2008-03-13 18:10:30 +00:00
|
|
|
sub powercmd {
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
|
|
|
my $op = $request->{op};
|
2007-11-16 19:47:00 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
# Get Power On/Off System URL
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
##################################
|
|
|
|
# Get current power state
|
|
|
|
##################################
|
|
|
|
if ( $res->content !~ /Current system power state: (.*)<br>/) {
|
|
|
|
return( [RC_ERROR,"Unable to determine current power state"] );
|
|
|
|
}
|
|
|
|
my $state = $1;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-03-13 18:10:30 +00:00
|
|
|
##################################
|
|
|
|
# Already in that state
|
|
|
|
##################################
|
|
|
|
if ( $op =~ /^$state$/i ) {
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get "Power On/Off System" form
|
|
|
|
##################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"'Power On/Off System' form not found"] );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get "Save and Submit" button
|
|
|
|
##################################
|
|
|
|
my $button = ($op eq "on") ? "on" : "of";
|
|
|
|
my @inputs = $form->inputs();
|
|
|
|
|
|
|
|
if ( !grep( $_->{name} eq $button, @inputs )) {
|
|
|
|
return( [RC_ERROR,"Unable to power $op from state: $state"] );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Send command
|
|
|
|
##################################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $data = $form->click( $button );
|
|
|
|
$res = $ua->request( $data );
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /(not allowed.*\.)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Success
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /(Operation completed successfully)/ ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,"Success"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"Unknown error"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Reset FSP
|
|
|
|
##########################################################################
|
|
|
|
sub reset {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Send Reset command
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => $id,
|
|
|
|
submit => "Continue" ]
|
2007-11-16 19:47:00 +00:00
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success()) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content =~ /(This feature is only available.*)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Success
|
|
|
|
##################################
|
|
|
|
if ( $res->content =~ /(Operation completed successfully)/ ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,"Success"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"Unknown error"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Boots FSP (Off->On, On->Reset)
|
|
|
|
##########################################################################
|
|
|
|
sub boot {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $menu = shift;
|
|
|
|
my $command = $request->{command};
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Check current power state
|
|
|
|
##################################
|
|
|
|
my $state = xCAT::PPCfsp::state(
|
|
|
|
$exp,
|
|
|
|
$request,
|
|
|
|
$menu->{$cmds{$command}{state}[0]},
|
|
|
|
$menu );
|
2008-03-13 18:10:30 +00:00
|
|
|
my $Rc = shift(@$state);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-03-13 18:10:30 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [$Rc,@$state[0]] );
|
|
|
|
}
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( @$state[0] !~ /^(on|off)$/i ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"Unable to boot in state: '@$state[0]'"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get command
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
$request->{op} = "on";
|
|
|
|
my $method = ( $state =~ /^on$/i ) ? "reset" : "powercmd";
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Get command form id
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
$id = $menu->{$cmds{$command}{$method}[0]};
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Run command
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $result = $cmds{$command}{$method}[1]( $exp, $request, $id );
|
2007-11-16 19:47:00 +00:00
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Clears Error/Event Logs
|
|
|
|
##########################################################################
|
|
|
|
sub clear {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
##################################
|
2007-12-11 20:35:07 +00:00
|
|
|
# Get Error/Event Logs URL
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
2007-12-11 20:35:07 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
2007-12-11 20:35:07 +00:00
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-12-11 20:35:07 +00:00
|
|
|
}
|
2008-01-25 15:57:14 +00:00
|
|
|
##################################
|
|
|
|
# Clear all error/event log entries:
|
|
|
|
# Are you sure? (OK/Cancel)
|
|
|
|
##################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
2008-03-13 18:10:30 +00:00
|
|
|
|
2007-12-11 20:35:07 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !defined( $form )) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"'Error/Event Logs' form not found"] );
|
2007-12-11 20:35:07 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Send Clear to JavaScript
|
|
|
|
##################################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $data = $form->click( 'clear' );
|
|
|
|
$res = $ua->request( $data );
|
2007-12-11 20:35:07 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,"Success"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets the number of Error/Event Logs entries specified
|
|
|
|
##########################################################################
|
|
|
|
sub entries {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $opt = $request->{opt};
|
2008-03-13 18:10:30 +00:00
|
|
|
my $count = (exists($opt->{e})) ? $opt->{e} : -1;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $result;
|
|
|
|
my $i = 1;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get log entries
|
|
|
|
##################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
my @entries = split /\n/, $res->content;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Prepend header
|
|
|
|
##################################
|
|
|
|
$result = (@entries) ?
|
2008-01-18 16:27:05 +00:00
|
|
|
"\n#Log ID Time Failing subsystem Severity SRC\n" :
|
2007-11-16 19:47:00 +00:00
|
|
|
"No entries";
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Parse log entries
|
|
|
|
##################################
|
|
|
|
foreach ( @entries ) {
|
2009-03-03 02:09:21 +00:00
|
|
|
if ( /tabindex=(\d+)><\/td><td>(.*)<\/td><\/tr>/ ){
|
|
|
|
my $values = $2;
|
2007-11-16 19:47:00 +00:00
|
|
|
$values =~ s/<\/td><td>/ /g;
|
|
|
|
$result.= "$values\n";
|
|
|
|
|
|
|
|
if ( $i++ == $count ) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,$result] );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-18 16:27:05 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system time of day
|
|
|
|
##########################################################################
|
|
|
|
sub time {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2008-01-18 16:27:05 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $value = $request->{method}{time};
|
2008-01-18 16:27:05 +00:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $result = xCAT::PPCfsp::timeofday( $exp, $request, $id );
|
2008-01-18 16:27:05 +00:00
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Return error
|
|
|
|
##############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [$Rc,"Time: @$result[0]"] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Get time
|
|
|
|
##############################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $value )) {
|
2008-01-18 16:27:05 +00:00
|
|
|
@$result[0] =~ /(\d+) (\d+) (\d+) $/;
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [SUCCESS,sprintf( "Time: %02d:%02d:%02d UTC",$1,$2,$3 )] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Set time
|
|
|
|
##############################
|
|
|
|
my @t = split / /, @$result[0];
|
2008-04-21 12:43:54 +00:00
|
|
|
my @new = split /:/, $value;
|
2008-01-18 16:27:05 +00:00
|
|
|
splice( @t,3,3,@new );
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $time = xCAT::PPCfsp::timeofday( $exp, $request, $id, \@t );
|
|
|
|
$Rc = shift(@$time);
|
|
|
|
return( [$Rc,"Time: @$time[0]"] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system date
|
|
|
|
##########################################################################
|
|
|
|
sub date {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2008-01-18 16:27:05 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $value = $request->{method}{date};
|
2008-01-18 16:27:05 +00:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $result = xCAT::PPCfsp::timeofday( $exp, $request, $id );
|
2008-01-18 16:27:05 +00:00
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Return error
|
|
|
|
##############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [$Rc,"Date: @$result[0]"] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Get date
|
|
|
|
##############################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $value )) {
|
2008-01-18 16:27:05 +00:00
|
|
|
@$result[0] =~ /^(\d+) (\d+) (\d+)/;
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [SUCCESS,sprintf( "Date: %02d-%02d-%4d",$1,$2,$3 )] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Set date
|
|
|
|
##############################
|
|
|
|
my @t = split / /, @$result[0];
|
2008-04-21 12:43:54 +00:00
|
|
|
my @new = split /-/, $value;
|
2008-01-18 16:27:05 +00:00
|
|
|
splice( @t,0,3,@new );
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Send command
|
|
|
|
##############################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $date = xCAT::PPCfsp::timeofday( $exp, $request, $id, \@t );
|
|
|
|
$Rc = shift(@$date);
|
|
|
|
return( [$Rc,"Date: @$date[0]"] );
|
2008-01-18 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets system time/date
|
|
|
|
##########################################################################
|
2008-03-13 18:10:30 +00:00
|
|
|
sub timeofday {
|
2008-01-18 16:27:05 +00:00
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2008-01-18 16:27:05 +00:00
|
|
|
my $d = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get time/date
|
|
|
|
######################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
2008-01-18 16:27:05 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /(only when the system is powered off)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
##################################
|
|
|
|
# Get "Power On/Off System" form
|
|
|
|
##################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !defined( $form )) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [RC_ERROR,"'Time Of Day' form not found"] );
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
2008-01-18 16:27:05 +00:00
|
|
|
######################################
|
|
|
|
# Get time/date fields
|
|
|
|
######################################
|
|
|
|
my $result;
|
2008-03-13 18:10:30 +00:00
|
|
|
my @option = qw(omo od oy oh omi os);
|
|
|
|
|
|
|
|
foreach ( @option ) {
|
|
|
|
if ( $res->content !~ /name='$_' value='(\d+)'/ ) {
|
2008-01-18 16:27:05 +00:00
|
|
|
return( [RC_ERROR,"Error getting time of day"] );
|
|
|
|
}
|
|
|
|
$result.= "$1 ";
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Return time/date
|
|
|
|
######################################
|
|
|
|
if ( !defined( $d )) {
|
|
|
|
return( [SUCCESS,$result] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Set time/date
|
|
|
|
######################################
|
2008-06-02 13:31:34 +00:00
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => $id,
|
2008-01-18 16:27:05 +00:00
|
|
|
mo => @$d[0],
|
|
|
|
d => @$d[1],
|
|
|
|
y => @$d[2],
|
|
|
|
h => @$d[3],
|
|
|
|
mi => @$d[4],
|
|
|
|
s => @$d[5],
|
|
|
|
submit => "Save settings" ]
|
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content =~ /(not allowed.*\.|Invalid entry)/ ) {
|
2008-01-18 16:27:05 +00:00
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
|
2008-01-14 16:38:44 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets I/O Adapter Enlarged Capacity
|
2008-01-14 15:05:14 +00:00
|
|
|
##########################################################################
|
2008-01-14 16:38:44 +00:00
|
|
|
sub iocap {
|
2008-04-21 12:43:54 +00:00
|
|
|
|
|
|
|
my $result = option( @_,"iocap" );
|
|
|
|
@$result[1] = "iocap: @$result[1]";
|
|
|
|
return( $result );
|
2008-01-14 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-14 15:05:14 +00:00
|
|
|
##########################################################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Gets/Sets Auto Power Restart
|
|
|
|
##########################################################
|
2008-01-14 15:05:14 +00:00
|
|
|
sub autopower {
|
2008-04-21 12:43:54 +00:00
|
|
|
|
|
|
|
my $result = option( @_,"autopower" );
|
|
|
|
@$result[1] = "autopower: @$result[1]";
|
|
|
|
return( $result );
|
2008-01-14 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets options
|
|
|
|
##########################################################################
|
|
|
|
sub option {
|
2008-01-14 15:05:14 +00:00
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-04-21 12:43:54 +00:00
|
|
|
my $id = shift;
|
2008-01-14 15:05:14 +00:00
|
|
|
my $menu = shift;
|
2008-04-21 12:43:54 +00:00
|
|
|
my $command = shift;
|
2008-01-14 15:05:14 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $option = ($command =~ /^iocap$/) ? "pe" : "apor";
|
|
|
|
my $value = $request->{method}{$command};
|
2008-01-14 15:05:14 +00:00
|
|
|
|
|
|
|
######################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Get option URL
|
2008-01-14 15:05:14 +00:00
|
|
|
######################################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $value )) {
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
2008-01-14 15:05:14 +00:00
|
|
|
|
|
|
|
##################################
|
2008-01-18 16:27:05 +00:00
|
|
|
# Return errors
|
2008-01-14 15:05:14 +00:00
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content !~ /selected value='\d+'>(\w+)</ ) {
|
|
|
|
return( [RC_ERROR,"Unknown"] );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,$1] );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
|
|
|
######################################
|
2008-01-14 16:38:44 +00:00
|
|
|
# Set option
|
2008-01-14 15:05:14 +00:00
|
|
|
######################################
|
|
|
|
my $res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => $id,
|
2008-04-21 12:43:54 +00:00
|
|
|
$option => ($value =~ /^disable$/i) ? "0" : "1",
|
2008-03-13 18:10:30 +00:00
|
|
|
submit => "Save settings" ]
|
2008-01-14 15:05:14 +00:00
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( $res->content !~ /Operation completed successfully/i ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"Error setting option"] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets Memory Deconfiguration
|
|
|
|
##########################################################################
|
|
|
|
sub memdecfg {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $values = $request->{method}{memdecfg};
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get settings
|
|
|
|
##################################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $values )) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( readdecfg( $exp, $request, $id ));
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Set settings
|
|
|
|
##################################
|
2008-04-21 12:43:54 +00:00
|
|
|
$values =~ /^(configure|deconfigure):(\d+):(unit|bank):(all|[\d,]+)$/i;
|
|
|
|
return( writedecfg( $exp, $request, $id, $1, $2, $3, $4 ));
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/Sets Processor Deconfiguration
|
|
|
|
##########################################################################
|
|
|
|
sub procdecfg {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $values = $request->{method}{procdecfg};
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get settings
|
|
|
|
##################################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $values )) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( readdecfg( $exp, $request, $id ));
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Set settings
|
|
|
|
##################################
|
2008-04-21 12:43:54 +00:00
|
|
|
$values =~ /^(configure|deconfigure):(\d+):(all|[\d,]+)$/i;
|
|
|
|
return( writedecfg( $exp, $request, $id, $1, $2, "Processor ID",$3 ));
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Sets Deconfiguration settings
|
|
|
|
##########################################################################
|
|
|
|
sub writedecfg {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-04-21 12:43:54 +00:00
|
|
|
my $formid = shift;
|
|
|
|
my $state = shift;
|
|
|
|
my $unit = shift;
|
|
|
|
my $type = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Command-line parameter specified
|
|
|
|
######################################
|
2008-04-21 12:43:54 +00:00
|
|
|
my @ids = split /,/, $id;
|
2008-03-17 13:34:20 +00:00
|
|
|
my $select = ($state =~ /^configure$/i) ? 0 : 1;
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Deconfiguration URL
|
|
|
|
######################################
|
2008-04-21 12:43:54 +00:00
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$formid";
|
2008-03-13 18:10:30 +00:00
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Find unit specified by user
|
|
|
|
######################################
|
|
|
|
my $html = $res->content;
|
|
|
|
my $value;
|
|
|
|
|
|
|
|
while ( $html =~
|
|
|
|
s/<input type=radio name=(\w+) value=(\w+)[^>]+><\/td><td>(\d+)<// ) {
|
|
|
|
if ( $unit eq $3 ) {
|
|
|
|
$value = $2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !defined( $value )) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [RC_ERROR,"Processing unit=$unit not found"] );
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get current settings
|
|
|
|
######################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
my @inputs = $form->inputs();
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"'Deconfiguration' form not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Find radio button
|
|
|
|
######################################
|
|
|
|
my ($radio) = grep($_->{type} eq "radio", @inputs );
|
|
|
|
if ( !defined( $radio )) {
|
|
|
|
return( [RC_ERROR,"Radio button not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Select radio button
|
|
|
|
######################################
|
|
|
|
$radio->value( $value );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Send command
|
|
|
|
######################################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $data = $form->click( "submit" );
|
|
|
|
$res = $ua->request( $data );
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get current settings
|
|
|
|
######################################
|
|
|
|
$form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
@inputs = $form->inputs();
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"'Deconfiguration' form not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get options
|
|
|
|
######################################
|
|
|
|
my %options = ();
|
|
|
|
my %key = ();
|
|
|
|
my $setall = 0;
|
|
|
|
|
|
|
|
foreach ( @inputs ) {
|
|
|
|
if ( $_->type eq "option" ) {
|
|
|
|
push @{$options{$_->name}}, $_->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my @units = split /<thead align=left><tr><th>/, $res->content;
|
|
|
|
shift(@units);
|
2008-06-02 13:31:34 +00:00
|
|
|
$html = undef;
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Break into unit types
|
|
|
|
######################################
|
|
|
|
foreach ( @units ) {
|
|
|
|
/([\w\s]+)<\/th><th>/;
|
|
|
|
if ( $1 =~ /$type/i ) {
|
|
|
|
$html = $_;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Look for unit type
|
|
|
|
######################################
|
|
|
|
if ( !defined( $html )) {
|
|
|
|
return( [RC_ERROR,"unit=$unit '$type' not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Set all IDs
|
|
|
|
######################################
|
|
|
|
if ( $ids[0] eq "all" ) {
|
|
|
|
@ids = ();
|
|
|
|
$setall = 1;
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Associate 'option' name with ID
|
|
|
|
######################################
|
|
|
|
foreach ( keys %options ) {
|
|
|
|
if ( $html =~ /\n<tr><td>(\d+)<\/td><td>.*name='$_'/ ) {
|
|
|
|
if ( $setall ) {
|
|
|
|
push @ids, $1;
|
|
|
|
}
|
|
|
|
push @{$options{$_}}, $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Check if each specified ID exist
|
|
|
|
######################################
|
|
|
|
foreach ( @ids ) {
|
|
|
|
foreach my $name ( keys %options ) {
|
|
|
|
my $id = @{$options{$name}}[1];
|
|
|
|
|
|
|
|
if ( $_ eq $id ) {
|
|
|
|
my $value = @{$options{$name}}[0];
|
|
|
|
$key{$id} = [$value,$name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Check if ID exists
|
|
|
|
######################################
|
|
|
|
foreach ( @ids ) {
|
|
|
|
if ( !exists( $key{$_} )) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [RC_ERROR,"Processing unit=$unit $type=$_ not found"] );
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
my $value = @{$key{$_}}[0];
|
|
|
|
if ( $value == $select ) {
|
|
|
|
delete $key{$_};
|
|
|
|
}
|
2008-01-14 15:05:14 +00:00
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
######################################
|
|
|
|
# Check in already in that state
|
|
|
|
######################################
|
|
|
|
if ( !scalar( keys %key )) {
|
2008-04-21 12:43:54 +00:00
|
|
|
return( [RC_ERROR,"All $type(s) specified already in '$state' state"]);
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Make changes to form
|
|
|
|
######################################
|
|
|
|
foreach ( keys %key ) {
|
|
|
|
my $name = @{$key{$_}}[1];
|
|
|
|
my ($button) = grep($_->{name} eq $name, @inputs );
|
|
|
|
if ( !defined( $button )) {
|
|
|
|
return( [RC_ERROR,"Option=$name not found"] );
|
|
|
|
}
|
|
|
|
$button->value( $select );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Send command
|
|
|
|
##################################
|
2008-06-02 13:31:34 +00:00
|
|
|
$data = $form->click( "submit" );
|
|
|
|
$res = $ua->request( $data );
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
if ( $res->content =~ /\n(.*Operation not allowed.*\.)/ ) {
|
|
|
|
my $result = $1;
|
|
|
|
$result =~ s/<br><br>/\n/g;
|
|
|
|
return( [RC_ERROR,$result] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets Deconfiguration settings
|
|
|
|
##########################################################################
|
|
|
|
sub readdecfg {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
my $result = "\n";
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Deconfiguration URL
|
|
|
|
######################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$id";
|
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get current settings
|
|
|
|
######################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
my @inputs = $form->inputs();
|
|
|
|
my $html = $res->content;
|
|
|
|
my $unit;
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"'Deconfiguration' form not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Find radio button
|
|
|
|
######################################
|
|
|
|
my ($radio) = grep($_->{type} eq "radio", @inputs );
|
|
|
|
if ( !defined( $radio )) {
|
|
|
|
return( [RC_ERROR,"Radio button not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Find unit identifier
|
|
|
|
######################################
|
|
|
|
if ( $html =~ /<thead align=left><tr><th><\/th><th>([\w\s]+)</ ) {
|
|
|
|
$unit = $1;
|
|
|
|
}
|
|
|
|
foreach ( @{$radio->{menu}} ) {
|
|
|
|
##################################
|
|
|
|
# Select radio button
|
|
|
|
##################################
|
2009-01-05 09:51:47 +00:00
|
|
|
my $value = ( ref($_) eq 'HASH' ) ? $_->{value} : $_;
|
2008-03-13 18:10:30 +00:00
|
|
|
$radio->value( $value );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Send command
|
|
|
|
##################################
|
|
|
|
my $request = $form->click( "submit" );
|
|
|
|
$res = $ua->request( $request );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
$html = $res->content;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Find unit identifier
|
|
|
|
##################################
|
|
|
|
if ( $html =~ /<p>([\w\s:]+)</ ) {
|
|
|
|
$result.= "$1\n";
|
|
|
|
}
|
|
|
|
my @group = split /<thead align=left><tr><th>/, $res->content;
|
|
|
|
shift(@group);
|
|
|
|
|
|
|
|
foreach ( @group ) {
|
|
|
|
my @maxlen = ();
|
|
|
|
my @values = ();
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Entry heading
|
|
|
|
##############################
|
|
|
|
/(.*)<\/th><\/tr><\/thead>/;
|
|
|
|
my @heading = split /<\/th><th>/, $1;
|
|
|
|
pop(@heading);
|
|
|
|
pop(@heading);
|
|
|
|
|
|
|
|
foreach ( @heading ) {
|
|
|
|
push @maxlen, length($_);
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Entry values
|
|
|
|
##############################
|
|
|
|
foreach ( split /\n/ ) {
|
|
|
|
if ( s/^<tr><td>// ) {
|
|
|
|
s/<br>/ /g;
|
|
|
|
|
|
|
|
my $i = 0;
|
|
|
|
my @d = split /<\/td><td>/;
|
|
|
|
pop(@d);
|
|
|
|
pop(@d);
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Length formatting
|
|
|
|
######################
|
|
|
|
foreach ( @d ) {
|
|
|
|
if ( length($_) > $maxlen[$i] ) {
|
|
|
|
$maxlen[$i] = length($_);
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
push @values, [@d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Output header
|
|
|
|
##############################
|
|
|
|
my $i = 0;
|
|
|
|
foreach ( @heading ) {
|
|
|
|
my $format = sprintf( "%%-%ds",$maxlen[$i++]+2 );
|
|
|
|
$result.= sprintf( $format, $_ );
|
|
|
|
}
|
|
|
|
$result.= "\n";
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Output values
|
|
|
|
##############################
|
|
|
|
foreach ( @values ) {
|
|
|
|
$i = 0;
|
|
|
|
foreach ( @$_ ) {
|
|
|
|
my $format = sprintf( "%%-%ds",$maxlen[$i++]+2 );
|
|
|
|
$result.= sprintf( $format, $_ );
|
|
|
|
}
|
|
|
|
$result.= "\n";
|
|
|
|
}
|
|
|
|
$result.= "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( [SUCCESS,$result] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Gets/sets Deconfiguration Policies
|
|
|
|
##########################################################################
|
|
|
|
sub decfg {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-04-21 12:43:54 +00:00
|
|
|
my $value = $request->{method}{decfg};
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Deconfiguration Policy URL
|
|
|
|
######################################
|
|
|
|
my $res = $ua->get( "https://$server/cgi-bin/cgi?form=$id" );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
my %d = ();
|
|
|
|
my $len = 0;
|
|
|
|
my $i = 0;
|
|
|
|
my $html = $res->content;
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
while ( $html =~ s/<br>(.*:)\s+<// ) {
|
|
|
|
my $desc = $1;
|
|
|
|
my $value = "unknown";
|
|
|
|
my $name;
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Get values
|
|
|
|
##################################
|
|
|
|
if ( $html =~ s/selected value='\d+'>(\w+)<// ) {
|
|
|
|
$value = $1;
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get name
|
|
|
|
##################################
|
|
|
|
if ( $html =~ s/select name='(\w+)'// ) {
|
|
|
|
$name = $1;
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Save for formatting output
|
|
|
|
##################################
|
|
|
|
if ( length( $desc ) > $len ) {
|
|
|
|
$len = length( $desc );
|
|
|
|
}
|
|
|
|
$d{$desc} = [$value,$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Deconfiguration Policy
|
|
|
|
######################################
|
2008-04-21 12:43:54 +00:00
|
|
|
if ( !defined( $value )) {
|
|
|
|
my $format = sprintf( "\n%%-%ds %%s",$len );
|
2008-03-13 18:10:30 +00:00
|
|
|
foreach ( keys %d ) {
|
2008-04-21 12:43:54 +00:00
|
|
|
$result.= sprintf( $format,$_,$d{$_}[0] );
|
2008-03-13 18:10:30 +00:00
|
|
|
}
|
|
|
|
return( [SUCCESS,$result] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Set Deconfiguration Policy
|
|
|
|
######################################
|
2008-04-21 12:43:54 +00:00
|
|
|
my ($op,$names) = split /:/, $value;
|
|
|
|
my @policy = split /,/, $names;
|
2008-03-17 13:34:20 +00:00
|
|
|
my $state = ($op =~ /^enable$/i) ? 0 : 1;
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Check for duplicate policies
|
|
|
|
######################################
|
|
|
|
foreach my $name ( @policy ) {
|
|
|
|
if ( grep( /^$name$/, @policy ) > 1 ) {
|
|
|
|
return( [RC_ERROR,"Duplicate policy specified: $name"] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get Deconfiguration Policy form
|
|
|
|
######################################
|
|
|
|
my $form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !defined( $form )) {
|
|
|
|
return( [RC_ERROR,"'Deconfiguration Policies' form not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Get hidden inputs
|
|
|
|
######################################
|
|
|
|
my @inputs = $form->inputs();
|
|
|
|
|
|
|
|
my (@hidden) = grep( $_->{type} eq "hidden", @inputs );
|
2008-06-02 13:31:34 +00:00
|
|
|
if ( !@hidden ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"<input type='hidden'> not found"] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Check for invalid policies
|
|
|
|
######################################
|
|
|
|
foreach my $name ( @policy ) {
|
|
|
|
my @p = grep( $_->{value_name}=~/\b$name\b/i, @hidden );
|
|
|
|
|
|
|
|
if ( @p > 1 ) {
|
|
|
|
return( [RC_ERROR,"Ambiguous policy: $name"] );
|
|
|
|
} elsif ( !@p ) {
|
|
|
|
return( [RC_ERROR,"Invalid policy: $name"] );
|
|
|
|
}
|
|
|
|
my $value_name = $p[0]->{value_name};
|
|
|
|
$policy[$i++] = @{$d{$value_name}}[1];
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Select option
|
|
|
|
######################################
|
|
|
|
foreach my $name ( @policy ) {
|
|
|
|
my ($in) = grep( $_->{name} eq $name, @inputs );
|
|
|
|
$in->value( $state );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Send command
|
|
|
|
######################################
|
2008-06-02 13:31:34 +00:00
|
|
|
my $data = $form->click( "submit" );
|
|
|
|
$res = $ua->request( $data );
|
2008-03-13 18:10:30 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Performs a System Dump
|
|
|
|
##########################################################################
|
|
|
|
sub sysdump {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Dump URL
|
|
|
|
######################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$id";
|
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Possible errors:
|
|
|
|
# not allowed when a dump of this type exists.
|
|
|
|
# not allowed when system is powered off.
|
|
|
|
######################################
|
|
|
|
if ( $res->content =~ /(not allowed.*\.)/ ) {
|
|
|
|
return( [RC_ERROR,$1] );
|
|
|
|
}
|
|
|
|
my @d;
|
|
|
|
my $html = $res->content;
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get current dump settings
|
|
|
|
######################################
|
|
|
|
foreach ( my $i=0; $i<3; $i++ ) {
|
|
|
|
if ( $html !~ s/selected value='(\d+)'// ) {
|
|
|
|
return( [RC_ERROR,"Error getting dump settings"] );
|
|
|
|
}
|
|
|
|
push @d, $1;
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Send dump command
|
|
|
|
######################################
|
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[ form => $id,
|
|
|
|
policy => $d[0],
|
|
|
|
content => $d[1],
|
|
|
|
phyp => $d[2],
|
|
|
|
page => "1",
|
|
|
|
takedump => "Save settings and initiate dump" ]
|
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Continue ?
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
|
|
|
[ form => $id,
|
|
|
|
policy => $d[0],
|
|
|
|
content => $d[1],
|
|
|
|
phyp => $d[2],
|
|
|
|
page => "2",
|
|
|
|
takedump => "Save settings and initiate dump",
|
|
|
|
submit => "Continue"]
|
|
|
|
);
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
|
|
|
return( [SUCCESS,"Success"] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-11 16:53:54 +00:00
|
|
|
##########################################################################
|
|
|
|
# Performs a Service Processor Dump
|
|
|
|
##########################################################################
|
|
|
|
sub spdump {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
2008-03-13 18:10:30 +00:00
|
|
|
my $id = shift;
|
2008-01-11 16:53:54 +00:00
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
2008-03-13 18:10:30 +00:00
|
|
|
my $button = "Save settings and initiate dump";
|
2008-01-11 16:53:54 +00:00
|
|
|
my $dump_setting = 1;
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Get Dump URL
|
|
|
|
######################################
|
2008-03-13 18:10:30 +00:00
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$id";
|
2008-01-11 16:53:54 +00:00
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Return error
|
|
|
|
######################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Dump disabled - enable it
|
|
|
|
######################################
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content =~ /selected value='0'>Disabled/ ) {
|
2008-01-11 16:53:54 +00:00
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => $id,
|
2008-01-18 16:27:05 +00:00
|
|
|
bdmp => "1",
|
|
|
|
save => "Save settings" ]
|
2008-01-11 16:53:54 +00:00
|
|
|
);
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
if ( $res->content !~ /Operation completed successfully/ ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,"Error enabling dump setting"] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Get Dump URL again
|
|
|
|
##################################
|
|
|
|
$res = $ua->get( $url );
|
|
|
|
|
|
|
|
if ( !$res->is_success() ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Restore setting after dump
|
|
|
|
##################################
|
|
|
|
$dump_setting = 0;
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
if ( $res->content !~ /$button/ ) {
|
|
|
|
return( [RC_ERROR,"'$button' button not found"] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# We will lose conection after dump
|
|
|
|
######################################
|
|
|
|
$ua->timeout(5);
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Send dump command
|
|
|
|
######################################
|
|
|
|
$res = $ua->post( "https://$server/cgi-bin/cgi",
|
2008-03-13 18:10:30 +00:00
|
|
|
[ form => $id,
|
|
|
|
bdmp => $dump_setting,
|
|
|
|
dump => "Save settings and initiate dump" ]
|
2008-01-11 16:53:54 +00:00
|
|
|
);
|
2008-03-13 18:10:30 +00:00
|
|
|
######################################
|
|
|
|
# Will lose connection on success -500
|
|
|
|
######################################
|
2008-01-11 16:53:54 +00:00
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
if ( $res->code ne "500" ) {
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [RC_ERROR,$res->status_line] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
return( [SUCCESS,"Success"] );
|
2008-01-11 16:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets all Error/Event Logs entries
|
|
|
|
##########################################################################
|
|
|
|
sub all {
|
|
|
|
return( entries(@_) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 18:10:30 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets all Error/Event Logs entries then clears the logs
|
|
|
|
##########################################################################
|
|
|
|
sub all_clear {
|
|
|
|
|
|
|
|
my $result = entries( @_ );
|
|
|
|
clear( @_);
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets and set network configuration
|
|
|
|
##########################################################################
|
|
|
|
sub netcfg
|
|
|
|
{
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Parsing arg
|
|
|
|
######################################
|
|
|
|
my $set_config = 0;
|
|
|
|
my ($inc_name, $inc_ip, $inc_host, $inc_gateway, $inc_netmask) = ();
|
|
|
|
my $real_inc_name = undef;
|
|
|
|
if ( $request->{'method'}->{'network'})
|
|
|
|
{
|
|
|
|
$set_config = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $interfaces = undef;
|
|
|
|
my $form = undef;
|
|
|
|
|
|
|
|
my $res = get_netcfg( $exp, $request, $id, \$interfaces, \$form);
|
|
|
|
|
|
|
|
return $res if ( $res->[0] == RC_ERROR);
|
|
|
|
|
|
|
|
my $output = "";
|
|
|
|
#######################################
|
|
|
|
# Set configuration
|
|
|
|
#######################################
|
|
|
|
if ( $set_config)
|
|
|
|
{
|
|
|
|
return set_netcfg( $exp, $request, $interfaces, $form);
|
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Get configuration and format output
|
|
|
|
#######################################
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return format_netcfg( $interfaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-03-13 18:10:30 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
##########################################################################
|
|
|
|
# Gets network configuration
|
|
|
|
##########################################################################
|
|
|
|
sub get_netcfg
|
|
|
|
{
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $interfaces = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
my $server = @$exp[1];
|
|
|
|
######################################
|
|
|
|
# Get Network Configuration URL
|
|
|
|
######################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=$id";
|
|
|
|
my $res = $ua->get( $url );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( [RC_ERROR,$res->status_line] );
|
|
|
|
}
|
2007-12-06 19:09:54 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
##################################
|
|
|
|
# Get "Network Configuraiton" form
|
|
|
|
##################################
|
|
|
|
$$form = HTML::Form->parse( $res->content, $res->base );
|
2007-12-11 20:35:07 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
##################################
|
|
|
|
# Return error
|
|
|
|
##################################
|
|
|
|
if ( !defined( $$form )) {
|
|
|
|
return( [RC_ERROR,"'Network Configuration' form not found"] );
|
|
|
|
}
|
2008-03-17 13:34:20 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
##################################
|
|
|
|
# For some P6 machines
|
|
|
|
##################################
|
|
|
|
if ( $$form->find_input('ip', 'radio', 1))
|
|
|
|
{
|
|
|
|
my $ipv4Radio = $$form->find_input('ip', 'radio', 1);
|
|
|
|
if (!$ipv4Radio)
|
|
|
|
{
|
|
|
|
print "Cannot find IPv4 option\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
#$ipv4Radio->check();
|
|
|
|
|
|
|
|
my $data = $$form->click('submit');
|
|
|
|
$res = $ua->request( $data);
|
|
|
|
$$form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
if ( !defined( $$form )) {
|
|
|
|
return( [RC_ERROR,"'Network Configuration' form not found"] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Parse the form to get the inc input
|
|
|
|
#######################################
|
|
|
|
my $has_found_all = 0;
|
|
|
|
my $i = 0;
|
|
|
|
while ( not $has_found_all)
|
|
|
|
{
|
|
|
|
my $input = $$form->find_input( "interface$i", 'checkbox');
|
|
|
|
if ( ! $input)
|
|
|
|
{
|
|
|
|
$has_found_all = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$$interfaces->{"interface$i"}->{'selected'} = $input;
|
|
|
|
$$interfaces->{"interface$i"}->{'type'} = $$form->find_input("ip$i", 'option');
|
|
|
|
$$interfaces->{"interface$i"}->{'hostname'} = $$form->find_input("host$i", 'text');
|
|
|
|
$$interfaces->{"interface$i"}->{'ip'} = $$form->find_input("static_ip$i", 'text');
|
|
|
|
$$interfaces->{"interface$i"}->{'gateway'} = $$form->find_input("gateway$i", 'text');
|
|
|
|
$$interfaces->{"interface$i"}->{'netmask'} = $$form->find_input("subnet$i", 'text');
|
|
|
|
#we do not support dns yet, just in case of future support
|
|
|
|
$$interfaces->{"interface$i"}->{'dns0'} = $$form->find_input("dns0$i", 'text');
|
|
|
|
$$interfaces->{"interface$i"}->{'dns1'} = $$form->find_input("dns1$i", 'text');
|
|
|
|
$$interfaces->{"interface$i"}->{'dns2'} = $$form->find_input("dns2$i", 'text');
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ( [RC_ERROR,"Cannot find any network interface on $server"]) if ( ! $$interfaces);
|
|
|
|
|
|
|
|
return ( [SUCCESS, undef]);
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Set network configuration
|
|
|
|
##########################################################################
|
|
|
|
sub set_netcfg
|
|
|
|
{
|
|
|
|
my $exp = shift;
|
|
|
|
my $request = shift;
|
|
|
|
my $interfaces = shift;
|
|
|
|
my $form = shift;
|
|
|
|
my $ua = @$exp[0];
|
|
|
|
|
|
|
|
my $real_inc_name;
|
|
|
|
my ($inc_name, $inc_ip, $inc_host, $inc_gateway, $inc_netmask) = split /,/, $request->{'method'}->{'network'};
|
|
|
|
|
|
|
|
chomp ($inc_name, $inc_ip, $inc_host, $inc_gateway, $inc_netmask);
|
|
|
|
if ( $inc_name =~ /^eth(\d)$/)
|
|
|
|
{
|
|
|
|
$real_inc_name = "interface$1";
|
|
|
|
}
|
|
|
|
elsif ( $inc_name =~/(\d+)\.(\d+)\.(\d+)\.(\d+)/)
|
|
|
|
{
|
|
|
|
for my $inc (keys %$interfaces)
|
|
|
|
{
|
|
|
|
if ($interfaces->{ $inc}->{'ip'}->value() eq $inc_name)
|
|
|
|
{
|
|
|
|
$real_inc_name = $inc;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return( [RC_ERROR, "Incorrect network interface name $inc_name"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( [RC_ERROR,"Cannot find interface $inc_name"]) if ( ! exists ($$interfaces{ $real_inc_name}));
|
|
|
|
|
|
|
|
$interfaces->{ $real_inc_name}->{'selected'}->check();
|
|
|
|
|
|
|
|
if ( $interfaces->{ $real_inc_name}->{'type'})
|
|
|
|
{
|
|
|
|
$interfaces->{ $real_inc_name}->{'type'}->value('Static');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR,"Cannot set this interface to static type"]);
|
|
|
|
}
|
|
|
|
my @set_entries = ();
|
|
|
|
if ( $inc_ip )
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR,"Cannot set IP address to $inc_ip"]) if (! $interfaces->{ $real_inc_name}->{'ip'});
|
|
|
|
$interfaces->{ $real_inc_name}->{'ip'}->value( $inc_ip);
|
|
|
|
push @set_entries, 'IP address';
|
|
|
|
}
|
|
|
|
if ( $inc_host)
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR,"Cannot set hostname to $inc_host"]) if (! $interfaces->{ $real_inc_name}->{'hostname'});
|
|
|
|
$interfaces->{ $real_inc_name}->{'hostname'}->value( $inc_host);
|
|
|
|
push @set_entries, 'hostname';
|
|
|
|
}
|
|
|
|
if ( $inc_gateway)
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR,"Cannot set gateway to $inc_gateway"]) if (! $interfaces->{ $real_inc_name}->{'gateway'});
|
|
|
|
$interfaces->{ $real_inc_name}->{'gateway'}->value( $inc_gateway);
|
|
|
|
push @set_entries, 'gateway';
|
|
|
|
}
|
|
|
|
if ( $inc_netmask)
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR,"Cannot set netmask to $inc_netmask"]) if (! $interfaces->{ $real_inc_name}->{'netmask'});
|
|
|
|
$interfaces->{ $real_inc_name}->{'netmask'}->value( $inc_netmask);
|
|
|
|
push @set_entries, 'netmask';
|
|
|
|
}
|
2008-04-21 12:43:54 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
#Click "Continue" button
|
|
|
|
my $data = $form->click('save');
|
|
|
|
my $res = $ua->request( $data);
|
|
|
|
if (!$res->is_success())
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR, "Failed to set " . join ',', @set_entries]);
|
|
|
|
}
|
2008-05-02 18:10:25 +00:00
|
|
|
|
2009-01-19 08:58:29 +00:00
|
|
|
#Go to the confirm page
|
|
|
|
$form = HTML::Form->parse( $res->content, $res->base );
|
|
|
|
# $data = $form->click('submit');
|
|
|
|
$res = $ua->request( $data);
|
|
|
|
if ($res->is_success())
|
|
|
|
{
|
|
|
|
return ( [SUCCESS, "Success to set " . join ',', @set_entries]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ( [RC_ERROR, "Failed to set " . join ',', @set_entries]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Format the output of network configuration
|
|
|
|
##########################################################################
|
|
|
|
sub format_netcfg
|
|
|
|
{
|
|
|
|
my $interfaces = shift;
|
|
|
|
my $output = undef;
|
|
|
|
for my $inc ( sort keys %$interfaces)
|
|
|
|
{
|
|
|
|
#improve needed: need to make the output consistent to MM
|
|
|
|
$output .= "\n\t" . $inc . ":\n";
|
|
|
|
$output =~ s/interface(\d)/eth$1/;
|
|
|
|
# There are 2 possible value for $type,
|
|
|
|
# 1 means "Dynamic", 2 means "Static"
|
|
|
|
# Now to find the correct type name
|
|
|
|
my @possible_values = $interfaces->{$inc}->{'type'}->possible_values();
|
|
|
|
my @possible_names = $interfaces->{$inc}->{'type'}->value_names();
|
|
|
|
my %value_names = {};
|
|
|
|
for ( my $i = 0; $i < scalar( @possible_values); $i++)
|
|
|
|
{
|
|
|
|
$value_names{ @possible_values[$i]} = @possible_names[$i];
|
|
|
|
}
|
|
|
|
my $type = $interfaces->{$inc}->{'type'} ? $value_names{ $interfaces->{$inc}->{'type'}->value()} : undef;;
|
|
|
|
$type = "Static" if ( $type == 2);
|
|
|
|
my $ip = $interfaces->{$inc}->{'ip'} ? $interfaces->{$inc}->{'ip'}->value() : undef;
|
|
|
|
my $hostname = $interfaces->{$inc}->{'hostname'} ? $interfaces->{$inc}->{'hostname'}->value() : undef;
|
|
|
|
my $gateway = $interfaces->{$inc}->{'gateway'} ? $interfaces->{$inc}->{'gateway'}->value() : undef;
|
|
|
|
my $netmask = $interfaces->{$inc}->{'netmask'} ? $interfaces->{$inc}->{'netmask'}->value() : undef;
|
|
|
|
|
|
|
|
$output .= "\t\tIP Type: " . $type . "\n";
|
|
|
|
$output .= "\t\tIP Address: " . $ip . "\n";
|
|
|
|
$output .= "\t\tHostname: " . $hostname . "\n";
|
|
|
|
$output .= "\t\tGateway: " . $gateway . "\n";
|
|
|
|
$output .= "\t\tNetmask: " . $netmask . "\n";
|
|
|
|
}
|
|
|
|
return( [SUCCESS,$output] );
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
2008-06-02 13:31:34 +00:00
|
|
|
|