forked from poppyred/1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.ufdbgclient.whitelists.php
executable file
·205 lines (160 loc) · 6.47 KB
/
exec.ufdbgclient.whitelists.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
$GLOBALS["SCHEDULE_ID"]=0;
$GLOBALS["AD_PROGRESS"]=0;
$GLOBALS["DEBUG_INCLUDES"]=false;
$GLOBALS["ARGVS"]=implode(" ",$argv);
if(preg_match("#schedule-id=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["SCHEDULE_ID"]=$re[1];}
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
if(preg_match("#--includes#",implode(" ",$argv))){$GLOBALS["DEBUG_INCLUDES"]=true;}
if(preg_match("#--progress-activedirectory=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["AD_PROGRESS"]=$re[1];}
if($GLOBALS["DEBUG_INCLUDES"]){echo basename(__FILE__)."::class.templates.inc\n";}
include_once(dirname(__FILE__).'/ressources/class.templates.inc');
include_once(dirname(__FILE__).'/ressources/class.squid.remote-stats-appliance.inc');
if($GLOBALS["DEBUG_INCLUDES"]){echo basename(__FILE__)."::class.ini.inc\n";}
include_once(dirname(__FILE__).'/ressources/class.ini.inc');
if($GLOBALS["DEBUG_INCLUDES"]){echo basename(__FILE__)."::class.squid.inc\n";}
include_once(dirname(__FILE__).'/ressources/class.squid.inc');
if($GLOBALS["DEBUG_INCLUDES"]){echo basename(__FILE__)."::framework/class.unix.inc\n";}
include_once(dirname(__FILE__).'/framework/class.unix.inc');
if($GLOBALS["DEBUG_INCLUDES"]){echo basename(__FILE__)."::frame.class.inc\n";}
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__).'/ressources/class.mysql.inc');
include_once(dirname(__FILE__).'/ressources/class.squid.acls.inc');
build_whitelist();
function build_whitelist(){
build_progress_wb("{compiling}",30);
urlrewriteaccessdeny();
build_progress_wb("{compiling}",35);
urlrewriteaccessdeny_squid();
build_progress_wb("{compiling}",40);
build_blacklists();
build_progress_wb("{done}",100);
$unix=new unix();
$php5=$unix->LOCATE_PHP5_BIN();
shell_exec("$php5 /usr/share/artica-postfix/exec.ufdbclient.reload.php");
}
function build_blacklists($aspid=false){
$unix=new unix();
$FINALARRAY=array();
$f=array();
$PidFile="/etc/artica-postfix/pids/squid_build_blacklists.pid";
$dbfile="/var/log/squid/ufdbgclient.black.db";
if($aspid){
$pid=$unix->get_pid_from_file($PidFile);
if($pid<>getmypid()){
if($unix->process_exists($pid,basename(__FILE__))){
echo "Starting......: ".date("H:i:s")." Blacklists: Another artica script running pid $pid, aborting ...\n";
WriteToSyslogMail("build_blacklists():: Another artica script running pid $pid, aborting ...", basename(__FILE__));
return;
}
}
}
@unlink($dbfile);
try {
echo "berekley_db:: Creating $dbfile database\n";
$db_desttmp = @dba_open($dbfile, "c","db4");
@dba_close($db_desttmp);
}
catch (Exception $e) {
$error=$e->getMessage();
echo "berekley_db::FATAL ERROR $error on $dbfile\n";
return;
}
$q=new mysql_squid_builder();
$array=array();
$db_con = @dba_open($dbfile, "c","db4");
$sql="SELECT * FROM deny_websites";
$results = $q->QUERY_SQL($sql);
if(!$q->ok){ echo "Starting......: ".date("H:i:s")." [ACLS]: $q->mysql_error\n"; return; }
@unlink("/etc/squid3/www-blacklists.db");
while ($ligne = mysql_fetch_assoc($results)) {
if($ligne["items"]==null){continue;}
$item=$ligne["items"];
$item=str_replace("/", "\/", $item);
$item=str_replace(".", "\.", $item);
$item=str_replace("*", ".*?", $item);
@dba_replace($item,$item,$db_con);
$array[]=$ligne["items"];
}
@dba_close($db_con);
@file_put_contents("/var/log/squid/ufdbgclient.reload", "#");
@chown("/var/log/squid/ufdbgclient.reload", "squid");
@chgrp("/var/log/squid/ufdbgclient.reload","squid");
$acl=new squid_acls();
$url_rewrite_program=$acl->clean_dstdomains($array);
echo "Starting......: ".date("H:i:s")." [ACLS]: ".count($url_rewrite_program)." blacklisted webistes\n";
@file_put_contents("/etc/squid3/www-blacklists.db", @implode("\n", $url_rewrite_program)."\n");
@chown("/etc/squid3/www-blacklists.db", "squid");
@chgrp("/etc/squid3/www-blacklists.db","squid");
}
function urlrewriteaccessdeny(){
$q=new mysql();
$dbfile="/var/log/squid/ufdbgclient.white.db";
$sql="SELECT * FROM urlrewriteaccessdeny";
$results = $q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." [ACLS]: $q->mysql_error\n";return; }
@unlink($dbfile);
if(!is_file($dbfile)){
try {
echo "berekley_db:: Creating $dbfile database\n";
$db_desttmp = @dba_open($dbfile, "c","db4");
@dba_close($db_desttmp);
}
catch (Exception $e) {
$error=$e->getMessage();
echo "berekley_db::FATAL ERROR $error on $dbfile\n";
return;
}
}
$db_con = @dba_open($dbfile, "c","db4");
if(!$db_con){
echo "berekley_db_size:: FATAL!!!::$dbfile, unable to open\n";
return false;
}
$c=0;
while ($ligne = mysql_fetch_assoc($results)) {
$ligne["items"]=trim($ligne["items"]);
if($ligne["items"]==null){continue;}
$c++;
echo "Starting......: ".date("H:i:s")." [ACLS]: {$ligne["items"]}\n";
$ligne["items"]=str_replace("/", "\/", $ligne["items"]);
$ligne["items"]=str_replace(".", "\.", $ligne["items"]);
$ligne["items"]=str_replace("*", ".*?", $ligne["items"]);
@dba_replace($ligne["items"],$ligne["items"],$db_con);
}
@dba_close($db_con);
if($c==0){@unlink($dbfile);}
echo "Starting......: ".date("H:i:s")." [ACLS]: $c Whitelisted webistes from webfiltering\n";
@chown($dbfile, "squid");
@chgrp($dbfile,"squid");
$unix=new unix();
$php=$unix->LOCATE_PHP5_BIN();
shell_exec("$php /usr/share/artica-postfix/exec.ufdbclient.reload.php");
}
function urlrewriteaccessdeny_squid(){
$q=new mysql();
$q2=new mysql_squid_builder();
$acl=new squid_acls();
$sql="SELECT * FROM urlrewriteaccessdeny";
$results = $q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." [ACLS]: $q->mysql_error\n";return; }
while ($ligne = mysql_fetch_assoc($results)) {
$ligne["items"]=trim($ligne["items"]);
if($ligne["items"]==null){continue;}
$array[]=$ligne["items"];
}
$acl=new squid_acls();
$url_rewrite_program=$acl->clean_dstdomains($array);
echo "Starting......: ".date("H:i:s")." [ACLS]: ".count($url_rewrite_program)." Whitelisted webistes from webfiltering\n";
@file_put_contents("/etc/squid3/url_rewrite_program.deny.db", @implode("\n", $url_rewrite_program)."\n");
@chown("/etc/squid3/url_rewrite_program.deny.db", "squid");
@chgrp("/etc/squid3/url_rewrite_program.deny.db","squid");
}
function build_progress_wb($text,$pourc){
$cachefile="/usr/share/artica-postfix/ressources/logs/squid.wb.progress";
$array["POURC"]=$pourc;
$array["TEXT"]=$text;
@file_put_contents($cachefile, serialize($array));
@chmod($cachefile,0755);
if($GLOBALS["PROGRESS"]){sleep(1);}
}