Skip to content

Commit

Permalink
Merge pull request #17 from J-P-S-O/master
Browse files Browse the repository at this point in the history
[ALMOST] Definitive version
  • Loading branch information
Octalbyte authored Dec 6, 2021
2 parents d6bc7ce + a50bf17 commit cf9ca72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
38 changes: 23 additions & 15 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');



Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)=>{
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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("<html><body><b>internal error</b></body></html>"+JSON.stringify(err));
return;
Expand Down
5 changes: 5 additions & 0 deletions static/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down

0 comments on commit cf9ca72

Please sign in to comment.