diff --git a/html/index.html b/html/index.html index 1b8ed31..3520923 100644 --- a/html/index.html +++ b/html/index.html @@ -34,10 +34,10 @@

Fawkes

Protect your images from facial recognition.

TODO: add more info

+

The table below shows the status for each image you've uploaded. You can select the files you want to protect using the Browse and Upload buttons below.

-
-

The table below shows the status for each image you've uploaded. You can select the files you want to protect using the Browse and Upload buttons below.

+
@@ -48,7 +48,7 @@
-
+
@@ -66,6 +66,9 @@ +
+
+ @@ -161,8 +164,9 @@ document.getElementById("button-start").addEventListener("click", function(){ return; } - // Disable button + // Disable button and upload document.getElementById("button-start").style.display = "none"; + document.getElementById("upload-area").style.display = "none"; // Send server request to start Fawkes socket.emit("FAWKES_START"); @@ -179,7 +183,7 @@ socket.on("FAWKES_STARTED", function(){ socket.on("FAWKES_STATE", function(data){ // Update state - if(data.done){ + if(data.face > data.numFaces){ document.getElementById("status-"+data.name).innerHTML = "   Processing Complete"; }else if(data.numFaces == 0){ document.getElementById("status-"+data.name).innerHTML = "   No Faces Detected"; @@ -188,6 +192,25 @@ socket.on("FAWKES_STATE", function(data){ } }); +socket.on("FAWKES_DONE", function(data){ + // When fawkes exited + if(data.success){ + // Download ready + var page = ""; + page += "
   Processing Complete
"; + page += "

Your images have been protected!

"; + page += "   Download"; + document.getElementById("download-area").innerHTML = page; + + }else{ + // Error + var page = ""; + page += "
   Processing Failed
"; + page += "

"+data.message+"

"; + document.getElementById("download-area").innerHTML = page; + } +}); + diff --git a/main.js b/main.js index 75ed1b2..4858e53 100644 --- a/main.js +++ b/main.js @@ -24,13 +24,14 @@ const fs = require("fs"); const util = require("util"); const crypto = require("crypto"); const spawn = require("child_process").spawn; +const exec = require("child_process").exec; // Vars const hostname = "192.168.0.128"; // Enter your local IP address here const port = 8001; // Enter a port number here var files = {}; -var lastImageId; +var fawkes = {}; // Create HTTP server @@ -43,9 +44,15 @@ const server = http.createServer((req, res) => { // Respond to requests try{ // Return requested page - res.statusCode = 200; - res.write(fs.readFileSync("html"+reqpath)); - res.end(); + if(reqpath.startsWith("/dl/")){ + res.statusCode = 200; + res.write(fs.readFileSync("fawkes/files/"+reqpath.substr(4))); + res.end(); + }else{ + res.statusCode = 200; + res.write(fs.readFileSync("html"+reqpath)); + res.end(); + } }catch(error){ // 404 if page not found @@ -76,7 +83,12 @@ io.on("connection", (socket) => { console.log(userId+": disconnect"); // Remove all files from this user - fs.rmSync("fawkes/files/"+userId, {recursive: true}); + try{ + fs.rmSync("fawkes/files/"+userId, {recursive: true}); + fs.rmSync("fawkes/files/"+userId+"cloaked", {recursive: true}); + }catch(error){ + console.log(userId+": couldn't delete some files"); + } }); // File upload @@ -99,7 +111,7 @@ io.on("connection", (socket) => { // Create file var name = data.name; - var path = "fawkes/files/"+userId+"/"+name; + var path = "fawkes/files/"+userId+"/"+name+".png"; var file = { length: data.length, name: data.name, @@ -167,33 +179,79 @@ io.on("connection", (socket) => { // Start binary var process = spawn("fawkes/protection", ["-d", "fawkes/files/"+userId, "--mode", "low"]); + // Update vars + fawkes[userId] = { + running: true, + images: [], + imageSentDone: [] + }; + // Add listeners process.stdout.setEncoding("utf8"); process.stdout.on("data", function(data){ // Received output from process + data = data.toString(); console.log("fawkes stdout: "+data); // Parse output - data = data.replace("\n", " "); - var splices = data.split(" "); - if(data.startsWith("Find ")){ - var numFaces = splices[1]; - var imageId = splices[4]; - console.log("fawkes found "+numFaces+" faces in image "+imageId); + var lines = data.split("\n"); + for(var l=0; l { process.on("close", function(code){ // Fawkes exited console.log("Fawkes exited with code "+code); + + // Check if success + if(code == 0){ + // Create archive + console.log("creating archive..."); + var archiveName = "fawkes-"+Date.now()+"-"+userId+".tar.gz"; + var child = exec( + "mkdir fawkes/files/"+userId+"cloaked && "+ + "mv fawkes/files/"+userId+"/*_cloaked* fawkes/files/"+userId+"cloaked/ && "+ + "tar -czvf fawkes/files/"+archiveName+" -C fawkes/files/"+userId+"cloaked ." + , (error, stdout, stderr) => { + console.log("archive creation done: "+error+", "+stdout+", "+stderr); + // Zip done + if(error){ + socket.emit("FAWKES_DONE", {success:false, message:"Internal server error. Couldn't create archive."}); + }else{ + socket.emit("FAWKES_DONE", {success:true, downloadUrl:"/dl/"+archiveName}); + } + }); + + }else{ + // Error + socket.emit("FAWKES_DONE", {success:false, message:"Internal server error. Fawkes exited with an exception."}); + } }); // Update file states