plugins/yubikey/yubikey.js
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--
Damn it Yubico, you changed your API and broke my code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     1
// sample OTP:
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     2
// ttttvvvvvvcurikvhjcvnlnbecbkubjvuittbifhndhn
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     3
// charset: cbdefghijklnrtuv
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     4
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     5
var yk_interval = false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     6
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     7
var YK_SEC_NORMAL_USERNAME = 1;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     8
var YK_SEC_NORMAL_PASSWORD = 2;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
     9
var YK_SEC_ELEV_USERNAME = 4;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    10
var YK_SEC_ELEV_PASSWORD = 8;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    11
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    12
var yubikey_otp_current = false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    13
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    14
function yk_mb_init(fieldid, statid)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    15
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    16
  load_component(['messagebox', 'fadefilter', 'flyin', 'jquery', 'jquery-ui', 'l10n']);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    17
  var mp = miniPrompt(yk_mb_construct);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    18
  if ( typeof(fieldid) == 'function' )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    19
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    20
    var input = mp.getElementsByTagName('input')[0];
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    21
    input.submit_func = fieldid;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    22
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    23
  else if ( fieldid && statid )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    24
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    25
    var input = mp.getElementsByTagName('input')[0];
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    26
    input.yk_field_id = fieldid;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    27
    input.yk_status_id = statid;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    28
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    29
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    30
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    31
function yk_mb_construct(mp)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    32
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    33
  mp.innerHTML = '';
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    34
  mp.style.textAlign = 'center';
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    35
  mp.innerHTML = '<h3>' + $lang.get('yubiauth_msg_please_touch_key') + '</h3>';
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    36
  var progress = document.createElement('div');
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    37
  $(progress).addClass('yubikey_bar');
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    38
  var progimg = document.createElement('img');
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    39
  progimg.src = cdnPath + '/images/spacer.gif';
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    40
  progress.appendChild(progimg);
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    41
  mp.appendChild(progress);
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    42
  var ta = document.createElement('input');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    43
  ta.submitted = false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    44
  $(ta)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    45
    .css('background-color', 'transparent')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    46
    .css('border-width', '0px')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    47
    .css('color', '#fff')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    48
    .css('font-size', '1px')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    49
    .css('padding', '0')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    50
    .attr('size', '1')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    51
    .keyup(function(e)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    52
      {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    53
        if ( e.keyCode == 27 )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    54
        {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    55
          window.clearInterval(yk_interval);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    56
          miniPromptDestroy(this);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    59
        {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    60
          this.submitted = true;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    61
          yk_handle_submit(this);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    62
        }
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    63
        else
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    64
        {
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    65
          $('div.yubikey_bar > img', this.parentNode)
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    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
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    68
        }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    69
        e.preventDefault();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    70
        e.stopPropagation();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    71
      });
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    72
  mp.appendChild(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    73
  setTimeout(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    74
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    75
      window.yk_interval = setInterval(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    76
        {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    77
          ta.focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    78
        }, 50);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    79
    }, 750);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    80
  var info = document.createElement('p');
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    81
  $(info)
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    82
    .html($lang.get('yubiauth_msg_close_instructions'))
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    83
    .css('margin-top', '0');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    84
  mp.appendChild(info);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    85
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    86
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    87
function yk_handle_submit(ta)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    90
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    91
    setTimeout(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
   109
    $('div.yubikey_bar > img', this.parentNode).addClass('yubikey_bar_error');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   110
    return false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   111
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   112
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   113
  window.clearInterval(yk_interval);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   114
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   115
  if ( ta.yk_field_id && ta.yk_status_id )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   116
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   117
    var field = document.getElementById(ta.yk_field_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   118
    var status = document.getElementById(ta.yk_status_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   119
    if ( $(status).hasClass('empty') || $(status).hasClass('rmpending') )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   120
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   121
      $(status).next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   122
        .text($lang.get('yubiauth_ctl_btn_change_key'))
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   123
        .addClass('abutton_green')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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;">'
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   125
               + $lang.get('yubiauth_ctl_btn_clear') +
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   126
               '</a>');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   127
    }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   128
    $(status).removeClass('empty').removeClass('enrolled').removeClass('rmpending').addClass('savepending').html($lang.get('yubiauth_ctl_status_enrolled_pending'));
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   129
    field.value = ta.value;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   130
    miniPromptDestroy(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   131
    return true;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   132
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   133
  else if ( ta.submit_func )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   134
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   135
    ta.submit_func(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   136
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   137
  else
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   138
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   139
    miniPromptDestroy(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   140
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   141
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   142
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   143
function yk_login_validate_reqs(ta)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   144
{
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
   145
  $(ta.parentNode).remove('p');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   146
  yubikey_otp_current = ta.value;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   191
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   192
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   193
function yk_clear(field_id, status_id)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   194
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   195
  var field = document.getElementById(field_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   196
  var status = document.getElementById(status_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   197
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   198
  var was_pending = $(field).hasClass('wasempty');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   199
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   200
  $(field).attr('value', '');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   201
  $(status)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   202
    .removeClass('savepending')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   203
    .removeClass('enrolled')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   204
    .addClass( was_pending ? 'empty' : 'rmpending' )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   205
    .text( was_pending ? $lang.get('yubiauth_ctl_status_empty') : $lang.get('yubiauth_ctl_status_remove_pending') )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   206
    .next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   207
      .text($lang.get('yubiauth_ctl_btn_enroll'))
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   208
      .removeClass('abutton_green')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   209
    .next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   210
      .remove();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   211
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   212
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   213
addOnloadHook(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   214
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   215
    attachHook('login_build_form', 'yk_login_dlg_hook(table);');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   216
    attachHook('login_build_userinfo', 'if ( window.yubikey_otp_current ) userinfo.yubikey_otp = window.yubikey_otp_current;');
12
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   217
    if ( title == namespace_list.Special + 'Preferences/Yubikey' )
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   218
    {
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   219
      load_component(['jquery', 'jquery-ui', 'expander']);
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   220
    }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   221
  });
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   222
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   223
function yk_login_dlg_hook(table)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   224
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   225
  window.yubikey_otp_current = false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   226
  var tr = document.createElement('tr');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   227
  var td = document.createElement('td');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   228
  $(td)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   229
    .attr('colspan', '2')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   230
    .css('text-align', 'center')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   231
    .css('font-size', 'smaller')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   232
    .css('font-weight', 'bold')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   233
    .html('<a href="#" onclick="yk_mb_init(yk_login_validate_reqs); return false;" style="color: #6fa202">' + $lang.get('yubiauth_btn_enter_otp') + '</a>');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   234
  $('a', td).blur(function(e)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   235
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   236
      $('#messageBoxButtons input:button:first').focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   237
      $('#ajax_login_field_captcha').focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   238
    });
10
748fa1b80031 Added timestamp-based verification.
Dan
parents: 9
diff changeset
   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
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   246
  tr.appendChild(td);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   247
  table.appendChild(tr);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   248
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   249