Access an APC AP5456 IP Gateway for Analog KVM in Linux

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.

#!/bin/bash

# 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

Posted

in

, ,

by

Tags:

Comments

9 responses to “Access an APC AP5456 IP Gateway for Analog KVM in Linux”

  1. Jay Avatar
    Jay

    I really, really appreciate your two articles on these APC IP KVMs — but can you provide an example of how this script is used? That’s the only thing missing!

    Thanks.

    1. Chris Avatar
      Chris

      Hi Jay, thanks for your interest. I’ll try to add some clarification. Sorry if any of this comes across as condescending, but I’ll just assume the least knowledge on your part to maximize the usefulness of this response to potential readers from the future. On a system with Wine and the other prerequisites covered the steps are:

      Download:
      user@host:~$ wget http://ethertubes.com/files/apc_kvm.sh

      Make the script executable:
      user@host:~$ chmod u+x apc_kvm.sh

      Run the script:
      user@host:~$ ./apc_kvm.sh

      Notice the proceeding ‘./’ before the script name, that lets the shell know we want to work with a file in the current directory. If you’re going to be using this script a lot, you might want to put it some place in your path. Example:

      user@host:~$ mv apc_kvm.sh /usr/local/bin

      On most Linux systems /usr/local/bin is in your $PATH environment, so in the future you can just type “apc_kvm.sh” like a normal system command without specifying the path (e.g. ‘./’)

      There are no command line arguments/switches. When ran the script is interactive, meaning it will ask you for the things it needs:

      user@host:~$ ./apc_kvm.sh
      FQDN of KVM Server (not including https://):

      Here it’s asking for the IP address or the DNS name for the IP KVM. If you know the web address for the IP KVM, this will be the same thing, just take whatever is in between the URI and the first forward slash in the resource.

      Example: Say you could access an IP KVM at https://www.example.org/global.asp then your answer for this question would just be ‘www.example.org’ (without the quotes of course)

      Next it will ask for the password you use to login to the KVM via the web interface for the ‘apc’ user.
      user@host:~$ ./apc_kvm.sh
      FQDN of KVM Server (not including https://): example.org
      Password:

      If you have created a new user on the APC IP KVM and would like to use those credentials instead of the ‘apc’ user, edit the apc.kvm.sh file and change the line that says:

      USERNAME=”apc”

      Replace the ‘apc’ with the username you’ve created (assuming you’ve created one). If you haven’t made a custom user, the default username and password is ‘apc’ with a password of ‘apc’.

      If you will be using the script with the same IP KVM all the time, you may want to modify the variables at the start of the script. By setting USERNAME, PASSWORD, and KVM_SERVER in the script you will prevent apc_kvm.sh from asking you all these questions in the future. The KVM_SERVER variable is for setting the IP or DNS name as described above.

      That should be all there is to it.

      Troubleshooting:

      Make sure you don’t already have the IP KVM in a browser some place else. If you run into errors you can try to comment with them here. No guarantee I’ll be able to help (or even try for the matter), but generally the more detail the better.

      Advanced:

      If you are accessing an APC IP KVM through an SSH tunnel, besides forwarding 443 for https you also need 5900 for the VNC-esque remote frame buffer data.

      I hope this helps.

  2. Jay Avatar
    Jay

    Awesome. Thanks for the help. Turns out I have a different model of IP KVM, but everything you’ve documented here is great. I’ll be sure to submit anything I write up back here for others to benefit from.

    1. Chris Avatar
      Chris

      The script scrapes some specific strings in the html served by the embedded web server of the AP5456, it may even break across firmware versions on that model. I believe the hardware of the AP5456 is similar to the StarTech SV1105IPEXT. I would bet that the script could be easily modified to work with the SV1105IPEXT, beyond that I have no idea. The information in my article leading up to this one describes the process I used for creating this script, it might be of benefit to you. Thanks for your feedback.

  3. Jay Avatar
    Jay

    Okay, thanks to your msgbox.exe and your sample code, I’ve managed to get an APC 16-port IP KVM (AP5405) working with Ubuntu Linux. I had to write a long-ish script to get it working (in Perl) and once I tidy up the code and test it a little more, I’ll post the results. Thanks again.

  4. Janos Avatar
    Janos

    Thanks for your post about this device.
    As it turns out, this device is basically the same as the Avocent SwitchView IP 1010, so your solution can be used with it, without any changes.

    1. JBevren Avatar

      As it also turns out, the IP modules in the Avocent KVM/NET+ series are pretty much SwitchView IP 1010 embedded cards, so some trickery can be done to access them with a modified version of Ethertubes’ script.

      I’ve been using my customized version with a KVM/NET+ 3204 for a couple years now and remembered its origins this evening. While not secure enough for a datacenter environment anymore, these venerable old KVM devices serve me well at home.

      Thanks Ethertubes!

      1. admin Avatar
        admin

        Thanks for the note! I always appreciate hearing when something I’ve posted was helpful.

  5. Brian Avatar
    Brian

    Did anyone ever get this to work with the AP5405?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.