PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/fileman/admin/fileman_server_access.php

https://gitlab.com/alexprowars/bitrix
PHP | 346 lines | 290 code | 56 blank | 0 comment | 42 complexity | 53fa3bb1956f1ba1d8514b62b38b3a1b MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/prolog.php");
  4. if (!$USER->CanDoOperation('fileman_admin_folders'))
  5. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  6. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/include.php");
  7. include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/classes/general/fileman_utils.php");
  8. IncludeModuleLangFile(__FILE__);
  9. $site = CFileMan::__CheckSite($site);
  10. $documentRoot = CSite::GetSiteDocRoot($site);
  11. $io = CBXVirtualIo::GetInstance();
  12. $path = $io->CombinePath("/", $path);
  13. $addUrl = 'lang='.LANGUAGE_ID.($logical == "Y"?'&logical=Y':'');
  14. $arPath = Array($site, $path);
  15. $strNotice = "";
  16. $strWarning = "";
  17. $abs_path = $documentRoot.$path;
  18. $arFiles = Array();
  19. $bSearch = isset($_REQUEST['search']) && $_REQUEST['search'] == 'Y';
  20. $searchSess = preg_replace("/[^a-z0-9]/i", "", $_REQUEST['ssess']);
  21. if (CFileMan::IsWindows())
  22. $strWarning .= GetMessage("FILEMAN_SA_WINDOWS_WARN")."\n";
  23. if (count($files) > 0)
  24. {
  25. for($i = 0; $i < count($files); $i++)
  26. {
  27. if(!$USER->CanDoFileOperation('fm_edit_permission', Array($site, $path."/".$files[$i])))
  28. $strWarning .= GetMessage("FILEMAN_ACCESS_TO_DENIED")." \"".$files[$i]."\".\n";
  29. elseif($files[$i] != '.')
  30. $arFiles[] = $files[$i];
  31. }
  32. }
  33. else
  34. {
  35. if ($bSearch)
  36. {
  37. $searchRes = CFilemanSearch::GetSearchResult($searchSess);
  38. for($i = 0, $l = count($searchRes); $i < $l; $i++)
  39. $arFiles[] = $searchRes[$i]['path'];
  40. }
  41. else
  42. {
  43. $arD = array();
  44. $arF = array();
  45. CFileMan::GetDirList(Array($site, $path), $arD, $arF, array("MIN_PERMISSION" => "X"), array(), "DF");
  46. foreach ($arD as $dir)
  47. if($USER->CanDoFileOperation('fm_edit_permission',Array($site, $dir['ABS_PATH'])))
  48. $arFiles[] = $dir["NAME"];
  49. foreach ($arF as $file)
  50. if($USER->CanDoFileOperation('fm_edit_permission',Array($site, $file['ABS_PATH'])))
  51. $arFiles[] = $file["NAME"];
  52. }
  53. }
  54. $filesCount = count($arFiles);
  55. $arFilesEx = array();
  56. $bFolderInList = false;
  57. $currentValue = false;
  58. $bCurrentValueDiff = false;
  59. for($i = 0; $i < $filesCount; $i++)
  60. {
  61. $arFile = array("NAME" => $arFiles[$i]);
  62. $arFile["PATH"] = $bSearch ? $arFiles[$i] : $path."/".$arFiles[$i];
  63. $arFile["ABS_PATH"] = $documentRoot.$arFile["PATH"];
  64. if (!$bFolderInList && $io->DirectoryExists($arFile["ABS_PATH"]))
  65. $bFolderInList = true;
  66. $arFile["PERM"] = CFileMan::GetUnixFilePermissions($arFile["ABS_PATH"]);
  67. if ($currentValue === false)
  68. $currentValue = $arFile["PERM"][0];
  69. if (!$bCurrentValueDiff && $currentValue != $arFile["PERM"][0])
  70. $bCurrentValueDiff = true;
  71. $arFilesEx[] = $arFile;
  72. }
  73. if ($REQUEST_METHOD == "POST" && $USER->CanDoOperation('fileman_admin_folders') && $_GET["fu_action"] == 'change_perms' && check_bitrix_sessid())
  74. {
  75. CUtil::JSPostUnescape();
  76. $APPLICATION->RestartBuffer();
  77. if (CFileMan::IsWindows())
  78. $result_value = $_POST['readonly'] == "Y" ? '0' : '666';
  79. else
  80. $result_value = intval($_POST['res_value']);
  81. $result_value = (int) "0".$result_value;
  82. $oChmod = new CFilemanChmod;
  83. $oChmod->Init(array(
  84. 'value' => $result_value,
  85. 'lastPath' => isset($_POST['last_path']) ? $_POST['last_path'] : false
  86. ));
  87. $bStoped = true;
  88. for($i = 0; $i < $filesCount; $i++)
  89. {
  90. $arFile = $arFilesEx[$i];
  91. if ($io->DirectoryExists($arFile['ABS_PATH']) && $_POST['recurcive'] == "Y")
  92. {
  93. $oDir = new CFilemanUtilDir($arFile['ABS_PATH'], array(
  94. 'obj' => $oChmod,
  95. 'site' => $Params['site'],
  96. 'callBack' => "Chmod",
  97. 'checkBreak' => "CheckBreak",
  98. 'checkSubdirs' => true
  99. ));
  100. $bSuccess = $oDir->Start();
  101. $bBreak = $oDir->bBreak;
  102. $nextPath = $oDir->nextPath;
  103. $bStoped = $oDir->bStoped;
  104. }
  105. else
  106. {
  107. $bBreak = $oChmod->CheckBreak();
  108. $bStoped = $i == $filesCount - 1; // Last iterration
  109. if ($bBreak && !$bStoped)
  110. $nextPath = $arFilesEx[$i]['ABS_PATH'];
  111. }
  112. if ($bStoped)
  113. $bBreak = false;
  114. if ($bBreak)
  115. break;
  116. $oChmod->Chmod($arFile['ABS_PATH']);
  117. }
  118. clearstatcache();
  119. ?>
  120. <script>
  121. <?if ($bBreak): // Execution breaks on timeout?>
  122. window.spBtimeout = true;
  123. window.spLastPath = '<?= CUtil::JSEscape(CFilemanUtils::TrimPath($nextPath))?>';
  124. <? else: ?>
  125. window.spBtimeout = false;
  126. <? endif; ?>
  127. window.spBstoped = <?= $bStoped ? 'true' : 'false'?>;
  128. window.spResult = <?= CUtil::PhpToJSObject($oChmod->Result)?>;
  129. </script>
  130. <?
  131. die();
  132. }
  133. $backToFolderUrl = "fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($path).($bSearch ? "&search=Y&ssess=".$searchSess : "");
  134. if ($bSearch)
  135. {
  136. $adminChain->AddItem(array("TEXT" => GetMessage("FM_SA_SEARCH_RESULT"), "LINK" => $backToFolderUrl));
  137. }
  138. else
  139. {
  140. $arParsedPath = CFileMan::ParsePath(Array($site, $path), true, false, "", $logical == "Y");
  141. foreach ($arParsedPath["AR_PATH"] as $chainLevel)
  142. {
  143. $adminChain->AddItem(
  144. array(
  145. "TEXT" => htmlspecialcharsex($chainLevel["TITLE"]),
  146. "LINK" => (($chainLevel["LINK"] <> '') ? $chainLevel["LINK"] : ""),
  147. )
  148. );
  149. }
  150. }
  151. $adminChain->AddItem(array("TEXT" => GetMessage("FILEMAN_SERV_ACCESS_TITLE"), "LINK" => ""));
  152. $APPLICATION->SetTitle(GetMessage("FILEMAN_SERV_ACCESS_TITLE"));
  153. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  154. CFilemanUtils::InitScript(array(
  155. 'initServerAccess' => true,
  156. 'site' => $site
  157. ));
  158. $aMenu = array(
  159. array(
  160. "TEXT" => $bSearch ? GetMessage("FILEMAN_SA_BACK_2_SEARCH_RES") : GetMessage("FILEMAN_SA_BACK_2_FOLDER"),
  161. "LINK" => $backToFolderUrl
  162. )
  163. );
  164. $context = new CAdminContextMenu($aMenu);
  165. $context->Show();
  166. ?>
  167. <?CAdminMessage::ShowMessage($strNotice);?>
  168. <?CAdminMessage::ShowMessage($strWarning);?>
  169. <?if($strWarning == ""):?>
  170. <?
  171. $aTabs = array(
  172. array("DIV" => "edit1", "TAB" => GetMessage("FILEMAN_SA_TAB"), "ICON" => "fileman", "TITLE" => GetMessage("FILEMAN_SA_TAB_ALT"))
  173. );
  174. $tabControl = new CAdminTabControl("tabControl", $aTabs);
  175. $tabControl->Begin();
  176. ?>
  177. <?$tabControl->BeginNextTab();?>
  178. <tr>
  179. <td colspan="2">
  180. <div id="bxsp_note_success" style="display: none; margin: 15px 5px;">
  181. <?= BeginNote();?>
  182. <?= GetMessage("FM_SA_SUCCESS_NOTE")?>
  183. <?= EndNote();?>
  184. </div>
  185. <div id="bxsp_note_errors" class="bxsp-error-note" style="display: none; margin: 15px 5px;">
  186. <?= BeginNote();?>
  187. <?= GetMessage("FM_SA_ERRORS_NOTE")?>: <br/>
  188. <div id="bxsp_note_errors_cont" class="bxsp-file"></div>
  189. <?= EndNote();?>
  190. </div>
  191. <span style="padding: 5px 15px;"><?= GetMessage("FILEMAN_SA_CHANGE_TO");?>:</span><br />
  192. <table class="bxsp-file-list bxsp-file-list-init" id="bxsp_file_list">
  193. <tr class="bxsp-header">
  194. <td><?= GetMessage("FM_SA_FILE_PATH")?></td>
  195. <td></td>
  196. <td><?= GetMessage("FM_SA_CUR_VAL")?></td>
  197. <td class="bxsp-status"><?= GetMessage("FM_SA_CHANGE_STATUS")?></td>
  198. </tr>
  199. <?for($i = 0, $l = count($arFilesEx); $i < $l; $i++):?>
  200. <?
  201. if (CFileMan::IsWindows())
  202. {
  203. $html = $arFilesEx[$i]["PERM"][0] == '444' ? GetMessage("FM_SA_WIN_READONLY") : GetMessage("FM_SA_WIN_FULL_ACCESS");
  204. $title = $html;
  205. }
  206. else
  207. {
  208. $html = $arFilesEx[$i]["PERM"][0];
  209. $title = GetMessage("FILEMAN_SA_CUR_VAL").": ".$arFilesEx[$i]["PERM"][1];
  210. }
  211. ?>
  212. <tr id="bxsp_file_row_<?= $i?>">
  213. <td class="bxsp-filename">"<?= htmlspecialcharsbx($APPLICATION->UnJSEscape($arFilesEx[$i]["PATH"]))?>"</td>
  214. <td class="bxsp-separator"> - </td>
  215. <td class="bxsp-value" title="<?= $title?>"><?= $html?></td>
  216. <td class="bxsp-status"><?= GetMessage("FM_SA_IN_PROC")?>...</td>
  217. </tr>
  218. <?endfor;?>
  219. </table>
  220. </td>
  221. </tr>
  222. <tr>
  223. <td colspan="2">
  224. <?$ar = array('owner', 'group', 'public');?>
  225. <span style="font-weight: bold; padding: 5px 15px;"><?= GetMessage("FM_SA_SET_NEW")?>:</b>
  226. <div class="bxfm-sperm-cont">
  227. <? foreach(array('owner', 'group', 'public') as $k):?>
  228. <div class="bx-s-perm-gr">
  229. <div class="bx-s-title"><?= GetMessage("FM_SA_".mb_strtoupper($k))?></div>
  230. <table class="bxsp-tbl"><tr>
  231. <td class="bxsp-inp-cell"><input id="bxsp_<?= $k?>_read" type="checkbox" value="Y"/></td>
  232. <td class="bxsp-label-cell"><label for="bxsp_<?= $k?>_read"><?= GetMessage("FM_SA_READ")?></label></td>
  233. <td class="bxsp-inp-cell"><input id="bxsp_<?= $k?>_write" type="checkbox" value="Y"/></td>
  234. <td class="bxsp-label-cell"><label for="bxsp_<?= $k?>_write"><?= GetMessage("FM_SA_WRITE")?></label></td>
  235. <td class="bxsp-inp-cell"><input id="bxsp_<?= $k?>_exec" type="checkbox" value="Y"/></td>
  236. <td class="bxsp-label-cell"><label for="bxsp_<?= $k?>_exec"><?= GetMessage("FM_SA_EXECUTE")?> </label></td>
  237. <td style="padding: 0 6px 0 80px !important;"><label for="bxsp_<?= $k?>_value"><?= GetMessage("FM_SA_VALUE")?>: </label></td>
  238. <td><input id="bxsp_<?= $k?>_value" type="text" readonly="readonly" size="2"/></td>
  239. </tr></table>
  240. </div>
  241. <?endforeach;?>
  242. <table class="bxsp-tbl-2">
  243. <tr>
  244. <td colSpan="2">
  245. <label for="bxsp_res_value" style="font-weight: bold;"><?= GetMessage("FM_SA_RES_VALUE")?>: </label>
  246. <input id="bxsp_res_value" type="text" value="" size="4" name="result_value" />
  247. </td>
  248. </tr>
  249. <?if ($bCurrentValueDiff):?>
  250. <tr id="bxsp_cur_val_diff">
  251. <td colSpan="4"><i style="color: #494949;"><?= GetMessage("FILEMAN_SA_CUR_VALUE_DIFF")?></i></td>
  252. </tr>
  253. <?endif;?>
  254. <?if ($bFolderInList):?>
  255. <tr>
  256. <td style="width: 20px;"><input name="recurcive" id="bxsp_recurcive" type="checkbox" value="Y" checked="checked"/></td>
  257. <td><label for="bxsp_recurcive"><?= GetMessage("FM_SA_SET_RECURCIVE")?></label></td>
  258. </tr>
  259. <?endif;?>
  260. </table>
  261. </div>
  262. <script>
  263. BX.ready(function()
  264. {
  265. new BXFMServerPerm(
  266. {
  267. currentValue: "<?= $currentValue?>",
  268. arFiles: <?= CUtil::PhpToJSObject($arFilesEx)?>,
  269. lang: '<?= LANGUAGE_ID?>',
  270. site: '<?= CUtil::JSEscape($site)?>',
  271. sessid_get: '<?= bitrix_sessid_get()?>',
  272. path: '<?= CUtil::JSEscape($path)?>',
  273. backUrl: '<?= CUtil::JSEscape($backToFolderUrl)?>',
  274. bSearch: <?= $bSearch ? 'true' : 'false'?>,
  275. searchSess: "<?= CUtil::JSEscape($searchSess)?>"
  276. }
  277. );
  278. });
  279. </script>
  280. </td>
  281. </tr>
  282. <?$tabControl->EndTab();?>
  283. <?$tabControl->Buttons(false);?>
  284. <input type="button" id="bx_sp_save" value="<?= GetMessage("admin_lib_edit_save")?>" title="<?= GetMessage("admin_lib_edit_save_title")?>" />
  285. <input type="button" id="bx_sp_apply" value="<?= GetMessage("admin_lib_edit_apply")?>" title="<?= GetMessage("admin_lib_edit_apply_title")?>" />
  286. <input type="button" id="bx_sp_cancel" value="<?= GetMessage("admin_lib_edit_cancel")?>" title="<?= GetMessage("admin_lib_edit_cancel_title")?>" />
  287. <?$tabControl->End();?>
  288. <?endif;?>
  289. <br>
  290. <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");?>