/** * Checks the archive's data integrity by performing a dry-run extraction (no data is written to disk, just making * sure the archive can be extracted). If you have enabled "Upload archive part immediately" this won't run and * produce a warning instead. * * @param Finalization $parent * * @return bool True when done or an error occurred */ public function test_extract($parent) { // If for any reason we're called outside the Finalization context let's give up without a fight if (!$parent instanceof Finalization) { return true; } // Load the configuration engine $config = Factory::getConfiguration(); // Only run if we're explicitly enabled $enabled = $config->get('akeeba.advanced.integritycheck', 0); if (!$enabled) { return true; } // Make sure the "Process each part immediately" option is not enabled if ($config->get('engine.postproc.common.after_part', 0, false)) { $parent->setWarning(JText::_('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_PROCESSIMMEDIATELY')); return true; } // Make sure an archiver engine producing backup archives of JPA, JPS or ZIP files is in use $archiver = Factory::getArchiverEngine(); $extension = $archiver->getExtension(); $extension = strtoupper($extension); $extension = ltrim($extension, '.'); if (!in_array($extension, array('JPA', 'JPS', 'ZIP'))) { $parent->setWarning(JText::_('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_INVALIDARCHIVERTYPE')); return true; } // Set the KICKSTART constant to prevent Akeeba Restore from taking over the page output if (!defined('KICKSTART')) { define('KICKSTART', 1); } // Try to load Akeeba Restore try { $this->loadAkeebaRestore(); } catch (\RuntimeException $e) { $parent->setError($e->getMessage()); return true; } // Set up the Akeeba Restore engine, either from a serialised factory or from scratch $factory = $config->get('volatile.finalization.testextract.factory', null, false); if (!is_null($factory) && is_string($factory)) { \AKFactory::unserialize($factory); } else { $this->setUpAkeebaRestore(); } $parent->relayStep('Archive integrity check'); $parent->relaySubstep('Testing if archive can be extracted'); \AKFactory::set('kickstart.enabled', true); /** @var \AKAbstractUnarchiver $engine */ $engine = \AKFactory::getUnarchiver(); $observer = new FakeRestorationObserver(); $engine->attach($observer); $engine->tick(); $ret = $engine->getStatusArray(); // Did an error occur? if ($ret['Error'] != '') { $parent->setError(JText::sprintf('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_INTEGRITYCHECKFAILED', $ret['Error'])); return true; } // Did we finish successfully? if (!$ret['HasRun']) { Factory::getLog()->log(LogLevel::INFO, __CLASS__ . ": The archive's integrity has been validated"); $config->set('volatile.finalization.testextract.factory', null, false); return true; } // Step finished and we need one more step to proceed. $factory = \AKFactory::serialize(); $config->set('volatile.finalization.testextract.factory', $factory, false); return false; }
/** * The Master Setup will read the configuration parameters from restoration.php, abiautomation.ini, or * the JSON-encoded "configuration" input variable and return the status. * @return bool True if the master configuration was applied to the Factory object */ function masterSetup() { // ------------------------------------------------------------ // 1. Import basic setup parameters // ------------------------------------------------------------ $ini_data = null; // In restore.php mode, require restoration.php or fail if (!defined('KICKSTART')) { // This is the standalone mode, used by Akeeba Backup Professional. It looks for a restoration.php // file to perform its magic. If the file is not there, we will abort. $setupFile = 'restoration.php'; if (!file_exists($setupFile)) { // Uh oh... Somebody tried to pooh on our back yard. Lock the gates! Don't let the traitor inside! AKFactory::set('kickstart.enabled', false); return false; } // Load restoration.php. It creates a global variable named $restoration_setup require_once $setupFile; $ini_data = $restoration_setup; if (empty($ini_data)) { // No parameters fetched. Darn, how am I supposed to work like that?! AKFactory::set('kickstart.enabled', false); return false; } AKFactory::set('kickstart.enabled', true); } else { // Maybe we have $restoration_setup defined in the head of kickstart.php global $restoration_setup; if (!empty($restoration_setup) && !is_array($restoration_setup)) { $ini_data = AKText::parse_ini_file($restoration_setup, false, true); } elseif (is_array($restoration_setup)) { $ini_data = $restoration_setup; } } // Import any data from $restoration_setup if (!empty($ini_data)) { foreach ($ini_data as $key => $value) { AKFactory::set($key, $value); } AKFactory::set('kickstart.enabled', true); } // Reinitialize $ini_data $ini_data = null; // ------------------------------------------------------------ // 2. Explode JSON parameters into $_REQUEST scope // ------------------------------------------------------------ // Detect a JSON string in the request variable and store it. $json = getQueryParam('json', null); // Remove everything from the request array if (!empty($_REQUEST)) { foreach ($_REQUEST as $key => $value) { unset($_REQUEST[$key]); } } // Decrypt a possibly encrypted JSON string if (!empty($json)) { $password = AKFactory::get('kickstart.security.password', null); if (!empty($password)) { $json = AKEncryptionAES::AESDecryptCtr($json, $password, 128); } // Get the raw data $raw = json_decode($json, true); // Pass all JSON data to the request array if (!empty($raw)) { foreach ($raw as $key => $value) { $_REQUEST[$key] = $value; } } } // ------------------------------------------------------------ // 3. Try the "factory" variable // ------------------------------------------------------------ // A "factory" variable will override all other settings. $serialized = getQueryParam('factory', null); if (!is_null($serialized)) { // Get the serialized factory AKFactory::unserialize($serialized); AKFactory::set('kickstart.enabled', true); return true; } // ------------------------------------------------------------ // 4. Try abiautomation.ini and the configuration variable for Kickstart // ------------------------------------------------------------ if (defined('KICKSTART')) { // We are in Kickstart mode. abiautomation.ini has precedence. $setupFile = 'abiautomation.ini'; if (file_exists($setupFile)) { // abiautomation.ini was found $ini_data = AKText::parse_ini_file('restoration.ini', false); } else { // abiautomation.ini was not found. Let's try input parameters. $configuration = getQueryParam('configuration'); if (!is_null($configuration)) { // Let's decode the configuration from JSON to array $ini_data = json_decode($configuration, true); } else { // Neither exists. Enable Kickstart's interface anyway. $ini_data = array('kickstart.enabled' => true); } } // Import any INI data we might have from other sources if (!empty($ini_data)) { foreach ($ini_data as $key => $value) { AKFactory::set($key, $value); } AKFactory::set('kickstart.enabled', true); return true; } } }
/** * The Master Setup will read the configuration parameters from restoration.php or * the JSON-encoded "configuration" input variable and return the status. * * @return bool True if the master configuration was applied to the Factory object */ function masterSetup() { // ------------------------------------------------------------ // 1. Import basic setup parameters // ------------------------------------------------------------ $ini_data = NULL; // In restore.php mode, require restoration.php or fail if (!defined('KICKSTART')) { // This is the standalone mode, used by Akeeba Backup Professional. It looks for a restoration.php // file to perform its magic. If the file is not there, we will abort. $setupFile = 'tmp/restoration.php'; if (!file_exists($setupFile)) { AKFactory::set('kickstart.enabled', FALSE); return FALSE; } // Load restoration.php. It creates a global variable named $restoration_setup require_once $setupFile; $ini_data = $restoration_setup; if (empty($ini_data)) { // No parameters fetched. Darn, how am I supposed to work like that?! AKFactory::set('kickstart.enabled', FALSE); return FALSE; } AKFactory::set('kickstart.enabled', TRUE); } else { // Maybe we have $restoration_setup defined in the head of kickstart.php global $restoration_setup; if (!empty($restoration_setup) && !is_array($restoration_setup)) { $ini_data = AKText::parse_ini_file($restoration_setup, FALSE, TRUE); } elseif (is_array($restoration_setup)) { $ini_data = $restoration_setup; } } // Import any data from $restoration_setup if (!empty($ini_data)) { foreach ($ini_data as $key => $value) { AKFactory::set($key, $value); } AKFactory::set('kickstart.enabled', TRUE); } // Reinitialize $ini_data $ini_data = NULL; // ------------------------------------------------------------ // 2. Explode JSON parameters into $_REQUEST scope // ------------------------------------------------------------ // Detect a JSON string in the request variable and store it. $json = getQueryParam('json', NULL); // Remove everything from the request, post and get arrays if (!empty($_REQUEST)) { foreach ($_REQUEST as $key => $value) { unset($_REQUEST[$key]); } } if (!empty($_POST)) { foreach ($_POST as $key => $value) { unset($_POST[$key]); } } if (!empty($_GET)) { foreach ($_GET as $key => $value) { unset($_GET[$key]); } } // Decrypt a possibly encrypted JSON string $password = AKFactory::get('kickstart.security.password', NULL); if (!empty($json)) { if (!empty($password)) { $json = AKEncryptionAES::AESDecryptCtr($json, $password, 128); if (empty($json)) { die('###{"status":false,"message":"Invalid login"}###'); } } // Get the raw data $raw = json_decode($json, TRUE); if (!empty($password) && empty($raw)) { die('###{"status":false,"message":"Invalid login"}###'); } // Pass all JSON data to the request array if (!empty($raw)) { foreach ($raw as $key => $value) { $_REQUEST[$key] = $value; } } } elseif (!empty($password)) { die('###{"status":false,"message":"Invalid login"}###'); } // ------------------------------------------------------------ // 3. Try the "factory" variable // ------------------------------------------------------------ // A "factory" variable will override all other settings. $serialized = getQueryParam('factory', NULL); if (!is_null($serialized)) { // Get the serialized factory AKFactory::unserialize($serialized); AKFactory::set('kickstart.enabled', TRUE); return TRUE; } // ------------------------------------------------------------ // 4. Try the configuration variable for Kickstart // ------------------------------------------------------------ if (defined('KICKSTART')) { $configuration = getQueryParam('configuration'); if (!is_null($configuration)) { // Let's decode the configuration from JSON to array $ini_data = json_decode($configuration, TRUE); } else { // Neither exists. Enable Kickstart's interface anyway. $ini_data = array('kickstart.enabled' => TRUE); } // Import any INI data we might have from other sources if (!empty($ini_data)) { foreach ($ini_data as $key => $value) { AKFactory::set($key, $value); } AKFactory::set('kickstart.enabled', TRUE); return TRUE; } } }