author | Dan |
Mon, 11 May 2009 08:50:37 -0400 | |
changeset 19 | 3a791f3f4b91 |
parent 18 | dd8c53454f31 |
child 23 | 4b868c7c241e |
child 25 | 2e7ccbdfdc0a |
permissions | -rw-r--r-- |
0 | 1 |
// sample OTP: |
2 |
// ttttvvvvvvcurikvhjcvnlnbecbkubjvuittbifhndhn |
|
3 |
// charset: cbdefghijklnrtuv |
|
4 |
||
5 |
var yk_interval = false; |
|
6 |
||
7 |
var YK_SEC_NORMAL_USERNAME = 1; |
|
8 |
var YK_SEC_NORMAL_PASSWORD = 2; |
|
9 |
var YK_SEC_ELEV_USERNAME = 4; |
|
10 |
var YK_SEC_ELEV_PASSWORD = 8; |
|
11 |
||
12 |
var yubikey_otp_current = false; |
|
13 |
||
14 |
function yk_mb_init(fieldid, statid) |
|
15 |
{ |
|
16 |
load_component(['messagebox', 'fadefilter', 'flyin', 'jquery', 'jquery-ui', 'l10n']); |
|
17 |
var mp = miniPrompt(yk_mb_construct); |
|
18 |
if ( typeof(fieldid) == 'function' ) |
|
19 |
{ |
|
20 |
var input = mp.getElementsByTagName('input')[0]; |
|
21 |
input.submit_func = fieldid; |
|
22 |
} |
|
23 |
else if ( fieldid && statid ) |
|
24 |
{ |
|
25 |
var input = mp.getElementsByTagName('input')[0]; |
|
26 |
input.yk_field_id = fieldid; |
|
27 |
input.yk_status_id = statid; |
|
28 |
} |
|
29 |
} |
|
30 |
||
31 |
function yk_mb_construct(mp) |
|
32 |
{ |
|
33 |
mp.innerHTML = ''; |
|
34 |
mp.style.textAlign = 'center'; |
|
35 |
mp.innerHTML = '<h3>' + $lang.get('yubiauth_msg_please_touch_key') + '</h3>'; |
|
6 | 36 |
var progress = document.createElement('div'); |
37 |
$(progress).addClass('yubikey_bar'); |
|
38 |
var progimg = document.createElement('img'); |
|
39 |
progimg.src = cdnPath + '/images/spacer.gif'; |
|
40 |
progress.appendChild(progimg); |
|
41 |
mp.appendChild(progress); |
|
0 | 42 |
var ta = document.createElement('input'); |
43 |
ta.submitted = false; |
|
44 |
$(ta) |
|
45 |
.css('background-color', 'transparent') |
|
46 |
.css('border-width', '0px') |
|
47 |
.css('color', '#fff') |
|
48 |
.css('font-size', '1px') |
|
49 |
.css('padding', '0') |
|
50 |
.attr('size', '1') |
|
51 |
.keyup(function(e) |
|
52 |
{ |
|
53 |
if ( e.keyCode == 27 ) |
|
54 |
{ |
|
55 |
window.clearInterval(yk_interval); |
|
56 |
miniPromptDestroy(this); |
|
57 |
} |
|
7
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
58 |
else if ( this.value.length >= 44 && !this.submitted ) |
0 | 59 |
{ |
60 |
this.submitted = true; |
|
61 |
yk_handle_submit(this); |
|
62 |
} |
|
6 | 63 |
else |
64 |
{ |
|
65 |
$('div.yubikey_bar > img', this.parentNode) |
|
66 |
.css('width', String(this.value.length * 2) + 'px') |
|
7
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
67 |
.css('background-position', String((this.value.length > 44 ? 44 : this.value.length) - 44) + 'px -88px'); |
6 | 68 |
} |
0 | 69 |
e.preventDefault(); |
70 |
e.stopPropagation(); |
|
71 |
}); |
|
72 |
mp.appendChild(ta); |
|
73 |
setTimeout(function() |
|
74 |
{ |
|
75 |
window.yk_interval = setInterval(function() |
|
76 |
{ |
|
77 |
ta.focus(); |
|
78 |
}, 50); |
|
79 |
}, 750); |
|
80 |
var info = document.createElement('p'); |
|
6 | 81 |
$(info) |
82 |
.html($lang.get('yubiauth_msg_close_instructions')) |
|
83 |
.css('margin-top', '0'); |
|
0 | 84 |
mp.appendChild(info); |
85 |
} |
|
86 |
||
87 |
function yk_handle_submit(ta) |
|
88 |
{ |
|
7
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
89 |
if ( ta.value.length > 44 || !ta.value.match(/^[cbdefghijklnrtuv]+$/) ) |
0 | 90 |
{ |
91 |
setTimeout(function() |
|
92 |
{ |
|
7
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
93 |
var parent = ta.parentNode; |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
94 |
var tabackup = { |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
95 |
field_id: ta.yk_field_id, |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
96 |
status_id: ta.yk_status_id, |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
97 |
submit_func: ta.submit_func |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
98 |
}; |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
99 |
yk_mb_construct(parent); |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
100 |
var input = parent.getElementsByTagName('input')[0]; |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
101 |
if ( tabackup.field_id ) |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
102 |
input.yk_field_id = tabackup.field_id; |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
103 |
if ( tabackup.status_id ) |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
104 |
input.yk_status_id = tabackup.status_id; |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
105 |
if ( tabackup.submit_func ) |
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
106 |
input.submit_func = tabackup.submit_func; |
0 | 107 |
}, 1000); |
7
c8fc1493eacd
Fixed a few issues with input postprocessing in client API
Dan
parents:
6
diff
changeset
|
108 |
$('h3', ta.parentNode).text($lang.get(ta.value.length > 44 ? 'yubiauth_msg_too_long' : 'yubiauth_msg_invalid_chars')); |
6 | 109 |
$('div.yubikey_bar > img', this.parentNode).addClass('yubikey_bar_error'); |
0 | 110 |
return false; |
111 |
} |
|
112 |
||
113 |
window.clearInterval(yk_interval); |
|
114 |
||
115 |
if ( ta.yk_field_id && ta.yk_status_id ) |
|
116 |
{ |
|
117 |
var field = document.getElementById(ta.yk_field_id); |
|
118 |
var status = document.getElementById(ta.yk_status_id); |
|
119 |
if ( $(status).hasClass('empty') || $(status).hasClass('rmpending') ) |
|
120 |
{ |
|
121 |
$(status).next('a') |
|
122 |
.text($lang.get('yubiauth_ctl_btn_change_key')) |
|
123 |
.addClass('abutton_green') |
|
124 |
.after(' <a class="abutton abutton_red yubikey_enroll" href="#yk_clear" onclick="yk_clear(\'' + ta.yk_field_id + '\', \'' + ta.yk_status_id + '\'); return false;">' |
|
125 |
+ $lang.get('yubiauth_ctl_btn_clear') + |
|
126 |
'</a>'); |
|
127 |
} |
|
128 |
$(status).removeClass('empty').removeClass('enrolled').removeClass('rmpending').addClass('savepending').html($lang.get('yubiauth_ctl_status_enrolled_pending')); |
|
129 |
field.value = ta.value; |
|
130 |
miniPromptDestroy(ta); |
|
131 |
return true; |
|
132 |
} |
|
133 |
else if ( ta.submit_func ) |
|
134 |
{ |
|
135 |
ta.submit_func(ta); |
|
136 |
} |
|
137 |
else |
|
138 |
{ |
|
139 |
miniPromptDestroy(ta); |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
function yk_login_validate_reqs(ta) |
|
144 |
{ |
|
6 | 145 |
$(ta.parentNode).remove('p'); |
0 | 146 |
yubikey_otp_current = ta.value; |
147 |
||
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
148 |
miniPromptDestroy(ta, true); |
0 | 149 |
|
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
150 |
if ( logindata ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
151 |
{ |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
152 |
if ( logindata.mb_object ) |
0 | 153 |
{ |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
154 |
// login window is open |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
155 |
if ( user_level == USER_LEVEL_GUEST ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
156 |
{ |
18
dd8c53454f31
Yubikey flags are no longer fetched from server at login time, instead provided with load
Dan
parents:
17
diff
changeset
|
157 |
var show_username = window.yk_user_flags & YK_SEC_NORMAL_USERNAME; |
dd8c53454f31
Yubikey flags are no longer fetched from server at login time, instead provided with load
Dan
parents:
17
diff
changeset
|
158 |
var show_password = window.yk_user_flags & YK_SEC_NORMAL_PASSWORD; |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
159 |
} |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
160 |
else |
0 | 161 |
{ |
18
dd8c53454f31
Yubikey flags are no longer fetched from server at login time, instead provided with load
Dan
parents:
17
diff
changeset
|
162 |
var show_username = window.yk_user_flags & YK_SEC_ELEV_USERNAME; |
dd8c53454f31
Yubikey flags are no longer fetched from server at login time, instead provided with load
Dan
parents:
17
diff
changeset
|
163 |
var show_password = window.yk_user_flags & YK_SEC_ELEV_PASSWORD; |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
164 |
} |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
165 |
if ( !show_username ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
166 |
$('#ajax_login_field_username').parent('td').hide().prev().hide(); |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
167 |
if ( !show_password ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
168 |
$('#ajax_login_field_password').parent('td').hide().prev().hide(); |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
169 |
|
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
170 |
var can_submit = true; |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
171 |
if ( show_username && !$('#ajax_login_field_username').attr('value') ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
172 |
{ |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
173 |
$('#ajax_login_field_password').focus(); |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
174 |
can_submit = false; |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
175 |
} |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
176 |
if ( show_password && !$('#ajax_login_field_password').attr('value') ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
177 |
{ |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
178 |
if ( can_submit ) |
0 | 179 |
{ |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
180 |
$('#ajax_login_field_password').focus(); |
0 | 181 |
} |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
182 |
can_submit = false; |
0 | 183 |
} |
17
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
184 |
|
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
185 |
if ( can_submit ) |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
186 |
{ |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
187 |
$('#messageBoxButtons input:button:first').click(); |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
188 |
} |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
189 |
} |
e04c0f64e972
SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents:
12
diff
changeset
|
190 |
} |
0 | 191 |
} |
192 |
||
193 |
function yk_clear(field_id, status_id) |
|
194 |
{ |
|
195 |
var field = document.getElementById(field_id); |
|
196 |
var status = document.getElementById(status_id); |
|
197 |
||
198 |
var was_pending = $(field).hasClass('wasempty'); |
|
199 |
||
200 |
$(field).attr('value', ''); |
|
201 |
$(status) |
|
202 |
.removeClass('savepending') |
|
203 |
.removeClass('enrolled') |
|
204 |
.addClass( was_pending ? 'empty' : 'rmpending' ) |
|
205 |
.text( was_pending ? $lang.get('yubiauth_ctl_status_empty') : $lang.get('yubiauth_ctl_status_remove_pending') ) |
|
206 |
.next('a') |
|
207 |
.text($lang.get('yubiauth_ctl_btn_enroll')) |
|
208 |
.removeClass('abutton_green') |
|
209 |
.next('a') |
|
210 |
.remove(); |
|
211 |
} |
|
212 |
||
213 |
addOnloadHook(function() |
|
214 |
{ |
|
215 |
attachHook('login_build_form', 'yk_login_dlg_hook(table);'); |
|
216 |
attachHook('login_build_userinfo', 'if ( window.yubikey_otp_current ) userinfo.yubikey_otp = window.yubikey_otp_current;'); |
|
12 | 217 |
if ( title == namespace_list.Special + 'Preferences/Yubikey' ) |
218 |
{ |
|
219 |
load_component(['jquery', 'jquery-ui', 'expander']); |
|
220 |
} |
|
0 | 221 |
}); |
222 |
||
223 |
function yk_login_dlg_hook(table) |
|
224 |
{ |
|
225 |
window.yubikey_otp_current = false; |
|
226 |
var tr = document.createElement('tr'); |
|
227 |
var td = document.createElement('td'); |
|
228 |
$(td) |
|
229 |
.attr('colspan', '2') |
|
230 |
.css('text-align', 'center') |
|
231 |
.css('font-size', 'smaller') |
|
232 |
.css('font-weight', 'bold') |
|
233 |
.html('<a href="#" onclick="yk_mb_init(yk_login_validate_reqs); return false;" style="color: #6fa202">' + $lang.get('yubiauth_btn_enter_otp') + '</a>'); |
|
234 |
$('a', td).blur(function(e) |
|
235 |
{ |
|
236 |
$('#messageBoxButtons input:button:first').focus(); |
|
237 |
$('#ajax_login_field_captcha').focus(); |
|
238 |
}); |
|
10 | 239 |
if ( window.yk_reg_require_otp || window.yk_user_enabled ) |
9
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
240 |
{ |
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
241 |
setTimeout(function() |
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
242 |
{ |
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
243 |
yk_mb_init(yk_login_validate_reqs); |
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
244 |
}, 750); |
65965da01c41
If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents:
7
diff
changeset
|
245 |
} |
0 | 246 |
tr.appendChild(td); |
247 |
table.appendChild(tr); |
|
248 |
} |
|
249 |