2021-05-20 22:11:48 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
source "${cfg[namespace]}/code/func.sh"
|
|
|
|
|
|
|
|
|
|
json="$(jq -r '.[] | select(.type == "request") | "\(.label)<29>\(.data.url)<29>\(.data.method)<29>\(.data.match)<29>\(.data.string)<29>\(.data.data)"' < storage/appconfig/$1.json)"
|
|
|
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
|
for i in $json; do
|
|
|
|
|
label="$(awk -F<> '{print $1}' <<< "$i")"
|
2021-06-10 22:57:41 +02:00
|
|
|
|
if [[ "$label" != '' ]]; then
|
|
|
|
|
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
|
|
|
|
url="$(awk -F<> '{print $2}' <<< "$i")"
|
|
|
|
|
method="$(awk -F<> '{print $3}' <<< "$i")"
|
|
|
|
|
match="$(awk -F<> '{print $4}' <<< "$i")"
|
|
|
|
|
string="$(awk -F<> '{print $5}' <<< "$i")"
|
|
|
|
|
data="$(awk -F<> '{print $6}' <<< "$i")"
|
2021-05-20 22:11:48 +02:00
|
|
|
|
|
2021-06-10 22:57:41 +02:00
|
|
|
|
[[ "$method" == '' ]] && method="GET"
|
|
|
|
|
|
|
|
|
|
if [[ "$match" == "body" ]]; then
|
|
|
|
|
res="$(curl -A "${cfg[useragent]}" -s -X "$method" "$url" --data "$data" | grep -E "$string")"
|
|
|
|
|
status=$?
|
|
|
|
|
elif [[ "$match" == "head" ]]; then
|
|
|
|
|
res="$(curl -A "${cfg[useragent]}" -sD - -o /dev/null -X "$method" "$url" --data "$data" | grep -E "$string")"
|
|
|
|
|
status=$?
|
|
|
|
|
elif [[ "$match" == "status" ]]; then
|
|
|
|
|
res="$(curl -A "${cfg[useragent]}" -sD - -o /dev/null -X "$method" "$url" --data "$data" | grep -E "HTTP.*? $string")"
|
|
|
|
|
status=$?
|
|
|
|
|
fi
|
2021-05-20 22:11:48 +02:00
|
|
|
|
|
2021-06-10 22:57:41 +02:00
|
|
|
|
unset json_res
|
|
|
|
|
declare -A json_res
|
|
|
|
|
json_res[type]="req"
|
|
|
|
|
json_res[label]="$label"
|
|
|
|
|
json_res[status]="$status"
|
|
|
|
|
json_res[res]="$res"
|
|
|
|
|
json_res[date]="$(date "+%T %d.%m.%y")"
|
|
|
|
|
|
|
|
|
|
json_object json_res >> "storage/data/$label_sha"
|
|
|
|
|
if [[ "$status" == 0 && -f "storage/reports/$label_sha" ]]; then
|
|
|
|
|
rm "storage/reports/$label_sha"
|
|
|
|
|
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
|
|
|
|
notify "$notify" 0
|
|
|
|
|
fi
|
2021-05-20 22:11:48 +02:00
|
|
|
|
fi
|
|
|
|
|
done
|
2021-06-10 22:57:41 +02:00
|
|
|
|
|
|
|
|
|
cleanup
|