CASA/extensions/common/casajar/content/casaOverlay.js
2006-04-27 17:35:20 +00:00

371 lines
9.8 KiB
JavaScript

// This is our javascript, which will pop up our message
// in an alert box.
var bGlobalPrompt = 'true';
var consoleService = null;
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";
}
}
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);
}
// 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"))
{
//alert(test);
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;
}
}
}
}
catch (err)
{
//alert(err);
}
}
try
{
res = obj.miCASAReadKey(secretId, 'autologin', theValue);
if (theValue.value == 'true')
{
logMessage('Autologin begins');
window._content.document.forms[0].submit();
}
}
catch (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)
{
res = -803;
}
if (res == 0)
{
if (theValue.value == ele.item(i).value)
{
bIsLogin = 'false';
break;
}
}
} 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)
{
logMessage(err);
}
}
}
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) ;