finished code for fawkes and archive creation
This commit is contained in:
parent
48fe04c4a9
commit
821163eeb3
|
@ -34,10 +34,10 @@
|
||||||
<h1>Fawkes</h1>
|
<h1>Fawkes</h1>
|
||||||
<p>Protect your images from facial recognition.</p>
|
<p>Protect your images from facial recognition.</p>
|
||||||
<p>TODO: add more info</p>
|
<p>TODO: add more info</p>
|
||||||
|
<p>The table below shows the status for each image you've uploaded. You can select the files you want to protect using the <i>Browse</i> and <i>Upload</i> buttons below.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div id="upload-area" class="container">
|
||||||
<p>The table below shows the status for each image you've uploaded. You can select the files you want to protect using the <i>Browse</i> and <i>Upload</i> buttons below.</p>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="twelve columns">
|
<div class="twelve columns">
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<button id="button-upload" class="button button-primary"><i class="fas fa-upload"></i> Upload</button>
|
<button id="button-upload" class="button button-primary"><i class="fas fa-upload"></i> Upload</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div id="table-area" class="container">
|
||||||
<table id="table-images" class="u-full-width">
|
<table id="table-images" class="u-full-width">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -66,6 +66,9 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="download-area" class="container">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<p>Many thanks to the people who made <a href="http://sandlab.cs.uchicago.edu/fawkes/">Fawkes</a>!<br/>Copyright © 2021 Thomas Van Acker<br/>Project hosted on <a target="_blank" href="https://git.bitscuit.be/bitscuit/Fawkes">Gitscuit</a></p>
|
<p>Many thanks to the people who made <a href="http://sandlab.cs.uchicago.edu/fawkes/">Fawkes</a>!<br/>Copyright © 2021 Thomas Van Acker<br/>Project hosted on <a target="_blank" href="https://git.bitscuit.be/bitscuit/Fawkes">Gitscuit</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -161,8 +164,9 @@ document.getElementById("button-start").addEventListener("click", function(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable button
|
// Disable button and upload
|
||||||
document.getElementById("button-start").style.display = "none";
|
document.getElementById("button-start").style.display = "none";
|
||||||
|
document.getElementById("upload-area").style.display = "none";
|
||||||
|
|
||||||
// Send server request to start Fawkes
|
// Send server request to start Fawkes
|
||||||
socket.emit("FAWKES_START");
|
socket.emit("FAWKES_START");
|
||||||
|
@ -179,7 +183,7 @@ socket.on("FAWKES_STARTED", function(){
|
||||||
|
|
||||||
socket.on("FAWKES_STATE", function(data){
|
socket.on("FAWKES_STATE", function(data){
|
||||||
// Update state
|
// Update state
|
||||||
if(data.done){
|
if(data.face > data.numFaces){
|
||||||
document.getElementById("status-"+data.name).innerHTML = "<i class='fas fa-check'></i> Processing Complete";
|
document.getElementById("status-"+data.name).innerHTML = "<i class='fas fa-check'></i> Processing Complete";
|
||||||
}else if(data.numFaces == 0){
|
}else if(data.numFaces == 0){
|
||||||
document.getElementById("status-"+data.name).innerHTML = "<i class='fas fa-check'></i> No Faces Detected";
|
document.getElementById("status-"+data.name).innerHTML = "<i class='fas fa-check'></i> 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 += "<h5><i class='fas fa-check'></i> Processing Complete</h5>";
|
||||||
|
page += "<p>Your images have been protected!</p>";
|
||||||
|
page += "<a class='button button-primary' href='"+data.downloadUrl+"' target='_blank'><i class='fas fa-download'></i> Download</a>";
|
||||||
|
document.getElementById("download-area").innerHTML = page;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
// Error
|
||||||
|
var page = "";
|
||||||
|
page += "<h5><i class='fas fa-exclamation-triangle'></i> Processing Failed</h5>";
|
||||||
|
page += "<p>"+data.message+"</p>";
|
||||||
|
document.getElementById("download-area").innerHTML = page;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
126
main.js
126
main.js
|
@ -24,13 +24,14 @@ const fs = require("fs");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
const spawn = require("child_process").spawn;
|
const spawn = require("child_process").spawn;
|
||||||
|
const exec = require("child_process").exec;
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
const hostname = "192.168.0.128"; // Enter your local IP address here
|
const hostname = "192.168.0.128"; // Enter your local IP address here
|
||||||
const port = 8001; // Enter a port number here
|
const port = 8001; // Enter a port number here
|
||||||
|
|
||||||
var files = {};
|
var files = {};
|
||||||
var lastImageId;
|
var fawkes = {};
|
||||||
|
|
||||||
|
|
||||||
// Create HTTP server
|
// Create HTTP server
|
||||||
|
@ -43,9 +44,15 @@ const server = http.createServer((req, res) => {
|
||||||
// Respond to requests
|
// Respond to requests
|
||||||
try{
|
try{
|
||||||
// Return requested page
|
// Return requested page
|
||||||
res.statusCode = 200;
|
if(reqpath.startsWith("/dl/")){
|
||||||
res.write(fs.readFileSync("html"+reqpath));
|
res.statusCode = 200;
|
||||||
res.end();
|
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){
|
}catch(error){
|
||||||
// 404 if page not found
|
// 404 if page not found
|
||||||
|
@ -76,7 +83,12 @@ io.on("connection", (socket) => {
|
||||||
console.log(userId+": disconnect");
|
console.log(userId+": disconnect");
|
||||||
|
|
||||||
// Remove all files from this user
|
// 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
|
// File upload
|
||||||
|
@ -99,7 +111,7 @@ io.on("connection", (socket) => {
|
||||||
|
|
||||||
// Create file
|
// Create file
|
||||||
var name = data.name;
|
var name = data.name;
|
||||||
var path = "fawkes/files/"+userId+"/"+name;
|
var path = "fawkes/files/"+userId+"/"+name+".png";
|
||||||
var file = {
|
var file = {
|
||||||
length: data.length,
|
length: data.length,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
@ -167,33 +179,79 @@ io.on("connection", (socket) => {
|
||||||
// Start binary
|
// Start binary
|
||||||
var process = spawn("fawkes/protection", ["-d", "fawkes/files/"+userId, "--mode", "low"]);
|
var process = spawn("fawkes/protection", ["-d", "fawkes/files/"+userId, "--mode", "low"]);
|
||||||
|
|
||||||
|
// Update vars
|
||||||
|
fawkes[userId] = {
|
||||||
|
running: true,
|
||||||
|
images: [],
|
||||||
|
imageSentDone: []
|
||||||
|
};
|
||||||
|
|
||||||
// Add listeners
|
// Add listeners
|
||||||
process.stdout.setEncoding("utf8");
|
process.stdout.setEncoding("utf8");
|
||||||
process.stdout.on("data", function(data){
|
process.stdout.on("data", function(data){
|
||||||
// Received output from process
|
// Received output from process
|
||||||
|
data = data.toString();
|
||||||
console.log("fawkes stdout: "+data);
|
console.log("fawkes stdout: "+data);
|
||||||
|
|
||||||
// Parse output
|
// Parse output
|
||||||
data = data.replace("\n", " ");
|
var lines = data.split("\n");
|
||||||
var splices = data.split(" ");
|
for(var l=0; l<lines.length; l++){
|
||||||
if(data.startsWith("Find ")){
|
|
||||||
var numFaces = splices[1];
|
|
||||||
var imageId = splices[4];
|
|
||||||
console.log("fawkes found "+numFaces+" faces in image "+imageId);
|
|
||||||
|
|
||||||
// Update file info
|
// For each line
|
||||||
files[userId+imageId].numFaces = numFaces;
|
var splices = lines[l].split(" ");
|
||||||
lastImageId = imageId;
|
if(splices.length == 0) continue;
|
||||||
|
|
||||||
// Update client states
|
if(splices[0] == "Find"){
|
||||||
socket.emit("FAWKES_STATE", {name:imageId, face:1, numFaces:numFaces});
|
var numFaces = splices[1];
|
||||||
|
var imageId = splices[4].substr(0, splices[4].indexOf("."));
|
||||||
|
console.log("fawkes found "+numFaces+" faces in image "+imageId);
|
||||||
|
|
||||||
}else if(splices[0] == "processing"){
|
// Update file info
|
||||||
var face = splices[2];
|
files[userId+imageId].numFaces = numFaces;
|
||||||
console.log("fawkes processing face "+face);
|
fawkes[userId].images.push(userId+imageId);
|
||||||
|
fawkes[userId].imageSentDone.push(numFaces == 0);
|
||||||
|
|
||||||
// Update client states
|
// Update state if no faces found
|
||||||
socket.emit("FAWKES_STATE", {name:lastImageId, face:face, numFaces:files[lastImageId].numFaces});
|
if(numFaces == 0){
|
||||||
|
var d = {name:imageId, face:0, numFaces:0};
|
||||||
|
console.log(d);
|
||||||
|
socket.emit("FAWKES_STATE", d);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(splices[0] == "processing"){
|
||||||
|
// Processing next face
|
||||||
|
console.log("fawkes processing face "+splices[2]);
|
||||||
|
|
||||||
|
// Calculate image
|
||||||
|
var image;
|
||||||
|
var f = splices[2] - 1;
|
||||||
|
for(var i=0; i<fawkes[userId].images.length; i++){
|
||||||
|
console.log("f = "+f);
|
||||||
|
if(f < files[fawkes[userId].images[i]].numFaces){
|
||||||
|
image = fawkes[userId].images[i];
|
||||||
|
console.log("image = "+image);
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
f -= files[fawkes[userId].images[i]].numFaces;
|
||||||
|
|
||||||
|
// If didn't send it yet, send 'done' message for this image
|
||||||
|
if(!fawkes[userId].imageSentDone[i]){
|
||||||
|
fawkes[userId].imageSentDone[i] = true;
|
||||||
|
|
||||||
|
var nf = files[fawkes[userId].images[i]].numFaces;
|
||||||
|
var d = {name:fawkes[userId].images[i].substr(userId.length), face:nf+1, numFaces:nf};
|
||||||
|
console.log(d);
|
||||||
|
socket.emit("FAWKES_STATE", d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update client states
|
||||||
|
var d = {name:image.substr(userId.length), face:f+1, numFaces:files[image].numFaces};
|
||||||
|
console.log(d);
|
||||||
|
socket.emit("FAWKES_STATE", d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +264,30 @@ io.on("connection", (socket) => {
|
||||||
process.on("close", function(code){
|
process.on("close", function(code){
|
||||||
// Fawkes exited
|
// Fawkes exited
|
||||||
console.log("Fawkes exited with code "+code);
|
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
|
// Update file states
|
||||||
|
|
Loading…
Reference in New Issue