• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/main.php
  • Класс: CAllMain
  • Вызов: CAllMain::SetFileAccessPermission
public function SetFileAccessPermission($path, $arPermissions, $bOverWrite=true)
{
	global $CACHE_MANAGER;

	CMain::InitPathVars($site, $path);
	$DOC_ROOT = CSite::GetSiteDocRoot($site);

	$path = rtrim($path, "/");
	if($path == '')
		$path = "/";

	if(($p = bxstrrpos($path, "/")) !== false)
	{
		$path_file = mb_substr($path, $p + 1);
		$path_dir = mb_substr($path, 0, $p);
	}
	else
		return false;

	if($path_file == "" && $path_dir == "")
		$path_file = "/";

	$PERM = array();

	$io = CBXVirtualIo::GetInstance();
	if ($io->FileExists($DOC_ROOT.$path_dir."/.access.php"))
	{
		$fTmp = $io->GetFile($DOC_ROOT.$path_dir."/.access.php");
		//include replaced with eval in order to honor of ZendServer
		eval("?>".$fTmp->GetContents());
	}

	$FILE_PERM = $PERM[$path_file];
	if(!is_array($FILE_PERM))
		$FILE_PERM = array();

	if(!$bOverWrite && !empty($FILE_PERM))
		return true;

	$bDiff = false;

	$str="$perm)
	{
		if($perm <> '')
			$str .= "$PERM["".EscapePHPString($path_file).""]["".EscapePHPString($group).""]="".EscapePHPString($perm)."";n";

		if(!$bDiff)
		{
			//compatibility with group id
			$curr_perm = $FILE_PERM[$group];
			if(!isset($curr_perm) && preg_match('/^G[0-9]+$/', $group))
				$curr_perm = $FILE_PERM[mb_substr($group, 1)];

			if($curr_perm != $perm)
				$bDiff = true;
		}
	}

	foreach($PERM as $file=>$arPerm)
	{
		if(strval($file) !== $path_file)
			foreach($arPerm as $group=>$perm)
				$str .= "$PERM["".EscapePHPString($file).""]["".EscapePHPString($group).""]="".EscapePHPString($perm)."";n";
	}

	if(!$bDiff)
	{
		foreach($FILE_PERM as $group=>$perm)
		{
			//compatibility with group id
			$new_perm = $arPermissions[$group];
			if(!isset($new_perm) && preg_match('/^G[0-9]+$/', $group))
				$new_perm = $arPermissions[mb_substr($group, 1)];

			if($new_perm != $perm)
			{
				$bDiff = true;
				break;
			}
		}
	}

	$str .= "?".">";

	$this->SaveFileContent($DOC_ROOT.$path_dir."/.access.php", $str);
	$CACHE_MANAGER->CleanDir("menu");
	CBitrixComponent::clearComponentCache("bitrix:menu");
	unset($this->FILE_PERMISSION_CACHE[$site."|".$path_dir."/.access.php"]);

	if($bDiff)
	{
		foreach(GetModuleEvents("main", "OnChangePermissions", true) as $arEvent)
			ExecuteModuleEventEx($arEvent, array(array($site, $path), $arPermissions, $FILE_PERM));

		if(COption::GetOptionString("main", "event_log_file_access", "N") === "Y")
			CEventLog::Log("SECURITY", "FILE_PERMISSION_CHANGED", "main", "[".$site."] ".$path, print_r($FILE_PERM, true)." => ".print_r($arPermissions, true));
	}
	return true;
}