private function processTypeFileCompressedSimple() { $timer = AKFactory::getTimer(); // Files are being processed in small chunks, to avoid timeouts if ($this->dataReadLength == 0 && !AKFactory::get('kickstart.setup.dryrun', '0')) { // Before processing file data, ensure permissions are adequate $this->setCorrectPermissions($this->fileHeader->file); } // Open the output file if (!AKFactory::get('kickstart.setup.dryrun', '0')) { // Open the output file $outfp = @fopen($this->fileHeader->realFile, 'wb'); // Can we write to the file? $ignore = AKFactory::get('kickstart.setup.ignoreerrors', false); if ($outfp === false && !$ignore) { // An error occured $this->setError(AKText::sprintf('COULDNT_WRITE_FILE', $this->fileHeader->realFile)); return false; } } // Does the file have any data, at all? if ($this->fileHeader->uncompressed == 0) { // No file data! if (!AKFactory::get('kickstart.setup.dryrun', '0')) { if (is_resource($outfp)) { @fclose($outfp); } } $this->runState = AK_STATE_DATAREAD; return true; } $leftBytes = $this->fileHeader->uncompressed - $this->dataReadLength; // Loop while there's data to write and enough time to do it while ($leftBytes > 0 && $timer->getTimeLeft() > 0) { // Read the mini header $binMiniHeader = fread($this->fp, 8); $reallyReadBytes = akstringlen($binMiniHeader); if ($reallyReadBytes < 8) { // We read less than requested! Why? Did we hit local EOF? if ($this->isEOF(true) && !$this->isEOF(false)) { // Yeap. Let's go to the next file $this->nextFile(); // Retry reading the header $binMiniHeader = fread($this->fp, 8); $reallyReadBytes = akstringlen($binMiniHeader); // Still not enough data? If so, the archive is corrupt or missing parts. if ($reallyReadBytes < 8) { $this->setError(AKText::_('ERR_CORRUPT_ARCHIVE')); return false; } } else { // Nope. The archive is corrupt $this->setError(AKText::_('ERR_CORRUPT_ARCHIVE')); return false; } } // Read the encrypted data $miniHeader = unpack('Vencsize/Vdecsize', $binMiniHeader); $toReadBytes = $miniHeader['encsize']; $data = $this->fread($this->fp, $toReadBytes); $reallyReadBytes = akstringlen($data); if ($reallyReadBytes < $toReadBytes) { // We read less than requested! Why? Did we hit local EOF? if ($this->isEOF(true) && !$this->isEOF(false)) { // Yeap. Let's go to the next file $this->nextFile(); // Read the rest of the data $toReadBytes -= $reallyReadBytes; $restData = $this->fread($this->fp, $toReadBytes); $reallyReadBytes = akstringlen($restData); if ($reallyReadBytes < $toReadBytes) { $this->setError(AKText::_('ERR_CORRUPT_ARCHIVE')); return false; } if (akstringlen($data) == 0) { $data = $restData; } else { $data .= $restData; } } else { // Nope. The archive is corrupt $this->setError(AKText::_('ERR_CORRUPT_ARCHIVE')); return false; } } // Decrypt the data $data = AKEncryptionAES::AESDecryptCBC($data, $this->password, 128); // Is the length of the decrypted data less than expected? $data_length = akstringlen($data); if ($data_length < $miniHeader['decsize']) { $this->setError(AKText::_('ERR_INVALID_JPS_PASSWORD')); return false; } // Trim the data $data = substr($data, 0, $miniHeader['decsize']); // Decompress $data = gzinflate($data); $unc_len = akstringlen($data); // Write the decrypted data if (!AKFactory::get('kickstart.setup.dryrun', '0')) { if (is_resource($outfp)) { @fwrite($outfp, $data, akstringlen($data)); } } // Update the read length $this->dataReadLength += $unc_len; $leftBytes = $this->fileHeader->uncompressed - $this->dataReadLength; } // Close the file pointer if (!AKFactory::get('kickstart.setup.dryrun', '0')) { if (is_resource($outfp)) { @fclose($outfp); } } // Was this a pre-timeout bail out? if ($leftBytes > 0) { $this->runState = AK_STATE_DATA; } else { // Oh! We just finished! $this->runState = AK_STATE_DATAREAD; $this->dataReadLength = 0; } }
function doAjax() { $ajax = $this->getState('ajax'); switch ($ajax) { // FTP Connection test for DirectFTP case 'testftp': // Grab request parameters $config = array('host' => $this->input->get('host', '', 'none', 2), 'port' => $this->input->get('port', 21, 'int'), 'user' => $this->input->get('user', '', 'none', 2), 'pass' => $this->input->get('pass', '', 'none', 2), 'initdir' => $this->input->get('initdir', '', 'none', 2), 'usessl' => $this->input->get('usessl', 'cmd') == 'true', 'passive' => $this->input->get('passive', 'cmd') == 'true'); // Perform the FTP connection test $test = new AEArchiverDirectftp(); $test->initialize('', $config); $errors = $test->getError(); if (empty($errors)) { $result = true; } else { $result = $errors; } break; case 'restoreFilesPing': case 'restoreFilesStart': case 'restoreFilesStep': case 'restoreFilesFinalize': global $restoration_setup; $restoration_setup = $this->getRestorationParameters(); define('KICKSTART', 1); include_once JPATH_COMPONENT_ADMINISTRATOR . '/restore.php'; akeebaTinyHackForRestorationObserver(); masterSetup(); $retArray = array('status' => true, 'message' => null); switch ($ajax) { case 'restoreFilesPing': // ping task - realy does nothing! $timer = AKFactory::getTimer(); $timer->enforce_min_exec_time(); break; case 'restoreFilesStart': AKFactory::nuke(); // Reset the factory // Reset the factory case 'restoreFilesStep': $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $tmp_path = $config->get('tmp_path', ''); } else { $tmp_path = $config->getValue('tmp_path', ''); } $override = array('rename_dirs' => array('sql' => rtrim($tmp_path, '/\\') . '/sql')); $engine = AKFactory::getUnarchiver($override); // Get the engine $observer = new RestorationObserver(); // Create a new observer $engine->attach($observer); // Attach the observer $engine->tick(); $ret = $engine->getStatusArray(); if ($ret['Error'] != '') { $retArray['status'] = false; $retArray['done'] = true; $retArray['message'] = $ret['Error']; } elseif (!$ret['HasRun']) { $retArray['files'] = $observer->filesProcessed; $retArray['bytesIn'] = $observer->compressedTotal; $retArray['bytesOut'] = $observer->uncompressedTotal; $retArray['status'] = true; $retArray['done'] = true; } else { $retArray['files'] = $observer->filesProcessed; $retArray['bytesIn'] = $observer->compressedTotal; $retArray['bytesOut'] = $observer->uncompressedTotal; $retArray['status'] = true; $retArray['done'] = false; $retArray['factory'] = AKFactory::serialize(); } break; case 'restoreFilesFinalize': $root = AKFactory::get('kickstart.setup.destdir'); // Remove the sql dump directory $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $tmp_path = $config->get('tmp_path', ''); } else { $tmp_path = $config->getValue('tmp_path', ''); } $sqldir = rtrim($tmp_path, '/\\') . '/sql'; recursive_remove_directory($sqldir); break; } return $retArray; break; case 'dbRestoreStart': $this->dbRestorationInit(); case 'dbRestore': $result = $this->dbRestore(); break; // Unrecognized AJAX task // Unrecognized AJAX task default: $result = false; break; } return $result; }