/** * Finalises the archive by compressing it. Overrides parent's method * @return boolean TRUE on success, FALSE on failure */ function finalize() { // Get gzip's binary location $registry = JoomlapackModelRegistry::getInstance(); $gzip = escapeshellcmd($registry->get('gzipbinary')); // Construct and run command line $command = "{$gzip} " . escapeshellcmd($this->_tempFilename); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerTARGZ :: Calling gzip. The command line is:"); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, $command); $result = shell_exec($command); // Normally, gzip should be silent as a fish. If anything was sput out, // there must have been an error. if (strlen(trim($result)) > 0) { $errorMessage = "Error calling gzip: " . $result . " \n Command line was: \n " . $command . " \n Please check file permissions and examine the result message for any hints regarding the problem tar faced archiving your files."; $this->setError($errorMessage); return false; } // Now, unregister the temp file (which no longer exists), register the gzipped file as // a new temp file and try to move it JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename); $this->_tempFilename = JoomlapackCUBETempfiles::registerTempFile(basename($this->_archiveFilename)); copy($this->_tempFilename, $this->_archiveFilename); JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename); // If no errors occured, return true return true; }
/** * Selects the algorithm to use based on the domain name * * @param string $domain The domain to return algorithm for * @return string The algorithm to use */ function selectAlgorithm($domain) { if (!class_exists('JoomlapackModelregistry')) { jpimport('models.registry', true); } $registry =& JoomlapackModelRegistry::getInstance(); switch ($domain) { case "installer": switch ($registry->get('BackupType')) { case 'full': return 'smart'; break; default: return '(null)'; break; } break; case "PackDB": return $registry->get('dbAlgorithm'); break; case "Packing": switch ($registry->get('BackupType')) { case 'full': return $registry->get('packAlgorithm'); break; default: return '(null)'; break; } break; default: return "(null)"; break; } }
function display() { $task = JRequest::getCmd('task', 'default'); switch ($task) { case 'showcomment': JToolBarHelper::title(JText::_('JOOMLAPACK') . ': <small><small>' . JText::_('BUADMIN') . '</small></small>'); JToolBarHelper::back('Back', 'index.php?option=' . JRequest::getCmd('option') . '&view=buadmin'); JoomlapackHelperUtils::addLiveHelp('buadmin'); $document =& JFactory::getDocument(); $document->addStyleSheet(JURI::base() . 'components/com_joomlapack/assets/css/joomlapack.css'); jpimport('models.statistics', true); $model =& JoomlapackModelStatistics::getInstance('Statistics', 'JoomlapackModel'); $model->setId(JRequest::getInt('id')); $record =& $model->getStatistic(); $this->assignRef('record', $record); JRequest::setVar('tpl', 'comment'); break; case 'restore': JToolBarHelper::title(JText::_('JOOMLAPACK') . ': <small><small>' . JText::_('BUADMIN') . '</small></small>'); JRequest::setVar('tpl', 'restore'); $this->assign('password', JRequest::getVar('password')); $this->assign('link', JRequest::getVar('linktarget')); break; default: $registry =& JoomlapackModelRegistry::getInstance(); $easy = $registry->get('easymode', false); if (!$easy) { JToolBarHelper::title(JText::_('JOOMLAPACK') . ': <small><small>' . JText::_('BUADMIN') . '</small></small>'); } else { JToolBarHelper::title(JText::_('JOOMLAPACKEASY') . ': <small><small>' . JText::_('BUADMIN') . '</small></small>'); } JToolBarHelper::back('Back', 'index.php?option=' . JRequest::getCmd('option')); JToolBarHelper::spacer(); JToolBarHelper::deleteList(); JToolBarHelper::custom('deletefiles', 'delete.png', 'delete_f2.png', JText::_('STATS_LABEL_DELETEFILES'), true); JToolBarHelper::save('download', JText::_('STATS_LOG_DOWNLOAD')); if (!$easy) { JToolBarHelper::editList('showcomment', JText::_('STATS_LOG_VIEWCOMMENT')); if (JPSPECIALEDITION) { JToolBarHelper::publish('restore', JText::_('STATS_LOG_RESTORE')); } } JToolBarHelper::spacer(); if (!$easy) { JoomlapackHelperUtils::addLiveHelp('buadmin'); } else { JoomlapackHelperUtils::addLiveHelp('buadmineasy'); } $document =& JFactory::getDocument(); $document->addStyleSheet(JURI::base() . 'components/com_joomlapack/assets/css/joomlapack.css'); jpimport('models.statistics', true); $model =& JoomlapackModelStatistics::getInstance('Statistics', 'JoomlapackModel'); $list =& $model->getStatisticsListWithMeta(); $this->assignRef('list', $list); $this->assignRef('pagination', $model->getPagination()); $this->assign('easy', $easy); break; } parent::display(JRequest::getVar('tpl')); }
/** * Implements the init method of JoomlapackFilter * */ function init() { $jreg =& JFactory::getConfig(); $configuration =& JoomlapackModelRegistry::getInstance(); $this->_skipContainedDirectoriesFilter = array(); $temp = $this->_loadFilters(); if (DS == '\\') { if (is_array($temp)) { foreach ($temp as $filter) { $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE . DS . $filter); } } } else { if (is_array($temp)) { foreach ($temp as $filter) { $this->_skipContainedDirectoriesFilter[] = JPATH_SITE . DS . $filter; } } } // Add temporary and output directories $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath($configuration->get('OutputDirectory'))); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath($configuration->getTemporaryDirectory())); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath($jreg->getValue('config.tmp_path'))); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath(JPATH_CACHE)); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath(JPATH_ADMINISTRATOR . DS . 'cache')); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JoomlapackHelperUtils::TranslateWinPath(JPATH_ROOT . DS . 'cache')); // Hack: add the same paths untranslated $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash($configuration->get('OutputDirectory')); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash($configuration->getTemporaryDirectory()); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash($jreg->getValue('config.tmp_path')); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JPATH_CACHE); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JPATH_ADMINISTRATOR . DS . 'cache'); $this->_skipContainedDirectoriesFilter[] = JoomlapackHelperUtils::TrimTrailingSlash(JPATH_ROOT . DS . 'cache'); }
function display() { // Decide what to do; delegate data loading to private methods $task = JRequest::getCmd('task', 'display'); $layout = JRequest::getCmd('layout', 'default'); JToolBarHelper::title(JText::_('JOOMLAPACK') . ': <small><small>' . JText::_('CRONMAN') . '</small></small>'); switch ($layout) { case 'default_edit': // Get the CRON configuration definition if ($task == 'add') { $definition = null; $registry =& JoomlapackModelRegistry::getInstance(); $secret = $registry->get('secret_key'); $this->assign('secret', $secret); } else { $id = JRequest::getInt('id', 0); $model =& $this->getModel('cronman'); $definition = $model->getConfiguration($id); } $this->assign('definition', $definition); // Get some lists and pass them on $model =& $this->getModel('cronman'); $postops = $model->getPostOpList(); $this->assign('postops', $postops); // Add the buttons JToolBarHelper::save(); JToolBarHelper::apply(); JToolBarHelper::cancel(); break; case 'default': default: $this->_default(); break; } // Load the util helper $this->loadHelper('utils'); // Add a spacer, a help button and show the template JToolBarHelper::spacer(); JoomlapackHelperUtils::addLiveHelp('profiles'); // Load a list of profiles $model =& $this->getModel('cronman'); jpimport('models.profiles', true); $profilesmodel = new JoomlapackModelProfiles(); $profiles_objects = $profilesmodel->getProfilesList(true); $profiles = array(); foreach ($profiles_objects as $profile) { $id = $profile->id; $profiles[(string) $id] = $profile->description; } unset($profiles_objects); unset($profilesmodel); $this->assign('profiles', $profiles); // Add JoomlaPack CSS $document =& JFactory::getDocument(); $document->addStyleSheet(JURI::base() . '/components/com_joomlapack/assets/css/joomlapack.css'); // Show the view parent::display(); }
function agree() { $registry =& JoomlapackModelRegistry::getInstance(); $registry->set('nagscreen', true); $registry->save(); $registry->reload(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=cpanel'); parent::redirect(); }
/** * Writes a line to the log, if the log level is high enough * * @param int|bool $level The log level (_JP_LOG_XX constants). Use FALSE to pause logging, TRUE to resume logging * @param string $message The message to write to the log */ function WriteLog($level, $message) { static $configuredLoglevel; static $site_root; if (empty($site_root)) { if (!class_exists('JoomlapackHelperUtils')) { jpimport('helpers.utils', true); } $site_root = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE); } if (empty($configuredLoglevel) or $level === true) { // Load the registry if (!class_exists('JoomlapackModelRegistry')) { jpimport('models.registry', true); } $registry =& JoomlapackModelRegistry::getInstance(); // Fetch log level $configuredLoglevel = $registry->get('logLevel'); } if ($level === false) { // Pause logging $configuredLogLevel = false; return; } // Catch paused logging if ($configuredLoglevel === false) { return; } if ($configuredLoglevel >= $level && $configuredLoglevel != 0) { $logName = JoomlapackLogger::logName(); $message = str_replace(JPATH_SITE, "<root>", $message); $message = str_replace($site_root, "<root>", $message); // Fix 2.4 - Also replace the translated path on Windows machines $message = str_replace("\n", ' \\n ', $message); // Fix 1.1.1 - Handle (error) messages containing newlines (by nicholas) switch ($level) { case _JP_LOG_ERROR: $string = "ERROR |"; break; case _JP_LOG_WARNING: $string = "WARNING |"; break; case _JP_LOG_INFO: $string = "INFO |"; break; default: $string = "DEBUG |"; break; } $string .= @strftime("%y%m%d %T") . "|{$message}\r\n"; $fp = @fopen($logName, "at"); if (!($fp === FALSE)) { @fwrite($fp, $string); @fclose($fp); } } }
/** * Displays the editor page * */ function display() { // Make sure we're on easy mode; otherwise redirect to Control Panel $registry =& JoomlapackModelRegistry::getInstance(); if (!$registry->get('easymode', false)) { $this->setRedirect(JURI::base() . 'index.php?option=' . JRequest::getCmd('option') . '&view=cpanel'); $this->redirect(); } parent::display(); }
function deleteTempFiles() { $configuration =& JoomlapackModelRegistry::getInstance(); $tempFiles = JoomlapackCUBETables::UnserializeVar('CUBETempFiles', array()); foreach ($tempFiles as $fileName) { $file = $configuration->getTemporaryDirectory() . DS . $fileName; if (file_exists($file)) { @unlink($file); } } JoomlapackCUBETables::DeleteVar('CUBETempFiles'); }
function display() { $task = JRequest::getCmd('task', 'default'); $act = JRequest::getCmd('act', 'start'); // Set the toolbar title JToolBarHelper::title(JText::_('JOOMLAPACK') . ':: <small><small>' . JText::_('BACKUP') . '</small></small>'); // Load the util helper $this->loadHelper('utils'); switch ($task) { case 'backup': if (!class_exists('JoomlapackModelRegistry')) { jpimport('models.registry', true); } $registry =& JoomlapackModelRegistry::getInstance(); $this->assign('backupMethod', $registry->get('backupMethod')); break; case 'error': $this->assign('errormessage', JRequest::getString('message')); JToolBarHelper::back('Back', 'index.php?option=' . JRequest::getCmd('option')); break; case 'finised': JToolBarHelper::back('Back', 'index.php?option=' . JRequest::getCmd('option')); JToolBarHelper::spacer(); JoomlapackHelperUtils::addLiveHelp('backup'); break; default: // Add some buttons JToolBarHelper::back('Back', 'index.php?option=' . JRequest::getCmd('option')); JToolBarHelper::spacer(); JoomlapackHelperUtils::addLiveHelp('backup'); // Load model $model =& $this->getModel('backup'); // Load the Status Helper jpimport('helpers.status', true); $helper =& JoomlapackHelperStatus::getInstance(); // Pass on data $this->assign('haserrors', !$helper->status); $this->assign('hasquirks', $helper->hasQuirks()); $this->assign('quirks', $helper->getQuirksCell(!$helper->status)); $this->assign('description', $model->getDescription()); $this->assign('comment', $model->getComment()); $this->assign('profile', $model->getProfileID()); $this->assign('profilelist', $model->getProfilesList()); break; } $css = JURI::base() . 'components/com_joomlapack/assets/css/joomlapack.css'; $document =& JFactory::getDocument(); $document->addStyleSheet($css); parent::display(JRequest::getCmd('tpl', null)); }
function getLogFilename() { // Make sure the registry model is loaded if (!class_exists('JoomlapackModelRegistry')) { jpimport('models.registry', true); } // Get output directory $registry =& JoomlapackModelRegistry::getInstance(); $outdir = $registry->get('OutputDirectory'); // Get log's file name $logName = $outdir . DS . 'joomlapack.log'; // Tidy up the path to the file jimport('joomla.filesystem.file'); return $logName; }
/** * Check that the user has sufficient permissions, or die in error * */ function _checkPermissions() { jpimport('models.registry', true); $registry =& JoomlapackModelRegistry::getInstance(); // Is frontend backup enabled? $febEnabled = $registry->get('enableFrontend'); if (!$febEnabled) { die('403 ' . JText::_('ERROR_NOT_ENABLED')); } // Is the key good? $key = JRequest::getVar('key'); $validKey = $registry->get('secretWord'); if ($key != $validKey) { die('403 ' . JText::_('ERROR_INVALID_KEY')); } }
/** * Applies the troubleshooter's suggestion and moves on to the backup page * */ function troubleshooter() { $model =& $this->getModel('cpanel'); $registry =& JoomlapackModelRegistry::getInstance(); $nextStep = $model->nextSettingsMode(); if (is_null($nextStep)) { // Oops! No further action to take, brother! $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=cpanel', JText::_('CPANEL_TROUBLESHOOTER_ERROR'), 'error'); return; } else { $registry->set('settingsmode', $nextStep); $registry->save(); $registry->reload(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=backup'); } }
function &getFolders($folder) { // Was the breakflag set BEFORE starting? -- This workaround is required due to PHP5 defaulting to assigning variables by reference $breakflag_before_process = $this->BREAKFLAG ? true : false; // Reset break flag before continuing $this->BREAKFLAG = false; // Initialize variables $arr = array(); $false = false; if (!is_dir($folder)) { return $false; } $counter = 0; $registry =& JoomlapackModelRegistry::getInstance(); $maxCounter = $registry->get('mnMaxFragmentFiles', 50) * 2; $cube =& JoomlapackCUBE::getInstance(); $allowBreakflag = $cube->operationCounter != 0 && !$breakflag_before_process; $handle = @opendir($folder); // If directory is not accessible, just return FALSE if ($handle === FALSE) { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning('Unreadable directory ' . $folder); return $false; } while (($file = @readdir($handle)) !== false && !$this->BREAKFLAG) { if ($file != '.' && $file != '..') { // # Fix 2.4: Do not add DS if we are on the site's root and it's an empty string $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DS ? '' : DS; $dir = $folder . $ds . $file; $isDir = is_dir($dir); if ($isDir) { $data = JPISWINDOWS ? JoomlapackHelperUtils::TranslateWinPath($dir) : $dir; if ($data) { $arr[] = $data; } } } $counter++; if ($counter >= $maxCounter) { $this->BREAKFLAG = $allowBreakflag; } } @closedir($handle); return $arr; }
/** * Loads the file filters off the database and stores them in the _singleFileFilters array * */ function init() { $configuration =& JoomlapackModelRegistry::getInstance(); $temp = $this->_loadFilters(); $this->_singleFileFilters = array(); if (DS == '\\') { if (is_array($temp)) { foreach ($temp as $filter) { $this->_singleFileFilters[] = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE . DS . $filter); } } } else { if (is_array($temp)) { foreach ($temp as $filter) { $this->_singleFileFilters[] = JPATH_SITE . DS . $filter; } } } }
/** * Default task; shows the initial page where the user selects a profile * and enters description and comment * */ function display() { $format = JRequest::getCmd('format', 'html'); // For raw view with default task use the default_raw.php template file if ($format == 'raw') { JRequest::setVar('tpl', 'raw'); } $registry =& JoomlapackModelRegistry::getInstance(); if ($format != 'raw' && $registry->get('easymode', false)) { // Easy Mode enabled and the defaut backup view was requested. Skip to backup start. $model =& $this->getModel('backup'); JRequest::setVar('description', $model->getDescription()); JRequest::setVar('comment', $model->getComment()); JRequest::setVar('profile', 1); JRequest::setVar('task', 'backup'); $this->backup(); return; } parent::display(); }
/** * Implements the init method of JoomlapackFilter * */ function init() { $configuration =& JoomlapackModelRegistry::getInstance(); $temp = $this->_loadFilters(); $this->_folderFilters = array(); if (DS == '\\') { if (is_array($temp)) { foreach ($temp as $filter) { $this->_folderFilters[] = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE . DS . $filter); } } } else { if (is_array($temp)) { foreach ($temp as $filter) { $this->_folderFilters[] = JPATH_SITE . DS . $filter; } } } // Add any leftover installation directory to exclusion filters. THIS SHOULD NEVER BE NECESSARY ON A REAL SITE! $this->_folderFilters[] = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE . DS . 'installation'); }
function &getFolders($folder) { // Initialize variables $arr = array(); $false = false; if (!is_dir($folder)) { return $false; } $counter = 0; $registry =& JoomlapackModelRegistry::getInstance(); $maxCounter = $registry->get('mnMaxFragmentFiles', 50) * 2; $cube =& JoomlapackCUBE::getInstance(); $allowBreakflag = $cube->operationCounter != 0; $handle = @opendir($folder); // If directory is not accessible, just return FALSE if ($handle === FALSE) { JoomlapackLogger::WriteLog(_JP_LOG_WARNING, 'Unreadable directory ' . $dirName); return $false; } while (($file = @readdir($handle)) !== false && !$this->BREAKFLAG) { if ($file != '.' && $file != '..') { $dir = $folder . DS . $file; $isDir = is_dir($dir); if ($isDir) { $data = JPISWINDOWS ? JoomlapackHelperUtils::TranslateWinPath($dir) : $dir; if ($data) { $arr[] = $data; } } } $counter++; if ($counter >= $maxCounter) { $this->BREAKFLAG = $allowBreakflag; } } @closedir($handle); return $arr; }
/** * Initialises the archiver class, creating the archive from an existent * installer's JPA archive. * * @param string $sourceJPAPath Absolute path to an installer's JPA archive * @param string $targetArchivePath Absolute path to the generated archive * @param array $options A named key array of options (optional). This is currently not supported * @access public */ function initialize($sourceJPAPath, $targetArchivePath, $options = array()) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerTAR :: initialize - archive {$targetArchivePath}"); // Get names of temporary files $configuration =& JoomlapackModelRegistry::getInstance(); $this->_dataFileName = $targetArchivePath; // Try to kill the archive if it exists JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerTAR :: Killing old archive"); $fp = fopen($this->_dataFileName, "wb"); if (!($fp === false)) { ftruncate($fp, 0); fclose($fp); } else { @unlink($this->_dataFileName); } if (!@touch($this->_dataFileName)) { $this->setError(JText::_('CUBE_ARCHIVER_CANTWRITE')); return false; } $this->_tarObject = new Archive_Tar($targetArchivePath); $this->_tarObject->owningObject =& $this; parent::initialize($sourceJPAPath, $targetArchivePath, $options); }
/** * Writes a line to the log, if the log level is high enough * * @param integer $level The log level (_JP_LOG_XX constants) * @param string $message The message to write to the log */ function WriteLog($level, $message) { // Load the registry if (!class_exists('JoomlapackModelRegistry')) { jpimport('models.registry', true); } $registry =& JoomlapackModelRegistry::getInstance(); // Fetch log level $configuredLoglevel = $registry->get('logLevel'); if ($configuredLoglevel >= $level && $configuredLoglevel != 0) { $logName = JoomlapackLogger::logName(); $message = str_replace(JPATH_SITE, "<root>", $message); $message = str_replace("\n", ' \\n ', $message); // Fix 1.1.1 - Handle (error) messages containing newlines (by nicholas) switch ($level) { case _JP_LOG_ERROR: $string = "ERROR |"; break; case _JP_LOG_WARNING: $string = "WARNING |"; break; case _JP_LOG_INFO: $string = "INFO |"; break; default: $string = "DEBUG |"; break; } $string .= @strftime("%y%m%d %T") . "|{$message}\r\n"; $fp = @fopen($logName, "at"); if (!($fp === FALSE)) { @fwrite($fp, $string); @fclose($fp); } } }
function display() { $registry =& JoomlapackModelRegistry::getInstance(); if ($registry->get('easymode', false)) { // Easy mode on, switch to expert $registry->set('easymode', false); } else { // Expert mdoe on, switch to easy // Get the model $model =& $this->getModel('switch'); // Remove all inclusions and exclusion filters $model->clearInclusionFilters(); $model->clearExclusionFilters(); // If we are on a custom settings level, switch to normal if ($registry->get('settingsmode') == 'custom') { $registry->set('settingsmode', 'normal'); } // Update mode selection $registry->set('easymode', true); } $registry->save(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=cpanel'); $this->redirect(); }
/** * Initialises the archiver class, seeding the remote installation * from an existent installer's JPA archive. * * @param string $sourceJPAPath Absolute path to an installer's JPA archive * @param string $targetArchivePath Absolute path to the generated archive (ignored in this class) * @param array $options A named key array of options (optional) * @access public */ function initialize($sourceJPAPath, $targetArchivePath, $options = array()) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, __CLASS__ . " :: new instance"); $registry =& JoomlapackModelRegistry::getInstance(); $this->_host = $registry->get('df_host', ''); $this->_port = $registry->get('df_port', '21'); $this->_user = $registry->get('df_user', ''); $this->_pass = $registry->get('df_pass', ''); $this->_initdir = $registry->get('df_initdir', ''); $this->_usessl = $registry->get('df_usessl', false); $this->_passive = $registry->get('df_passive', true); if (isset($options['host'])) { $this->_host = $options['host']; } if (isset($options['port'])) { $this->_port = $options['port']; } if (isset($options['user'])) { $this->_user = $options['user']; } if (isset($options['pass'])) { $this->_pass = $options['pass']; } if (isset($options['initdir'])) { $this->_initdir = $options['initdir']; } if (isset($options['usessl'])) { $this->_usessl = $options['usessl']; } if (isset($options['passive'])) { $this->_passive = $options['passive']; } $this->connect_ok = $this->_connectFTP(); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, __CLASS__ . " :: Initializing with {$sourceJPAPath}"); parent::initialize($sourceJPAPath, $targetArchivePath, $options); }
/** * Outputs the necessary JavaScript to the browser * */ function renderJavaScript() { jpimport('models.registry', true); $profile =& JoomlapackModelRegistry::getInstance(); $method = $profile->get('backupMethod'); if ($method == 'ajax') { JoomlapackHelperSkip::_renderAJAXJavaScript(); } else { JoomlapackHelperSkip::_renderRedirectsJavaScript(); } }
function _setProfile() { // Set profile $profile = JRequest::getInt('profile', 1); if (!JPSPECIALEDITION) { $profile = 1; } if (!is_numeric($profile)) { $profile = 1; } $session =& JFactory::getSession(); $session->set('profile', $profile, 'joomlapack'); // Reload registry jpimport('models.registry', true); $registry =& JoomlapackModelRegistry::getInstance(); $registry->reload(); }
/** * The most basic file transaction: add a single entry (file or directory) to * the archive. * * @param bool $isVirtual If true, the next parameter contains file data instead of a file name * @param string $sourceNameOrData Absolute file name to read data from or the file data itself is $isVirtual is true * @param string $targetName The (relative) file name under which to store the file in the archive * @return True on success, false otherwise * @since 1.2.1 * @access protected * @abstract */ function _addFile($isVirtual, &$sourceNameOrData, $targetName) { static $configuration; if (!$configuration) { jpimport('models.registry', true); $configuration =& JoomlapackModelRegistry::getInstance(); } // See if it's a directory $isDir = $isVirtual ? false : is_dir($sourceNameOrData); // Get real size before compression if ($isVirtual) { $fileSize = strlen($sourceNameOrData); } else { $fileSize = $isDir ? 0 : filesize($sourceNameOrData); } // Decide if we will compress if ($isDir) { $compressionMethod = 0; // don't compress directories... } else { // Do we have plenty of memory left? $memLimit = ini_get("memory_limit"); if (is_numeric($memLimit) && $memLimit < 0) { $memLimit = ""; } // 1.2a3 -- Rare case with memory_limit < 0, e.g. -1Mb! if ($memLimit == "" || $fileSize >= _JoomlapackPackerZIP_COMPRESSION_THRESHOLD) { // No memory limit, or over 1Mb files => always compress up to 1Mb files (otherwise it times out) $compressionMethod = $fileSize <= _JoomlapackPackerZIP_COMPRESSION_THRESHOLD ? 1 : 0; } elseif (function_exists("memory_get_usage")) { // PHP can report memory usage, see if there's enough available memory; Joomla! alone eats about 5-6Mb! This code is called on files <= 1Mb $memLimit = $this->_return_bytes($memLimit); $availableRAM = $memLimit - memory_get_usage(); $compressionMethod = $availableRAM / 2.5 >= $fileSize ? 1 : 0; } else { // PHP can't report memory usage, compress only files up to 512Kb (conservative approach) and hope it doesn't break $compressionMethod = $fileSize <= 524288 ? 1 : 0; } } $compressionMethod = function_exists("gzcompress") ? $compressionMethod : 0; $storedName = $targetName; /* "Entity Description BLock" segment. */ $unc_len =& $fileSize; // File size $storedName .= $isDir ? "/" : ""; if ($compressionMethod == 1) { if ($isVirtual) { $udata =& $sourceNameOrData; } else { // Get uncompressed data if (function_exists("file_get_contents") && _JoomlapackPackerZIP_FORCE_FOPEN == false) { $udata = @file_get_contents($sourceNameOrData); // PHP > 4.3.0 saves us the trouble } else { // Argh... the hard way! $udatafp = @fopen($sourceNameOrData, "rb"); if (!($udatafp === false)) { $udata = ""; while (!feof($udatafp)) { // Keep-alive on file reading if ($configuration->get("enableMySQLKeepalive", false)) { list($usec, $sec) = explode(" ", microtime()); $endTime = (double) $usec + (double) $sec; if ($endTime - $this->startTime > 0.5) { $this->startTime = $endTime; JoomlapackCUBETables::WriteVar('dummy', 1); } } $udata .= fread($udatafp, JPPACK_CHUNK); } fclose($udatafp); } else { $udata = false; } } } if ($udata === FALSE) { // Unreadable file, skip it. JoomlapackLogger::WriteLog(_JP_LOG_WARNING, JText::sprintf('CUBE_WARN_UNREADABLEFILE', $sourceNameOrData)); return false; } else { // Proceed with compression $zdata = @gzcompress($udata); if ($zdata === false) { // If compression fails, let it behave like no compression was available $c_len =& $unc_len; $compressionMethod = 0; } else { unset($udata); $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); $c_len = strlen($zdata); } } } else { $c_len = $unc_len; } $this->_compressedSize += $c_len; // Update global data $this->_uncompressedSize += $fileSize; // Update global data $this->_fileCount++; // Get file permissions $perms = $isVirtual ? 0777 : @fileperms($sourceNameOrData); // Calculate Entity Description Block length $blockLength = 21 + strlen($storedName); // Open data file for output $fp = @fopen($this->_dataFileName, "ab"); if ($fp === false) { $this->setError("Could not open archive file '{$this->_dataFileName}' for append!"); return; } $this->_fwrite($fp, $this->_fileHeader); // Entity Description Block header if ($this->getError()) { return; } $this->_fwrite($fp, pack('v', $blockLength)); // Entity Description Block header length $this->_fwrite($fp, pack('v', strlen($storedName))); // Length of entity path $this->_fwrite($fp, $storedName); // Entity path $this->_fwrite($fp, pack('C', $isDir ? 0 : 1)); // Entity type $this->_fwrite($fp, pack('C', $compressionMethod)); // Compression method $this->_fwrite($fp, pack('V', $c_len)); // Compressed size $this->_fwrite($fp, pack('V', $unc_len)); // Uncompressed size $this->_fwrite($fp, pack('V', $perms)); // Entity permissions /* "File data" segment. */ if ($compressionMethod == 1) { // Just dump the compressed data $this->_fwrite($fp, $zdata); if ($this->getError()) { return; } unset($zdata); } elseif (!$isDir) { if ($isVirtual) { $this->_fwrite($fp, $sourceNameOrData); if ($this->getError()) { return; } } else { // Copy the file contents, ignore directories $zdatafp = @fopen($sourceNameOrData, "rb"); if ($zdatafp === FALSE) { JoomlapackLogger::WriteLog(_JP_LOG_WARNING, JText::sprintf('CUBE_WARN_UNREADABLEFILE', $sourceNameOrData)); return false; } else { while (!feof($zdatafp)) { $zdata = fread($zdatafp, JPPACK_CHUNK); $this->_fwrite($fp, $zdata); if ($this->getError()) { return; } } fclose($zdatafp); } } } fclose($fp); // ... and return TRUE = success return TRUE; }
/** * Scans a directory for files and directories, updating the _directoryList and _fileList * private fields * * @return bool True if more work has to be done, false if the dirextory stack is empty */ function _scanNextDirectory() { // Are we supposed to scan for more files? if ($this->_doneScanning) { return true; } // Get the next directory to scan, if the folders and files of the last directory // have been scanned. if ($this->_doneSubdirectoryScanning && $this->_doneFileScanning) { if (count($this->_directoryList) == 0) { // No directories left to scan return false; } else { // Get and remove the last entry from the $_directoryList array $this->_dirName = array_pop($this->_directoryList); $this->_Step = $this->_dirName; $this->_doneSubdirectoryScanning = false; $this->_doneFileScanning = false; $this->_processedFiles = 0; } } $cube =& JoomlapackCUBE::getInstance(); $provisioning =& $cube->getProvisioning(); $engine =& $provisioning->getListerEngine(); // Scan subdirectories, if they have not yet been scanned. if (!$this->_doneSubdirectoryScanning) { // Apply DEF (directory exclusion filters) if (in_array($this->_dirName, $this->_ExcludeDirs)) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Skipping directory " . $this->_dirName); $this->_doneSubdirectoryScanning = true; $this->_doneFileScanning = true; return true; } // Apply Skip Contained Directories Filters if (in_array($this->_dirName, $this->_skipContainedDirectories)) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Skipping subdirectories of directory " . $this->_dirName); $this->_doneSubdirectoryScanning = true; } else { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Scanning directories of " . $this->_dirName); // Get subdirectories $subdirs = $engine->getFolders($this->_dirName); // If the list contains "too many" items, please break this step! if ($engine->BREAKFLAG) { // Unset the BREAKFLAG of the engine $engine->BREAKFLAG = false; // Set the BREAKFLAG of our class $this->setBreakFlag(); // Log this decision, for debugging reasons JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Large directory " . $this->_dirName . " while scanning for subdirectories; I will resume scanning in next step."); // Return immediately, marking that we are not done yet! return true; } // Error propagation if ($engine->getError()) { $this->setError($engine->getError()); return false; } if (!empty($subdirs) && is_array($subdirs)) { $registry =& JoomlapackModelRegistry::getInstance(); $dereferencesymlinks = $registry->get('dereferencesymlinks'); if ($dereferencesymlinks) { // Treat symlinks to directories as actual directories foreach ($subdirs as $subdir) { $this->_directoryList[] = $subdir; } } else { // Treat symlinks to directories as simple symlink files (ONLY WORKS WITH CERTAIN ARCHIVERS!) foreach ($subdirs as $subdir) { if (is_link($subdir)) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, 'Symlink found: ' . $subdir); $this->_fileList[] = $subdir; } else { $this->_directoryList[] = $subdir; } } } } } $this->_doneSubdirectoryScanning = true; return true; // Break operation } // If we are here, we have not yet scanned the directory for files, so there // is no need to test for _doneFileScanning (saves a tiny amount of CPU time) // Apply Skipfiles, a.k.a. CFF (Contained Files Filter) if (in_array($this->_dirName, $this->_skipContainedFiles)) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Skipping files of directory " . $this->_dirName); // Try to find and include .htaccess and index.htm(l) files jimport('joomla.filesystem.file'); // # Fix 2.4: Do not add DS if we are on the site's root and it's an empty string $ds = $this->_dirName == '' || $this->_dirName == '/' ? '' : DS; $checkForTheseFiles = array($this->_dirName . $ds . '.htaccess', $this->_dirName . $ds . 'index.html', $this->_dirName . $ds . 'index.htm', $this->_dirName . $ds . 'robots.txt'); $this->_processedFiles = 0; foreach ($checkForTheseFiles as $fileName) { if (JFile::exists($fileName)) { $this->_fileList[] = $fileName; $this->_processedFiles++; } } $this->_doneFileScanning = true; } else { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Scanning files of " . $this->_dirName); // Get file listing $fileList =& $engine->getFiles($this->_dirName); // If the list contains "too many" items, please break this step! if ($engine->BREAKFLAG) { // Unset the BREAKFLAG of the engine $engine->BREAKFLAG = false; // Set the BREAKFLAG of our class $this->setBreakFlag(); // Log this decision, for debugging reasons JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Large directory " . $this->_dirName . " while scanning for files; I will resume scanning in next step."); // Return immediately, marking that we are not done yet! return true; } // Error propagation if ($engine->getError()) { $this->setError($engine->getError()); return false; } $this->_processedFiles = 0; if ($fileList === false) { // A non-browsable directory; however, it seems that I never get FALSE reported here?! $cube->addWarning(JText::sprintf('CUBE_WARN_UNREADABLEDIR', $this->_dirName)); } else { if (is_array($fileList) && !empty($fileList)) { // Scan all directory entries foreach ($fileList as $fileName) { $skipThisFile = is_array($this->_ExcludeFiles) ? in_array($fileName, $this->_ExcludeFiles) : false; if ($skipThisFile) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Skipping file {$fileName}"); } else { $this->_fileList[] = $fileName; $this->_processedFiles++; } } // end foreach } // end if } // end filelist not false $this->_doneFileScanning = true; } // Check to see if there were no contents of this directory added to our search list if ($this->_processedFiles == 0) { $archiver =& $provisioning->getArchiverEngine(); $archiver->addFile($this->_dirName, $this->_removePath, $this->_addPath); if ($archiver->getError()) { $this->setError($archiver->getError()); return false; } JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Empty directory " . $this->_dirName); unset($archiver); $this->_doneScanning = false; // Because it was an empty dir $_fileList is empty and we have to scan for more files } else { // Next up, add the files to the archive! $this->_doneScanning = true; } // We're done listing the contents of this directory unset($engine); unset($provisioning); unset($cube); return true; }
/** * Returns the directly more conservative "Settings Mode" setting * which is then proposed to be applied in order to attempt overcoming * backup problems. * * @return string|null The next Settings Mode, or null if we're already on conservative mode */ function nextSettingsMode() { $registry =& JoomlapackModelRegistry::getInstance(); $currentMode = $registry->get('settingsmode'); switch ($currentMode) { case 'custom': case 'optimistic': return 'normal'; break; case 'normal': return 'conservative'; break; case 'conservative': return null; break; } }
/** * Returns the CRC32 of a file, selecting the more appropriate algorithm. * * @param string $filename Absolute path to the file being processed * @param integer $JoomlapackPackerZIP_CHUNK_SIZE Obsoleted * @return integer The CRC32 in numerical form */ function crc32_file($filename, $JoomlapackPackerZIP_CHUNK_SIZE) { static $configuration; if (!$configuration) { jpimport('models.registry', true); $configuration =& JoomlapackModelRegistry::getInstance(); } // Keep-alive before CRC32 calculation if ($configuration->get("enableMySQLKeepalive", false)) { list($usec, $sec) = explode(" ", microtime()); $endTime = (double) $usec + (double) $sec; if ($endTime - $this->startTime > 0.5) { $this->startTime = $endTime; JoomlapackCUBETables::WriteVar('dummy', 1); } } if (function_exists("hash_file")) { $res = $this->crc32_file_php512($filename); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "File {$filename} - CRC32 = " . dechex($res) . " [PHP512]"); } else { if (function_exists("file_get_contents") && @filesize($filename) <= $JoomlapackPackerZIP_CHUNK_SIZE) { $res = $this->crc32_file_getcontents($filename); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "File {$filename} - CRC32 = " . dechex($res) . " [GETCONTENTS]"); } else { $res = $this->crc32_file_php4($filename, $JoomlapackPackerZIP_CHUNK_SIZE); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "File {$filename} - CRC32 = " . dechex($res) . " [PHP4]"); } } if ($res === FALSE) { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning("File {$filename} - NOT READABLE: CRC32 IS WRONG!"); } return $res; }
/** * Returns the database packer object instance * * @param bool $forceNew Force creation of a fresh instance, overriding the stored one * @return JoomlapackEngineParts The database packer object instance * @todo Create an abstract class for database packer classes */ function &getDBPackerEngine($forceNew = false) { if (!is_object($this->_dumperInstance) || $forceNew) { $configuration =& JoomlapackModelRegistry::getInstance(); $engine = $configuration->get('dbdumpengine'); $this->_dumperInstance =& $this->_getAnEngine('dumper', $engine); } return $this->_dumperInstance; }
} function to_json($var) { // Prefer native PHP 5.2.1+ JSON encoder (uber-fast!)... if (function_exists('json_encode')) { return json_encode($var); } else { $encoder = new Services_JSON(); return $encoder->encode($var); } } $task = JRequest::getCmd('task', ''); switch ($task) { case 'getdirectory': // Return the output directory in JSON format $registry =& JoomlapackModelRegistry::getInstance(); $outdir = $registry->get('OutputDirectory'); // # Fix 2.4: Drop the output buffer if (function_exists('ob_clean')) { @ob_clean(); } echo to_json($outdir); break; default: // Return the CUBE array in JSON format $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); // # Fix 2.4: Drop the output buffer if (function_exists('ob_clean')) { @ob_clean(); }