adblock v2: update to 2.72b

arm-master
pedro 2 years ago
parent 4096f95d3e
commit e3799f9cb4

@ -1,14 +1,14 @@
#!/bin/sh
# Adblock (a.k.a. DNS-filtering) FreshTomato GUI back-end
ver="v2.72 - 04/23" # rs232
ver="v2.72b - 04/23" # rs232
PID=$$
pidfile="/var/run/adblock.pid"
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/root:
pre=$(date +%s)
alias only="sed -e 's/^[ \t]*//' | grep -Ev '^($|#|!)'"
alias only="sed -e 's/^[ \t]*//' | grep -Ev '^($|#|!)' | sort"
hashblack() {
hb="=B+ $(nvram get adblock_blacklist) $(nvram get adblock_enable) $(nvram get adblock_path) $(nvram get adblock_limit) =BC+ $(nvram get adblock_blacklist_custom | only ) =BCF+"
hb="=B+ $(nvram get adblock_blacklist | tr '>' '\n' | grep -E ^1 | cut -d/ -f3- | sort | cut -f1 -d'<') $(nvram get adblock_enable) $(nvram get adblock_path) $(nvram get adblock_limit) =BC+ $(nvram get adblock_blacklist_custom | only ) =BCF+"
for i in $(nvram get adblock_blacklist_custom | only | grep -E ^/ ); do hb="$hb $(cat ${i} | only )"; done
echo $hb | tr " " "\n" | grep -Ev '^($|#|!)'
}
@ -301,7 +301,7 @@ download() {
} || {
grep -q -E '^https?://' "$D/${uriname}.list" && {
# List of lists
logn "[$COUNT][$URL] List-of-lists (List of URLs) format >> Parsing..."
logn "[$COUNT][$URL] Group-of-lists (List of URLs) format >> Parsing..."
grep -E '^https?://' "$D/${uriname}.list" | awk '{print $1}'| while read u; do
SUBLIST=$((SUBLIST+1))
urinamed=$(echo "$u" | md5sum | awk '{print $1}')
@ -417,9 +417,9 @@ download() {
subsed="$subsed ${i}"
done
# Whitelist domains defined in list-of-lists content
# Whitelist domains defined in Group-of-lists content
[[ -f $PREFIX/white.url ]] && {
logd "Whitelisting domains found in list-of-lists URLs"
logd "Whitelisting domains found in Group-of-lists URLs"
for i in $(grep -Eo '((([a-zA-Z]{1,2})|([0-9]{1,2})|([a-zA-Z0-9]{1,2})|([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]))\.)+[a-zA-Z]{2,6}\s*/\s*' $PREFIX/white.url | tr "/" " "); do
subsed="$subsed ${i}"
done

@ -2,7 +2,7 @@
<!--
Tomato GUI
Copyright (C) 2007-2022 FreshTomato
ver="v2.72 - 01/23" # rs232
ver="v2.72b - 04/23" # rs232
https://www.freshtomato.org/
For use with Tomato Firmware only.
No part of this file may be used without permission.
@ -11,7 +11,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="robots" content="noindex,nofollow">
<title>[<% ident(); %>] Advanced: Adblock (DNS resolution filtering)</title>
<title>[<% ident(); %>] Advanced: Adblock (DNS filtering)</title>
<link rel="stylesheet" type="text/css" href="tomato.css">
<% css(); %>
<script src="tomato.js"></script>
@ -152,6 +152,76 @@ function earlyInit() {
adblockg.setup();
verifyFields(null, true);
}
/* Determine Delimiter/Separator */
function determineDelimiter(inputString) {
const lines = inputString.split(/\r?\n/);
let isSpaceDelimited = false;
var i = 0
for (const line of lines) {
const trimmedLine = line.trim();
if (trimmedLine.startsWith('#') || trimmedLine === '') {
continue;
}
const units = trimmedLine.split(' ');
if (units.length > 1) {
return ' ';
}
else if (i > 1) {
return '\n';
}
i += 1;
}
}
/* Sort Domains */
function sortDomains(element) {
var textarea = document.getElementById(element);
var delimiter = determineDelimiter(textarea.value.trim());
var splitDomains = textarea.value.split(delimiter).map((domain) => domain.trim().split(".").reverse());
const regex = /[%!#+\s]/g
splitDomains.sort((a, b) => {
const aList = a.map(item => item.replace(regex, ''));
const bList = b.map(item => item.replace(regex, ''));
var aSeg = aList[1], bSeg = bList[1];
if ( aSeg === undefined || bSeg === undefined) { return 0; }
if (a.length > 2 && aList[0].length === 2 && aSeg.length <= 3)
aSeg = aList[2];
if (b.length > 2 && bList[0].length === 2 && bSeg.length <= 3)
bSeg = bList[2];
var domainCompare = aSeg.toLowerCase().localeCompare(bSeg.toLowerCase());
if (domainCompare !== 0) return domainCompare;
var tldCompare = aList[0].toLowerCase().localeCompare(bList[0].toLowerCase());
if (tldCompare !== 0) return tldCompare;
var i = 1;
while ( true ) {
var aSeg = aList[i], bSeg = bList[i];
if (aSeg === undefined && bSeg === undefined) {
return 0;
}
else if (aSeg === undefined) {
return -1;
}
else if (bSeg === undefined) {
return 1;
}
var subCompare = aSeg.toLowerCase().localeCompare(bSeg.toLowerCase());
if (subCompare !== 0) return subCompare;
i += 1;
}
});
var sortedDomains = splitDomains.map((segments) => segments.reverse().join("."));
textarea.value = sortedDomains.join(delimiter).trim();
}
</script>
</head>
@ -178,7 +248,7 @@ function earlyInit() {
<!-- / / / -->
<div class="section-title">Adblock (DNS resolution filtering) - Settings</div>
<div class="section-title">Adblock (DNS filtering) - Settings</div>
<div class="section">
<div class="section">
<script>
@ -193,29 +263,31 @@ function earlyInit() {
<!-- / / / -->
<div class="section-title">Domain blacklist URLs & List-of-lists</div>
<div class="section-title">Domain blacklist URLs & Group-of-lists</div>
<div class="section">
<div class="tomato-grid" id="adblock-grid"></div>
</div>
<!-- / / / -->
<div class="section-title">Domain blacklist custom</div>
<div class="section-title">Domain blacklist custom</div><input type="button" value="Sort domains backward a-z ↓" onclick="sortDomains('domain-blacklist')" id="sort-button-blacklist" style="float: right;">
<div class="section">
<script>
createFieldTable('', [
{ title: 'Individual blacklisted domains and/or the path to external file/s containing domain references only.<br>Domains defined with a prepending <b>+<\/b> will have any found subdomain pruned from the blockfile.<br>Prepend <b>#<\/b> to quote a line.', name: 'adblock_blacklist_custom', type: 'textarea', placeholder: 'baddomain.com&#10;/mnt/usb/list-of-bad-domains.list&#10;/mnt/usb/list-of-blacklisted-urls.list&#10;+prune-subdomains.com', value: nvram.adblock_blacklist_custom }
{ title: 'Individual domains and/or path to external file/s.<br>Domains defined with a prepending <b>+<\/b> will have any found subdomain pruned from the blockfile.<br>Prepend <b>#<\/b> to comment.', name: 'adblock_blacklist_custom', type: 'textarea', placeholder: 'baddomain.com&#10;/mnt/usb/list-of-bad-domains.list&#10;/mnt/usb/list-of-blacklisted-urls.list&#10;+prune-subdomains.com', value: nvram.adblock_blacklist_custom, id: 'domain-blacklist' }
]);
</script>
</div>
<!-- / / / -->
<div class="section-title">Domain whitelist</div>
<input type="button" value="Sort domains backward a-z ↓" onclick="sortDomains('domain-whitelist')" id="sort-button-whitelist" style="float: right;">
<div class="section">
<script>
createFieldTable('', [
{ title: 'Individual domains and/or the path to external file/s containing domain references only.<br>Domains defined with a prepending <b>%<\/b> will not have the own subdomains blocked.<br>Prepend <b>#<\/b> to quote a line.', name: 'adblock_whitelist', type: 'textarea', placeholder: 'gooddomain.com\&#10;/mnt/usb/list-of-good-domains.list&#10;/mnt/usb/file-cointaining-list-of-urls.list&#10;%onlythis-nosubdomains.com', value: nvram.adblock_whitelist }
{ title: 'Individual domains and/or path to external file/s.<br>Domains defined with a prepending <b>%<\/b> will not have the own subdomains blocked.<br>Prepend <b>#<\/b> to comment.', name: 'adblock_whitelist', type: 'textarea', placeholder: 'gooddomain.com\&#10;/mnt/usb/list-of-good-domains.list&#10;/mnt/usb/file-cointaining-list-of-urls.list&#10;%onlythis-nosubdomains.com', value: nvram.adblock_whitelist, id: 'domain-whitelist' }
]);
</script>
</div>
@ -227,8 +299,8 @@ function earlyInit() {
<table cellspacing="1" cellpadding="2" border="0">
<tr><td>Controls -</td><td>Status -</td></tr>
<tr><td>&nbsp;</td>
<th rowspan="10" valign="top" style="text-align:left;padding-left:30px;padding-top:5px;font-size:9px;width:100%;border:1px solid #aaaaaa"><div id="status"><wbr></div></th></tr>
<td><input type="button" style="width:130px" value="▶️ Load " id="adblock-start" onclick="adblockMe('start');"></td></tr>
<th rowspan="10" valign="top" style="text-align: left;padding-left:30px;padding-top:5px;font-size:9px;width:100%;border:1px solid #aaaaaa"><div id="status"><wbr></div></th></tr>
<tr><td><input type="button" style="width:130px" value="▶️ Load " id="adblock-start" onclick="adblockMe('start');"></td></tr>
<tr><td><input type="button" style="width:130px" value="⏏️ Unload" id="adblock-stop" onclick="adblockMe('stop');"></td></tr>
<tr><td><input type="button" style="width:130px" value="🔄 Update" id="adblock-update" onclick="adblockMe('update');"></td></tr>
<tr><td><input type="button" style="width:130px" value="♻️ Reset limit" id="adblock-reset" onclick="adblockMe('reset');"></td></tr>
@ -255,9 +327,9 @@ function earlyInit() {
<li><b>Enable</b> - Used to activate/deactivate the adblock function. When enable is set the script runs after a save, a manual Load/Update, it autostart at boot and set autoupdate to run daily at a random time between 3am and 6am (excluding mins 59,00,01).</li>
<li><b>Blockfile size limit</b> - Defined in Bytes, it's an automatically calculated hard limit for the dnsmasq.adblock file. This limit can be overwritten manually. Removing the number and saving will trigger an internal calculation performed at the next run.</li>
<li><b>Custom path</b> - Optional, allows to save the potentially large adblock files on permanent storage like USB/CIFS/etc. This indirectly also means lower RAM usage and additional list control to avoid downloads/processing when not necessary.</li>
<li><b>Blacklist URL & List-of-lists</b> - Supported blacklist can come in multiple format. as long as they are text and with maximum one domain reference per line. Empty lines and lines starting with "#" or "!" are always ignored. A particular note on the List-of-lists format where the content of the defined list contains references to external URLs e.g.<br><code>[https://provider.com/badaddresses.txt] --> containing a list of URLs</code>.</li>
<li><b>Blacklist Custom</b> - Optional, space or newline separated: domain1.com domain2.com domain3.com. It also accepts external files as a source e.g. <code>/mnt/usb/blacklist</code>, with one domain per line. Prepending a '+' to the domain will force a removal of all the child domains from the blocklist file keeping only the custom defined one (blocking all its subdomains).</li>
<li><b>Whitelist</b> - Optional, space or newline separated: domain1.com domain2.com domain3.com. It also accepts external files as a source e.g. <code>/mnt/usb/whitelist</code>, with one domain per line. Please note by default given a domain, any of its subdomains will be whitelisted. To have a domain strictly whitelisted (subdomains blocked) prepend a <B>%</B> to the domain.</li>
<li><b>Blacklist URL & Group-of-lists</b> - Supported blacklist can come in multiple format. as long as they are text and with maximum one domain reference per line. Empty lines and lines starting with "#" or "!" are always ignored. A particular note on the Group-of-lists format where the content of the defined list contains references to external URLs e.g.<br><code>[https://provider.com/badaddresses.txt] --> containing a list of URLs</code>.</li>
<li><b>Blacklist Custom</b> - Optional, newline separated: domain1.com domain2.com domain3.com. It also accepts external files as a source e.g. <code>/mnt/usb/blacklist</code>, with one domain per line. Prepending a '+' to the domain will force a removal of all the child domains from the blocklist file keeping only the custom defined one (blocking all its subdomains).</li>
<li><b>Whitelist</b> - Optional, newline separated: domain1.com domain2.com domain3.com. It also accepts external files as a source e.g. <code>/mnt/usb/whitelist</code>, with one domain per line. Please note by default given a domain, any of its subdomains will be whitelisted. To have a domain strictly whitelisted (subdomains blocked) prepend a <B>%</B> to the domain.</li>
<li><b>Files</b> - Do not defined your custom files within the adblock folder as this is periodically cleaned up
<li><b>Caution</b> - Configuring large blocklists in adblock is not ideal. Add one list at the time and monitor the RAM usage. There are multiple protections in place but the most important is to trim down your final blocklist if too many resources are needed, this is reflected in the <code>Blockfile size limit</code> field</li>
<li><b>Hold-time</b> - There's a 30 min hold-time between consecutive updates to avoid false positive calls. This can be manually overridden performing an unload + update</li>

Loading…
Cancel
Save