forked from ya-mouse/redirector
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredirector-ATEN
321 lines (306 loc) · 13.3 KB
/
redirector-ATEN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/sh
ATEN_guess()
{
fgrep -q 'META NAME="ATEN International' $1
}
ATEN_session_open()
{
local SID
eval `$curl -f -c - -X POST \
-d "name=$opt_user&pwd=$opt_passwd" \
"https://$hostip/cgi/login.cgi" | parse_cookie`
session=$SID
[ "$session" != 'Failure_Login_IPMI_Then_LDAP_then_Active_Directory' ] || session=
}
ATEN_session_close()
{
$curl -o /dev/null \
-b "SID=$session" \
"https://$hostip/cgi/logout.cgi"
}
ATEN_mc_info()
{
local BIOS_VERSION=
local REDFISH_REV=
local PLATFORM_INFO_CPLD_REV=N/A
local PLATFORM_INFO_BIOS_VERSION=
local PLATFORM_INFO_REDFISH_REV=
local bios=N/A
local biosdate=N/A
local license=N/A
ATEN_sm_lic_check && license=Activated
# Get relevant info from ipmitool
local mfg_id="$(ipmitool -U $opt_user -P $opt_passwd -I lanplus -H $hostip_nb mc info 2>&1 | $sed -n -e '/^Manufacturer\ ID/,/^Product\ ID/p')"
eval `$curl -b "SID=$session" \
-d "GENERIC_INFO.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
eval `$curl -b "SID=$session" \
-d "Get_BoradID_XML.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
# power status
eval `$curl -b "SID=$session" \
-d "POWER_INFO.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
# try to fetch BIOS info (for X10 models)
eval `$curl -b "SID=$session" \
-d "Get_PlatformInfo.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
# try to fetch POST CODE
eval `$curl -b "SID=$session" \
-d "SNOOPING.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
[ "$PLATFORM_INFO_BIOS_VERSION" != ' ' -o -n "$PLATFORM_INFO_REDFISH_REV" ] && \
# try to fetch SMBIOS_INFO
eval `$curl -b "SID=$session" \
-d "SMBIOS_INFO.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
cat <<EOF
BMC Firmware Revision : $(echo $GENERIC_IPMIFW_VERSION | $sed 's,\(..\),\1.,' | xargs printf "%.2f")
BMC Firmware Tag : $GENERIC_IPMIFW_TAG
BMC Build Time : $GENERIC_IPMIFW_BLDTIME
BMC Kernel Version : $KERNAL_VERSION
BMC IP Address : $(echo ${GENERIC_BMC_IP:-$BMC_IP}|$sed -ne 's/^0//;{s/\.0\?/./gp}')
BMC MAC Address : $GENERIC_BMC_MAC
BMC License status : $license
EOF
if [ -n "$PLATFORM_INFO_BIOS_VERSION" -a "$PLATFORM_INFO_BIOS_VERSION" != ' ' ]; then
bios="$PLATFORM_INFO_BIOS_VERSION"
biosdate="$PLATFORM_INFO_BIOS_BUILD_DATE"
fi
if [ -n "$BIOS_VERSION" -a "$BIOS_VERSION" != ' ' ]; then
bios="$BIOS_VERSION"
biosdate="$PLATFORM_INFO_BIOS_BUILD_DATE"
fi
[ -n "$REDFISH_REV" ] || \
REDFISH_REV=$($curl -f https://$hostip/redfish/v1/|jq -r .RedfishVersion -)
[ -z "$REDFISH_REV" -o "$REDFISH_REV" == 'null' ] && REDFISH_REV=N/A
cat <<EOF
Platform BIOS Version : $bios
Platform BIOS Build Time : $biosdate
Platform BIOS POST code : ${POST_CODE:-N/A}
Platform CPLD Version : ${PLATFORM_INFO_CPLD_VERSION:-$PLATFORM_INFO_CPLD_REV}
Platform EC Version : ${PLATFORM_INFO_EC_VERSION:-N/A}
Platform RedFish Version : ${PLATFORM_INFO_REDFISH_REV:-$REDFISH_REV}
Platform Power status : ${POWER_STATUS:-N/A}
Platform NIC(s) : ${PLATFORM_INFO_MB_MAC_NUM}
Platform NIC1 MAC : ${PLATFORM_INFO_MB_MAC_ADDR:-$PLATFORM_INFO_MB_MAC_ADDR1}
$(if [ ${PLATFORM_INFO_MB_MAC_NUM} -gt 3 ]; then
echo "Platform NIC2 MAC : ${PLATFORM_INFO_MB_MAC_ADDR1}"
echo "Platform NIC3 MAC : ${PLATFORM_INFO_MB_MAC_ADDR2}"
echo "Platform NIC4 MAC : ${PLATFORM_INFO_MB_MAC_ADDR3}"
else
echo "Platform NIC2 MAC : ${PLATFORM_INFO_MB_MAC_ADDR2:-$PLATFORM_INFO_MB_MAC_ADDR1}"
fi)
$mfg_id
Product Name : Unknown (0x$BoardID_ID)
Product Serial Number : ${SYSTEM_SN:-N/A}
Product Model : ${SYSTEM_PN:-N/A}
System CPU Name : ${CPU_VER:-N/A}
System CPU Speed : ${CPU_SPEED:-N/A}
System CPU Cores : ${CPU_CORE_ENABLED:-N/A}
EOF
}
ATEN_mc_reset_cold()
{
$curl -o /dev/null \
-b "SID=$session" \
"https://$hostip/cgi/BMCReset.cgi"
}
ATEN_chk_jnlp()
{
grep -q '<jnlp spec=".*" codebase=' "$1"
}
ATEN_kvm()
{
$curl -f -o "$1" \
-b "SID=$session" \
"https://$hostip/cgi/Build_jnlp.cgi" && ATEN_chk_jnlp "$1" ||
$curl -f -o "$1" \
-b "SID=$session" \
"https://$hostip/jnlp/sess_${session}.jnlp" && ATEN_chk_jnlp "$1" ||
$curl -f -o "$1" \
-b "SID=$session" \
-H "Referer: https://$hostip/cgi/url_redirect.cgi?url_name=man_ikvm" \
"https://$hostip/cgi/url_redirect.cgi?url_name=sess_${session}&url_type=jwsk" && ATEN_chk_jnlp "$1" ||
$curl -f -o "$1" \
-b "SID=$session" \
-H "Referer: https://$hostip/cgi/url_redirect.cgi?url_name=man_ikvm" \
"https://$hostip/cgi/url_redirect.cgi?url_name=ikvm&url_type=jwsk" && ATEN_chk_jnlp "$1" || return $?
}
ATEN_redirect()
{
local s rc=0
case "$2" in
cdrom)
ATEN_kvm "$1" || rc=$?
[ "$rc" -eq 0 -o "$rc" -eq 18 ] || return $rc
s=$($stat $3)
cnt="$($sed -n 's,[[:space:]]*<argument>\([^<]\+\)</argument>,\1,p' "$1" | wc -l)"
rev=r1
[ "$cnt" -ne 8 ] || rev=r2
$sed -n 's,[[:space:]]*<argument>\([^<]\+\)</argument>,\1,p' "$1" | tr '\n' ' ' |
$sed "s,^,$3 $(((s - (s * 277) / 10000) / 1024)) $opt_timeout $rev ," |
timeout_pass -9 $((opt_timeout * 60 + 15)) java -cp $java_path/redirector.jar com.redirector.ATEN.kvm.Redirector
;;
*)
error "Redirection for $2 not supported"
;;
esac
}
ATEN_sol()
{
ipmitool -I lanplus -H $hostip_nb -p 623 -U $opt_user -P $opt_passwd sol activate
}
ATEN_sm_lic_check()
{
local cookies="langSetFlag=0;language=English;SID=$session;mainpage=maintenance;subpage=main_bios_upload"
local get="$curl -b $cookies https://$hostip"
$get/cgi/url_redirect.cgi?url_name=misc_license | fgrep -q ' license_activated()' && return 0 || return 1
}
ATEN_activate()
{
[ -n "$1" ] || error "License file not specified"
[ -e "$1" ] || error "License \`$1' doesn't exist"
eval `$curl -b "SID=$session" \
-d "GENERIC_INFO.XML=(0,0)" \
"https://$hostip/cgi/ipmi.cgi" | parse_xml`
[ -n "$GENERIC_BMC_MAC" ] && GENERIC_BMC_MAC=$(echo $GENERIC_BMC_MAC|tr a-z A-Z|sed -e 's/://g') \
|| error 'BMC MAC not found'
local key=$(fgrep $GENERIC_BMC_MAC $1)
[ -n "$key" ] && echo "Found activation key for $GENERIC_BMC_MAC.." || error "$GENERIC_BMC_MAC: No key found!"
# key usually shipped as <MAC>;;key
key=$(echo "${key##*;;}"|awk -F"-" '{ for (i=1; i<=NF; i++) printf "%s","&bioskey"(i-1)"="$i }')
local fmt='+%a%%20%b%%20%d%%20%Y%%20%T%%20GMT%z%%20(%Z)'
echo -n 'Checking activation status...'
ATEN_sm_lic_check && error 'Activated' || echo 'Not activated, good'
echo -n 'Sending activation key...'
local cookies="langSetFlag=0;language=English;SID=$session;mainpage=miscellaneous;subpage=misc_license"
local get="$curl -b $cookies https://$hostip"
$get/cgi/ipmi.cgi -d "BIOS_LINCENSE_ACTIVATE.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")$key" | fgrep -q 'BIOS_LINCESNE CHECK="1"' && echo 'OK!' \
|| error 'Failed to activate :('
echo 'License activated successfully'
}
ATEN_lan_print()
{
# CONFIG_INFO.XML
# CONFIG_IPV6.XML
ipmitool -U $opt_user -P $opt_passwd -I lanplus -H $hostip_nb lan print
}
ATEN_lan_set()
{
local fmt='+%a%%20%b%%20%d%%20%Y%%20%T%%20GMT%z%%20(%Z)'
local cnt=0
case "$1" in
fwup) shift
[ -n "$1" ] || error "Image file not specified"
[ -e "$1" ] || error "File \`$1' not exists"
local cookies="langSetFlag=0;language=English;SID=$session;mainpage=maintenance;subpage=main_fw_update"
local get="$curl -b $cookies https://$hostip"
echo -n "Preparing BMC to flash [$session]..."
$get/cgi/ipmi.cgi -d "LOCK_UPLOAD_FW.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="1"' && echo done || error failed
echo -n "Uploading image..."
$get/cgi/oem_firmware_upload.cgi -m 300 -H 'Expect:' -f -F "\"form1\"=@$1;filename=\"$(basename $1)\";type=application/octet-stream" | fgrep -q 'btn_upgrade' && echo done || error failed
replace=`$get/cgi/ipmi.cgi -d "UPLOAD_FW_VERSION.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | $sed -n 's,.*FW_VERSION\ \(NEW=.*"\)\/.*,\1,p'` || error failed
if [ -n "$replace" ]; then
new=${replace%% OLD=*}
old=${replace##*OLD=}
new=${new#NEW=}
if [ "$new" == "$old" ]; then
echo "BMC versions are the same, exiting..."
echo -n "Rebooting BMC..."
ATEN_mc_reset_cold && echo "done" || error failed
session=
return 1
else
echo "Going to replace fw $old -> $new..."
fi
else
echo "Unable to guess BMC version, exiting..."
echo -n "Rebooting BMC..."
ATEN_mc_reset_cold && echo "done" || error failed
session=
return 1
fi
echo "Flashing..."
# FIXME new X10 use 'preserve_ssl'
# param to keep ssl cert probably need to add this too
fwreply=`$get/cgi/oem_firmware_update.cgi -m 5 -d "preserve_config=1&preserve_sdr=1&timeStamp=$(LC_ALL=C date "$fmt")" ||:`
[ -n "$fwreply" ] || error 'startflash failed'
case "$fwreply" in
ok) percent=`$get/cgi/upgrade_process.cgi -d "fwtype=0&time_stamp=$(LC_ALL=C date "$fmt")" | $sed -n 's,.*<percent>\([0-9 ]\+\)</percent>,\1,p'` ||:
printf "\rCompleted %s%%" "$percent"
;;
*) error 'startflash falied'
;;
esac
while sleep 5; do
percent=`$get/cgi/upgrade_process.cgi -d "fwtype=0&time_stamp=$(LC_ALL=C date "$fmt")" | $sed -n 's,.*<percent>\([0-9 ]\+\)</percent>,\1,p'` ||:
printf "\rCompleted %s%%" "$percent"
[ "$percent" != 100 ] || break
cnt=$((cnt+1))
[ "$cnt" -lt 15 ] || [ -n "$percent" -o "$percent" -ne 0 ] || error failed
done
printf "\nFlash complete. Rebooting...\n"
session=
;;
biosup) shift
[ -n "$1" ] || error "BIOS file not specified"
[ -e "$1" ] || error "File \`$1' not exists"
echo -n 'Checking BIOS license status...'
ATEN_sm_lic_check && echo 'Activated' || error 'Not activated, exiting...'
local cookies="langSetFlag=0;language=English;SID=$session;mainpage=maintenance;subpage=main_bios_upload"
local get="$curl -b $cookies https://$hostip"
echo -n "Preparing BMC to flash [$session]..."
$get/cgi/ipmi.cgi -d "BIOS_UPDATE_MISC.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="-1"' && echo done || error failed
echo -n "Locking firmware for update..."
$get/cgi/ipmi.cgi -d "BIOS_UPLOAD.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="1"' && echo done || error failed
echo -n "Uploading image..."
$get/cgi/bios_upload.cgi -m 300 -H 'Expect:' -f -F "\"form1\"=@$1;filename=\"$(basename $1)\";type=application/octet-stream" | fgrep -q 'btn_upgrade' && echo done || error failed
$get/cgi/ipmi.cgi -d "BIOS_UPDATE_CHECK.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="00"' || error 'Update check failed'
biosreplace=`$get/cgi/ipmi.cgi -d "BIOS_REV.XML=&time_stamp=$(LC_ALL=C date "$fmt")"|$sed -n -e '/BIOS_Rev/,/\/>/s,.*\ OldRev\=\([^N]\+\).*NewRev\=\([^>]\+\)\/>.*,Old=\1 New=\2,gp'`
if [ -n "$biosreplace" ]; then
new=${biosreplace##*New=}
old=${biosreplace%% New=*}
old=${old##Old=}
if [ "$new" == "$old" ]; then
echo "BIOS versions are the same, exiting..."
echo -n "Rebooting BMC..."
ATEN_mc_reset_cold && echo "done" || error failed
session=
return 1
else
echo "Going to replace |$old| -> |$new|..."
fi
else
echo "Unable to guess BIOS version, exiting..."
echo -n "Rebooting BMC..."
ATEN_mc_reset_cold && echo "done" || error failed
session=
return 1
fi
echo -n "Setting flash options..."
$get/cgi/ipmi.cgi -d "BIOS_OPTION.XML=&me_en=1&nve_en=1&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'Res="3"' || error failed
# ensure that process is locked
$get/cgi/ipmi.cgi -d "BIOS_UPDATE_MISC.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="-1"' && echo done || error failed
echo "Flashing..."
$get/cgi/bios_update.cgi -m 5 -d "timeStamp=$(LC_ALL=C date "$fmt")" ||:
# sometimes there is no 'ok' in reply to blindly poll for progress status (
while sleep 5; do
percent=`$get/cgi/upgrade_process.cgi -d "fwtype=1&time_stamp=$(LC_ALL=C date "$fmt")" | $sed -n 's,.*<percent>\([0-9 ]\+\)</percent>,\1,p'` ||:
printf "\rCompleted %s%%" "$percent"
[ "$percent" != 100 ] || break
cnt=$((cnt+1))
[ "$cnt" -lt 15 ] || [ -n "$percent" -o "$percent" -ne 0 ] || error failed
done
printf "\nFlash complete. Finalizing things...\n"
$get/cgi/ipmi.cgi -d "BIOS_UPDATE_DONE.XML=(1,0)&time_stamp=$(LC_ALL=C date "$fmt")" ||:
$get/cgi/ipmi.cgi -d "POWER_INFO.XML=(0,0)&time_stamp=$(LC_ALL=C date "$fmt")" | fgrep -q 'POWER STATUS="ON"' || error 'Failed to get power state'
echo -n "Unlocking UI..."
$get/cgi/ipmi.cgi -d "BIOS_UPDATE_MISC.XML=(1,0)&time_stamp$(LC_ALL=C date "$fmt")" | fgrep -q 'RES="0"' && echo done || error failed
echo "Rebooting the system..."
$get/cgi/ipmi.cgi -d "POWER_INFO.XML=(1,2)&time_stamp$(LC_ALL=C date "$fmt")" | fgrep -q 'POWER STATUS="ON"' \
&& echo 'Please wait up to 5min to complete boot cycle' ||:
session=
;;
esac
}