Files
FemaTests/req.sh
2025-12-04 10:10:40 +03:00

241 lines
11 KiB
Bash
Executable File

CFG="LOCAL"
# CFG="POLYGON"
# CFG="KRBL"
# CFG="EKB"
MFA_OFF="YES"
source .env
if [ $CFG == "LOCAL" ]; then
ADDR=$LOCAL_ADDR
LOGIN=$LOCAL_LOGIN
PASSWORD=$LOCAL_PASSWORD
MASTER_CODE=$LOCAL_MASTER_CODE
elif [ $CFG == "EKB" ]; then
ADDR=$EKB_ADDR
LOGIN=$EKB_LOGIN
PASSWORD=$EKB_PASSWORD
MASTER_CODE=$EKB_MASTER_CODE
elif [ $CFG == "KRBL" ]; then
ADDR=$KRBL_ADDR
LOGIN=$KRBL_LOGIN
PASSWORD=$KRBL_PASSWORD
MASTER_CODE=$KRBL_MASTER_CODE
elif [ $CFG == "POLYGON" ]; then
ADDR=$POLYGON_ADDR
LOGIN=$POLYGON_LOGIN
PASSWORD=$POLYGON_PASSWORD
MASTER_CODE=$POLYGON_MASTER_CODE
fi
#set -x
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 [ "$MFA_OFF" != "YES" ]; then
if [[ $(echo $RESP | jq '.message') != "\"OK\"" ]]; then
echo "Failed to login1"
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")
fi
if [[ $(echo $RESP | jq '.message') != "\"OK\"" ]]; then
echo "Failed to login2"
echo $RESP | jq '.error'
exit 1
fi
echo "Login success!"
echo $RESP | jq ".data" | tr -d "\"" > tmp.token
elif [[ $1 == "update-user" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{\"username\": \"admin\", \"email\": \"yotia@unprism.ru\", \"full_name\": \"oaf\", \"is_admin\": true}" \
"$ADDR/auth/updateUser"
elif [[ $1 == "groups" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/transport/groups"
elif [[ $1 == "list-groups" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/transport/listAllGroups"
elif [[ $1 == "users" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" "$ADDR/system/getUsers"
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 == "export-backup" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"startTime\": $(($(date +%s)-20000)), \"endTime\": $(date +%s) }" \
"$ADDR/data/backup/export" --output export.zip
elif [[ $1 == "export-logs" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"], \"start\": 1, \"end\": $(date +%s), \"timezone\": \"GMT+03:00\"}" \
"$ADDR/data/logs/exportLogsReport" | jq
elif [[ $1 == "export-alarms" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"], \"start\": 1, \"end\": $(date +%s), \"timezone\": \"GMT+03:00\"}" \
"$ADDR/data/alarms/exportIncidentsReport" | jq
elif [[ $1 == "export-sensors-readings" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"], \"sensors\": [\"TEMPERATURE/85\"], \"start\": 1, \"end\": $(date +%s), \"timezone\": \"GMT+03:00\"}" \
"$ADDR/data/sensors/exportSensorReadings" | jq
elif [[ $1 == "export-alarm-settings" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"] }" \
"$ADDR/data/alarms/exportIncidentDetectionSensorSettingsReport" | jq
elif [[ $1 == "export-vehicle" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"] }" \
"$ADDR/data/exportVehiclesReport" | jq
elif [[ $1 == "get-from-redis" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
"$ADDR/data/getDataFromRedis?fileID=$2"
elif [[ $1 == "alarms-amount" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d '{ "start_time": 1761226492158, "end_time": 1761140092158 }' \
"$ADDR/data/alarms/getAlarmsAmount" | jq
elif [[ $1 == "alarms-amount-per-device" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d '{ "start_time": 0, "end_time": 0, "active": false }' \
"$ADDR/data/alarms/getGroupAlarmsAmountPerDevice" | jq
elif [[ $1 == "alarms" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [\"A56AF66F17D902B8\"], \"start_time\": 1, \"end_time\": $(date +%s), \"order\": [[\"sensor_id\", \"+\"]], \"page_number\": 1, \"page_size\": 30}" \
"$ADDR/data/alarms/getAlarms" | jq
elif [[ $1 == "geo" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"requests\": [ { \"type\": 2, \"mark\": \"$2\" } ] }" \
"$ADDR/data/geo/getSerial" | jq
elif [[ $1 == "argus" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
"$ADDR/settings/argusServerAddr?device=A56AF66F17D902B8" | jq
elif [[ $1 == "argus1" ]]; then
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"device\": \"A56AF66F17D902B8\", \"addr\": \"test-addr1\" }" \
"$ADDR/settings/argusServerAddr" | jq
elif [[ $1 == "argus2" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
"$ADDR/settings/argusSerial?device=A56AF66F17D902B8" | jq
elif [[ $1 == "argus3" ]]; then
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"device\": \"A56AF66F17D902B8\", \"argusSerial\": \"argus-test-erial\" }" \
"$ADDR/settings/argusSerial" | jq
elif [[ $1 == "device-group" ]]; then
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
"$ADDR/settings/deviceGroup?device=A56AF66F17D902B8" | jq
elif [[ $1 == "device-group1" ]]; then
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"device\": \"A56AF66F17D902B8\", \"group\": 3 }" \
"$ADDR/settings/deviceGroup" | jq
elif [[ $1 == "logs-amount" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [ \"A56AF66F17D902B8\" ] }" \
"$ADDR/data/logs/getLogsAmount" | jq
elif [[ $1 == "logs" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"devices\": [ \"A56AF66F17D902B8\" ], \"page_number\": 1, \"page_size\": 1000, \"search\": \"test%\", \"order\": [ [\"time\", \"+\" ] ] }" \
"$ADDR/data/logs/getLogs" | jq
elif [[ $1 == "transport-group-create" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"name\": \"test-group-1\" }" \
"$ADDR/transport/createGroup" | jq
elif [[ $1 == "sensor-data" ]]; then
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"device\": \"A56AF66F17D902B8\", \"sensor\": \"TEMPERATURE/85\", \"start\": $(($(date +%s)-5000)), \"end\": $(date +%s), \"skip\": 1 }" \
"$ADDR/data/sensors/getDeviceSensorData" | jq
elif [[ $1 == "factory-models" ]]; then
if [[ $2 == "" ]]; then
echo "No serial presented"
exit 1
fi
curl -X GET -s -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" -d "{ \"ids\": $2 }" "$ADDR/data/getFactoryModels" | jq
elif [[ $1 == "grouped-sensors" ]]; 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 "{ \"devices\": [\"$2\"] }" "$ADDR/data/sensors/getGroupedDevicesSensors" | jq
elif [[ $1 == "multi-device-sensors" ]]; then
if [[ $2 == "" ]]; then
echo "No group presented"
exit 1
fi
if [[ $3 == "" ]]; then
echo "No devices presented"
exit 1
fi
curl -X POST -s -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" -d "{ \"group\": \"$2\", \"devices\": [$3] }" "$ADDR/data/sensors/getMultiDeviceSensors" | jq
elif [[ $1 == "device-params-v2" ]]; 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/deviceSettingsV2" | jq
elif [[ $1 == "connected-chart" ]]; then
curl -X POST -s -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
-d "{ \"start_time\": 1757867195, \"end_time\": 1757937195 }" "$ADDR/data/getConnectedDevicesChart" | jq
elif [[ $1 == "connected-chart-v2" ]]; then
curl -X GET -s -H "Content-Type: application/json" -H "Authorization: Bearer $(cat tmp.token)" \
"$ADDR/data/getConnectedDevicesChartV2" | jq
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-device-params-v2" ]]; 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/deviceSettingsV2" --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