PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/security/admin/security_session.php

https://gitlab.com/alexprowars/bitrix
PHP | 208 lines | 186 code | 18 blank | 4 comment | 26 complexity | 7d08fe33cb384d220b51d5ab880e2008 MD5 | raw file
  1. <?php
  2. use Bitrix\Main\Config\Configuration;
  3. use Bitrix\Main\Localization\Loc;
  4. use Bitrix\Main\Session\Handlers\StrictSessionHandler;
  5. use Bitrix\Main\Session\SessionConfigurationResolver;
  6. define("ADMIN_MODULE_NAME", "security");
  7. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  8. CModule::IncludeModule('security');
  9. IncludeModuleLangFile(__FILE__);
  10. /**
  11. * @global CMain $APPLICATION
  12. * @global CUser $USER
  13. */
  14. $canRead = $USER->CanDoOperation('security_session_settings_read');
  15. $canWrite = $USER->CanDoOperation('security_session_settings_write');
  16. if(!$canRead && !$canWrite)
  17. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  18. $aTabs = array(
  19. array(
  20. "DIV" => "savedb",
  21. "TAB" => GetMessage("SEC_SESSION_ADMIN_SAVEDB_TAB_V2"),
  22. "ICON"=>"main_user_edit",
  23. "TITLE"=>GetMessage("SEC_SESSION_ADMIN_SAVEDB_TAB_TITLE_V2"),
  24. ),
  25. array(
  26. "DIV" => "sessid",
  27. "TAB" => GetMessage("SEC_SESSION_ADMIN_SESSID_TAB"),
  28. "ICON"=>"main_user_edit",
  29. "TITLE"=>GetMessage("SEC_SESSION_ADMIN_SESSID_TAB_TITLE"),
  30. ),
  31. );
  32. $tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
  33. $returnUrl = $_GET["return_url"]? "&return_url=".urlencode($_GET["return_url"]): "";
  34. if(
  35. $_SERVER['REQUEST_METHOD'] == "POST"
  36. && (
  37. $_REQUEST['save'].$_REQUEST['apply'] != ""
  38. || $_REQUEST['sessid_ttl_off'].$_REQUEST['sessid_ttl_on'] != ""
  39. )
  40. && $canWrite
  41. && check_bitrix_sessid()
  42. )
  43. {
  44. $ttl = intval($_POST["sessid_ttl"]);
  45. if($ttl <= 0)
  46. $ttl = 60;
  47. COption::SetOptionInt("main", "session_id_ttl", $ttl);
  48. if(array_key_exists("sessid_ttl_on", $_POST))
  49. {
  50. COption::SetOptionString("main", "use_session_id_ttl", "Y");
  51. }
  52. elseif(array_key_exists("sessid_ttl_off", $_POST))
  53. {
  54. COption::SetOptionString("main", "use_session_id_ttl", "N");
  55. }
  56. if($_REQUEST["save"] != "" && $_GET["return_url"] != "")
  57. LocalRedirect($_GET["return_url"]);
  58. else
  59. LocalRedirect("/bitrix/admin/security_session.php?lang=".LANGUAGE_ID.$returnUrl."&".$tabControl->ActiveTabParam());
  60. }
  61. $APPLICATION->SetTitle(GetMessage("SEC_SESSION_ADMIN_TITLE"));
  62. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  63. $session = \Bitrix\Main\Application::getInstance()->getSession();
  64. if (method_exists($session, 'getSessionHandler'))
  65. {
  66. $sessionHandler = $session->getSessionHandler();
  67. }
  68. else
  69. {
  70. $reflectionClass = new \ReflectionClass($session);
  71. $reflectionProperty = $reflectionClass->getProperty('sessionHandler');
  72. $reflectionProperty->setAccessible(true);
  73. $sessionHandler = $reflectionProperty->getValue($session);
  74. }
  75. $resolver = new SessionConfigurationResolver(Configuration::getInstance());
  76. $sessionConfig = $resolver->getSessionConfig();
  77. $generalHandlerType = $sessionConfig['handlers']['general']['type'] ?? null;
  78. $sessionInFiles = $sessionHandler instanceof StrictSessionHandler;
  79. $showSecondMessage = true;
  80. $messages = array();
  81. if (!$sessionInFiles)
  82. {
  83. $messageType = "OK";
  84. $nameOfStorage = Loc::getMessage("SEC_SESSION_ADMIN_STORAGE_NAME_TYPE_" . strtoupper($generalHandlerType));
  85. $messageText = GetMessage("SEC_SESSION_ADMIN_STORAGE_WITH_SESSION_DATA", ['#NAME#' => $nameOfStorage]);
  86. if(COption::GetOptionString("main", "use_session_id_ttl") == "Y")
  87. {
  88. $messageText .= "<br>";
  89. $messageText .= GetMessage("SEC_SESSION_ADMIN_SESSID_ON");
  90. $showSecondMessage = false;
  91. }
  92. $messages[] = array("type" => $messageType, "text" => $messageText);
  93. }
  94. else
  95. {
  96. $messageType = "ERROR";
  97. $messageText = GetMessage("SEC_SESSION_ADMIN_STORAGE_IN_FILES");
  98. if(COption::GetOptionString("main", "use_session_id_ttl") != "Y")
  99. {
  100. $messageText .= "<br>";
  101. $messageText .= GetMessage("SEC_SESSION_ADMIN_SESSID_OFF");
  102. $showSecondMessage = false;
  103. }
  104. $messages[] = array("type" => $messageType, "text" => $messageText);
  105. }
  106. if($showSecondMessage)
  107. {
  108. if(COption::GetOptionString("main", "use_session_id_ttl") == "Y")
  109. {
  110. $messages[] = array(
  111. "type" => "OK",
  112. "text" => GetMessage("SEC_SESSION_ADMIN_SESSID_ON")
  113. );
  114. }
  115. else
  116. {
  117. $messages[] = array(
  118. "type" => "ERROR",
  119. "text" => GetMessage("SEC_SESSION_ADMIN_SESSID_OFF")
  120. );
  121. }
  122. }
  123. foreach($messages as $message)
  124. {
  125. CAdminMessage::ShowMessage(array(
  126. "MESSAGE" => $message["text"],
  127. "TYPE" => $message["type"],
  128. "HTML" => true
  129. ));
  130. }
  131. ?>
  132. <form method="POST" action="security_session.php?lang=<?=LANGUAGE_ID?><?=$returnUrl?>" enctype="multipart/form-data" name="editform">
  133. <?
  134. $tabControl->Begin();
  135. $tabControl->BeginNextTab();
  136. ?>
  137. <tr>
  138. <td colspan="2">
  139. <?echo BeginNote();?><?echo GetMessage("SEC_SESSION_ADMIN_DB_NOTE_V2")?>
  140. <?echo EndNote(); ?>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td colspan="2">
  145. <?echo BeginNote();?><span style="color:red">*</span><?echo GetMessage("SEC_SESSION_ADMIN_DB_WARNING")?>
  146. <?echo EndNote(); ?>
  147. </td>
  148. </tr>
  149. <?
  150. $tabControl->BeginNextTab();
  151. ?>
  152. <?if(COption::GetOptionString("main", "use_session_id_ttl") == "Y"):?>
  153. <td colspan="2" align="left">
  154. <input type="submit" name="sessid_ttl_off" value="<?echo GetMessage("SEC_SESSION_ADMIN_SESSID_BUTTON_OFF")?>"<?if(!$canWrite) echo " disabled"?>>
  155. </td>
  156. </tr>
  157. <?else:?>
  158. <tr>
  159. <td colspan="2" align="left">
  160. <input type="submit" name="sessid_ttl_on" value="<?echo GetMessage("SEC_SESSION_ADMIN_SESSID_BUTTON_ON")?>"<?if(!$canWrite) echo " disabled"?> class="adm-btn-save">
  161. </td>
  162. </tr>
  163. <?endif;?>
  164. <tr>
  165. <td width="40%"><?echo GetMessage("SEC_SESSION_ADMIN_SESSID_TTL")?>:</td>
  166. <td width="60%"><input type="text" name="sessid_ttl" size="6" value="<?echo COption::GetOptionInt("main", "session_id_ttl", 60)?>"></td>
  167. </tr>
  168. <tr>
  169. <td colspan="2">
  170. <?echo BeginNote();?><?echo GetMessage("SEC_SESSION_ADMIN_SESSID_NOTE")?>
  171. <?echo EndNote(); ?>
  172. </td>
  173. </tr>
  174. <?
  175. $tabControl->Buttons(
  176. array(
  177. "disabled"=>(!$canWrite),
  178. "back_url"=>$_GET["return_url"]? $_GET["return_url"]: "security_session.php?lang=".LANG,
  179. )
  180. );
  181. ?>
  182. <?echo bitrix_sessid_post();?>
  183. <input type="hidden" name="lang" value="<?echo LANG?>">
  184. <?
  185. $tabControl->End();
  186. ?>
  187. </form>
  188. <?
  189. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
  190. ?>