PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/main/admin/composite_log.php

https://gitlab.com/alexprowars/bitrix
PHP | 461 lines | 400 code | 55 blank | 6 comment | 20 complexity | 7f655a5385c646b173f2208bff18dcf6 MD5 | raw file
  1. <?
  2. use Bitrix\Main\Composite;
  3. use Bitrix\Main\Composite\Debug\Logger;
  4. use Bitrix\Main\Composite\Debug\Model\LogTable;
  5. use Bitrix\Main\Config\Option;
  6. use Bitrix\Main\Context;
  7. use Bitrix\Main\Localization\Loc;
  8. use Bitrix\Main\UI\AdminPageNavigation;
  9. use Bitrix\Main\Type;
  10. /**
  11. * @global \CUser $USER
  12. * @global \CMain $APPLICATION
  13. */
  14. require_once(dirname(__FILE__)."/../include/prolog_admin_before.php");
  15. require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/prolog.php");
  16. define("HELP_FILE", "settings/composite_pages.php");
  17. if (!$USER->canDoOperation("view_other_settings") || Composite\Engine::isSelfHostedPortal())
  18. {
  19. $APPLICATION->authForm(Loc::getMessage("ACCESS_DENIED"));
  20. }
  21. Loc::loadMessages(__FILE__);
  22. CJSCore::Init(array("timer"));
  23. $tableID = "tbl_composite_log";
  24. $sorting = new CAdminSorting($tableID, "ID", "DESC");
  25. $adminList = new CAdminList($tableID, $sorting);
  26. $request = Context::getCurrent()->getRequest();
  27. if ($request->getPost("debug_form") && check_bitrix_sessid())
  28. {
  29. $duration = intval($request->getPost("duration"));
  30. $duration = max($duration, 300);
  31. Option::set("main", "composite_debug_duration", $duration);
  32. if ($request->getPost("enable_debug"))
  33. {
  34. Logger::enable(time() + $duration);
  35. }
  36. elseif ($request->getPost("disable_debug"))
  37. {
  38. Logger::disable();
  39. }
  40. localRedirect($APPLICATION->getCurPage()."?lang=".LANGUAGE_ID);
  41. }
  42. if ($request->get("action_button") === "delete" && ($ids = $adminList->groupAction()))
  43. {
  44. $ids = array_map("intval", $ids);
  45. foreach ($ids as $id)
  46. {
  47. $id = intval($id);
  48. $result = LogTable::delete($id);
  49. if (!$result->isSuccess())
  50. {
  51. $adminList->addGroupError("(ID=".$id.") ".implode("<br>", $result->getErrorMessages()), $id);
  52. }
  53. }
  54. }
  55. if ($request->get("action") === "clear_all" && check_bitrix_sessid())
  56. {
  57. LogTable::deleteAll();
  58. localRedirect($APPLICATION->getCurPage()."?lang=".LANGUAGE_ID);
  59. }
  60. $APPLICATION->setTitle(Loc::getMessage("MAIN_COMPOSITE_LOG_TITLE"));
  61. //Filter
  62. $filterFields = array(
  63. "find_id",
  64. "find_host",
  65. "find_uri",
  66. "find_title",
  67. "find_created_start",
  68. "find_created_end",
  69. "find_type",
  70. "find_ajax",
  71. "find_user_id",
  72. );
  73. $adminList->initFilter($filterFields);
  74. function getFilterDate($date)
  75. {
  76. if (!isset($date) || mb_strlen(trim($date)) < 1)
  77. {
  78. return null;
  79. }
  80. $date = trim($date);
  81. return Type\DateTime::isCorrect($date) ? new Type\DateTime($date) : null;
  82. }
  83. $filter = array(
  84. "=ID" => $find_id,
  85. "=HOST" => $find_host,
  86. "?URI" => $find_uri,
  87. "?TITLE" => $find_title,
  88. ">=CREATED" => getFilterDate($find_created_start),
  89. "<=CREATED" => getFilterDate($find_created_end),
  90. "=TYPE" => $find_type,
  91. "=AJAX" => $find_ajax,
  92. "=USER_ID" => $find_user_id,
  93. );
  94. foreach ($filter as $key => $value)
  95. {
  96. if (!is_array($value) && !mb_strlen(trim($value)))
  97. {
  98. unset($filter[$key]);
  99. }
  100. }
  101. $logEntity = LogTable::getEntity();
  102. //Sorting
  103. $sortBy = mb_strtoupper($sorting->getField());
  104. $sortBy = $logEntity->hasField($sortBy) ? $sortBy : "ID";
  105. $sortOrder = mb_strtoupper($sorting->getOrder());
  106. $sortOrder = $sortOrder !== "DESC" ? "ASC" : "DESC";
  107. $nav = new AdminPageNavigation("nav");
  108. $logList = LogTable::getList(array(
  109. "select" => array(
  110. "ID", "HOST", "URI", "TITLE", "CREATED", "TYPE", "AJAX", "USER_ID", "PAGE_ID", "MESSAGE_SHORT",
  111. "USER_NAME" => "USER.NAME",
  112. "USER_LAST_NAME" => "USER.LAST_NAME",
  113. "USER_SECOND_NAME" => "USER.SECOND_NAME",
  114. "USER_LOGIN" => "USER.LOGIN"
  115. ),
  116. "filter" => $filter,
  117. "order" => array($sortBy => $sortOrder),
  118. "count_total" => true,
  119. "offset" => $nav->getOffset(),
  120. "limit" => $nav->getLimit(),
  121. ));
  122. $nav->setRecordCount($logList->getCount());
  123. $adminList->setNavigation($nav, Loc::getMessage("MAIN_COMPOSITE_LOG_PAGES"));
  124. $adminList->addHeaders(array(
  125. array(
  126. "id" => "ID",
  127. "content" => "ID",
  128. "sort" => "ID",
  129. "default" => true
  130. ),
  131. array(
  132. "id" => "PAGE",
  133. "content" => Loc::getMessage("MAIN_COMPOSITE_LOG_PAGE_COLUMN"),
  134. "sort" => "TITLE",
  135. "default" => true
  136. ),
  137. array(
  138. "id" => "HOST",
  139. "content" => $logEntity->getField("HOST")->getTitle(),
  140. "sort" => "HOST",
  141. ),
  142. array(
  143. "id" => "URI",
  144. "content" => $logEntity->getField("URI")->getTitle(),
  145. "sort" => "URI",
  146. ),
  147. array(
  148. "id" => "TITLE",
  149. "content" => $logEntity->getField("TITLE")->getTitle(),
  150. ),
  151. array(
  152. "id" => "CREATED",
  153. "content" => $logEntity->getField("CREATED")->getTitle(),
  154. "sort" => "CREATED",
  155. "default" => true
  156. ),
  157. array(
  158. "id" => "TYPE",
  159. "content" => $logEntity->getField("TYPE")->getTitle(),
  160. "sort" => "TYPE",
  161. "default" => true
  162. ),
  163. array(
  164. "id" => "MESSAGE_SHORT",
  165. "content" => $logEntity->getField("MESSAGE")->getTitle(),
  166. "default" => true
  167. ),
  168. array(
  169. "id" => "AJAX",
  170. "content" => $logEntity->getField("AJAX")->getTitle(),
  171. "sort" => "AJAX",
  172. "default" => true
  173. ),
  174. array(
  175. "id" => "USER_ID",
  176. "content" => $logEntity->getField("USER_ID")->getTitle(),
  177. "sort" => "USER_ID",
  178. ),
  179. ));
  180. while ($record = $logList->fetch())
  181. {
  182. $row = &$adminList->addRow($record["ID"], $record);
  183. $pageCell = '<div style="max-width:250px; word-wrap: break-word"><a href="//%s" target="_blank">%s</a><br>%s</div>';
  184. $pageLink = htmlspecialcharsbx($record["HOST"].$record["URI"]);
  185. $title = trim($record["TITLE"]) <> ''? $record["TITLE"] : $pageLink;
  186. $title = htmlspecialcharsbx($title, ENT_COMPAT, false);
  187. $row->addViewField("PAGE", sprintf($pageCell, $pageLink, $title, $pageLink));
  188. $row->addViewField("AJAX", $record["AJAX"] === "Y" ? Loc::getMessage("MAIN_YES") : Loc::getMessage("MAIN_NO"));
  189. $row->addViewField("TYPE", Logger::getTypeName($record["TYPE"]));
  190. if ($record["TYPE"] === Logger::TYPE_CACHE_REWRITING)
  191. {
  192. $messageCell =
  193. '<a href="composite_diff.php?lang='.LANGUAGE_ID.'&log_id='.$record["ID"].'" target="_blank">'.
  194. Loc::getMessage("MAIN_COMPOSITE_LOG_VIEW_DIFF").'</a>';
  195. $row->addViewField("MESSAGE_SHORT", $messageCell);
  196. }
  197. else
  198. {
  199. $messageCell = '<div style="max-width:250px; word-wrap: break-word;">%s</div>';
  200. $message = str_replace("\n", "<br>", htmlspecialcharsbx($record["MESSAGE_SHORT"]));
  201. $row->addViewField("MESSAGE_SHORT", sprintf($messageCell, $message));
  202. }
  203. if ($record["USER_ID"])
  204. {
  205. $userCell = '<a href="user_edit.php?lang='.LANGUAGE_ID.'&ID=%s">%s</a>';
  206. $userName = \CUser::formatName(
  207. \CSite::getNameFormat(),
  208. array(
  209. "NAME" => $record["USER_NAME"],
  210. "SECOND_NAME" => $record["USER_SECOND_NAME"],
  211. "LAST_NAME" => $record["USER_LAST_NAME"],
  212. "LOGIN" => $record["USER_LOGIN"],
  213. ),
  214. true,
  215. true
  216. );
  217. $row->addViewField("USER_ID", sprintf($userCell, $record["USER_ID"], $userName));
  218. }
  219. else
  220. {
  221. $row->addViewField("USER_ID", "&ndash;");
  222. }
  223. $actions = array(
  224. array(
  225. "ICON" => "delete",
  226. "TEXT" => Loc::getMessage("MAIN_DELETE"),
  227. "ACTION" =>
  228. "if(confirm('".Loc::getMessage('admin_lib_list_del_sel')."')) ".
  229. $adminList->actionDoGroup($record["ID"], "delete")
  230. )
  231. );
  232. $row->addActions($actions);
  233. }
  234. $adminList->addGroupActionTable(
  235. array("delete" => true),
  236. array("disable_action_target" => true)
  237. );
  238. $toolbar = array(
  239. array(
  240. "TEXT" => Loc::getMessage("MAIN_COMPOSITE_LOG_CLEAR_ALL"),
  241. "LINK" => $APPLICATION->getCurPage()."?lang=".LANGUAGE_ID."&action=clear_all&".bitrix_sessid_get(),
  242. "TITLE" => Loc::getMessage("MAIN_COMPOSITE_LOG_CLEAR_ALL_TITLE"),
  243. "LINK_PARAM" =>
  244. "onclick=\"if (!confirm('".htmlspecialcharsbx(CUtil::JSEscape(
  245. Loc::getMessage("MAIN_COMPOSITE_LOG_CLEAR_ALL_CONFIRM")))."')) return false;\"",
  246. "ICON" => "btn_delete"
  247. ),
  248. );
  249. $adminList->addAdminContextMenu($toolbar);
  250. $adminList->checkListMode();
  251. require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/prolog_admin_after.php");
  252. ?>
  253. <?=BeginNote()?>
  254. <form method="POST" action="<?=$APPLICATION->getCurPage()?>" name="enable_debug_form">
  255. <?=bitrix_sessid_post();?>
  256. <input type="hidden" name="lang" value="<?=LANGUAGE_ID?>">
  257. <input type="hidden" name="debug_form" value="Y">
  258. <? if (Logger::isOn()):?>
  259. <div style="color:red; margin: 0 0 10px 1px;">
  260. <b><?=Loc::getMessage("MAIN_COMPOSITE_LOG_DEBUG_ENABLED")?></b>
  261. </div>
  262. <input type="submit" name="disable_debug"
  263. value="<?=Loc::getMessage("MAIN_COMPOSITE_LOG_DISABLE_DEBUG")?>" class="adm-btn-save">&nbsp;&nbsp;
  264. <?
  265. $secondsLeft = Logger::getEndTime() - time();
  266. if ($secondsLeft > 0):
  267. ?>
  268. <span><?=Loc::getMessage("MAIN_COMPOSITE_LOG_TIME_LEFT")?>: <span id="time-left"></span></span>
  269. <script>
  270. BX.timer(BX("time-left"), {
  271. display: "clock",
  272. to: new Date((new Date().valueOf() + <?=$secondsLeft?> * 1000)),
  273. accuracy: 1
  274. });
  275. </script>
  276. <? endif ?>
  277. <? else: ?>
  278. <div style="color:green; margin: 0 0 10px 1px;">
  279. <b><?=Loc::getMessage("MAIN_COMPOSITE_LOG_DEBUG_DISABLED")?></b>
  280. </div>
  281. <input type="submit" name="enable_debug" value="<?=Loc::getMessage("MAIN_COMPOSITE_LOG_ENABLE_DEBUG")?>">
  282. &nbsp;&nbsp;
  283. <select name="duration">
  284. <?
  285. $currentDuration = Option::get("main", "composite_debug_duration", 300);
  286. ?>
  287. <? foreach (array(300, 600, 1200, 1800, 3600) as $duration): ?>
  288. <option
  289. value="<?=$duration?>"
  290. <?=($currentDuration == $duration ? " selected" : "")?>
  291. ><?=Loc::getMessage("MAIN_COMPOSITE_LOG_INTERVAL_".$duration."_SEC")?></option>
  292. <? endforeach ?>
  293. </select>
  294. <? endif ?>
  295. <div style="margin: 10px 0 0 1px;">
  296. <?=Loc::getMessage("MAIN_COMPOSITE_LOG_DEBUG_DESC")?><br>
  297. <?=Loc::getMessage("MAIN_COMPOSITE_LOG_PLUGIN_AD", array(
  298. "#LINK_START#" =>
  299. '<a href="https://chrome.google.com/webstore/detail/bitrix-composite-notifier/'.
  300. 'bhjmmlcdfdcdloebidhnlgoabjpbfjbk?hl=en" target="_blank">',
  301. "#LINK_END#" => "</a>"
  302. ))?>
  303. </div>
  304. </form>
  305. <?=EndNote()?>
  306. <form method="GET" action="<?=$APPLICATION->getCurPage()?>" name="find_form">
  307. <?
  308. $filterControl = new CAdminFilter(
  309. $tableID."_filter",
  310. array(
  311. $logEntity->getField("HOST")->getTitle(),
  312. $logEntity->getField("URI")->getTitle(),
  313. $logEntity->getField("TITLE")->getTitle(),
  314. $logEntity->getField("CREATED")->getTitle(),
  315. $logEntity->getField("TYPE")->getTitle(),
  316. $logEntity->getField("AJAX")->getTitle(),
  317. $logEntity->getField("USER_ID")->getTitle(),
  318. )
  319. );
  320. $filterControl->begin();
  321. ?>
  322. <tr>
  323. <td>ID:</td>
  324. <td><input type="text" name="find_id" value="<?=htmlspecialcharsbx($find_id)?>" size="40"></td>
  325. </tr>
  326. <tr>
  327. <td><?=$logEntity->getField("HOST")->getTitle()?>:</td>
  328. <td><input type="text" name="find_host" value="<?=htmlspecialcharsbx($find_host)?>" size="40"></td>
  329. </tr>
  330. <tr>
  331. <td><?=$logEntity->getField("URI")->getTitle()?>:</td>
  332. <td><input type="text" name="find_uri" value="<?=htmlspecialcharsbx($find_uri)?>" size="40"></td>
  333. </tr>
  334. <tr>
  335. <td><?=$logEntity->getField("TITLE")->getTitle()?>:</td>
  336. <td><input type="text" name="find_title" value="<?=htmlspecialcharsbx($find_title)?>" size="40"></td>
  337. </tr>
  338. <tr>
  339. <td><?=$logEntity->getField("CREATED")->getTitle()?>:</td>
  340. <td><?=calendarPeriod(
  341. "find_created_start",
  342. htmlspecialcharsbx($find_created_start),
  343. "find_created_end",
  344. htmlspecialcharsbx($find_created_end),
  345. "find_form",
  346. "Y",
  347. "class=\"typeselect\"",
  348. "class=\"typeinput\"",
  349. "20" //important
  350. )?></td>
  351. </tr>
  352. <tr>
  353. <td><?=$logEntity->getField("TYPE")->getTitle()?>:</td>
  354. <td>
  355. <?
  356. $types = array_map(
  357. function($type) {
  358. return Logger::getTypeName($type);
  359. },
  360. Logger::getTypes()
  361. );
  362. echo SelectBoxMFromArray(
  363. "find_type[]",
  364. array(
  365. "reference" => $types,
  366. "reference_id" => Logger::getTypes()
  367. ),
  368. $find_type,
  369. "",
  370. false,
  371. "5"
  372. );
  373. ?>
  374. </td>
  375. </tr>
  376. <tr>
  377. <td><?=$logEntity->getField("AJAX")->getTitle()?>:</td>
  378. <td>
  379. <?=SelectBoxFromArray(
  380. "find_ajax",
  381. array(
  382. "reference" => array(Loc::getMessage("MAIN_YES"), Loc::getMessage("MAIN_NO")),
  383. "reference_id" => array("Y", "N")
  384. ),
  385. htmlspecialcharsbx($find_ajax),
  386. Loc::getMessage("MAIN_ALL")
  387. );
  388. ?>
  389. </td>
  390. </tr>
  391. <tr>
  392. <td><?=$logEntity->getField("USER_ID")->getTitle()?>:</td>
  393. <td><input type="text" name="find_user_id" value="<?=htmlspecialcharsbx($find_user_id)?>" size="40"></td>
  394. </tr>
  395. <?
  396. $filterControl->buttons(array(
  397. "table_id" => $tableID,
  398. "url"=> $APPLICATION->getCurPage(),
  399. "form"=>"find_form",
  400. ));
  401. $filterControl->end();
  402. ?>
  403. </form>
  404. <?
  405. $adminList->displayList();
  406. require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_admin.php");