forked from yogeshmundada/appu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblacklist.js
More file actions
89 lines (71 loc) · 2.77 KB
/
blacklist.js
File metadata and controls
89 lines (71 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function pii_add_blacklisted_sites(message) {
var dnt_site = message.dnt_site;
var r = {};
if (pii_vault.options.blacklist.indexOf(dnt_site) == -1) {
pii_vault.options.blacklist.push(dnt_site);
r.new_entry = dnt_site;
}
else {
r.new_entry = null;
}
console.log("New blacklist: " + pii_vault.options.blacklist);
vault_write("options:blacklist", pii_vault.options.blacklist);
return r;
}
function pii_check_blacklisted_sites(message) {
var r = {};
r.blacklisted = "no";
//console.log("Checking blacklist for site: " + message.domain);
for (var i = 0; i < pii_vault.options.blacklist.length; i++) {
var protocol_matched = "yes";
var port_matched = "yes";
var bl_url = pii_vault.options.blacklist[i];
//Split URLs, simplifying assumption that protocol is only HTTP.
var url_parts = bl_url.split('/');
var bl_hostname = "";
var bl_protocol = "";
var bl_port = "";
bl_hostname = ((url_parts[0].toLowerCase() == 'http:' ||
url_parts[0].toLowerCase() == 'https:')) ? url_parts[2] : url_parts[0];
bl_protocol = ((url_parts[0].toLowerCase() == 'http:' ||
url_parts[0].toLowerCase() == 'https:')) ? url_parts[0].toLowerCase() : undefined;
bl_port = (bl_hostname.split(':')[1] == undefined) ? undefined : bl_hostname.split(':')[1];
var curr_url_parts = message.domain.split('/');
var curr_hostname = "";
var curr_protocol = "";
var curr_port = "";
curr_hostname = ((curr_url_parts[0].toLowerCase() == 'http:' ||
curr_url_parts[0].toLowerCase() == 'https:')) ? curr_url_parts[2] : curr_url_parts[0];
curr_protocol = ((curr_url_parts[0].toLowerCase() == 'http:' ||
curr_url_parts[0].toLowerCase() == 'https:')) ? curr_url_parts[0].toLowerCase() : '';
curr_port = (curr_hostname.split(':')[1] == undefined) ? '' : curr_hostname.split(':')[1];
rev_bl_hostname = bl_hostname.split("").reverse().join("");
rev_curr_hostname = curr_hostname.split("").reverse().join("");
if (bl_protocol && (curr_protocol != bl_protocol)) {
protocol_matched = "no";
}
if (bl_port && (curr_port != bl_port)) {
port_matched = "no";
}
//First part of IF checks if the current URL under check is a
//subdomain of blacklist domain.
if ((rev_curr_hostname.indexOf(rev_bl_hostname) == 0) &&
protocol_matched == "yes" && port_matched == "yes") {
r.blacklisted = "yes";
console.log("Site is blacklisted: " + message.domain);
break;
}
}
return r;
}
function pii_get_blacklisted_sites(message) {
var r = [];
for (var i = 0; i < pii_vault.options.blacklist.length; i++) {
r.push(pii_vault.options.blacklist[i]);
}
return r;
}
function pii_delete_dnt_list_entry(message) {
pii_vault.options.blacklist.splice(message.dnt_entry, 1);
vault_write("options:blacklist", pii_vault.options.blacklist);
}