Skip to content

Commit

Permalink
Mise à jour vers cookieviz 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LaboCNIL committed Jun 2, 2022
1 parent 78c2212 commit ad17c80
Show file tree
Hide file tree
Showing 23 changed files with 1,040 additions and 646 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
/node_modules
/package-lock.json
/launch.bat
/launch.sh
/package.sh
.DS_Store
.vscode/launch.json
node_modules/
130 changes: 56 additions & 74 deletions analyses/favicons.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const psl = require('psl');
const getFavicons = require('get-website-favicon');
var favicons ={};

const favicons_table_column = {
"favicons": [
"website"
]
}

const favicons_stored = [];

function extractHostname(url, keep_protocol) {
let hostname;

if (!url) return "";

//find & remove protocol (http, ftp, etc.) and get hostname
if (url.indexOf("//") > -1) {
hostname = url.split('/')[2];
}
else
{
else {
hostname = url.split('/')[0];
}

//find & remove port number
hostname = hostname.split(':')[0];
//find & remove "?"
Expand All @@ -26,101 +32,77 @@ function extractHostname(url, keep_protocol) {


function processFaviconRequest(requestdetails) {
if (!db) return;

//Parsing all cookies
let initiator = psl.get(extractHostname(requestdetails.initiator));
let request_url = psl.get(extractHostname(requestdetails.url));

function checkFavicon(request) {
if (request in favicons) {
return;
}
favicons[request] = null;
getFavicons(request).then(data => {
db.transaction(function (tx) {
const insert_query = 'INSERT OR IGNORE INTO favicons (website, favicon) VALUES (?,?)';
if (data.icons.length > 0) {
favicons[request] = data.icons[0].src;
tx.executeSql(insert_query, [request, data.icons[0].src]);
} else {
tx.executeSql(insert_query, [request, null]);
}
});
});
favicons_stored.push(request);
let txn = db.transaction(["favicons"], 'readonly');
let objectStore = txn.objectStore('favicons');
var index = objectStore.index('website');

index.get(request).onsuccess = function (event) {
var cursor = event.target.result;
if (cursor) {
return;
} else {
getFavicons(request).then(data => {
if (data.icons.length > 0) {
WriteToDb("favicons", { website: request, favicon: data.icons[0].src });
} else {
WriteToDb("favicons", { website: request, favicon: null });
}
});
}
};
}

if (initiator) checkFavicon(initiator);
if (request_url) checkFavicon(request_url);
if (initiator && !favicons_stored.includes(initiator)) checkFavicon(initiator);
if (request_url && !favicons_stored.includes(request_url)) checkFavicon(request_url);
}

function initFaviconCrawler(){
db.transaction(function (tx) {
tx.executeSql(`CREATE TABLE IF NOT EXISTS favicons (
website varchar(255) UNIQUE NOT NULL,
favicon varchar(255)
)`);

}, errorHandler);

db.transaction(function (tx) {
const load_query = 'SELECT * FROM favicons';
tx.executeSql(load_query, [], async function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
const row = results.rows.item(i);
favicons[row['website']]= row['favicon'];
}
});
});

function initFaviconCrawler() {
// Read cookie
chrome.webRequest.onBeforeSendHeaders.addListener(processFaviconRequest, {
urls: ["*://*/*"]
}, []
);
}

function deleteFaviconCrawler(){
function deleteFaviconCrawler() {
chrome.webRequest.onBeforeSendHeaders.removeListener(processFaviconRequest);
}

async function cleanFaviconTrigger(){
async function get_all_favicons() {
return new Promise((resolve, reject) => {
db.transaction(function (tx) {
tx.executeSql("DELETE FROM favicons", [], function(tx){
favicons = {};
resolve();
});
});
});
}

async function get_all_favicons(){
return new Promise((resolve, reject) => {
db.transaction(function (tx) {
const load_query = 'SELECT * FROM favicons';
tx.executeSql(load_query, [], async function (tx, results) {
const favicons = {};
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
const row = results.rows.item(i);
favicons[row['website']]= row['favicon'];
}
const favicons = {};
let txn = db.transaction(["favicons"], 'readonly');
const objectStore = txn.objectStore("favicons");
objectStore.openCursor().onsuccess = function (event) {
var cursor = event.target.result;
if (cursor) {
favicons[cursor.value.website]= cursor.value.favicon;
cursor.continue();
} else {
resolve(favicons);
});
});
}, errorHandler);
}
}
});
}


// Template for plugins
const plugins_favicon = {
name : "favicons",
description : "This plugins stores favicons of every website that send/receive requests",
author:"linc",
init:initFaviconCrawler,
delete:deleteFaviconCrawler,
clean:cleanFaviconTrigger,
data:{
name: "favicons",
description: "This plugins stores favicons of every website that send/receive requests",
author: "linc",
tables: favicons_table_column,
init: initFaviconCrawler,
delete: deleteFaviconCrawler,
data: {
"get_all_favicons": get_all_favicons
}
}
Expand Down
Loading

0 comments on commit ad17c80

Please sign in to comment.