Example #1
0
IncludeModuleLangFile(__FILE__);
/**
 * @global CUser $USER
 * @global CMain $APPLICATION
 **/
$canRead = $USER->CanDoOperation('security_otp_settings_read');
$canWrite = $USER->CanDoOperation('security_otp_settings_write');
if (!$canRead && !$canWrite) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$aTabs = array(array("DIV" => "main", "TAB" => GetMessage("SEC_OTP_NEW_MAIN_TAB"), "ICON" => "main_user_edit", "TITLE" => GetMessage("SEC_OTP_NEW_MAIN_TAB_TITLE")), array("DIV" => "params", "TAB" => GetMessage("SEC_OTP_PARAMETERS_TAB"), "ICON" => "main_user_edit", "TITLE" => GetMessage("SEC_OTP_NEW_PARAMETERS_TAB_TITLE")));
$tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
$returnUrl = $_GET["return_url"] ? "&return_url=" . urlencode($_GET["return_url"]) : "";
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["save"] . $_REQUEST["apply"] . $_REQUEST["otp_siteb"] != "" && $canWrite && check_bitrix_sessid()) {
    if ($_REQUEST["otp_siteb"] != "") {
        CSecurityUser::setActive($_POST["otp_active"] === "Y");
    }
    $hotp_user_window = intval($_POST["window_size"]);
    if ($hotp_user_window <= 0) {
        $hotp_user_window = 10;
    }
    COption::SetOptionString("security", "hotp_user_window", $hotp_user_window);
    COption::SetOptionString("security", "otp_allow_remember", $_POST["otp_allow_remember"] === "Y" ? "Y" : "N");
    COption::SetOptionString("security", "otp_allow_recovery_codes", $_POST["otp_allow_recovery_codes"] === "Y" ? "Y" : "N");
    if ($_POST['otp_default_type']) {
        Bitrix\Security\Mfa\Otp::setDefaultType($_POST['otp_default_type']);
    }
    if (is_numeric($_POST['otp_mandatory_skip_days'])) {
        Bitrix\Security\Mfa\Otp::setSkipMandatoryDays($_POST['otp_mandatory_skip_days']);
    }
    Bitrix\Security\Mfa\Otp::setMandatoryUsing($_POST['otp_mandatory_using'] === 'Y');