Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html>
<head>
{% for src in js %}
<script type="text/javascript" src="{{ src }}"></script>
{% endfor %}
{% for src in css %}
<link type="text/css" rel="stylesheet" href="{{ src }}">
{% endfor %}
<script src="https://icnml.unil.ch/cdn/otplib-browser.js"></script>
<link type="text/css" rel="stylesheet" href="{{ url_for( 'send_app_files', path = 'app.css' ) }}">
<script type="text/javascript">
baseurl = "{{ baseurl }}";
secret = "{{ secret }}";
</script>
</head>
<body>
<div class="icnml_login">
<h1 style="margin-bottom: 0px">ICNML</h1>
<h4 style="margin-top: 0px">International Close Non-Matches Library</h4>
<div class="ui-widget-header ui-corner-top icnml_login_top">Time-based One Time Password</div>
<div class="ui-widget-content ui-corner-bottom icnml_login_form">
<div style="min-height: 378px">
<img alt="qrcode" id="icnml_qrcode" width="100%">
</div>
<div style="text-align: center; margin-bottom: 10px;">
<div style="font-size: 1.17em; font-weight: bold;">Current TOTP:</div>
<h1 id="icnml_current_totp"></h1>
<div>Valid for <span id="icnml_totp_timeremaining"></span> second(s)</div>
</div>
<div style="text-align: center; margin-bottom: 10px;">
<div>Secret value:</div>
<input id="icnml_totp_secret_value" size="52"></input>
</div>
<div class="icnml_button" style="margin-top: 10px;">
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="set_secret_button" role="button" aria-disabled="false">
<span class="ui-button-text">Set new TOTP</span>
</a>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="set_secret_button" role="button" aria-disabled="false" href="{{ url_for( 'home' ) }}">
<span class="ui-button-text">Cancel</span>
</a>
</div>
<div class="icnml_button" style="margin-top: 10px;">
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="new_secret_button" role="button" aria-disabled="false">
<span class="ui-button-text">New secret</span>
</a>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="copy_secret_button" role="button" aria-disabled="false">
<span class="ui-button-text">Copy secret</span>
</a>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var renew_secret = function()
{
secret = "";
$( '#icnml_qrcode' )
.css( 'display', 'None' )
.attr( 'src', '' );
$.ajax( {
url: '{{ url_for( 'request_renew_secret' ) }}',
dataType: 'json',
method: 'GET',
success: function( data )
{
if( ! data.error )
{
secret = data.secret;
update();
}
}
} );
}
var fetch_secret = function()
{
secret = "";
$.ajax( {
url: '{{ url_for( 'request_secret' ) }}',
dataType: 'json',
method: 'GET',
success: function( data )
{
if( ! data.error )
{
secret = data.secret;
}
}
} );
}
var copy_secret = function()
{
$( "#icnml_totp_secret_value" ).select();
document.execCommand( 'copy' );
}
var update_data = function()
{
if( secret != "" )
{
var tr = otplib.authenticator.timeRemaining();
var h = otplib.authenticator.generate( secret );
h = h.substr( 0, 3 ) + " " + h.substr( 3, 6 );
$( '#icnml_current_totp' ).text( h );
$( '#icnml_totp_timeremaining' ).text( tr );
$( "#icnml_totp_secret_value" ).val( secret );
} else {
$( '#icnml_current_totp' ).text( "-" );
$( '#icnml_totp_timeremaining' ).text( "-" );
$( "#icnml_totp_secret_value" ).val( "-" );
}
}
var update_qrcode = function()
{
var uid = Math.floor( Math.random() * 100000000 );
var url = "{{ url_for( 'send_qrcode' ) }}?" + uid;
$( '#icnml_qrcode' )
.css( 'display', 'block' )
.attr( 'src', url );
}
var update = function()
{
update_data();
update_qrcode();
}
var set_secret = function()
{
$.ajax( {
url: '{{ url_for( 'set_secret' ) }}',
dataType: 'json',
success: function( data )
{
if( ! data.error )
{
location.href = "{{ url_for( 'home' ) }}";
} else {
console.log( "error" );
console.log( data );
}
}
} );
}
update();
setInterval( update_data, 1000 );
$( '#set_secret_button' ).on( 'click', set_secret );
$( '#new_secret_button' ).on( 'click', renew_secret );
$( '#copy_secret_button' ).on( 'click', copy_secret );
</script>
</html>