Skip to content

Commit

Permalink
adding company tree and token analyzier
Browse files Browse the repository at this point in the history
  • Loading branch information
konarkmodi committed May 12, 2019
1 parent 35b18c3 commit aa82c01
Show file tree
Hide file tree
Showing 9 changed files with 21,212 additions and 163 deletions.
190 changes: 174 additions & 16 deletions background.js

Large diffs are not rendered by default.

85 changes: 42 additions & 43 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const db = new Dexie('localSheriff');
const dbCookie = new Dexie('localSheriffCookieTable');

db.version(1).stores({
reftp: '++id, ref, tp',
refhtml: '++id, ref, html',
tpurl: '++id, tpurl',
inputFields: '++id, value, sender, details',
inputFieldsCache: '++id, value, summary',
tpURLFP: '++id, tpurl, details'
reftp: '++id, ref, tp',
refhtml: '++id, ref, html',
tpurl: '++id, tpurl',
inputFields: '++id, value, sender, details',
inputFieldsCache: '++id, value, summary',
tpURLFP: '++id, tpurl, details'
});

// Save cookies
Expand All @@ -20,71 +20,70 @@ dbCookie.version(1).stores({
});

db.open().then(function (db) {
// Database opened successfully
console.log(" DB connection successful.");
loadFromDatabase();
}).catch (function (err) {
// Error occurred
console.log("Error occurred while opening DB." + err);
// Database opened successfully
console.log(" DB connection successful.");
loadFromDatabase();
}).catch(function (err) {
// Error occurred
console.log("Error occurred while opening DB." + err);
});

// Access cookie table:
dbCookie.open().then(function (dbCookie) {
// Database opened successfully
console.log(" DB connection successful.");
loadCookiesFromDatabase();
}).catch (function (err) {
// Error occurred
console.log("Error occurred while opening DB." + err);
// Database opened successfully
console.log(" DB connection successful.");
loadCookiesFromDatabase();
}).catch(function (err) {
// Error occurred
console.log("Error occurred while opening DB." + err);
});

// Currently dumping complete objects every 2 minutes.

function dump() {
console.log("Dumping data to disk");
db.reftp.add(JSON.stringify(refTP), 'raw');
db.refhtml.add({refhtml: JSON.stringify(refHTML)});
db.tpurl.add({tpurl: JSON.stringify(tpURL)});
db.refhtml.add({ refhtml: JSON.stringify(refHTML) });
db.tpurl.add({ tpurl: JSON.stringify(tpURL) });
}

// When extension starts try to load data from disk.
function load(obj, key) {
db[key].get(key).then(e => {
if(e) obj = JSON.parse(e);
if (e) obj = JSON.parse(e);
});
}

function saveInDB(ref, tp) {
console.log("saving");
db.reftp.add({ref: ref,tp: tp});
db.reftp.add({ ref: ref, tp: tp });
}

function saveHTML(ref, html) {
db.refhtml.add({ref: ref,html: html});
db.refhtml.add({ ref: ref, html: html });
}

function savetpList(tpurl) {
db.tpurl.add({tpurl: tpurl});
db.tpurl.add({ tpurl: tpurl });
}

function saveInputFields(value, sender, details) {
db.inputFields.add({value: value, sender: sender, details: details});
db.inputFields.add({ value: value, sender: sender, details: details });
}

function saveInputFieldsCache(value, summary) {
db.inputFieldsCache.add({value: value, summary: summary});
db.inputFieldsCache.add({ value: value, summary: summary });
}

function savetpURLFP(tpurl, details) {
db.tpURLFP.add({tpurl: tpurl, details: details});
db.tpURLFP.add({ tpurl: tpurl, details: details });
}

function saveCookies(url, details) {
dbCookie.cookietable.add({url: url, details: details});
dbCookie.cookietable.add({ url: url, details: details });
}

function loadFromDatabase() {
db.reftp.each(row => {addToDict(row.ref, row.tp, 'load')});
db.reftp.each(row => { addToDict(row.ref, row.tp, 'load') });

db.refhtml.each(row => {
if (!refHTML.hasOwnProperty(row.ref)) {
Expand All @@ -100,51 +99,51 @@ function loadFromDatabase() {
db.inputFields.each(row => {
if (!inputFields.hasOwnProperty(row.value)) inputFields[row.value] = {};
if (!inputFields[row.value].hasOwnProperty(row.sender)) inputFields[row.value][row.sender] = {};
inputFields[row.value][row.sender] = row.details;
inputFields[row.value][row.sender] = row.details;
});

db.inputFieldsCache.each( row => {
db.inputFieldsCache.each(row => {
inputFieldsCache[row.value] = row.summary;
});

db.tpURLFP.each( row => {
db.tpURLFP.each(row => {
thirdPartyFP[row.tpurl] = row.details;
});
}

function loadCookiesFromDatabase() {
dbCookie.cookietable.each( row => {
dbCookie.cookietable.each(row => {
cookieTable[row.url] = row.details;
});
}

function cleanLSDB() {
// Clean local-sheriff DB.
return db.delete().then(() => {
console.log("Local-sheriff Database successfully deleted");
Promise.resolve(true);
console.log("Local-sheriff Database successfully deleted");
Promise.resolve(true);
}).catch((err) => {
console.error("Could not delete cookie database: " + err);
Promise.reject(false);
console.error("Could not delete cookie database: " + err);
Promise.reject(false);
});
}

function cleanCookieDB() {
// Clean local-sheriff DB.
return dbCookie.delete().then(() => {
console.log("Cookie Database successfully deleted");
Promise.resolve(true);
console.log("Cookie Database successfully deleted");
Promise.resolve(true);
}).catch((err) => {
console.error("Could not delete cookie database: " + err);
Promise.reject(false);
console.error("Could not delete cookie database: " + err);
Promise.reject(false);
});
}

function cleanStorage() {

// Clean databases and then re-load the extension.

Promise.all([cleanLSDB(), cleanCookieDB()]).then( status => {
Promise.all([cleanLSDB(), cleanCookieDB()]).then(status => {
chrome.runtime.reload();
}).catch(console.log);
}
85 changes: 81 additions & 4 deletions scripts/control-panel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
function safeHTML(str) {
const temp = document.createElement('div');
temp.textContent = str;
return temp.innerHTML;
};


// Change icon which shows it's recording.
function start_recording() {
// We need to store the pref. to keep track.
Expand All @@ -7,10 +14,9 @@ function start_recording() {
}
chrome.storage.local.set(saveObject, e => {
console.log("State changed. It's recording now.");
chrome.browserAction.setIcon({path: '../icons/green-38.png'});
chrome.browserAction.setIcon({ path: '../icons/green-38.png' });
document.getElementById('start-recording').style.display = 'none';
document.getElementById('stop-recording').style.display = 'block';
console.log(">>>>>> var >>" + status);
const additionalInfo = {
type: 'recording',
recordingStatus: recordingState
Expand All @@ -29,7 +35,7 @@ function stop_recording() {
}
chrome.storage.local.set(saveObject, e => {
console.log("State changed. It's not recording now.");
chrome.browserAction.setIcon({path: '../icons/tool-icon-38.png'});
chrome.browserAction.setIcon({ path: '../icons/tool-icon-38.png' });
document.getElementById('stop-recording').style.display = 'none';
document.getElementById('start-recording').style.display = 'block';

Expand All @@ -40,4 +46,75 @@ function stop_recording() {

chrome.runtime.sendMessage(additionalInfo);
});
}
}

// Listener of headings to display or hide.
function loadListeners() {
document.getElementById("h-input-fields-summary").addEventListener("click", function (e) {
const style = document.getElementById('input-fields-summary').style.display;

if (style === 'none') {
document.getElementById('input-fields-summary').style.display = 'block';
} else {
document.getElementById('input-fields-summary').style.display = 'none';
}
});

// poi
document.getElementById("h-poi-summary").addEventListener("click", function (e) {
const style = document.getElementById('poi-summary').style.display;

if (style === 'none') {
// Let's get the values that can be used for tracking a user.
const additionalInfoIFL = {
type: 'checkTrackingValues'

}

chrome.runtime.sendMessage(additionalInfoIFL, e => {
console.log(e);
e.response.forEach((y, idx) => {
console.log(y);
const safeY = safeHTML(y);
const fields_summary = document.getElementById('poi-summary');
// Info leaked.
const code = document.createElement('code');
code.textContent = `${safeY}:`;
fields_summary.appendChild(code);

const btn = document.createElement('button');
btn.textContent = 'Yes';
btn.value = `${safeY}`;
btn.id = `input-details-${idx}`;
btn.className = 'label label-danger';
fields_summary.appendChild(btn);
fields_summary.appendChild(document.createElement('br'));

// This is a very inefficient way of adding a listener. But keeping it like this for now.
Object.keys(e.response).forEach((y, idx) => {
if (document.getElementById(`input-details-${idx}`)) {
document.getElementById(`input-details-${idx}`).removeEventListener("click", function (e) {

});

document.getElementById(`input-details-${idx}`).addEventListener("click", function () {
inputSearch(document.getElementById(`input-details-${idx}`).value, "tracking_id");
});
}
});
});
});
document.getElementById('poi-summary').style.display = 'block';
} else {
document.getElementById('poi-summary').style.display = 'none';
}
});

// company.
document.getElementById("h-company-summary").addEventListener("click", function (e) {
const style = document.getElementById('company-summary').style.display;
window.open('./company-tree.html');
});
}

window.setTimeout(loadListeners, 1000);
Loading

0 comments on commit aa82c01

Please sign in to comment.