]>
git.zerfleddert.de Git - rsbs2/blob - rsbs2
7591fb7c9368d96e5706dbbefe22cec1cf978acc
7 use Digest
::MD5
qw(md5);
9 my $ua = LWP
::UserAgent
->new;
12 my $host = "192.168.50.6";
19 for my $k (0..length($str)-1) {
20 $crc ^= ord(substr($str, $k, 1)) << 8;
22 $crc = (($crc & 0x8000) == 32768 ?
($crc<<1) ^ 0x1021 : $crc<<1);
30 my ($password, $challenge) = @_;
31 my @challenge_bytes = unpack 'c16', decode_base64
($challenge);
32 my @pwd_hash = unpack 'c16', md5
($password);
35 $xor_bytes[$i] = $challenge_bytes[$i] ^ $pwd_hash[$i];
37 my $hash = md5
(pack 'c16', @xor_bytes);
38 my $crc = _crc16
($hash);
39 $hash .= chr($crc & 0xff) . chr($crc >> 8 & 0xff);
40 return encode_base64
($hash, "");
45 $request = HTTP
::Request
->new(POST
=> "http://${host}/cgi/bin");
46 $request->header(Cookie
=> "sid=$sid");
47 $request->content_type('application/x-www-form-urlencoded');
48 $request->content($xml);
49 $response = $ua->request($request);
50 die("Error in request: " . $response->status_line . "\n") unless ($response->is_success);
51 XMLin
($response->content);
57 my $reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="propget"><PROPLIST><PROP NAME="'.$property.'"/></PROPLIST></REQ></RMCSEQ>';
58 my $resp = _req
($reqstr);
60 if ($resp->{RESP
}->{RC
} ne '0x0') {
61 "Error: " . $resp->{RESP
}->{RC
};
63 $resp->{RESP
}->{PROPLIST
}->{PROP
}->{VAL
};
69 my $request = HTTP
::Request
->new(GET
=> "http://${host}/cgi/logout");
70 $request->header(Cookie
=> "sid=$sid");
71 my $response = $ua->request($request);
72 die("While trying to logout: " . $response->status_line . "\n") unless ($response->is_success);
74 my $xmlin = XMLin
($response->decoded_content);
75 die "Error logging out: ".$xmlin->{RC
} if ($xmlin->{RC
} ne '0x0');
82 my $oldval = _getprop
($property);
84 if ($value eq $oldval) {
85 print "${property} is already ${value}\n";
89 my $reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="propset"><PROP NAME="'.$property.'"><VAL>'.$value.'</VAL></PROP></REQ></RMCSEQ>';
90 my $res = _req
($reqstr);
92 if ($res->{RESP
}->{RC
} ne '0x0') {
93 print "Error setting ${property} to ${value}: ".$res->{RESP
}->{RC
}."\n";
95 print "${property}: ${oldval} -> ${value}\n";
102 print "${action}...\n";
103 my $reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="serveraction"><ACT>'.$action.'</ACT></REQ></RMCSEQ>';
104 my $res = _req
($reqstr);
106 if ($res->{RESP
}->{RC
} ne '0x0') {
107 print "FAILED:".$res->{RESP
}->{RC
}."\n";
112 my $property = shift;
114 print "${property}: " . _getprop
($property) . "\n";
118 my $response = $ua->get("http://${host}/cgi/challenge");
119 die $response->status_line if (!($response->is_success));
121 my $xmlin = XMLin
($response->decoded_content);
122 die "Error getting Challenge: ".$xmlin->{RC
} if ($xmlin->{RC
} ne '0x0');
123 my $challenge = $xmlin->{CHALLENGE
};
124 print "Challenge: ${challenge}\n";
126 $sid = $response->headers->header('Set-Cookie');
127 die "No SessionID!" if (!defined($sid));
129 $sid =~ s/.*sid=(.*);.*/$1/;
130 print "SID: ${sid}\n";
132 my $login_hash = _hash
($pass, $challenge);
133 print "Hash: ${login_hash}\n";
135 my $request = HTTP
::Request
->new(GET
=> "http://${host}/cgi/login?user=${user}&hash=${login_hash}");
136 $request->header(Cookie
=> "sid=$sid");
137 $response = $ua->request($request);
138 die("While trying to login: " . $response->status_line . "\n") unless ($response->is_success);
140 $xmlin = XMLin
($response->decoded_content);
141 die "Error logging in: ".$xmlin->{RC
} if ($xmlin->{RC
} ne '0x0');
143 $reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="boardpropget"><BPROPLIST><BPROP NAME="BOARD_DESCRIPTION"/></BPROPLIST></REQ></RMCSEQ>';
144 my $boarddesc64 = _req
($reqstr)->{RESP
}->{BPROPLIST
}->{BPROP
}->{VAL
};
145 my $boarddesc = decode_base64
($boarddesc64);
146 my @board = split(//, $boarddesc);
147 foreach my $byte (@board) {
148 printf ("0x%02x ", ord($byte));
151 printf("byte 22: 0x%x\n", ord($board[22]));
153 showprop
("FP_REMOTE_POWER");
154 showprop
("FP_REMOTE_BOOT");
155 showprop
("SERVER_HARD_RESET_VIA_IPMI");
156 showprop
("SERVER_HARD_RESET_PULSE_MS");
157 showprop
("SERVER_POWER_CHANGE_VIA_IPMI");
158 showprop
("SERVER_POWER_ON_MODE");
159 showprop
("SERVER_POWER_ON_PULSE_MS");
160 showprop
("SERVER_POWER_OFF_MODE");
161 showprop
("SERVER_POWER_OFF_PULSE_MS");
163 #server_power_on modes: (com/agilent/rmc/mgui/panels/PowerMgmtConf.class)
164 #0: l_pmconf_option_disabled
165 #1: l_pmconf_option_atx
166 #2: l_pmconf_option_relay
171 setprop
("SERVER_HARD_RESET_VIA_IPMI", "FALSE");
172 setprop
("SERVER_POWER_CHANGE_VIA_IPMI", "FALSE");
174 setprop
("FP_REMOTE_POWER", "TRUE");
176 setprop
("SERVER_POWER_ON_MODE", sprintf("0x%x", $pmode));
177 setprop
("SERVER_POWER_OFF_MODE", sprintf("0x%x", $pmode));
179 #$reqstr='<?xml version="1.0"?><?RMCXML version="1.0"?><RMCSEQ><REQ CMD="boardpropset"><BPROP NAME="BOARD_DESCRIPTION"><VAL>'.$boarddesc_new.'</VAL></BPROP></REQ></RMCSEQ>';
181 #print Dumper(_req($reqstr));
183 #serveraction("hardreset");
184 serveraction
("powerup");
185 serveraction
("powerdown");