// 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 = ''; var IAWindow; var props = null; var sCurrentPersona = "home"; var bShowValues = false; function dumpRealms() { logMessage("dumpRealms called"); var realms = Packages.Jim.getRealms("jim_realms.xml"); } function writeTestKey() { writeCASASetting("Bandit", "ldapdn", "cn=bandit1,o=novell"); writeCASASetting("Bandit", "password", "11111111"); writeCASASetting("Bandit", "ftoBalance", "100"); writeCASASetting("Bandit", "costCenter", "Marketing"); writeCASASetting("Bandit", "sn", "CASA Last Name"); writeCASASetting("Bandit", "facsimileTelephoneNumber", "111-222-3333"); writeCASASetting("Bandit", "postalAddress", "Los Angeles"); writeCASASetting("Bandit", "manager", "CASA Manager"); writeCASASetting("Bandit", "mail", "casa@novell.com"); writeCASASetting("Bandit", "telephoneNumber", "999-999-8888"); writeCASASetting("Bandit", "givenName", "CASA First name"); writeCASASetting("Bandit", "kBalance", "100000"); writeCASASetting("Bandit", "cn", "Casa"); writeCASASetting("Bandit", "title", "My House"); writeCASASetting("Bandit", "creditCard", "9999-8888-7777-6666"); writeCASASetting("Bandit", "salary", "The same as Steve Jobs"); } function writeCASASetting(sID, sKey, sValue) { var obj = getMiCASAStore(); try { res = obj.miCASAWriteKey(sID, sKey, sValue); } catch (err) { alert(err); } } function readTestKey() { readCASASetting("Bandit", "ldapdn"); readCASASetting("Bandit", "password"); } function readCASASetting(sID, sKey) { var obj = getMiCASAStore(); var theValue = new String(); logMessage("Reading from CASA: " + sKey); try { res = obj.miCASAReadKey(sID, sKey, theValue); logMessage("rcode:"+res + " sValue:"+theValue.value); } catch (err) { logMessage(err); } return theValue.value; } function getCASAData(arraySelected) { var htData = new java.util.Hashtable(); for (var i=0; i 0)) { htData.put(arraySelected[i], sValue); } } return htData; } function getPeristentPersona() { try { var props = loadMapFileAndReturnProps(); var sPersona = props.getProperty("CurrentPersona"); return sPersona; } catch (error) { return "home"; } } function setLocalPersona() { sCurrentPersona = "home"; changePersona(sCurrentPersona); if (bShowValues) { showAttribsWithValues(); } } function setEnterprisePersona() { sCurrentPersona = "work"; changePersona(sCurrentPersona); if (bShowValues) { showAttribsWithValues(); } } function setCombinedPersona() { sCurrentPersona = "joined"; changePersona(sCurrentPersona); if (bShowValues) { showAttribsWithValues(); } } function setCasaPersona() { sCurrentPersona = "CASA"; changePersona(sCurrentPersona); if (bShowValues) { showAttribsWithValues(); } } function displayCurrentPersona() { var curPersonaIDElement = document.getElementById("curPersonaID"); if (curPersonaIDElement != null) { curPersonaIDElement.value = sCurrentPersona; } } function changePersona(persona) { logMessage("Changing persona to: "+persona); try { var props = loadMapFileAndReturnProps(); props.setProperty("CurrentPersona", persona); storeProperties(props); } catch (err) { alert(err); } sCurrentPersona = persona; displayCurrentPersona(); } 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 showConsole() { var jvm = Components.classes["@mozilla.org/oji/jvm-mgr;1"].getService(Components.interfaces.nsIJVMManager); if (jvm != null) { jvm.showJavaConsole(); } else { logMessage("No JVM"); alert("No JVM"); } } function displayUserDir() { alert(java.lang.System.getProperty("user.dir")); } function displayUserHome() { alert(java.lang.System.getProperty("user.home")); } function displayJavaInfo() { alert("Version: " + java.lang.System.getProperty("java.version") + "\r\nClassPath: " + java.lang.System.getProperty("java.class.path")); } function storeProperties(props) { var userdir = java.lang.System.getProperty("user.dir"); logMessage("looking for namemap.properties in " + userdir); try { var os = java.io.FileOutputStream(userdir + "/namemap.properties"); props.store(os,null); os.close(); } catch (error) { alert(error); } } function loadMapFileAndReturnProps() { try { var userdir = java.lang.System.getProperty("user.dir"); logMessage("looking for namemap.properties in " + userdir); var is = java.io.FileInputStream(userdir + "/namemap.properties"); //alert(is); props = new java.util.Properties(); props.load(is); is.close(); logMessage(props); return props; } catch (ioerror) { logMessage(ioerror); } } function mapAttrib(sName) { if (sName == null) return; if (sName.indexOf('opt.')==0) { //sName = sName.substring(4); } if (props == null) { props = loadMapFileAndReturnProps(); if (props == null) { logMessage("did not load props"); return sName; } } var newName = props.getProperty(sName); //alert(newName); if (newName != null) { logMessage("found mapped name: " + newName); return newName; } else { logMessage("did not find mapped name: " + sName); return sName; } } function mapName(sName) { if (sName.indexOf('opt.')==0) { //sName = sName.subString(4); } switch (sName) { case "cn": return 'User_name'; break; case "mail": return 'Email_Address'; break; case "mailStop": return 'Post-office'; break; case "jobCode": return 'Job_Code'; break; case "costCenter": return 'Cost.Center'; break; case "givenName": return 'First_name'; break; case "workForceId": return 'EmployeID'; break; } return sName; } function handleIA(attribs) { var attribsRequested = attribs.split(','); var params = ''; for (var i=0; i= para.length) ; j++) { if((para.item(j).type == "password")) { ssosite = "yes"; logMessage("Password field"); logMessage(para.item(j).name); } /* var banditForm = window._content.document.getElementsByName("Bandit.Form"); if (banditForm != null) { alert("Found bandit form"); alert(banditForm.name); var inputs = banditForm.hasChildNodes(); alert(inputs); } */ if((para.item(j).type == "hidden") && (para.item(j).name == "bandit")) { handleIA(para.item(j).value); return; } } 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")) { password = ele.item(i).value; if (password.length > 0) { bIsLogin = 'true'; } else { break; } 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); } 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); } var bAllSelected = false; function toogleAllAttribsOptional() { var lstBoxOpt = document.getElementById('attribListOptional'); var bttnSelectAll = document.getElementById('selectall'); if (bAllSelected) { lstBoxOpt.clearSelection(); bAllSelected = false; bttnSelectAll.label = "Select All "; } else { lstBoxOpt.selectAll(); bAllSelected = true; bttnSelectAll.label = " Clear All"; } } function selectAllAttribsOptional() { var lstBoxOpt = document.getElementById('attribListOptional'); var bttnSelectAll = document.getElementById('selectall'); lstBoxOpt.selectAll(); bAllSelected = true; bttnSelectAll.label = " Clear All"; } function selectAllAttribs() { var lstBox = document.getElementById('attribList'); lstBox.selectAll(); } function getAllValues(arraySelected) { var sUser = readCASASetting("Bandit", "ldapdn"); var sPass = readCASASetting("Bandit", "password"); if (sUser != null) { logMessage("CASA returned:"+sUser); } else { logMessage("SecretID Bandit not found"); sUser = "cn=admin,o=novell"; } var htData; if (sCurrentPersona == "CASA") { htData = getCASAData(arraySelected); } else { try { logMessage(" ********* Calling IA"); htData = Packages.Jim.main2("cn=bandit1,o=Novell", sPass, null, sCurrentPersona, arraySelected); logMessage(" ******** Returned"); } catch (err) { logMessage(" ******** Error calling IA: " + err); } } return htData; } function toogleShowHide() { var bttn = document.getElementById('bttnShowValues'); clearBoxes(); if (bShowValues) { bShowValues = false; setAttribs(); if (bttn != null) { bttn.label = "Show Values"; } } else { bShowValues = true; showAttribsWithValues(); if (bttn != null) { bttn.label = "Hide Values"; } } } function showAttribsWithValues() { logMessage("showAttribsWithValues called"); bShowValues = true; sCurrentPersona = getPeristentPersona(); displayCurrentPersona(); var parentHost = opener._content.location.host; var label = document.getElementById('hostsite'); label.value = parentHost; var url = document.location.toString(); var sAttrib = ""; var sDisplay = ""; var lstBox = document.getElementById('attribList'); var lstBoxOpt = document.getElementById('attribListOptional'); var params = url.substring(url.indexOf('?')+1).split('&'); var csvRequested = ""; //collect requested attribs and query IA for values for (var i = 0; !(i > params.length - 1); i++) { sAttrib = params[i].substring(0, params[i].indexOf('=')); sDisplay = params[i].substring(params[i].indexOf('=')+1); if (sAttrib.length > 0) { if (sAttrib.indexOf('opt') == 0) { csvRequested += sAttrib.substring(4); } else { csvRequested += sAttrib; } } // append comma if (i < params.length -2) { csvRequested += ','; } } //alert(csvRequested); // query all values requested var arrayRequested = csvRequested.split(','); var htValues = getAllValues(arrayRequested); //alert(htValues); // clear the current listboxes clearBoxes(); var sCurrentValue = ''; for (var i = 0; !(i > params.length - 1); i++) { sAttrib = params[i].substring(0, params[i].indexOf('=')); sDisplay = params[i].substring(params[i].indexOf('=')+1); if (sAttrib.length > 0) { // reset sCurrentValue sCurrentValue = ''; if (sAttrib.indexOf('opt') == 0) { sCurrentValue = htValues.get(sAttrib.substring(4)); if (sCurrentValue != null) { sCurrentValue = " (" + sCurrentValue + ")"; } else { sCurrentValue = ''; } lstBoxOpt.appendItem(mapAttrib(sDisplay.substring(4)) + sCurrentValue, sAttrib.substring(4)); } else { //alert("getting: " + sAttrib); //alert(htValues); sCurrentValue = htValues.get(sAttrib); if (sCurrentValue != null) { sCurrentValue = " (" + sCurrentValue + ")"; } else { sCurrentValue = ''; } lstBox.appendItem(sDisplay + sCurrentValue, sAttrib); } } } selectAllAttribs(); centerPrompt(); } function clearBoxes() { // clear required var lstBox = document.getElementById('attribList'); for (var i=lstBox.getRowCount(); i>0; i--) { lstBox.removeItemAt(i-1); } // clear optional lstBox = document.getElementById('attribListOptional'); for (var i=lstBox.getRowCount(); i>0; i--) { lstBox.removeItemAt(i-1); } } function setAttribs() { logMessage("setAttribs called"); sCurrentPersona = getPeristentPersona(); changePersona(sCurrentPersona); var parentHost = opener._content.location.host; var label = document.getElementById('hostsite'); label.value = parentHost; var url = document.location.toString(); var sAttrib = ""; var sDisplay = ""; var lstBox = document.getElementById('attribList'); var lstBoxOpt = document.getElementById('attribListOptional'); var params = url.substring(url.indexOf('?')+1).split('&'); for (var i = 0; !(i > params.length - 1); i++) { sAttrib = params[i].substring(0, params[i].indexOf('=')); sDisplay = params[i].substring(params[i].indexOf('=')+1); if (sAttrib.length > 0) { if (sAttrib.indexOf('opt') == 0) { lstBoxOpt.appendItem(mapAttrib(sDisplay.substring(4)), sAttrib.substring(4)); } else { lstBox.appendItem(sDisplay, sAttrib); } } } selectAllAttribs(); centerPrompt(); } function getSelectedPersona() { var personaLst = document.getElementById('theList'); var personaSelected = personaLst.selectedItems; return personaSelected[0].value } function getSelectedAttribsOptional() { var lstBox = document.getElementById('attribListOptional'); var selected = lstBox.selectedItems; return selected; } function displaySelectedAttribsOptional() { var selected = getSelectedAttribsOptional(); for (var i=0; i 0)) { var repostURL = opener._content.location + "?"; var keys = htData.keys(); while (keys.hasMoreElements()) { var sKey = keys.nextElement(); var sValue = htData.get(sKey); repostURL += (sKey + "=" + sValue); if (keys.hasMoreElements()) repostURL += "&"; } opener._content.location = repostURL; } // close this window window.close(); } 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 { if (sValue.length > 0) { logMessage('Writing ' + secretID + '[' + secretID.length + '] : ' + 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) ;