* @author Greg Beaver * @link http://www.synapticmedia.net Synaptic Media * @version Id$ * @package PHP_Archive * @category PHP */ class PHP_Archive { const GZ = 0x00001000; const BZ2 = 0x00002000; const SIG = 0x00010000; const SHA1 = 0x0002; const MD5 = 0x0001; const SHA256 = 0x0003; const SHA512 = 0x0004; const OPENSSL = 0x0010; /** * Whether this archive is compressed with zlib * * @var bool */ private $_compressed; /** * @var string Real path to the .phar archive */ private $_archiveName = null; /** * Current file name in the phar * @var string */ protected $currentFilename = null; /** * Length of current file in the phar * @var string */ protected $internalFileLength = null; /** * true if the current file is an empty directory * @var string */ protected $isDir = false; /** * Current file statistics (size, creation date, etc.) * @var string */ protected $currentStat = null; /** * @var resource|null Pointer to open .phar */ protected $fp = null; /** * @var int Current Position of the pointer */ protected $position = 0; /** * Map actual realpath of phars to meta-data about the phar * * Data is indexed by the alias that is used by internal files. In other * words, if a file is included via: * * require_once 'phar://PEAR.phar/PEAR/Installer.php'; * * then the alias is "PEAR.phar" * * Information stored is a boolean indicating whether this .phar is compressed * with zlib, another for bzip2, phar-specific meta-data, and * the precise offset of internal files * within the .phar, used with the {@link $_manifest} to load actual file contents * @var array */ private static $_pharMapping = array(); /** * Map real file paths to alias used * * @var array */ private static $_pharFiles = array(); /** * File listing for the .phar * * The manifest is indexed per phar. * * Files within the .phar are indexed by their relative path within the * .phar. Each file has this information in its internal array * * - 0 = uncompressed file size * - 1 = timestamp of when file was added to phar * - 2 = offset of file within phar relative to internal file's start * - 3 = compressed file size (actual size in the phar) * @var array */ private static $_manifest = array(); /** * Absolute offset of internal files within the .phar, indexed by absolute * path to the .phar * * @var array */ private static $_fileStart = array(); /** * file name of the phar * * @var string */ private $_basename; /** * Default MIME types used for the web front controller * * @var array */ public static $defaultmimes = array( 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'arc' => 'application/octet-stream', 'arj' => 'application/octet-stream', 'art' => 'image/x-jg', 'asf' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'avi' => 'video/avi', 'bin' => 'application/octet-stream', 'bm' => 'image/bmp', 'bmp' => 'image/bmp', 'bz2' => 'application/x-bzip2', 'css' => 'text/css', 'doc' => 'application/msword', 'dot' => 'application/msword', 'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi', 'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'gif' => 'image/gif', 'gz' => 'application/x-gzip', 'gzip' => 'application/x-gzip', 'htm' => 'text/html', 'html' => 'text/html', 'ico' => 'image/x-icon', 'jpe' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'js' => 'application/x-javascript', 'log' => 'text/plain', 'mid' => 'audio/x-midi', 'mov' => 'video/quicktime', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg3', 'mpg' => 'audio/mpeg', 'pdf' => 'aplication/pdf', 'png' => 'image/png', 'rtf' => 'application/rtf', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'txt' => 'text/plain', 'xml' => 'text/xml', ); public static $defaultphp = array( 'php' => true ); public static $defaultphps = array( 'phps' => true ); public static $deny = array('/.+\.inc$/'); public static function viewSource($archive, $file) { // security, idea borrowed from PHK if (!file_exists($archive . '.introspect')) { header("HTTP/1.0 404 Not Found"); return false; } if (self::_fileExists($archive, $_GET['viewsource'])) { $source = highlight_file('phar://go-pear.phar/' . $_GET['viewsource'], true); header('Content-Type: text/html'); header('Content-Length: ' . strlen($source)); echo 'Source of ', htmlspecialchars($_GET['viewsource']), ''; echo '

Source of ', htmlspecialchars($_GET['viewsource']), '

'; if (isset($_GET['introspect'])) { echo 'Return to ', htmlspecialchars($_GET['introspect']), '
'; } echo $source; return false; } else { header("HTTP/1.0 404 Not Found"); return false; } } public static function introspect($archive, $dir) { // security, idea borrowed from PHK if (!file_exists($archive . '.introspect')) { header("HTTP/1.0 404 Not Found"); return false; } if (!$dir) { $dir = '/'; } $dir = self::processFile($dir); if ($dir[0] != '/') { $dir = '/' . $dir; } try { $self = htmlspecialchars($_SERVER['PHP_SELF']); $iterate = new DirectoryIterator('phar://go-pear.phar' . $dir); echo 'Introspect ', htmlspecialchars($dir), '

Introspect ', htmlspecialchars($dir), '