diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-07 20:15:23 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-07 20:15:23 +0200 |
commit | c90ebfa1c84e1ba668a65d0325e96d201c4abbf8 (patch) | |
tree | 3a4e80dc0461ad1c6e0c763aad669d39a458ebe3 /php | |
parent | 981b80066504cf94224f0fd431281edb740f2669 (diff) | |
download | electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.tar.gz electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.tar.bz2 electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.zip |
Electrode is stable!
Diffstat (limited to 'php')
-rw-r--r-- | php/cache.js | 22 | ||||
-rw-r--r-- | php/runtime.js | 13 |
2 files changed, 29 insertions, 6 deletions
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 = "<?php\n\n$_PHPID = \"" + cid + "\";\nrequire \"headers.php\";\n\n" - + "\n$oldsrv = $_SERVER; $_SERVER = [];"; - + "\n$__electrode_version = \"" + version + "\""; + content = "<?php\n\nset_include_path(\"" + publicDir + "\" . PATH_SEPARATOR . get_include_path());\n$_PHPID = \"" + cid + "\";\nrequire \"headers.php\";\n\n" + + "\nregister_shutdown_function(\"__electrode_end_hooks\");" + + "\n$oldsrv = $_SERVER; $_SERVER = [];" + + "\n$__electrode_version = \"" + version + "\";" + + "\n$__electrode_node_version = \"" + process.versions.node + "\";"; content = addPhpServerVariable(content, "PHP_SELF", path.resolve(file)); content = addPhpServerVariable(content, "GATEWAY_INTERFACE", "CGI/1.1"); content = addPhpServerVariable(content, "SERVER_ADDR", Object.values(require('os').networkInterfaces()).reduce((r, list) => 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}; |