Example #1
0
$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');
    if (is_array($_POST['otp_mandatory_rights'])) {
        Bitrix\Security\Mfa\Otp::setMandatoryRights($_POST['otp_mandatory_rights']);
    }
    if ($_REQUEST["save"] != "" && $_GET["return_url"] != "") {
        LocalRedirect($_GET["return_url"]);
    } else {
        LocalRedirect("/bitrix/admin/security_otp.php?lang=" . LANGUAGE_ID . $returnUrl . "&" . $tabControl->ActiveTabParam());
    }
}
$availableTypes = \Bitrix\Security\Mfa\Otp::getAvailableTypes();