cvs: pecl /phar shortarc.php stub.h
| From: | Steph Fox | Date: | Mon, 28 Jan 2008 21:23:01 +0000 |
| Subject: | cvs: pecl /phar shortarc.php stub.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-9617@lists.php.net to get a copy of this message | ||
sfox Mon Jan 28 21:23:01 2008 UTC
Modified files:
/pecl/phar shortarc.php stub.h
Log:
'It works on my box'.
Please test.
http://cvs.php.net/viewvc.cgi/pecl/phar/shortarc.php?r1=1.5&r2=1.6&diff_format=u Index: pecl/phar/shortarc.php diff -u pecl/phar/shortarc.php:1.5 pecl/phar/shortarc.php:1.6 --- pecl/phar/shortarc.php:1.5 Sat Jan 26 00:11:59 2008 +++ pecl/phar/shortarc.php Mon Jan 28 21:23:01 2008 @@ -1,273 +1,276 @@ -<?php -$web = '000'; -if ($web) { - if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { - Phar::interceptFileFuncs(); - Phar::webPhar(null, $web); - include 'phar://' . __FILE__ . '/' . Extract_Phar::START; - return; - } - if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { - Extract_Phar::go(true); - $mimes = array( - 'phps' => 2, - 'c' => 'text/plain', - 'cc' => 'text/plain', - 'cpp' => 'text/plain', - 'c++' => 'text/plain', - 'dtd' => 'text/plain', - 'h' => 'text/plain', - 'log' => 'text/plain', - 'rng' => 'text/plain', - 'txt' => 'text/plain', - 'xsd' => 'text/plain', - 'php' => 1, - 'inc' => 1, - 'avi' => 'video/avi', - 'bmp' => 'image/bmp', - 'css' => 'text/css', - 'gif' => 'image/gif', - 'htm' => 'text/html', - 'html' => 'text/html', - 'htmls' => 'text/html', - 'ico' => 'image/x-ico', - 'jpe' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'js' => 'application/x-javascript', - 'midi' => 'audio/midi', - 'mid' => 'audio/midi', - 'mod' => 'audio/mod', - 'mov' => 'movie/quicktime', - 'mp3' => 'audio/mp3', - 'mpg' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'pdf' => 'application/pdf', - 'png' => 'image/png', - 'swf' => 'application/shockwave-flash', - 'tif' => 'image/tiff', - 'tiff' => 'image/tiff', - 'wav' => 'audio/wav', - 'xbm' => 'image/xbm', - 'xml' => 'text/xml', - ); - $basename = basename(__FILE__); - if (!strpos($_SERVER['REQUEST_URI'], $basename)) { - chdir(Extract_Phar::$temp); - include Extract_Phar::START; - } - $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); - if (!$pt || $pt == '/') { - $pt = $web; - header('HTTP/1.1 301 Moved Permanently'); - header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); - } - $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); - if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { - header('HTTP/1.0 404 Not Found'); - 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>"; - exit; - } - $b = pathinfo($a); - if (!isset($b['extension'])) { - header('Content-Type: text/plain'); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; - } - if (isset($mimes[$b['extension']])) { - if ($mimes[$b['extension']] === 1) { - $_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO']; - $_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename)); - if (isset($_SERVER['PATH_TRANSLATED'])) { - $_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED']; - $_SERVER['PATH_TRANSLATED'] = $a; - } - include $a; - exit; - } - if ($mimes[$b['extension']] === 2) { - highlight_file($a); - exit; - } - header('Content-Type: ' .$mimes[$b['extension']]); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; - } - } -} -if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { - Phar::interceptFileFuncs(); - include 'phar://' . __FILE__ . '/' . Extract_Phar::START; - return; -} -class Extract_Phar -{ - static $temp; - static $tmp = array(); - static $origdir; - const GZ = 0x1000; - const BZ2 = 0x2000; - const MASK = 0x3000; - const START = 'index.php'; - const LEN = XXXX; - static function go($return = false) - { - register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); - $fp = fopen(__FILE__, 'rb'); - fseek($fp, self::LEN); - $L = unpack('V', $a = fread($fp, 4)); - $m = ''; - do { - $read = 8192; - if ($L[1] - strlen($m) < 8192) { - $read = $L[1] - strlen($m); - } - $last = fread($fp, $read); - $m .= $last; - } while (strlen($last) && strlen($m) < $L[1]); - if (strlen($m) < $L[1]) { - die('ERROR: manifest length read was "' . - strlen($m) .'" should be "' . - $L[1] . '"'); - } - $info = self::_unpack($m); - $f = $info['c']; - if ($f & self::GZ) { - if (!function_exists('gzinflate')) { - die('Error: zlib extension is not enabled -' . - ' gzinflate() function needed for zlib-compressed .phars'); - } - } - if ($f & self::BZ2) { - if (!function_exists('bzdecompress')) { - die('Error: bzip2 extension is not enabled -' . - ' bzdecompress() function needed for bz2-compressed .phars'); - } - } - $temp = self::tmpdir(); - if (!$temp || !is_writable($temp)) { - $sessionpath = session_save_path(); - if (strpos ($sessionpath, ";") !== false) - $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); - if (!file_exists($sessionpath) || !is_dir($sessionpath)) { - die('Could not locate temporary directory to extract phar'); - } - $temp = $sessionpath; - } - $temp .= '/pharextract'; - self::$temp = $temp; - while (file_exists($temp)) { - $temp .= 1; - } - @mkdir($temp); - @chmod($temp, 0777); - $temp = realpath($temp); - self::$tmp[] = $temp; - self::$origdir = getcwd(); - foreach ($info['m'] as $path => $file) { - $a = !file_exists(dirname($temp . '/' . $path)); - @mkdir(dirname($temp . '/' . $path), 0777, true); - clearstatcache(); - if ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path)); - if ($path[strlen($path) - 1] == '/') { - mkdir($temp . '/' . $path); - @chmod($temp . '/' . $path, 0777); - } else { - file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); - @chmod($temp . '/' . $path, 0666); - } - self::$tmp[] = realpath($temp . '/' . $path); - } - chdir($temp); - if (!$return) include self::START; - } - - static function tmpdir() - { - if (strpos(PHP_OS, 'WIN') !== false) { - if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { - return $var; - } - if (is_dir('/temp') || mkdir('/temp')) { - return realpath('/temp'); - } - return false; - } - if ($var = getenv('TMPDIR')) { - return $var; - } - return realpath('/tmp'); - } - - static function _unpack($m) - { - $info = unpack('V', substr($m, 0, 4)); - // skip API version, phar flags, alias, metadata - $l = unpack('V', substr($m, 10, 4)); - $m = substr($m, 14 + $l[1]); - $s = unpack('V', substr($m, 0, 4)); - $o = 0; - $start = 4 + $s[1]; - $ret['c'] = 0; - for ($i = 0; $i < $info[1]; $i++) { - // length of the file name - $len = unpack('V', substr($m, $start, 4)); - $start += 4; - // file name - $savepath = substr($m, $start, $len[1]); - $start += $len[1]; - // retrieve manifest data: - // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags - // 5 = metadata length - $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); - $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] - & 0xffffffff); - $ret['m'][$savepath][7] = $o; - $o += $ret['m'][$savepath][2]; - $start += 24 + $ret['m'][$savepath][5]; - $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; - } - return $ret; - } - - static function extractFile($path, $entry, $fp) - { - $data = ''; - $c = $entry[2]; - while ($c) { - if ($c < 8192) { - $data .= @fread($fp, $c); - $c = 0; - } else { - $c -= 8192; - $data .= @fread($fp, 8192); - } - } - if ($entry[4] & self::GZ) { - $data = gzinflate($data); - } elseif ($entry[4] & self::BZ2) { - $data = bzdecompress($data); - } - if (strlen($data) != $entry[0]) { - die("Invalid internal .phar file (size error " . strlen($data) . " != " . - $stat[7] . ")"); - } - if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { - die("Invalid internal .phar file (checksum error)"); - } - return $data; - } - - static function _removeTmpFiles() - { - if (count(self::$tmp)) { - foreach (array_reverse(self::$tmp) as $f) { - if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); - } - - } - chdir(self::$origdir); - } -} +<?php +$web = '000'; +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { + Phar::interceptFileFuncs(); + if (!$web || PHP_SAPI == 'cli') { + include 'phar://' . __FILE__ . '/' . Extract_Phar::START; + } else { + Phar::webPhar(null, $web); + include 'phar://' . __FILE__ . '/' . $web; + } + exit; +} +if ($web) { + if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST')) { + Extract_Phar::go(true); + $mimes = array( + 'phps' => 2, + 'c' => 'text/plain', + 'cc' => 'text/plain', + 'cpp' => 'text/plain', + 'c++' => 'text/plain', + 'dtd' => 'text/plain', + 'h' => 'text/plain', + 'log' => 'text/plain', + 'rng' => 'text/plain', + 'txt' => 'text/plain', + 'xsd' => 'text/plain', + 'php' => 1, + 'inc' => 1, + 'avi' => 'video/avi', + 'bmp' => 'image/bmp', + 'css' => 'text/css', + 'gif' => 'image/gif', + 'htm' => 'text/html', + 'html' => 'text/html', + 'htmls' => 'text/html', + 'ico' => 'image/x-ico', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'js' => 'application/x-javascript', + 'midi' => 'audio/midi', + 'mid' => 'audio/midi', + 'mod' => 'audio/mod', + 'mov' => 'movie/quicktime', + 'mp3' => 'audio/mp3', + 'mpg' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'pdf' => 'application/pdf', + 'png' => 'image/png', + 'swf' => 'application/shockwave-flash', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'wav' => 'audio/wav', + 'xbm' => 'image/xbm', + 'xml' => 'text/xml', + ); + + header("Cache-Control: no-cache, must-revalidate"); + header("Pragma: no-cache"); + + $basename = basename(__FILE__); + if (!strpos($_SERVER['REQUEST_URI'], $basename)) { + chdir(Extract_Phar::$temp); + include $web; + return; + } + $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); + if (!$pt || $pt == '/') { + $pt = $web; + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); + exit; + } + $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); + if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { + header('HTTP/1.0 404 Not Found'); + 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>"; + exit; + } + $b = pathinfo($a); + if (!isset($b['extension'])) { + header('Content-Type: text/plain'); + header('Content-Length: ' . filesize($a)); + readfile($a); + exit; + } + if (isset($mimes[$b['extension']])) { + if ($mimes[$b['extension']] === 1) { + include $a; + return; + } + if ($mimes[$b['extension']] === 2) { + highlight_file($a); + } + header('Content-Type: ' .$mimes[$b['extension']]); + header('Content-Length: ' . filesize($a)); + readfile($a); + exit; + } + } +} + +class Extract_Phar +{ + static $temp; + static $origdir; + const GZ = 0x1000; + const BZ2 = 0x2000; + const MASK = 0x3000; + const START = 'index.php'; + const LEN = XXXX; + static function go($return = false) + { + $fp = fopen(__FILE__, 'rb'); + fseek($fp, self::LEN); + $L = unpack('V', $a = fread($fp, 4)); + $m = ''; + do { + $read = 8192; + if ($L[1] - strlen($m) < 8192) { + $read = $L[1] - strlen($m); + } + $last = fread($fp, $read); + $m .= $last; + } while (strlen($last) && strlen($m) < $L[1]); + if (strlen($m) < $L[1]) { + die('ERROR: manifest length read was "' . + strlen($m) .'" should be "' . + $L[1] . '"'); + } + $info = self::_unpack($m); + $f = $info['c']; + if ($f & self::GZ) { + if (!function_exists('gzinflate')) { + die('Error: zlib extension is not enabled -' . + ' gzinflate() function needed for zlib-compressed .phars'); + } + } + if ($f & self::BZ2) { + if (!function_exists('bzdecompress')) { + die('Error: bzip2 extension is not enabled -' . + ' bzdecompress() function needed for bz2-compressed .phars'); + } + } + $temp = self::tmpdir(); + if (!$temp || !is_writable($temp)) { + $sessionpath = session_save_path(); + if (strpos ($sessionpath, ";") !== false) + $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); + if (!file_exists($sessionpath) || !is_dir($sessionpath)) { + die('Could not locate temporary directory to extract phar'); + } + $temp = $sessionpath; + } + $temp .= '/pharextract/'.basename(__FILE__, '.phar'); + self::$temp = $temp; + self::$origdir = getcwd(); + if (file_exists(realpath($temp))) { + if (file_exists($temp. DIRECTORY_SEPARATOR . md5_file(__FILE__))) { + return; + } + self::_removeTmpFiles($temp, getcwd()); + } + @mkdir($temp, 0777, true); + $temp = realpath($temp); + file_put_contents($temp . '/' . md5_file(__FILE__), ''); + foreach ($info['m'] as $path => $file) { + $a = !file_exists(dirname($temp . '/' . $path)); + @mkdir(dirname($temp . '/' . $path), 0777, true); + clearstatcache(); + if ($path[strlen($path) - 1] == '/') { + @mkdir($temp . '/' . $path, 0777); + } else { + file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); + @chmod($temp . '/' . $path, 0666); + } + } + chdir($temp); + if (!$return) { + include self::START; + } + } + + static function tmpdir() + { + if (strpos(PHP_OS, 'WIN') !== false) { + if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { + return $var; + } + if (is_dir('/temp') || mkdir('/temp')) { + return realpath('/temp'); + } + return false; + } + if ($var = getenv('TMPDIR')) { + return $var; + } + return realpath('/tmp'); + } + + static function _unpack($m) + { + $info = unpack('V', substr($m, 0, 4)); + // skip API version, phar flags, alias, metadata + $l = unpack('V', substr($m, 10, 4)); + $m = substr($m, 14 + $l[1]); + $s = unpack('V', substr($m, 0, 4)); + $o = 0; + $start = 4 + $s[1]; + $ret['c'] = 0; + for ($i = 0; $i < $info[1]; $i++) { + // length of the file name + $len = unpack('V', substr($m, $start, 4)); + $start += 4; + // file name + $savepath = substr($m, $start, $len[1]); + $start += $len[1]; + // retrieve manifest data: + // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags + // 5 = metadata length + $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); + $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] + & 0xffffffff); + $ret['m'][$savepath][7] = $o; + $o += $ret['m'][$savepath][2]; + $start += 24 + $ret['m'][$savepath][5]; + $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; + } + return $ret; + } + + static function extractFile($path, $entry, $fp) + { + $data = ''; + $c = $entry[2]; + while ($c) { + if ($c < 8192) { + $data .= @fread($fp, $c); + $c = 0; + } else { + $c -= 8192; + $data .= @fread($fp, 8192); + } + } + if ($entry[4] & self::GZ) { + $data = gzinflate($data); + } elseif ($entry[4] & self::BZ2) { + $data = bzdecompress($data); + } + if (strlen($data) != $entry[0]) { + die("Invalid internal .phar file (size error " . strlen($data) . " != " . + $stat[7] . ")"); + } + if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { + die("Invalid internal .phar file (checksum error)"); + } + return $data; + } + + static function _removeTmpFiles($temp, $origdir) + { + chdir($temp); + foreach (glob('*') as $f) { + if (file_exists($f)) { + is_dir($f) ? @rmdir($f) : @unlink($f); + if (file_exists($f) && is_dir($f)) { + self::_removeTmpFiles($f, getcwd()); + } + } + } + @rmdir($temp); + clearstatcache(); + chdir($origdir); + } +} http://cvs.php.net/viewvc.cgi/pecl/phar/stub.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phar/stub.h diff -u pecl/phar/stub.h:1.5 pecl/phar/stub.h:1.6 --- pecl/phar/stub.h:1.5 Sat Jan 26 00:11:59 2008 +++ pecl/phar/stub.h Mon Jan 28 21:23:01 2008 @@ -16,19 +16,19 @@ +----------------------------------------------------------------------+ */ -/* $Id: stub.h,v 1.5 2008/01/26 00:11:59 sfox Exp $ */ +/* $Id: stub.h,v 1.6 2008/01/28 21:23:01 sfox Exp $ */ static inline void phar_get_stub(const char *index_php, const char *web, size_t *len, char **stub, const int name_len, const int web_len TSRMLS_DC) { static const char newstub0[] = "<?php\n$web = '"; - static const char newstub1_0[] = "';\nif ($web) {\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nif (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico' => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n! 'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude Extract_Phar::START;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);\nif (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\ne! cho \"<html>\\n <head>\\n <title>File Not Found<title>\\n </head>\\n <body>\\n <h1>404 - File \", $pt, "; - static const char newstub1_1[] = "\" Not Found</h1>\\n </body>\\n</html>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\n$_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO'];\n$_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename));\nif (isset($_SERVER['PATH_TRANSLATED'])) {\n$_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED'];\n$_SERVER['PATH_TRANSLATED'] = $a;\n}\ninclude $a;\nexit;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\nexit;\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\n}\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\ninclude 'phar://' . __FIL! E__ . '/' . Extract_Phar::START;\nreturn;\n}\nclass Extract_Phar\n{\nstatic $temp;\nstatic $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; + static const char newstub1_0[] = "';\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nif (!$web || PHP_SAPI == 'cli') {\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\n} else {\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . $web;\n}\nexit;\n}\nif ($web) {\nif (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST')) {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico'! => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n\nheader(\"Cache-Control: no-cache, must-revalidate\");\nheader(\"Pragma: no-cache\");\n\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude $web;\nreturn;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' .! $pt);\nexit;\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARA TOR . $pt);\nif (!$a || strlen(dirn"; + static const char newstub1_1[] = "ame($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\necho \"<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>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\ninclude $a;\nreturn;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\n}\n\nclass Extract_Phar\n{\nstatic $temp;\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; static const char newstub2[] = "';\nconst LEN = "; - static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled -' .\n' gzinflate() function needed for zlib-compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled -' .\n' bzdecompress() function needed for bz2-compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$te! mp || !is_writable($temp)) {\n$sessionpath = session_save_path();\nif (strpos ($sessionpath, \";\") !== false)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) || !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract';\nself::$temp = $temp;\nwhile (file_exists($temp)) {\n$temp .= 1;\n}\n@mkdir($temp);\n@chmod($temp, 0777);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\nself::$origdir = getcwd();\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path));\nif ($path[strlen($path) - 1] == '/') {\nmkdir($temp . '/' . $path);\n@chmod($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' . $pat! h, 0666);\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir( $temp);\nif (!$return) include self"; - static const char newstub3_1[] = "::START;\n}\n\nstatic function tmpdir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {\nreturn $var;\n}\nif (is_dir('/temp') || mkdir('/temp')) {\nreturn realpath('/temp');\n}\nreturn false;\n}\nif ($var = getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = ar! ray_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles()\n{\nif (count(se! lf::$tmp)) {\nforeach (array_reverse(self::$tmp) as $f) {\nif (file_ex ists($f)) is_dir($f) ? @rmdir($f) :"; - static const char newstub3_2[] = " @unlink($f);\n}\n\n}\nchdir(self::$origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; + static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled -' .\n' gzinflate() function needed for zlib-compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled -' .\n' bzdecompress() function needed for bz2-compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$temp || !is_writable($temp)) {\n$sessionpath = session_save_path();\nif (! strpos ($sessionpath, \";\") !== false)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) || !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract/'.basename(__FILE__, '.phar');\nself::$temp = $temp;\nself::$origdir = getcwd();\nif (file_exists(realpath($temp))) {\nif (file_exists($temp. DIRECTORY_SEPARATOR . md5_file(__FILE__))) {\nreturn;\n}\nself::_removeTmpFiles($temp, getcwd());\n}\n@mkdir($temp, 0777, true);\n$temp = realpath($temp);\nfile_put_contents($temp . '/' . md5_file(__FILE__), '');\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($path[strlen($path) - 1] == '/') {\n@mkdir($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' ! . $path, 0666);\n}\n}\nchdir($temp);\nif (!$return) {\ninclude self::S TART;\n}\n}\n\nstatic function tmpd"; + static const char newstub3_1[] = "ir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {\nreturn $var;\n}\nif (is_dir('/temp') || mkdir('/temp')) {\nreturn realpath('/temp');\n}\nreturn false;\n}\nif ($var = getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/V! f', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles($temp, $origdir)\n{\nchdir($temp);\nforeach (glob('*'! ) as $f) {\nif (file_exists($f)) {\nis_dir($f) ? @rmdir($f) : @unlink( $f);\nif (file_exists($f) && is_dir"; + static const char newstub3_2[] = "($f)) {\nself::_removeTmpFiles($f, getcwd());\n}\n}\n}\n@rmdir($temp);\nclearstatcache();\nchdir($origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; - static const int newstub_len = 7123; + static const int newstub_len = 6843; *len = spprintf(stub, name_len + web_len + newstub_len, "%s%s%s%s%s%s%d%s%s%s", newstub0, web, newstub1_0, newstub1_1, index_php, newstub2, name_len + web_len + newstub_len, newstub3_0, newstub3_1, newstub3_2); }
http://cvs.php.net/viewvc.cgi/pecl/phar/shortarc.php?r1=1.5&r2=1.6&diff_format=u Index: pecl/phar/shortarc.php diff -u pecl/phar/shortarc.php:1.5 pecl/phar/shortarc.php:1.6 --- pecl/phar/shortarc.php:1.5 Sat Jan 26 00:11:59 2008 +++ pecl/phar/shortarc.php Mon Jan 28 21:23:01 2008 @@ -1,273 +1,276 @@ -<?php -$web = '000'; -if ($web) { - if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { - Phar::interceptFileFuncs(); - Phar::webPhar(null, $web); - include 'phar://' . __FILE__ . '/' . Extract_Phar::START; - return; - } - if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { - Extract_Phar::go(true); - $mimes = array( - 'phps' => 2, - 'c' => 'text/plain', - 'cc' => 'text/plain', - 'cpp' => 'text/plain', - 'c++' => 'text/plain', - 'dtd' => 'text/plain', - 'h' => 'text/plain', - 'log' => 'text/plain', - 'rng' => 'text/plain', - 'txt' => 'text/plain', - 'xsd' => 'text/plain', - 'php' => 1, - 'inc' => 1, - 'avi' => 'video/avi', - 'bmp' => 'image/bmp', - 'css' => 'text/css', - 'gif' => 'image/gif', - 'htm' => 'text/html', - 'html' => 'text/html', - 'htmls' => 'text/html', - 'ico' => 'image/x-ico', - 'jpe' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'js' => 'application/x-javascript', - 'midi' => 'audio/midi', - 'mid' => 'audio/midi', - 'mod' => 'audio/mod', - 'mov' => 'movie/quicktime', - 'mp3' => 'audio/mp3', - 'mpg' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'pdf' => 'application/pdf', - 'png' => 'image/png', - 'swf' => 'application/shockwave-flash', - 'tif' => 'image/tiff', - 'tiff' => 'image/tiff', - 'wav' => 'audio/wav', - 'xbm' => 'image/xbm', - 'xml' => 'text/xml', - ); - $basename = basename(__FILE__); - if (!strpos($_SERVER['REQUEST_URI'], $basename)) { - chdir(Extract_Phar::$temp); - include Extract_Phar::START; - } - $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); - if (!$pt || $pt == '/') { - $pt = $web; - header('HTTP/1.1 301 Moved Permanently'); - header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); - } - $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); - if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { - header('HTTP/1.0 404 Not Found'); - 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>"; - exit; - } - $b = pathinfo($a); - if (!isset($b['extension'])) { - header('Content-Type: text/plain'); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; - } - if (isset($mimes[$b['extension']])) { - if ($mimes[$b['extension']] === 1) { - $_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO']; - $_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename)); - if (isset($_SERVER['PATH_TRANSLATED'])) { - $_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED']; - $_SERVER['PATH_TRANSLATED'] = $a; - } - include $a; - exit; - } - if ($mimes[$b['extension']] === 2) { - highlight_file($a); - exit; - } - header('Content-Type: ' .$mimes[$b['extension']]); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; - } - } -} -if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { - Phar::interceptFileFuncs(); - include 'phar://' . __FILE__ . '/' . Extract_Phar::START; - return; -} -class Extract_Phar -{ - static $temp; - static $tmp = array(); - static $origdir; - const GZ = 0x1000; - const BZ2 = 0x2000; - const MASK = 0x3000; - const START = 'index.php'; - const LEN = XXXX; - static function go($return = false) - { - register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); - $fp = fopen(__FILE__, 'rb'); - fseek($fp, self::LEN); - $L = unpack('V', $a = fread($fp, 4)); - $m = ''; - do { - $read = 8192; - if ($L[1] - strlen($m) < 8192) { - $read = $L[1] - strlen($m); - } - $last = fread($fp, $read); - $m .= $last; - } while (strlen($last) && strlen($m) < $L[1]); - if (strlen($m) < $L[1]) { - die('ERROR: manifest length read was "' . - strlen($m) .'" should be "' . - $L[1] . '"'); - } - $info = self::_unpack($m); - $f = $info['c']; - if ($f & self::GZ) { - if (!function_exists('gzinflate')) { - die('Error: zlib extension is not enabled -' . - ' gzinflate() function needed for zlib-compressed .phars'); - } - } - if ($f & self::BZ2) { - if (!function_exists('bzdecompress')) { - die('Error: bzip2 extension is not enabled -' . - ' bzdecompress() function needed for bz2-compressed .phars'); - } - } - $temp = self::tmpdir(); - if (!$temp || !is_writable($temp)) { - $sessionpath = session_save_path(); - if (strpos ($sessionpath, ";") !== false) - $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); - if (!file_exists($sessionpath) || !is_dir($sessionpath)) { - die('Could not locate temporary directory to extract phar'); - } - $temp = $sessionpath; - } - $temp .= '/pharextract'; - self::$temp = $temp; - while (file_exists($temp)) { - $temp .= 1; - } - @mkdir($temp); - @chmod($temp, 0777); - $temp = realpath($temp); - self::$tmp[] = $temp; - self::$origdir = getcwd(); - foreach ($info['m'] as $path => $file) { - $a = !file_exists(dirname($temp . '/' . $path)); - @mkdir(dirname($temp . '/' . $path), 0777, true); - clearstatcache(); - if ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path)); - if ($path[strlen($path) - 1] == '/') { - mkdir($temp . '/' . $path); - @chmod($temp . '/' . $path, 0777); - } else { - file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); - @chmod($temp . '/' . $path, 0666); - } - self::$tmp[] = realpath($temp . '/' . $path); - } - chdir($temp); - if (!$return) include self::START; - } - - static function tmpdir() - { - if (strpos(PHP_OS, 'WIN') !== false) { - if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { - return $var; - } - if (is_dir('/temp') || mkdir('/temp')) { - return realpath('/temp'); - } - return false; - } - if ($var = getenv('TMPDIR')) { - return $var; - } - return realpath('/tmp'); - } - - static function _unpack($m) - { - $info = unpack('V', substr($m, 0, 4)); - // skip API version, phar flags, alias, metadata - $l = unpack('V', substr($m, 10, 4)); - $m = substr($m, 14 + $l[1]); - $s = unpack('V', substr($m, 0, 4)); - $o = 0; - $start = 4 + $s[1]; - $ret['c'] = 0; - for ($i = 0; $i < $info[1]; $i++) { - // length of the file name - $len = unpack('V', substr($m, $start, 4)); - $start += 4; - // file name - $savepath = substr($m, $start, $len[1]); - $start += $len[1]; - // retrieve manifest data: - // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags - // 5 = metadata length - $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); - $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] - & 0xffffffff); - $ret['m'][$savepath][7] = $o; - $o += $ret['m'][$savepath][2]; - $start += 24 + $ret['m'][$savepath][5]; - $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; - } - return $ret; - } - - static function extractFile($path, $entry, $fp) - { - $data = ''; - $c = $entry[2]; - while ($c) { - if ($c < 8192) { - $data .= @fread($fp, $c); - $c = 0; - } else { - $c -= 8192; - $data .= @fread($fp, 8192); - } - } - if ($entry[4] & self::GZ) { - $data = gzinflate($data); - } elseif ($entry[4] & self::BZ2) { - $data = bzdecompress($data); - } - if (strlen($data) != $entry[0]) { - die("Invalid internal .phar file (size error " . strlen($data) . " != " . - $stat[7] . ")"); - } - if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { - die("Invalid internal .phar file (checksum error)"); - } - return $data; - } - - static function _removeTmpFiles() - { - if (count(self::$tmp)) { - foreach (array_reverse(self::$tmp) as $f) { - if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); - } - - } - chdir(self::$origdir); - } -} +<?php +$web = '000'; +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { + Phar::interceptFileFuncs(); + if (!$web || PHP_SAPI == 'cli') { + include 'phar://' . __FILE__ . '/' . Extract_Phar::START; + } else { + Phar::webPhar(null, $web); + include 'phar://' . __FILE__ . '/' . $web; + } + exit; +} +if ($web) { + if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST')) { + Extract_Phar::go(true); + $mimes = array( + 'phps' => 2, + 'c' => 'text/plain', + 'cc' => 'text/plain', + 'cpp' => 'text/plain', + 'c++' => 'text/plain', + 'dtd' => 'text/plain', + 'h' => 'text/plain', + 'log' => 'text/plain', + 'rng' => 'text/plain', + 'txt' => 'text/plain', + 'xsd' => 'text/plain', + 'php' => 1, + 'inc' => 1, + 'avi' => 'video/avi', + 'bmp' => 'image/bmp', + 'css' => 'text/css', + 'gif' => 'image/gif', + 'htm' => 'text/html', + 'html' => 'text/html', + 'htmls' => 'text/html', + 'ico' => 'image/x-ico', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'js' => 'application/x-javascript', + 'midi' => 'audio/midi', + 'mid' => 'audio/midi', + 'mod' => 'audio/mod', + 'mov' => 'movie/quicktime', + 'mp3' => 'audio/mp3', + 'mpg' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'pdf' => 'application/pdf', + 'png' => 'image/png', + 'swf' => 'application/shockwave-flash', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'wav' => 'audio/wav', + 'xbm' => 'image/xbm', + 'xml' => 'text/xml', + ); + + header("Cache-Control: no-cache, must-revalidate"); + header("Pragma: no-cache"); + + $basename = basename(__FILE__); + if (!strpos($_SERVER['REQUEST_URI'], $basename)) { + chdir(Extract_Phar::$temp); + include $web; + return; + } + $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); + if (!$pt || $pt == '/') { + $pt = $web; + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); + exit; + } + $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); + if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { + header('HTTP/1.0 404 Not Found'); + 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>"; + exit; + } + $b = pathinfo($a); + if (!isset($b['extension'])) { + header('Content-Type: text/plain'); + header('Content-Length: ' . filesize($a)); + readfile($a); + exit; + } + if (isset($mimes[$b['extension']])) { + if ($mimes[$b['extension']] === 1) { + include $a; + return; + } + if ($mimes[$b['extension']] === 2) { + highlight_file($a); + } + header('Content-Type: ' .$mimes[$b['extension']]); + header('Content-Length: ' . filesize($a)); + readfile($a); + exit; + } + } +} + +class Extract_Phar +{ + static $temp; + static $origdir; + const GZ = 0x1000; + const BZ2 = 0x2000; + const MASK = 0x3000; + const START = 'index.php'; + const LEN = XXXX; + static function go($return = false) + { + $fp = fopen(__FILE__, 'rb'); + fseek($fp, self::LEN); + $L = unpack('V', $a = fread($fp, 4)); + $m = ''; + do { + $read = 8192; + if ($L[1] - strlen($m) < 8192) { + $read = $L[1] - strlen($m); + } + $last = fread($fp, $read); + $m .= $last; + } while (strlen($last) && strlen($m) < $L[1]); + if (strlen($m) < $L[1]) { + die('ERROR: manifest length read was "' . + strlen($m) .'" should be "' . + $L[1] . '"'); + } + $info = self::_unpack($m); + $f = $info['c']; + if ($f & self::GZ) { + if (!function_exists('gzinflate')) { + die('Error: zlib extension is not enabled -' . + ' gzinflate() function needed for zlib-compressed .phars'); + } + } + if ($f & self::BZ2) { + if (!function_exists('bzdecompress')) { + die('Error: bzip2 extension is not enabled -' . + ' bzdecompress() function needed for bz2-compressed .phars'); + } + } + $temp = self::tmpdir(); + if (!$temp || !is_writable($temp)) { + $sessionpath = session_save_path(); + if (strpos ($sessionpath, ";") !== false) + $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); + if (!file_exists($sessionpath) || !is_dir($sessionpath)) { + die('Could not locate temporary directory to extract phar'); + } + $temp = $sessionpath; + } + $temp .= '/pharextract/'.basename(__FILE__, '.phar'); + self::$temp = $temp; + self::$origdir = getcwd(); + if (file_exists(realpath($temp))) { + if (file_exists($temp. DIRECTORY_SEPARATOR . md5_file(__FILE__))) { + return; + } + self::_removeTmpFiles($temp, getcwd()); + } + @mkdir($temp, 0777, true); + $temp = realpath($temp); + file_put_contents($temp . '/' . md5_file(__FILE__), ''); + foreach ($info['m'] as $path => $file) { + $a = !file_exists(dirname($temp . '/' . $path)); + @mkdir(dirname($temp . '/' . $path), 0777, true); + clearstatcache(); + if ($path[strlen($path) - 1] == '/') { + @mkdir($temp . '/' . $path, 0777); + } else { + file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); + @chmod($temp . '/' . $path, 0666); + } + } + chdir($temp); + if (!$return) { + include self::START; + } + } + + static function tmpdir() + { + if (strpos(PHP_OS, 'WIN') !== false) { + if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { + return $var; + } + if (is_dir('/temp') || mkdir('/temp')) { + return realpath('/temp'); + } + return false; + } + if ($var = getenv('TMPDIR')) { + return $var; + } + return realpath('/tmp'); + } + + static function _unpack($m) + { + $info = unpack('V', substr($m, 0, 4)); + // skip API version, phar flags, alias, metadata + $l = unpack('V', substr($m, 10, 4)); + $m = substr($m, 14 + $l[1]); + $s = unpack('V', substr($m, 0, 4)); + $o = 0; + $start = 4 + $s[1]; + $ret['c'] = 0; + for ($i = 0; $i < $info[1]; $i++) { + // length of the file name + $len = unpack('V', substr($m, $start, 4)); + $start += 4; + // file name + $savepath = substr($m, $start, $len[1]); + $start += $len[1]; + // retrieve manifest data: + // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags + // 5 = metadata length + $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); + $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] + & 0xffffffff); + $ret['m'][$savepath][7] = $o; + $o += $ret['m'][$savepath][2]; + $start += 24 + $ret['m'][$savepath][5]; + $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; + } + return $ret; + } + + static function extractFile($path, $entry, $fp) + { + $data = ''; + $c = $entry[2]; + while ($c) { + if ($c < 8192) { + $data .= @fread($fp, $c); + $c = 0; + } else { + $c -= 8192; + $data .= @fread($fp, 8192); + } + } + if ($entry[4] & self::GZ) { + $data = gzinflate($data); + } elseif ($entry[4] & self::BZ2) { + $data = bzdecompress($data); + } + if (strlen($data) != $entry[0]) { + die("Invalid internal .phar file (size error " . strlen($data) . " != " . + $stat[7] . ")"); + } + if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { + die("Invalid internal .phar file (checksum error)"); + } + return $data; + } + + static function _removeTmpFiles($temp, $origdir) + { + chdir($temp); + foreach (glob('*') as $f) { + if (file_exists($f)) { + is_dir($f) ? @rmdir($f) : @unlink($f); + if (file_exists($f) && is_dir($f)) { + self::_removeTmpFiles($f, getcwd()); + } + } + } + @rmdir($temp); + clearstatcache(); + chdir($origdir); + } +} http://cvs.php.net/viewvc.cgi/pecl/phar/stub.h?r1=1.5&r2=1.6&diff_format=u Index: pecl/phar/stub.h diff -u pecl/phar/stub.h:1.5 pecl/phar/stub.h:1.6 --- pecl/phar/stub.h:1.5 Sat Jan 26 00:11:59 2008 +++ pecl/phar/stub.h Mon Jan 28 21:23:01 2008 @@ -16,19 +16,19 @@ +----------------------------------------------------------------------+ */ -/* $Id: stub.h,v 1.5 2008/01/26 00:11:59 sfox Exp $ */ +/* $Id: stub.h,v 1.6 2008/01/28 21:23:01 sfox Exp $ */ static inline void phar_get_stub(const char *index_php, const char *web, size_t *len, char **stub, const int name_len, const int web_len TSRMLS_DC) { static const char newstub0[] = "<?php\n$web = '"; - static const char newstub1_0[] = "';\nif ($web) {\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nif (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico' => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n! 'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude Extract_Phar::START;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);\nif (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\ne! cho \"<html>\\n <head>\\n <title>File Not Found<title>\\n </head>\\n <body>\\n <h1>404 - File \", $pt, "; - static const char newstub1_1[] = "\" Not Found</h1>\\n </body>\\n</html>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\n$_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO'];\n$_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename));\nif (isset($_SERVER['PATH_TRANSLATED'])) {\n$_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED'];\n$_SERVER['PATH_TRANSLATED'] = $a;\n}\ninclude $a;\nexit;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\nexit;\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\n}\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\ninclude 'phar://' . __FIL! E__ . '/' . Extract_Phar::START;\nreturn;\n}\nclass Extract_Phar\n{\nstatic $temp;\nstatic $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; + static const char newstub1_0[] = "';\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nif (!$web || PHP_SAPI == 'cli') {\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\n} else {\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . $web;\n}\nexit;\n}\nif ($web) {\nif (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST')) {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico'! => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n\nheader(\"Cache-Control: no-cache, must-revalidate\");\nheader(\"Pragma: no-cache\");\n\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude $web;\nreturn;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' .! $pt);\nexit;\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARA TOR . $pt);\nif (!$a || strlen(dirn"; + static const char newstub1_1[] = "ame($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\necho \"<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>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\ninclude $a;\nreturn;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\n}\n\nclass Extract_Phar\n{\nstatic $temp;\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; static const char newstub2[] = "';\nconst LEN = "; - static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled -' .\n' gzinflate() function needed for zlib-compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled -' .\n' bzdecompress() function needed for bz2-compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$te! mp || !is_writable($temp)) {\n$sessionpath = session_save_path();\nif (strpos ($sessionpath, \";\") !== false)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) || !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract';\nself::$temp = $temp;\nwhile (file_exists($temp)) {\n$temp .= 1;\n}\n@mkdir($temp);\n@chmod($temp, 0777);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\nself::$origdir = getcwd();\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path));\nif ($path[strlen($path) - 1] == '/') {\nmkdir($temp . '/' . $path);\n@chmod($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' . $pat! h, 0666);\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir( $temp);\nif (!$return) include self"; - static const char newstub3_1[] = "::START;\n}\n\nstatic function tmpdir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {\nreturn $var;\n}\nif (is_dir('/temp') || mkdir('/temp')) {\nreturn realpath('/temp');\n}\nreturn false;\n}\nif ($var = getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = ar! ray_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles()\n{\nif (count(se! lf::$tmp)) {\nforeach (array_reverse(self::$tmp) as $f) {\nif (file_ex ists($f)) is_dir($f) ? @rmdir($f) :"; - static const char newstub3_2[] = " @unlink($f);\n}\n\n}\nchdir(self::$origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; + static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled -' .\n' gzinflate() function needed for zlib-compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled -' .\n' bzdecompress() function needed for bz2-compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$temp || !is_writable($temp)) {\n$sessionpath = session_save_path();\nif (! strpos ($sessionpath, \";\") !== false)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) || !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract/'.basename(__FILE__, '.phar');\nself::$temp = $temp;\nself::$origdir = getcwd();\nif (file_exists(realpath($temp))) {\nif (file_exists($temp. DIRECTORY_SEPARATOR . md5_file(__FILE__))) {\nreturn;\n}\nself::_removeTmpFiles($temp, getcwd());\n}\n@mkdir($temp, 0777, true);\n$temp = realpath($temp);\nfile_put_contents($temp . '/' . md5_file(__FILE__), '');\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($path[strlen($path) - 1] == '/') {\n@mkdir($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' ! . $path, 0666);\n}\n}\nchdir($temp);\nif (!$return) {\ninclude self::S TART;\n}\n}\n\nstatic function tmpd"; + static const char newstub3_1[] = "ir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {\nreturn $var;\n}\nif (is_dir('/temp') || mkdir('/temp')) {\nreturn realpath('/temp');\n}\nreturn false;\n}\nif ($var = getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/V! f', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles($temp, $origdir)\n{\nchdir($temp);\nforeach (glob('*'! ) as $f) {\nif (file_exists($f)) {\nis_dir($f) ? @rmdir($f) : @unlink( $f);\nif (file_exists($f) && is_dir"; + static const char newstub3_2[] = "($f)) {\nself::_removeTmpFiles($f, getcwd());\n}\n}\n}\n@rmdir($temp);\nclearstatcache();\nchdir($origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; - static const int newstub_len = 7123; + static const int newstub_len = 6843; *len = spprintf(stub, name_len + web_len + newstub_len, "%s%s%s%s%s%s%d%s%s%s", newstub0, web, newstub1_0, newstub1_1, index_php, newstub2, name_len + web_len + newstub_len, newstub3_0, newstub3_1, newstub3_2); }