9 var g_SwekeyPlugin
= null;
11 // -------------------------------------------------------------------
12 // Create the swekey plugin if it does not exists
13 function Swekey_Plugin()
17 if (g_SwekeyPlugin
!= null)
18 return g_SwekeyPlugin
;
20 if (window
.ActiveXObject
)
22 g_SwekeyPlugin
= document
.getElementById("swekey_activex");
23 if (g_SwekeyPlugin
== null)
25 // we must create the activex that way instead of new ActiveXObject("FbAuthAx.FbAuthCtl");
26 // ortherwise SetClientSite is not called and we can not get the url
27 var div
= document
.createElement('div');
28 div
.innerHTML
='<object id="swekey_activex" style="display:none" CLASSID="CLSID:8E02E3F9-57AA-4EE1-AA68-A42DD7B0FADE"></object>';
30 // Never append to the body because it may still loading and it breaks IE
31 document
.body
.insertBefore(div
, document
.body
.firstChild
);
32 g_SwekeyPlugin
= document
.getElementById("swekey_activex");
34 return g_SwekeyPlugin
;
37 g_SwekeyPlugin
= document
.getElementById("swekey_plugin");
38 if (g_SwekeyPlugin
!= null)
39 return g_SwekeyPlugin
;
41 for (i
= 0; i
< navigator
.plugins
.length
; i ++
)
45 if (navigator
.plugins
[i
] == null)
47 navigator
.plugins
.refresh();
49 else if (navigator
.plugins
[i
][0] != null && navigator
.plugins
[i
][0].type
== "application/fbauth-plugin")
51 var x
= document
.createElement('embed');
52 x
.setAttribute('type', 'application/fbauth-plugin');
53 x
.setAttribute('id', 'swekey_plugin');
54 x
.setAttribute('width', '0');
55 x
.setAttribute('height', '0');
56 x
.style
.dislay
='none';
58 //document.body.appendChild(x);
59 document
.body
.insertBefore(x
, document
.body
.firstChild
);
60 g_SwekeyPlugin
= document
.getElementById("swekey_plugin");
61 return g_SwekeyPlugin
;
66 navigator
.plugins
.refresh();
67 //alert ('Failed to create plugin: ' + e);
73 //alert("Swekey_Plugin " + e);
74 g_SwekeyPlugin
= null;
79 // -------------------------------------------------------------------
80 // Returns true if the swekey plugin is installed
81 function Swekey_Installed()
83 return (Swekey_Plugin() != null);
86 // -------------------------------------------------------------------
87 // List the id of the Swekey connected to the PC
88 // Returns a string containing comma separated Swekey Ids
89 // A Swekey is a 32 char hexadecimal value.
90 function Swekey_ListKeyIds()
94 return Swekey_Plugin().list();
98 // alert("Swekey_ListKeyIds " + e);
103 // -------------------------------------------------------------------
104 // Ask the Connected Swekey to generate an OTP
105 // id: The id of the connected Swekey (returne by Swekey_ListKeyIds())
106 // rt: A random token
107 // return: The calculated OTP encoded in a 64 chars hexadecimal value.
108 function Swekey_GetOtp(id
, rt
)
112 return Swekey_Plugin().getotp(id
, rt
);
116 // alert("Swekey_GetOtp " + e);
121 // -------------------------------------------------------------------
122 // Ask the Connected Swekey to generate a OTP linked to the current https host
123 // id: The id of the connected Swekey (returne by Swekey_ListKeyIds())
124 // rt: A random token
125 // return: The calculated OTP encoded in a 64 chars hexadecimal value.
126 // or "" if the current url does not start with https
127 function Swekey_GetLinkedOtp(id
, rt
)
131 return Swekey_Plugin().getlinkedotp(id
, rt
);
135 // alert("Swekey_GetSOtp " + e);
140 // -------------------------------------------------------------------
141 // Calls Swekey_GetOtp or Swekey_GetLinkedOtp depending if we are in
142 // an https page or not.
143 // id: The id of the connected Swekey (returne by Swekey_ListKeyIds())
144 // rt: A random token
145 // return: The calculated OTP encoded in a 64 chars hexadecimal value.
146 function Swekey_GetSmartOtp(id
, rt
)
148 var res
= Swekey_GetLinkedOtp(id
, rt
);
150 res
= Swekey_GetOtp(id
, rt
);
155 // -------------------------------------------------------------------
156 // Set a unplug handler (url) to the specified connected feebee
157 // id: The id of the connected Swekey (returne by Swekey_ListKeyIds())
158 // key: The key that index that url, (aplhanumeric values only)
159 // url: The url that will be launched ("" deletes the url)
160 function Swekey_SetUnplugUrl(id
, key
, url
)
164 return Swekey_Plugin().setunplugurl(id
, key
, url
);
168 // alert("Swekey_SetUnplugUrl " + e);