Annotation of embedaddon/php/ext/phar/tests/phar_createdefaultstub.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Phar: Phar::createDefaultStub() with and without arg
! 3: --SKIPIF--
! 4: <?php if (!extension_loaded("phar")) die("skip"); ?>
! 5: --FILE--
! 6: <?php
! 7: try {
! 8: var_dump(Phar::createDefaultStub());
! 9: echo "============================================================================\n";
! 10: echo "============================================================================\n";
! 11: var_dump(Phar::createDefaultStub('my/custom/thingy.php'));
! 12: echo "============================================================================\n";
! 13: echo "============================================================================\n";
! 14: var_dump(strlen(Phar::createDefaultStub(str_repeat('a', 400))));
! 15: echo "============================================================================\n";
! 16: echo "============================================================================\n";
! 17: var_dump(Phar::createDefaultStub(str_repeat('a', 401)));
! 18: } catch(Exception $e) {
! 19: echo $e->getMessage() . "\n";
! 20: }
! 21: echo "============================================================================\n";
! 22: echo "============================================================================\n";
! 23: echo "============================================================================\n";
! 24: echo "============================================================================\n";
! 25: try {
! 26: var_dump(Phar::createDefaultStub('my/custom/thingy.php', 'the/web.php'));
! 27: echo "============================================================================\n";
! 28: echo "============================================================================\n";
! 29: var_dump(strlen(Phar::createDefaultStub('index.php', str_repeat('a', 400))));
! 30: var_dump(Phar::createDefaultStub('hio', str_repeat('a', 401)));
! 31: } catch (Exception $e) {
! 32: echo $e->getMessage() . "\n";
! 33: }
! 34: ?>
! 35: ===DONE===
! 36: --EXPECT--
! 37: string(6683) "<?php
! 38:
! 39: $web = 'index.php';
! 40:
! 41: if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
! 42: Phar::interceptFileFuncs();
! 43: set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
! 44: Phar::webPhar(null, $web);
! 45: include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
! 46: return;
! 47: }
! 48:
! 49: if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
! 50: Extract_Phar::go(true);
! 51: $mimes = array(
! 52: 'phps' => 2,
! 53: 'c' => 'text/plain',
! 54: 'cc' => 'text/plain',
! 55: 'cpp' => 'text/plain',
! 56: 'c++' => 'text/plain',
! 57: 'dtd' => 'text/plain',
! 58: 'h' => 'text/plain',
! 59: 'log' => 'text/plain',
! 60: 'rng' => 'text/plain',
! 61: 'txt' => 'text/plain',
! 62: 'xsd' => 'text/plain',
! 63: 'php' => 1,
! 64: 'inc' => 1,
! 65: 'avi' => 'video/avi',
! 66: 'bmp' => 'image/bmp',
! 67: 'css' => 'text/css',
! 68: 'gif' => 'image/gif',
! 69: 'htm' => 'text/html',
! 70: 'html' => 'text/html',
! 71: 'htmls' => 'text/html',
! 72: 'ico' => 'image/x-ico',
! 73: 'jpe' => 'image/jpeg',
! 74: 'jpg' => 'image/jpeg',
! 75: 'jpeg' => 'image/jpeg',
! 76: 'js' => 'application/x-javascript',
! 77: 'midi' => 'audio/midi',
! 78: 'mid' => 'audio/midi',
! 79: 'mod' => 'audio/mod',
! 80: 'mov' => 'movie/quicktime',
! 81: 'mp3' => 'audio/mp3',
! 82: 'mpg' => 'video/mpeg',
! 83: 'mpeg' => 'video/mpeg',
! 84: 'pdf' => 'application/pdf',
! 85: 'png' => 'image/png',
! 86: 'swf' => 'application/shockwave-flash',
! 87: 'tif' => 'image/tiff',
! 88: 'tiff' => 'image/tiff',
! 89: 'wav' => 'audio/wav',
! 90: 'xbm' => 'image/xbm',
! 91: 'xml' => 'text/xml',
! 92: );
! 93:
! 94: header("Cache-Control: no-cache, must-revalidate");
! 95: header("Pragma: no-cache");
! 96:
! 97: $basename = basename(__FILE__);
! 98: if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
! 99: chdir(Extract_Phar::$temp);
! 100: include $web;
! 101: return;
! 102: }
! 103: $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
! 104: if (!$pt || $pt == '/') {
! 105: $pt = $web;
! 106: header('HTTP/1.1 301 Moved Permanently');
! 107: header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
! 108: exit;
! 109: }
! 110: $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
! 111: if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
! 112: header('HTTP/1.0 404 Not Found');
! 113: 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>";
! 114: exit;
! 115: }
! 116: $b = pathinfo($a);
! 117: if (!isset($b['extension'])) {
! 118: header('Content-Type: text/plain');
! 119: header('Content-Length: ' . filesize($a));
! 120: readfile($a);
! 121: exit;
! 122: }
! 123: if (isset($mimes[$b['extension']])) {
! 124: if ($mimes[$b['extension']] === 1) {
! 125: include $a;
! 126: exit;
! 127: }
! 128: if ($mimes[$b['extension']] === 2) {
! 129: highlight_file($a);
! 130: exit;
! 131: }
! 132: header('Content-Type: ' .$mimes[$b['extension']]);
! 133: header('Content-Length: ' . filesize($a));
! 134: readfile($a);
! 135: exit;
! 136: }
! 137: }
! 138:
! 139: class Extract_Phar
! 140: {
! 141: static $temp;
! 142: static $origdir;
! 143: const GZ = 0x1000;
! 144: const BZ2 = 0x2000;
! 145: const MASK = 0x3000;
! 146: const START = 'index.php';
! 147: const LEN = 6685;
! 148:
! 149: static function go($return = false)
! 150: {
! 151: $fp = fopen(__FILE__, 'rb');
! 152: fseek($fp, self::LEN);
! 153: $L = unpack('V', $a = (binary)fread($fp, 4));
! 154: $m = (binary)'';
! 155:
! 156: do {
! 157: $read = 8192;
! 158: if ($L[1] - strlen($m) < 8192) {
! 159: $read = $L[1] - strlen($m);
! 160: }
! 161: $last = (binary)fread($fp, $read);
! 162: $m .= $last;
! 163: } while (strlen($last) && strlen($m) < $L[1]);
! 164:
! 165: if (strlen($m) < $L[1]) {
! 166: die('ERROR: manifest length read was "' .
! 167: strlen($m) .'" should be "' .
! 168: $L[1] . '"');
! 169: }
! 170:
! 171: $info = self::_unpack($m);
! 172: $f = $info['c'];
! 173:
! 174: if ($f & self::GZ) {
! 175: if (!function_exists('gzinflate')) {
! 176: die('Error: zlib extension is not enabled -' .
! 177: ' gzinflate() function needed for zlib-compressed .phars');
! 178: }
! 179: }
! 180:
! 181: if ($f & self::BZ2) {
! 182: if (!function_exists('bzdecompress')) {
! 183: die('Error: bzip2 extension is not enabled -' .
! 184: ' bzdecompress() function needed for bz2-compressed .phars');
! 185: }
! 186: }
! 187:
! 188: $temp = self::tmpdir();
! 189:
! 190: if (!$temp || !is_writable($temp)) {
! 191: $sessionpath = session_save_path();
! 192: if (strpos ($sessionpath, ";") !== false)
! 193: $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
! 194: if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
! 195: die('Could not locate temporary directory to extract phar');
! 196: }
! 197: $temp = $sessionpath;
! 198: }
! 199:
! 200: $temp .= '/pharextract/'.basename(__FILE__, '.phar');
! 201: self::$temp = $temp;
! 202: self::$origdir = getcwd();
! 203: @mkdir($temp, 0777, true);
! 204: $temp = realpath($temp);
! 205:
! 206: if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
! 207: self::_removeTmpFiles($temp, getcwd());
! 208: @mkdir($temp, 0777, true);
! 209: @file_put_contents($temp . '/' . md5_file(__FILE__), '');
! 210:
! 211: foreach ($info['m'] as $path => $file) {
! 212: $a = !file_exists(dirname($temp . '/' . $path));
! 213: @mkdir(dirname($temp . '/' . $path), 0777, true);
! 214: clearstatcache();
! 215:
! 216: if ($path[strlen($path) - 1] == '/') {
! 217: @mkdir($temp . '/' . $path, 0777);
! 218: } else {
! 219: file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
! 220: @chmod($temp . '/' . $path, 0666);
! 221: }
! 222: }
! 223: }
! 224:
! 225: chdir($temp);
! 226:
! 227: if (!$return) {
! 228: include self::START;
! 229: }
! 230: }
! 231:
! 232: static function tmpdir()
! 233: {
! 234: if (strpos(PHP_OS, 'WIN') !== false) {
! 235: if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
! 236: return $var;
! 237: }
! 238: if (is_dir('/temp') || mkdir('/temp')) {
! 239: return realpath('/temp');
! 240: }
! 241: return false;
! 242: }
! 243: if ($var = getenv('TMPDIR')) {
! 244: return $var;
! 245: }
! 246: return realpath('/tmp');
! 247: }
! 248:
! 249: static function _unpack($m)
! 250: {
! 251: $info = unpack('V', substr($m, 0, 4));
! 252: $l = unpack('V', substr($m, 10, 4));
! 253: $m = substr($m, 14 + $l[1]);
! 254: $s = unpack('V', substr($m, 0, 4));
! 255: $o = 0;
! 256: $start = 4 + $s[1];
! 257: $ret['c'] = 0;
! 258:
! 259: for ($i = 0; $i < $info[1]; $i++) {
! 260: $len = unpack('V', substr($m, $start, 4));
! 261: $start += 4;
! 262: $savepath = substr($m, $start, $len[1]);
! 263: $start += $len[1];
! 264: $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
! 265: $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
! 266: & 0xffffffff);
! 267: $ret['m'][$savepath][7] = $o;
! 268: $o += $ret['m'][$savepath][2];
! 269: $start += 24 + $ret['m'][$savepath][5];
! 270: $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
! 271: }
! 272: return $ret;
! 273: }
! 274:
! 275: static function extractFile($path, $entry, $fp)
! 276: {
! 277: $data = '';
! 278: $c = $entry[2];
! 279:
! 280: while ($c) {
! 281: if ($c < 8192) {
! 282: $data .= @fread($fp, $c);
! 283: $c = 0;
! 284: } else {
! 285: $c -= 8192;
! 286: $data .= @fread($fp, 8192);
! 287: }
! 288: }
! 289:
! 290: if ($entry[4] & self::GZ) {
! 291: $data = gzinflate($data);
! 292: } elseif ($entry[4] & self::BZ2) {
! 293: $data = bzdecompress($data);
! 294: }
! 295:
! 296: if (strlen($data) != $entry[0]) {
! 297: die("Invalid internal .phar file (size error " . strlen($data) . " != " .
! 298: $stat[7] . ")");
! 299: }
! 300:
! 301: if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
! 302: die("Invalid internal .phar file (checksum error)");
! 303: }
! 304:
! 305: return $data;
! 306: }
! 307:
! 308: static function _removeTmpFiles($temp, $origdir)
! 309: {
! 310: chdir($temp);
! 311:
! 312: foreach (glob('*') as $f) {
! 313: if (file_exists($f)) {
! 314: is_dir($f) ? @rmdir($f) : @unlink($f);
! 315: if (file_exists($f) && is_dir($f)) {
! 316: self::_removeTmpFiles($f, getcwd());
! 317: }
! 318: }
! 319: }
! 320:
! 321: @rmdir($temp);
! 322: clearstatcache();
! 323: chdir($origdir);
! 324: }
! 325: }
! 326:
! 327: Extract_Phar::go();
! 328: __HALT_COMPILER(); ?>"
! 329: ============================================================================
! 330: ============================================================================
! 331: string(6694) "<?php
! 332:
! 333: $web = 'index.php';
! 334:
! 335: if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
! 336: Phar::interceptFileFuncs();
! 337: set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
! 338: Phar::webPhar(null, $web);
! 339: include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
! 340: return;
! 341: }
! 342:
! 343: if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
! 344: Extract_Phar::go(true);
! 345: $mimes = array(
! 346: 'phps' => 2,
! 347: 'c' => 'text/plain',
! 348: 'cc' => 'text/plain',
! 349: 'cpp' => 'text/plain',
! 350: 'c++' => 'text/plain',
! 351: 'dtd' => 'text/plain',
! 352: 'h' => 'text/plain',
! 353: 'log' => 'text/plain',
! 354: 'rng' => 'text/plain',
! 355: 'txt' => 'text/plain',
! 356: 'xsd' => 'text/plain',
! 357: 'php' => 1,
! 358: 'inc' => 1,
! 359: 'avi' => 'video/avi',
! 360: 'bmp' => 'image/bmp',
! 361: 'css' => 'text/css',
! 362: 'gif' => 'image/gif',
! 363: 'htm' => 'text/html',
! 364: 'html' => 'text/html',
! 365: 'htmls' => 'text/html',
! 366: 'ico' => 'image/x-ico',
! 367: 'jpe' => 'image/jpeg',
! 368: 'jpg' => 'image/jpeg',
! 369: 'jpeg' => 'image/jpeg',
! 370: 'js' => 'application/x-javascript',
! 371: 'midi' => 'audio/midi',
! 372: 'mid' => 'audio/midi',
! 373: 'mod' => 'audio/mod',
! 374: 'mov' => 'movie/quicktime',
! 375: 'mp3' => 'audio/mp3',
! 376: 'mpg' => 'video/mpeg',
! 377: 'mpeg' => 'video/mpeg',
! 378: 'pdf' => 'application/pdf',
! 379: 'png' => 'image/png',
! 380: 'swf' => 'application/shockwave-flash',
! 381: 'tif' => 'image/tiff',
! 382: 'tiff' => 'image/tiff',
! 383: 'wav' => 'audio/wav',
! 384: 'xbm' => 'image/xbm',
! 385: 'xml' => 'text/xml',
! 386: );
! 387:
! 388: header("Cache-Control: no-cache, must-revalidate");
! 389: header("Pragma: no-cache");
! 390:
! 391: $basename = basename(__FILE__);
! 392: if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
! 393: chdir(Extract_Phar::$temp);
! 394: include $web;
! 395: return;
! 396: }
! 397: $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
! 398: if (!$pt || $pt == '/') {
! 399: $pt = $web;
! 400: header('HTTP/1.1 301 Moved Permanently');
! 401: header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
! 402: exit;
! 403: }
! 404: $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
! 405: if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
! 406: header('HTTP/1.0 404 Not Found');
! 407: 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>";
! 408: exit;
! 409: }
! 410: $b = pathinfo($a);
! 411: if (!isset($b['extension'])) {
! 412: header('Content-Type: text/plain');
! 413: header('Content-Length: ' . filesize($a));
! 414: readfile($a);
! 415: exit;
! 416: }
! 417: if (isset($mimes[$b['extension']])) {
! 418: if ($mimes[$b['extension']] === 1) {
! 419: include $a;
! 420: exit;
! 421: }
! 422: if ($mimes[$b['extension']] === 2) {
! 423: highlight_file($a);
! 424: exit;
! 425: }
! 426: header('Content-Type: ' .$mimes[$b['extension']]);
! 427: header('Content-Length: ' . filesize($a));
! 428: readfile($a);
! 429: exit;
! 430: }
! 431: }
! 432:
! 433: class Extract_Phar
! 434: {
! 435: static $temp;
! 436: static $origdir;
! 437: const GZ = 0x1000;
! 438: const BZ2 = 0x2000;
! 439: const MASK = 0x3000;
! 440: const START = 'my/custom/thingy.php';
! 441: const LEN = 6696;
! 442:
! 443: static function go($return = false)
! 444: {
! 445: $fp = fopen(__FILE__, 'rb');
! 446: fseek($fp, self::LEN);
! 447: $L = unpack('V', $a = (binary)fread($fp, 4));
! 448: $m = (binary)'';
! 449:
! 450: do {
! 451: $read = 8192;
! 452: if ($L[1] - strlen($m) < 8192) {
! 453: $read = $L[1] - strlen($m);
! 454: }
! 455: $last = (binary)fread($fp, $read);
! 456: $m .= $last;
! 457: } while (strlen($last) && strlen($m) < $L[1]);
! 458:
! 459: if (strlen($m) < $L[1]) {
! 460: die('ERROR: manifest length read was "' .
! 461: strlen($m) .'" should be "' .
! 462: $L[1] . '"');
! 463: }
! 464:
! 465: $info = self::_unpack($m);
! 466: $f = $info['c'];
! 467:
! 468: if ($f & self::GZ) {
! 469: if (!function_exists('gzinflate')) {
! 470: die('Error: zlib extension is not enabled -' .
! 471: ' gzinflate() function needed for zlib-compressed .phars');
! 472: }
! 473: }
! 474:
! 475: if ($f & self::BZ2) {
! 476: if (!function_exists('bzdecompress')) {
! 477: die('Error: bzip2 extension is not enabled -' .
! 478: ' bzdecompress() function needed for bz2-compressed .phars');
! 479: }
! 480: }
! 481:
! 482: $temp = self::tmpdir();
! 483:
! 484: if (!$temp || !is_writable($temp)) {
! 485: $sessionpath = session_save_path();
! 486: if (strpos ($sessionpath, ";") !== false)
! 487: $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
! 488: if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
! 489: die('Could not locate temporary directory to extract phar');
! 490: }
! 491: $temp = $sessionpath;
! 492: }
! 493:
! 494: $temp .= '/pharextract/'.basename(__FILE__, '.phar');
! 495: self::$temp = $temp;
! 496: self::$origdir = getcwd();
! 497: @mkdir($temp, 0777, true);
! 498: $temp = realpath($temp);
! 499:
! 500: if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
! 501: self::_removeTmpFiles($temp, getcwd());
! 502: @mkdir($temp, 0777, true);
! 503: @file_put_contents($temp . '/' . md5_file(__FILE__), '');
! 504:
! 505: foreach ($info['m'] as $path => $file) {
! 506: $a = !file_exists(dirname($temp . '/' . $path));
! 507: @mkdir(dirname($temp . '/' . $path), 0777, true);
! 508: clearstatcache();
! 509:
! 510: if ($path[strlen($path) - 1] == '/') {
! 511: @mkdir($temp . '/' . $path, 0777);
! 512: } else {
! 513: file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
! 514: @chmod($temp . '/' . $path, 0666);
! 515: }
! 516: }
! 517: }
! 518:
! 519: chdir($temp);
! 520:
! 521: if (!$return) {
! 522: include self::START;
! 523: }
! 524: }
! 525:
! 526: static function tmpdir()
! 527: {
! 528: if (strpos(PHP_OS, 'WIN') !== false) {
! 529: if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
! 530: return $var;
! 531: }
! 532: if (is_dir('/temp') || mkdir('/temp')) {
! 533: return realpath('/temp');
! 534: }
! 535: return false;
! 536: }
! 537: if ($var = getenv('TMPDIR')) {
! 538: return $var;
! 539: }
! 540: return realpath('/tmp');
! 541: }
! 542:
! 543: static function _unpack($m)
! 544: {
! 545: $info = unpack('V', substr($m, 0, 4));
! 546: $l = unpack('V', substr($m, 10, 4));
! 547: $m = substr($m, 14 + $l[1]);
! 548: $s = unpack('V', substr($m, 0, 4));
! 549: $o = 0;
! 550: $start = 4 + $s[1];
! 551: $ret['c'] = 0;
! 552:
! 553: for ($i = 0; $i < $info[1]; $i++) {
! 554: $len = unpack('V', substr($m, $start, 4));
! 555: $start += 4;
! 556: $savepath = substr($m, $start, $len[1]);
! 557: $start += $len[1];
! 558: $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
! 559: $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
! 560: & 0xffffffff);
! 561: $ret['m'][$savepath][7] = $o;
! 562: $o += $ret['m'][$savepath][2];
! 563: $start += 24 + $ret['m'][$savepath][5];
! 564: $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
! 565: }
! 566: return $ret;
! 567: }
! 568:
! 569: static function extractFile($path, $entry, $fp)
! 570: {
! 571: $data = '';
! 572: $c = $entry[2];
! 573:
! 574: while ($c) {
! 575: if ($c < 8192) {
! 576: $data .= @fread($fp, $c);
! 577: $c = 0;
! 578: } else {
! 579: $c -= 8192;
! 580: $data .= @fread($fp, 8192);
! 581: }
! 582: }
! 583:
! 584: if ($entry[4] & self::GZ) {
! 585: $data = gzinflate($data);
! 586: } elseif ($entry[4] & self::BZ2) {
! 587: $data = bzdecompress($data);
! 588: }
! 589:
! 590: if (strlen($data) != $entry[0]) {
! 591: die("Invalid internal .phar file (size error " . strlen($data) . " != " .
! 592: $stat[7] . ")");
! 593: }
! 594:
! 595: if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
! 596: die("Invalid internal .phar file (checksum error)");
! 597: }
! 598:
! 599: return $data;
! 600: }
! 601:
! 602: static function _removeTmpFiles($temp, $origdir)
! 603: {
! 604: chdir($temp);
! 605:
! 606: foreach (glob('*') as $f) {
! 607: if (file_exists($f)) {
! 608: is_dir($f) ? @rmdir($f) : @unlink($f);
! 609: if (file_exists($f) && is_dir($f)) {
! 610: self::_removeTmpFiles($f, getcwd());
! 611: }
! 612: }
! 613: }
! 614:
! 615: @rmdir($temp);
! 616: clearstatcache();
! 617: chdir($origdir);
! 618: }
! 619: }
! 620:
! 621: Extract_Phar::go();
! 622: __HALT_COMPILER(); ?>"
! 623: ============================================================================
! 624: ============================================================================
! 625: int(7074)
! 626: ============================================================================
! 627: ============================================================================
! 628: Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
! 629: ============================================================================
! 630: ============================================================================
! 631: ============================================================================
! 632: ============================================================================
! 633: string(6696) "<?php
! 634:
! 635: $web = 'the/web.php';
! 636:
! 637: if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
! 638: Phar::interceptFileFuncs();
! 639: set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
! 640: Phar::webPhar(null, $web);
! 641: include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
! 642: return;
! 643: }
! 644:
! 645: if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
! 646: Extract_Phar::go(true);
! 647: $mimes = array(
! 648: 'phps' => 2,
! 649: 'c' => 'text/plain',
! 650: 'cc' => 'text/plain',
! 651: 'cpp' => 'text/plain',
! 652: 'c++' => 'text/plain',
! 653: 'dtd' => 'text/plain',
! 654: 'h' => 'text/plain',
! 655: 'log' => 'text/plain',
! 656: 'rng' => 'text/plain',
! 657: 'txt' => 'text/plain',
! 658: 'xsd' => 'text/plain',
! 659: 'php' => 1,
! 660: 'inc' => 1,
! 661: 'avi' => 'video/avi',
! 662: 'bmp' => 'image/bmp',
! 663: 'css' => 'text/css',
! 664: 'gif' => 'image/gif',
! 665: 'htm' => 'text/html',
! 666: 'html' => 'text/html',
! 667: 'htmls' => 'text/html',
! 668: 'ico' => 'image/x-ico',
! 669: 'jpe' => 'image/jpeg',
! 670: 'jpg' => 'image/jpeg',
! 671: 'jpeg' => 'image/jpeg',
! 672: 'js' => 'application/x-javascript',
! 673: 'midi' => 'audio/midi',
! 674: 'mid' => 'audio/midi',
! 675: 'mod' => 'audio/mod',
! 676: 'mov' => 'movie/quicktime',
! 677: 'mp3' => 'audio/mp3',
! 678: 'mpg' => 'video/mpeg',
! 679: 'mpeg' => 'video/mpeg',
! 680: 'pdf' => 'application/pdf',
! 681: 'png' => 'image/png',
! 682: 'swf' => 'application/shockwave-flash',
! 683: 'tif' => 'image/tiff',
! 684: 'tiff' => 'image/tiff',
! 685: 'wav' => 'audio/wav',
! 686: 'xbm' => 'image/xbm',
! 687: 'xml' => 'text/xml',
! 688: );
! 689:
! 690: header("Cache-Control: no-cache, must-revalidate");
! 691: header("Pragma: no-cache");
! 692:
! 693: $basename = basename(__FILE__);
! 694: if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
! 695: chdir(Extract_Phar::$temp);
! 696: include $web;
! 697: return;
! 698: }
! 699: $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
! 700: if (!$pt || $pt == '/') {
! 701: $pt = $web;
! 702: header('HTTP/1.1 301 Moved Permanently');
! 703: header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
! 704: exit;
! 705: }
! 706: $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
! 707: if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
! 708: header('HTTP/1.0 404 Not Found');
! 709: 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>";
! 710: exit;
! 711: }
! 712: $b = pathinfo($a);
! 713: if (!isset($b['extension'])) {
! 714: header('Content-Type: text/plain');
! 715: header('Content-Length: ' . filesize($a));
! 716: readfile($a);
! 717: exit;
! 718: }
! 719: if (isset($mimes[$b['extension']])) {
! 720: if ($mimes[$b['extension']] === 1) {
! 721: include $a;
! 722: exit;
! 723: }
! 724: if ($mimes[$b['extension']] === 2) {
! 725: highlight_file($a);
! 726: exit;
! 727: }
! 728: header('Content-Type: ' .$mimes[$b['extension']]);
! 729: header('Content-Length: ' . filesize($a));
! 730: readfile($a);
! 731: exit;
! 732: }
! 733: }
! 734:
! 735: class Extract_Phar
! 736: {
! 737: static $temp;
! 738: static $origdir;
! 739: const GZ = 0x1000;
! 740: const BZ2 = 0x2000;
! 741: const MASK = 0x3000;
! 742: const START = 'my/custom/thingy.php';
! 743: const LEN = 6698;
! 744:
! 745: static function go($return = false)
! 746: {
! 747: $fp = fopen(__FILE__, 'rb');
! 748: fseek($fp, self::LEN);
! 749: $L = unpack('V', $a = (binary)fread($fp, 4));
! 750: $m = (binary)'';
! 751:
! 752: do {
! 753: $read = 8192;
! 754: if ($L[1] - strlen($m) < 8192) {
! 755: $read = $L[1] - strlen($m);
! 756: }
! 757: $last = (binary)fread($fp, $read);
! 758: $m .= $last;
! 759: } while (strlen($last) && strlen($m) < $L[1]);
! 760:
! 761: if (strlen($m) < $L[1]) {
! 762: die('ERROR: manifest length read was "' .
! 763: strlen($m) .'" should be "' .
! 764: $L[1] . '"');
! 765: }
! 766:
! 767: $info = self::_unpack($m);
! 768: $f = $info['c'];
! 769:
! 770: if ($f & self::GZ) {
! 771: if (!function_exists('gzinflate')) {
! 772: die('Error: zlib extension is not enabled -' .
! 773: ' gzinflate() function needed for zlib-compressed .phars');
! 774: }
! 775: }
! 776:
! 777: if ($f & self::BZ2) {
! 778: if (!function_exists('bzdecompress')) {
! 779: die('Error: bzip2 extension is not enabled -' .
! 780: ' bzdecompress() function needed for bz2-compressed .phars');
! 781: }
! 782: }
! 783:
! 784: $temp = self::tmpdir();
! 785:
! 786: if (!$temp || !is_writable($temp)) {
! 787: $sessionpath = session_save_path();
! 788: if (strpos ($sessionpath, ";") !== false)
! 789: $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
! 790: if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
! 791: die('Could not locate temporary directory to extract phar');
! 792: }
! 793: $temp = $sessionpath;
! 794: }
! 795:
! 796: $temp .= '/pharextract/'.basename(__FILE__, '.phar');
! 797: self::$temp = $temp;
! 798: self::$origdir = getcwd();
! 799: @mkdir($temp, 0777, true);
! 800: $temp = realpath($temp);
! 801:
! 802: if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
! 803: self::_removeTmpFiles($temp, getcwd());
! 804: @mkdir($temp, 0777, true);
! 805: @file_put_contents($temp . '/' . md5_file(__FILE__), '');
! 806:
! 807: foreach ($info['m'] as $path => $file) {
! 808: $a = !file_exists(dirname($temp . '/' . $path));
! 809: @mkdir(dirname($temp . '/' . $path), 0777, true);
! 810: clearstatcache();
! 811:
! 812: if ($path[strlen($path) - 1] == '/') {
! 813: @mkdir($temp . '/' . $path, 0777);
! 814: } else {
! 815: file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
! 816: @chmod($temp . '/' . $path, 0666);
! 817: }
! 818: }
! 819: }
! 820:
! 821: chdir($temp);
! 822:
! 823: if (!$return) {
! 824: include self::START;
! 825: }
! 826: }
! 827:
! 828: static function tmpdir()
! 829: {
! 830: if (strpos(PHP_OS, 'WIN') !== false) {
! 831: if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
! 832: return $var;
! 833: }
! 834: if (is_dir('/temp') || mkdir('/temp')) {
! 835: return realpath('/temp');
! 836: }
! 837: return false;
! 838: }
! 839: if ($var = getenv('TMPDIR')) {
! 840: return $var;
! 841: }
! 842: return realpath('/tmp');
! 843: }
! 844:
! 845: static function _unpack($m)
! 846: {
! 847: $info = unpack('V', substr($m, 0, 4));
! 848: $l = unpack('V', substr($m, 10, 4));
! 849: $m = substr($m, 14 + $l[1]);
! 850: $s = unpack('V', substr($m, 0, 4));
! 851: $o = 0;
! 852: $start = 4 + $s[1];
! 853: $ret['c'] = 0;
! 854:
! 855: for ($i = 0; $i < $info[1]; $i++) {
! 856: $len = unpack('V', substr($m, $start, 4));
! 857: $start += 4;
! 858: $savepath = substr($m, $start, $len[1]);
! 859: $start += $len[1];
! 860: $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
! 861: $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
! 862: & 0xffffffff);
! 863: $ret['m'][$savepath][7] = $o;
! 864: $o += $ret['m'][$savepath][2];
! 865: $start += 24 + $ret['m'][$savepath][5];
! 866: $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
! 867: }
! 868: return $ret;
! 869: }
! 870:
! 871: static function extractFile($path, $entry, $fp)
! 872: {
! 873: $data = '';
! 874: $c = $entry[2];
! 875:
! 876: while ($c) {
! 877: if ($c < 8192) {
! 878: $data .= @fread($fp, $c);
! 879: $c = 0;
! 880: } else {
! 881: $c -= 8192;
! 882: $data .= @fread($fp, 8192);
! 883: }
! 884: }
! 885:
! 886: if ($entry[4] & self::GZ) {
! 887: $data = gzinflate($data);
! 888: } elseif ($entry[4] & self::BZ2) {
! 889: $data = bzdecompress($data);
! 890: }
! 891:
! 892: if (strlen($data) != $entry[0]) {
! 893: die("Invalid internal .phar file (size error " . strlen($data) . " != " .
! 894: $stat[7] . ")");
! 895: }
! 896:
! 897: if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
! 898: die("Invalid internal .phar file (checksum error)");
! 899: }
! 900:
! 901: return $data;
! 902: }
! 903:
! 904: static function _removeTmpFiles($temp, $origdir)
! 905: {
! 906: chdir($temp);
! 907:
! 908: foreach (glob('*') as $f) {
! 909: if (file_exists($f)) {
! 910: is_dir($f) ? @rmdir($f) : @unlink($f);
! 911: if (file_exists($f) && is_dir($f)) {
! 912: self::_removeTmpFiles($f, getcwd());
! 913: }
! 914: }
! 915: }
! 916:
! 917: @rmdir($temp);
! 918: clearstatcache();
! 919: chdir($origdir);
! 920: }
! 921: }
! 922:
! 923: Extract_Phar::go();
! 924: __HALT_COMPILER(); ?>"
! 925: ============================================================================
! 926: ============================================================================
! 927: int(7074)
! 928: Illegal web filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
! 929: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>