BxDolIO.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolIO extends BxDol
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public static function isRealOwner()
  16. {
  17. if(defined('BX_DOL_CRON_EXECUTE'))
  18. trigger_error('Function can\'t be called under cron', E_USER_ERROR);
  19. $sName = time() . rand(0, 999999999);
  20. $sFilePath = BX_DIRECTORY_PATH_TMP . $sName . '.txt';
  21. if(!$rHandler = fopen($sFilePath, 'w'))
  22. return false;
  23. if(!fwrite($rHandler, $sName))
  24. return false;
  25. fclose($rHandler);
  26. $bResult = fileowner(BX_DIRECTORY_PATH_INC . 'utils.inc.php') === fileowner($sFilePath);
  27. @unlink($sFilePath);
  28. return $bResult;
  29. }
  30. public static function isExecutable($sFile)
  31. {
  32. clearstatcache();
  33. $aPathInfo = pathinfo(__FILE__);
  34. $sFile = $aPathInfo['dirname'] . '/../../' . $sFile;
  35. return (is_file($sFile) && is_executable($sFile));
  36. }
  37. public static function isWritable($sFile)
  38. {
  39. clearstatcache();
  40. $aPathInfo = pathinfo(__FILE__);
  41. $sFile = $aPathInfo['dirname'] . '/../../' . $sFile;
  42. return is_readable($sFile) && is_writable($sFile);
  43. }
  44. public static function getPermissions($sFileName)
  45. {
  46. $sPath = isset($GLOBALS['logged']['admin']) && $GLOBALS['logged']['admin'] ? BX_DIRECTORY_PATH_ROOT : '../';
  47. clearstatcache();
  48. $hPerms = @fileperms($sPath . $sFileName);
  49. if($hPerms == false) return false;
  50. $sRet = substr( decoct( $hPerms ), -3 );
  51. return $sRet;
  52. }
  53. }
  54. /** @} */