-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathphp_burner.php
More file actions
123 lines (100 loc) · 4.01 KB
/
php_burner.php
File metadata and controls
123 lines (100 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/* ======================================================================== *\
Pre burner for PHP script execution with note.js
* Set up the predefined global variables for the PHP script.
* Limit access to predefined list of scripts
This is a close aproximation to the population of globals done by mod_php in Apache
Version 0.1: Simon Rigét - Basic funtionalaty in place.
todo:
fake header()
set ini open_basedir
remove $_ENV (programds can use getenv();
See copyrights notes in licese.txt (MIT licence)
\* ======================================================================== */
// Configuration
$sw_name="PHP Burner 0.1";
// Set max execution time (since we use the php CLI we need a web setting)
set_time_limit(30);
/* ======================================================================== *\
Get client request and server information
Data passed throug stdin
including all http headers
\* ======================================================================== */
$request=json_decode(file_get_contents("php://stdin"),true);
/* ======================================================================== *\
Populate predefined global variables
\* ======================================================================== */
// _ENV
// All enviroment variables are now in the _SERVER array
// $_ENV=$_SERVER;
// _SERVER
$path=$_SERVER['PATH'];
// Clear array
unset($_SERVER);
$argc=0;
// Add HTTP headers
if(@is_array($request['header'])) foreach($request['header'] as $key=>$val)
$_SERVER['HTTP_'.strtoupper($key)]=$val;
$_SERVER['HTTP_COOKIE_PARSE_RAW']=@$request['header']['cookie'];
if(@$request['httpversion']) $_SERVER['SERVER_PROTOCOL'] = "HTTP/" . $request['httpversion'];
$_SERVER['REQUEST_METHOD']=@$request['method'];
// Add query information
if(@$request['url']){
$_SERVER['QUERY_STRING']=substr($request['url'],strpos($request['url'],"?")+1);
$_SERVER['REQUEST_URI']=$request['url'];
}
$_SERVER['REMOTE_ADDR']=@$request['remoteaddress'];
$_SERVER['REMOTE_HOST']=@$request['header']['host'];
$_SERVER['REMOTE_PORT']=@$request['remoteport'];
// Split address and port
if(@$_SERVER['HTTP_REFERER']){
$url=parse_url($_SERVER['HTTP_REFERER']);
if(@$url['port'])
$_SERVER['SERVER_PORT'] = ($url['port']);
else
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['SERVER_ADDR'] =$url['host'];
}
// Add script name and paths
if(@$request['pathname'][0]!='/') $request['pathname'] = '/' . $request['pathname'];
$_SERVER['SCRIPT_NAME']=$request['pathname'];
$_SERVER['DOCUMENT_ROOT']=@$request['docroot'];
$_SERVER['PHP_SELF']=$request['pathname'];
$_SERVER['SCRIPT_FILENAME']=$_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
$_SERVER['PATH']=$path;
// Add some predefined settings
$_SERVER['GATEWAY_INTERFACE']=$sw_name;
$_SERVER['SERVER_SOFTWARE'] = "PHP Appilation Server using Node.js and WS Websockets";
// Generate a signature
$_SERVER['SERVER_SIGNATURE']="$_SERVER[SERVER_SOFTWARE] Server with $_SERVER[GATEWAY_INTERFACE] at ". @$request['header']['host'];
// _GET
$_GET=@$request['query'];
// Process body data
$_POST=@$request['body'];
// _FILES
$_FILES=@$request['files'];
// Delete file on exit;
// register_shutdown_function(create_function('', "unlink('{$file['tmp_name']}');"));
//process_body($request['body'],$_SERVER['HTTP_CONTENT-TYPE']);
// _COOKIE
if($_SERVER['HTTP_COOKIE_PARSE_RAW'])
foreach(explode(";",$_SERVER['HTTP_COOKIE_PARSE_RAW']) as $line){
list($key,$val) = explode("=",$line);
$_COOKIE[trim($key)]=urldecode(trim($val));
}
// _REQUEST
$_REQUEST=(array)$_GET + (array)$_POST + (array)$_COOKIE;
/* ======================================================================== *\
Go
\* ======================================================================== */
// Clean up
unset($key,$val,$line,$request,$sw_name,$default_script,$path);
// Run script
if(realpath($_SERVER['SCRIPT_FILENAME'])){
chdir($_SERVER['DOCUMENT_ROOT']);
require $_SERVER['SCRIPT_FILENAME'];
}else{
// Websocket responce
echo '{"error":"File '.$_SERVER['SCRIPT_FILENAME'].' Missing"}';
}
?>