ervu-lkrp-landing/html/script/access-check.js
2025-11-24 14:18:49 +03:00

86 lines
No EOL
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function checkBrowser() {
const userAgent = navigator.userAgent;
return userAgent.includes("Chromium GOST") || userAgent.includes("YaBrowser");
}
function checkCsp(cspTimeout) {
let timeoutMillis;
if (cspTimeout) {
timeoutMillis = cspTimeout * 1000;
}
else {
timeoutMillis = 5000;
}
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Истекло время ожидания загрузки плагина'));
}, timeoutMillis);
window.cadesplugin
.then(() => {
clearTimeout(timeout);
if (window.cadesplugin.CreateObjectAsync) {
return window.cadesplugin.CreateObjectAsync("CAdESCOM.About");
} else {
return Promise.resolve(window.cadesplugin.CreateObject("CAdESCOM.About"));
}
})
.then((oAbout) => {
if (!oAbout || !oAbout.CSPVersion) {
throw new Error('Не удалось создать объект CAdESCOM.About');
}
return oAbout.CSPVersion();
})
.then((cspVersion) => {
return Promise.all([
cspVersion.MajorVersion,
cspVersion.MinorVersion,
cspVersion.BuildVersion
]);
})
.then(([majorVersion, minorVersion, buildVersion]) => {
if (majorVersion === 5 && minorVersion === 0 && buildVersion >= 12000) {
resolve(true);
} else {
console.error(
`Версия CSP не подходит. Необходима версия 5.0.12000 и выше, текущая версия: ${majorVersion}.${minorVersion}.${buildVersion}`
);
resolve(false);
}
})
.catch((error) => {
console.error("Ошибка при получении версии CSP:", error);
clearTimeout(timeout);
resolve(false);
});
})
.catch((error) => {
console.error("Ошибка при проверке CSP:", error);
return false;
});
}
window.addEventListener('DOMContentLoaded', () => {
const browserCheckInfo = document.getElementById('browser-check-info');
const loginButton = document.getElementById('login-button');
const browserPassed = checkBrowser();
if (browserPassed) {
checkCsp(5).then(cspCheckPassed => {
if (cspCheckPassed) {
if (browserCheckInfo) {
browserCheckInfo.hidden = true;
}
} else {
if (loginButton) {
loginButton.classList.add('disabled');
}
}
});
} else {
if (loginButton) {
loginButton.classList.add('disabled');
}
}
});