screenshot-service/Docker/run-analysis.sh

90 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
export DISPLAY=:0
INPUT="$1"
ID=$2
unquote(){
echo $1 | sed 's/"//g'
}
URL=$(unquote $(echo $INPUT | jq .url))
DOMAINS=`node array-to-lines.js "$(echo $INPUT | jq .third_party_domains)"`
source ./utils.sh
PREVIEW="FALSE" # set to "TRUE" in order to enable automatic screenshots kept in preview.png
if [ "$PREVIEW" = "TRUE" ];
then
(while true; do
grab_screen_to_public $ID
sleep 1
done) &
refresher_pid=$!;
fi
load_website "$URL"
grab load_website
open_network_inspector
grab open_network_inspector
declare -a pids;
pids=()
index=0
mkdir -p "/opt/static/$ID"
while IFS= read -r DOMAIN; do
if [ "$DOMAIN" = "" ]; then
continue
fi
echo "{\"current_action\": \"scanning for requests from $DOMAIN...\"}"
# network_inspector_search "domain:$DOMAIN" # can filter with more granularity: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_list#filtering_by_properties
network_inspector_search "$DOMAIN" # the "domain:" prefix caused problems, as the GUI forces an autocomplete action. This can be worked around by pressing `ESC`, but if you press ESC when there are NO requests, then the console appears and messes up the layout.
# grab ni_search
count=0
while network_inspector_has_more_entries
do
filename="$ID/${index}.png"
scrot "/opt/static/$filename"
grab "searching $DOMAIN"
BASE_URL="$BASE_URL" python annotate_header.py "$filename" "$DOMAIN" \
"set-cookie" "identyfikator internetowy z cookie" \
"Cookie" "identyfikator internetowy z cookie" \
"Referer" "Część mojej historii przeglądania" &
pids+=($!)
network_inspector_next_entry
((index++))
((count++))
if [ $count -gt 10 ]; then
break;
fi
done
done <<< "$DOMAINS"
if [ "$PREVIEW" = "TRUE" ];
then
kill $refresher_pid;
fi
echo "{\"current_action\": \"awaiting al background processes...\"}"
for PID in "${pids[@]}"
do
wait $PID
done
kill -2 %%;
cleanup
echo "Done!"