-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopAdware.php
executable file
·117 lines (100 loc) · 3 KB
/
StopAdware.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
function getDomains($string) {
global $hosts;
$result = false;
if ((substr($string, 0, 3)) == ":: ") {
$result = trim(substr($string, 4, strlen($string) - 4), "\n\r\t");
$hosts['v6'][] = $result;
} elseif ((substr($string, 0, 9)) == "127.0.0.1") {
$result = trim(substr($string, 10, strlen($string) - 10), "\n\r\t");
$hosts['v4'][] = $result;
} elseif ((substr($string, 0, 7)) == "0.0.0.0") {
$result = trim(substr($string, 8, strlen($string) - 8), "\n\r\t");
$hosts['v4'][] = $result;
}
}
if (php_sapi_name() == 'cli') {
$countHosts = ['v4'=>0, 'v6'=>0];
while(1) {
$servers = json_decode(file_get_contents('https://raw.githubusercontent.com/JeBance/StopAdware/gh-pages/servers.json'), true);
$hosts = ['v4'=>[], 'v6'=>[]];
for ($i = 0; $i < count($servers); $i++) {
try {
$file = new SplFileObject($servers[$i]);
echo $servers[$i];
while (!$file->eof()) {
$string = $file->current();
if (!empty($string)) {
getDomains($string);
}
$file->next();
} unset($file);
echo "\n";
} catch (Exception $e) {
echo "Not found ".$servers[$i]."\n";
}
}
if (($countHosts['v4'] < count($hosts['v4'])) || ($countHosts['v6'] < count($hosts['v6']))) {
sort($hosts['v4']);
sort($hosts['v6']);
$hosts['v4'] = array_values(array_unique($hosts['v4']));
$hosts['v6'] = array_values(array_unique($hosts['v6']));
$data = "# --------------------------------------------
#
# StopAdware
# ------
# ad.porn.malware blocking.
# ------
# Merged collection of hosts from
# reputable sources.
# ------
# https://jebance.github.io/StopAdware/hosts
#
# --------------------------------------------
# L O C A L H O S T
# --------------------------------------------
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
127.0.0.1 local
255.255.255.255 broadcasthost
::1 localhost
::1 ip6-localhost
::1 ip6-loopback
fe80::1%lo0 localhost
ff00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
0.0.0.0 0.0.0.0
# --------------------------------------------
# B E G I N S I P V 4
# --------------------------------------------
";
for ($i = 0; $i < count($hosts['v4']); $i++) {
$data .= "0.0.0.0 ".$hosts['v4'][$i]."\n";
}
$data .= "
# --------------------------------------------
# B E G I N S I P V 6
# --------------------------------------------
";
for ($i = 0; $i < count($hosts['v6']); $i++) {
$data .= ":: ".$hosts['v6'][$i]."\n";
}
$fcreate = fopen('/PATH_TO_FILE/hosts', "w+");
fwrite($fcreate, $data);
fclose($fcreate);
unset($data);
$countHosts['v4'] = count($hosts['v4']);
$countHosts['v6'] = count($hosts['v6']);
echo "v4: ".$countHosts['v4']."\nv6: ".$countHosts['v6']."\n";
unset($hosts);
}
exec('git add --all');
exec('git commit -m "updated '.date('d.m.Y h:i').'"');
exec('git push -u origin gh-pages');
sleep(86400); // updated every 24 hours
}
}
?>