cancel
Showing results for 
Search instead for 
Did you mean: 

Ruckus Unleashed API using curl?

Jeronimo
New Contributor III

 

Hi.

I saw a API for unleashed on https://github.com/commscope-ruckus/RUCKUS-Unleashed

But I need a bash script using curl.

when I tried this via postman , it worked good.

But I tried this via curl in centos, it didn't work like below at wlan stats.

1) Login :

curl -G 'https://192.168.40.241/admin/login.jsp?username=admin&action=login.jsp&password=ruckus1234&ok=ruckus' --insecure -I -s | grep CSRF_TOKEN | awk '{print $2}'

vxCkT3sqRh
-> It is worked.

2) Get wlan stats

curl -i -k -X POST \
-H "X-CSRF-Token:vxCkT3sqRh" \
-H "Content-Type:text/xml" \
-d \
'<ajax-request action=\''getstat\'' comp=\''stamgr\'' enable-gzip="0" caller="SCI">
<vap INTERVAL-STATS="yes" INTERVAL-START="1604710474" INTERVAL-STOP="1605315274" LEVEL=\''1\''/>
</ajax-request>' \
'https://192.168.40.241/admin/_cmdstat.jsp'

-> It didn't work like below.

<html><head><title>Moved Temporarily</title></head>
<body><h1>Moved Temporarily</h1>
<p>The document has moved <a href="https://192.168.40.241/admin/login.jsp">here</a>.</p>
<address> at https:443 Port 443</address></body>
</html>

How do I apply at curl?

 

1 ACCEPTED SOLUTION

Well unfortunately the output is xml, so you'll need some basic bash scripting to extract out the info you want.

Here is a bash script which calls the wlan stats:-

ZD='192.168.40.241'
ZD_USERNAME='admin'
ZD_PASSWORD='ruckus1234'

# create a cookie jar
ZD_COOKIE=$(mktemp)

# sniff login url
ZD_LOGIN_URL="$(curl https://$ZD -k -s -L -I -o /dev/null -w '%{url_effective}')"
# login and collect token and session cookie
ZD_XSS="$(curl $ZD_LOGIN_URL -k -s -c $ZD_COOKIE  -d username=$ZD_USERNAME -d password=$ZD_PASSWORD -d ok=Log\ In -i | awk '/^HTTP_X_CSRF_TOKEN:/ { print $2 }' | tr -d '\040\011\012\015')"
ZD_CONF="$(dirname $ZD_LOGIN_URL)/_cmdstat.jsp"

# calculate the interval start and end time
INTERVAL_STOP=$(date +%s)
INTERVAL_START=$(date -d '24 hours ago' +%s)

# get wlan stats for the calculated interval
curl $ZD_CONF -H "X-CSRF-Token: $ZD_XSS" -k -s -b $ZD_COOKIE -c $ZD_COOKIE --data-raw "<ajax-request action=\"getstat\" comp=\"stamgr\" enable-gzip=\"0\" caller=\"SCI\"><vap INTERVAL-STATS=\"yes\" INTERVAL-START=\"$INTERVAL_START\" INTERVAL-STOP=\"$INTERVAL_STOP\" LEVEL=\"1\"/></ajax-request>"

# remove cookie jar
rm $ZD_COOKIE

 

View solution in original post

7 REPLIES 7

ms264556
Contributor III

I have a small bash script here if you want to crib the useful bits (especially the logon part and keeping track of the cookies).

Since every Linux comes with python3 these days, you might find it easier to just write a python script.

Jeronimo
New Contributor III

Hi ms264556.

Thanks for reply.

But I'm not a expert for bash script.

That's too difficult script for me. ^^;

Jeronimo
New Contributor III

Hi ms264556.

Thanks for reply.

But I'm not a expert for bash script.

That's too difficult script for me. ^^;

 

Well unfortunately the output is xml, so you'll need some basic bash scripting to extract out the info you want.

Here is a bash script which calls the wlan stats:-

ZD='192.168.40.241'
ZD_USERNAME='admin'
ZD_PASSWORD='ruckus1234'

# create a cookie jar
ZD_COOKIE=$(mktemp)

# sniff login url
ZD_LOGIN_URL="$(curl https://$ZD -k -s -L -I -o /dev/null -w '%{url_effective}')"
# login and collect token and session cookie
ZD_XSS="$(curl $ZD_LOGIN_URL -k -s -c $ZD_COOKIE  -d username=$ZD_USERNAME -d password=$ZD_PASSWORD -d ok=Log\ In -i | awk '/^HTTP_X_CSRF_TOKEN:/ { print $2 }' | tr -d '\040\011\012\015')"
ZD_CONF="$(dirname $ZD_LOGIN_URL)/_cmdstat.jsp"

# calculate the interval start and end time
INTERVAL_STOP=$(date +%s)
INTERVAL_START=$(date -d '24 hours ago' +%s)

# get wlan stats for the calculated interval
curl $ZD_CONF -H "X-CSRF-Token: $ZD_XSS" -k -s -b $ZD_COOKIE -c $ZD_COOKIE --data-raw "<ajax-request action=\"getstat\" comp=\"stamgr\" enable-gzip=\"0\" caller=\"SCI\"><vap INTERVAL-STATS=\"yes\" INTERVAL-START=\"$INTERVAL_START\" INTERVAL-STOP=\"$INTERVAL_STOP\" LEVEL=\"1\"/></ajax-request>"

# remove cookie jar
rm $ZD_COOKIE