74 lines
2.7 KiB
Bash
Executable File
74 lines
2.7 KiB
Bash
Executable File
#ADDR=api-fema.ekatgortrans.ru:39080
|
|
ADDR=https://api.fema.krbl.ru
|
|
#ADDR=62.217.183.88:8080
|
|
LOGIN=admin
|
|
PASSWORD=admin
|
|
#PASSWORD=ra8KvcMxS2baUxe*
|
|
#MASTER_CODE=342985
|
|
MASTER_CODE=111111
|
|
|
|
H="-H \"Authorization: Bearer $(cat tmp.token)\""
|
|
|
|
if [[ $1 == "login" ]]; then
|
|
# Login
|
|
RESP=$(curl -X POST -H "Content-Type: application/json" -d "{ \"login\": \"$LOGIN\", \"password\": \"$PASSWORD\" }" "$ADDR/auth/signin")
|
|
if [[ $(echo $RESP | jq '.message') != "\"OK\"" ]]; then
|
|
echo "Failed to login"
|
|
echo $RESP | jq '.error'
|
|
exit 1
|
|
fi
|
|
|
|
# 2FA
|
|
RESP=$(curl -X POST -H "Content-Type: application/json" "$ADDR/auth/2fa?login=$LOGIN&code=$MASTER_CODE")
|
|
if [[ $(echo $RESP | jq '.message') != "\"OK\"" ]]; then
|
|
echo "Failed to login"
|
|
echo $RESP | jq '.error'
|
|
exit 1
|
|
fi
|
|
|
|
echo "Login success!"
|
|
echo $RESP | jq ".data" | tr -d "\"" > tmp.token
|
|
elif [[ $1 == "devices" ]]; then
|
|
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/data/getDevices"
|
|
elif [[ $1 == "devices-serial" ]]; then
|
|
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/data/getDevices" | jq ".devices[] | .SERIAL" | tr -d "\""
|
|
elif [[ $1 == "devices-serial-with-reg" ]]; then
|
|
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/data/getDevices" | jq ".devices[] | (.SERIAL) +\" -- \"+ (.REG_NUMBER)" | tr -d "\""
|
|
elif [[ $1 == "devices-status" ]]; then
|
|
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/data/getDevices" | jq ".devices[] | (.SERIAL) +\" -- \"+ (.IS_CONNECTED|tostring)+\" -- \"+ (.REG_NUMBER)" | tr -d "\""
|
|
elif [[ $1 == "device-params" ]]; then
|
|
if [[ $2 == "" ]]; then
|
|
echo "No serial presented"
|
|
exit 1
|
|
fi
|
|
curl -X POST -s -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" -d "{ \"serial\": \"$2\" }" "$ADDR/settings/deviceSettings" | jq
|
|
elif [[ $1 == "set-device-params" ]]; then
|
|
if [[ $2 == "" ]]; then
|
|
echo "No params file presenter"
|
|
exit 1
|
|
fi
|
|
SERIAL=$(cat $2 | jq ".SERIAL")
|
|
if [[ $SERIAL == "" ]]; then
|
|
echo "File does not contain serial"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Settings device params for $SERIAL"
|
|
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/settings/deviceSettings" --data-binary @"$2"
|
|
elif [[ $1 == "set-ips" ]]; then
|
|
if [[ $2 == "" ]]; then
|
|
echo "No serial provided"
|
|
exit 1
|
|
fi
|
|
if [[ $3 == "" ]]; then
|
|
echo "No ips provided"
|
|
exit 1
|
|
fi
|
|
|
|
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" -d "{ \"serial\": \"$2\", \"ips\": $3 }" "$ADDR/settings/ips"
|
|
else
|
|
echo "Invalid method"
|
|
exit 1
|
|
fi
|
|
|