Beispiel #1
0
 public function step()
 {
     // Check permissions
     $this->_checkPermissions();
     // Set the profile
     $this->_setProfile();
     $kettenrad =& AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN);
     $array = $kettenrad->tick();
     AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN);
     if ($array['Error'] != '') {
         @ob_end_clean();
         echo '500 ERROR -- ' . $array['Error'];
         flush();
         JFactory::getApplication()->close();
     } elseif ($array['HasRun'] == false) {
         // All done
         AEFactory::nuke();
         AEUtilTempvars::reset();
         @ob_end_clean();
         echo '200 OK';
         flush();
         JFactory::getApplication()->close();
     } else {
         $noredirect = JRequest::getInt('noredirect', 0);
         if ($noredirect != 0) {
             @ob_end_clean();
             echo "301 More work required";
             flush();
             JFactory::getApplication()->close();
         } else {
             $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=backup&task=step&key=' . JRequest::getVar('key') . '&profile=' . JRequest::getInt('profile', 1));
         }
     }
 }
Beispiel #2
0
 /**
  * Step through the backup, informing user of the progress
  */
 public function step()
 {
     // Enforce raw mode - I need to be in full control!
     $document =& JFactory::getDocument();
     $document->setType('raw');
     $key = JRequest::getVar('key');
     if (!$this->_checkPermissions()) {
         parent::redirect();
         return;
     }
     JRequest::setVar('tpl', 'step');
     $kettenrad =& AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN);
     $array = $kettenrad->getStatusArray();
     if ($array['Error'] != '') {
         // An error occured
         $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=light&format=raw&key=' . urlencode($key) . '&task=error&error=' . urlencode($array['Error']));
         parent::redirect();
     } elseif ($array['HasRun'] == 1) {
         // All done
         $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=light&format=raw&key=' . urlencode($key) . '&task=done');
         parent::redirect();
     } else {
         $kettenrad->tick();
         AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN);
         parent::display();
     }
 }
Beispiel #3
0
 public function step()
 {
     // Check permissions
     $this->_checkPermissions();
     // Set the profile
     $this->_setProfile();
     $kettenrad = AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN);
     $kettenrad->tick();
     $array = $kettenrad->getStatusArray();
     $kettenrad->resetWarnings();
     // So as not to have duplicate warnings reports
     AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN);
     if ($array['Error'] != '') {
         @ob_end_clean();
         echo '500 ERROR -- ' . $array['Error'];
         flush();
         JFactory::getApplication()->close();
     } elseif ($array['HasRun'] == 1) {
         // All done
         AEFactory::nuke();
         AEUtilTempvars::reset();
         @ob_end_clean();
         echo '200 OK';
         flush();
         JFactory::getApplication()->close();
     } else {
         $noredirect = $this->input->get('noredirect', 0, 'int');
         if ($noredirect != 0) {
             @ob_end_clean();
             echo "301 More work required";
             flush();
             JFactory::getApplication()->close();
         } else {
             $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=backup&task=step&key=' . $this->input->get('key', '', 'none', 2) . '&profile=' . $this->input->get('profile', 1, 'int'));
         }
     }
 }
Beispiel #4
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;
     }
     $kettenrad = AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN, $backupId);
     $kettenrad->setBackupId($backupId);
     $kettenrad->tick();
     $array = $kettenrad->getStatusArray();
     $kettenrad->resetWarnings();
     // So as not to have duplicate warnings reports
     AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN, $backupId);
     if ($array['Error'] != '') {
         @ob_end_clean();
         echo '500 ERROR -- ' . $array['Error'];
         flush();
         JFactory::getApplication()->close();
     } elseif ($array['HasRun'] == 1) {
         // All done
         AEFactory::nuke();
         AEUtilTempvars::reset();
         @ob_end_clean();
         echo '200 OK';
         flush();
         JFactory::getApplication()->close();
     } else {
         $noredirect = $this->input->get('noredirect', 0, 'int');
         if ($noredirect != 0) {
             @ob_end_clean();
             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);
         }
     }
 }
Beispiel #5
0
 /**
  * Resets the Kettenrad state, wipping out any pending backups and/or stale
  * temporary data.
  *
  * @param array $config Configuration parameters for the reset operation
  */
 public static function reset($config = array())
 {
     $default_config = array('global' => true, 'log' => false, 'maxrun' => 0);
     $config = (object) array_merge($default_config, $config);
     // Pause logging if so desired
     if (!$config->log) {
         AEUtilLogger::WriteLog(false, '');
     }
     $tag = null;
     if (!$config->global) {
         // If we're not resetting globally, get a list of running backups per tag
         $tag = AEPlatform::getInstance()->get_backup_origin();
     }
     // Cache the factory before proceeding
     $factory = AEFactory::serialize();
     $runningList = AEPlatform::getInstance()->get_running_backups($tag);
     // Origins we have to clean
     $origins = array(AEPlatform::getInstance()->get_backup_origin());
     // 1. Detect failed backups
     if (is_array($runningList) && !empty($runningList)) {
         // The current timestamp
         $now = time();
         // Mark running backups as failed
         foreach ($runningList as $running) {
             if (empty($tag)) {
                 // Check the timestamp of the log file to decide if it's stuck,
                 // but only if a tag is not set
                 $tstamp = @filemtime(AEUtilLogger::logName($running['origin']));
                 if ($tstamp !== false) {
                     // We can only check the timestamp if it's returned. If not, we assume the backup is stale
                     $difference = abs($now - $tstamp);
                     // Backups less than 3 minutes old are not considered stale
                     if ($difference < $config->maxrun) {
                         continue;
                     }
                 }
             }
             $filenames = AEUtilStatistics::get_all_filenames($running, false);
             // Process if there are files to delete...
             if (!is_null($filenames)) {
                 // Delete the failed backup's archive, if exists
                 foreach ($filenames as $failedArchive) {
                     AEPlatform::getInstance()->unlink($failedArchive);
                 }
             }
             // Mark the backup failed
             $running['status'] = 'fail';
             $running['multipart'] = 0;
             $dummy = null;
             AEPlatform::getInstance()->set_or_update_statistics($running['id'], $running, $dummy);
             $origins[] = $running['origin'];
         }
     }
     if (!empty($origins)) {
         $origins = array_unique($origins);
         foreach ($origins as $tag) {
             AECoreKettenrad::load($tag);
             // Remove temporary files
             AEUtilTempfiles::deleteTempFiles();
             // Delete any stale temporary data
             AEUtilTempvars::reset($tag);
         }
     }
     // Reload the factory
     AEFactory::unserialize($factory);
     unset($factory);
     // Unpause logging if it was previously paused
     if (!$config->log) {
         AEUtilLogger::WriteLog(true, '');
     }
 }
Beispiel #6
0
 /**
  * Step through the backup, informing user of the progress
  */
 public function step()
 {
     $key = $this->input->get('key', '', 'none', 2);
     if (!$this->_checkPermissions()) {
         parent::redirect();
         return true;
     }
     $model = $this->getThisModel();
     $model->setState('key', $key);
     $kettenrad = AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN);
     $array = $kettenrad->getStatusArray();
     if ($array['Error'] != '') {
         // An error occured
         $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=light&format=raw&key=' . urlencode($key) . '&task=error&error=' . urlencode($array['Error']));
         parent::redirect();
     } elseif ($array['HasRun'] == 1) {
         // All done
         $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=light&format=raw&key=' . urlencode($key) . '&task=done');
         parent::redirect();
     } else {
         $kettenrad->tick();
         AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN);
         parent::display();
     }
 }
 public function runBackup()
 {
     $ret_array = array();
     $ajaxTask = $this->getState('ajax');
     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');
             $tag = $this->getState('tag');
             // Try resetting the engine
             AECoreKettenrad::reset(array('maxrun' => 0));
             // Remove any stale memory files left over from the previous step
             if (empty($tag)) {
                 $tag = AEPlatform::getInstance()->get_backup_origin();
             }
             AEUtilTempvars::reset($tag);
             $kettenrad = AECoreKettenrad::load($tag);
             // Take care of System Restore Point setup
             if ($tag == 'restorepoint') {
                 // Fetch the extension's version information
                 require_once JPATH_COMPONENT_ADMINISTRATOR . '/liveupdate/classes/xmlslurp.php';
                 $slurp = new LiveUpdateXMLSlurp();
                 $exttype = $this->getState('type');
                 switch ($exttype) {
                     case 'component':
                         $extname = 'com_';
                         break;
                     case 'module':
                         $extname = 'mod_';
                         break;
                     case 'plugin':
                         $extname = 'plg_';
                         break;
                     case 'template':
                         $extname = 'tpl_';
                         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 = '';
                 // Set a custom finalization action queue
                 $configOverrides['volatile.core.finalization.action_handlers'] = array(new AEFinalizationSrpquotas());
                 $configOverrides['volatile.core.finalization.action_queue'] = array('remove_temp_files', 'update_statistics', 'update_filesizes', 'apply_srp_quotas');
                 // Apply the configuration overrides, please
                 $platform = AEPlatform::getInstance();
                 $platform->configOverrides = $configOverrides;
             }
             $options = array('description' => $description, 'comment' => $comment, 'jpskey' => $jpskey);
             $kettenrad->setup($options);
             $kettenrad->tick();
             if ($kettenrad->getState() != 'running' && $tag == 'restorepoint') {
                 $kettenrad->tick();
             }
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             AECoreKettenrad::save($tag);
             break;
         case 'step':
             $tag = $this->getState('tag');
             $kettenrad = AECoreKettenrad::load($tag);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             AECoreKettenrad::save($tag);
             if ($ret_array['HasRun'] == 1) {
                 // Clean up
                 AEFactory::nuke();
                 AEUtilTempvars::reset($tag);
             }
             break;
         default:
             break;
     }
     return $ret_array;
 }
Beispiel #8
0
 private function _apiStepBackup($config)
 {
     $defConfig = array('profile' => null, 'tag' => AKEEBA_BACKUP_ORIGIN);
     $config = array_merge($defConfig, $config);
     extract($config);
     // Try to set the profile from the setup parameters
     if (!empty($profile)) {
         $registry = AEFactory::getConfiguration();
         $session = JFactory::getSession();
         $session->set('profile', $profile, 'akeeba');
     }
     $kettenrad = AECoreKettenrad::load($tag);
     $registry = AEFactory::getConfiguration();
     $session = JFactory::getSession();
     $session->set('profile', $registry->activeProfile, 'akeeba');
     $array = $kettenrad->tick();
     $ret_array = $kettenrad->getStatusArray();
     $array['Progress'] = $ret_array['Progress'];
     AECoreKettenrad::save($tag);
     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) {
         AEFactory::nuke();
         AEUtilTempvars::reset();
     }
     return $array;
 }
	public function __construct(& $subject, $config = array())
	{
		// Use the parent constructor to create the plugin object
		parent::__construct($subject, $config);
		
		// Check if we have to disable ourself
		$akreset = JRequest::getCmd('akreset','');
		$defaultpw = $this->params->get('resetpw','');
		if( ($akreset == $defaultpw) && !empty($defaultpw) )
		{
			// Disable the plugin
			$db = JFactory::getDBO();

			if( version_compare( JVERSION, '1.6.0', 'ge' ) ) {
				$sql = 'UPDATE `#__extensions` SET `enabled` = 0 WHERE `type` = \'plugin\' AND `element` = \'aklazy\'';
			} else {
				$sql = 'UPDATE #__plugins SET `published` = 0 WHERE `element` = \'aklazy\'';
			}
			$db->setQuery($sql);
			$db->query();

			// Load the configuration
			$profile = (int)$this->params->get('profile',1);
			if($profile <= 0) $profile = 1;
			$session = JFactory::getSession();
			$session->set('profile', $profile, 'akeeba');
			AEPlatform::getInstance()->load_configuration($profile);

			// Remove the log files
			$logfile = AEUtilLogger::logName(null);
			@unlink($logfile);
			AEUtilLogger::ResetLog('lazy');
			
			// Clear lock
			$this->unsetLock();
			$this->unsetNonce();
			$this->saveStorage();

			// Reset pending backups
			AECoreKettenrad::reset(array(
				'maxrun'	=> 0
			));
			
			// Redirect
			$app = JFactory::getApplication();
			$app->redirect('index.php');

			return;
		}

		// Hijack the application to do the backup steps if aklazy and nonce
		// params are defined in the URL query
		$aklazy = JRequest::getCmd('aklazy',null);
		$nonce = JRequest::getCmd('nonce',null);
		
		// Can we create test files in the storage directory?
		$filename = $this->getStorageFilename().'.tmp';
		jimport('joomla.filesystem.file');
		// Fix 3.2.2: JFile::write in 1.6 uses pass-by-reference for the data part
		$dummyData = 'x';
		$touched = @file_put_contents($filename, $dummyData);
		if(!$touched) {
			$touched = JFile::write($filename,$dummyData);
		}
		if($touched) {
			if(!@unlink($filename)) {
				JFile::delete($filename);
			}
		} else {
			$app = JFactory::getApplication();
			if(JFactory::getApplication()->isAdmin()) {
				JError::raiseWarning(0, "Your cache directory (".JPATH_SITE.DS."cache) is not writable. Akeeba Backup Lazy Scheduling plugin will not work until you fix this issue.");
			}
			return;
		}

		// Load the settings
		$status = $this->loadStorage();
		if(!$status) {
			$app = JFactory::getApplication();
			if(JFactory::getApplication()->isAdmin()) {
				JError::raiseWarning(0, "Akeeba Backup Lazy Scheduling plugin can not read its temporary file. Make sure the cache directory in your site's root is writable and readable.");
			}
			return;
		}

		// When aklazy is 'check', it returns a backup URL, or dies if there's
		// no need to start/step a backup.
		if( ($aklazy == 'check') )
		{
			// Do a backup necessity check and return a URL or nothing at all
			$state = $this->getBackupState();
			if($state != 'none')
			{
				$url = JURI::base().'index.php?aklazy='.$state.'&nonce='.$this->nonce;
			}
			else
			{
				$url = '';
			}
			@ob_end_clean(); // Just in case...
			echo('###'.$url.'###');
			jexit();
		}

		if( (in_array($aklazy, array('start','step','ajaxstart','ajaxstep'))) && !empty($nonce) )
		{
			// Make sure we're not locked
			if($this->isLocked()) return;

			// Get the saved nonce and compare it to the one in the URL
			$this->getNonce();
			if(empty($this->nonce)) return;
			if($this->nonce != $nonce) return;
			if($this->isLocked()) return;

			// Try to convince PHP to not abort the request when the user is disconnected
			if(function_exists('ignore_user_abort')) {
				@ignore_user_abort(true);
			}
			
			// Set a time limit of 5 mintues
			if(function_exists('set_time_limit')) {
				@set_time_limit(300);
			}
			
			// Lock the backup process
			$this->setNonce();
			$this->setLock();
			$this->saveStorage();

			// Define the basic constants for the Akeeba Engine
			if(!defined('AKEEBA_BACKUP_ORIGIN')) {
				define('AKEEBA_BACKUP_ORIGIN','lazy'); // Set the backup origin
			}
			
			// Load the language files
			$jlang = JFactory::getLanguage();
			$jlang->load('com_akeeba', JPATH_SITE, 'en-GB', true);
			$jlang->load('com_akeeba', JPATH_SITE, $jlang->getDefault(), true);
			$jlang->load('com_akeeba', JPATH_SITE, null, true);
			$jlang->load('com_akeeba', JPATH_ADMINISTRATOR, 'en-GB', true);
			$jlang->load('com_akeeba', JPATH_ADMINISTRATOR, $jlang->getDefault(), true);
			$jlang->load('com_akeeba', JPATH_ADMINISTRATOR, null, true);

			// Set the profile and load the configuration
			$profile = (int)$this->params->get('profile',1);
			if($profile <= 0) $profile = 1;
			$session = JFactory::getSession();
			$session->set('profile', $profile, 'akeeba');
			
			AEPlatform::getInstance()->load_configuration($profile);
			if(empty($tag)) $tag = AEPlatform::getInstance()->get_backup_origin();

			$isDone = false;
			register_shutdown_function('AkeebaBackupLazyShutdown');
			if(in_array($aklazy,array('start','ajaxstart')))
			{
				// Start a new backup
				AEUtilTempvars::reset($tag);

				$kettenrad = AECoreKettenrad::load($tag);
				
				$user = JFactory::getUser();
				$userTZ = $user->getParam('timezone',0);
				$dateNow = new JDate();
				$dateNow->setOffset($userTZ);
				if( version_compare( JVERSION, '1.6.0', 'ge' ) ) {
					$description = JText::_('BACKUP_DEFAULT_DESCRIPTION').' '.$dateNow->format(JText::_('DATE_FORMAT_LC2'), true);
				} else {
					$description = JText::_('BACKUP_DEFAULT_DESCRIPTION').' '.$dateNow->toFormat(JText::_('DATE_FORMAT_LC2'));
				}
				$options = array(
					'description'	=> $description,
					'comment'		=> ''
				);
				$kettenrad->setup($options); // Setting up the engine
				$kettenrad->tick(); // Initializes the init domain
			} else {
				// Run a backup step
				$kettenrad = AECoreKettenrad::load($tag);
				$kettenrad->tick();
			}
			$array = $kettenrad->getStatusArray();
			$kettenrad->resetWarnings(); // So as not to have duplicate warnings reports
			AECoreKettenrad::save($tag);

			// Parse the return array
			if($array['Error'] != '')
			{
				// An error occured. Reset the engine and unset the nonce.
				$this->unsetNonce();
				$this->saveStorage();
				AECoreKettenrad::reset(array(
					'maxrun'	=> 0
				));
				$isDone = true;
			}
			elseif($array['HasRun'] == 1)
			{
				// All done. Clean up and unset the nonce.
				$this->unsetNonce();
				$this->saveStorage();
				AEFactory::nuke();
				AEUtilTempvars::reset($tag);
				$isDone = true;
			}

			// Unlock the process
			$this->unsetLock();
			$this->saveStorage();

			// Do we need to forward to the new step?
			if(in_array($aklazy, array('start','step')))
			{
				// IFRAME handling
				if(!$isDone)
				{
					$url = JURI::base().'index.php?aklazy=step&nonce='.$this->nonce;
					echo "<html><head><meta http-equiv=\"refresh\" content=\"0;$url\" /></head><body></body></html>";
					jexit();
				}
			}
			else
			{
				if(!$isDone)
				{
					echo '###'.$this->nonce.'###';
					jexit();
				}
			}

			// Stop processing
			jexit();
		}
	}