Files
Facilitor/APPL/PRS/prs_perslid_otp.asp
2025-03-25 10:00:27 +00:00

130 lines
4.4 KiB
Plaintext

<%@language = "javascript" %>
<% /*
$Revision$
$Id$
File: prs_perslid_otp.asp
Description: Genereert en toont de *bestaande* QRcode voor de Google Authenticator
Parameters:
Context:
Note: (Alleen) met FACFAC mag je dat ook bij iemand anders zien
*/ %>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc"-->
<!--#include file="../aut/login.inc"-->
<!--#include file="../Shared/encoding.inc"-->
<%
var theUser_key = getQParamInt("prs_key", user_key);
if (theUser_key != user_key && !user.has("WEB_FACFAC"))
abort_with_warning(L("lcl_no_auth"));
var user_info = new Perslid(theUser_key);
var otpsecret = user_info.otpsecret();
if (!otpsecret)
{
Response.Redirect("prs_perslid_otp_new.asp?prs_key=" + theUser_key);
Response.End;
}
var otpresult = otpcodes(otpsecret);
%>
<html>
<head>
<% FCLTHeader.Generate();
var progressWidth = 200;
%>
<script type='text/javascript'>
function updateProgress(ppos)
{
var pp = $("#progress");
var pw = <%=progressWidth%>;
var ww = Math.max(1, ppos);
if (ww >= pw)
FcltMgr.reload();
pp.css('borderLeftWidth', ww + "px");
pp.width(pw - ww);
setTimeout("updateProgress("+(ppos+1)+")", 1000 * <%=otpresult.otpstep%> / pw);
}
function clear_otp()
{
FcltMgr.confirm(L("lcl_R_U_sure"), function() {
var data = {
prs_key: <%= theUser_key %>
};
<% protectRequest.dataToken("data"); %>
$.post("prs_perslid_otp_clear.asp",
data,
FcltCallbackClose,
"json");
});
}
function new_otp()
{
window.location.href = "prs_perslid_otp_new.asp?prs_key=<%=theUser_key%>";
}
</script>
<style>
geenhekjeaanbeginregel,#progress {
width: <%=progressWidth%>px;
border: 1px solid #888;
}
span.otptokencurrent span.otpnumber {
font-size: 3em;
line-height: 1em;
}
</style>
</head>
<body class="fclt-modal" id="mod_authQR">
<% MODAL_START();
MODAL_BLOCK_START("", L("lcl_otp_authenticatie_activate"), {icon: "fa-shield-check"});
var secret32 = binary_to_base32(hex_to_binary(otpresult.otpseed));
%>
<tr>
<td colspan="2">
<div id="myQR"><%=L("lcl_otp_auth_header").format(secret32)%></div>
<center><img alt="<%=L("lcl_fac_qrcode")%>" class="QRC" src='./qrcodeotp.asp?size=4&prs_key=<%=theUser_key%>'><br></center>
</td>
</tr>
<%
if (user.has("WEB_FACFAC"))
{
Response.Write("<tr><td colspan=\"2\">Omdat je WEB_FACFAC hebt zie je onderstaande:</td></tr><tr><td>");
for (var i = 0; i < otpresult.codes.length; i++)
{
var otpshould = otpresult.codes[i].otpshould;
var dtsfrom = otpresult.codes[i].dtsfrom;
var dtsto = otpresult.codes[i].dtsto;
var cls = 'otptoken';
if (otpresult.codes[i].offset == 0)
{
cls = 'otptokencurrent';
}
//Response.Write("<span class='{3}'>OTP from {0} to {1} should be <span class='otpnumber' style='font-weight:bold'>{2}</span></span>{4}<br>".format(toTimeString(dtsfrom, true), toTimeString(dtsto, true), otpshould, cls));
Response.Write("<span class='{1}'><span class='otpnumber' style='font-weight:bold'>{0}</span></span><br>".format(otpshould, cls));
}
Response.Write("</td><td style='vertical-align:middle'><div id='progress'>&nbsp;</div></td></tr>");
}
MODAL_BLOCK_END();
var buttons = [ { title: L("lcl_clear_otp"), icon: "fa-ban", action: "clear_otp()", importance: 1 },
{ title: L("lcl_new_otp"), icon: "fa-plus", action: "new_otp()", importance: 1 },
{ title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "gen_cancel()", importance: 3 }
];
SIMPLE_BLOCK_START();
CreateButtons(buttons);
SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
<script>
updateProgress(<%=Math.floor(otpresult.tokenpassed * progressWidth)%>);
</script>
<% MODAL_END(); %>
</body>
</html>
<% ASPPAGE_END(); %>