Exemplo n.º 1
0
	/**
	 * Unregister and delete a temporary file
	 * @param $fileName The filename to unregister and delte
	 * @param $removePrefix The prefix to remove
	 */
	static function unregisterAndDeleteTempFile( $fileName, $removePrefix = false )
	{
		$configuration =& AEFactory::getConfiguration();

		if($removePrefix)
		{
			$fileName = str_replace( AEUtilFilesystem::TranslateWinPath($configuration->get('akeeba.basic.temporary_directory')) , '', $fileName);
			if( (substr($fileName, 0, 1) == '/') || (substr($fileName, 0, 1) == '\\') )
			{
				$fileName = substr($fileName, 1 );
			}
			if( (substr($fileName, -1) == '/') || (substr($fileName, -1) == '\\') )
			{
				$fileName = substr($fileName, 0, -1 );
			}
		}

		// We don't unregister the tempfile here, because on some systems (Windows &
		// servers on FastCGI) the files wouldn't get deleted.

		$file = $configuration->get('akeeba.basic.temporary_directory').DS.$fileName;
		AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Removing temporary file $fileName" );
		$platform = strtoupper(PHP_OS);
		if( (substr($platform,0,6) == 'CYGWIN') || (substr($platform,0,3) == 'WIN') )
		{
			// On Windows we have to chwon() the file first to make it owned by Nobody
			AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Windows hack: chowning $fileName" );
			@chown($file, 600);
		}
		return @self::nullifyAndDelete($file);
	}
Exemplo n.º 2
0
 public function __construct()
 {
     $this->object = 'dir';
     $this->subtype = 'inclusion';
     $this->method = 'direct';
     // FIXME This filter doesn't work very well on many live hosts. Disabled for now.
     parent::__construct();
     return;
     if (empty($this->filter_name)) {
         $this->filter_name = strtolower(basename(__FILE__, '.php'));
     }
     // Get the saved library path and compare it to the default
     $jlibdir = AEPlatform::getInstance()->get_platform_configuration_option('jlibrariesdir', '');
     if (empty($jlibdir)) {
         if (defined('JPATH_LIBRARIES')) {
             $jlibdir = JPATH_LIBRARIES;
         } elseif (defined('JPATH_PLATFORM')) {
             $jlibdir = JPATH_PLATFORM;
         } else {
             $jlibdir = false;
         }
     }
     if ($jlibdir !== false) {
         $jlibdir = AEUtilFilesystem::TranslateWinPath($jlibdir);
         $defaultLibraries = AEUtilFilesystem::TranslateWinPath(JPATH_SITE . '/libraries');
         if ($defaultLibraries != $jlibdir) {
             // The path differs, add it here
             $this->filter_data['JPATH_LIBRARIES'] = $jlibdir;
         }
     } else {
         $this->filter_data = array();
     }
     parent::__construct();
 }
Exemplo n.º 3
0
 protected function scanFolder($folder, &$position, $forFolders = true, $threshold_key = 'dir', $threshold_default = 50)
 {
     $registry = AEFactory::getConfiguration();
     // Initialize variables
     $arr = array();
     $false = false;
     if (!is_dir($folder) && !is_dir($folder . '/')) {
         return $false;
     }
     try {
         $di = new DirectoryIterator($folder);
     } catch (Exception $e) {
         $this->setWarning('Unreadable directory ' . $folder);
         return $false;
     }
     if (!$di->valid()) {
         $this->setWarning('Unreadable directory ' . $folder);
         return $false;
     }
     if (!empty($position)) {
         $di->seek($position);
         if ($di->key() != $position) {
             $position = null;
             return $arr;
         }
     }
     $counter = 0;
     $maxCounter = $registry->get("engine.scan.large.{$threshold_key}_threshold", $threshold_default);
     while ($di->valid()) {
         if ($di->isDot()) {
             $di->next();
             continue;
         }
         if ($di->isDir() != $forFolders) {
             $di->next();
             continue;
         }
         $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
         $dir = $folder . $ds . $di->getFilename();
         $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir;
         if ($data) {
             $counter++;
             $arr[] = $data;
         }
         if ($counter == $maxCounter) {
             break;
         } else {
             $di->next();
         }
     }
     // Determine the new value for the position
     $di->next();
     if ($di->valid()) {
         $position = $di->key() - 1;
     } else {
         $position = null;
     }
     return $arr;
 }
Exemplo n.º 4
0
	private function get_site_path()
	{
		// FIX 1.1.0 $mosConfig_absolute_path may contain trailing slashes or backslashes incompatible with exclusion filters
		// FIX 1.2.2 Some hosts yield an empty string on realpath(JPATH_SITE)
		// FIX 2.2 On Windows, realpath might fail
		// FIX 2.4: Make an assumption (wild guess...)
		if( (JPATH_BASE == '/administrator') || (JPATH_ROOT == '') )
		{
			$this->setWarning("Your site's root is an empty string. I am trying a workaround.");
			$jpath_site_real = '/';
		}
		else
		{
			// Fix 2.4: Make sure that $jpath_site_real contains something even if realpath fails
			$jpath_site_real = @realpath(trim(JPATH_SITE));
			$jpath_site_real = ($jpath_site_real === false) ? trim(JPATH_SITE) : $jpath_site_real;
			$jpath_site_real = AEUtilFilesystem::TranslateWinPath($jpath_site_real);
		}

		if( $jpath_site_real == '' )
		{
			// The JPATH_SITE is resolved to an empty string; attempt a workaround

			// Windows hosts
			if(DIRECTORY_SEPARATOR == '\\')
			{
				if( (trim(JPATH_SITE) != '') && (trim(JPATH_SITE) != '\\') && (trim(JPATH_SITE) != '/'))
				{
					$this->setWarning("The site's root couldn't be normalized on a Windows host. Attempting workaround (filters might not work)");
					$jpath_site_real = JPATH_SITE; // Forcibly use the configured JPATH_SITE
				}
				else
				{
					$this->setWarning("The normalized path to your site's root seems to be an empty string; I will attempt a workaround (Windows host)");
					$jpath_site_real = '/'; // Start scanning from filesystem root (workaround mode)
				}
			}
			// *NIX hosts
			else
			{
				$this->setWarning("The normalized path to your site's root seems to be an empty string; I will attempt a workaround (*NIX host)");
				# Fix 2.1 Since JPATH_SITE is an empty string, shouldn't I begin scanning from the FS root, for crying out loud? What was I thinking putting JPATH_SITE there?
				$jpath_site_real = '/'; // Start scanning from filesystem root (workaround mode)
			}
		}

		// Fix 2.4.b1 : Add the trailing slash
		if( (substr($jpath_site_real,-1) != '/') && !empty($jpath_site_real) )
		{
			$jpath_site_real .= '/';
		}

		return $jpath_site_real;
	}
Exemplo n.º 5
0
 public function processPart($absolute_filename, $upload_as = null)
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $account = trim($config->get('engine.postproc.azure.account', ''));
     $key = trim($config->get('engine.postproc.azure.key', ''));
     $container = $config->get('engine.postproc.azure.container', 0);
     $directory = $config->get('volatile.postproc.directory', null);
     if (empty($directory)) {
         $directory = $config->get('engine.postproc.azure.directory', 0);
     }
     // Sanity checks
     if (empty($account)) {
         $this->setWarning('You have not set up your Windows Azure account name');
         return false;
     }
     if (empty($key)) {
         $this->setWarning('You have not set up your Windows Azure key');
         return false;
     }
     if (empty($container)) {
         $this->setWarning('You have not set up your Windows Azure container');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($directory)) {
         $directory = trim($directory);
         $directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
     } else {
         $directory = '';
     }
     // Parse tags
     $directory = AEUtilFilesystem::replace_archive_name_variables($directory);
     $config->set('volatile.postproc.directory', $directory);
     // Calculate relative remote filename
     $filename = basename($absolute_filename);
     if (!empty($directory) && $directory != '/') {
         $filename = $directory . '/' . $filename;
     }
     // Store the absolute remote path in the class property
     $this->remote_path = $filename;
     // Connect and send
     try {
         $blob = new AEUtilAzure(AEUtilAzureStorage::URL_CLOUD_BLOB, $account, $key);
         $policyNone = new AEUtilAzureNoRetryPolicy();
         $blob->setRetryPolicy($policyNone);
         $blob->putBlob($container, $filename, $absolute_filename);
     } catch (Exception $e) {
         $this->setWarning($e->getMessage());
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 private static function treatDirectory($directory)
 {
     $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
     $directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
     // Trim site root from beginning of directory
     if (substr($directory, 0, strlen($site_root)) == $site_root) {
         $directory = substr($directory, strlen($site_root));
         if (substr($directory, 0, 1) == '/') {
             $directory = substr($directory, 1);
         }
     }
     return $directory;
 }
Exemplo n.º 7
0
 /**
  * Unregister and delete a temporary file
  * @param $fileName The filename to unregister and delte
  * @param $removePrefix The prefix to remove
  */
 static function unregisterAndDeleteTempFile($fileName, $removePrefix = false)
 {
     $configuration = AEFactory::getConfiguration();
     if ($removePrefix) {
         $fileName = str_replace(AEUtilFilesystem::TranslateWinPath($configuration->get('akeeba.basic.output_directory')), '', $fileName);
         if (substr($fileName, 0, 1) == '/' || substr($fileName, 0, 1) == '\\') {
             $fileName = substr($fileName, 1);
         }
         if (substr($fileName, -1) == '/' || substr($fileName, -1) == '\\') {
             $fileName = substr($fileName, 0, -1);
         }
     }
     // Make sure this file is registered
     $configuration = AEFactory::getConfiguration();
     $tempFiles = $configuration->get('volatile.tempfiles', false);
     if ($tempFiles === false) {
         $tempFiles = array();
     } else {
         $tempFiles = @unserialize($tempFiles);
     }
     $found = false;
     if (!empty($tempFiles)) {
         $found = in_array($fileName, $tempFiles);
     }
     if (!$found) {
         return false;
     }
     $file = $configuration->get('akeeba.basic.output_directory') . '/' . $fileName;
     AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Removing temporary file {$fileName}");
     $platform = strtoupper(PHP_OS);
     if (substr($platform, 0, 6) == 'CYGWIN' || substr($platform, 0, 3) == 'WIN') {
         // On Windows we have to chwon() the file first to make it owned by Nobody
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Windows hack: chowning {$fileName}");
         @chown($file, 600);
     }
     $result = @self::nullifyAndDelete($file);
     // Make sure the file is removed before unregistering it
     if (!@file_exists($file)) {
         $aPos = array_search($fileName, $tempFiles);
         if ($aPos !== false) {
             unset($tempFiles[$aPos]);
             $configuration->set('volatile.tempfiles', serialize($tempFiles));
         }
     }
     return $result;
 }
Exemplo n.º 8
0
 private static function treatDirectory($directory)
 {
     // Get the site's root
     $configuration = AEFactory::getConfiguration();
     if ($configuration->get('akeeba.platform.override_root', 0)) {
         $root = $configuration->get('akeeba.platform.newroot', '[SITEROOT]');
         if (stristr($root, '[')) {
             $root = AEUtilFilesystem::translateStockDirs($root);
         }
         $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($root));
     } else {
         $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
     }
     $directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
     // Trim site root from beginning of directory
     if (substr($directory, 0, strlen($site_root)) == $site_root) {
         $directory = substr($directory, strlen($site_root));
         if (substr($directory, 0, 1) == '/') {
             $directory = substr($directory, 1);
         }
     }
     return $directory;
 }
Exemplo n.º 9
0
 public function processPart($absolute_filename, $upload_as = null)
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $accesskey = trim($config->get('engine.postproc.googlestorage.accesskey', ''));
     $secret = trim($config->get('engine.postproc.googlestorage.secretkey', ''));
     $usessl = $config->get('engine.postproc.googlestorage.usessl', 0) == 0 ? false : true;
     $bucket = $config->get('engine.postproc.googlestorage.bucket', '');
     $directory = $config->get('volatile.postproc.directory', null);
     $lowercase = $config->get('engine.postproc.googlestorage.lowercase', 1);
     if (empty($directory)) {
         $directory = $config->get('engine.postproc.googlestorage.directory', 0);
     }
     // Sanity checks
     if (empty($accesskey)) {
         $this->setError('You have not set up your Google Storage Access Key');
         return false;
     }
     if (empty($secret)) {
         $this->setError('You have not set up your Google Storage Secret Key');
         return false;
     }
     if (empty($bucket)) {
         $this->setError('You have not set up your Google Storage Bucket');
         return false;
     } else {
         // Remove any slashes from the bucket
         $bucket = str_replace('/', '', $bucket);
         if ($lowercase) {
             $bucket = strtolower($bucket);
         }
     }
     // Create an S3 instance with the required credentials
     $s3 = AEUtilAmazons3::getInstance($accesskey, $secret, $usessl);
     $s3->defaultHost = 'commondatastorage.googleapis.com';
     // If we are here, we'll have to start uploading the file. Let's prepare ourselves for that.
     // Fix the directory name, if required
     if (!empty($directory)) {
         $directory = trim($directory);
         $directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
     } else {
         $directory = '';
     }
     // Parse tags
     $directory = AEUtilFilesystem::replace_archive_name_variables($directory);
     $config->set('volatile.postproc.directory', $directory);
     // Calculate relative remote filename
     $filename = empty($upload_as) ? basename($absolute_filename) : $upload_as;
     if (!empty($directory) && $directory != '/') {
         $filename = $directory . '/' . $filename;
     }
     // Store the absolute remote path in the class property
     $this->remote_path = $filename;
     // Do we have to upload in one go or do a multipart upload instead?
     $filesize = @filesize($absolute_filename);
     AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Google Storage -- Uploading " . basename($absolute_filename));
     // Legacy single part uploads
     $result = $s3->putObject(AEUtilAmazons3::inputFile($absolute_filename, false), $bucket, $filename, AEUtilAmazons3::ACL_BUCKET_OWNER_FULL_CONTROL, array(), array());
     // Return the result
     $this->propagateFromObject($s3);
     return $result;
 }
 public static function &getFolders($folder, $fullpath = false)
 {
     // Initialize variables
     $arr = array();
     $false = false;
     if (!is_dir($folder) && !is_dir($folder . '/')) {
         return $false;
     }
     $handle = @opendir($folder);
     if ($handle === FALSE) {
         $handle = @opendir($folder . '/');
     }
     // If directory is not accessible, just return FALSE
     if ($handle === FALSE) {
         return $false;
     }
     $registry = AEFactory::getConfiguration();
     $dereferencesymlinks = $registry->get('engine.archiver.common.dereference_symlinks');
     while (($file = @readdir($handle)) !== false) {
         if ($file != '.' && $file != '..') {
             $dir = "{$folder}/{$file}";
             $isDir = @is_dir($dir);
             $isLink = @is_link($dir);
             if ($isDir) {
                 //if(!$dereferencesymlinks && $isLink) continue;
                 if ($fullpath) {
                     $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir;
                 } else {
                     $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($file) : $file;
                 }
                 if ($data) {
                     $arr[] = $data;
                 }
             }
         }
     }
     @closedir($handle);
     return $arr;
 }
Exemplo n.º 11
0
 /**
  * Get the paths for a specific section
  *
  * @param   string $section The section to get the path list for (engine, installer, gui, filter)
  *
  * @return  array
  */
 public static function getPaths($section = 'gui')
 {
     // Create the key if it's not already present
     if (!array_key_exists($section, static::$paths)) {
         static::$paths[$section] = array();
     }
     // Add the defaults if the list is empty
     if (empty(static::$paths[$section])) {
         switch ($section) {
             case 'engine':
                 static::$paths[$section] = array(AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/engines'), AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/plugins/engines'));
                 break;
             case 'installer':
                 static::$paths[$section] = array(AEUtilFilesystem::TranslateWinPath(AEPlatform::getInstance()->get_installer_images_path()));
                 break;
             case 'gui':
                 // Add core GUI definitions
                 static::$paths[$section] = array(AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/core'));
                 // Add additional core GUI definitions
                 if (AKEEBA_PRO) {
                     AEUtilFilesystem::TranslateWinPath(static::$paths[$section][] = AEFactory::getAkeebaRoot() . '/plugins/core');
                 }
                 // Add platform GUI definition files
                 $platform_paths = AEPlatform::getInstance()->getPlatformDirectories();
                 foreach ($platform_paths as $p) {
                     static::$paths[$section][] = AEUtilFilesystem::TranslateWinPath($p . '/config');
                 }
                 break;
             case 'filter':
                 static::$paths[$section] = array(AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/platform/filters/stack'), AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/filters/stack'), AEUtilFilesystem::TranslateWinPath(AEFactory::getAkeebaRoot() . '/plugins/filters/stack'));
                 $platform_paths = AEPlatform::getInstance()->getPlatformDirectories();
                 foreach ($platform_paths as $p) {
                     static::$paths[$section][] = AEUtilFilesystem::TranslateWinPath($p . '/filters/stack');
                 }
                 break;
         }
     }
     return static::$paths[$section];
 }
Exemplo n.º 12
0
 protected function _getSettings()
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $username = trim($config->get('engine.postproc.webdav.username', ''));
     $password = trim($config->get('engine.postproc.webdav.password', ''));
     $url = trim($config->get('engine.postproc.webdav.url', ''));
     $this->directory = $config->get('volatile.postproc.directory', null);
     if (empty($this->directory)) {
         $this->directory = $config->get('engine.postproc.webdav.directory', '');
     }
     // Sanity checks
     if (empty($username) || empty($password)) {
         $this->setError('You have not linked Akeeba Backup with your CloudMe account');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($this->directory)) {
         $this->directory = trim($this->directory);
         $this->directory = ltrim(AEUtilFilesystem::TranslateWinPath($this->directory), '/');
     } else {
         $this->directory = '';
     }
     // Parse tags
     $this->directory = AEUtilFilesystem::replace_archive_name_variables($this->directory);
     $config->set('volatile.postproc.directory', $this->directory);
     $settings = array('baseUri' => $url, 'userName' => $username, 'password' => $password);
     $this->webdav = new AEUtilDavclient($settings);
     $this->webdav->addTrustedCertificates(AKEEBA_CACERT_PEM);
     return true;
 }
 private function _getEngineSettings()
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $email = trim($config->get('engine.postproc.sugarsync.email', ''));
     $password = trim($config->get('engine.postproc.sugarsync.password', ''));
     $directory = $config->get('volatile.postproc.directory', null);
     if (empty($directory)) {
         $directory = $config->get('engine.postproc.sugarsync.directory', 0);
     }
     // Sanity checks
     if (empty($email)) {
         $this->setWarning('You have not set up your SugarSync email address');
         return false;
     }
     if (empty($password)) {
         $this->setWarning('You have not set up your SugarSync password');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($directory)) {
         $directory = trim($directory);
         $directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
     } else {
         $directory = '';
     }
     // Parse tags
     $directory = AEUtilFilesystem::replace_archive_name_variables($directory);
     $config->set('volatile.postproc.directory', $directory);
     return array('email' => $email, 'password' => $password, 'directory' => $directory);
 }
Exemplo n.º 14
0
 /**
  * Returns the relative and absolute path to the archive, if defined
  *
  * @param    string $relative The relative path
  * @param    string $absolute The absolute path
  */
 public static function get_archive_name(&$relative, &$absolute)
 {
     static $relative_path = null;
     static $absolute_path = null;
     if (is_null($relative_path) || is_null($absolute_path)) {
         $registry = AEFactory::getConfiguration();
         // Import volatile scripting keys to the registry
         AEUtilScripting::importScriptingToRegistry();
         // Determine the extension
         $force_extension = AEUtilScripting::getScriptingParameter('core.forceextension', null);
         if (is_null($force_extension)) {
             $archiver = AEFactory::getArchiverEngine();
             $extension = $archiver->getExtension();
         } else {
             $extension = $force_extension;
         }
         // Get the template name
         $templateName = $registry->get('akeeba.basic.archive_name');
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Archive template name: {$templateName}");
         // Parse all tags
         $templateName = self::replace_archive_name_variables($templateName);
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Expanded template name: {$templateName}");
         $ds = DIRECTORY_SEPARATOR;
         $relative_path = $templateName . $extension;
         $absolute_path = AEUtilFilesystem::TranslateWinPath($registry->get('akeeba.basic.output_directory') . $ds . $relative_path);
     }
     $relative = $relative_path;
     $absolute = $absolute_path;
 }
Exemplo n.º 15
0
Arquivo: smart.php Projeto: 01J/topm
 public function &getFolders($folder, &$position)
 {
     // Was the breakflag set BEFORE starting? -- This workaround is required due to PHP5 defaulting to assigning variables by reference
     $registry = AEFactory::getConfiguration();
     $breakflag_before_process = $registry->get('volatile.breakflag', false);
     // Reset break flag before continuing
     $breakflag = false;
     // Initialize variables
     $arr = array();
     $false = false;
     if (!is_dir($folder) && !is_dir($folder . '/')) {
         return $false;
     }
     $counter = 0;
     $registry = AEFactory::getConfiguration();
     $maxCounter = $registry->get('engine.scan.smart.large_dir_threshold', 100);
     $allowBreakflag = $registry->get('volatile.operation_counter', 0) != 0 && !$breakflag_before_process;
     if ($this->method == 'opendir') {
         $handle = @opendir($folder);
         /* If opening the directory doesn't work, try adding a trailing slash. This is useful in cases
          * like this: open_basedir=/home/user/www/ and the root is /home/user/www. Trying to scan
          * /home/user/www results in error, trying to scan /home/user/www/ succeeds. Duh!
          */
         if ($handle === false) {
             $handle = @opendir($folder . '/');
         }
         // If directory is not accessible, just return FALSE
         if ($handle === false) {
             $this->setWarning('Unreadable directory ' . $folder);
             return $false;
         }
     } else {
         $handle = dir($folder);
         if ($handle->handle === false) {
             $handle = dir($folder . '/');
             if ($handle->handle === false) {
                 $this->setWarning('Unreadable directory ' . $folder);
                 return $false;
             }
         }
     }
     while (($file = $this->method == 'opendir' ? @readdir($handle) : $handle->read()) !== false && !$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) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
             $dir = $folder . $ds . $file;
             $isDir = is_dir($dir);
             if ($isDir) {
                 $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir;
                 if ($data) {
                     $arr[] = $data;
                 }
             }
         }
         $counter++;
         if ($counter >= $maxCounter) {
             $breakflag = $allowBreakflag;
         }
     }
     $this->method == 'opendir' ? @closedir($handle) : $handle->close();
     // Save break flag status
     $registry->set('volatile.breakflag', $breakflag);
     return $arr;
 }
 protected function _getSettings()
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $username = trim($config->get('engine.postproc.idrivesync.username', ''));
     $password = trim($config->get('engine.postproc.idrivesync.password', ''));
     $pvtkey = trim($config->get('engine.postproc.idrivesync.pvtkey', ''));
     $this->directory = $config->get('volatile.postproc.directory', null);
     if (empty($this->directory)) {
         $this->directory = $config->get('engine.postproc.idrivesync.directory', '');
     }
     // Sanity checks
     if (empty($username) || empty($password)) {
         $this->setError('You have not set up the connection to your iDriveSync account');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($this->directory)) {
         $this->directory = trim($this->directory);
         $this->directory = ltrim(AEUtilFilesystem::TranslateWinPath($this->directory), '/');
     } else {
         $this->directory = '';
     }
     // Parse tags
     $this->directory = AEUtilFilesystem::replace_archive_name_variables($this->directory);
     $config->set('volatile.postproc.directory', $this->directory);
     $this->idrivesync = new AEUtilIdrivesync($username, $password, $pvtkey);
     return true;
 }
Exemplo n.º 17
0
 /**
  * Calculates the absolute path to the log file
  * @param	string	$tag	The backup run's tag
  * @return	string	The absolute path to the log file
  */
 public static function logName($tag = null)
 {
     if (empty($tag)) {
         $fileName = 'akeeba.log';
     } else {
         $fileName = "akeeba.{$tag}.log";
     }
     // Get output directory
     $registry =& AEFactory::getConfiguration();
     $outdir = $registry->get('akeeba.basic.output_directory');
     // Get log's file name
     return AEUtilFilesystem::TranslateWinPath($outdir . DIRECTORY_SEPARATOR . $fileName);
 }
 public function processPart($absolute_filename)
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $accesskey = trim($config->get('engine.postproc.s3.accesskey', ''));
     $secret = trim($config->get('engine.postproc.s3.secretkey', ''));
     $usessl = $config->get('engine.postproc.s3.usessl', 0) == 0 ? false : true;
     $bucket = $config->get('engine.postproc.s3.bucket', '');
     $legacy = $config->get('engine.postproc.s3.legacy', 0);
     $directory = $config->get('volatile.postproc.directory', null);
     $lowercase = $config->get('engine.postproc.s3.lowercase', 1);
     $rrs = $config->get('engine.postproc.s3.rrs', 1);
     $endpoint = $config->get('engine.postproc.s3.customendpoint', '');
     if (empty($directory)) {
         $directory = $config->get('engine.postproc.s3.directory', 0);
     }
     if (!empty($directory)) {
         $directory = str_replace('\\', '/', $directory);
         $directory = rtrim($directory, '/');
     }
     $endpoint = trim($endpoint);
     if (!empty($endpoint)) {
         $protoPos = strpos($endpoint, ':\\');
         if ($protoPos !== false) {
             $endpoint = substr($endpoint, $protoPos + 3);
         }
         $slashPos = strpos($endpoint, '/');
         if ($slashPos !== false) {
             $endpoint = substr($endpoint, $slashPos + 1);
         }
     }
     // Sanity checks
     if (empty($accesskey)) {
         $this->setError('You have not set up your Amazon S3 Access Key');
         return false;
     }
     if (empty($secret)) {
         $this->setError('You have not set up your Amazon S3 Secret Key');
         return false;
     }
     if (empty($bucket)) {
         $this->setError('You have not set up your Amazon S3 Bucket');
         return false;
     } else {
         // Remove any slashes from the bucket
         $bucket = str_replace('/', '', $bucket);
         if ($lowercase) {
             $bucket = strtolower($bucket);
         }
     }
     // Create an S3 instance with the required credentials
     $s3 = AEUtilAmazons3::getInstance($accesskey, $secret, $usessl);
     if (!empty($endpoint)) {
         $s3->defaultHost = $endpoint;
     }
     // Do not use multipart uploads when in an immediate post-processing step,
     // i.e. we are uploading a part right after its creation
     $immediateEnabled = $config->get('engine.postproc.common.after_part', 0);
     if ($immediateEnabled) {
         $noMultipart = true;
     } else {
         $noMultipart = false;
     }
     // Disable multipart uploads if the user requested it
     if ($legacy) {
         $noMultipart = true;
     }
     // Are we already processing a multipart upload?
     if (!empty($this->cache)) {
         // Continue processing an existing file and return
         $filename = $this->cache->filename;
         $absolute_filename = $this->cache->absolute_filename;
         $partNumber = $this->cache->partnumber;
         $uploadID = $this->cache->uploadid;
         $etags = $this->cache->etags;
         $partNumber++;
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "S3 -- Uploading part {$partNumber} of {$uploadID}");
         // DEBUG
         /**
         			$flatetags = implode(', ',$etags);
         			AEUtilLogger::WriteLog(_AE_LOG_DEBUG,"S3 -- Absolute/relative filenames: $absolute_filename ### $filename");
         			AEUtilLogger::WriteLog(_AE_LOG_DEBUG,"S3 -- Etags: ".$flatetags);
         			AEUtilLogger::WriteLog(_AE_LOG_DEBUG,"S3 -- Serialized cache: ".serialize($this->cache));
         			/**/
         $fileInfo = AEUtilAmazons3::inputFile($absolute_filename, false);
         $fileInfo['UploadID'] = $uploadID;
         $fileInfo['etags'] = $etags;
         $fileInfo['PartNumber'] = $partNumber;
         $input = $fileInfo;
         // So that it doesn't get overwritten
         $etag = AEUtilAmazons3::uploadMultipart($input, $bucket, $filename);
         if ($etag === 0) {
             // Done uploading, finalize
             $this->cache = null;
             AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "S3 -- Finalizing multipart upload of " . basename($absolute_filename) . " (part #{$partNumber})");
             $result = AEUtilAmazonS3::finalizeMultipart($fileInfo, $bucket, $filename);
             $this->propagateFromObject($s3);
             if ($result === false) {
                 // Finalization failed
                 return false;
             } else {
                 // Finalization successful
                 return true;
             }
         } elseif ($etag === false) {
             // Upload failed
             $this->propagateFromObject($s3);
             return false;
         } else {
             // Successfully uploaded part
             $this->propagateFromObject($s3);
             $fileInfo['etags'][] = $etag;
             // Update stored values
             $this->cache->partnumber = $partNumber;
             $this->cache->etags = $fileInfo['etags'];
             $this->cache->uploadid = $fileInfo['UploadID'];
             // Return -1 so that we get called again
             return -1;
         }
     }
     // If we are here, we'll have to start uploading the file. Let's prepare ourselves for that.
     // Fix the directory name, if required
     if (!empty($directory)) {
         $directory = trim($directory);
         $directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
     } else {
         $directory = '';
     }
     // Parse tags
     $directory = AEUtilFilesystem::replace_archive_name_variables($directory);
     $config->set('volatile.postproc.directory', $directory);
     // Calculate relative remote filename
     $filename = basename($absolute_filename);
     if (!empty($directory) && $directory != '/') {
         $filename = $directory . '/' . $filename;
     }
     // Store the absolute remote path in the class property
     $this->remote_path = $filename;
     // Do we have to upload in one go or do a multipart upload instead?
     $filesize = @filesize($absolute_filename);
     if ($filesize > 5242880 && !$noMultipart) {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "S3 -- Starting multipart upload of " . basename($absolute_filename));
         // Start multipart processing for files over 5Mb
         $fileInfo = AEUtilAmazons3::inputFile($absolute_filename, false);
         $input = $fileInfo;
         // Required to avoid the original array being tampered with
         $uploadID = AEUtilAmazonS3::startMultipart($input, $bucket, $filename, AEUtilAmazons3::ACL_BUCKET_OWNER_FULL_CONTROL, array(), array('x-amz-storage-class' => $rrs ? 'REDUCED_REDUNDANCY' : 'STANDARD'));
         // Necessary warnings propagation, no matter the outcome
         $this->propagateFromObject($s3);
         if ($uploadID === false) {
             // We couldn't start the upload. Bail out at once!
             return false;
         } else {
             // Save the information we need for multipart uploading
             $fileInfo['UploadID'] = $uploadID;
             $fileInfo['etags'] = array();
             $cache = array('absolute_filename' => $absolute_filename, 'filename' => $filename, 'partnumber' => 0, 'uploadid' => $uploadID, 'etags' => array());
             $this->cache = (object) $cache;
             // Return -1 so that we get called again, even on the same step
             return -1;
         }
     } else {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "S3 -- Legacy (single part) upload of " . basename($absolute_filename));
         // Legacy single part uploads
         $result = $s3->putObject(AEUtilAmazons3::inputFile($absolute_filename, false), $bucket, $filename, AEUtilAmazons3::ACL_BUCKET_OWNER_FULL_CONTROL, array(), array('x-amz-storage-class' => $rrs ? 'REDUCED_REDUNDANCY' : 'STANDARD'));
         // Return the result
         $this->propagateFromObject($s3);
         return $result;
     }
 }
Exemplo n.º 19
0
 /**
  * Steps the files scanning of the current directory
  *
  * @return  boolean  True on success, false on fatal error
  */
 private function scanFiles()
 {
     $engine = AEFactory::getScanEngine();
     list($root, $translated_root, $dir) = $this->getCleanDirectoryComponents();
     // Get a filters instance
     $filters = AEFactory::getFilters();
     if (is_null($this->getFiles_position)) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Scanning files of " . $this->current_directory);
         $this->processed_files_counter = 0;
     } else {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Resuming scanning files of " . $this->current_directory);
     }
     // Get file listing
     $fileList = $engine->getFiles($this->current_directory, $this->getFiles_position);
     // Error propagation
     $this->propagateFromObject($engine);
     // If the list contains "too many" items, please break this step!
     if (AEFactory::getConfiguration()->get('volatile.breakflag', false)) {
         // Log the step break decision, for debugging reasons
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Large directory " . $this->current_directory . " while scanning for files; I will resume scanning in next step.");
         // Return immediately, marking that we are not done yet!
         return true;
     }
     // Error control
     if ($this->getError()) {
         return false;
     }
     // Do I have an unreadable directory?
     if ($fileList === false) {
         $this->setWarning('Unreadable directory ' . $this->current_directory);
         $this->done_file_scanning = true;
     } else {
         if (is_array($fileList) && !empty($fileList)) {
             // Add required trailing slash to $dir
             if (!empty($dir)) {
                 $dir .= '/';
             }
             // Scan all directory entries
             foreach ($fileList as $fileName) {
                 $check = $dir . basename($fileName);
                 if (_AKEEBA_IS_WINDOWS) {
                     $check = AEUtilFilesystem::TranslateWinPath($check);
                 }
                 // Do I need this? $dir contains a path relative to the root anyway...
                 $check = ltrim(str_replace($translated_root, '', $check), '/');
                 $byFilter = '';
                 $skipThisFile = $filters->isFilteredExtended($check, $root, 'file', 'all', $byFilter);
                 if ($skipThisFile) {
                     AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping file {$fileName} (filter: {$byFilter})");
                 } else {
                     $this->file_list[] = $fileName;
                     $this->processed_files_counter++;
                     $this->progressAddFile();
                 }
             }
         }
     }
     // If the scanner engine nullified the next position we are done
     // scanning for files
     if (is_null($this->getFiles_position)) {
         $this->done_file_scanning = true;
     }
     // If the directory was genuinely empty we will have to add an empty
     // directory entry in the archive, otherwise this directory will never
     // be restored.
     if ($this->done_file_scanning && $this->processed_files_counter == 0) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Empty directory " . $this->current_directory);
         $archiver = AEFactory::getArchiverEngine();
         if ($this->current_directory != $this->remove_path_prefix) {
             $archiver->addFile($this->current_directory, $this->remove_path_prefix, $this->path_prefix);
         }
         // Error propagation
         $this->propagateFromObject($archiver);
         // Check for errors
         if ($this->getError()) {
             return false;
         }
         unset($archiver);
     }
     return true;
 }
Exemplo n.º 20
0
 /**
  * Update the cached live site's URL for the front-end backup feature (altbackup.php)
  * and the detected Joomla! libraries path
  */
 public function updateMagicParameters()
 {
     $component = JComponentHelper::getComponent('com_akeeba');
     if (is_object($component->params) && $component->params instanceof JRegistry) {
         $params = $component->params;
     } else {
         $params = new JParameter($component->params);
     }
     $params->set('siteurl', str_replace('/administrator', '', JURI::base()));
     if (defined('JPATH_LIBRARIES')) {
         $params->set('jlibrariesdir', AEUtilFilesystem::TranslateWinPath(JPATH_LIBRARIES));
     } elseif (defined("JPATH_PLATFORM")) {
         $params->set('jlibrariesdir', AEUtilFilesystem::TranslateWinPath(JPATH_PLATFORM));
     }
     $joomla16 = true;
     $params->set('jversion', '1.6');
     $db = JFactory::getDBO();
     $data = $params->toString();
     $sql = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('params') . ' = ' . $db->q($data))->where($db->qn('element') . ' = ' . $db->q('com_akeeba'))->where($db->qn('type') . ' = ' . $db->q('component'));
     $db->setQuery($sql);
     $db->execute();
 }
 private function isPlatformDirectory($path)
 {
     static $allPlatformPaths = array();
     if (empty($allPlatformPaths)) {
         $platform_paths = AEPlatform::getInstance()->getPlatformDirectories();
         foreach ($platform_paths as $p) {
             $allPlatformPaths[] = AEUtilFilesystem::TranslateWinPath($p . '/filters');
             $allPlatformPaths[] = AEUtilFilesystem::TranslateWinPath($p . '/filters/stack');
         }
     }
     $search = AEUtilFilesystem::TranslateWinPath($path);
     return in_array($search, $allPlatformPaths);
 }
Exemplo n.º 22
0
 /**
  * Scans a directory for files and directories, updating the directory_list and file_list
  * private fields
  *
  * @return bool True if more work has to be done, false if the dirextory stack is empty
  */
 private function scan_directory()
 {
     // Are we supposed to scan for more files?
     if ($this->done_scanning) {
         return true;
     }
     // Get the next directory to scan, if the folders and files of the last directory
     // have been scanned.
     if ($this->done_subdir_scanning && $this->done_file_scanning) {
         if (count($this->directory_list) == 0) {
             // No directories left to scan
             return false;
         } else {
             // Get and remove the last entry from the $directory_list array
             $this->current_directory = array_pop($this->directory_list);
             $this->setStep($this->current_directory);
             $this->done_subdir_scanning = false;
             $this->done_file_scanning = false;
             $this->processed_files_counter = 0;
         }
     }
     $engine = AEFactory::getScanEngine();
     // Break directory components
     if (AEFactory::getConfiguration()->get('akeeba.platform.override_root', 0)) {
         $siteroot = AEFactory::getConfiguration()->get('akeeba.platform.newroot', '[SITEROOT]');
     } else {
         $siteroot = '[SITEROOT]';
     }
     $root = $this->root;
     if ($this->root == $siteroot) {
         $translated_root = AEUtilFilesystem::translateStockDirs($siteroot, true);
     } else {
         $translated_root = $this->remove_path_prefix;
     }
     $dir = AEUtilFilesystem::TrimTrailingSlash($this->current_directory);
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $translated_root = AEUtilFilesystem::TranslateWinPath($translated_root);
         $dir = AEUtilFilesystem::TranslateWinPath($dir);
     }
     if (substr($dir, 0, strlen($translated_root)) == $translated_root) {
         $dir = substr($dir, strlen($translated_root));
     } elseif (in_array(substr($translated_root, -1), array('/', '\\'))) {
         $new_translated_root = rtrim($translated_root, '/\\');
         if (substr($dir, 0, strlen($new_translated_root)) == $new_translated_root) {
             $dir = substr($dir, strlen($new_translated_root));
         }
     }
     if (substr($dir, 0, 1) == '/') {
         $dir = substr($dir, 1);
     }
     // get a filters instance
     $filters = AEFactory::getFilters();
     // Scan subdirectories, if they have not yet been scanned.
     if (!$this->done_subdir_scanning) {
         // Apply DEF (directory exclusion filters)
         // Note: the !empty($dir) prevents the site's root from being filtered out
         if ($filters->isFiltered($dir, $root, 'dir', 'all') && !empty($dir)) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping directory " . $this->current_directory);
             $this->done_subdir_scanning = true;
             $this->done_file_scanning = true;
             return true;
         }
         // Apply Skip Contained Directories Filters
         if ($filters->isFiltered($dir, $root, 'dir', 'children')) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping subdirectories of directory " . $this->current_directory);
             $this->done_subdir_scanning = true;
         } else {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Scanning directories of " . $this->current_directory);
             // Get subdirectories
             $subdirs = $engine->getFolders($this->current_directory);
             // Error propagation
             $this->propagateFromObject($engine);
             // If the list contains "too many" items, please break this step!
             $registry = AEFactory::getConfiguration();
             if ($registry->get('volatile.breakflag', false)) {
                 // Log the step break decision, for debugging reasons
                 AEUtilLogger::WriteLog(_AE_LOG_INFO, "Large directory " . $this->current_directory . " while scanning for subdirectories; I will resume scanning in next step.");
                 // Return immediately, marking that we are not done yet!
                 return true;
             }
             // Error control
             if ($this->getError()) {
                 return false;
             }
             if (!empty($subdirs) && is_array($subdirs)) {
                 $registry = AEFactory::getConfiguration();
                 $dereferencesymlinks = $registry->get('engine.archiver.common.dereference_symlinks');
                 if ($dereferencesymlinks) {
                     // Treat symlinks to directories as actual directories
                     foreach ($subdirs as $subdir) {
                         $this->directory_list[] = $subdir;
                         $this->progressAddFolder();
                     }
                 } else {
                     // Treat symlinks to directories as simple symlink files (ONLY WORKS WITH CERTAIN ARCHIVERS!)
                     foreach ($subdirs as $subdir) {
                         if (is_link($subdir)) {
                             // Symlink detected; apply file filters to it
                             if (empty($dir)) {
                                 $dirSlash = $dir;
                             } else {
                                 $dirSlash = $dir . '/';
                             }
                             $check = $dir . basename($subdir);
                             if (_AKEEBA_IS_WINDOWS) {
                                 $check = AEUtilFilesystem::TranslateWinPath($check);
                             }
                             // Do I need this? $dir contains a path relative to the root anyway...
                             $check = ltrim(str_replace($translated_root, '', $check), '/');
                             if ($filters->isFiltered($check, $root, 'file', 'all')) {
                                 AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping directory symlink " . $check);
                             } else {
                                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Adding symlink to folder as file: ' . $check);
                                 $this->file_list[] = $subdir;
                                 $this->progressAddFile();
                             }
                         } else {
                             $this->directory_list[] = $subdir;
                             $this->progressAddFolder();
                         }
                     }
                 }
             }
         }
         $this->done_subdir_scanning = 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 done_file_scanning (saves a tiny amount of CPU time)
     // Apply Skipfiles
     if ($filters->isFiltered($dir, $root, 'dir', 'content')) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping files of directory " . $this->current_directory);
         // Try to find and include .htaccess and index.htm(l) files
         // # Fix 2.4: Do not add DIRECTORY_SEPARATOR if we are on the site's root and it's an empty string
         $ds = $this->current_directory == '' || $this->current_directory == '/' ? '' : DIRECTORY_SEPARATOR;
         $checkForTheseFiles = array($this->current_directory . $ds . '.htaccess', $this->current_directory . $ds . 'index.html', $this->current_directory . $ds . 'index.htm', $this->current_directory . $ds . 'robots.txt');
         $this->processed_files_counter = 0;
         foreach ($checkForTheseFiles as $fileName) {
             if (@file_exists($fileName)) {
                 // Fix 3.3 - We have to also put them through other filters, ahem!
                 if (!$filters->isFiltered($fileName, $root, 'file', 'all')) {
                     $this->file_list[] = $fileName;
                     $this->processed_files_counter++;
                 }
             }
         }
         $this->done_file_scanning = true;
     } else {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Scanning files of " . $this->current_directory);
         // Get file listing
         $fileList = $engine->getFiles($this->current_directory);
         // Error propagation
         $this->propagateFromObject($engine);
         // If the list contains "too many" items, please break this step!
         $registry = AEFactory::getConfiguration();
         if ($registry->get('volatile.breakflag', false)) {
             // Log the step break decision, for debugging reasons
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Large directory " . $this->current_directory . " while scanning for files; I will resume scanning in next step.");
             // Return immediately, marking that we are not done yet!
             return true;
         }
         // Error control
         if ($this->getError()) {
             return false;
         }
         $this->processed_files_counter = 0;
         if ($fileList === false) {
             // A non-browsable directory; however, it seems that I never get FALSE reported here?!
             $this->setWarning('Unreadable directory ' . $this->current_directory);
         } else {
             if (is_array($fileList) && !empty($fileList)) {
                 // Add required trailing slash to $dir
                 if (!empty($dir)) {
                     $dir .= '/';
                 }
                 // Scan all directory entries
                 foreach ($fileList as $fileName) {
                     $check = $dir . basename($fileName);
                     if (_AKEEBA_IS_WINDOWS) {
                         $check = AEUtilFilesystem::TranslateWinPath($check);
                     }
                     // Do I need this? $dir contains a path relative to the root anyway...
                     $check = ltrim(str_replace($translated_root, '', $check), '/');
                     $skipThisFile = $filters->isFiltered($check, $root, 'file', 'all');
                     if ($skipThisFile) {
                         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping file {$fileName}");
                     } else {
                         $this->file_list[] = $fileName;
                         $this->processed_files_counter++;
                         $this->progressAddFile();
                     }
                 }
                 // end foreach
             }
             // end if
         }
         // end filelist not false
         $this->done_file_scanning = true;
     }
     // Check to see if there were no contents of this directory added to our search list
     if ($this->processed_files_counter == 0) {
         $archiver = AEFactory::getArchiverEngine();
         if ($this->current_directory != $this->remove_path_prefix) {
             $archiver->addFile($this->current_directory, $this->remove_path_prefix, $this->path_prefix);
         }
         // Error propagation
         $this->propagateFromObject($archiver);
         if ($this->getError()) {
             return false;
         }
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Empty directory " . $this->current_directory);
         unset($archiver);
         $this->done_scanning = false;
         // Because it was an empty dir $file_list is empty and we have to scan for more files
     } else {
         // Next up, add the files to the archive!
         $this->done_scanning = true;
     }
     // We're done listing the contents of this directory
     unset($engine);
     return true;
 }
Exemplo n.º 23
0
 protected function _getSettings()
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $token = trim($config->get('engine.postproc.dropbox.token', ''));
     $token_secret = trim($config->get('engine.postproc.dropbox.token_secret', ''));
     $token_uid = trim($config->get('engine.postproc.dropbox.uid', ''));
     $this->chunked = $config->get('engine.postproc.dropbox.chunk_upoad', true);
     $this->chunk_size = $config->get('engine.postproc.dropbox.chunk_upoad_size', 4);
     $this->directory = $config->get('volatile.postproc.directory', null);
     if (empty($this->directory)) {
         $this->directory = $config->get('engine.postproc.dropbox.directory', '');
     }
     // Sanity checks
     if (empty($token) || empty($token_secret) || empty($token_uid)) {
         $this->setError('You have not linked Akeeba Backup with your DropBox account');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($this->directory)) {
         $this->directory = trim($this->directory);
         $this->directory = ltrim(AEUtilFilesystem::TranslateWinPath($this->directory), '/');
     } else {
         $this->directory = '';
     }
     // Parse tags
     $this->directory = AEUtilFilesystem::replace_archive_name_variables($this->directory);
     $config->set('volatile.postproc.directory', $this->directory);
     $token = (object) array('oauth_token_secret' => $token_secret, 'oauth_token' => $token, 'uid' => $token_uid);
     $keys = $this->_getKeys();
     $this->dropbox = new AEUtilDropbox();
     $this->dropbox->setAppKeys($keys);
     $this->dropbox->setToken($token);
     return true;
 }
Exemplo n.º 24
0
 /**
  * Returns a listing of contained directories and files, as well as their
  * exclusion status
  * @param string $root The root directory
  * @param string $node The subdirectory to scan
  * @return array
  */
 private function &get_listing($root, $node)
 {
     // Initialize the absolute directory root
     $directory = substr($root, 0);
     // Replace stock directory tags, like [SITEROOT]
     $stock_dirs = AEPlatform::getInstance()->get_stock_directories();
     if (!empty($stock_dirs)) {
         foreach ($stock_dirs as $key => $replacement) {
             $directory = str_replace($key, $replacement, $directory);
         }
     }
     $directory = AEUtilFilesystem::TranslateWinPath($directory);
     // Clean and add the node
     $node = AEUtilFilesystem::TranslateWinPath($node);
     if ($node == '/') {
         $node = '';
     }
     // Just a dir. sep. is treated as no dir at all
     // Trim leading and trailing slashes
     $node = trim($node, '/');
     // Add node to directory
     if (!empty($node)) {
         $directory .= '/' . $node;
     }
     // Add any required trailing slash to the node to be used below
     if (!empty($node)) {
         $node .= '/';
     }
     // Get a filters instance
     $filters = AEFactory::getFilters();
     // Detect PHP 5.2.5or earlier, with broken json_decode implementation
     $phpversion = PHP_VERSION;
     $vparts = explode('.', $phpversion);
     if ($vparts[0] == 5 && $vparts[1] == 2 && $vparts[2] <= 5 || $vparts[0] == 5 && $vparts[1] == 1) {
         define('AKEEBA_SAFE_JSON', false);
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php';
     } else {
         $test = '-test-';
         $tj = json_encode($test);
         $test = json_decode($test);
         if ($test == '-test-') {
             define('AKEEBA_SAFE_JSON', true);
         } else {
             define('AKEEBA_SAFE_JSON', false);
             require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php';
         }
     }
     // Get a listing of folders and process it
     $folders = AEUtilScanner::getFolders($directory);
     asort($folders);
     $folders_out = array();
     if (!empty($folders)) {
         foreach ($folders as $folder) {
             $folder = AEUtilFilesystem::TranslateWinPath($folder);
             // Filter out files whose names result to an empty JSON representation
             if (AKEEBA_SAFE_JSON) {
                 $json_folder = json_encode($folder);
                 $folder = json_decode($json_folder);
             } else {
                 $jsonobj = new Akeeba_Services_JSON(0);
                 $json_folder = $jsonobj->encode($folder);
                 $folder = $jsonobj->decode($json_folder);
             }
             if (empty($folder)) {
                 continue;
             }
             $test = $node . $folder;
             $status = array();
             // Check dir/all filter (exclude)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'all', $byFilter);
             $status['directories'] = !$result ? 0 : ($byFilter == 'directories' ? 1 : 2);
             // Check dir/content filter (skip_files)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'content', $byFilter);
             $status['skipfiles'] = !$result ? 0 : ($byFilter == 'skipfiles' ? 1 : 2);
             // Check dir/children filter (skip_dirs)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'children', $byFilter);
             $status['skipdirs'] = !$result ? 0 : ($byFilter == 'skipdirs' ? 1 : 2);
             // Add to output array
             $folders_out[$folder] = $status;
         }
     }
     unset($folders);
     $folders = $folders_out;
     // Get a listing of files and process it
     $files = AEUtilScanner::getFiles($directory);
     asort($files);
     $files_out = array();
     if (!empty($files)) {
         foreach ($files as $file) {
             // Filter out files whose names result to an empty JSON representation
             if (AKEEBA_SAFE_JSON) {
                 $json_file = json_encode($file);
                 $file = json_decode($json_file);
             } else {
                 $jsonobj = new Akeeba_Services_JSON(0);
                 $json_file = $jsonobj->encode($file);
                 $file = $jsonobj->decode($json_file);
             }
             if (empty($file)) {
                 continue;
             }
             $test = $node . $file;
             $status = array();
             // Check file/all filter (exclude)
             $result = $filters->isFilteredExtended($test, $root, 'file', 'all', $byFilter);
             $status['files'] = !$result ? 0 : ($byFilter == 'files' ? 1 : 2);
             $status['size'] = @filesize($directory . '/' . $file);
             // Add to output array
             $files_out[$file] = $status;
         }
     }
     unset($files);
     $files = $files_out;
     // Return a compiled array
     $retarray = array('folders' => $folders, 'files' => $files);
     return $retarray;
     /* Return array format
      * [array] :
      * 		'folders' [array] :
      * 			(folder_name) => [array]:
      *				'directories'	=> 0|1|2
      *				'skipfiles'		=> 0|1|2
      *				'skipdirs'		=> 0|1|2
      *		'files' [array] :
      *			(file_name) => [array]:
      *				'files'			=> 0|1|2
      *
      * Legend:
      * 0 -> Not excluded
      * 1 -> Excluded by the direct filter
      * 2 -> Excluded by another filter (regex, api, an unknown plugin filter...)
      */
 }
Exemplo n.º 25
0
 /**
  * Removes the $p_remove_dir from $p_filename, while prepending it with $p_add_dir.
  * Largely based on code from the pclZip library.
  *
  * @param   string  $p_filename    The absolute file name to treat
  * @param   string  $p_remove_dir  The path to remove
  * @param   string  $p_add_dir     The path to prefix the treated file name with
  *
  * @return  string  The treated file name
  */
 private final function _addRemovePaths($p_filename, $p_remove_dir, $p_add_dir)
 {
     $p_filename = AEUtilFilesystem::TranslateWinPath($p_filename);
     $p_remove_dir = $p_remove_dir == '' ? '' : AEUtilFilesystem::TranslateWinPath($p_remove_dir);
     //should fix corrupt backups, fix by nicholas
     if (!($p_remove_dir == "")) {
         if (substr($p_remove_dir, -1) != '/') {
             $p_remove_dir .= "/";
         }
         if (substr($p_filename, 0, 2) == "./" || substr($p_remove_dir, 0, 2) == "./") {
             if (substr($p_filename, 0, 2) == "./" && substr($p_remove_dir, 0, 2) != "./") {
                 $p_remove_dir = "./" . $p_remove_dir;
             }
             if (substr($p_filename, 0, 2) != "./" && substr($p_remove_dir, 0, 2) == "./") {
                 $p_remove_dir = substr($p_remove_dir, 2);
             }
         }
         $v_compare = $this->_PathInclusion($p_remove_dir, $p_filename);
         if ($v_compare > 0) {
             if ($v_compare == 2) {
                 $v_stored_filename = "";
             } else {
                 $v_stored_filename = substr($p_filename, function_exists('mb_strlen') ? mb_strlen($p_remove_dir, '8bit') : strlen($p_remove_dir));
             }
         }
     } else {
         $v_stored_filename = $p_filename;
     }
     if (!($p_add_dir == "")) {
         if (substr($p_add_dir, -1) == "/") {
             $v_stored_filename = $p_add_dir . $v_stored_filename;
         } else {
             $v_stored_filename = $p_add_dir . "/" . $v_stored_filename;
         }
     }
     return $v_stored_filename;
 }
Exemplo n.º 26
0
 /**
  * Q203 - MED  - Default output directory in use
  *
  * @return bool
  */
 private static function q203()
 {
     $stock_dirs = AEPlatform::getInstance()->get_stock_directories();
     $registry =& AEFactory::getConfiguration();
     $outdir = $registry->get('akeeba.basic.output_directory');
     foreach ($stock_dirs as $macro => $replacement) {
         $outdir = str_replace($macro, $replacement, $outdir);
     }
     $default = $stock_dirs['[DEFAULT_OUTPUT]'];
     $outdir = AEUtilFilesystem::TranslateWinPath($outdir);
     $default = AEUtilFilesystem::TranslateWinPath($default);
     return $outdir == $default;
 }
Exemplo n.º 27
0
 /**
  * Update the cached live site's URL for the front-end backup feature (altbackup.php)
  * and the detected Joomla! libraries path
  */
 public function updateMagicParameters()
 {
     $component =& JComponentHelper::getComponent('com_akeeba');
     if (is_object($component->params) && $component->params instanceof JRegistry) {
         $params = $component->params;
     } else {
         $params = new JParameter($component->params);
     }
     $params->set('siteurl', str_replace('/administrator', '', JURI::base()));
     if (defined('JPATH_LIBRARIES')) {
         $params->set('jlibrariesdir', AEUtilFilesystem::TranslateWinPath(JPATH_LIBRARIES));
     } elseif (defined("JPATH_PLATFORM")) {
         $params->set('jlibrariesdir', AEUtilFilesystem::TranslateWinPath(JPATH_PLATFORM));
     }
     if (AKEEBA_JVERSION == '16') {
         // Joomla! 1.6
         $joomla16 = true;
         $params->set('jversion', '1.6');
     } else {
         // Joomla! 1.5
         $joomla16 = false;
         $params->set('jversion', '1.5');
     }
     $db =& JFactory::getDBO();
     $data = $params->toString();
     if ($joomla16) {
         // Joomla! 1.6
         $sql = 'UPDATE `#__extensions` SET `params` = ' . $db->Quote($data) . ' WHERE ' . "`element` = 'com_akeeba' AND `type` = 'component'";
     } else {
         // Joomla! 1.5
         $sql = 'UPDATE `#__components` SET `params` = ' . $db->Quote($data) . ' WHERE ' . "`option` = 'com_akeeba' AND `parent` = 0 AND `menuid` = 0";
     }
     $db->setQuery($sql);
     $db->query();
 }
 /**
  * Calculates the absolute path to the log file. Instead of using the path coming from
  * Akeeba Backup config, we will always use Joomla Tmp dir
  *
  * @param   string  $tag    The backup run's tag
  *
  * @return  string    The absolute path to the log file
  */
 public static function logName($tag = null)
 {
     if (empty($tag)) {
         $fileName = 'akeeba.log';
     } else {
         $fileName = "akeeba.{$tag}.log";
     }
     // Get log's file name
     return AEUtilFilesystem::TranslateWinPath(JPATH_ROOT . '/tmp' . DIRECTORY_SEPARATOR . $fileName);
 }
Exemplo n.º 29
0
 private function _getEngineSettings()
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $username = trim($config->get('engine.postproc.cloudfiles.username', ''));
     $apikey = trim($config->get('engine.postproc.cloudfiles.apikey', ''));
     $container = $config->get('engine.postproc.cloudfiles.container', 0);
     $directory = $config->get('volatile.postproc.directory', null);
     $isUKAccount = $config->get('engine.postproc.cloudfiles.isukaccount', 0);
     if (empty($directory)) {
         $directory = $config->get('engine.postproc.cloudfiles.directory', 0);
     }
     // Sanity checks
     if (empty($username)) {
         $this->setWarning('You have not set up your CloudFiles user name');
         return false;
     }
     if (empty($apikey)) {
         $this->setWarning('You have not set up your CoudFiles API Key');
         return false;
     }
     if (empty($container)) {
         $this->setWarning('You have not set up your CloudFiles container');
         return false;
     }
     // Fix the directory name, if required
     if (!empty($directory)) {
         $directory = trim($directory);
         $directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
     } else {
         $directory = '';
     }
     // Parse tags
     $directory = AEUtilFilesystem::replace_archive_name_variables($directory);
     $config->set('volatile.postproc.directory', $directory);
     return array('username' => $username, 'apikey' => $apikey, 'container' => $container, 'directory' => $directory, 'isUKAccount' => $isUKAccount);
 }