Return images in chronological order

This commit is contained in:
Kuba Orlik 2022-05-27 15:49:56 +02:00
parent a0fea094f5
commit e38daf52de
4 changed files with 34 additions and 32 deletions

View File

@ -40,7 +40,7 @@ annotate_header(){
all_positions=$(python ./get-text-position.py "$cropped_filename" ) all_positions=$(python ./get-text-position.py "$cropped_filename" )
END=$(date +%s.%N) END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
echo "{'ocr_took': '${DIFF}s'}" echo "{\"ocr_took\": \"${DIFF}s\"}"
while [ $# -gt 0 ] while [ $# -gt 0 ]
do do
@ -87,16 +87,16 @@ annotate_header(){
shift shift
END=$(date +%s.%N) END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
echo "{'annotation_took': '${DIFF}s'}" echo "{\"annotation_took\": \"${DIFF}s\"}"
done done
START=$(date +%s.%N) START=$(date +%s.%N)
convert "$filename" "$overlay_filename" -compose Darken -composite "${annotated_filename}.step.png" convert "$filename" "$overlay_filename" -compose Darken -composite "${annotated_filename}.step.png"
convert "${annotated_filename}.step.png" "$hardoverlay_filename" -compose src-over -composite "$annotated_filename" convert "${annotated_filename}.step.png" "$hardoverlay_filename" -compose src-over -composite "$annotated_filename"
rm "$overlay_filename" "$annotated_filename.step.png" "$hardoverlay_filename" "$cropped_filename" "$filename" rm "$overlay_filename" "$annotated_filename.step.png" "$hardoverlay_filename" "$cropped_filename" "$filename"
echo "{'new_file': \"${BASE_URL}/$(echo "$annotated_filename" | sed 's|/opt/||')\"}" echo "{\"new_file\": \"${BASE_URL}/$(echo "$annotated_filename" | sed 's|/opt/||')\"}"
END=$(date +%s.%N) END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
echo "{'composition_took': '${DIFF}s'}" echo "{\"composition_took\": \"${DIFF}s\"}"
} }
#annotate_header "set-cookie" "identyfikator internetowy z cookie" "Cookie" "identyfikator internetowy z cookie" #annotate_header "set-cookie" "identyfikator internetowy z cookie" "Cookie" "identyfikator internetowy z cookie"

View File

@ -13,17 +13,23 @@ DOMAINS=`node array-to-lines.js "$(echo $INPUT | jq .third_party_domains)"`
source ./utils.sh source ./utils.sh
source ./annotate_header.sh source ./annotate_header.sh
echo "{'current_action': 'Setting up X environment...'}" echo "{\"current_action\": \"Setting up X environment...\"}"
source ./ephemeral-x.sh source ./ephemeral-x.sh
# (while true; do
# grab_screen_to_public $ID PREVIEW="FALSE" # set to "TRUE" in order to enable automatic screenshots kept in preview.png
# sleep 1
# done) & if [ "$PREVIEW" = "TRUE" ];
# refresher_pid=$!; then
(while true; do
grab_screen_to_public $ID
sleep 1
done) &
refresher_pid=$!;
fi
echo "{'current_action': 'Starting firefox...'}" echo "{\"current_action\": \"Starting firefox...\"}"
start_firefox start_firefox
grab start_firefox grab start_firefox
prepare_firefox prepare_firefox
@ -45,7 +51,7 @@ while IFS= read -r DOMAIN; do
if [ "$DOMAIN" = "" ]; then if [ "$DOMAIN" = "" ]; then
continue continue
fi fi
echo "{'current_action': 'scanning for requests from $DOMAIN...'}" 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:$DOMAIN" # can filter with more granularity: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_list#filtering_by_properties
grab ni_search grab ni_search
@ -70,9 +76,12 @@ while IFS= read -r DOMAIN; do
done done
done <<< "$DOMAINS" done <<< "$DOMAINS"
# kill $refresher_pid; if [ "$PREVIEW" = "TRUE" ];
then
kill $refresher_pid;
fi
echo "{'current_action': 'awaiting al background processes...'}" echo "{\"current_action\": \"awaiting al background processes...\"}"
for PID in "${pids[@]}" for PID in "${pids[@]}"
do do

View File

@ -14,7 +14,7 @@ _get_pixel_color(){
magick $output_path -format "%[hex:p{$x,$y}]" info: magick $output_path -format "%[hex:p{$x,$y}]" info:
END=$(timestamp) END=$(timestamp)
DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
echo "{'getting_pixel_color_took': '${DIFF}ms'}" > /dev/stderr echo "{\"getting_pixel_color_took\": \"${DIFF}ms\"}" > /dev/stderr
} }
@ -144,7 +144,7 @@ load_website(){
xdotool key Return xdotool key Return
grab enter grab enter
sleep 1 sleep 1
echo "{'current_action': 'waiting for $URL to load...'}" echo "{\"current_action\": \"waiting for $URL to load...\"}"
times=0 times=0
while [ $(get_pixel_color 143 122) = "#2e3436" ] # the center of the X icon that becomes a "refresh" icon once the website is finished loading while [ $(get_pixel_color 143 122) = "#2e3436" ] # the center of the X icon that becomes a "refresh" icon once the website is finished loading
do do
@ -154,11 +154,11 @@ load_website(){
times=$((times + 1)) times=$((times + 1))
if [ $times -eq 30 ] if [ $times -eq 30 ]
then then
echo "{'current_action': 'website load timeout, proceeding anyway...'}" echo "{\"current_action\": \"website load timeout, proceeding anyway...\"}"
break; break;
fi fi
done done
echo "{'current_action': 'website loaded'}" echo "{\"current_action\": \"website loaded\"}"
} }
open_network_inspector(){ open_network_inspector(){

View File

@ -1,9 +1,7 @@
const { q, requests } = require("./memory"); const { q, requests } = require("./memory");
const DOCKER_ARGS = require("./docker-args"); const DOCKER_ARGS = require("./docker-args");
const { v4: uuid } = require("uuid"); const { v4: uuid } = require("uuid");
const { promises: fs } = require("fs");
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const { resolve } = require("path");
module.exports = class ScreenshotRequest { module.exports = class ScreenshotRequest {
constructor(url, domains) { constructor(url, domains) {
@ -24,17 +22,6 @@ module.exports = class ScreenshotRequest {
requests[this.id] = this; requests[this.id] = this;
} }
async getImages() {
try {
const files = await fs.readdir(resolve(__dirname, "./static/" + this.id));
return files
.filter((file) => file.match(/.final.png$/))
.map((file) => `/static/${this.id}/${file}`);
} catch (e) {
return [];
}
}
async getJSON() { async getJSON() {
return { return {
url: this.url, url: this.url,
@ -42,7 +29,7 @@ module.exports = class ScreenshotRequest {
id: this.id, id: this.id,
status: this.status, status: this.status,
output: this.output, output: this.output,
files: await this.getImages(), images: this.images,
request_time: this.request_time, request_time: this.request_time,
started_time: this.started_time, started_time: this.started_time,
finished_time: this.finished_time, finished_time: this.finished_time,
@ -88,6 +75,12 @@ module.exports = class ScreenshotRequest {
} }
}); });
this.process.stdout.on("data", (d) => { this.process.stdout.on("data", (d) => {
try {
const parsed = JSON.parse(d.toString());
if (parsed.new_file) {
this.images.push(parsed.new_file);
}
} catch (e) {}
this.output += d.toString(); this.output += d.toString();
/* console.log("DATA!", d.toString()); */ /* console.log("DATA!", d.toString()); */
}); });