CanDoOperation('fileman_admin_files') || $USER->CanDoOperation('fileman_edit_existent_files'))) { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/include.php"); IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/admin/fileman_html_edit.php"); IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/public/file_edit.php"); $obJSPopup = new CJSPopup("lang=".urlencode($_GET["lang"] ?? '')."&site=".urlencode($_GET["site"] ?? '')."&back_url=".urlencode($_GET["back_url"] ?? '')."&path=".urlencode($_GET["path"] ?? '')."&name=".urlencode($_GET["name"] ?? ''), array("SUFFIX"=>(isset($_REQUEST['subdialog']) && $_REQUEST['subdialog'] == 'Y'? 'editor':''))); $strWarning = ""; $site_template = false; $rsSiteTemplates = CSite::GetTemplateList($site ?? ''); while($arSiteTemplate = $rsSiteTemplates->Fetch()) { if($arSiteTemplate["CONDITION"] == '') { $site_template = $arSiteTemplate["TEMPLATE"]; break; } } $io = CBXVirtualIo::GetInstance(); $bVarsFromForm = false; // if 'true' - we will get content and variables from form, if 'false' - from saved file $bSessIDRefresh = false; // флаг, указывающий, нужно ли обновлять ид сессии на клиенте $editor_name = ($_REQUEST['editor_name'] ?? 'filesrc_pub'); if (!empty($filename) && ($mess = CFileMan::CheckFileName($filename)) !== true) { $filename2 = $filename; $filename = ''; $strWarning = $mess; $bVarsFromForm = true; } $path = urldecode($path ?? ''); $path = $io->CombinePath("/", $path); $site = CFileMan::__CheckSite($site); if(!$site) $site = CSite::GetSiteByFullPath($_SERVER["DOCUMENT_ROOT"].$path); $DOC_ROOT = CSite::GetSiteDocRoot($site); $abs_path = $DOC_ROOT.$path; if(GetFileType($abs_path) == "IMAGE") $strWarning = GetMessage("PUBLIC_EDIT_FILE_IMAGE_ERROR"); $arPath = Array($site, $path); if(!$io->FileExists($abs_path) && !$io->DirectoryExists($abs_path)) { $p = mb_strrpos($path, "/"); if($p!==false) { $new = "Y"; $filename = mb_substr($path, $p + 1); $path = mb_substr($path, 0, $p); } } $relPath = $io->ExtractPathFromPath($path); $NEW_ROW_CNT = 1; $arParsedPath = CFileMan::ParsePath(Array($site, $path), true, false, "", false); $isScriptExt = in_array(CFileman::GetFileExtension($path), CFileMan::GetScriptFileExt()); if (CAutoSave::Allowed()) $AUTOSAVE = new CAutoSave(); $imgName = $filename; if ($filename == '') { $imgName = $io->ExtractNameFromPath($path); } $imgName = GetFileNameWithoutExtension($imgName).'-img'; //Check access to file if( ( $new <> '' && !( $USER->CanDoOperation('fileman_admin_files') && $USER->CanDoFileOperation('fm_create_new_file', $arPath) ) ) || ( $new == '' && !( $USER->CanDoOperation('fileman_edit_existent_files') && $USER->CanDoFileOperation('fm_edit_existent_file',$arPath) ) ) ) { $strWarning = GetMessage("ACCESS_DENIED"); } elseif($strWarning == '') { if(!$USER->IsAdmin() && mb_substr(CFileman::GetFileName($abs_path), 0, 1) == ".") { $strWarning = GetMessage("FILEMAN_FILEEDIT_BAD_FNAME")." "; $bEdit = false; $bVarsFromForm = true; $path = $io->CombinePath("/", $arParsedPath["PREV"]); $arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y"); $abs_path = $DOC_ROOT.$path; } elseif($new == 'Y') { $bEdit = false; } else { if(!$io->FileExists($abs_path)) $strWarning = GetMessage("FILEMAN_FILEEDIT_FOLDER_EXISTS")." "; else $bEdit = true; } $limit_php_access = ($USER->CanDoFileOperation('fm_lpa', $arPath) && !$USER->CanDoOperation('edit_php')); if ($limit_php_access) { //OFP - 'original full path' used for restorin' php code fragments in limit_php_access mode if (!isset(\Bitrix\Main\Application::getInstance()->getSession()['arOFP'])) \Bitrix\Main\Application::getInstance()->getSession()['arOFP'] = Array(); if(isset($_POST['ofp_id'])) { $ofp_id = $_POST['ofp_id']; } else { $ofp_id = mb_substr(md5($site.'|'.$path), 0, 8); if(!isset(\Bitrix\Main\Application::getInstance()->getSession()['arOFP'][$ofp_id])) \Bitrix\Main\Application::getInstance()->getSession()['arOFP'][$ofp_id] = $path; } } } if($strWarning == '') { if($bEdit) { $oFile = $io->GetFile($abs_path); $filesrc_tmp = $oFile->GetContents(); } else { $arTemplates = CFileman::GetFileTemplates(LANGUAGE_ID, array($site_template)); if(!empty($template)) { foreach ($arTemplates as $arTemplate) { if($arTemplate["file"] == $template) { $filesrc_tmp = CFileman::GetTemplateContent($arTemplate["file"],LANGUAGE_ID, array($site_template)); break; } } } else { $filesrc_tmp = CFileman::GetTemplateContent($arTemplates[0]["file"], LANGUAGE_ID, array($site_template)); } } if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_REQUEST['save']) && $_REQUEST['save'] == 'Y') { $filesrc = $filesrc_pub; if(!check_bitrix_sessid()) { $strWarning = GetMessage("FILEMAN_SESSION_EXPIRED"); $bVarsFromForm = true; $bSessIDRefresh = true; } elseif((CFileman::IsPHP($filesrc) || $isScriptExt) && !($USER->CanDoOperation('edit_php') || $limit_php_access)) //check rights { $strWarning = GetMessage("FILEMAN_FILEEDIT_CHANGE"); $bVarsFromForm = true; } else { if($limit_php_access) { // ofp - original full path :) $ofp = \Bitrix\Main\Application::getInstance()->getSession()['arOFP'][$ofp_id]; $ofp = $io->CombinePath("/", $ofp); $abs_ofp = $DOC_ROOT.$ofp; $f = $io->GetFile($abs_ofp); $old_filesrc_tmp = $f->GetContents(); $old_res = CFileman::ParseFileContent($old_filesrc_tmp, true); $old_filesrc = $old_res["CONTENT"]; $filesrc = LPA::Process($filesrc, $old_filesrc); } $res = CFileman::ParseFileContent($filesrc_tmp, true); $prolog = CFileman::SetTitle($res["PROLOG"], $title); for ($i = 0; $i<=$maxind; $i++) { if(trim($_POST["CODE_".$i]) <> '') { if($_POST["CODE_".$i] != $_POST["H_CODE_".$i]) { $prolog = CFileman::SetProperty($prolog, trim($_POST["H_CODE_".$i]), ""); $prolog = CFileman::SetProperty($prolog, trim($_POST["CODE_".$i]), trim($_POST["VALUE_".$i])); } else $prolog = CFileman::SetProperty($prolog, trim($_POST["CODE_".$i]), trim($_POST["VALUE_".$i])); } else $prolog = CFileman::SetProperty($prolog, trim($_POST["H_CODE_".$i]), ""); } $epilog = $res["EPILOG"]; $filesrc_for_save = $prolog.$filesrc.$epilog; } if($strWarning == '') { if (!CFileMan::CheckOnAllowedComponents($filesrc_for_save)) { $str_err = $APPLICATION->GetException(); if($str_err && ($err = $str_err ->GetString())) $strWarning .= $err; $bVarsFromForm = true; } } if($strWarning == '') { // File was created just a second ago if (isset($_REQUEST["edit_new_file_undo"]) && $_REQUEST["edit_new_file_undo"] <> '') { CUndo::ShowUndoMessage($_REQUEST["edit_new_file_undo"]); } else { $f = $io->GetFile($abs_path); $arUndoParams = array( 'module' => 'fileman', 'undoType' => 'edit_file', 'undoHandler' => 'CFileman::UndoEditFile', 'arContent' => array( 'absPath' => $abs_path, 'content' => $f->GetContents() ) ); } if(!$APPLICATION->SaveFileContent($abs_path, $filesrc_for_save)) { if($str_err = $APPLICATION->GetException()) { if ($err = $str_err ->GetString()) $strWarning = $err; $bVarsFromForm = true; $path = $io->CombinePath("/", $arParsedPath["PREV"]); $arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y"); $abs_path = $DOC_ROOT.$path; } if (empty($strWarning)) $strWarning = GetMessage("FILEMAN_FILE_SAVE_ERROR")." "; } else { if(COption::GetOptionString("fileman", "log_page", "Y")=="Y") { $res_log['path'] = mb_substr($path, 1); CEventLog::Log( "content", "PAGE_EDIT", "main", "", serialize($res_log), $_REQUEST["site"] ?? '' ); } if (CAutoSave::Allowed()) $AUTOSAVE->Reset(); } } if($strWarning == '') { if ($arUndoParams) CUndo::ShowUndoMessage(CUndo::Add($arUndoParams)); ?>