From c90ebfa1c84e1ba668a65d0325e96d201c4abbf8 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sat, 7 Aug 2021 20:15:23 +0200 Subject: Electrode is stable! --- php/cache.js | 22 +++++++++++++++++----- php/runtime.js | 13 ++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'php') diff --git a/php/cache.js b/php/cache.js index 25c47be..8cfe5e1 100644 --- a/php/cache.js +++ b/php/cache.js @@ -17,9 +17,11 @@ module.exports = (req, res, file, post, files) => { fid = "PHP_" + cid; parsed = url.parse(req.url, true); - content = " r.concat(list.reduce((rr, i) => rr.concat(i.family==='IPv4' && !i.internal && i.address || []), [])), [])[0]); @@ -65,6 +67,8 @@ module.exports = (req, res, file, post, files) => { content = content + "\n$_FILES = [];"; content = content + "\n$_POST = [];"; content = content + "\n$_GET = [];"; + content = content + "\n$GLOBALS = [];"; + content = content + "\n$GLOBALS[\"SYSTEM_ROOT\"] = \"\";"; Object.keys(parsed.query).forEach((key) => { content = content + "\n$_GET[\"" + key.split("\"").join("\\\"").split("$").join("\\\$") + "\"] = \"" + parsed.query[key].split("\"").join("\\\"").split("$").join("\\\$") + "\";" }) @@ -80,11 +84,19 @@ module.exports = (req, res, file, post, files) => { Object.keys(cookies).forEach((key) => { content = content + "\n$_COOKIE[\"" + key.split("\"").join("\\\"").split("$").join("\\\$") + "\"] = \"" + cookies[key].split("\"").join("\\\"").split("$").join("\\\$") + "\";" }) - content = content + "\nrequire_once \"" + file.split("\"").join("\\\"") + "\";\n\n__electrode_end_hooks();"; + + p = "./public" + + regex = /require_once\(["'`].*resources\/private\/relative\.php["'`]\);/gm; + regex2 = /require_once ["'`].*resources\/private\/relative\.php["'`];/gm; + + fs.writeFileSync(file + ".ELECTRODECACHE~.php", fs.readFileSync(file).toString().replace(regex, "").replace(regex2, "")); + content = content + "\nchdir(\"" + p + "\");\nfunction getRelativeDetails() {};\nrequire_once \"." + file.split("\"").join("\\\"").substr(8) + ".ELECTRODECACHE~.php" + "\";\n\n__electrode_end_hooks();"; fs.writeFileSync("./cache/" + fid + ".php", content); return [ "./cache/" + fid + ".php", - cid + cid, + file + ".ELECTRODECACHE~.php" ]; } diff --git a/php/runtime.js b/php/runtime.js index ce2629d..fc0c122 100644 --- a/php/runtime.js +++ b/php/runtime.js @@ -1,19 +1,30 @@ const child = require('child_process'); const util = require('util'); const chalk = require('chalk'); +const fs = require('fs'); const exec = util.promisify(child.exec); module.exports = async ([file, id]) => { startd = new Date(); try { error = undefined; - var { stdout, stderr } = await exec("php \"" + file.split("\"").join("\\\"") + "\""); + if (require('os').platform() === "win32") { + var { stdout, stderr } = await exec("runtime\\php.exe \"" + file.split("\"").join("\\\"") + "\""); + } else { + var { stdout, stderr } = await exec("php \"" + file.split("\"").join("\\\"") + "\""); + } } catch (e) { error = e; } stopd = new Date(); diff = stopd - startd; + if (fs.existsSync(file + ".ELECTRODECACHE~.php")) { + fs.unlinkSync(file + ".ELECTRODECACHE~.php"); + } + + require('../core/cacheClean')(); + console.log(chalk.gray(cluster.worker.id + " ") + chalk.blueBright("php:") + " total run time: " + diff + "ms"); returnobj = {error: null, content: null, stderr: null, id: id}; -- cgit