forked from poppyred/1.6.x
/
exec.mvps.php
executable file
·111 lines (96 loc) · 3.55 KB
/
exec.mvps.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
<?php
ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);
include_once(dirname(__FILE__)."/framework/class.unix.inc");
include_once(dirname(__FILE__)."/ressources/class.squid.categorize.generic.inc");
include_once(dirname(__FILE__)."/ressources/class.mysql.squid.builder.php");
include_once(dirname(__FILE__)."/ressources/class.categorize.externals.inc");
include_once(dirname(__FILE__)."/ressources/class.tcpip.inc");
include_once(dirname(__FILE__)."/ressources/class.ccurl.inc");
include_once(dirname(__FILE__)."/ressources/class.familysites.inc");
xstart();
function xstart(){
$unix=new unix();
$filetime="/etc/artica-postfix/pids/exec.mvps.php.time";
if($unix->file_time_min($filetime)<240){
echo "Need 240mn, current is {$filetime}Mn\n";
return;
}
@unlink($filetime);
@file_put_contents($filetime, time());
$q=new mysql_squid_builder();
$curl=new ccurl("http://winhelp2002.mvps.org/hosts.txt");
$targetpath=$unix->FILE_TEMP();
if(!$curl->GetFile($targetpath)){
squid_admin_mysql(1, "Unable to download hosts.txt from winhelp2002.mvps.org", null,__FILE__,__LINE__);
return;
}
$f=explode("\n",@file_get_contents($targetpath));
@unlink($targetpath);
$fam=new familysite();
$sql="CREATE TABLE IF NOT EXISTS `squidlogs`.`ads_domains` (
`servername` VARCHAR(255) PRIMARY KEY,
`enabled` smallint(1) NOT NULL DEFAULT 1,
KEY `enabled`(`enabled`)
) ENGINE=MYISAM;";
$q->QUERY_SQL($sql);
if(!$q->ok){echo $q->mysql_error;return;}
$COUNT1=$q->COUNT_ROWS("ads_domains");
$QQR=array();
while (list ($a,$line) = each ($f) ){
$line=trim($line);
if(strpos($line, "localhost")>0){continue;}
if(substr($line, 0,1)=="#"){continue;}
$line=str_replace("0.0.0.0 ", "", $line);
if(strpos($line, "#")>0){$FI=explode("#",$line);$line=$FI[0];}
if(strpos($line, ".")==0){continue;}
$line=trim($line);
$familysite=$fam->GetFamilySites($line);
if($line==$familysite){$line=".$line";}
$QQR[]="('$line','1')";
if(count($QQR)>500){
$sql="INSERT IGNORE INTO `ads_domains` (`servername`,`enabled`) VALUES ".@implode(",", $QQR);
$q->QUERY_SQL($sql);
$QQR=array();
}
}
if(count($QQR)>0){
$sql="INSERT IGNORE INTO `ads_domains` (`servername`,`enabled`) VALUES ".@implode(",", $QQR);
$q->QUERY_SQL($sql);
$QQR=array();
}
$curl=new ccurl("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext");
$targetpath=$unix->FILE_TEMP();
if(!$curl->GetFile($targetpath)){
squid_admin_mysql(1, "Unable to download serverlist from yoyo.org", null,__FILE__,__LINE__);
return;
}
$f=explode("\n",@file_get_contents($targetpath));
@unlink($targetpath);
while (list ($a,$line) = each ($f) ){
$line=trim($line);
if(strpos($line, "localhost")>0){continue;}
if(substr($line, 0,1)=="#"){continue;}
$line=str_replace("127.0.0.1 ", "", $line);
if(strpos($line, "#")>0){$FI=explode("#",$line);$line=$FI[0];}
if(strpos($line, ".")==0){continue;}
$line=trim($line);
$QQR[]="('$line','1')";
$familysite=$fam->GetFamilySites($line);
if($line==$familysite){$line=".$line";}
if(count($QQR)>500){
$sql="INSERT IGNORE INTO `ads_domains` (`servername`,`enabled`) VALUES ".@implode(",", $QQR);
$q->QUERY_SQL($sql);
$QQR=array();
}
}
if(count($QQR)>0){
$sql="INSERT IGNORE INTO `ads_domains` (`servername`,`enabled`) VALUES ".@implode(",", $QQR);
$q->QUERY_SQL($sql);
$QQR=array();
}
$COUNT2=$q->COUNT_ROWS("ads_domains");
if($COUNT2>$COUNT1){
$TOTAL=$COUNT2-$COUNT1;
squid_admin_mysql(1, "$TOTAL ads and tracker added in ACLs", null,__FILE__,__LINE__);
}
}