I recently wrote about running an ActiveX component without Internet Explorer. I used that technique to come up with a shell script front-end for downloading, unpacking and running an executable in Wine for accessing an APC IP KVM (model AP5456). Here is the results of that effort.
At a minimum the script requires Wine and curl, but to do everything without manually downloading and extracting the cabinet file yourself, you’ll also need cabextract. Some less exotic stuff from coreutils: basename and dirname are needed, but you probably have those already.
You can download the script here.
# A script to access an APC brand model AP5456 IP Gateway for Analog KVM
# In Linux, using Wine
USERNAME="apc"
PASSWORD=""
KVM_SERVER=""
VIEWER_PATH=""
while [ -z "$KVM_SERVER" ]
do
echo -n "FQDN of KVM Server (not including https://): "
read KVM_SERVER
done
while [ -z "$USERNAME" ]
do
echo -n "Username: "
read USERNAME
done
while [ -z "$PASSWORD" ]
do
echo -n "Password: "
tput invis
read PASSWORD
tput sgr0
done
get_cab_name () {
while read line
do
if [ "${line/’OBJECT CODEBASE’/}" != "$line" ]; then
cab_name="${line##*'<OBJECT CODEBASE="’}"
cab_name="${cab_name%%’"’*}"
echo "$cab_name"
fi
done
}
get_cmd_args () {
while read line
do
if [ "${line/PARAM/}" != "$line" ]; then
ipaddr="${line##*'<PARAM NAME="ipaddr" VALUE="’}"
ipaddr="${ipaddr%%’"’*}"
sessionkey="${line##*'<PARAM NAME="sessionkey" VALUE="’}"
sessionkey="${sessionkey%%’"’*}"
encryptionkey="${line##*'<PARAM NAME="encryptionkey" VALUE="’}"
encryptionkey="${encryptionkey%%’"’*}"
fi
done
if [ -n "$sessionkey" ] && [ -n "$encryptionkey" ] && [ -n "$ipaddr" ]; then
echo "-k $sessionkey -e $encryptionkey $ipaddr"
fi
}
wine="`which wine`"
if [ -z "$wine" ]; then
echo "Wine was not found, but is required. Can not continue without it." >&2
exit 1
fi
cd "`dirname $0`"
#If a path to vpclient.exe wasn’t specified, and we can’t find it, use /tmp
#as a place to download it to
if [ -z "$VIEWER_PATH" ] && ! [ -f "vpclient.exe" ]; then
mkdir -p "/tmp/vpclient"
VIEWER_PATH="/tmp/vpclient"
fi
#If a full path wasn’t specified, prepend current working directory
if [ "${VIEWER_PATH:0:1}" != "/" ]; then
VIEWER_PATH="`pwd`/$VIEWER_PATH"
fi
if ! [ -f "$VIEWER_PATH/vpclient.exe" ]; then
cab_url="`curl -s –insecure –user "$USERNAME:$PASSWORD" "https://$KVM_SERVER/launch.asp" |get_cab_name`"
cab_url="https://$KVM_SERVER/$cab_url"
cabextract="`which cabextract`"
if [ -z "$cabextract" ]; then
echo "vpclient.exe was not found in $VIEWER_PATH" >&2
echo "cabextract was not found either, so we can’t download">&2
echo -e "and extract vpclient.exe from it’s CAB archive.\n" >&2
echo "Error: user intervention required." >&2
echo "———————————-" >&2
echo "Download $cab_url" >&2
echo "Unpack `basename $cab_url` into $VIEWER_PATH" >&2
echo " — OR — " >&2
echo "Install cabextract" >&2
exit 1
fi
if ! [ -d "$VIEWER_PATH" ]; then
echo "WARNING: Viewer Path specified is not valid." >&2
echo "Path: $VIEWER_PATH" >&2
echo -e "——————————————-\n" >&2
echo -n "Would you like me to create it? (y/N)?" >&2
read answer
shopt -s nocasematch
if [ "$answer" = "y" ]; then
mkdir -p "$VIEWER_PATH"
if ! [ -d "$VIEWER_PATH" ]; then
echo "Couldn’t create: $VIEWER_PATH" >&2
exit 1
fi
else
exit
fi
shopt -u nocasematch
fi
cd "$VIEWER_PATH"
curl -s –insecure –user "$USERNAME:$PASSWORD" "$cab_url" >"`basename $cab_url`"
$cabextract -q "`basename $cab_url`" 2>/dev/null
fi
cmd_args="`curl -s –insecure –user "$USERNAME:$PASSWORD" "https://$KVM_SERVER/launch.asp" |get_cmd_args`"
cd "$VIEWER_PATH"
#Sanity check
if [ -f "./vpclient.exe" ]; then
$wine "./vpclient.exe" $cmd_args
else
echo "Failed, do it yourself: $wine vpclient.exe $cmd_args"
fi
Leave a Reply to JBevren Cancel reply