plugins/yubikey/yubikey.js
author Dan
Wed, 29 Jul 2009 12:09:35 -0400
changeset 24 ba1a31f16afe
parent 23 4b868c7c241e
child 28 b9a3da602841
permissions -rw-r--r--
Disabled JS login hook for iPhone Safari
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
        }
23
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    58
        else if ( this.value.length == 44 && !this.submitted )
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    59
        {
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    60
          this.submitted = true;
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    61
          yk_handle_submit(this);
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    62
        }
4b868c7c241e JS: Change to submit behavior: allowed keycode 13 (enter) for submit
Dan
parents: 18
diff changeset
    63
        else if ( e.keyCode == 13 && this.value.length != 44 )
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    64
        {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    65
          this.submitted = true;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    66
          yk_handle_submit(this);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    67
        }
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    68
        else
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    69
        {
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    70
          $('div.yubikey_bar > img', this.parentNode)
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    71
            .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
    72
            .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
    73
        }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    74
        e.preventDefault();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    75
        e.stopPropagation();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    76
      });
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    77
  mp.appendChild(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    78
  setTimeout(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    79
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    80
      window.yk_interval = setInterval(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    81
        {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    82
          ta.focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    83
        }, 50);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    84
    }, 750);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    85
  var info = document.createElement('p');
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    86
  $(info)
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    87
    .html($lang.get('yubiauth_msg_close_instructions'))
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
    88
    .css('margin-top', '0');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    89
  mp.appendChild(info);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    90
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    91
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    92
function yk_handle_submit(ta)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    93
{
7
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
    94
  if ( ta.value.length > 44 || !ta.value.match(/^[cbdefghijklnrtuv]+$/) )
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    95
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    96
    setTimeout(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
    97
      {
7
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
    98
        var parent = ta.parentNode;
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
    99
        var tabackup = {
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   100
          field_id: ta.yk_field_id,
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   101
          status_id: ta.yk_status_id,
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   102
          submit_func: ta.submit_func
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   103
        };
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   104
        yk_mb_construct(parent);
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   105
        var input = parent.getElementsByTagName('input')[0];
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   106
        if ( tabackup.field_id )
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   107
          input.yk_field_id = tabackup.field_id;
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   108
        if ( tabackup.status_id )
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   109
          input.yk_status_id = tabackup.status_id;
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   110
        if ( tabackup.submit_func )
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   111
          input.submit_func = tabackup.submit_func;
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   112
      }, 1000);
7
c8fc1493eacd Fixed a few issues with input postprocessing in client API
Dan
parents: 6
diff changeset
   113
    $('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
   114
    $('div.yubikey_bar > img', this.parentNode).addClass('yubikey_bar_error');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   115
    return false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   116
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   117
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   118
  window.clearInterval(yk_interval);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   119
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   120
  if ( ta.yk_field_id && ta.yk_status_id )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   121
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   122
    var field = document.getElementById(ta.yk_field_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   123
    var status = document.getElementById(ta.yk_status_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   124
    if ( $(status).hasClass('empty') || $(status).hasClass('rmpending') )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   125
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   126
      $(status).next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   127
        .text($lang.get('yubiauth_ctl_btn_change_key'))
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   128
        .addClass('abutton_green')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   129
        .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
   130
               + $lang.get('yubiauth_ctl_btn_clear') +
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   131
               '</a>');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   132
    }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   133
    $(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
   134
    field.value = ta.value;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   135
    miniPromptDestroy(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   136
    return true;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   137
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   138
  else if ( ta.submit_func )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   139
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   140
    ta.submit_func(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   141
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   142
  else
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   143
  {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   144
    miniPromptDestroy(ta);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   145
  }
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   146
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   147
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   148
function yk_login_validate_reqs(ta)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   149
{
6
4f85ab095cc8 Added visual feedback for key entry
Dan
parents: 0
diff changeset
   150
  $(ta.parentNode).remove('p');
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   151
  yubikey_otp_current = ta.value;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   152
  
17
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   153
  miniPromptDestroy(ta, true);
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   154
  
17
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   155
  if ( logindata )
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   156
  {
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   157
    if ( logindata.mb_object )
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   158
    {
17
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   159
      // login window is open
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   160
      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
   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_NORMAL_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_NORMAL_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
      else
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   166
      {
18
dd8c53454f31 Yubikey flags are no longer fetched from server at login time, instead provided with load
Dan
parents: 17
diff changeset
   167
        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
   168
        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
   169
      }
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   170
      if ( !show_username )
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   171
        $('#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
   172
      if ( !show_password )
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   173
        $('#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
   174
      
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   175
      var can_submit = true;
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   176
      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
   177
      {
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   178
        $('#ajax_login_field_password').focus();
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   179
        can_submit = false;
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   180
      }
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   181
      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
   182
      {
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   183
        if ( can_submit )
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   184
        {
17
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   185
          $('#ajax_login_field_password').focus();
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   186
        }
17
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   187
        can_submit = false;
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   188
      }
17
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
      if ( can_submit )
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   191
      {
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   192
        $('#messageBoxButtons input:button:first').click();
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   193
      }
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   194
    }
e04c0f64e972 SECURITY (critical): If username provided, any Yubikey could be used to log in.
Dan
parents: 12
diff changeset
   195
  }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   196
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   197
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   198
function yk_clear(field_id, status_id)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   199
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   200
  var field = document.getElementById(field_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   201
  var status = document.getElementById(status_id);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   202
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   203
  var was_pending = $(field).hasClass('wasempty');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   204
  
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   205
  $(field).attr('value', '');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   206
  $(status)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   207
    .removeClass('savepending')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   208
    .removeClass('enrolled')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   209
    .addClass( was_pending ? 'empty' : 'rmpending' )
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   210
    .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
   211
    .next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   212
      .text($lang.get('yubiauth_ctl_btn_enroll'))
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   213
      .removeClass('abutton_green')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   214
    .next('a')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   215
      .remove();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   216
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   217
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   218
addOnloadHook(function()
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   219
  {
24
ba1a31f16afe Disabled JS login hook for iPhone Safari
Dan
parents: 23
diff changeset
   220
    if ( is_iPhone )
ba1a31f16afe Disabled JS login hook for iPhone Safari
Dan
parents: 23
diff changeset
   221
      // kinda can't plug a yubikey into an iPhone
ba1a31f16afe Disabled JS login hook for iPhone Safari
Dan
parents: 23
diff changeset
   222
      // ... yet?
ba1a31f16afe Disabled JS login hook for iPhone Safari
Dan
parents: 23
diff changeset
   223
      return;
ba1a31f16afe Disabled JS login hook for iPhone Safari
Dan
parents: 23
diff changeset
   224
    
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   225
    attachHook('login_build_form', 'yk_login_dlg_hook(table);');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   226
    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
   227
    if ( title == namespace_list.Special + 'Preferences/Yubikey' )
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   228
    {
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   229
      load_component(['jquery', 'jquery-ui', 'expander']);
6faa838e4433 Whoops! That load_component was needed in prefs page
Dan
parents: 11
diff changeset
   230
    }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   231
  });
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   232
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   233
function yk_login_dlg_hook(table)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   234
{
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   235
  window.yubikey_otp_current = false;
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   236
  var tr = document.createElement('tr');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   237
  var td = document.createElement('td');
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   238
  $(td)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   239
    .attr('colspan', '2')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   240
    .css('text-align', 'center')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   241
    .css('font-size', 'smaller')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   242
    .css('font-weight', 'bold')
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   243
    .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
   244
  $('a', td).blur(function(e)
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   245
    {
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   246
      $('#messageBoxButtons input:button:first').focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   247
      $('#ajax_login_field_captcha').focus();
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   248
    });
10
748fa1b80031 Added timestamp-based verification.
Dan
parents: 9
diff changeset
   249
  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
   250
  {
65965da01c41 If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents: 7
diff changeset
   251
    setTimeout(function()
65965da01c41 If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents: 7
diff changeset
   252
      {
65965da01c41 If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents: 7
diff changeset
   253
        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
   254
      }, 750);
65965da01c41 If yubikey_reg_require_otp is 1, opening login window now auto-opens Yubikey prompt
Dan
parents: 7
diff changeset
   255
  }
0
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   256
  tr.appendChild(td);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   257
  table.appendChild(tr);
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   258
}
9d2c4f04a0d0 First commit! Hoping everything works.
Dan
parents:
diff changeset
   259