429 lines
12 KiB
JavaScript
429 lines
12 KiB
JavaScript
// This is our javascript, which will pop up our message
|
|
// in an alert box.
|
|
|
|
var bGlobalPrompt = 'true';
|
|
var consoleService = null;
|
|
var loginCounter = 0;
|
|
var sAttemptedHost = '';
|
|
|
|
function logMessage(message)
|
|
{
|
|
try
|
|
{
|
|
if (consoleService == null)
|
|
{
|
|
consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
|
.getService(Components.interfaces.nsIConsoleService);
|
|
}
|
|
|
|
consoleService.logStringMessage("CASA: " + message +"\n");
|
|
}
|
|
catch (err)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function websso()
|
|
{
|
|
logMessage("PAGE LOADED");
|
|
var url = window._content.location.host;
|
|
var enabledsite = "no";
|
|
var ssosite = "no";
|
|
var fileindex = 0;
|
|
var obj = null;
|
|
|
|
if (url == null || url.length < 1)
|
|
{
|
|
logMessage("Host URL not found");
|
|
return;
|
|
}
|
|
// reset loginprompt
|
|
bGlobalPrompt = 'true';
|
|
|
|
var para=window._content.document.getElementsByTagName("input");
|
|
|
|
|
|
for (var j = 0; !(j >= para.length) ; j++)
|
|
{
|
|
if((para.item(j).type == "password"))
|
|
{
|
|
ssosite = "yes";
|
|
logMessage("Password field");
|
|
logMessage(para.item(j).name);
|
|
}
|
|
}
|
|
|
|
if (ssosite == "yes")
|
|
{
|
|
//alert('password field found');
|
|
var secretId = url;
|
|
var sKey = "";
|
|
//var theValue;
|
|
var bAutoLogin = false;
|
|
|
|
//bGlobalPrompt = false;
|
|
try {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
//alert('test2');
|
|
const cid = "@novell.com/CASA/MiCASAKeys;1";
|
|
if (obj == null)
|
|
{
|
|
obj = Components.classes[cid].createInstance();
|
|
//alert('test3');
|
|
obj = obj.QueryInterface(Components.interfaces.IMiCASAKeys);
|
|
//alert(obj);
|
|
}
|
|
}
|
|
catch (err)
|
|
{
|
|
logMessage(err);
|
|
}
|
|
|
|
var theValue = new String;
|
|
var res;
|
|
|
|
// does config allow sso for this site?
|
|
|
|
try
|
|
{
|
|
res = obj.miCASAReadKey(secretId, 'Config.DoNotSave', theValue);
|
|
if (res == 0)
|
|
{
|
|
if (theValue.value == 'true')
|
|
{
|
|
logMessage('Config does not allow SSO for this url');
|
|
window.removeEventListener("submit",promptuser,true) ;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
catch (err)
|
|
{
|
|
logMessage(err);
|
|
}
|
|
|
|
|
|
var formToSubmit;
|
|
|
|
// looping for inputs and setting the correct values
|
|
for (var j = 0; !(j >= para.length) ; j++)
|
|
{
|
|
try
|
|
{
|
|
if((para.item(j).type == "text") || (para.item(j).type == "password"))
|
|
{
|
|
sKey = para.item(j).name;
|
|
logMessage('Getting: ' + secretId + ':' + sKey);
|
|
|
|
theValue = new String;
|
|
res = obj.miCASAReadKey(secretId, sKey, theValue);
|
|
|
|
if (res == 0)
|
|
{
|
|
var ele = window._content.document.getElementsByName(sKey);
|
|
if (ele != null)
|
|
{
|
|
ele[0].value = theValue.value;
|
|
}
|
|
}
|
|
|
|
// locate and save off the form of the password element
|
|
if (para.item(j).type == "password")
|
|
{
|
|
formToSubmit = para.item(j).parentNode.parentNode;
|
|
|
|
// did we get it?
|
|
if (formToSubmit.type != "form")
|
|
{
|
|
formToSubmit = formToSubmit.parentNode;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (err)
|
|
{
|
|
//alert(err);
|
|
}
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
res = obj.miCASAReadKey(secretId, 'autologin', theValue);
|
|
if (theValue.value == 'true')
|
|
{
|
|
// if this is a new url, reset the counter
|
|
if (sAttemptedHost != url)
|
|
{
|
|
loginCounter = 0;
|
|
}
|
|
|
|
// if we've attempted this login before, don't try it again
|
|
if (loginCounter > 2)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// if there's more than one form, determine which one to submit.
|
|
var forms = window._content.document.forms;
|
|
if (forms.length > 1)
|
|
{
|
|
// find the form with the matching password id.
|
|
logMessage("More than 1 form on page");
|
|
}
|
|
else
|
|
{
|
|
formToSubmit = window._content.document.forms[0].submit();
|
|
}
|
|
|
|
//try it now
|
|
logMessage('Autologin begins');
|
|
sAttemptedHost = url;
|
|
loginCounter += 1;
|
|
|
|
formToSubmit.submit();
|
|
}
|
|
}
|
|
catch (err1)
|
|
{
|
|
logMessage(err1);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function promptuser()
|
|
{
|
|
var username = "";
|
|
var password = "";
|
|
var bIsLogin = 'false';
|
|
var sPromptURL = "chrome://casa/content/prompt.xul?";
|
|
var ele=window._content.document.getElementsByTagName("input");
|
|
var secretID = window._content.location.host;
|
|
|
|
if (bGlobalPrompt != 'true')
|
|
{
|
|
bGlobalPrompt = 'true';
|
|
return;
|
|
}
|
|
|
|
sPromptURL = sPromptURL + "secretid=" + secretID;
|
|
|
|
for (i = 0; !(i>= ele.length); i++)
|
|
{
|
|
|
|
if((ele.item(i).type == "password"))
|
|
{
|
|
bIsLogin = 'true';
|
|
password = ele.item(i).value;
|
|
sPromptURL = sPromptURL + "&" + ele.item(i).name + "=" + ele.item(i).value;
|
|
|
|
// don't prompt user if password field is the same
|
|
try
|
|
{
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
const cid = "@novell.com/CASA/MiCASAKeys;1";
|
|
|
|
//if (obj == null)
|
|
{
|
|
obj = Components.classes[cid].createInstance();
|
|
obj = obj.QueryInterface(Components.interfaces.IMiCASAKeys);
|
|
}
|
|
|
|
//alert("Reading");
|
|
var theValue = new String;
|
|
var res;
|
|
try
|
|
{
|
|
res = obj.miCASAReadKey(secretID, ele.item(i).name, theValue);
|
|
}
|
|
catch (err)
|
|
{
|
|
if (err.toString().indexOf("fcdd") > 0)
|
|
{
|
|
logMessage("fcdd found");
|
|
res = -803;
|
|
}
|
|
else
|
|
{
|
|
logMessage("fcdd not found");
|
|
}
|
|
}
|
|
|
|
if (res == 0)
|
|
{
|
|
if (theValue.value == ele.item(i).value)
|
|
{
|
|
bIsLogin = 'false';
|
|
break;
|
|
}
|
|
}
|
|
else if (res == -803)
|
|
{
|
|
logMessage("CASA Services not available");
|
|
return;
|
|
}
|
|
|
|
} catch (err) {
|
|
bIsLogin = 'false';
|
|
}
|
|
|
|
//bIsLogin = 'true';
|
|
}
|
|
else if((ele.item(i).type == "text"))
|
|
{
|
|
username = ele.item(i).value;
|
|
sPromptURL = sPromptURL + "&" + ele.item(i).name + "=" + ele.item(i).value;
|
|
}
|
|
}
|
|
|
|
if (bIsLogin == 'true')
|
|
{
|
|
//if (confirm("Save credentials in CASA?"))
|
|
{
|
|
var properties = "modal=yes,status=no,titlebar=no,toolbar=no,menubar=no,location=no,height=100,width=100";
|
|
var win = window.open(sPromptURL, null, properties);
|
|
}
|
|
}
|
|
}
|
|
|
|
function centerPrompt()
|
|
{
|
|
var sh = screen.height;
|
|
var sw = screen.width;
|
|
|
|
sizeToContent();
|
|
|
|
var contentheight = window.innerHeight;
|
|
var contentwidth = window.innerWidth;
|
|
|
|
window.moveTo((sw-contentwidth)/2 , (sh-contentheight)/2);
|
|
}
|
|
|
|
|
|
function closeWin()
|
|
{
|
|
var secretID = "";
|
|
var sKey = "";
|
|
var sValue = "";
|
|
|
|
var url = document.location.toString();
|
|
var params = url.substring(url.indexOf('?')+1).split('&');
|
|
|
|
var remember = document.getElementById("CASA.RememberMe");
|
|
var autologin = document.getElementById("CASA.RemAndLogin");
|
|
var never = document.getElementById("CASA.Never");
|
|
|
|
try
|
|
{
|
|
//alert('test1');
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
//alert('test2');
|
|
const cid = "@novell.com/CASA/MiCASAKeys;1";
|
|
//if (obj == null)
|
|
{
|
|
obj = Components.classes[cid].createInstance();
|
|
//alert(obj);
|
|
obj = obj.QueryInterface(Components.interfaces.IMiCASAKeys);
|
|
//alert(obj);
|
|
}
|
|
|
|
} catch (err)
|
|
{
|
|
logMessage(err);
|
|
return;
|
|
}
|
|
|
|
// get the secretID (url host)
|
|
for (var i = 0; !(i > params.length - 1); i++)
|
|
{
|
|
sKey = params[i].substring(0, params[i].indexOf('='));
|
|
sValue = params[i].substring(params[i].indexOf('=')+1);
|
|
|
|
if (sKey == "secretid")
|
|
{
|
|
secretID = sValue;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//alert(never.selected);
|
|
|
|
if (never.selected)
|
|
{
|
|
try
|
|
{
|
|
res = obj.miCASAWriteKey(secretID, 'Config.DoNotSave', 'true');
|
|
}
|
|
catch (err)
|
|
{
|
|
//alert(err);
|
|
}
|
|
window.close();
|
|
return;
|
|
}
|
|
|
|
|
|
if (remember.selected || autologin.selected)
|
|
{
|
|
// save each key-value
|
|
var res;
|
|
for (i = 0; !(i > params.length - 1); i++)
|
|
{
|
|
sKey = params[i].substring(0, params[i].indexOf('='));
|
|
sValue = params[i].substring(params[i].indexOf('=')+1);
|
|
|
|
if (sKey == "secretid")
|
|
{
|
|
//alert('do nothing');
|
|
}
|
|
else
|
|
{
|
|
logMessage('Writing ' + secretID + ' : ' + sKey + ' : xxxxxxx');
|
|
try {
|
|
res = obj.miCASAWriteKey(secretID, sKey, sValue);
|
|
if (res != 0)
|
|
logMessage('Error saving key');
|
|
}
|
|
catch (err)
|
|
{
|
|
alert('CASA services not available');
|
|
logMessage(err);
|
|
window.close();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (autologin.selected)
|
|
{
|
|
//alert(" set autologin flag ");
|
|
res = obj.miCASAWriteKey(secretID, 'autologin', 'true');
|
|
}
|
|
else
|
|
{
|
|
res = obj.miCASAWriteKey(secretID, 'autologin', 'false');
|
|
}
|
|
}
|
|
|
|
window.close();
|
|
}
|
|
|
|
function cancelWin()
|
|
{
|
|
window.close();
|
|
}
|
|
|
|
|
|
|
|
logMessage('adding event listener');
|
|
window.addEventListener("load",websso,true) ;
|
|
window.addEventListener("submit",promptuser,true) ;
|
|
|