if (!file_exists($_GET['delete'])) {
        $error = ERR_FILE_NOT_AVAILABLE;
    } elseif (!isUnderRoot($_GET['delete'])) {
        $error = ERR_FOLDER_PATH_NOT_ALLOWED;
    } else {
        include_once CLASS_FILE;
        $file = new file();
        if (is_dir($_GET['delete']) && isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, getBaseName($_GET['delete'])) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, getBaseName($_GET['delete']))) {
            $file->delete(addTrailingSlash(backslashToSlash($_GET['delete'])));
        } elseif (is_file($_GET['delete']) && isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, getBaseName($_GET['delete'])) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, getBaseName($_GET['delete']))) {
            $file->delete($_GET['delete']);
        }
    }
} else {
    if (!isset($_POST['selectedDoc']) || !is_array($_POST['selectedDoc']) || sizeof($_POST['selectedDoc']) < 1) {
        $error = ERR_NOT_FILE_SELECTED;
    } else {
        include_once CLASS_FILE;
        $file = new file();
        foreach ($_POST['selectedDoc'] as $doc) {
            if (file_exists($doc) && isUnderRoot($doc)) {
                if (is_dir($doc) && isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, $doc) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, $doc)) {
                    $file->delete(addTrailingSlash(backslashToSlash($doc)));
                } elseif (is_file($doc) && isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, $doc) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, $doc)) {
                    $file->delete($doc);
                }
            }
        }
    }
}
echo "{error:'" . $error . "'}";
Ejemplo n.º 2
0
         /**
          * check if such document is allowed to shown on the list
          *
          * @param string $path the path to the document
          * @return boolean
          */
         function isListingDocument($path)
         {
         	$file = basename($path);
         	if(CONFIG_SYS_PATTERN_FORMAT == 'list')
         	{// comma delimited vague file/folder name



			    		
      			if(is_dir($path))
      			{
 				$includeDir = trimlrm(CONFIG_SYS_INC_DIR_PATTERN);
				$excludeDir = trimlrm(CONFIG_SYS_EXC_DIR_PATTERN);     				
				$found_includeDir = strpos($includeDir, $file);
				$found_excludeDir = strpos($excludeDir, $file);      				
      				if((!CONFIG_SYS_INC_DIR_PATTERN || (!($found_includeDir === FALSE))) && (!CONFIG_SYS_EXC_DIR_PATTERN || (($found_excludeDir === FALSE))))
      				{
      					return true;
      				}else 
      				{
      					return false;
      				}
      			}elseif(is_file($path))
      			{
				$includeFile = trimlrm(CONFIG_SYS_INC_FILE_PATTERN);
				$excludeFile = trimlrm(CONFIG_SYS_EXC_FILE_PATTERN);            				
				$found_includeFile = strpos($includeFile, $file);
				$found_excludeFile = strpos($excludeFile, $file);	      				
      				if((!CONFIG_SYS_INC_FILE_PATTERN || (!($found_includeFile === FALSE))) && (!CONFIG_SYS_EXC_FILE_PATTERN ||   (($found_excludeFile === FALSE))))
      				{
      					return true;
      				}else 
      				{
      					return false;
      				}
      			}
         	}elseif(CONFIG_SYS_PATTERN_FORMAT == 'csv')
         	{//comma delimited file/folder name
         		
         		if(is_dir($path))
         		{
         		
	 				$includeDir = trimlrm(CONFIG_SYS_INC_DIR_PATTERN);
					$excludeDir = trimlrm(CONFIG_SYS_EXC_DIR_PATTERN);
					        
					if(!empty($includeDir) && !empty($excludeDir))
					{
						
						$validDir = explode(',', $includeDir);
						
						$invalidDir = explode(",", $excludeDir);

						if(array_search(basename($path), $validDir) !== false && array_search(basename($path), $invalidDir) === false)
						{
							return true;
						}else 
						{
							return false;
						}
					}elseif(!empty($includeDir))
					{
						$validDir = explode(',', $includeDir);
						if(array_search(basename($path), $validDir) !== false)
						{
							return true;
						}else 
						{
							return false;
						}
						
					}elseif(!empty($excludeFile))
					{
						$invalidDir = explode(",", $excludeDir);
						if(array_search(basename($path), $invalidDir) === false)
						{
							return true;
						}else 
						{
							return false;
						}
					}
					return true;
					
         		}elseif(is_file($path))
         		{
				$includeFile = trimlrm(CONFIG_SYS_INC_FILE_PATTERN);
				$excludeFile = trimlrm(CONFIG_SYS_EXC_FILE_PATTERN);   
				if(!empty($includeFile) && !empty($excludeFile))
				{
					$validFile = explode(',', $includeFile);
					$invalidFile = explode(',', $excludeFile);
					if(array_search(basename($path), $validFile) !== false && array_search(basename($path), $invalidFile) === false)
					{
						return true;
					}else 
					{
						return false;
					}
				}elseif(!empty($includeFile))
				{
					$validFile = explode(',', $includeFile);
					if(array_search(basename($path), $validFile) !== false)
					{
						return true;
					}else 
					{
						return false;
					}
				}elseif(!empty($excludeFile))
				{
					$invalidFile = explode(',', $excludeFile);
					if(array_search(basename($path), $invalidFile) === false)
					{
						return true;
					}else 
					{
						return false;
					}
				}
				return true;
         		}
         	}
         	else 
         	{//regular expression
	          	if(is_dir($path) )
	         	{
	         		if(isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, $path) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, $path))
	         		{
	         			 return true;	
	         		}else 
	         		{
	         			return false;
	         		}
	         	
	         	}elseif(is_file($path))
	         	{
	         		if(isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, $path) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, $path)  )
	         		{
	         			return true;
	         		}else 
	         		{
	         			return false;
	         		}
	         	}
         	}
         	return false;

         }