+sub read_inifile {
+ my $filename = shift;
+
+ open(INIFILE,"<${filename}") || die("can't open config: ${filename}: $!");
+ my %Ini = ();
+ my @sections = ();
+ while(<INIFILE>) {
+ chomp;
+
+ next if (m/^#/);
+
+ if (m/^\s*\[(.*)\]\s*$/) {
+ push @sections, $1;
+ next;
+ }
+
+ if (@sections) {
+ if (m/^\s*([^=]+)\s*=\s*(.*)\s*$/) {
+ ${$Ini{$sections[$#sections]}}{$1} = $2;
+ }
+ }
+ }
+ close(INIFILE);
+
+ %Ini;
+}
+
+my %Config = read_inifile("$ENV{HOME}/.rsbs2rc");
+
+my $valid_arg = 0;
+my $powup = 0;
+my $powdown = 0;
+my $powcyc = 0;
+my $reset = 0;
+my $resetrsbs2 = 0;
+my @sprop = ();
+my @gprop = ();
+my @xmlsend = ();
+my $show = 0;
+my $enable_debug = "";
+my $save = "";
+my $load = "";
+my $showstat = 0;
+my $gui = 0;
+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;
+ };
+ /^-R$/ && do {
+ $resetrsbs2 = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-l$/ && do {
+ shift @ARGV;
+ $enable_debug = shift @ARGV;
+ last SWITCH;
+ };
+ /^-x$/ && do {
+ $show = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-X$/ && do {
+ shift @ARGV;
+ push @xmlsend, shift @ARGV;
+ last SWITCH;
+ };
+ /^-b$/ && do {
+ $showstat = 1;
+ shift @ARGV;
+ last SWITCH;
+ };
+ /^-G$/ && do {
+ $gui = 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); }
+ }
+}
+
+if ($valid_arg && (!defined($Config{$hostalias}))) {
+ $valid_arg = 0;
+}
+
+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-R\t\treset RSB S2 borad\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-b\t\tshow board/server status\n";
+ print STDERR "\t-X\t\tsend raw XML string (start with REQ tag)\n";
+ print STDERR "\t-G\t\tstart GUI in appletviewer\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 (keys(%Config)) {
+ 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"}));
+
+if ($gui) {
+ open(APPLET,"|appletviewer /dev/stdin");
+ print APPLET '<HTML><HEAD><TITLE>RSB S2 User Interface</TITLE></HEAD>';
+ print APPLET '<BODY>';
+ print APPLET '<object width="640" height="480">';
+ print APPLET '<param name="code" value="com/agilent/rmc/mgui/RmcUI.class">';
+ print APPLET '<param name="codebase" value="http://'.$host.'/">';
+ print APPLET '<param name="archive" value="gui.jar, msa_shared.jar, msa_shared_comm.jar, msa_shared_oem.jar">';
+ print APPLET '</object>';
+ print APPLET '</BODY></HTML>';
+ close(APPLET);
+}
+
+$sid = login(${$Config{$hostalias}}{"user"}, ${$Config{$hostalias}}{"pass"});