Exemplo n.º 1
0
 /**
  * Starts or step a backup process
  *
  * @return array An Akeeba Engine return array
  */
 public function runBackup()
 {
     $ret_array = array();
     $ajaxTask = $this->getState('ajax');
     $tag = $this->getState('tag');
     $backupId = $this->getState('backupid');
     switch ($ajaxTask) {
         // Start a new backup
         case 'start':
             // Description is passed through a strict filter which removes HTML
             $description = $this->getState('description');
             // The comment is passed through the Safe HTML filter (note: use 2 to force no filtering)
             $comment = $this->getState('comment');
             $jpskey = $this->getState('jpskey');
             $angiekey = $this->getState('angiekey');
             if (is_null($backupId)) {
                 $db = $this->getDbo();
                 $query = $db->getQuery(true)->select('MAX(' . $db->qn('id') . ')')->from($db->qn('#__ak_stats'));
                 try {
                     $maxId = $db->setQuery($query)->loadResult();
                 } catch (Exception $e) {
                     $maxId = 0;
                 }
                 $backupId = 'id' . ($maxId + 1);
             }
             // Try resetting the engine
             Factory::resetState(array('maxrun' => 0));
             // Remove any stale memory files left over from the previous step
             if (empty($tag)) {
                 $tag = Platform::getInstance()->get_backup_origin();
             }
             $tempVarsTag = $tag;
             $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
             Factory::getFactoryStorage()->reset($tempVarsTag);
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             $options = array('description' => $description, 'comment' => $comment, 'jpskey' => $jpskey, 'angiekey' => $angiekey);
             $kettenrad->setup($options);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             try {
                 Factory::saveState($tag, $backupId);
             } catch (\RuntimeException $e) {
                 $ret_array['Error'] = $e->getMessage();
             }
             break;
             // Step through a backup
         // Step through a backup
         case 'step':
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             try {
                 Factory::saveState($tag, $backupId);
             } catch (\RuntimeException $e) {
                 $ret_array['Error'] = $e->getMessage();
             }
             if ($ret_array['HasRun'] == 1) {
                 // Clean up
                 Factory::nuke();
                 $tempVarsTag = $tag;
                 $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
                 Factory::getFactoryStorage()->reset($tempVarsTag);
             }
             break;
             // Send a push notification for backup failure
         // Send a push notification for backup failure
         case 'pushFail':
             Factory::loadState($tag, $backupId);
             $errorMessage = $this->getState('errorMessage');
             $platform = Platform::getInstance();
             $pushSubject = sprintf($platform->translate('COM_AKEEBA_PUSH_ENDBACKUP_FAIL_SUBJECT'), $platform->get_site_name(), $platform->get_host());
             $key = empty($errorMessage) ? 'COM_AKEEBA_PUSH_ENDBACKUP_FAIL_BODY' : 'COM_AKEEBA_PUSH_ENDBACKUP_FAIL_BODY_WITH_MESSAGE';
             $pushDetails = sprintf($platform->translate($key), $platform->get_site_name(), $platform->get_host(), $errorMessage);
             Factory::getPush()->message($pushSubject, $pushDetails);
             break;
         default:
             break;
     }
     return $ret_array;
 }
Exemplo n.º 2
0
 private function _apiStepBackup($config)
 {
     $defConfig = array('profile' => null, 'tag' => AKEEBA_BACKUP_ORIGIN, 'backupid' => null);
     $config = array_merge($defConfig, $config);
     $profile = $config['profile'];
     $tag = $config['tag'];
     $backupid = $config['backupid'];
     // Try to set the profile from the setup parameters
     if (!empty($profile)) {
         $registry = Factory::getConfiguration();
         $session = JFactory::getSession();
         $session->set('profile', $profile, 'akeeba');
     }
     Factory::loadState($tag, $backupid);
     $kettenrad = Factory::getKettenrad();
     $kettenrad->setBackupId($backupid);
     $registry = Factory::getConfiguration();
     $session = JFactory::getSession();
     $session->set('profile', $registry->activeProfile, 'akeeba');
     $array = $kettenrad->tick();
     $ret_array = $kettenrad->getStatusArray();
     $array['Progress'] = $ret_array['Progress'];
     try {
         Factory::saveState(AKEEBA_BACKUP_ORIGIN, $backupid);
     } catch (\RuntimeException $e) {
         $array['Error'] = $e->getMessage();
     }
     if ($array['Error'] != '') {
         // A backup error had occurred. Why are we here?!
         $this->status = self::STATUS_ERROR;
         $this->encapsulation = self::ENCAPSULATION_RAW;
         return 'A backup error had occurred: ' . $array['Error'];
     } elseif ($array['HasRun'] == false) {
         Factory::nuke();
         Factory::getFactoryStorage()->reset();
     } else {
         $statistics = Factory::getStatistics();
         $array['BackupID'] = $statistics->getId();
     }
     return $array;
 }
Exemplo n.º 3
0
 public function step()
 {
     // Check permissions
     $this->_checkPermissions();
     // Set the profile
     $this->_setProfile();
     // Get the backup ID
     $backupId = $this->input->get('backupid', null, 'raw', 2);
     if (empty($backupId)) {
         $backupId = null;
     }
     Factory::loadState(AKEEBA_BACKUP_ORIGIN, $backupId);
     $kettenrad = Factory::getKettenrad();
     $kettenrad->setBackupId($backupId);
     $kettenrad->tick();
     $array = $kettenrad->getStatusArray();
     $kettenrad->resetWarnings();
     // So as not to have duplicate warnings reports
     try {
         Factory::saveState(AKEEBA_BACKUP_ORIGIN, $backupId);
     } catch (\RuntimeException $e) {
         $array['Error'] = $e->getMessage();
     }
     if ($array['Error'] != '') {
         @ob_end_clean();
         echo '500 ERROR -- ' . $array['Error'];
         flush();
         JFactory::getApplication()->close();
     } elseif ($array['HasRun'] == 1) {
         // All done
         Factory::nuke();
         Factory::getFactoryStorage()->reset();
         @ob_end_clean();
         header('Content-type: text/plain');
         header('Connection: close');
         echo '200 OK';
         flush();
         JFactory::getApplication()->close();
     } else {
         $noredirect = $this->input->get('noredirect', 0, 'int');
         if ($noredirect != 0) {
             @ob_end_clean();
             header('Content-type: text/plain');
             header('Connection: close');
             echo "301 More work required";
             flush();
             JFactory::getApplication()->close();
         } else {
             $curUri = JUri::getInstance();
             $ssl = $curUri->isSSL() ? 1 : 0;
             $tempURL = JRoute::_('index.php?option=com_akeeba', false, $ssl);
             $uri = new JUri($tempURL);
             $uri->setVar('view', 'backup');
             $uri->setVar('task', 'step');
             $uri->setVar('key', $this->input->get('key', '', 'none', 2));
             $uri->setVar('profile', $this->input->get('profile', 1, 'int'));
             if (!empty($backupId)) {
                 $uri->setVar('backupid', $backupId);
             }
             // Maybe we have a multilingual site?
             $lg = F0FPlatform::getInstance()->getLanguage();
             $languageTag = $lg->getTag();
             $uri->setVar('lang', $languageTag);
             $redirectionUrl = $uri->toString();
             $this->_customRedirect($redirectionUrl);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Starts or step a backup process
  *
  * @return array An Akeeba Engine return array
  */
 public function runBackup()
 {
     $ret_array = array();
     $ajaxTask = $this->getState('ajax');
     $tag = $this->getState('tag');
     $backupId = $this->getState('backupid');
     switch ($ajaxTask) {
         case 'start':
             // Description is passed through a strict filter which removes HTML
             $description = $this->getState('description');
             // The comment is passed through the Safe HTML filter (note: use 2 to force no filtering)
             $comment = $this->getState('comment');
             $jpskey = $this->getState('jpskey');
             $angiekey = $this->getState('angiekey');
             if (is_null($backupId)) {
                 $db = $this->getDbo();
                 $query = $db->getQuery(true)->select('MAX(' . $db->qn('id') . ')')->from($db->qn('#__ak_stats'));
                 try {
                     $maxId = $db->setQuery($query)->loadResult();
                 } catch (Exception $e) {
                     $maxId = 0;
                 }
                 $backupId = 'id' . ($maxId + 1);
             }
             // Try resetting the engine
             Factory::resetState(array('maxrun' => 0));
             // Remove any stale memory files left over from the previous step
             if (empty($tag)) {
                 $tag = Platform::getInstance()->get_backup_origin();
             }
             $tempVarsTag = $tag;
             $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
             Factory::getFactoryStorage()->reset($tempVarsTag);
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             // Take care of System Restore Point setup
             if ($tag == 'restorepoint') {
                 // Fetch the extension's version information
                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/assets/xmlslurp/xmlslurp.php';
                 $slurp = new LiveUpdateXMLSlurp();
                 $exttype = $this->getState('type');
                 switch ($exttype) {
                     case 'component':
                         $extname = 'com_';
                         break;
                     case 'file':
                         $extname = 'file';
                         break;
                     case 'library':
                         $extname = 'lib_';
                         break;
                     case 'module':
                         $extname = 'mod_';
                         break;
                     case 'package':
                         $extname = 'pkg_';
                         break;
                     case 'plugin':
                         $extname = 'plg_';
                         break;
                     case 'template':
                         $extname = 'tpl_';
                         break;
                     default:
                         $extname = '';
                         break;
                 }
                 $extname .= $this->getState('name');
                 $info = $slurp->getInfo($extname, '');
                 // Get the configOverrides for this extension
                 $configOverrides = $this->getConfigOverridesForSRP($extname, $info);
                 // Create an SRP descriptor
                 $srpdescriptor = array('type' => $this->getState('type'), 'name' => $this->getState('name'), 'group' => $this->getState('group'), 'version' => $info['version'], 'date' => $info['date']);
                 // Set the description and comment
                 $description = "System Restore Point - " . JText::_($exttype) . ": {$extname}";
                 $comment = "---BEGIN SRP---\n" . json_encode($srpdescriptor) . "\n---END SRP---";
                 $jpskey = '';
                 $angiekey = '';
                 // Set a custom finalization action queue
                 $configOverrides['volatile.core.finalization.action_handlers'] = array(new Akeeba\Engine\Finalization\Srpquotas());
                 $configOverrides['volatile.core.finalization.action_queue'] = array('remove_temp_files', 'update_statistics', 'update_filesizes', 'apply_srp_quotas');
                 // Apply the configuration overrides, please
                 $platform = Platform::getInstance();
                 $platform->configOverrides = $configOverrides;
             }
             $options = array('description' => $description, 'comment' => $comment, 'jpskey' => $jpskey, 'angiekey' => $angiekey);
             $kettenrad->setup($options);
             $kettenrad->tick();
             if ($kettenrad->getState() != 'running' && $tag == 'restorepoint') {
                 Factory::saveState($tag, $backupId);
                 Factory::loadState($tag, $backupId);
                 $kettenrad = Factory::getKettenrad();
                 $kettenrad->setBackupId($backupId);
                 $kettenrad->tick();
             }
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             Factory::saveState($tag, $backupId);
             break;
         case 'step':
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             Factory::saveState($tag, $backupId);
             if ($ret_array['HasRun'] == 1) {
                 // Clean up
                 Factory::nuke();
                 $tempVarsTag = $tag;
                 $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
                 Factory::getFactoryStorage()->reset($tempVarsTag);
             }
             break;
         default:
             break;
     }
     return $ret_array;
 }
Exemplo n.º 5
0
 /**
  * Starts or step a backup process
  *
  * @return array An Akeeba Engine return array
  */
 public function runBackup()
 {
     $ret_array = array();
     $ajaxTask = $this->getState('ajax');
     $tag = $this->getState('tag');
     $backupId = $this->getState('backupid');
     switch ($ajaxTask) {
         case 'start':
             // Description is passed through a strict filter which removes HTML
             $description = $this->getState('description');
             // The comment is passed through the Safe HTML filter (note: use 2 to force no filtering)
             $comment = $this->getState('comment');
             $jpskey = $this->getState('jpskey');
             $angiekey = $this->getState('angiekey');
             if (is_null($backupId)) {
                 $db = $this->getDbo();
                 $query = $db->getQuery(true)->select('MAX(' . $db->qn('id') . ')')->from($db->qn('#__ak_stats'));
                 try {
                     $maxId = $db->setQuery($query)->loadResult();
                 } catch (Exception $e) {
                     $maxId = 0;
                 }
                 $backupId = 'id' . ($maxId + 1);
             }
             // Try resetting the engine
             Factory::resetState(array('maxrun' => 0));
             // Remove any stale memory files left over from the previous step
             if (empty($tag)) {
                 $tag = Platform::getInstance()->get_backup_origin();
             }
             $tempVarsTag = $tag;
             $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
             Factory::getFactoryStorage()->reset($tempVarsTag);
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             $options = array('description' => $description, 'comment' => $comment, 'jpskey' => $jpskey, 'angiekey' => $angiekey);
             $kettenrad->setup($options);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             Factory::saveState($tag, $backupId);
             break;
         case 'step':
             Factory::loadState($tag, $backupId);
             $kettenrad = Factory::getKettenrad();
             $kettenrad->setBackupId($backupId);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             Factory::saveState($tag, $backupId);
             if ($ret_array['HasRun'] == 1) {
                 // Clean up
                 Factory::nuke();
                 $tempVarsTag = $tag;
                 $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
                 Factory::getFactoryStorage()->reset($tempVarsTag);
             }
             break;
         default:
             break;
     }
     return $ret_array;
 }
Exemplo n.º 6
0
 /**
  * Steps the file scan
  *
  * @return array
  */
 public function stepScan()
 {
     if (!$this->scanEngineSetup()) {
         return array('status' => false, 'error' => 'Could not load the file scanning engine; please try reinstalling the component', 'done' => true);
     }
     \Akeeba\Engine\Factory::loadState(AKEEBA_BACKUP_ORIGIN);
     $kettenrad = \Akeeba\Engine\Factory::getKettenrad();
     $kettenrad->tick();
     \Akeeba\Engine\Factory::saveState(AKEEBA_BACKUP_ORIGIN);
     return $this->parseScanArray($kettenrad->getStatusArray());
 }
Exemplo n.º 7
0
 /**
  * Steps through a backup.
  *
  * State variables expected (MUST be set):
  * backupid		The ID of the backup.
  * tag			The backup tag, e.g. "frontend".
  * profile      (optional) The profile ID of the backup.
  *
  * @param   bool  $requireBackupId  Should the backup ID be required?
  *
  * @return  array  An Akeeba Engine return array
  */
 public function stepBackup($requireBackupId = true)
 {
     // Get the tag. If not specified use the AKEEBA_BACKUP_ORIGIN constant.
     $tag = $this->getState('tag', null, 'string');
     if (is_null($tag) && defined('AKEEBA_BACKUP_ORIGIN')) {
         $tag = AKEEBA_BACKUP_ORIGIN;
     }
     // Get the Backup ID. If not specified use the AKEEBA_BACKUP_ID constant.
     $backupId = $this->getState('backupid', null, 'string');
     if (is_null($backupId) && defined('AKEEBA_BACKUP_ID')) {
         $backupId = AKEEBA_BACKUP_ID;
     }
     // Get the profile from the session, the AKEEBA_PROFILE constant or the model state – in this order
     $session = $this->container->session;
     $profile = $session->get('profile', null);
     $profile = defined('AKEEBA_PROFILE') ? AKEEBA_PROFILE : $profile;
     $profile = $this->getState('profile', $profile, 'int');
     $profile = max(0, (int) $profile);
     if (empty($profile)) {
         $profile = $this->getLastBackupProfile($tag, $backupId);
     }
     // Set the active profile
     $session->set('profile', $profile);
     if (!defined('AKEEBA_PROFILE')) {
         define('AKEEBA_PROFILE', $profile);
     }
     // Run a backup step
     $ret_array = array('Error' => '');
     try {
         // Reload the configuration
         Platform::getInstance()->load_configuration($profile);
         // Load the engine from storage
         Factory::loadState($tag, $backupId, $requireBackupId);
         // Set the backup ID and run a backup step
         $kettenrad = Factory::getKettenrad();
         $kettenrad->setBackupId($backupId);
         $kettenrad->tick();
         $ret_array = $kettenrad->getStatusArray();
         // Prevent duplicate reporting of warnings
         $kettenrad->resetWarnings();
     } catch (\Exception $e) {
         $ret_array['Error'] = $e->getMessage();
     }
     try {
         if (empty($ret_array['Error']) && $ret_array['HasRun'] != 1) {
             Factory::saveState($tag, $backupId);
         }
     } catch (\RuntimeException $e) {
         $ret_array['Error'] = $e->getMessage();
     }
     if (!empty($ret_array['Error']) || $ret_array['HasRun'] == 1) {
         // Clean up
         Factory::nuke();
         $tempVarsTag = $tag;
         $tempVarsTag .= empty($backupId) ? '' : '.' . $backupId;
         Factory::getFactoryStorage()->reset($tempVarsTag);
     }
     return $ret_array;
 }