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