Zum Hauptinhalt springen

How to download systemfiles using the session based token - Wissensdatenbank / Produkte / HiOS - Belden Support Center

How to download systemfiles using the session based token

Context

With older HiOS Version you could directly download system files such as:

  • systeminfo

  • eventlog

  • etc.

via direct url such as


Note

http://admin:password@<IP-ADDRESS>/download.html?filetype=systemlog

The authentication was done in the http request.

Starting with HiOS 10.0.0 the authentication method was extended with a session based Token to increase the security level.

Therefore you now need at least two http(s) requests to retrieve these files.

Example

Please see belows’s example utilizing curl and wget as an CLI download tool to download the system log.

Also be aware that you need to disable the certification validation, if you are using the default https certificates, as they are self signed.

Default

#!/bin/sh

echo "Get SESSION_KEY"

curl_output=$(curl "https://$2/mops_login" -H 'accept: application/xml' -H 'content-type: application/xml' --data-raw '<mops-auth><login><app-name>webif</app-name><credentials><user>admin</user><password>private</password></credentials></login></mops-auth>' --compressed --insecure)

# Extract session key using grep and cut

SESSION_KEY=$(echo "$curl_output" | grep session-key | cut -d '>' -f2 | cut -d '<' -f1)

# (Optional) Check if session key is retrieved successfully

if [[ -z "$SESSION_KEY" ]] ; then

echo "Error: Could not retrieve session key"

exit 1

fi

# Use the SESSION_KEY variable for further requests

echo "Retrieved session key: $SESSION_KEY"

wget --no-check-certificate -v --method POST --timeout=0 --header "Authorization: Mops $SESSION_KEY" --header 'Content-Type: application/octet-stream' "https://$2/download.html?filetype=systemlog"

echo " !DONE! "