home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 101
/
FreelogNo101-JanvierFevrier2011.iso
/
Securite
/
Passter
/
Passter.exe
/
content.js
< prev
next >
Wrap
Text File
|
2010-10-26
|
9KB
|
251 lines
/* ------------------------------------------------------------------------------------ */
/* Copyright (c) 2010 PASSTER.COM. All rights reserved. */
/* This software and all information contained therein is confidential and */
/* proprietary and shall not be duplicated, used, disclosed or disseminated in any */
/* way except as authorized by the applicable license agreement, without the */
/* express written permission of PASSTER.COM. All authorized reproductions must be */
/* marked with this language. */
/* */
/* EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE */
/* EXTENT PERMITTED BY APPLICABLE LAW, PASSTER.COM PROVIDES THIS SOFTWARE */
/* WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY */
/* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR */
/* PURPOSE. IN NO EVENT WILL PASSTER.COM BE LIABLE TO THE END USER OR ANY */
/* THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE */
/* USE OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, LOST PROFITS, */
/* BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF PASSTER.COM IS */
/* EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE. */
/* ------------------------------------------------------------------------------------ */
chrome.extension.sendRequest({"init":true});
//$(document).ready(function() {
function formSubmit() {
formSubmit(null);
}
function formSubmit(frm) {
console.log("Submitting form: " + frm.id);
var msg = buildFormFields(frm, "pwdForm", true);
if (msg && msg.pwdForm[0].username) {
console.log("Form fields were built - submit");
chrome.extension.sendRequest(msg);
}
return true;
}
function getPasswordFields (form, skipEmptyFields) {
// Locate the password fields in the form.
var pwFields = [];
for (var i = 0; i < form.elements.length; i++) {
if (form.elements[i].type != "password")
continue;
if (skipEmptyFields && !form.elements[i].value)
continue;
pwFields[pwFields.length] = {
index : i,
element : form.elements[i]
};
}
// If too few or too many fields, bail out.
if (pwFields.length == 0) {
console.log("(form ignored -- no password fields.)");
return null;
} else if (pwFields.length > 3) {
console.log("(form ignored -- too many password fields. [got " +
pwFields.length + "])");
return null;
}
return pwFields;
}
function getFormFields (form, isSubmission) {
var usernameField = null;
// Locate the password field(s) in the form. Up to 3 supported.
// If there's no password field, there's nothing for us to do.
var pwFields = getPasswordFields(form, isSubmission);
if (!pwFields)
return [null, null, null];
// Locate the username field in the form by searching backwards
// from the first passwordfield, assume the first text field is the
// username. We might not find a username field if the user is
// already logged in to the site.
for (var i = pwFields[0].index - 1; i >= 0; i--) {
if (form.elements[i].type == "text") {
usernameField = form.elements[i];
break;
}
}
if (!usernameField)
console.log("(form -- no username field found)");
// If we're not submitting a form (it's a page load), there are no
// password field values for us to use for identifying fields. So,
// just assume the first password field is the one to be filled in.
if (!isSubmission || pwFields.length == 1)
return [usernameField, pwFields[0].element, null];
// Try to figure out WTF is in the form based on the password values.
var oldPasswordField, newPasswordField;
var pw1 = pwFields[0].element.value;
var pw2 = pwFields[1].element.value;
var pw3 = (pwFields[2] ? pwFields[2].element.value : null);
if (pwFields.length == 3) {
// Look for two identical passwords, that's the new password
if (pw1 == pw2 && pw2 == pw3) {
// All 3 passwords the same? Weird! Treat as if 1 pw field.
newPasswordField = pwFields[0].element;
oldPasswordField = null;
} else if (pw1 == pw2) {
newPasswordField = pwFields[0].element;
oldPasswordField = pwFields[2].element;
} else if (pw2 == pw3) {
oldPasswordField = pwFields[0].element;
newPasswordField = pwFields[2].element;
} else if (pw1 == pw3) {
// A bit odd, but could make sense with the right page layout.
newPasswordField = pwFields[0].element;
oldPasswordField = pwFields[1].element;
} else {
// We can't tell which of the 3 passwords should be saved.
console.log("(form ignored -- all 3 pw fields differ)");
return [null, null, null];
}
} else { // pwFields.length == 2
if (pw1 == pw2) {
// Treat as if 1 pw field
newPasswordField = pwFields[0].element;
oldPasswordField = null;
} else {
// Just assume that the 2nd password is the new password
oldPasswordField = pwFields[0].element;
newPasswordField = pwFields[1].element;
}
}
return [usernameField, newPasswordField, oldPasswordField];
}
function removeDomainPrefix(domain) {
var result = domain;
if (domain.indexOf("www.") == 0)
result = domain.substring(4);
return result;
}
var domain = removeDomainPrefix(window.location.hostname);
chrome.extension.sendRequest({"domain":domain});
$("link[rel='shortcut icon']").each(function () { chrome.extension.sendRequest({"domainIcon":this.href}); } );
var pwdFields = $("input:password");
if (pwdFields && pwdFields.length > 0) {
// first send notification of password fields
console.log("found some password fields");
var pwdFieldsArr = buildIdNameFieldArr(pwdFields);
var domain = removeDomainPrefix(window.location.hostname);
chrome.extension.sendRequest({"password":true, "pwdFields":pwdFieldsArr, "domain":domain});
if (document.getElementsByTagName) {
elementsForms = document.getElementsByTagName("form");
console.log("found " + elementsForms.length + " forms in the page");
// send notification of form fields
$('form').each(function() {
console.log("Processing form: " + this.id);
var msg = null;
msg = buildFormFields(this, "detectedPwdForm", false);
if (msg) {
console.log("Form fields were built - detect");
chrome.extension.sendRequest(msg);
}
$(this).change(function() {
var msg = buildFormFields(this, "pwdChgForm", true);
if (msg && msg.pwdForm[0].username) {
chrome.extension.sendRequest(msg);
}
});
var org = this.onsubmit;
this.onsubmit = function() {
formSubmit(this);
var result = true;
if (org) {
result = org();
}
return result;
};
$(':input').each( function () {
$(this).submit( function () {
$(this).attr('form').onsubmit();
});
});
});
$("form a").each(function() {
var aObj = this;
var org = this.onclick;
var form = $(this).parents("form");
form.each( function () {
var frmSubmit = this;
aObj.onclick = function () {
formSubmit(frmSubmit);
if (org) {
org();
}
}
});
});
} else {
console.log("did not find any form elements, can't continue...");
}
} else {
// no password fields
console.log("did not find any password fields");
chrome.extension.sendRequest({"password":false});
}
function buildIdNameFieldArr(fields) {
var arr = new Array();
for (var i = 0; i < fields.length; i++) {
var json = {"id":fields[i].id,"name":fields[i].name};
arr.push(json);
}
return arr;
}
function buildFormFields(frm, type, isSubmit) {
var msg = null;
var action = frm.getAttribute("action");
if (!action) {
action = "";
}
// search for the username and password in the form
var frmFields = getFormFields(frm, isSubmit);
if (frmFields && frmFields.length == 3 && frmFields[1] != null ) {
var username = (frmFields[0]?frmFields[0].value:"");
var password1 = (frmFields[1]?frmFields[1].value:"");
var password2 = (frmFields[2]?frmFields[2].value:"");
var usernameElement = (frmFields[0] && frmFields[0].id?frmFields[0].id:(frmFields[0]?frmFields[0].name:""));
var password1Element = (frmFields[1] && frmFields[1].id?frmFields[1].id:(frmFields[1]?frmFields[1].name:""));
var password2Element = (frmFields[2] && frmFields[2].id?frmFields[2].id:(frmFields[2]?frmFields[2].name:""));
var title = document.title;
var url = document.location.href;
var domain = removeDomainPrefix(window.location.hostname);
var date = new Date();
msg = {"type" : type, "pwdForm" : [{"username" : username, "password1" : password1, "password2" : password2, "usernameElm" : usernameElement, "password1Elm" : password1Element, "password2Elm" : password2Element, "url" : url, "domain" : domain, "title" : title, "action" : action, "touch" : date.getTime()}]};
}
return msg;
}
//});