mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-02 11:47:47 +00:00
747 lines
26 KiB
Bash
Executable File
747 lines
26 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
# License type: BSD 3-Clause License
|
|
# License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
|
#
|
|
# Created by Stephane Bourque on 2021-03-04.
|
|
# Arilia Wireless Inc.
|
|
#
|
|
|
|
if [[ "$(which jq)" == "" ]]
|
|
then
|
|
echo "You need the package jq installed to use this script."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$(which curl)" == "" ]]
|
|
then
|
|
echo "You need the package curl installed to use this script."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "${OWSEC}" == "" ]]
|
|
then
|
|
echo "You must set the variable OWSEC in order to use this script. Something like"
|
|
echo "OWSEC=security.isp.com:16001"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "${FLAGS}" == "" ]]
|
|
then
|
|
FLAGS="-s"
|
|
fi
|
|
|
|
token=""
|
|
result_file=result.json
|
|
username="tip@ucentral.com"
|
|
password="Snoopy99!!!"
|
|
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
|
browser=""
|
|
|
|
login() {
|
|
payload="{ \"userId\" : \"$username\" , \"password\" : \"$password\" }"
|
|
token=$(curl ${FLAGS} -X POST -H "Content-Type: application/json" -d "$payload" "https://${OWSEC}/api/v1/oauth2" | jq -r '.access_token')
|
|
|
|
if [[ "${token}" == "" ]]
|
|
then
|
|
echo "Could not login. Please verify the host and username/password."
|
|
exit 13
|
|
fi
|
|
echo "${token}" > token.json
|
|
setgateway
|
|
}
|
|
|
|
findbrowser() {
|
|
if [[ "${browser}" != "" ]]
|
|
then
|
|
echo
|
|
elif [[ "$(uname)" == "Darwin" ]]
|
|
then
|
|
browser=open
|
|
else
|
|
BROWSER_LIST=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
|
for br_name in "${browser_list[@]}"
|
|
do
|
|
if [[ $(which ${br_name}) != "" ]]
|
|
then
|
|
browser=${br_name}
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
setgateway() {
|
|
curl ${FLAGS} -X GET "https://${OWSEC}/api/v1/systemEndpoints" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
# jq < ${result_file}
|
|
|
|
for index in {0..10}
|
|
do
|
|
endpointlocation=".endpoints[${index}].uri"
|
|
endpointlocationtype=".endpoints[${index}].type"
|
|
rawurl="$(cat ${result_file} | jq -r ${endpointlocation})"
|
|
svctype="$(cat ${result_file} | jq -r ${endpointlocationtype})"
|
|
proto="$(echo $rawurl | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
|
url="$(echo ${rawurl/$proto/})"
|
|
user="$(echo $url | grep @ | cut -d@ -f1)"
|
|
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
|
|
host="$(echo $hostport | sed -e 's,:.*,,g')"
|
|
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
|
path="$(echo $url | grep / | cut -d/ -f2-)"
|
|
if [[ ${url} != "null" ]]
|
|
then
|
|
if [[ ${svctype} == "owgw" ]]
|
|
then
|
|
# echo "url: $url"
|
|
# echo " proto: $proto"
|
|
# echo " user: $user"
|
|
# echo " host: $host"
|
|
# echo " port: $port"
|
|
# echo " path: $path"
|
|
OWGW="${url}"
|
|
break
|
|
fi
|
|
fi
|
|
done
|
|
# echo "Using ${OWGW}..."
|
|
}
|
|
|
|
logout() {
|
|
curl ${FLAGS} -X DELETE -H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
"https://${OWSEC}/api/v1/oauth2/${token}"
|
|
rm -rf token.json
|
|
}
|
|
|
|
getdevice() {
|
|
curl ${FLAGS} -X GET --url "https://${OWGW}/api/v1/device/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
getcommand() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/command/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletecommand() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/command/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
listcommands() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/commands?serialNumber=$1&limit=300" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
newestcommands() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/commands?serialNumber=$1&newest=true&limit=50" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletecommands() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/commands?serialNumber=$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
getcapabilities() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/capabilities" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletecapabilities() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/device/$1/capabilities" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
listdevices() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
ldevs() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices?offset=$1&limit=$2" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletedevice() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/device/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
deleteoui() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/device/$1?oui=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
|
|
createdevice() {
|
|
payload="{ \"serialNumber\": \"$1\", \"UUID\": 1234456, \"configuration\" : $(cat "$2") , \"deviceType\": \"AP\",\"location\": \"\", \"macAddress\": \"$3\", \"manufacturer\": \"Linksys EA8300 (Dallas)\", \"owner\": \"\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
addnote() {
|
|
payload="{ \"serialNumber\": \"$1\", \"notes\" : [ {\"note\" : \"$2\"} ] }"
|
|
curl ${FLAGS} -X PUT "https://${OWGW}/api/v1/device/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
reboot() {
|
|
payload="{ \"serialNumber\" : \"$1\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/reboot" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
setloglevel() {
|
|
payload="{ \"command\" : \"setloglevel\" , \"subsystems\" : [ { \"tag\" : \"$1\" , \"value\" : \"$2\" } ] }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/system" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
getloglevels() {
|
|
payload="{ \"command\" : \"getloglevels\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/system" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
getloglevelnames() {
|
|
payload="{ \"command\" : \"getloglevelnames\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/system" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
getsubsystemnames() {
|
|
payload="{ \"command\" : \"getsubsystemnames\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/system" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
systeminfo() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/system?command=info" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
reloadsubsystem() {
|
|
payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"$1\" ] }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/system" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
getdevicestatus() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/status" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
upgrade() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"uri\" : \"$2\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/upgrade" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
leds() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"duration\" : $3, \"pattern\" : \"$2\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/leds" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
factory() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"keepRedirector\" : $2 }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/factory" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
configure() {
|
|
payload="{ \"serialNumber\" : \"$1\", \"UUID\" : 123456 , \"configuration\" : $(cat "$2") }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/configure" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
request() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"message\" : \"$2\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/request" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
wifiscan() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"verbose\" : $2 }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/wifiscan" \
|
|
--max-time 20 \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
activescan() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"verbose\" : $2, \"activeScan\" : true}"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/wifiscan" \
|
|
--max-time 20 \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
trace() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"duration\" : $2, \"network\" : \"$3\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/trace" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
getstats() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/statistics" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
getlogs() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/logs" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletelogs() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/device/$1/logs" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
gethealthchecks() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/healthchecks" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
createdefaultconfig() {
|
|
payload="{ \"name\": \"$1\", \"modelIds\" : \"$2\", \"configuration\" : $(cat "$3")}"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/default_configuration/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deletedefaultconfig() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/default_configuration/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
jq < ${result_file}
|
|
}
|
|
|
|
listdefaultconfigs() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/default_configurations" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
addblacklistdevice() {
|
|
payload="{ \"serialNumber\": \"$1\" , \"reason\" : \"$2\" }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/blacklist" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload"
|
|
}
|
|
|
|
deleteblacklistdevice() {
|
|
curl ${FLAGS} -X DELETE "https://${OWGW}/api/v1/blacklist/$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}"
|
|
}
|
|
|
|
getblacklist() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/blacklist" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
eventqueue() {
|
|
payload="{ \"serialNumber\" : \"$1\" , \"types\" : [ \"dhcp\", \"wifi\" ] }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/eventqueue" \
|
|
--max-time 20 \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
selectdevices() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices?select=$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deviceserialnumbers() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices?serialOnly=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
deviceswithstatus() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices?deviceWithStatus=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
devicecount() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/devices?countOnly=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
getfile() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/file/$2?serialNumber=$1" \
|
|
-H "accept: application/octet-stream" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-o "$2.pcap"
|
|
}
|
|
|
|
rtty() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/rtty" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
|
|
cid=$(cat ${result_file} | jq -r '.connectionId')
|
|
vport=$(cat ${result_file} | jq -r '.viewport')
|
|
server=$(cat ${result_file} | jq -r '.server')
|
|
url=https://${server}:${vport}/connect/${cid}
|
|
|
|
findbrowser
|
|
if [[ "${browser}" != "" ]]
|
|
then
|
|
${browser} ${url}
|
|
fi
|
|
}
|
|
|
|
lifetimestats() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/statistics?lifetime=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
laststats() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/statistics?lastOnly=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
lasthealthcheck() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/healthchecks?lastOnly=true" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
neweststats() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/statistics?newest=true&limit=50" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
newestlogs() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/logs?newest=true&limit=50" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
newesthealthchecks() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/device/$1/healthchecks?newest=true&limit=50" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
ouilookup() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/ouis?macList=$1" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
dashboard() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/deviceDashboard" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
validateconfig() {
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/1?validateOnly=true" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-H "accept: application/json" \
|
|
-d @"$1" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
|
|
wstest() {
|
|
echo "Token:${token}"
|
|
wscat \
|
|
-c wss://${OWGW}/api/v1/ws
|
|
}
|
|
|
|
telemetry() {
|
|
payload="{ \"serialNumber\" : \"$1\", \"interval\" : 2 , \"types\" : [ \"wifi-frames\", \"dhcp-snooping\", \"state\" ] }"
|
|
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/telemetry" \
|
|
-H "accept: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-d "$payload" > ${result_file}
|
|
jq < ${result_file}
|
|
socket=$(jq -r '.uri' < result.json)
|
|
if [[ "$(which wscat)" == "" ]]
|
|
then
|
|
echo "wscat command not found. Cannot start a websocket session."
|
|
else
|
|
wscat \
|
|
-c "${socket}"
|
|
fi
|
|
}
|
|
|
|
caplist() {
|
|
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/capabilities" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer ${token}" \
|
|
-H "accept: application/json" > ${result_file}
|
|
jq < ${result_file}
|
|
}
|
|
|
|
|
|
help() {
|
|
echo
|
|
echo "getdevice <serial> Get the device JSON document."
|
|
echo "deletedevice <serial> Delete the device."
|
|
echo "createdevice <serial> <cfg> <MAC> Create a device using the default configuration."
|
|
echo "validateconfig <config file> Validate a configuration file."
|
|
echo " cfg: JSON config file name"
|
|
echo " <MAC>: string MAC Address"
|
|
echo "getdevicestatus <serial> Get the device status JSON document."
|
|
echo "getstats <serial> Get statistics for the device."
|
|
echo "gethealthchecks <serial> Get healthchecks for a device."
|
|
echo "newesthealthchecks <serial> Get newest healthchecks for a device."
|
|
echo "lasthealthcheck <serial> Get the last healthcheck"
|
|
echo "addnote <serial> <note> Add a notes to the notes section"
|
|
echo
|
|
echo "getcapababilities <serial> Get the device capabilities JSON document."
|
|
echo "deletecapababilities <serial> Delete the device capabilities JSON."
|
|
echo
|
|
echo "reboot <serial> Reboot the device."
|
|
echo "upgrade <serial> <URI> Do firmware upgrade for a device."
|
|
echo "leds <serial> <pattern> <d> Activate LEDs a device."
|
|
echo " pattern: on/off/blink"
|
|
echo " d: number in seconds"
|
|
echo "configure <serial> <cfg> Change configuration for a device."
|
|
echo " cfg must be valid JSON config."
|
|
echo "factory <serial> <true/false> Do factory reset for device. true=keep redirector, false=reset redirector"
|
|
echo "request <serial> <message> Force a message from the device."
|
|
echo " message=state/healthcheck"
|
|
echo "wifiscan <serial> <verbose> Do wifiscan for a device."
|
|
echo " verbose=true/false"
|
|
echo "active <serial> <verbose> Do an active wifiscan for a device."
|
|
echo " verbose=true/false"
|
|
echo "trace <serial> <d> <n> Launch a remote trace for a device."
|
|
echo " d=number of seconds"
|
|
echo " n=lan/wan"
|
|
echo
|
|
echo "getcommand <command-uuid> Get the command JSON document."
|
|
echo "deletecommand <command-uuid> Delete the command."
|
|
echo "newestcommands <serial> Get the newest commands for a device."
|
|
echo "listdevices List devices"
|
|
echo "listcommands <serial> List commands for a specific device"
|
|
echo "deletecommands <serial> Delete commands for a device."
|
|
echo
|
|
echo "getlogs <serial> Get logs for the device."
|
|
echo "newestlogs <serial> Get the latest logs for the device."
|
|
echo "deletelogs <serial> Delete logs for the device."
|
|
echo "eventqueue <serial> Request event queue for the device."
|
|
echo
|
|
echo "listdefaultconfigs List a default configurations"
|
|
echo "createdefaultconfig <name> <ids> <cfg> Create a default configuration"
|
|
echo " name=unique name, no spaces"
|
|
echo " ids=coma separated list of models"
|
|
echo " cfg=config file name"
|
|
echo "deletedefaultconfig <name> Delete a default configuration"
|
|
echo
|
|
echo "addblacklistdevice <serial> <r> Add a device to the black list"
|
|
echo " <r> Reason for blacklisting"
|
|
echo "getblacklist List all blacklisted devices"
|
|
echo "deleteblacklistdevice <serial> Add a device to the black list"
|
|
echo
|
|
echo "devicecount Get the number of devices in the DB"
|
|
echo "deviceserialnumbers Get only the serial numbers"
|
|
echo "selectdevices <serial list> get a list of serial numbers (must be comma separated)"
|
|
echo "deviceswithstatus Get devices with their status"
|
|
echo
|
|
echo "setloglevel <sys> <level> Set the logging system level for individual subsystems."
|
|
echo " sys:ufileuploader/websocket/storage/restapi/commandmanager/auth/deviceregistry/all"
|
|
echo " level:none/fatal/critical/error/warning/notice/information/debug/trace"
|
|
echo "getloglevels Get the log levels of all the subsystems"
|
|
echo "getloglevelnames Get the list of log level names possible"
|
|
echo "getsubsystemnames Get the subsystems that can be used when setting log levels."
|
|
echo "getfile <serial> <uuid> <name> Get the file associated with trace command <uuid> for device <serial>"
|
|
echo " The file will be saved with the name <name>"
|
|
echo
|
|
echo "rtty <serial> Get the details for an rtty session."
|
|
echo
|
|
echo "lifetimestats <serial> Get the lifetime stats counters for a device"
|
|
echo "laststats <serial> Get the last statistics for a device"
|
|
echo "neweststats <serial> Get the newest statistics for a device"
|
|
echo
|
|
echo "ouilookup <serial> Lookup an OUI"
|
|
echo
|
|
echo "dashboard Get the dashboard document"
|
|
echo "systeminfo Get information on the system running the service."
|
|
echo
|
|
echo "wstest Testing the WebSocket interface."
|
|
echo
|
|
echo
|
|
echo "To pass additional flags to the CURL command, create an environment variable called FLAGS and git ve the values you"
|
|
echo "want. For example, for force all call to use IPv6, set FLAGS=\"-6\", for verbose mode and IPv6, set FLAGS=\"-6 -v\""
|
|
echo
|
|
echo
|
|
}
|
|
|
|
shopt -s nocasematch
|
|
case "$1" in
|
|
"getdevice") login; getdevice "$2"; logout ;;
|
|
"help") login; help ; logout ;;
|
|
"getcommand") login; getcommand "$2" ; logout ;;
|
|
"deletecommand") login; deletecommand "$2" ; logout ;;
|
|
"getcapabilities") login; getcapabilities "$2" ; logout ;;
|
|
"deletecapabilities") login; deletecapabilities "$2" ; logout ;;
|
|
"listdevices") login; listdevices ; logout ;;
|
|
"deletedevice") login; deletedevice "$2" ; logout ;;
|
|
"deleteoui") login; deleteoui "$2" ; logout ;;
|
|
"createdevice") login; createdevice "$2" "$3" "$4" ; logout ;;
|
|
"reboot") login; reboot "$2" ; logout ;;
|
|
"getdevicestatus") login; getdevicestatus "$2" ; logout ;;
|
|
"upgrade") login; upgrade "$2" "$3" ; logout ;;
|
|
"factory") login; factory "$2" "$3" ; logout ;;
|
|
"leds") login; leds "$2" "$3" "$4" ; logout ;;
|
|
"listcommands") login; listcommands "$2" ; logout ;;
|
|
"deletecommands") login; deletecommands "$2" ; logout ;;
|
|
"configure") login; configure "$2" "$3" ; logout ;;
|
|
"request") login; request "$2" "$3" ; logout ;;
|
|
"wifiscan") login; wifiscan "$2" "$3" ; logout ;;
|
|
"activescan") login; activescan "$2" "$3" ; logout ;;
|
|
"trace") login; trace "$2" "$3" "$4" ; logout ;;
|
|
"getstats") login; getstats "$2" ; logout ;;
|
|
"getlogs") login; getlogs "$2" ; logout ;;
|
|
"deletelogs") login; deletelogs "$2" ; logout ;;
|
|
"gethealthchecks") login; gethealthchecks "$2" ; logout ;;
|
|
"createdefaultconfig") login; createdefaultconfig "$2" "$3" "$4" ; logout ;;
|
|
"deletedefaultconfig") login; deletedefaultconfig "$2" ; logout ;;
|
|
"listdefaultconfigs") login; listdefaultconfigs "$2" ; logout ;;
|
|
"addblacklistdevice") login; addblacklistdevice "$2" "$3" ; logout ;;
|
|
"deleteblacklistdevice") login; deleteblacklistdevice "$2" ; logout ;;
|
|
"getblacklist") login; getblacklist ; logout ;;
|
|
"eventqueue") login; eventqueue "$2" ; logout ;;
|
|
"selectdevices") login; selectdevices "$2" ; logout ;;
|
|
"deviceserialnumbers") login; deviceserialnumbers ; logout ;;
|
|
"devicecount") login; devicecount ; logout ;;
|
|
"deviceswithstatus") login; deviceswithstatus ; logout ;;
|
|
"getfile") login; getfile "$2" "$3" ; logout ;;
|
|
"rtty") login; rtty "$2" ; logout ;;
|
|
"lifetimestats") login; lifetimestats "$2"; logout;;
|
|
"laststats") login; laststats "$2"; logout;;
|
|
"newestcommands") login; newestcommands "$2"; logout;;
|
|
"neweststats") login; neweststats "$2"; logout;;
|
|
"newestlogs") login; newestlogs "$2"; logout;;
|
|
"newesthealthchecks") login; newesthealthchecks "$2"; logout;;
|
|
"lasthealthcheck") login; lasthealthcheck "$2"; logout;;
|
|
"login") login ;;
|
|
"findbrowser") findbrowser; echo "Browser: ${browser}" ;;
|
|
"setloglevel") login; setloglevel "$2" "$3" ; logout ;;
|
|
"getloglevels") login; getloglevels; logout ;;
|
|
"getloglevelnames") login; getloglevelnames; logout ;;
|
|
"getsubsystemnames") login; getsubsystemnames; logout ;;
|
|
"reloadsubsystem") login; reloadsubsystem; logout ;;
|
|
"systeminfo") login; systeminfo ; logout;;
|
|
"ouilookup") login; ouilookup "$2"; logout;;
|
|
"telemetry") login; telemetry "$2"; logout;;
|
|
"dashboard") login; dashboard ; logout;;
|
|
"addnote") login; addnote "$2" "$3"; logout;;
|
|
"ldevs") login; ldevs "$2" "$3"; logout ;;
|
|
"validateconfig") login; validateconfig "$2" ; logout ;;
|
|
"wstest") login; wstest; logout;;
|
|
"caplist") login; caplist; logout;;
|
|
*) help ;;
|
|
esac
|
|
|