diff --git a/run.js b/run.js index b619cd7..9421912 100644 --- a/run.js +++ b/run.js @@ -42,7 +42,9 @@ const requestListener = function (req, res) { let intcode = "" + crypto.randomInt(999999); if (req.url!=="/favicon.ico") { - log( String(new Date) + ": " + req.method + " => " + String(req.url)) + var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; + + log( String(new Date) + ": " + req.method + " => " + String(req.url) + " => User IP: " + ip) } if (req.url === "/test"){ @@ -110,7 +112,8 @@ const requestListener = function (req, res) { //console.log(lines) /* fs.writeFileSync(intcode, lines); */ //fs.writeFileSync(intcode+".type",type) -console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\x1b[37m" +" Type: " + type) + +console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\x1b[37m" +" Type: " /*+ type*/) /*})*/; @@ -128,7 +131,7 @@ console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\ res.end(data); }); - } else if(String(req.url).startsWith("/download/") && false){ + } else if(String(req.url).startsWith("/download/") ){ //log(String(req.url).replace("/download/","")) let pathh = (String(req.url).replace("/download/","")) pathh = "./data/keys/" + pathh + ".type" diff --git a/static/start.js b/static/start.js index 5be10a1..934d560 100644 --- a/static/start.js +++ b/static/start.js @@ -1,12 +1,36 @@ window.onload = function(){ let codeplace = document.getElementById("code") -let upbutton = document.getElementById("upb") +let upbutton = document.getElementById("fileupload") let dbutton = document.getElementById("downb") +console.log(upbutton) console.log("Script included.") -upbutton.onclick = function(){ +upbutton.onchange = function(e){ + var file = upbutton.files[0]; + + var reader = new FileReader(); + + reader.onload = function(e) { + console.log(reader.result) + console.log(file.type) + console.log(file.name) + let xhr = new XMLHttpRequest() + xhr.open('POST', '/upload') + xhr.setRequestHeader('Content-Type', file.type); + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + xhr.send(reader.result) + xhr.onload = () => { + window.alert(xhr.responseText); + + } + } + + reader.readAsBinaryString(file); + + + } dbutton.onclick =function(){ diff --git a/templates/start.html b/templates/start.html index 6f3aa0f..adb585e 100644 --- a/templates/start.html +++ b/templates/start.html @@ -27,8 +27,12 @@
-
- + +
+ + + +