forked from poppyred/1.6.x
/
exec.squid27.php
executable file
·615 lines (499 loc) · 22.2 KB
/
exec.squid27.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?php
if(is_file("/etc/artica-postfix/FROM_ISO")){if(is_file("/etc/init.d/artica-cd")){print "Starting......: ".date("H:i:s")." artica-". basename(__FILE__)." Waiting Artica-CD to finish\n";die();}}
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
$GLOBALS["FORCE"]=false;
$GLOBALS["RECONFIGURE"]=false;
$GLOBALS["SWAPSTATE"]=false;
$GLOBALS["SERVICE_NAME"]="Squid-Cache NAT front-end";
if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true;$GLOBALS["OUTPUT"]=true;$GLOBALS["debug"]=true;ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);}
if(preg_match("#--output#",implode(" ",$argv))){$GLOBALS["OUTPUT"]=true;}
if(preg_match("#schedule-id=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["SCHEDULE_ID"]=$re[1];}
if(preg_match("#--force#",implode(" ",$argv),$re)){$GLOBALS["FORCE"]=true;}
if(preg_match("#--reconfigure#",implode(" ",$argv),$re)){$GLOBALS["RECONFIGURE"]=true;}
$GLOBALS["AS_ROOT"]=true;
include_once(dirname(__FILE__).'/framework/class.unix.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__).'/framework/class.settings.inc');
include_once(dirname(__FILE__).'/ressources/class.squid.inc');
$GLOBALS["ARGVS"]=implode(" ",$argv);
if($argv[1]=="--stop"){$GLOBALS["OUTPUT"]=true;stop();die();}
if($argv[1]=="--start"){$GLOBALS["OUTPUT"]=true;start();die();}
if($argv[1]=="--restart"){$GLOBALS["OUTPUT"]=true;restart();die();}
if($argv[1]=="--reload"){$GLOBALS["OUTPUT"]=true;reload();die();}
if($argv[1]=="--build"){$GLOBALS["OUTPUT"]=true;build();die();}
function restart($nopid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
stop(true);
build();
start(true);
}
function reload($nopid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
$sock=new sockets();
$EnableTransparent27=intval($sock->GET_INFO("EnableTransparent27"));
if($EnableTransparent27==0){
if($GLOBALS["OUTPUT"]){echo "Reload........: [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see EnableTransparent27 )...\n";}
return;
}
build();
$masterbin=$unix->find_program("squid27");
if(!is_file($masterbin)){
if($GLOBALS["OUTPUT"]){echo "Reload........: [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";}
return;
}
$pid=squid_27_pid();
if($unix->process_exists($pid)){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Reload........: [INIT]: {$GLOBALS["SERVICE_NAME"]} Service running since {$time}Mn...\n";}
shell_exec("$masterbin -f /etc/squid27/squid.conf -k reconfigure");
return;
}
start(true);
}
function NETWORK_ALL_INTERFACES(){
if(isset($GLOBALS["NETWORK_ALL_INTERFACES"])){return $GLOBALS["NETWORK_ALL_INTERFACES"];}
$unix=new unix();
$GLOBALS["NETWORK_ALL_INTERFACES"]=$unix->NETWORK_ALL_INTERFACES(true);
unset($GLOBALS["NETWORK_ALL_INTERFACES"]["127.0.0.1"]);
}
function build(){
$sock=new sockets();
$unix=new unix();
$ini=new Bs_IniHandler();
$IPADDRSSL=array();
$IPADDRSSL2=array();
$ArticaSquidParameters=$sock->GET_INFO('ArticaSquidParameters');
$visible_hostname=$ini->_params["NETWORK"]["visible_hostname"];
if($visible_hostname==null){$visible_hostname=$unix->hostname_g();}
$SquidBinIpaddr=$sock->GET_INFO("SquidBinIpaddr");
$AllowAllNetworksInSquid=$sock->GET_INFO("AllowAllNetworksInSquid");
if(!is_numeric($AllowAllNetworksInSquid)){$AllowAllNetworksInSquid=1;}
$ini->loadString($ArticaSquidParameters);
NETWORK_ALL_INTERFACES();
$LISTEN_PORT=intval($ini->_params["NETWORK"]["LISTEN_PORT"]);
$ICP_PORT=intval(trim($ini->_params["NETWORK"]["ICP_PORT"]));
$certificate_center=$ini->_params["NETWORK"]["certificate_center"];
$SSL_BUMP=intval($ini->_params["NETWORK"]["SSL_BUMP"]);
$LogsWarninStop=intval($sock->GET_INFO("LogsWarninStop"));
$ssl=false;
if($ICP_PORT==0){$ICP_PORT=3130;}
if($LISTEN_PORT==0){$LISTEN_PORT=3128;}
$squid=new squidbee();
$q=new mysql_squid_builder();
$IPADDRS=array();
if($SquidBinIpaddr<>null){
if(!isset($GLOBALS["NETWORK_ALL_INTERFACES"][$SquidBinIpaddr])){
$SquidBinIpaddr=null;
}else{
$IPADDRS[$SquidBinIpaddr]=$LISTEN_PORT;
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Listens $SquidBinIpaddr\n";}
}
}
if($SSL_BUMP==1){
$ssl=true;
$ssl_port=$squid->get_ssl_port();
}
if($SquidBinIpaddr==null){
reset($GLOBALS["NETWORK_ALL_INTERFACES"]);
while (list ($ipaddr, $val) = each ($GLOBALS["NETWORK_ALL_INTERFACES"])){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Listens $ipaddr:$LISTEN_PORT\n";}
$IPADDRS[$ipaddr]=$LISTEN_PORT;
$IPADDRSSL[$ipaddr]=$ssl_port;
}
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} visible hostname........: $visible_hostname\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} AllowAllNetworksInSquid.: $AllowAllNetworksInSquid\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} ICP Port................: $ICP_PORT\n";}
if($ssl){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} SSL Intercept...........: Yes - $ssl_port\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Certificate.............: $certificate_center\n";}
$MAINSSL=$squid->SaveCertificate($certificate_center,false,false,false,true);
$f[]=$MAINSSL[0];
$certificate=$MAINSSL[1]["certificate"];
$key=$MAINSSL[1]["key"];
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Certificate.............: $certificate\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Key.....................: $key\n";}
}
$sql="SELECT * FROM proxy_ports WHERE enabled=1 and transparent=1";
$results = $q->QUERY_SQL($sql);
$f[]="# --------- proxy_ports enabled=1 and transparent=1 -> ". mysql_num_rows($results)." ports";
while ($ligne = mysql_fetch_assoc($results)) {
$ipaddr=$ligne["ipaddr"];
$xport=$ligne["port"];
$transparent_text=null;
if(!isset($GLOBALS["NETWORK_ALL_INTERFACES"][$ipaddr])){
$f[]="# --------- table proxy_ports $ipaddr:$xport -> Hardware Error [".__LINE__."]\n";
$f[]="# --------- http $ipaddr -> Hardware Error [".__LINE__."]\n";
continue;
}
if($ssl){
$IPADDRSSL[$ipaddr]=$ssl_port;
}
$IPADDRS[$ipaddr]=$xport;
}
$transparent=" transparent";
while (list ($ipaddr, $xport) = each ($IPADDRSSL)){ $IPADDRSSL2["$ipaddr:$xport"]=true; }
while (list ($ipaddr, $xport) = each ($IPADDRS)){ $IPADDRS2["$ipaddr:$xport"]=true; }
while (list ($ipaddr, $none) = each ($IPADDRS2)){
$f[]="http_port $ipaddr$transparent";
}
if($ssl){
$f[]="# --------- https -> ".count($IPADDRSSL2)." addresses";
while (list ($ipaddr, $none) = each ($IPADDRSSL2)){
$f[]="https_port $ipaddr transparent cert=$certificate key=$key";
}
}
if($AllowAllNetworksInSquid==1){
$f[]="acl localnet src all";
}
if($AllowAllNetworksInSquid==0){
$k=array();
$NetworkScannerMasks=$sock->GET_INFO('NetworkScannerMasks');
$tbl=explode("\n",$NetworkScannerMasks);
if(is_array($tbl)){while (list ($num, $cidr) = each ($tbl)){if(trim($cidr)==null){continue;} $k[$cidr]=$cidr; } }
if(count($this->network_array)>0){
while (list ($num, $val) = each ($this->network_array)){
if($val==null){continue;}
$k[$val]=$val;
}
}
if(count($k==0)){$f[]="acl localnet src all";}
if(count($k>0)){
while (list ($m, $l) = each ($k)){$s[]=$l;}
$f[]="acl localnet src " . implode(" ",$s);
}
}
if($ssl){
}
$f[]="acl all src all";
$f[]="acl manager proto cache_object";
$f[]="acl localhost src 127.0.0.1/32";
$f[]="acl to_localhost dst 127.0.0.0/8 0.0.0.0/32";
$f[]="acl SSL_ports port \"/etc/squid3/acls/SSLPorts\"";
$f[]="acl Safe_ports port 80 # http";
$f[]="acl Safe_ports port 21 # ftp";
$f[]="acl Safe_ports port 443 # https";
$f[]="acl Safe_ports port 70 # gopher";
$f[]="acl Safe_ports port 210 # wais";
$f[]="acl Safe_ports port 1025-65535 # unregistered ports";
$f[]="acl Safe_ports port 280 # http-mgmt";
$f[]="acl Safe_ports port 488 # gss-http";
$f[]="acl Safe_ports port 591 # filemaker";
$f[]="acl Safe_ports port 777 # multiling http";
$f[]="acl CONNECT method CONNECT";
$f[]="";
$f[]="";
if($sock->EnableUfdbGuard()==1){
$f[]=ufdbguard27();
$EnableUfdbGuardArtica=$sock->EnableUfdbGuardArtica();
if(!is_file("/etc/squid3/acls/office365-nets.acl")){@touch("/etc/squid3/acls/office365-nets.acl");}
if(!is_file("/etc/squid3/acls/office365-domains.acl")){@touch("/etc/squid3/acls/office365-domains.acl");}
if(!is_file("/etc/squid3/acls/skype-nets.acl")){@touch("/etc/squid3/acls/skype-nets.acl");}
if(!is_file("/etc/squid3/acls/dropbox-nets.acl")){@touch("/etc/squid3/acls/dropbox-nets.acl");}
$f[]="acl squidclient proto cache_object";
$f[]="acl MgRDest dst 127.0.0.1";
$f[]="acl MgRPort dst 127.0.0.1";
$f[]="acl MyTestPort src 127.0.0.1";
$f[]="acl MyLocalIpsDest dst 127.0.0.1";
$f[]="acl ToArticaWWW dstdomain .artica.fr .articatech.net .articatech.com";
if($EnableUfdbGuardArtica==0){
$f[]="acl UrlRewriteDenyList dstdomain \"/etc/squid3/url_rewrite_program.deny.db\"";
}
$f[]="acl ArticaMetaWhiteDoms dstdomain \"/etc/squid3/artica-meta/whitelist-domains.db\"";
$f[]="acl ArticaMetaWhiteIPs dst \"/etc/squid3/artica-meta/whitelist-nets.db\"";
$f[]="acl BrowsersNoWebF browser -i \"/etc/squid3/acls/Browsers-nofilter.acl\"";
$f[]="acl whitelisted_mac_computers arp \"/etc/squid3/whitelisted-computers-by-mac.acl\"";
$f[]="acl office365_ips dst \"/etc/squid3/acls/office365-nets.acl\"";
$f[]="acl office365_www dstdomain \"/etc/squid3/acls/office365-domains.acl\"";
$f[]="acl skype_www dstdomain .live.com .skypeassets.com";
$f[]="acl skype_ips dst \"/etc/squid3/acls/skype-nets.acl\"";
$f[]="acl dropbox_ips dst \"/etc/squid3/acls/dropbox-nets.acl\"";
$f[]="acl dropbox_www dstdomain .dropbox.com";
$f[]=@file_get_contents("/etc/squid3/url_rewrite_access.conf");
}
$f[]="http_access allow manager localhost";
$f[]="http_access deny manager";
$f[]="http_access deny !Safe_ports";
$f[]="http_access deny CONNECT !SSL_ports";
$f[]="http_access allow localnet";
$f[]="http_access deny all";
$f[]="icp_access allow localnet";
$f[]="icp_access deny all";
$f[]="cache_peer 127.0.0.1\tparent\t$LISTEN_PORT\t3130\tdefault";
$f[]="never_direct allow all";
$f[]="cache_mem 64 MB";
$f[]="maximum_object_size_in_memory 256 KB";
$f[]="memory_replacement_policy lru";
$LOGFORMAT[]="%>a";
$LOGFORMAT[]="%[ui";
$LOGFORMAT[]="%[un";
$LOGFORMAT[]="[%tl]";
$LOGFORMAT[]="\"%rm %ru HTTP/%rv\"";
$LOGFORMAT[]="%Hs";
$LOGFORMAT[]="%<st";
$LOGFORMAT[]="%Ss:";
$LOGFORMAT[]="%Sh";
$LOGFORMAT[]="UserAgent:\"%{User-Agent}>h\"";
$LOGFORMAT[]="Forwarded:\"%{X-Forwarded-For}>h\"";
$f[]="logformat common MAC:00:00:00:00:00:00 ".@implode(" ", $LOGFORMAT);
$f[]="access_log none";
$f[]="cache_store_log none";
if($LogsWarninStop==0){
$f[]="logfile_rotate 10";
}
if($LogsWarninStop==1){
$f[]="logfile_rotate 0";
}
$f[]="# emulate_httpd_log off";
$f[]="log_ip_on_direct on";
$f[]="mime_table /etc/squid27/mime.conf";
$f[]="# log_mime_hdrs off";
$f[]="pid_filename /var/run/squid/squid-nat.pid";
$f[]="debug_options ALL,1";
$f[]="log_fqdn on";
$f[]="client_netmask 255.255.255.255";
$f[]="strip_query_terms off";
$f[]="buffered_logs on";
$f[]="netdb_filename /var/log/squid/netdb_nat.state";
if($LogsWarninStop==0){
$f[]="cache_log /var/log/squid/cache-nat.log";
}
if($LogsWarninStop==1){
$f[]="cache_log /dev/null";
}
$f[]="#url_rewrite_program";
$f[]="# url_rewrite_children 5";
$f[]="# url_rewrite_concurrency 0";
$f[]="# url_rewrite_host_header on";
$f[]="refresh_pattern . 0 20% 4320";
$f[]="cache_effective_user squid";
$f[]="cache_effective_group squid";
$f[]="httpd_suppress_version_string on";
$f[]="visible_hostname $visible_hostname";
$f[]="cache_dir null /tmp";
$f[]="# icon_directory /usr/share/squid27/icons";
$f[]="# error_directory /usr/share/squid27/errors/English";
$f[]="forwarded_for on";
$f[]="client_db on";
$f[]="";
CheckFilesAndSecurity();
@file_put_contents("/etc/squid27/squid.conf", @implode("\n", $f));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/squid27/squid.conf done\n";}
}
function start($nopid=false){
$unix=new unix();
$sock=new sockets();
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
$pid=squid_27_pid();
if($unix->process_exists($pid)){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Already running since {$time}Mn...\n";}
return;
}
$EnableTransparent27=intval($sock->GET_INFO("EnableTransparent27"));
if($EnableTransparent27==0){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see EnableTransparent27 )...\n";}
return;
}
$masterbin=$unix->find_program("squid27");
if(!is_file($masterbin)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed...\n";}
return;
}
CheckFilesAndSecurity();
$squid_27_version=squid_27_version();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service v$squid_27_version\n";}
$cmd="$masterbin -f /etc/squid27/squid.conf -sD";
shell_exec($cmd);
$c=1;
for($i=0;$i<10;$i++){
sleep(1);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service waiting $c/10\n";}
$pid=squid_27_pid();
if($unix->process_exists($pid)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Success PID $pid\n";}
break;
}
$c++;
}
$pid=squid_27_pid();
if(!$unix->process_exists($pid)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Failed\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} $cmd\n";}
}
}
function CheckFilesAndSecurity(){
$unix=new unix();
$f[]="/var/spool/squid27";
$f[]="/usr/share/squid27";
while (list ($num, $val) = each ($f)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} checking \"$val\"\n";}
if(!is_dir($val)){@mkdir($val,0755,true);}
$unix->chown_func("squid","squid","$val/*");
}
}
function ufdbguard27(){
$unix=new unix();
$sock=new sockets();
$squid=new squidbee();
$users=new usersMenus();
$major=$unix->UFDBGUARDD_MAJOR();
$minor=$unix->UFDBGUARDD_MINOR();
$datas=unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
$ufdbClass=new compile_ufdbguard();
$datas=$ufdbClass->SetDefaultsConfig($datas);
if(!isset($datas["url_rewrite_children_concurrency"])){$datas["url_rewrite_children_concurrency"]=2;}
if(!isset($datas["url_rewrite_children_startup"])){$datas["url_rewrite_children_startup"]=5;}
if(!isset($datas["url_rewrite_children_idle"])){$datas["url_rewrite_children_idle"]=5;}
if(!is_numeric($datas["url_rewrite_children_concurrency"])){$datas["url_rewrite_children_concurrency"]=2;}
if($datas["url_rewrite_children_concurrency"]>1){$moinsC="-C ";}
if($squid->EnableRemoteStatisticsAppliance==1){
$RemoteStatisticsApplianceSettings=unserialize(base64_decode($sock->GET_INFO("RemoteStatisticsApplianceSettings")));
if($this->ASROOT){
echo "Starting......: ".date("H:i:s")." [UFDB]: Using remote appliance {$RemoteStatisticsApplianceSettings["SERVER"]}:{$datas["listen_port"]} as Web filtering engine\n";
}
$datas["remote_server"]=$RemoteStatisticsApplianceSettings["SERVER"];
$datas["UseRemoteUfdbguardService"]=1;
$datas["remote_port"]=$datas["listen_port"];
}
$binary="/usr/share/artica-postfix/ufdbgclient.php";
$log="-l /var/log/squid";
if(!is_numeric($datas["listen_port"])){$datas["listen_port"]="3977";}
if(!is_numeric($datas["tcpsockets"])){$datas["tcpsockets"]=1;}
if(!is_numeric($datas["remote_port"])){$datas["remote_port"]=3977;}
if($datas["remote_port"]==null){$datas["UseRemoteUfdbguardService"]=0;}
if($datas["listen_addr"]==null){$datas["listen_addr"]="127.0.0.1";}
if($datas["listen_addr"]=="all"){$datas["listen_addr"]="127.0.0.1";}
if($datas["UseRemoteUfdbguardService"]==1){
if(trim($datas["remote_server"]==null)){$datas["remote_server"]="127.0.0.1";}
$address="-S {$datas["remote_server"]} -p {$datas["remote_port"]} ";
echo "Starting......: ".date("H:i:s")." ufdbguardd: Use remote ufdbguard service: {$datas["remote_server"]}:{$datas["remote_port"]}\n";
$GLOBALS[__FUNCTION__]="$binary $moinsC$address $log";
return "$binary $moinsC$address $log";
}
$effective_port=$squid->ufdbguard_value("port");
echo "Starting......: ".date("H:i:s")." ufdbguardd: Effective port:`$effective_port`\n";
if(is_numeric($effective_port)){$datas["tcpsockets"]=1;}
if($major>0){
if($minor>26){
if($datas["tcpsockets"]==1){
if(trim($datas["listen_addr"]==null)){$datas["listen_addr"]="127.0.0.1";}
echo "Starting......: ".date("H:i:s")." ufdbguardd: Use remote ufdbguard service: {$datas["listen_addr"]}:{$datas["remote_port"]}\n";
$address="-S {$datas["listen_addr"]} -p {$datas["listen_port"]} ";
$GLOBALS[__FUNCTION__]="$binary $moinsC$address $log";
$f[]="url_rewrite_program $binary $moinsC$address $log";
$f[]=$squid->url_rewrite_children();
return @implode("\n", $f);
}
}
}
echo "Starting......: ".date("H:i:s")." ufdbguardd: Use remote ufdbguard service: $binary $moinsC$log\n";
$GLOBALS[__FUNCTION__]="$binary $moinsC$log";
$f[]="url_rewrite_program /usr/share/artica-postfix/ufdbgclient.php";
$f[]=$squid->url_rewrite_children();
return @implode("\n", $f);
}
function stop(){
$unix=new unix();
$sock=new sockets();
$masterbin=$unix->find_program("squid27");
$EnableArticaHotSpot=$sock->GET_INFO("EnableArticaHotSpot");
$SquidHotSpotPort=$sock->GET_INFO("SquidHotSpotPort");
$ArticaHotSpotPort=$sock->GET_INFO("ArticaHotSpotPort");
$ArticaSSLHotSpotPort=$sock->GET_INFO("ArticaSSLHotSpotPort");
$ArticaSplashHotSpotPort=$sock->GET_INFO("ArticaSplashHotSpotPort");
$ArticaSplashHotSpotPortSSL=$sock->GET_INFO("ArticaSplashHotSpotPortSSL");
if(!is_numeric($ArticaHotSpotPort)){$ArticaHotSpotPort=0;}
if(!is_numeric($ArticaSplashHotSpotPort)){$ArticaSplashHotSpotPort=16080;}
if(!is_numeric($ArticaSplashHotSpotPortSSL)){$ArticaSplashHotSpotPortSSL=16443;}
$pid=squid_27_pid();
if(!is_file($masterbin)){
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed\n";}
return;
}
if(!$unix->process_exists($pid)){
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Already stopped...\n";}
return;
}
$nohup=$unix->find_program("nohup");
$php5=$unix->LOCATE_PHP5_BIN();
$kill=$unix->find_program("kill");
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid $pid...\n";}
shell_exec("$masterbin -f /etc/squid27/squid.conf -k shutdown");
for($i=0;$i<5;$i++){
$pid=squid_27_pid();
if(!$unix->process_exists($pid)){break;}
shell_exec("$masterbin -f /etc/squid27/squid.conf -k shutdown");
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:$pid $i/5...\n";}
sleep(1);
}
$pid=squid_27_pid();
if(!$unix->process_exists($pid)){
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n";}
return;
}
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid $pid...\n";}
shell_exec("$masterbin -f /etc/squid27/squid.conf -k kill");
for($i=0;$i<5;$i++){
$pid=squid_27_pid();
if(!$unix->process_exists($pid)){break;}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:$pid $i/5...\n";}
shell_exec("$masterbin -f /etc/squid27/squid.conf -k kill");
sleep(1);
}
if(!$unix->process_exists($pid)){
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} success stopped...\n";}
return;
}else{
if($GLOBALS["OUTPUT"]){echo "Stopping......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n";}
}
}
function squid_27_version(){
$unix=new unix();
if(isset($GLOBALS["squid_27_version"])){return $GLOBALS["squid_27_version"];}
$squidbin=$unix->find_program("squid27");
if(!is_file($squidbin)){return "0.0.0";}
exec("$squidbin -v 2>&1",$results);
while (list ($num, $val) = each ($results)){
if(preg_match("#Squid Cache: Version\s+(.+)#", $val,$re)){
$GLOBALS["squid_27_version"]=trim($re[1]);
return $GLOBALS["squid_27_version"];
}
}
}
function squid_27_pid(){
$unix=new unix();
$masterbin=$unix->find_program("squid27");
$pid=$unix->get_pid_from_file('/var/run/squid/squid-nat.pid');
if($unix->process_exists($pid)){return $pid;}
return $unix->PIDOF_PATTERN($masterbin." -f /etc/squid27/squid.conf");
}