private function _readEndCentralDir(&$arCentralDir) { $res = 1; //going to the end of the file $size = filesize($this->io->GetPhysicalName($this->zipname)); @fseek($this->zipfile, $size); if (@ftell($this->zipfile) != $size) { $this->_errorLog("ERR_ARC_END", str_replace("#FILE_NAME#", removeDocRoot($this->zipname), GetMessage("MAIN_ZIP_ERR_ARC_END"))); return $this->arErrors; } //if archive is without comments (usually), the end of central dir is at 22 bytes of the file end $isFound = 0; $pos = 0; if ($size > 26) { @fseek($this->zipfile, $size - 22); if (($pos = @ftell($this->zipfile)) != $size - 22) { $this->_errorLog("ERR_ARC_MID", str_replace("#FILE_NAME#", removeDocRoot($this->zipname), GetMessage("MAIN_ZIP_ERR_ARC_MID"))); return $this->arErrors; } //read 4 bytes $binary_data = @fread($this->zipfile, 4); $data = unpack('Vid', $binary_data); //signature check if ($data['id'] == 0x6054b50) { $isFound = 1; } $pos = ftell($this->zipfile); } //going back to the max possible size of the Central Dir End Record if (!$isFound) { $maxSize = 65557; // 0xFFFF + 22; if ($maxSize > $size) { $maxSize = $size; } @fseek($this->zipfile, $size - $maxSize); if (@ftell($this->zipfile) != $size - $maxSize) { $this->_errorLog("ERR_ARC_MID", str_replace("#FILE_NAME#", removeDocRoot($this->zipname), GetMessage("MAIN_ZIP_ERR_ARC_MID"))); return $this->arErrors; } //reading byte per byte to find the signature $pos = ftell($this->zipfile); $bytes = 0x0; while ($pos < $size) { //reading 1 byte $byte = @fread($this->zipfile, 1); //adding the byte $bytes = $bytes << 8 | ord($byte); //compare bytes if ($bytes == 0x504b0506) { $pos++; break; } $pos++; } //if end of the central dir is not found if ($pos == $size) { $this->_errorLog("ERR_ARC_MID_END", GetMessage("MAIN_ZIP_ERR_ARC_MID_END")); return $this->arErrors; } } //reading first 18 bytes of the header $binary_data = fread($this->zipfile, 18); //if block size is not valid if ((self::$bMbstring ? mb_strlen($binary_data, "latin1") : strlen($binary_data)) != 18) { $this->_errorLog("ERR_ARC_END_SIZE", str_replace("#SIZE#", strlen($binary_data), GetMessage("MAIN_ZIP_ERR_ARC_END_SIZE"))); return $this->arErrors; } //extracting values $data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $binary_data); //checking global size if ($pos + $data['comment_size'] + 18 != $size) { $this->_errorLog("ERR_SIGNATURE", GetMessage("MAIN_ZIP_ERR_SIGNATURE")); return $this->arErrors; } //reading comments if ($data['comment_size'] != 0) { $arCentralDir['comment'] = fread($this->zipfile, $data['comment_size']); } else { $arCentralDir['comment'] = ''; } $arCentralDir['entries'] = $data['entries']; $arCentralDir['disk_entries'] = $data['disk_entries']; $arCentralDir['offset'] = $data['offset']; $arCentralDir['size'] = $data['size']; $arCentralDir['disk'] = $data['disk']; $arCentralDir['disk_start'] = $data['disk_start']; return $res; }
private function _openRead() { if ($this->_bCompress) { $this->_dFile = @gzopen($this->io->GetPhysicalName($this->_strArchiveName), "rb"); } else { $this->_dFile = @fopen($this->io->GetPhysicalName($this->_strArchiveName), "rb"); } if (!$this->_dFile) { $this->_arErrors[] = array("ERR_OPEN", str_replace("#FILE_NAME#", removeDocRoot($this->_strArchiveName), GetMessage("MAIN_ARCHIVE_ERR_OPEN"))); return false; } return true; }
/** * Return path without $_SERVER['DOCUMENT_ROOT'] * @param string $path * @return string */ protected static function removeDocumentRoot($path) { $path = removeDocRoot($path); return $path; }
/** * Checks if current user has access to the file or folder according to Bitrix permissions * @static * @param string $strFilename full path to the file * @param boolean $isFile true if we check file permissions, false if folder permissions should be checked * @return boolean */ public static function HasAccess($strFilename, $isFile) { $result = false; $path = removeDocRoot($strFilename); global $USER; if (!$isFile) { if ($USER->CanDoFileOperation("fm_view_listing", array(SITE_ID, $path))) { $result = true; } } else { if ($USER->CanDoFileOperation('fm_view_file', array(SITE_ID, $path)) && ($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', array(SITE_ID, $path)) || !(HasScriptExtension($path) || substr(GetFileName($path), 0, 1) == "."))) { $result = true; } } return $result; }