1 #!/usr/bin/php -dphar.readonly=1
6 if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
7 Phar
::interceptFileFuncs();
8 set_include_path('phar://' . __FILE__
. PATH_SEPARATOR
. get_include_path());
9 Phar
::webPhar(null, $web);
10 include 'phar://' . __FILE__
. '/' . Extract_Phar
::START
;
14 if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'POST'))) {
15 Extract_Phar
::go(true);
20 'cpp' => 'text/plain',
21 'c++' => 'text/plain',
22 'dtd' => 'text/plain',
24 'log' => 'text/plain',
25 'rng' => 'text/plain',
26 'txt' => 'text/plain',
27 'xsd' => 'text/plain',
35 'html' => 'text/html',
36 'htmls' => 'text/html',
37 'ico' => 'image/x-ico',
38 'jpe' => 'image/jpeg',
39 'jpg' => 'image/jpeg',
40 'jpeg' => 'image/jpeg',
41 'js' => 'application/x-javascript',
42 'midi' => 'audio/midi',
43 'mid' => 'audio/midi',
45 'mov' => 'movie/quicktime',
47 'mpg' => 'video/mpeg',
48 'mpeg' => 'video/mpeg',
49 'pdf' => 'application/pdf',
51 'swf' => 'application/shockwave-flash',
52 'tif' => 'image/tiff',
53 'tiff' => 'image/tiff',
59 header("Cache-Control: no-cache, must-revalidate");
60 header("Pragma: no-cache");
62 $basename = basename(__FILE__
);
63 if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
64 chdir(Extract_Phar
::$temp);
68 $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) +
strlen($basename));
69 if (!$pt ||
$pt == '/') {
71 header('HTTP/1.1 301 Moved Permanently');
72 header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
75 $a = realpath(Extract_Phar
::$temp . DIRECTORY_SEPARATOR
. $pt);
76 if (!$a ||
strlen(dirname($a)) < strlen(Extract_Phar
::$temp)) {
77 header('HTTP/1.0 404 Not Found');
78 echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
82 if (!isset($b['extension'])) {
83 header('Content-Type: text/plain');
84 header('Content-Length: ' . filesize($a));
88 if (isset($mimes[$b['extension']])) {
89 if ($mimes[$b['extension']] === 1) {
93 if ($mimes[$b['extension']] === 2) {
97 header('Content-Type: ' .$mimes[$b['extension']]);
98 header('Content-Length: ' . filesize($a));
111 const START
= 'pharext_installer.php';
114 static function go($return = false)
116 $fp = fopen(__FILE__
, 'rb');
117 fseek($fp, self
::LEN
);
118 $L = unpack('V', $a = (binary
)fread($fp, 4));
123 if ($L[1] - strlen($m) < 8192) {
124 $read = $L[1] - strlen($m);
126 $last = (binary
)fread($fp, $read);
128 } while (strlen($last) && strlen($m) < $L[1]);
130 if (strlen($m) < $L[1]) {
131 die('ERROR: manifest length read was "' .
132 strlen($m) .'" should be "' .
136 $info = self
::_unpack($m);
140 if (!function_exists('gzinflate')) {
141 die('Error: zlib extension is not enabled -' .
142 ' gzinflate() function needed for zlib-compressed .phars');
146 if ($f & self
::BZ2
) {
147 if (!function_exists('bzdecompress')) {
148 die('Error: bzip2 extension is not enabled -' .
149 ' bzdecompress() function needed for bz2-compressed .phars');
153 $temp = self
::tmpdir();
155 if (!$temp ||
!is_writable($temp)) {
156 $sessionpath = session_save_path();
157 if (strpos ($sessionpath, ";") !== false)
158 $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+
1);
159 if (!file_exists($sessionpath) ||
!is_dir($sessionpath)) {
160 die('Could not locate temporary directory to extract phar');
162 $temp = $sessionpath;
165 $temp .= '/pharextract/'.basename(__FILE__
, '.phar');
167 self
::$origdir = getcwd();
168 @mkdir
($temp, 0777, true);
169 $temp = realpath($temp);
171 if (!file_exists($temp . DIRECTORY_SEPARATOR
. md5_file(__FILE__
))) {
172 self
::_removeTmpFiles($temp, getcwd());
173 @mkdir
($temp, 0777, true);
174 @file_put_contents
($temp . '/' . md5_file(__FILE__
), '');
176 foreach ($info['m'] as $path => $file) {
177 $a = !file_exists(dirname($temp . '/' . $path));
178 @mkdir
(dirname($temp . '/' . $path), 0777, true);
181 if ($path[strlen($path) - 1] == '/') {
182 @mkdir
($temp . '/' . $path, 0777);
184 file_put_contents($temp . '/' . $path, self
::extractFile($path, $file, $fp));
185 @chmod
($temp . '/' . $path, 0666);
197 static function tmpdir()
199 if (strpos(PHP_OS
, 'WIN') !== false) {
200 if ($var = getenv('TMP') ?
getenv('TMP') : getenv('TEMP')) {
203 if (is_dir('/temp') ||
mkdir('/temp')) {
204 return realpath('/temp');
208 if ($var = getenv('TMPDIR')) {
211 return realpath('/tmp');
214 static function _unpack($m)
216 $info = unpack('V', substr($m, 0, 4));
217 $l = unpack('V', substr($m, 10, 4));
218 $m = substr($m, 14 +
$l[1]);
219 $s = unpack('V', substr($m, 0, 4));
224 for ($i = 0; $i < $info[1]; $i++
) {
225 $len = unpack('V', substr($m, $start, 4));
227 $savepath = substr($m, $start, $len[1]);
229 $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
230 $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
232 $ret['m'][$savepath][7] = $o;
233 $o +
= $ret['m'][$savepath][2];
234 $start +
= 24 +
$ret['m'][$savepath][5];
235 $ret['c'] |
= $ret['m'][$savepath][4] & self
::MASK
;
240 static function extractFile($path, $entry, $fp)
247 $data .= @fread
($fp, $c);
251 $data .= @fread
($fp, 8192);
255 if ($entry[4] & self
::GZ
) {
256 $data = gzinflate($data);
257 } elseif ($entry[4] & self
::BZ2
) {
258 $data = bzdecompress($data);
261 if (strlen($data) != $entry[0]) {
262 die("Invalid internal .phar file (size error " . strlen($data) . " != " .
266 if ($entry[3] != sprintf("%u", crc32((binary
)$data) & 0xffffffff)) {
267 die("Invalid internal .phar file (checksum error)");
273 static function _removeTmpFiles($temp, $origdir)
277 foreach (glob('*') as $f) {
278 if (file_exists($f)) {
279 is_dir($f) ? @rmdir
($f) : @unlink
($f);
280 if (file_exists($f) && is_dir($f)) {
281 self
::_removeTmpFiles($f, getcwd());
293 __HALT_COMPILER(); ?
>