mirror of
https://github.com/privacy-protection-tools/anti-AD.git
synced 2025-02-02 19:53:02 +08:00
完善easylist的白名单逻辑,提升黑名单优先级到最高
This commit is contained in:
parent
3202db8998
commit
af969174f1
@ -1,4 +1,4 @@
|
|||||||
#TIME=20200116151638
|
#TIME=20200117051510
|
||||||
#URL=https://github.com/privacy-protection-tools/anti-AD
|
#URL=https://github.com/privacy-protection-tools/anti-AD
|
||||||
address=/0024aaaa.com/
|
address=/0024aaaa.com/
|
||||||
address=/0026645142c89aeb1.com/
|
address=/0026645142c89aeb1.com/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
!TIME=20200116151638
|
!TIME=20200117051510
|
||||||
!URL=https://github.com/privacy-protection-tools/anti-AD
|
!URL=https://github.com/privacy-protection-tools/anti-AD
|
||||||
||0024aaaa.com^
|
||0024aaaa.com^
|
||||||
||0026645142c89aeb1.com^
|
||0026645142c89aeb1.com^
|
||||||
@ -35752,3 +35752,8 @@
|
|||||||
||zszgjiejuw.mobi^
|
||zszgjiejuw.mobi^
|
||||||
||zzasj.cn^
|
||zzasj.cn^
|
||||||
||zzhssy.cn^
|
||zzhssy.cn^
|
||||||
|
@@||ad.10010.com^
|
||||||
|
@@||ad.abchina.com^
|
||||||
|
@@||ad.filmweb.pl^
|
||||||
|
@@||ad.kazakinfo.com^
|
||||||
|
@@||ad.ourgame.com^
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#TIME=20200116151638
|
#TIME=20200117051511
|
||||||
#URL=https://github.com/privacy-protection-tools/anti-AD
|
#URL=https://github.com/privacy-protection-tools/anti-AD
|
||||||
[RULE]
|
[RULE]
|
||||||
DOMAIN-SUFFIX,0024aaaa.com,REJECT
|
DOMAIN-SUFFIX,0024aaaa.com,REJECT
|
||||||
|
@ -13,8 +13,10 @@ error_reporting(7);
|
|||||||
|
|
||||||
define('START_TIME', microtime(true));
|
define('START_TIME', microtime(true));
|
||||||
define('ROOT_DIR', dirname(__DIR__). '/');
|
define('ROOT_DIR', dirname(__DIR__). '/');
|
||||||
define('LIB_DIR', ROOT_DIR . 'lib');
|
define('LIB_DIR', ROOT_DIR . 'lib/');
|
||||||
|
|
||||||
|
$black_domain_list = require_once LIB_DIR . 'black_domain_list.php';
|
||||||
|
require_once LIB_DIR . 'addressMaker.class.php';
|
||||||
define('WILDCARD_SRC', ROOT_DIR . 'origin-files/wildcard-src-easylist.txt');
|
define('WILDCARD_SRC', ROOT_DIR . 'origin-files/wildcard-src-easylist.txt');
|
||||||
define('WHITERULE_SRC', ROOT_DIR . 'origin-files/whiterule-src-easylist.txt');
|
define('WHITERULE_SRC', ROOT_DIR . 'origin-files/whiterule-src-easylist.txt');
|
||||||
|
|
||||||
@ -69,6 +71,10 @@ $ARR_REGEX_LIST = array(
|
|||||||
'/^pixels?\..+$/' => null,
|
'/^pixels?\..+$/' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ARR_WHITE_RULE_LIST = array(
|
||||||
|
'@@||github.com^',
|
||||||
|
);
|
||||||
|
|
||||||
if(PHP_SAPI != 'cli'){
|
if(PHP_SAPI != 'cli'){
|
||||||
die('nothing.');
|
die('nothing.');
|
||||||
}
|
}
|
||||||
@ -97,7 +103,6 @@ $wild_fp = fopen(WILDCARD_SRC, 'r');
|
|||||||
$new_fp = fopen($src_file . '.txt', 'w');
|
$new_fp = fopen($src_file . '.txt', 'w');
|
||||||
|
|
||||||
$wrote_wild = array();
|
$wrote_wild = array();
|
||||||
$wrote_regex = array();
|
|
||||||
$arr_wild_src = array();
|
$arr_wild_src = array();
|
||||||
|
|
||||||
while(!feof($wild_fp)){
|
while(!feof($wild_fp)){
|
||||||
@ -129,9 +134,9 @@ while(!feof($src_fp)){
|
|||||||
foreach($ARR_REGEX_LIST as $regex_str => $regex_row){
|
foreach($ARR_REGEX_LIST as $regex_str => $regex_row){
|
||||||
if(preg_match($regex_str, substr(trim($row), 2, -1))){
|
if(preg_match($regex_str, substr(trim($row), 2, -1))){
|
||||||
$matched = true;
|
$matched = true;
|
||||||
if(!array_key_exists($regex_str, $wrote_regex)){
|
if(!array_key_exists($regex_str, $wrote_wild)){
|
||||||
fwrite($new_fp, "${regex_str}\n");
|
fwrite($new_fp, "${regex_str}\n");
|
||||||
$wrote_regex[$regex_str] = 1;
|
$wrote_wild[$regex_str] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,9 +164,9 @@ while(!feof($src_fp)){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//按需写入白名单规则
|
//按需写入白名单规则
|
||||||
$whiterule_fp = fopen(WHITERULE_SRC, 'r');
|
$whiterule = file(WHITERULE_SRC, FILE_SKIP_EMPTY_LINES);
|
||||||
while(!feof($whiterule_fp)){
|
$ARR_WHITE_RULE_LIST = array_merge($ARR_WHITE_RULE_LIST, $whiterule);
|
||||||
$row = fgets($whiterule_fp, 1024);
|
foreach ($ARR_WHITE_RULE_LIST as $row){
|
||||||
if(empty($row) || $row{0} !== '@' || $row{1} !== '@'){
|
if(empty($row) || $row{0} !== '@' || $row{1} !== '@'){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -170,15 +175,25 @@ while(!feof($whiterule_fp)){
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach($wrote_wild as $core_str => $val){
|
foreach($wrote_wild as $core_str => $val){
|
||||||
$match_rule = str_replace('*', '.*', $core_str);
|
if($core_str{0} === '/'){
|
||||||
if(preg_match("/\|${match_rule}\^/", $row)){
|
$match_rule = $core_str;
|
||||||
fwrite($new_fp, "@@||${matches[1]}^");
|
}else{
|
||||||
|
$match_rule = str_replace('*', '.*', $core_str);
|
||||||
|
$match_rule = "/${match_rule}/";
|
||||||
|
}
|
||||||
|
if(preg_match($match_rule, $matches[1])) {
|
||||||
|
$domain = addressMaker::extract_main_domain($matches[1]); //@TODO 注意!这里假设白名单域名无通配符
|
||||||
|
if(array_key_exists($domain, $black_domain_list) ||
|
||||||
|
(is_array($black_domain_list[$domain]) && in_array($matches[1], $black_domain_list[$domain]))
|
||||||
|
){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fwrite($new_fp, "@@||${matches[1]}^\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($src_fp);
|
fclose($src_fp);
|
||||||
fclose($new_fp);
|
fclose($new_fp);
|
||||||
fclose($whiterule_fp);
|
|
||||||
rename($src_file . '.txt', $src_file);
|
rename($src_file . '.txt', $src_file);
|
||||||
echo 'Time cost:', microtime(true) - START_TIME, "s, at ", date('m-d H:i:s'), "\n";
|
echo 'Time cost:', microtime(true) - START_TIME, "s, at ", date('m-d H:i:s'), "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user