diff --git a/php-webkit/main.js b/php-webkit/main.js index a9935d2..f06ab7a 100644 --- a/php-webkit/main.js +++ b/php-webkit/main.js @@ -17,8 +17,16 @@ if(port === undefined) { port = 9090; } +var phpinfo = { + "path": "./application", + "host": host, + "port": port, + "arguments": gui.App.argv, + "manifest": gui.App.manifest +}; + var server = http.createServer(app); -app.use('/', php.cgi('./application')); +app.use('/', php.cgi(phpinfo)); server.listen(port, host); var url = 'http://'+host+':'+port+'/'; diff --git a/php-webkit/node_modules/node-php/main.js b/php-webkit/node_modules/node-php/main.js index bc49d67..2b5dd6c 100644 --- a/php-webkit/node_modules/node-php/main.js +++ b/php-webkit/node_modules/node-php/main.js @@ -3,7 +3,9 @@ var child = require("child_process"); var path = require("path"); var fs = require("fs"); -function runPHP(req, response, next, phpdir){ +function runPHP(req, response, next, phpinfo){ + + var phpdir = phpinfo.path; var parts = url.parse(req.url); var query = parts.query; @@ -22,6 +24,13 @@ function runPHP(req, response, next, phpdir){ var env = { SERVER_SIGNATURE: "php-webkit", + PW_BIN_PATH: path.dirname(process.execPath), + PW_BIN_FILE: process.execPath, + PW_ARGUMENTS: phpinfo.arguments, + PW_MANIFEST: phpinfo.manifest, + PW_APP_PATH: process.cwd(), + PW_SERVER_HOST: phpinfo.host, + PW_SERVER_PORT: phpinfo.port, PATH_INFO: pathinfo, //The extra path information, as given in the requested URL. In fact, scripts can be accessed by their virtual path, followed by extra information at the end of this path. The extra information is sent in PATH_INFO. PATH_TRANSLATED: "", //The virtual-to-real mapped version of PATH_INFO. SCRIPT_NAME: parts.pathname, //The virtual path of the script being executed. @@ -41,9 +50,9 @@ function runPHP(req, response, next, phpdir){ ALL_HTTP: Object.keys(req.headers).map(function(x){return "HTTP_"+x.toUpperCase().replace("-", "_")+": "+req.headers[x];}).reduce(function(a, b){return a+b+"\n";}, ""), //All HTTP headers sent by the client. Headers are separated by carriage return characters (ASCII 13 - \n) and each header name is prefixed by HTTP_, transformed to upper cases, and - characters it contains are replaced by _ characters. ALL_RAW: Object.keys(req.headers).map(function(x){return x+": "+req.headers[x];}).reduce(function(a, b){return a+b+"\n";}, ""), //All HTTP headers as sent by the client in raw form. No transformation on the header names is applied. SERVER_SOFTWARE: "php-webkit", //The web server's software identity. - SERVER_NAME: "localhost", //The host name or the IP address of the computer running the web server as given in the requested URL. - SERVER_ADDR: "127.0.0.1", //The IP address of the computer running the web server. - SERVER_PORT: 8011, //The port to which the request was sent. + SERVER_NAME: phpinfo.host, //The host name or the IP address of the computer running the web server as given in the requested URL. + SERVER_ADDR: phpinfo.host, //The IP address of the computer running the web server. + SERVER_PORT: phpinfo.port, //The port to which the request was sent. GATEWAY_INTERFACE: "CGI/1.1", //The CGI Specification version supported by the web server; always set to CGI/1.1. SERVER_PROTOCOL: "", //The HTTP protocol version used by the current request. REMOTE_ADDR: "", //The IP address of the computer that sent the request. @@ -136,7 +145,7 @@ function runPHP(req, response, next, phpdir){ } } -exports.cgi = function(phproot){ +exports.cgi = function(phpinfo){ return function(req, res, next){ var data = null; @@ -152,7 +161,7 @@ exports.cgi = function(phproot){ req.rawBody = data||""; //console.log(req.rawBody); //console.log("ENCODING: "+req.get("Content-type")+", len: "+req.rawBody.length); - runPHP(req, res, next, phproot); + runPHP(req, res, next, phpinfo); }); } } \ No newline at end of file