forked from privacy-protection-tools/anti-AD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-addr.php
53 lines (39 loc) · 1.71 KB
/
make-addr.php
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
<?php
/**
* 根据下载的原始文件,生成dnsmasq的屏蔽广告用途的配置
*
* @file make-addr.php
* @author gently
* @date 2017.12.31
*
*
*/
define('ROOT_DIR', __DIR__ . '/');
set_time_limit(600);
error_reporting(0);
if(PHP_SAPI != 'cli'){
die('nothing.');
}
$arr_blacklist = require ROOT_DIR . 'lib/black_domain_list.php';
$arr_whitelist = require ROOT_DIR . 'lib/white_domain_list.php';
require ROOT_DIR . 'lib/writerFormat.class.php';
require ROOT_DIR . 'lib/addressMaker.class.php';
//白名单机制增强,加入dead hosts
$arr_dead_hosts = file(ROOT_DIR . 'origin-files/base-src-dead-hosts.txt', FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
$arr_dead_hosts=array_fill_keys($arr_dead_hosts, 1); //这里设置为1,表示命中的子域名同时加白
$arr_whitelist = array_merge($arr_dead_hosts, $arr_whitelist);
$arr_result = array();
$easylist = file_get_contents('./origin-files/base-src-easylist.txt');
$arr_result = array_merge_recursive($arr_result, addressMaker::get_domain_from_easylist($easylist));
$hosts = file_get_contents('./origin-files/base-src-hosts.txt');
$arr_result = array_merge_recursive($arr_result, addressMaker::get_domain_list($hosts));
$strict_hosts = file_get_contents('./origin-files/base-src-strict-hosts.txt');
$arr_result = array_merge_recursive($arr_result, addressMaker::get_domain_list($strict_hosts, true));
$arr_result = array_merge_recursive($arr_result, $arr_blacklist);
$reflect = new ReflectionClass('writerFormat');
$formatterList = $reflect->getConstants();
$arr_output = array();
foreach ($formatterList as $name => $formatObj){
$arr_output[] = '['. $name . ']' . addressMaker::write_to_conf($arr_result, $formatObj);
}
echo implode('---', $arr_output);