From c973e3647c36c39a779ac1a3c5f69385566cf3cb Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Fri, 19 May 2006 19:56:29 +0000 Subject: [PATCH] Bug 176348. Submit the correct form for autologin. --- .../common/casajar/content/casaOverlay.js | 68 +++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/extensions/common/casajar/content/casaOverlay.js b/extensions/common/casajar/content/casaOverlay.js index eda9f407..df001536 100644 --- a/extensions/common/casajar/content/casaOverlay.js +++ b/extensions/common/casajar/content/casaOverlay.js @@ -3,6 +3,8 @@ var bGlobalPrompt = 'true'; var consoleService = null; +var loginCounter = 0; +var sAttemptedHost = ''; function logMessage(message) { @@ -37,17 +39,19 @@ function websso() logMessage("Host URL not found"); return; } - // reset loginprompt bGlobalPrompt = 'true'; - var para=window._content.document.getElementsByTagName("input"); + 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); } } @@ -102,7 +106,7 @@ function websso() } - + var formToSubmit; // looping for inputs and setting the correct values for (var j = 0; !(j >= para.length) ; j++) @@ -110,8 +114,7 @@ function websso() try { if((para.item(j).type == "text") || (para.item(j).type == "password")) - { - //alert(test); + { sKey = para.item(j).name; logMessage('Getting: ' + secretId + ':' + sKey); @@ -126,6 +129,20 @@ function websso() 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) @@ -140,14 +157,41 @@ function websso() res = obj.miCASAReadKey(secretId, 'autologin', theValue); if (theValue.value == 'true') { - logMessage('Autologin begins'); - window._content.document.forms[0].submit(); + // 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); } } } @@ -159,7 +203,7 @@ function promptuser() var password = ""; var bIsLogin = 'false'; var sPromptURL = "chrome://casa/content/prompt.xul?"; - var ele=window._content.document.getElementsByTagName("input"); + var ele=window._content.document.getElementsByTagName("input"); var secretID = window._content.location.host; if (bGlobalPrompt != 'true') @@ -177,7 +221,7 @@ function promptuser() { bIsLogin = 'true'; password = ele.item(i).value; - sPromptURL = sPromptURL + "&" + ele.item(i).name + "=" + 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 @@ -228,7 +272,7 @@ function promptuser() } 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";