%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.217.193.85
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/io/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/io/path.php
<?php
namespace Bitrix\Main\IO;

use Bitrix\Main;
use Bitrix\Main\Text;

/**
 *
 */
class Path
{
	const DIRECTORY_SEPARATOR = '/';
	const DIRECTORY_SEPARATOR_ALT = '\\';
	const PATH_SEPARATOR = PATH_SEPARATOR;

	const INVALID_FILENAME_CHARS = "\\/:*?\"'<>|~#&;";

	//the pattern should be quoted, "|" is allowed below as a delimiter
	const INVALID_FILENAME_BYTES = "\xE2\x80\xAE"; //Right-to-Left Override Unicode Character

	protected static $physicalEncoding = "";
	protected static $logicalEncoding = "";

	protected static $directoryIndex = null;

	public static function normalize($path)
	{
		if (!is_string($path) || ($path == ""))
			return null;

		//slashes doesn't matter for Windows
		static $pattern = null, $tailPattern;
		if (!$pattern)
		{
			if(strncasecmp(PHP_OS, "WIN", 3) == 0)
			{
				//windows
				$pattern = "'[\\\\/]+'";
				$tailPattern = "\0.\\/+ ";
			}
			else
			{
				//unix
				$pattern = "'[/]+'";
				$tailPattern = "\0/";
			}
		}
		$pathTmp = preg_replace($pattern, "/", $path);

		if (mb_strpos($pathTmp, "\0") !== false)
			throw new InvalidPathException($path);

		if (preg_match("#(^|/)(\\.|\\.\\.)(/|\$)#", $pathTmp))
		{
			$arPathTmp = explode('/', $pathTmp);
			$arPathStack = array();
			foreach ($arPathTmp as $i => $pathPart)
			{
				if ($pathPart === '.')
					continue;

				if ($pathPart === "..")
				{
					if (array_pop($arPathStack) === null)
						throw new InvalidPathException($path);
				}
				else
				{
					array_push($arPathStack, $pathPart);
				}
			}
			$pathTmp = implode("/", $arPathStack);
		}

		$pathTmp = rtrim($pathTmp, $tailPattern);

		if (mb_substr($path, 0, 1) === "/" && mb_substr($pathTmp, 0, 1) !== "/")
			$pathTmp = "/".$pathTmp;

		if ($pathTmp === '')
			$pathTmp = "/";

		return $pathTmp;
	}

	public static function getExtension($path)
	{
		$path = self::getName($path);
		if ($path != '')
		{
			$pos = Text\UtfSafeString::getLastPosition($path, '.');
			if ($pos !== false)
				return mb_substr($path, $pos + 1);
		}
		return '';
	}

	public static function getName($path)
	{
		//$path = self::normalize($path);

		$p = Text\UtfSafeString::getLastPosition($path, self::DIRECTORY_SEPARATOR);
		if ($p !== false)
			return mb_substr($path, $p + 1);

		return $path;
	}

	public static function getDirectory($path)
	{
		return mb_substr($path, 0, -mb_strlen(self::getName($path)) - 1);
	}

	public static function convertLogicalToPhysical($path)
	{
		if (self::$physicalEncoding == "")
			self::$physicalEncoding = self::getPhysicalEncoding();

		if (self::$logicalEncoding == "")
			self::$logicalEncoding = self::getLogicalEncoding();

		if (self::$physicalEncoding == self::$logicalEncoding)
			return $path;

		return Text\Encoding::convertEncoding($path, self::$logicalEncoding, self::$physicalEncoding);
	}

	public static function convertPhysicalToLogical($path)
	{
		if (self::$physicalEncoding == "")
			self::$physicalEncoding = self::getPhysicalEncoding();

		if (self::$logicalEncoding == "")
			self::$logicalEncoding = self::getLogicalEncoding();

		if (self::$physicalEncoding == self::$logicalEncoding)
			return $path;

		return Text\Encoding::convertEncoding($path, self::$physicalEncoding, self::$logicalEncoding);
	}

	public static function convertLogicalToUri($path)
	{
		if (self::$logicalEncoding == "")
			self::$logicalEncoding = self::getLogicalEncoding();

		if (self::$directoryIndex == null)
			self::$directoryIndex = self::getDirectoryIndexArray();

		if (isset(self::$directoryIndex[self::getName($path)]))
			$path = self::getDirectory($path)."/";

		if ('utf-8' !== self::$logicalEncoding)
			$path = Text\Encoding::convertEncoding($path, self::$logicalEncoding, 'utf-8');

		return implode('/', array_map("rawurlencode", explode('/', $path)));
	}

	public static function convertPhysicalToUri($path)
	{
		if (self::$physicalEncoding == "")
			self::$physicalEncoding = self::getPhysicalEncoding();

		if (self::$directoryIndex == null)
			self::$directoryIndex = self::getDirectoryIndexArray();

		if (isset(self::$directoryIndex[self::getName($path)]))
			$path = self::getDirectory($path)."/";

		if ('utf-8' !== self::$physicalEncoding)
			$path = Text\Encoding::convertEncoding($path, self::$physicalEncoding, 'utf-8');

		return implode('/', array_map("rawurlencode", explode('/', $path)));
	}

	public static function convertUriToPhysical($path)
	{
		if (self::$physicalEncoding == "")
			self::$physicalEncoding = self::getPhysicalEncoding();

		if (self::$directoryIndex == null)
			self::$directoryIndex = self::getDirectoryIndexArray();

		$path = implode('/', array_map("rawurldecode", explode('/', $path)));

		if ('utf-8' !== self::$physicalEncoding)
			$path = Text\Encoding::convertEncoding($path, 'utf-8', self::$physicalEncoding);

		return $path;
	}

	protected static function getLogicalEncoding()
	{
		if (defined('BX_UTF'))
			$logicalEncoding = "utf-8";
		elseif (defined("SITE_CHARSET") && (SITE_CHARSET <> ''))
			$logicalEncoding = SITE_CHARSET;
		elseif (defined("LANG_CHARSET") && (LANG_CHARSET <> ''))
			$logicalEncoding = LANG_CHARSET;
		elseif (defined("BX_DEFAULT_CHARSET"))
			$logicalEncoding = BX_DEFAULT_CHARSET;
		else
			$logicalEncoding = "windows-1251";

		return mb_strtolower($logicalEncoding);
	}

	protected static function getPhysicalEncoding()
	{
		$physicalEncoding = defined("BX_FILE_SYSTEM_ENCODING") ? BX_FILE_SYSTEM_ENCODING : "";
		if ($physicalEncoding == "")
		{
			if (mb_strtoupper(mb_substr(PHP_OS, 0, 3)) === "WIN")
				$physicalEncoding = "windows-1251";
			else
				$physicalEncoding = "utf-8";
		}
		return mb_strtolower($physicalEncoding);
	}

	public static function combine()
	{
		$numArgs = func_num_args();
		if ($numArgs <= 0)
			return "";

		$arParts = array();
		for ($i = 0; $i < $numArgs; $i++)
		{
			$arg = func_get_arg($i);
			if (is_array($arg))
			{
				if (empty($arg))
					continue;

				foreach ($arg as $v)
				{
					if (!is_string($v) || $v == "")
						continue;
					$arParts[] = $v;
				}
			}
			elseif (is_string($arg))
			{
				if ($arg == "")
					continue;

				$arParts[] = $arg;
			}
		}

		$result = "";
		foreach ($arParts as $part)
		{
			if ($result !== "")
				$result .= self::DIRECTORY_SEPARATOR;
			$result .= $part;
		}

		$result = self::normalize($result);

		return $result;
	}

	public static function convertRelativeToAbsolute($relativePath)
	{
		if (!is_string($relativePath))
			throw new Main\ArgumentTypeException("relativePath", "string");
		if ($relativePath == "")
			throw new Main\ArgumentNullException("relativePath");

		return self::combine($_SERVER["DOCUMENT_ROOT"], $relativePath);
	}

	public static function convertSiteRelativeToAbsolute($relativePath, $site = null)
	{
		if (!is_string($relativePath) || $relativePath == "")
			$site = SITE_ID;

		$basePath = Main\SiteTable::getDocumentRoot($site);

		return self::combine($basePath, $relativePath);
	}

	protected static function validateCommon($path)
	{
		if (!is_string($path))
		{
			return false;
		}

		if (trim($path) == "")
		{
			return false;
		}

		if (mb_strpos($path, "\0") !== false)
		{
			return false;
		}

		if(preg_match("#(".self::INVALID_FILENAME_BYTES.")#", $path))
		{
			return false;
		}

		return true;
	}

	public static function validate($path)
	{
		if(!static::validateCommon($path))
		{
			return false;
		}

		return (preg_match("#^([a-z]:)?/([^\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS, "#")."]+/?)*$#isD", $path) > 0);
	}

	public static function validateFilename($filename)
	{
		if(!static::validateCommon($filename))
		{
			return false;
		}

		return (preg_match("#^[^\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS, "#")."]+$#isD", $filename) > 0);
	}

	/**
	 * @param string $filename
	 * @param callable $callback
	 * @return string
	 */
	public static function replaceInvalidFilename($filename, $callback)
	{
		return preg_replace_callback(
			"#([\x01-\x1F".preg_quote(self::INVALID_FILENAME_CHARS, "#")."]|".self::INVALID_FILENAME_BYTES.")#",
			$callback,
			$filename
		);
	}

	/**
	 * @param string $filename
	 * @return string
	 */
	public static function randomizeInvalidFilename($filename)
	{
		return static::replaceInvalidFilename($filename,
			function()
			{
				return chr(rand(97, 122));
			}
		);
	}

	public static function isAbsolute($path)
	{
		return (mb_substr($path, 0, 1) === "/") || preg_match("#^[a-z]:/#i", $path);
	}

	protected static function getDirectoryIndexArray()
	{
		static $directoryIndexDefault = array("index.php" => 1, "index.html" => 1, "index.htm" => 1, "index.phtml" => 1, "default.html" => 1, "index.php3" => 1);

		$directoryIndex = Main\Config\Configuration::getValue("directory_index");
		if ($directoryIndex !== null)
			return $directoryIndex;

		return $directoryIndexDefault;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit