1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
/*
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2018 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
var setupWin;
var imagePath;
var helperPath;
function cbSuccess (url, idserver, oid_ret, sig, nam, mail) {
setImage ('login-bg.gif');
setNote ('', '#FFFFFF');
var ex, elm;
var oid_sig = document.getElementById('oid_sig');
oid_sig.value = oid_ret;
elm = document.getElementById('email1');
elm.value = mail;
elm = document.getElementById('name1');
elm.value = nam;
// find the setup window, if they clicked the regular link
if (! setupWin) {
try {
setupWin = window.open("about:blank", "user_setup_url_win");
} catch (ex) { }
}
// and now try to close whatever it was
// try {
// if (setupWin)
// setupWin.close();
// } catch (ex) { }
prepareWipeOnType();
}
function cbError (errcode, errtxt) {
setImage ('excl_16.gif');
setNote("<b>Error:</b> " + ehtml(errtxt), '#FFA3A2');
prepareWipeOnType();
var ue = document.getElementById('openid_url');
ue.focus();
}
function ehtml (str) {
if (!str) return "";
return str.replace(/&/g, "&").replace(/\"/g, """).replace(/\'/g, "'").replace(/>/g, ">").replace(/</g, "<");
}
var setup_URL;
function popSetupURL () {
setupWin = window.open(setup_URL, "user_setup_url_win");
return false;
}
function cbNeedPermissions (url) {
setImage ('excl_16.gif');
setup_URL = url;
setNote("<b>Note:</b> You need to <a onclick='return popSetupURL();' target='user_setup_url_win' href='" + url + "'>grant permission</a> for this site to know who you are. Once you do so, press Login again.", '#FBFFC6');
popSetupURL();
prepareWipeOnType();
}
function cbDebug (txt) {
}
function cbPostHelper (id, url, macKey) {
var oid_key = document.getElementById('oid_key');
setImage ('wait_16.gif');
prepareWipeOnType();
if (oid_key != null)
oid_key.value = macKey;
}
function setPaths (image_path, helper_path)
{
imagePath = '/weblog/public/images/';
helperPath = '/weblog/public/';
if (image_path != null)
imagePath = image_path;
if (helper_path != null)
helperPath = helper_path;
}
function setImage (img)
{
var msg = document.getElementById('img');
msg.innerHTML = '<img src="' + imagePath + img +'" border="0" hspace="1" alt="'+ img +'" />';
if (img != '')
msg.style.visibility = "visible";
else
msg.style.visibility = "hidden";
}
function stopBubble (e) {
if (e.stopPropagation)
e.stopPropagation();
if ("cancelBubble" in e)
e.cancelBubble = true;
}
// stops the bubble, as well as the default action
function stopEvent (e) {
stopBubble(e);
if (e.preventDefault)
e.preventDefault();
if ("returnValue" in e)
e.returnValue = false;
return false;
}
function regEvent (target, evt, func) {
if (! target) return;
if (target.attachEvent)
target.attachEvent("on"+evt, func);
if (target.addEventListener)
target.addEventListener(evt, func, false);
}
function onClickVerify (e) {
if (!e) e = window.event;
setNote ('', '#FFFFFF');
setImage ('');
var ue = document.getElementById('openid_url');
if (!ue) return alert("assert: no ue");
var client_url = ue.value;
var opts = {
'client_url': client_url,
'on_success': cbSuccess,
'on_error': cbError,
'on_debug': cbDebug,
'on_need_permissions': cbNeedPermissions,
'on_post_helper': cbPostHelper,
'post_grant': "close"
};
opts.helper_url = "http://" + location.host + helperPath + "openid_helper.vsp";
OpenID_verify(opts);
setImage ('wait_16.gif');
return stopEvent(e);
}
function setNote (txt, color) {
var me = document.getElementById('msg');
if (!me) return alert("assert: no me");
me.innerHTML = txt;
me.style.background = color;
}
function introUI () {
var oid_sig = document.getElementById('oid_sig');
setImage ('');
setNote ('', '#FFFFFF');
oid_sig.value = '';
removeWipeOnType();
}
function prepareWipeOnType () {
var ue = document.getElementById('openid_url');
ue.onkeydown = introUI;
ue.onkeypress = introUI;
}
function removeWipeOnType () {
var ue = document.getElementById('openid_url');
ue.onkeydown = null;
ue.onkeypress = null;
}
function _OpenID_iframe_include (uri) {
//var se = document.createElement("iframe");
//se.width = 1;
//se.height = 1;
//se.style.display = 'inline';
//se.style.border = '0';
//var be = document.getElementsByTagName('body').item(0);
//be.appendChild(se);
//se.contentWindow.location = uri;
window.open (uri, "OpenID_window", "");
}
// returns whether the browser is able to do the client-side version of OpenID
function OpenID_capable () {
return getXTR() ? 1 : 0;
}
// args is object with keys:
// client_url: the HTML URL the client provided. is just
// sent as-is to the helper URL on the server.
// helper_url: the URL of the helper on the server
// on_success: (canonical_identity_url, id_server, oid_ret, sig)
// on_error (errtxt) general error callback
// on_need_permissions (url) URL to send user
function OpenID_verify (arg_hargs) {
var xtr = getXTR();
var nf = function () {}; // null function
// make a copy to work around Safari bug w/ closures not capturing formal parameters
var hargs = arg_hargs;
// make a top-level function that captures some internal variables
window.OpenID_callback_pass = function (identityURL, sig, oid_ret, nam, mail) {
(hargs.on_success||nf)(identityURL, hargs.id_server, oid_ret, sig, nam, mail);
};
window.OpenID_callback_fail = function (url) {
(hargs.on_need_permissions||nf)(url);
};
window.OpenID_general_error = function (erro) {
(hargs.on_error||nf)(erro.err_code, erro.err_text);
};
var state_callback = function () {
var ex;
var helperRes;
if (xtr.readyState != 4)
return;
if (xtr.status == 200) {
try {
(hargs.on_debug||nf)("responseText = [" + xtr.responseText + "]");
try {
eval("var helperRes = " + xtr.responseText + ";\n");
} catch (ex) {
(hargs.on_error||nf)("invalid_json", "Got invalid JSON response from helper. Got: " + xtr.responseText + ", e = " + ex);
return;
}
if (helperRes.err_code) {
(hargs.on_error||nf)(helperRes.err_code, helperRes.err_text);
return;
}
var cleanIdentityURL = helperRes.clean_identity_url;
var macKey = helperRes.openid_key;
(hargs.on_post_helper||nf)(helperRes.id_server, cleanIdentityURL, macKey);
hargs.id_server = helperRes.id_server;
_OpenID_iframe_include(helperRes.checkid_immediate_url);
} catch (ex) {
(hargs.on_error||nf)("iframe_exception", "Error loading remote iframe: " + ex);
}
} else {
(hargs.on_error||nf)("helper_not_200", "Didn't get status code 200 contacting helper. Got: " + xtr.status);
}
};
xtr.onreadystatechange = state_callback;
xtr.open("GET", hargs.helper_url + "?openid_url=" + escape(hargs.client_url), true);
xtr.send(null);
}
function getXTR (need_req_header) {
var xtr;
var ex;
if (typeof(XMLHttpRequest) != "undefined") {
// The Firefox/Safari/Opera way
xtr = new XMLHttpRequest();
} else {
// The IE way(s)
try {
xtr = new ActiveXObject("Msxml2.XMLHTTP.4.0");
} catch (ex) {
try {
xtr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (ex) {
}
}
}
if (need_req_header) {
// don't work in Opera that only half-supports XMLHttpRequest
try {
if (xtr && ! xtr.setRequestHeader)
xtr = null;
} catch (ex) { }
}
return xtr;
}
|