my $host;
my $poweronms=200;
my $poweroffms=4500;
+my $verbose = 0;
my @fw_vars = qw(ENABLE_LAN_AUTONEG ENABLE_LAN_100 ENABLE_LAN_FDUPLEX GATEWAY
IP_ADDRESS NETMASK TFTP_FIRMWARE_FILE TFTP_ADDR_FIRMWARE ENABLE_DHCP
}
sub logout {
- print "Logout\n";
+ print "Logout\n" if ($verbose);
my $request = HTTP::Request->new(GET => "http://${host}/cgi/logout");
$request->header(Cookie => "sid=$sid");
my $response = $ua->request($request);
my $oldval = _getprop($property)->{RESP}->{PROPLIST}->{PROP}->{VAL};
if ($value eq $oldval) {
- #print "${property} is already ${value}\n";
+ print "${property} is already ${value}\n" if ($verbose);
return;
}
if ($res->{RESP}->{RC} ne '0x0') {
print "Error setting ${property} to ${value}: ".$res->{RESP}->{RC}."\n";
} else {
- print "${property}: ${oldval} -> ${value}\n";
+ print "${property}: ${oldval} -> ${value}\n" if ($verbose);
}
}
setprop("SERVER_POWER_ON_MODE", sprintf("0x%x", $pmode));
setprop("SERVER_POWER_OFF_MODE", sprintf("0x%x", $pmode));
- print "${action}...\n";
+ print "${action}...\n" if ($verbose);
my $reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="serveraction"><ACT>'.$action.'</ACT></REQ></RMCSEQ>';
my $res = _req($reqstr);
}
sub powerup {
+ print "powerup\n" if ($verbose);
setprop("SERVER_POWER_ON_PULSE_MS", sprintf("0x%x", $poweronms));
setprop("SERVER_POWER_OFF_PULSE_MS", "0x0");
serveraction("powercycle");
}
sub powerdown {
+ print "powerdown\n" if ($verbose);
setprop("SERVER_POWER_ON_PULSE_MS", "0x0");
setprop("SERVER_POWER_OFF_PULSE_MS", sprintf("0x%x", $poweroffms));
serveraction("powercycle");
}
sub powercycle {
+ print "powercycle\n" if ($verbose);
setprop("SERVER_POWER_ON_PULSE_MS", sprintf("0x%x", $poweronms));
setprop("SERVER_POWER_OFF_PULSE_MS", sprintf("0x%x", $poweroffms));
serveraction("powercycle");
my $xmlin = XMLin($response->decoded_content);
die "Error getting Challenge: ".$xmlin->{RC} if ($xmlin->{RC} ne '0x0');
my $challenge = $xmlin->{CHALLENGE};
- print "Challenge: ${challenge}\n";
+ print "Challenge: ${challenge}\n" if ($verbose);
$sid = $response->headers->header('Set-Cookie');
die "No SessionID!" if (!defined($sid));
chomp($sid);
$sid =~ s/.*sid=(.*);.*/$1/;
- print "SID: ${sid}\n";
+ print "SID: ${sid}\n" if ($verbose);
my $login_hash = _hash($pass, $challenge);
- print "Hash: ${login_hash}\n";
+ print "Hash: ${login_hash}\n" if ($verbose);
my $request = HTTP::Request->new(GET => "http://${host}/cgi/login?user=${user}&hash=${login_hash}");
$request->header(Cookie => "sid=$sid");
}
close(INIFILE);
-$host = ${$Config{$sections[0]}}{"host"};
-$poweronms = ${$Config{$sections[0]}}{"poweronms"} if (defined(${$Config{$sections[0]}}{"poweronms"}));
-$poweroffms = ${$Config{$sections[0]}}{"poweroffms"} if (defined(${$Config{$sections[0]}}{"poweroffms"}));
+my $valid_arg = 0;
+my $powup = 0;
+my $powdown = 0;
+my $powcyc = 0;
+my $reset = 0;
+my @sprop = ();
+my @gprop = ();
+my $show = 0;
+my $enable_debug = "";
+my $save = "";
+my $load = "";
+my $hostalias;
+
+while (defined($ARGV[0])) {
+ SWITCH: for ($ARGV[0]) {
+ /^-v$/ && do {
+ $verbose = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-g$/ && do {
+ shift @ARGV;
+ push @gprop, shift @ARGV;
+ last SWITCH;
+ };
+ /^-s$/ && do {
+ shift @ARGV;
+ push @sprop, shift @ARGV;
+ last SWITCH;
+ };
+ /^-u$/ && do {
+ $powup = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-d$/ && do {
+ $powdown = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-c$/ && do {
+ $powcyc = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-r$/ && do {
+ $reset = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-l$/ && do {
+ shift @ARGV;
+ $enable_debug = shift @ARGV;
+ last SWITCH;
+ };
+ /^-x$/ && do {
+ $show = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-save$/ && do {
+ shift @ARGV;
+ $save = shift @ARGV;
+ last SWITCH;
+ };
+ /^-load$/ && do {
+ shift @ARGV;
+ $load = shift @ARGV;
+ last SWITCH;
+ };
+
+ if (defined($ARGV[0])) {
+ $hostalias = $ARGV[0];
+ shift(@ARGV);
+ $valid_arg = 1;
+ }
+
+ while ( defined($ARGV[0]) ) { $valid_arg = 0; shift(@ARGV); }
+ }
+}
-$sid = login(${$Config{$sections[0]}}{"user"}, ${$Config{$sections[0]}}{"pass"});
+if (!defined(${$Config{$hostalias}}{'host'})) {
+ $valid_arg = 0;
+}
-show_boarddesc();
+if (!$valid_arg) {
+ print STDERR "Usage: $0 options card-alias\n";
+ print STDERR "Options:\n";
+ print STDERR "\t-g property\tget property value\n";
+ print STDERR "\t-s property=val\tset property value\n";
+ print STDERR "\t-u\t\tpowerup\n";
+ print STDERR "\t-d\t\tpowerdown\n";
+ print STDERR "\t-c\t\tpowercycle\n";
+ print STDERR "\t-r\t\treset\n";
+ print STDERR "\t-x\t\tshow all properties, variables and settings\n";
+ print STDERR "\t-l IP\t\tsend SYSLOG debug messages to IP\n";
+ print STDERR "\t-v\t\tverbose\n";
+ print STDERR "\t-save file\tsave configuration to 'file'\n";
+ print STDERR "\t-load file\tload configuration from 'file'\n";
+ print STDERR "\n";
+ print STDERR "card-alias\tone of: ";
+ foreach my $alias (@sections) {
+ print STDERR "\"${alias}\" ";
+ }
+ print STDERR "(see ~/.rsbs2rc)\n";
+ exit(1);
+}
+
+$host = ${$Config{$hostalias}}{"host"};
+$poweronms = ${$Config{$hostalias}}{"poweronms"} if (defined(${$Config{$hostalias}}{"poweronms"}));
+$poweroffms = ${$Config{$hostalias}}{"poweroffms"} if (defined(${$Config{$hostalias}}{"poweroffms"}));
+
+$sid = login(${$Config{$hostalias}}{"user"}, ${$Config{$hostalias}}{"pass"});
+
+if ($show) {
+ show_boarddesc();
+ board_properties();
+ show_all_vars();
+}
-#showprop("FP_REMOTE_POWER");
-#showprop("FP_REMOTE_BOOT");
-#showprop("SERVER_HARD_RESET_VIA_IPMI");
-#showprop("SERVER_HARD_RESET_PULSE_MS");
-#showprop("SERVER_POWER_CHANGE_VIA_IPMI");
-#showprop("SERVER_POWER_ON_MODE");
-#showprop("SERVER_POWER_ON_PULSE_MS");
-#showprop("SERVER_POWER_OFF_MODE");
-#showprop("SERVER_POWER_OFF_PULSE_MS");
+if (@gprop) {
+ foreach my $p (@gprop) {
+ showprop($p);
+ }
+}
-board_properties();
+if (@sprop) {
+ foreach my $p (@sprop) {
+ (my $pr, $v) = split(/=/,$p,2);
+ setprop($pr, $v);
+ }
+}
-#show_all_vars();
+if ($save ne '') {
+ print "save: implement me!\n";
+}
-syslog_debug("255.255.255.255", "TRUE");
+if ($load ne '') {
+ print "load: implement me!\n";
+}
-#Power Mgmt. Pane
-setprop("FP_REMOTE_POWER", "TRUE");
+if ($enable_debug ne '') {
+ syslog_debug($enable_debug, "TRUE");
+}
-#server_power_on modes: (com/agilent/rmc/mgui/panels/PowerMgmtConf.class)
-#0: l_pmconf_option_disabled
-#1: l_pmconf_option_atx
-#2: l_pmconf_option_relay
-#default: disabled
+if ($reset) {
+ print "hardreset\n" if ($verbose);
+ serveraction("hardreset");
+}
+if ($powup) {
+ powerup();
+}
-#$reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="boardpropset"><BPROP NAME="BOARD_DESCRIPTION"><VAL>'.$boarddesc_new.'</VAL></BPROP></REQ></RMCSEQ>';
-#print $reqstr."\n";
-#print Dumper(_req($reqstr));
+if ($powdown) {
+ powerdown();
+}
-serveraction("hardreset");
-powerup();
-powerdown();
-powercycle();
+if ($powcyc) {
+ powercycle();
+}
logout();