From f0e0c73e9befa7fba45f27f25911beeeac68dae0 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 17 Oct 2019 15:51:41 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02517=20-=20Supportability=20-=20file=20S?= =?UTF-8?q?ystem=20integrity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/utils.inc.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/application/utils.inc.php b/application/utils.inc.php index 8b189f90e4..ba710563c9 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -2126,4 +2126,43 @@ class utils return $sFileRealPath; } + + /** + * Returns the local path relative to the iTop installation of an existing file + * Dir separator is changed to '/' for consistency among the different OS + * + * @param string $sPath absolute path + * + * @return false|string + */ + final public static function LocalPath($sPath) + { + $sRootPath = realpath(APPROOT); + $sFullPath = realpath($sPath); + if (($sFullPath === false) || !self::StartsWith($sFullPath, $sRootPath)) + { + return false; + } + $sLocalPath = substr($sFullPath, strlen($sRootPath.DIRECTORY_SEPARATOR)); + $sLocalPath = str_replace(DIRECTORY_SEPARATOR, '/', $sLocalPath); + return $sLocalPath; + } + + /** + * return absolute path of an existing file localed in iTop + * + * @param string $sPath relative iTop path + * + * @return string|false absolute path + */ + public static function AbsolutePath($sPath) + { + $sRootPath = realpath(APPROOT); + $sFullPath = realpath($sRootPath.DIRECTORY_SEPARATOR.$sPath); + if (($sFullPath === false) || !self::StartsWith($sFullPath, $sRootPath)) + { + return false; + } + return $sFullPath; + } }