|
|
|
The open-source utility curl (http://curl.haxx.se/ or http://curl.sourceforge.net/) provides a couple of convenient ways to communicate with CNA.
The utility--which includes SSL encryption/decryption capabilities--comes as either a command-line process or a library with interfaces in C, C++, Java, Perl, and many other programming languages. There are command-line binaries for most operating systems, including Windows, Linux, and Solaris.
There are some differences between the curl interface and HTTP requirements. The curl utility will encode user ID and password strings in base64 format, so you should enter them in plain text, using the --user flag. However, the utility will not encode the enable password, which you must enter using an -H flag.
To use the curl process to send the ls command to a device called PathControl from the command line, a user named user, whose password is password, would enter the following on his or her host’s command line (enter all on a single line):
curl -d 'ls' \ -H 'Content-type: text/plain' \ -H 'Enable-Authorization: Basic cHJpdmVsZWdlZA==' \ --user user:password \ http://PathControl/exec
The curl utility will use the values specified by the --user flag to encode the HTTP authorization string in base64 format, open an HTTP connection with the specified URI, and transmit the data. The URI should point to CNA’s hostname or the IP address of the management module’s eth0 interface, with either /exec or /configure appended.
Note also that you do not specify the Content-Length header; the curl utility will calculate it for you.
However, you must specify the Content-Type header. This will cause the curl utility to submit the data as content body rather than as form data.
By default, the curl utility treats data specified with the -d flag as HTTP form data, formats it accordingly and appends it to the URI. The CNA web server will not be able to process the request, and a 500 HTTP status message will be returned along with a Java IllegalArgumentException error message. The Content-Type header in the curl command prevents this from happening.
You can also use the curl utility to copy commands from a file.
Specify the name of the file containing the commands in the curl utility’s data block with the @ character, as follows:
curl -d ‘@myconfig.cfg’ \ -H 'Content-type: text/plain' \ -H ‘Enable-Authorization: Basic cHJpdmVsZWdlZA== \ --user user:password \ http://PathControl/configure
If the file is located on CNA itself, use the copy command to copy the file to the device’s running configuration:
curl -d ‘copy myconfig.cfg running-config’ \ -H 'Content-type: text/plain' \ -H ‘Enable-Authorization: Basic cHJpdmVsZWdlZA== \ --user user:password \ http://PathControl/configure
|
|
|