diff --git a/plugins/php/index.js b/plugins/php/index.js index e4be11d..7e43c62 100644 --- a/plugins/php/index.js +++ b/plugins/php/index.js @@ -1,14 +1,19 @@ const PHPFPM = require("./phpfpm"); const path = require("path"); +const fs = require("fs"); const phpfpm = new PHPFPM({ sockFile: "/run/php/php7.3-fpm.sock", documentRoot: path.join(__dirname, "../../contents") }); +const useIndex = true; + module.exports = { enabled: true, exec(ctx){ return new Promise((resolve, reject)=>{ + if(ctx.request.url.split("/")[ctx.request.url.split("/").length - 1] == "")ctx.request.url += "index.php"; + phpfpm.run({ hostname: ctx.hostname, remote_addr: ctx.request.ip, @@ -22,15 +27,22 @@ module.exports = { ctx.body = output; - if (phpErrors) console.error(err, phpErrors); + if (phpErrors) console.error(phpErrors); resolve(); }); }) }, rules(ctx){ + var p = path.join(__dirname, "../../contents/", ctx.request.url); + if(ctx.request.url.split("/")[ctx.request.url.split("/").length - 1] == "" && useIndex)p = path.join(p, "index.php"); + + + if(!fs.existsSync(p))return false; + + if(ctx.request.url.split("/")[ctx.request.url.split("/").length - 1] == "" && useIndex)return true; + var ext = ctx.request.url.split('.').pop(); - console.log("Filetype: " + ext); return ext == "php"; }, priority: -2, diff --git a/plugins/static/index.js b/plugins/static/index.js index bd5766d..25a93fa 100644 --- a/plugins/static/index.js +++ b/plugins/static/index.js @@ -6,20 +6,40 @@ const fs = require("fs"); const path = require("path") const PassThrough = require('stream').PassThrough; +const useIndex = true; + module.exports = { enabled: true, exec(ctx){ var p = path.join(__dirname, "../../contents", ctx.request.url); + + if(ctx.request.url.split("/")[ctx.request.url.split("/").length - 1] == "" && useIndex){ + p = path.join(p, "index.html"); + + if(!fs.existsSync(p)){ + ctx.body = "Forbidden"; + ctx.status = 403; + return; + } + } + + if(fs.lstatSync(path_string).isDirectory()){ + ctx.body = "Forbidden"; + ctx.status = 403; + return; + } + if(!fs.existsSync(p)){ ctx.body = "Not Found"; ctx.status = 404; return; } + ctx.set('Content-Type', 'text/html'); - ctx.body = fs.createReadStream(p).on('error', ctx.onerror).pipe(PassThrough()); + ctx.body = fs.createReadStream(p).on('error', (e)=>{ctx.onerror(e)}).pipe(PassThrough()); }, rules(ctx){ return ctx.request.url.split('.').pop() != "php"; }, - priority: -5 + priority: -1 } \ No newline at end of file