Beispiel #1
0
	protected function _run()
	{
		// Run in a loop until we run out of time, or breakflag is set
		$registry =& AEFactory::getConfiguration();
		$timer =& AEFactory::getTimer();

		while( ($timer->getTimeLeft() > 0) && (!$registry->get('volatile.breakflag', false)) )
		{
			if ($this->getState() == 'postrun') {
				AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__." :: Already finished");
				$this->setStep("-");
				$this->setSubstep("");
				break;
			}
			else
			{
				if($this->done_scanning)
				{
					$this->pack_files();
					if($this->getError()) return false;
				}
				else
				{
					$result = $this->scan_directory();
					if($this->getError()) return false;
					if(!$result)
					{
						// We have finished with our directory list. Hmm... Do we have extra directories?
						if(count($this->root_definitions) > 0)
						{
							AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "More off-site directories detected");
							$registry =& AEFactory::getConfiguration();
							$dir_definition = array_shift($this->root_definitions);

							$this->remove_path_prefix = $dir_definition[0]; // Remove absolute path to directory when storing the file
							if(is_null($dir_definition[1]))
							{
								$this->path_prefix = ''; // No added path for main site
							}
							else
							{
								$this->path_prefix = $registry->get('akeeba.advanced.virtual_folder').'/'.$dir_definition[1];
							}

							$this->done_scanning = false; // Make sure we process this file list!
							$this->root = $dir_definition[0];

							// Translate the root into an absolute path
							$stock_dirs = AEPlatform::get_stock_directories();
							$absolute_dir = substr($this->root,0);
							if(!empty($stock_dirs))
							{
								foreach($stock_dirs as $key => $replacement)
								{
									$absolute_dir = str_replace($key, $replacement, $absolute_dir);
								}
							}
							$this->directory_list[] = $absolute_dir;
							$this->remove_path_prefix = $absolute_dir;

							$registry->set('volatile.filesystem.current_root', $absolute_dir);
							
							$this->total_files = 0;
							$this->done_files = 0;
							$this->total_folders = 0;
							$this->done_folders = 0;
							
							AEUtilLogger::WriteLog(_AE_LOG_INFO, "Including new off-site directory to ".$dir_definition[1]);
						}
						else
						// Nope, we are completely done!
						$this->setState('postrun');
					} // if not result
				} // if not doneScanning
			} // if not postrun
		} // while
		return true;
	}
Beispiel #2
0
	/**
	 * Q203 - MED  - Default output directory in use
	 *
	 * @return bool
	 */
	private static function q203()
	{
		$stock_dirs = AEPlatform::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;
	}
Beispiel #3
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::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.DS.'helpers'.DS.'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.DS.'helpers'.DS.'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.DS.$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...)
		 */
	}
Beispiel #4
0
	static function translateStockDirs( $folder, $translate_win_dirs = false, $trim_trailing_slash = false )
	{
		static $stock_dirs;
		if(empty($stock_dirs))
		{
			$stock_dirs = AEPlatform::get_stock_directories();
		}

		$temp = $folder;
		foreach($stock_dirs as $find => $replace)
		{
			$temp = str_replace($find, $replace, $temp);
		}
		if($translate_win_dirs)
		{
			$temp = self::TranslateWinPath( $temp );
		}
		if( $trim_trailing_slash )
		{
			$temp = self::TrimTrailingSlash( $temp );
		}
		return $temp;
	}
Beispiel #5
0
	function display()
	{
		jimport('joomla.filesystem.folder');
		jimport('joomla.filesystem.path');

		// Get the folder to browse
		$folder = JRequest::getString('folder', '');
		$processfolder = JRequest::getInt('processfolder', 0);

		if(empty($folder))
		{
			$folder = '';
			$folder_raw = '';
			$isFolderThere = false;
			$isInRoot = false;
			$isOpenbasedirRestricted = false;
		}
		else
		{
			$stock_dirs = AEPlatform::get_stock_directories();
			arsort($stock_dirs);

			if($processfolder == 1)
			{
				foreach($stock_dirs as $find => $replace)
				{
					$folder = str_replace($find, $replace, $folder);
				}
			}

			// Normalise name, but only if realpath() really, REALLY works...
			$old_folder = $folder;
			$folder = @realpath($folder);
			if($folder === false) $folder = $old_folder;

			if(AEUtilFilesystem::folderExists($folder))
			{
				$isFolderThere = true;
			}
			else
			{
				$isFolderThere = false;
			}
			JRequest::setVar('folder', $folder);

			// Check if it's a subdirectory of the site's root
			$isInRoot = (strpos($folder, JPATH_SITE) === 0);

			// Check open_basedir restrictions
			$isOpenbasedirRestricted = AEUtilQuirks::checkOpenBasedirs($folder);

			// -- Get the meta form of the directory name, if applicable
			$folder_raw = $folder;
			foreach($stock_dirs as $replace => $find)
			{
				$folder_raw = str_replace($find, $replace, $folder_raw);
			}

		}

		// Writable check and contents listing if it's in site root and not restricted
		if($isFolderThere && !$isOpenbasedirRestricted)
		{
			// Get writability status
			$isWritable = is_writable($folder);

			// Get contained folders
			$subfolders = JFolder::folders($folder);
		}
		else
		{
			if($isFolderThere && !$isOpenbasedirRestricted)
			{
				$isWritable = is_writable($folder);
			}
			else
			{
				$isWritable = false;
			}

			$subfolders = array();
		}

		// Get parent directory
		$pathparts = explode(DS, $folder);
		if(is_array($pathparts))
		{
			$path = '';
			foreach($pathparts as $part)
			{
				$path .= empty($path) ? $part : DS.$part;
				if(empty($part)) {
					if( DS != '\\' ) $path = DS;
					$part = DS;
				}
				$crumb['label'] = $part;
				$crumb['folder'] = $path;
				$breadcrumbs[]=$crumb;
			}

			$junk = array_pop($pathparts);
			$parent = implode(DS, $pathparts);
		}
		else
		{
			// Can't identify parent dir, use ourselves.
			$parent = $folder;
			$breadcrumbs = array();
		}

		$this->assign('folder',					$folder);
		$this->assign('folder_raw',				$folder_raw);
		$this->assign('parent',					$parent);
		$this->assign('exists',					$isFolderThere);
		$this->assign('inRoot',					$isInRoot);
		$this->assign('openbasedirRestricted',	$isOpenbasedirRestricted);
		$this->assign('writable',				$isWritable);
		$this->assign('subfolders',				$subfolders);
		$this->assign('breadcrumbs',			$breadcrumbs);

		parent::display();
	}
Beispiel #6
0
	/**
	 * Set a registry value
	 * @param	string	$regpath 	Registry Path (e.g. global.directory.temporary)
	 * @param 	mixed	$value		Value of entry
	 * @param	bool	$process_special_vars Optional. If true (default), it processes special variables, e.g. [SITEROOT] in folder names
	 * @return 	mixed	Value of old value or boolean false if operation failed
	 */
	public function set($regpath, $value, $process_special_vars = true)
	{
		// Cache the platform-specific stock directories
		static $stock_directories = array();
		if(empty($stock_directories))
		{
			$stock_directories = AEPlatform::get_stock_directories();
		}

		// Explode the registry path into an array
		$nodes = explode('.', $regpath);

		// Get the namespace
		$count = count($nodes);

		if ($count < 2) {
			$namespace = $this->defaultNameSpace;
		} else {
			$namespace = array_shift($nodes);
			$count--;
		}

		if (!isset($this->registry[$namespace])) {
			$this->makeNameSpace($namespace);
		}

		$ns = $this->registry[$namespace]['data'];

		$pathNodes = $count - 1;

		if ($pathNodes < 0) {
			$pathNodes = 0;
		}

		for ($i = 0; $i < $pathNodes; $i ++)
		{
			// If any node along the registry path does not exist, create it
			if (!isset($ns->$nodes[$i])) {
				$ns->$nodes[$i] = new stdClass();
			}
			$ns = $ns->$nodes[$i];
		}

		// Set the new values
		if(is_string($value))
		{
			if(substr($value,0,10) == '###json###')
			{
				$value = json_decode(substr($value,10));
			}
		}

		// Post-process certain directory-containing variables
		if( $process_special_vars && in_array($regpath, $this->directory_containing_keys) )
		{
			if(!empty($stock_directories))
			{
				$data = $value;
				foreach($stock_directories as $tag => $content)
				{
					$data = str_replace($tag, $content, $data);
				}
				$ns->$nodes[$i] = $data;
				return $ns->$nodes[$i];
			}
		}

		// This is executed if any of the previous two if's is false

		$ns->$nodes[$i] = $value;
		return $ns->$nodes[$i];
	}