forked from ya-mouse/redirector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirector-ATEN
132 lines (119 loc) · 4.28 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
#!/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" \
"http://$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" \
"http://$hostip/cgi/logout.cgi"
}
ATEN_mc_info()
{
eval `$curl -b "SID=$session" \
-d "GENERIC_INFO.XML=(0,0)" \
"http://$hostip/cgi/ipmi.cgi" | parse_xml`
eval `$curl -b "SID=$session" \
-d "Get_BoradID_XML.XML=(0,0)" \
"http://$hostip/cgi/ipmi.cgi" | parse_xml`
cat <<EOF
Firmware Revision : $(echo $GENERIC_IPMIFW_VERSION | sed 's,\(..\),\1.,' | xargs printf "%.2f")
Firmware Tag : $GENERIC_IPMIFW_TAG
Build Time : $GENERIC_IPMIFW_BLDTIME
Kernel Version : $KERNAL_VERSION
Manufacturer ID : 47488
Manufacturer Name : Unknown (0xB980)
Product ID : $(printf "%d" 0x$BoardID_ID) (0x$BoardID_ID)
Product Name : Unknown (0x$BoardID_ID)
EOF
}
ATEN_mc_reset_cold()
{
$curl -o /dev/null \
-b "SID=$session" \
"http://$hostip/cgi/BMCReset.cgi"
}
ATEN_chk_jnlp()
{
grep -q '<jnlp spec=".*" codebase=' "$1"
}
ATEN_kvm()
{
$curl -f -o "$1" \
-b "SID=$session" \
"http://$hostip/cgi/Build_jnlp.cgi" && ATEN_chk_jnlp "$1" ||
$curl -f -o "$1" \
-b "SID=$session" \
"http://$hostip/jnlp/sess_${session}.jnlp" && ATEN_chk_jnlp "$1" ||
$curl -f -o "$1" \
-b "SID=$session" \
-H "Referer: http://$hostip/cgi/url_redirect.cgi?url_name=man_ikvm" \
"http://$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: http://$hostip/cgi/url_redirect.cgi?url_name=man_ikvm" \
"http://$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 -c%s $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.redirerctor.ATEN.kvm.Redirector
;;
*)
error "Redirection for $2 not supported"
;;
esac
}
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 get="$curl -b SID=$session http://$hostip"
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"
echo -n "Preparing BMC to flash [$session]..."
$get/cgi/ipmi.cgi -G -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=firmware.bin;type=application/octet-stream" | fgrep -q 'UpgradeFW' && echo done || error failed
echo "Flashing..."
$get/cgi/oem_firmware_update.cgi -G -d "preserve_config=0&timeStamp=$(LC_ALL=C date "$fmt")" | egrep -q '^ok' || error 'startflash failed'
while sleep 10; do
percent=`$get/cgi/upgrade_process.cgi -G -d "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 5 ] || [ -n "$percent" -o "$percent" -ne 0 ] || error failed
done
printf "\nFlash complete. Rebooting...\n"
session=
;;
esac
}