N°2985 Security hardening (#140)

Thanks @bruno-ds  for the review !
This commit is contained in:
Pierre Goiffon
2020-05-13 10:04:40 +02:00
committed by GitHub
parent 3c9318d56a
commit 834297e675
3 changed files with 140 additions and 91 deletions

View File

@@ -2049,6 +2049,39 @@ class utils
return ITOP_REVISION === 'svn';
}
/**
* helper to test if a string starts with another
* @param $haystack
* @param $needle
*
* @return bool
*/
final public static function StartsWith($haystack, $needle)
{
if (strlen($needle) > strlen($haystack))
{
return false;
}
return substr_compare($haystack, $needle, 0, strlen($needle)) === 0;
}
/**
* helper to test if a string ends with another
* @param $haystack
* @param $needle
*
* @return bool
*/
final public static function EndsWith($haystack, $needle) {
if (strlen($needle) > strlen($haystack))
{
return false;
}
return substr_compare($haystack, $needle, -strlen($needle)) === 0;
}
/**
* @param string $sPath for example '/var/www/html/itop/data/backups/manual/itop_27-2019-10-03_15_35.tar.gz'
* @param string $sBasePath for example '/var/www/html/itop/data/'