diff --git a/run.js b/run.js index d834fee..6e80ec2 100644 --- a/run.js +++ b/run.js @@ -12,7 +12,8 @@ let fs = require("fs") let log = console.log; let http = require("http") let crypto = require("crypto") -let path = require("path") +let path = require("path"); +const { Console } = require('console'); @@ -51,10 +52,12 @@ const requestListener = function (req, res) { if (req.url!=="/favicon.ico") { var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; - log( String(new Date) + ": " + req.method + " => " + String(req.url) + " => User IP: " + ip) + let date = String(new Date).split("GMT-")[0] + log( date + " => " + req.method + " => " + String(req.url) + " => User IP: " + ip) } if (req.url === "/test"){ + console.log("[TEST PAGE]") fs.readFile("templates/rick.html", function (err,data) { if (err) { res.writeHead(203); @@ -65,6 +68,7 @@ const requestListener = function (req, res) { res.end(data); }); }else if (req.url === "/"){ + console.log("[START PAGE]") fs.readFile("templates/start.html", function (err,data) { if (err) { res.writeHead(203); @@ -83,6 +87,7 @@ const requestListener = function (req, res) { res.end(data); }); }else if(String(req.url).split("?")[0]==="/upload"){ + console.log("[UPLOAD STARTED]") //console.log("upload") let body = ""; req.on("data",(chunk)=>{ @@ -99,18 +104,12 @@ const requestListener = function (req, res) { let code = intcode intcode = "./static/" + intcode+".upload."+ext fs.writeFileSync(intcode,body) - - - - -console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type) - -/*})*/; - - +console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type) +console.log("[UPLOAD ENDED]") }) }else if(req.url.includes("/../")) { + console.log["BAD REQUEST"] fs.readFile("templates/500.html", function (err,data) { if (err) { res.writeHead(203); @@ -122,24 +121,29 @@ console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type) }); } else if(String(req.url).startsWith("/download/") ){ + console.log("[DOWNLOAD STARTED]") let number = String(req.url).replace("/download/","") let filepath = new RegExp(number+"\.upload\."+"*") let defpath = "undefined" let files = fs.readdirSync("static") console.log(filepath) for (file in files){ - console.log(files[file]) + console.log("Testing... => "+ files[file]) if (String(files[file]).match(filepath)){ defpath = String(files[file]) - console.log(defpath) + console.log("Definitive path => "+ defpath) + break } } - fs.readFile(defpath, function(err,data) { + fs.readFile(path.join("static", defpath), function(err,data) { + if (err) { + console.log(err) if(err.code=="ENOENT"){ res.writeHead(404); res.end(data); + console.log("File not found at "+"\x1b[34m"+defpath+"\x1b[37m") return; } res.writeHead(203); @@ -150,15 +154,19 @@ console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type) res.writeHead(200); res.end(defpath); console.log("File downloaded from "+"\x1b[32m"+String(req.url).replace("/download/","")+"\x1b[37m") + console.log("[DOWNLOAD ENDED]") }); }else{ fs.readFile("static" + req.url, function (err,data) { + console.log["STATIC FILE"] if (err) { if(err.code=="ENOENT"){ - + console.log("[404 ERROR]") fs.readFile("templates/404.html", function (err,data) { if (err) { + console.log("[INTERNAL CRASH]") + console.log(err) res.writeHead(203); res.end("
internal error"+JSON.stringify(err)); return; diff --git a/static/start.js b/static/start.js index c480bed..4974395 100644 --- a/static/start.js +++ b/static/start.js @@ -40,6 +40,11 @@ dbutton.onclick =function(){ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.send() xhr.onload = () => { + console.log("Status: " +xhr.status) + console.log("Response: "+xhr.response) + console.log("ResponseText: "+xhr.responseText) + console.log("Type: "+xhr.responseType) + window.location = xhr.responseText; }