forked from dtouzeau/artica-1.5
/
exec.status.php
executable file
·5817 lines (4621 loc) · 190 KB
/
exec.status.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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include_once(dirname(__FILE__)."/ressources/class.system.network.inc");
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after class.system.network.inc","MAIN",__LINE__);
include_once(dirname(__FILE__)."/ressources/class.mysql.inc");
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after class.mysql.inc","MAIN",__LINE__);
include_once(dirname(__FILE__).'/framework/class.unix.inc');
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after class.unix.inc","MAIN",__LINE__);
include_once(dirname(__FILE__)."/framework/frame.class.inc");
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after frame.class.inc","MAIN",__LINE__);
include_once(dirname(__FILE__)."/ressources/class.os.system.inc");
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after class.os.system.inc","MAIN",__LINE__);
include_once(dirname(__FILE__)."/framework/class.settings.inc");
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after class.settings.inc","MAIN",__LINE__);
$GLOBALS["DISABLE_WATCHDOG"]=false;
$GLOBALS["MY-POINTER"]="/etc/artica-postfix/pids/". basename(__FILE__).".pointer";
$GLOBALS["COMMANDLINE"]=implode(" ",$argv);
if(strpos($GLOBALS["COMMANDLINE"],"--verbose")>0){
$GLOBALS["VERBOSE"]=true;$GLOBALS["debug"]=true;$GLOBALS["DEBUG"]=true;
ini_set('html_errors',0);
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
}
if(preg_match("#--nowachdog#",$GLOBALS["COMMANDLINE"])){$GLOBALS["DISABLE_WATCHDOG"]=true;}
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
$sock=new sockets();
$unix=new unix();
$GLOBALS["ArticaWatchDogList"]=unserialize(base64_decode($sock->GET_INFO("ArticaWatchDogList")));
$GLOBALS["PHP5"]=$unix->LOCATE_PHP5_BIN();
$GLOBALS["NICE"]=$unix->EXEC_NICE();
$GLOBALS["nohup"]=$unix->find_program("nohup");
if($GLOBALS["VERBOSE"]){echo "DEBUG MODE ENABLED\n";}
if($GLOBALS["VERBOSE"]){echo "command line: {$GLOBALS["COMMANDLINE"]}\n";}
$GLOBALS["AMAVIS_WATCHDOG"]=unserialize(@file_get_contents("/etc/artica-postfix/amavis.watchdog.cache"));
$GLOBALS["TOTAL_MEMORY_MB"]=$unix->TOTAL_MEMORY_MB();
$sock=null;
$unix=null;
if(strlen($argv[1])>0){
events("parsing command line ".@implode(";", $argv),"MAIN",__LINE__);
$GLOBALS["CLASS_UNIX"]=new unix();
$GLOBALS["CLASS_SOCKETS"]=new sockets();
$GLOBALS["CLASS_USERS"]=new settings_inc();
CheckCallable();
}
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB after declarations","MAIN",__LINE__);
if(strlen($argv[1])>2){events("parsing command line {$argv[1]}","MAIN",__LINE__);}
if($argv[1]=="--all"){
events("-> launch_all_status()","MAIN",__LINE__);
launch_all_status();
die();
}
if($argv[1]=="--free"){echo getmem();exit;}
if($argv[1]=="--squid"){echo squid_master_status();exit;}
if($argv[1]=="--c-icap"){echo c_icap_master_status();exit;}
if($argv[1]=="--kav4proxy"){echo kav4Proxy_status();exit;}
if($argv[1]=="--dansguardian"){echo dansguardian_master_status();exit;}
if($argv[1]=="--wifi"){echo wpa_supplicant();;exit;}
if($argv[1]=="--fetchmail"){echo fetchmail();;exit;}
if($argv[1]=="--milter-greylist"){echo milter_greylist();;exit;}
if($argv[1]=="--framework"){echo framework();;exit;}
if($argv[1]=="--pdns"){echo pdns_server()."\n".pdns_recursor();exit;}
if($argv[1]=="--cyrus-imap"){echo cyrus_imap();exit;}
if($argv[1]=="--mysql"){echo "\n".mysql_server()."\n".mysql_mgmt()."\n". mysql_replica();exit;}
if($argv[1]=="--openldap"){echo "\n".openldap();;exit;}
if($argv[1]=="--saslauthd"){echo "\n".saslauthd();;exit;}
if($argv[1]=="--sysloger"){echo "\n".syslogger();;exit;}
if($argv[1]=="--squid-tail"){echo "\n".squid_tail();;exit;}
if($argv[1]=="--amavis"){echo "\n".amavis();exit;}
if($argv[1]=="--amavis-milter"){echo"\n". amavis_milter();exit;}
if($argv[1]=="--boa"){echo"\n". boa();exit;}
if($argv[1]=="--lighttpd"){echo"\n". lighttpd();exit;}
if($argv[1]=="--fcron"){echo"\n". fcron1()."\n".fcron2(); exit;}
if($argv[1]=="--clamav"){echo"\n". clamd()."\n".clamscan()."\n".clammilter()."\n".freshclam(); exit;}
if($argv[1]=="--retranslator"){echo"\n". retranslator_httpd(); exit;}
if($argv[1]=="--spamassassin"){echo spamassassin_milter()."\n".spamassassin();exit;}
if($argv[1]=="--postfix"){echo "\n".postfix();exit;}
if($argv[1]=="--postfix-logger"){echo "\n".postfix_logger();exit;}
if($argv[1]=="--mailman"){echo "\n".mailman();exit;}
if($argv[1]=="--kas3"){echo "\n".kas3_milter()."\n".kas3_ap(); exit;}
if($argv[1]=="--samba"){echo "\n".smbd()."\n".nmbd()."\n".winbindd()."\n".scanned_only()."\n"; exit;}
if($argv[1]=="--roundcube"){echo "\n".roundcube();exit;}
if($argv[1]=="--cups"){echo "\n".cups();exit;}
if($argv[1]=="--apache-groupware"){echo "\n".apache_groupware();exit;}
if($argv[1]=="--gdm"){echo "\n".gdm();exit;}
if($argv[1]=="--console-kit"){echo "\n".consolekit();exit;}
if($argv[1]=="--xfce"){echo "\n".xfce();exit;}
if($argv[1]=="--vmtools"){echo "\n".vmtools();exit;}
if($argv[1]=="--hamachi"){echo "\n".hamachi();exit;}
if($argv[1]=="--artica-notifier"){echo "\n".artica_notifier();exit;}
if($argv[1]=="--dhcpd"){echo "\n".dhcpd_server();exit;}
if($argv[1]=="--pure-ftpd"){echo "\n".pure_ftpd();exit;}
if($argv[1]=="--mldonkey"){echo "\n".mldonkey();exit;}
if($argv[1]=="--policydw"){echo "\n".policyd_weight();exit;}
if($argv[1]=="--backuppc"){echo "\n".backuppc();exit;}
if($argv[1]=="--kav4fs"){echo "\n".kav4fs()."\n".kav4fsavs();exit;}
if($argv[1]=="--ocsweb"){echo "\n".apache_ocsweb()."\n".apache_ocsweb_download()."\n";exit;}
if($argv[1]=="--ocsagent"){echo "\n".ocs_agent();exit;}
if($argv[1]=="--openssh"){echo "\n".openssh();exit;}
if($argv[1]=="--gluster"){echo "\n".gluster();exit;}
if($argv[1]=="--auditd"){echo "\n".auditd();exit;}
if($argv[1]=="--squidguard-http"){echo "\n".squidguardweb();exit;}
if($argv[1]=="--opendkim"){echo "\n".opendkim();exit;}
if($argv[1]=="--ufdbguardd"){echo "\n".ufdbguardd();exit;}
if($argv[1]=="--ufdb-tail"){echo "\n".ufdbguardd_tail();exit;}
if($argv[1]=="--squidguard-tail"){echo "\n".squidguard_logger();exit;}
if($argv[1]=="--dkim-milter"){echo "\n".milter_dkim();exit;}
if($argv[1]=="--dropbox"){echo "\n".dropbox();exit;}
if($argv[1]=="--artica-policy"){echo "\n".artica_policy();exit;}
if($argv[1]=="--vboxwebsrv"){echo "\n".virtualbox_webserv();exit;}
if($argv[1]=="--tftpd"){echo "\n".tftpd();exit;}
if($argv[1]=="--vdi"){echo "\n".virtualbox_webserv()."\n".tftpd()."\n".dhcpd_server();exit;}
if($argv[1]=="--crossroads"){echo "\n".crossroads();exit;}
if($argv[1]=="--artica-status"){echo "\n".artica_status();exit;}
if($argv[1]=="--artica-executor"){echo "\n".artica_executor();exit;}
if($argv[1]=="--artica-background"){echo "\n".artica_background();exit;}
if($argv[1]=="--pptpd"){echo "\n".pptpd();exit;}
if($argv[1]=="--pptpd-clients"){echo "\n".pptp_clients();exit;}
if($argv[1]=="--bandwith"){echo "\n".bandwith();exit;}
if($argv[1]=="--apt-mirror"){echo "\n".apt_mirror();exit;}
if($argv[1]=="--squidclamav-tail"){echo "\n".squid_clamav_tail();exit;}
if($argv[1]=="--ddclient"){echo "\n".ddclient();exit;}
if($argv[1]=="--cluebringer"){echo "\n".cluebringer();exit;}
if($argv[1]=="--apachesrc"){echo "\n".apachesrc();exit;}
if($argv[1]=="--assp"){echo "\n".assp();exit;}
if($argv[1]=="--freewebs"){echo "\n".apachesrc()."\n".pure_ftpd();exit;}
if($argv[1]=="--openvpn"){echo "\n".openvpn();exit;}
if($argv[1]=="--vboxguest"){echo "\n".vboxguest();exit;}
if($argv[1]=="--sabnzbdplus"){echo "\n".sabnzbdplus();exit;}
if($argv[1]=="--openvpn-clients"){echo "\n".OpenVPNClientsStatus();exit;}
if($argv[1]=="--stunnel"){echo "\n".stunnel();exit;}
if($argv[1]=="--meta-checks"){echo "\n".meta_checks();exit;}
if($argv[1]=="--smbd"){echo "\n".smbd();exit;}
if($argv[1]=="--vnstat"){echo "\n".vnstat();exit;}
if($argv[1]=="--munin"){echo "\n".munin();exit;}
if($argv[1]=="--autofs"){echo "\n".autofs();exit;}
if($argv[1]=="--greyhole"){echo "\n".greyhole();exit;}
if($argv[1]=="--amavis-watchdog"){echo "\n".AmavisWatchdog();exit;}
if($argv[1]=="--dnsmasq"){echo "\n".dnsmasq();exit;}
if($argv[1]=="--iscsi"){echo "\n".iscsi();exit;}
if($argv[1]=="--yorel"){echo "\n".watchdog_yorel();exit;}
if($argv[1]=="--watchdog-service"){echo "\n".WATCHDOG($argv[2],$argv[3]);exit;}
if($argv[1]=="--postfwd2"){echo "\n".postfwd2();exit;}
if($argv[1]=="--zarafa-watchdog"){zarafa_watchdog();exit;}
if($argv[1]=="--vps"){echo vps_servers();exit;}
if($argv[1]=="--crossroads-multiple"){echo crossroads_multiple();exit;}
if($argv[1]=="--smartd"){echo "\n".smartd();exit;}
if($argv[1]=="--watchdog-me"){echo watchdog_me();die();}
if($argv[1]=="--auth-tail"){echo auth_tail();exit;}
if($argv[1]=="--snort"){echo snort();exit;}
if($argv[1]=="--xload"){echo xLoadAvg();$GLOBALS["VERBOSE"]=true;exit;}
if($argv[1]=="--greyhole-watchdog"){greyhole_watchdog();exit;}
if($argv[1]=="--greensql"){echo greensql();exit;}
if($argv[1]=="--functions"){
$arr = get_defined_functions();
print_r($arr);
die();
}
if($argv[1]=="--all-squid"){
$conf[]=dansguardian_tail_status();
$conf[]=squid_master_status();
$conf[]=c_icap_master_status();
$conf[]=dansguardian_master_status();
$conf[]=kav4Proxy_status();
$conf[]=proxy_pac_status();
$conf[]=squid_tail();
$conf[]=squidguardweb();
$conf[]=ufdbguardd();
echo @implode("\n",$conf);
die();
}
if($argv[1]=="--zarafa"){
$conf[]=zarafa_web();
$conf[]=zarafa_ical();
$conf[]=zarafa_dagent();
$conf[]=zarafa_monitor();
$conf[]=zarafa_gateway();
$conf[]=zarafa_spooler();
$conf[]=zarafa_server();
$conf[]=zarafa_licensed();
$conf[]=zarafa_indexer();
echo @implode("\n",$conf);
die();
}
if($argv[1]=="--amavis-full"){
$conf[]=spamassassin();
$conf[]=clamd();
$conf[]=amavis();
$conf[]=amavis_milter();
echo @implode("\n",$conf);
die();
}
if(strlen($argv[1])>0){
write_syslog("Unable to understand {$argv[1]}",basename(__FILE__));
die();
}
$pidfile="/etc/artica-postfix/".basename(__FILE__).".pid";
$unix=new unix();
if($unix->process_exists(@file_get_contents($pidfile))){
print "Starting......: artica-status Already executed...\n";
die();
}
$mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB artica-status Memory {$GLOBALS["TOTAL_MEMORY_MB"]}MB","MAIN",__LINE__);
print "Starting......: artica-status Memory {$GLOBALS["TOTAL_MEMORY_MB"]}MB\n";
if(!function_exists("pcntl_fork")){$nofork=true;}
if($GLOBALS["TOTAL_MEMORY_MB"]<400){$nofork=true;}
if($nofork){
print "Starting......: artica-status pcntl_fork module not loaded !\n";
$pidfile="/etc/artica-postfix/".basename(__FILE__).".pid";
$childpid=posix_getpid();
events("{$mem}MB artica-status Memory NO fork.... pid=$childpid","MAIN",__LINE__);
@file_put_contents($pidfile,$childpid);
$timefile="/etc/artica-postfix/".basename(__FILE__).".time";
if(file_time_min($timefile)>1){
@unlink($timefile);
events("{$mem}MB artica-status Memory NO fork.... -> launch_all_status()","MAIN",__LINE__);
launch_all_status();
@file_put_contents($timefile,"#");
}
events("{$mem}MB artica-status Memory NO fork.... -> die()","MAIN",__LINE__);
$nohup=$unix->find_program("nohup");
shell_exec(trim($nohup." ".$unix->LOCATE_PHP5_BIN()." ".dirname(__FILE__)."/exec.parse-orders.php >/dev/null 2>&1 &"));
die();
}
if(function_exists("pcntl_signal")){
pcntl_signal(SIGTERM,'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
pcntl_signal(SIGCHLD,'sig_handler');
pcntl_signal(SIGHUP, 'sig_handler');
}
set_time_limit(0);
ob_implicit_flush();
declare(ticks = 1);
$stop_server=false;
$reload=false;
$pid = pcntl_fork();
if ($pid == -1) {
die("Starting......: artica-status fork() call asploded!\n");
} else if ($pid) {
// we are the parent
print "Starting......: artica-status fork()ed successfully.\n";
die();
}
$pidfile="/etc/artica-postfix/".basename(__FILE__).".pid";
$childpid=posix_getpid();
@file_put_contents($pidfile,$childpid);
events("Starting PID $childpid","MAIN",__LINE__);
$renice_bin=$unix->find_program("renice");
events("$renice_bin 19 $childpid","MAIN",__LINE__);
shell_exec("$renice_bin 19 $childpid &");
events("Memory: ".round(((memory_get_usage()/1024)/1000),2) ." before start service".__LINE__);
$count=0;
while ($stop_server==false) {
$count++;
sleep(1);
$mem=round(((memory_get_usage()/1024)/1000),2);
$timefile=$unix->file_time_min("/usr/share/artica-postfix/ressources/logs/global.status.ini");
if($count==10){events("waiting $count/120 {$mem}MB global.status.ini:{$timefile}Mn",__FUNCTION__,__LINE__);}
if($count==30){events("waiting $count/120 {$mem}MB global.status.ini:{$timefile}Mn",__FUNCTION__,__LINE__);}
if($count==60){events("waiting $count/120 {$mem}MB global.status.ini:{$timefile}Mn",__FUNCTION__,__LINE__);}
if($count==100){events("waiting $count/120 {$mem}MB global.status.ini:{$timefile}Mn",__FUNCTION__,__LINE__);}
if(is_file("/usr/share/artica-postfix/ressources/logs/launch.status.task")){
events("launch.status.task detected",__FUNCTION__,__LINE__);
if(!is_file("/etc/artica-postfix/launch.status.lock")){@file_put_contents("/etc/artica-postfix/launch.status.lock",time());}
$timeLock=$unix->file_time_min("/etc/artica-postfix/launch.status.lock");
events("timeLock {$timeLock}Mn",__FUNCTION__,__LINE__);
@unlink("/usr/share/artica-postfix/ressources/logs/launch.status.task");
if($timeLock>0){
try {launch_all_status(true);} catch (Exception $e) {writelogs("Fatal while running function launch_all_status $e",__FUNCTION__,__FILE__,__LINE__);}
@unlink("/etc/artica-postfix/launch.status.lock");
}
}
if($timefile>2){
events("global.status.ini time ($timefile) is more than 2Mn -> Launch all status...",__FUNCTION__,__LINE__);
try {launch_all_status(true);} catch (Exception $e) {writelogs("Fatal while running function launch_all_status $e",__FUNCTION__,__FILE__,__LINE__);}
$count=0;
continue;
}
if(!is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")){
events("global.status.ini does not exists -> Launch all status...",__FUNCTION__,__LINE__);
try {launch_all_status(true);} catch (Exception $e) {writelogs("Fatal while running function launch_all_status $e",__FUNCTION__,__FILE__,__LINE__);}
$count=0;
continue;
}
if($count>120){
$count=0;
events("Counter ($count) is up to 120 -> Launch all status...",__FUNCTION__,__LINE__);
try {launch_all_status(true);} catch (Exception $e) {writelogs("Fatal while running function launch_all_status $e",__FUNCTION__,__FILE__,__LINE__);}
continue;
}
if($reload){
$reload=false;
events("reload daemon ($count seconds)",__FUNCTION__,__LINE__);
$GLOBALS["CLASS_SOCKETS"]=new sockets();
$GLOBALS["CLASS_USERS"]=new settings_inc();
$GLOBALS["CLASS_UNIX"]=new unix();
$GLOBALS["TIME_CLASS"]=time();
$GLOBALS["ArticaWatchDogList"]=unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("ArticaWatchDogList")));
unset($GLOBALS["GetVersionOf"]);
if(!is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")){
launch_all_status(true);
$count=0;
}
$GLOBALS["AMAVIS_WATCHDOG"]=unserialize(@file_get_contents("/etc/artica-postfix/amavis.watchdog.cache"));
}
include_once("ressources/class.os.system.tools.inc");
$os=new os_system();
$GLOBALS["MEMORY_INSTALLED"]=$os->memory();
$os=null;
$GLOBALS["CLASS_SOCKETS"]=null;
$GLOBALS["CLASS_USERS"]=null;
$GLOBALS["CLASS_UNIX"]=null;
}
events("die()...","MAIN",__LINE__);
function sig_handler($signo) {
global $stop_server;
global $reload;
switch($signo) {
case SIGTERM: {
$stop_server = true;
break;
}
case 1: {
$reload=true;
}
default: {
if($signo<>17){events("Receive sig_handler $signo",__FUNCTION__,__LINE__);}
}
}
}
function watchdog_me(){
if($GLOBALS["TOTAL_MEMORY_MB"]<400){
events("watchdog_me: {$GLOBALS["TOTAL_MEMORY_MB"]}M installed on this computer, aborting",__FUNCTION__,__LINE__);
$unix=new unix();
$cmd=trim($nohup." ".$unix->LOCATE_PHP5_BIN()." ".dirname(__FILE__)."/exec.parse-orders.php >/dev/null 2>&1 &");
shell_exec($cmd);
return;
}
$unix=new unix();
$time_file=$unix->file_time_min($GLOBALS["MY-POINTER"]);
events("Pointer: {$GLOBALS["MY-POINTER"]} = {$time_file}Mn",__FUNCTION__,__LINE__);
if($time_file>2){
events("Pointer: restart artica-status !!!",__FUNCTION__,__LINE__);
shell_exec("{$GLOBALS["nohup"]} /etc/init.d/artica-postfix restart artica-status >/dev/null 2>&1 &");
}
}
function amavis_watchdog_load_conf(){
if(is_file("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration")){
$ini=new iniFrameWork();
$ini->loadFile("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration");
$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]=$ini->_params["BEHAVIORS"]["max_servers"];
$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]=$ini->_params["BEHAVIORS"]["child_timeout"];
}
$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]=filemtime("/usr/local/etc/amavisd.conf");
events("/usr/local/etc/amavisd.conf: time:{$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]}",__FUNCTION__,__LINE__);
events("max_servers: {$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]}",__FUNCTION__,__LINE__);
events("child_timeout: {$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]}",__FUNCTION__,__LINE__);
}
function amavis_watchdog_removebayes(){
$f[]="bayes_journal";
$f[]="bayes_seen";
$f[]="bayes_toks";
while (list ($num, $filename) = each ($f)){
if(is_file("/etc/spamassassin/$filename")){@unlink("/etc/spamassassin/$filename");}
if(is_file("/etc/mail/spamassassin/$filename")){@unlink("/etc/mail/spamassassin/$filename");}
}
}
function AmavisWatchdog(){
if(!is_file("/usr/local/etc/amavisd.conf")){return;}
if(!isset($GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"])){amavis_watchdog_load_conf();}
if(!isset($GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"])){amavis_watchdog_load_conf();}
$time=filemtime("/usr/local/etc/amavisd.conf");
if($time<>$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]){amavis_watchdog_load_conf();}
if(preg_match("#([0-9]+)\*([0-9]+)#",$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"],$re)){
$seconds=intval($re[2]);
$int=intval($re[1]);
$AmavisWatchdogMaxInterval=round($int*$seconds)/60;
}else{
$AmavisWatchdogMaxInterval=50;
}
$AmavisWatchdogFinalInterval=$AmavisWatchdogMaxInterval+5;
if(!is_numeric($AmavisWatchdogMaxInterval)){$AmavisWatchdogMaxInterval=50;}
if(!is_numeric($GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"])){$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]=5;}
$enabled=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableAmavisWatchdog");
$AmavisWatchdogMaxCPU=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("AmavisWatchdogMaxCPU");
$AmavisWatchdogKillProcesses=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("AmavisWatchdogKillProcesses");
if(!is_numeric($enabled)){$enabled=1;}
if($enabled==0){return;}
if(!is_numeric($AmavisWatchdogMaxCPU)){$AmavisWatchdogMaxCPU=80;}
if(!is_numeric($AmavisWatchdogKillProcesses)){$AmavisWatchdogKillProcesses=1;}
if(!isset($GLOBALS["psbin"])){$GLOBALS["psbin"]=$GLOBALS["CLASS_UNIX"]->find_program("ps");}
if(!isset($GLOBALS["grepbin"])){$GLOBALS["grepbin"]=$GLOBALS["CLASS_UNIX"]->find_program("grep");}
if(!isset($GLOBALS["killbin"])){$GLOBALS["killbin"]=$GLOBALS["CLASS_UNIX"]->find_program("kill");}
if(!isset($GLOBALS["AMAVIS_WATCHDOG"])){
if(is_file("/etc/artica-postfix/amavis.watchdog.cache")){
$GLOBALS["AMAVIS_WATCHDOG"]=unserialize(@file_get_contents("/etc/artica-postfix/amavis.watchdog.cache"));
}
}
$notify_text="";
$cmd="{$GLOBALS["psbin"]} aux|{$GLOBALS["grepbin"]} -E \"amavisd \(\" 2>&1";
if($GLOBALS["VERBOSE"]){echo "$cmd\n";}
exec("$cmd",$results);
$childs=0;
while (list ($num, $line) = each ($results)){
if(preg_match("#[a-z]+\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.]+).+?amavisd\s+\((.+?)\)#",$line,$re)){
$type=$re[4];
$pid=$re[1];
$cpu_pourc=intval($re[2]);
$cpumem=$re[3];
$time=$GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($pid);
$time_by_pid=$time;
$rss=$GLOBALS["CLASS_UNIX"]->PROCESS_MEMORY($pid);
$vm=$GLOBALS["CLASS_UNIX"]->PROCESS_CACHE_MEMORY($pid);
$array_status[$pid]=array("TYPE"=>$type,"CPU"=>$cpu_pourc,"TIME"=>$time
,"RSS"=>$rss,"VMSIZE"=>$vm
);
if($type<>"master"){if($type<>"virgin"){if($type<>"virgin child"){$childs++;}}}
$info="$childs/{$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]} Found child type:$type pid:$pid CPU:$cpu_pourc% Memory:{$rss}Mb Cached :{$vm}Mb running since {$time}Mn max running:{$AmavisWatchdogFinalInterval}Mn";
events("$info",__FUNCTION__,__LINE__);
$text[]="$info";
if($type<>"master"){
if($time_by_pid>=$AmavisWatchdogFinalInterval){
events("Killing $pid pid...",__FUNCTION__,__LINE__);
shell_exec("{$GLOBALS["killbin"]} -9 $pid");
$notify_text="This process has been killed";
$GLOBALS["CLASS_UNIX"]->send_email_events("Warning Amavis child ($type) reach {$AmavisWatchdogFinalInterval}Mn ({$time_by_pid}Mn)",
"Amavis child PID $pid using $cpu_pourc and has been detected {$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]} times
in {$time_by_pid}Mn
$notify_text
\n".@implode("\n",$text),"postfix");
amavis_watchdog_removebayes();
continue;
}
}
if($cpu_pourc>$AmavisWatchdogMaxCPU){
events("Warning on pid $pid",__FUNCTION__,__LINE__);
if(!isset($GLOBALS["AMAVIS_WATCHDOG"][$pid]["time"])){
$GLOBALS["AMAVIS_WATCHDOG"][$pid]["time"]=time();
$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]=1;
continue;
}else{
$min_interval=calc_time_min($GLOBALS["AMAVIS_WATCHDOG"][$pid]["time"]);
$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]=$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]+1;
events("Last detected time $min_interval minutes add score +1 -> {$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]}",__FUNCTION__,__LINE__);
if($min_interval>$AmavisWatchdogMaxInterval){
if($AmavisWatchdogKillProcesses==1){
shell_exec("{$GLOBALS["killbin"]} -9 $pid");
$notify_text="This process has been killed";
}
$GLOBALS["CLASS_UNIX"]->send_email_events("Warning Amavis child reach $AmavisWatchdogMaxCPU% CPU after {$AmavisWatchdogMaxInterval}Mn max running:$AmavisWatchdogFinalInterval",
"Amavis child PID $pid using $cpu_pourc and has been detected {$GLOBALS["AMAVIS_WATCHDOG"][$pid]["count"]} times
in {$min_interval}Mn
$notify_text
\n".@implode("\n",$text),"postfix");
amavis_watchdog_removebayes();
continue;
}
}
}else{
if(isset($GLOBALS["AMAVIS_WATCHDOG"][$pid])){
events("Remove warning on pid $pid",__FUNCTION__,__LINE__);
unset($GLOBALS["AMAVIS_WATCHDOG"][$pid]);
}
}
}
}
/*if($childs>=$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]){
$GLOBALS["CLASS_UNIX"]->send_email_events("Warning Amavis reach the maximal servers processes",
"You have defined Amavis to run {$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]}, you need to increase this value\nhere it
is the processes list:\n".@implode("\n",$text),"postfix");
}*/
if(is_array($GLOBALS["AMAVIS_WATCHDOG"])){
while (list ($pid, $array) = each ($GLOBALS["AMAVIS_WATCHDOG"])){
events("in memory... PID:$pid",__FUNCTION__,__LINE__);
if(!$GLOBALS["CLASS_UNIX"]->process_exists($pid)){
events("remove from memory... PID:$pid",__FUNCTION__,__LINE__);
unset($GLOBALS["AMAVIS_WATCHDOG"][$pid]);
}
}
}
@file_put_contents("/etc/artica-postfix/amavis.watchdog.cache",@serialize($GLOBALS["AMAVIS_WATCHDOG"]));
@file_put_contents("/usr/share/artica-postfix/ressources/logs/amavis.infos.array",@serialize($array_status));
@chmod("/usr/share/artica-postfix/ressources/logs/amavis.infos.array",0777);
}
function SwapWatchdog(){
$reboot=false;
$filecache="/etc/artica-postfix/cron.1/".basename(__FILE__).".".__FUNCTION__.".time";
$SwapOffOn=unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SwapOffOn")));
if(!is_numeric($SwapOffOn["SwapEnabled"])){$SwapOffOn["SwapEnabled"]=1;}
if(!is_numeric($SwapOffOn["SwapMaxPourc"])){$SwapOffOn["SwapMaxPourc"]=20;}
if(!is_numeric($SwapOffOn["SwapMaxMB"])){$SwapOffOn["SwapMaxMB"]=0;}
if($SwapOffOn["SwapEnabled"]==0){return;}
$filetime=file_time_min($filecache);
if($filetime<30){
events("{$filetime}Mn need to wait 30mn",__FUNCTION__,__LINE__);
return;
}
include_once(dirname(__FILE__)."/ressources/class.main_cf.inc");
$sys=new systeminfos();
events("$sys->swap_used/$sys->swap_total ",__FUNCTION__,__LINE__);
$pourc=round(($sys->swap_used/$sys->swap_total)*100);
events("{$sys->swap_used}MB used ($pourc%)",__FUNCTION__,__LINE__);
if($SwapOffOn["SwapMaxMB"]>0){
if($sys->swap_used>$SwapOffOn["SwapMaxMB"]){
$execeed_text=$SwapOffOn["SwapMaxMB"]."MB";
$reboot=true;
}
}
if($SwapOffOn["SwapMaxMB"]==0){
if($pourc>3){
if($pourc>$SwapOffOn["SwapMaxPourc"]){
$execeed_text=$SwapOffOn["SwapMaxPourc"]."%";
$reboot=true;
}
}
}
@unlink($filecache);
@file_put_contents($filecache,"#");
if(!$reboot){return;}
$swapoff=$GLOBALS["CLASS_UNIX"]->find_program("swapoff");
$swapon=$GLOBALS["CLASS_UNIX"]->find_program("swapon");
if(!is_file($swapoff)){events("swapoff no such file",__FUNCTION__,__LINE__);shell_exec("sync; echo \"3\" > /proc/sys/vm/drop_caches >/dev/null 2>&1");return;}
if(!is_file($swapon)){events("swapon no such file",__FUNCTION__,__LINE__);shell_exec("sync; echo \"3\" > /proc/sys/vm/drop_caches >/dev/null 2>&1");return;}
$time=time();
$cmd="$swapoff -a 2>&1";
$results=array();
$results[]=$cmd;
events("running $cmd",__FUNCTION__,__LINE__);
exec($cmd,$results);
$cmd="$swapon -a 2>&1";
$results[]=$cmd;
events("running $cmd",__FUNCTION__,__LINE__);
exec($cmd,$results);
$text=@implode("\n",$results);
$time_duration=distanceOfTimeInWords($time,time());
shell_exec("sync; echo \"3\" > /proc/sys/vm/drop_caches >/dev/null 2>&1");
events("results: $time_duration\n $text",__FUNCTION__,__LINE__);
$GLOBALS["CLASS_UNIX"]->send_email_events("Memory swap purge $execeed_text ($time_duration)",$text,"system");
}
function xLoadAvg(){
if(function_exists("sys_getloadavg")){
$array_load=sys_getloadavg();
$internal_load=$array_load[0];
events("System load $internal_load",__FUNCTION__,__LINE__);
if(!is_dir("/var/log/artica-postfix/loadavg")){@mkdir("/var/log/artica-postfix/loadavg",644,true);}
@file_put_contents("/var/log/artica-postfix/loadavg/".time(), $internal_load);
}
}
function launch_all_status($force=false){
xLoadAvg();
$trace=debug_backtrace();if(isset($trace[1])){$called=" called by ". basename($trace[1]["file"])." {$trace[1]["function"]}() line {$trace[1]["line"]}";events("$called",__FUNCTION__,__LINE__);}
CheckCallable();
if(!is_file("/usr/share/artica-postfix/ressources/logs/global.versions.conf")){
events("-> artica-install --write-version",__FUNCTION__,__LINE__);
$GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --write-versions");
}else{
$filetime=file_time_min("/usr/share/artica-postfix/ressources/logs/global.versions.conf");
events("global.versions.conf={$filetime}mn ",__FUNCTION__,__LINE__);
if($filetime>60){
events("global.versions.conf \"$filetime\"mn",__FUNCTION__,__LINE__);
@unlink("/usr/share/artica-postfix/ressources/logs/global.versions.conf");
$GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --write-versions");
}
}
@unlink($GLOBALS["MY-POINTER"]);
@file_put_contents($GLOBALS["MY-POINTER"],time());
$functions=array("squid_master_status","c_icap_master_status","kav4Proxy_status","dansguardian_master_status","wpa_supplicant","fetchmail","milter_greylist",
"framework","pdns_server","pdns_recursor","cyrus_imap","mysql_server","mysql_mgmt","mysql_replica","openldap","saslauthd","syslogger","squid_tail","amavis",
"amavis_milter","boa","lighttpd","fcron1","fcron2","clamd","clamscan","clammilter","freshclam","retranslator_httpd","spamassassin_milter","spamassassin",
"postfix","postfix_logger","mailman","kas3_milter","kas3_ap","smbd","nmbd","winbindd","scanned_only","roundcube","cups","apache-groupware","apache_groupware",
"gdm","console-kit","xfce","vmtools","hamachi","artica_notifier","dhcpd_server","pure_ftpd","mldonkey","policyd_weight","backuppc","kav4fs","kav4fsavs",
"apache_ocsweb","web_download","ocs_agent","openssh","gluster","auditd","squidguardweb","opendkim","ufdbguardd","squidguard_logger","milter_dkim","dropbox",
"artica_policy","virtualbox_webserv","tftpd","dhcpd_server","crossroads","artica_status","artica_executor","artica_background","bandwith",
"pptpd","pptp_clients","apt_mirror","squid_clamav_tail","ddclient","cluebringer","apachesrc","zarafa_web","zarafa_ical","zarafa_dagent","zarafa_indexer",
"zarafa_monitor","zarafa_gateway","zarafa_spooler","zarafa_server","assp","openvpn","vboxguest","sabnzbdplus","SwapWatchdog","artica_meta_scheduler",
"OpenVPNClientsStatus","stunnel","meta_checks","zarafa_licensed","CheckCurl","ufdbguardd_tail","vnstat","NetAdsWatchdog","munin","autofs","greyhole",
"dnsmasq","iscsi","watchdog_yorel","postfwd2","vps_servers","smartd","crossroads_multiple","auth_tail","greyhole_watchdog","greensql"
);
$data1=$GLOBALS["TIME_CLASS"];
$data2 = time();
$difference = ($data2 - $data1);
$min=round($difference/60);
if($min>9){
events("reloading classes...",__FUNCTION__,__LINE__);
$GLOBALS["TIME_CLASS"]=time();
$GLOBALS["CLASS_SOCKETS"]=new sockets();
$GLOBALS["CLASS_USERS"]=new settings_inc();
$GLOBALS["CLASS_UNIX"]=new unix();
}
while (list ($num, $func) = each ($functions) ){
if(function_exists($func)){
$mem=round(((memory_get_usage()/1024)/1000),2);
events("running function \"$func\" {$mem}MB in memory",__FUNCTION__,__LINE__);
if(!$force){
if(system_is_overloaded()){
events("System is overloaded: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, pause 2 seconds",__FUNCTION__,__LINE__);
AmavisWatchdog();
greyhole_watchdog();
sleep(2);
return;
}else{
if(systemMaxOverloaded()){
events("System is very overloaded {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, pause 5 seconds",__FUNCTION__,__LINE__);
AmavisWatchdog();
greyhole_watchdog();
sleep(5);
return;
}
}
}
try {
$results=call_user_func($func);
} catch (Exception $e) {
writelogs("Fatal while running function $func ($e)",__FUNCTION__,__FILE__,__LINE__);
}
if(trim($results)<>null){$conf[]=$results;}
}
}
@unlink("/usr/share/artica-postfix/ressources/logs/global.status.ini");
file_put_contents("/usr/share/artica-postfix/ressources/logs/global.status.ini",@implode("\n",$conf));
@chmod(770,"/usr/share/artica-postfix/ressources/logs/global.status.ini");
@file_put_contents("/etc/artica-postfix/cache.global.status",@implode("\n",$conf));
events("creating status done ". count($conf)." lines....",__FUNCTION__,__LINE__);
}
// ========================================================================================================================================================
function artica_meta_scheduler(){
if($GLOBALS["CLASS_SOCKETS"]->GET_INFO("ArticaMetaEnabled")==0){events("Artica meta console is disabled....",__FUNCTION__,__LINE__);return;}
if($GLOBALS["PHP5"]==null){$GLOBALS["PHP5"]=LOCATE_PHP5_BIN2();}
$agent_pid="/etc/artica-postfix/pids/exec.artica.meta.php.SendStatus.pid";
$filetime=file_time_min($agent_pid);
events("pid return {$filetime}Mn",__FUNCTION__,__LINE__);
$cmd="{$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} ". dirname(__FILE__)."/exec.artica.meta.php --status";
if($filetime>15){
events("It seems that scheduler did not wants to execute agent, i execute it myself",__FUNCTION__,__LINE__);
$nohup=$GLOBALS["CLASS_UNIX"]->find_program("nohup");
if(strlen($nohup)>4){$cmd="$nohup $cmd >/dev/null 2>&1";}
events("$cmd",__FUNCTION__,__LINE__);
shell_exec($cmd);
return;
}
events("Scheduling status to Artica meta console....GLOBALS[CLASS_UNIX]->THREAD_COMMAND_SET(\"$cmd\")",__FUNCTION__,__LINE__);
$GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET("$cmd");
events("Done...",__FUNCTION__,__LINE__);
}
function OpenVPNClientsStatus(){
$q=new mysql();
@unlink("/usr/share/artica-postfix/ressources/logs/openvpn-clients.status");
$sql="SELECT ID,connexion_name FROM vpnclient WHERE `connexion_type`=2 AND `enabled`=1";
$results=$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){
events($q->mysql_error,__FUNCTION__,__FILE__,__LINE__);
return;
}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$id=$ligne["ID"];
events("Checking VPN client N.$id",__FUNCTION__,__FILE__,__LINE__);
$l[]="[{$ligne["connexion_name"]}]";
$l[]="service_name={$ligne["connexion_name"]}";
$l[]="service_cmd=openvpn";
$l[]="master_version=".GetVersionOf("openvpn");
$l[]="service_disabled=1";
$l[]="family=vpn";
$l[]="watchdog_features=1";
$master_pid=$GLOBALS["CLASS_UNIX"]->get_pid_from_file("/etc/artica-postfix/openvpn/clients/$id/pid");
if(!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)){
WATCHDOG("APP_OPENVPN {$ligne["connexion_name"]}","openvpn");
$l[]="running=0\ninstalled=1";$l[]="";
}else{
$l[]="running=1";
$l[]=GetMemoriesOf($master_pid);
$l[]="";
}
}
if(is_array($l)){$final=implode("\n",$l);}
@file_put_contents("/usr/share/artica-postfix/ressources/logs/openvpn-clients.status",$final);
return $final;
}
function squid_master_status(){
if(!$GLOBALS["CLASS_USERS"]->SQUID_INSTALLED){
if($GLOBALS["VERBOSE"]){echo __FUNCTION__." squid is not installed\n";}
return null;
}else{if($GLOBALS["VERBOSE"]){echo __FUNCTION__." squid is installed\n";}}
$SQUIDEnable=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
if($SQUIDEnable==null){
$SQUIDEnable=1;
$GLOBALS["CLASS_SOCKETS"]->SET_INFO("SQUIDEnable",1);
}
exec("/usr/share/artica-postfix/bin/artica-install --export-version squid 2>&1",$results);
$version=trim(implode("",$results));
$l[]="[SQUID]";
$l[]="service_name=APP_SQUID";
$l[]="master_version=$version";
$l[]="service_cmd=squid-cache";
$l[]="service_disabled=$SQUIDEnable";
$l[]="watchdog_features=1";
$l[]="explain=SQUID_CACHE_TINYTEXT";
$l[]="remove_cmd=--squid-remove";
$l[]="family=squid";
if($GLOBALS["CLASS_USERS"]->SQUID_ICAP_ENABLED){
$l[]="icap_enabled=1";
}
if(!is_file("/var/log/squid/cache.log")){shell_exec("/etc/init/d/artica-postfix restart squid-cache >/dev/null 2>&1 &");}
if($SQUIDEnable==0){$l[]="running=0\ninstalled=1";return implode("\n",$l);return;}
$pid=trim(@file_get_contents("/var/run/squid.pid"));
if(!$GLOBALS["CLASS_UNIX"]->process_exists($pid)){
WATCHDOG("APP_SQUID","squid-cache");
$l[]="running=0\ninstalled=1";
$l[]="";
return implode("\n",$l);return;
}
$l[]="running=1";
$l[]=GetMemoriesOf($pid);
$l[]="";
return implode("\n",$l);return;
}
// ========================================================================================================================================================
function squid_clamav_tail(){
if(!$GLOBALS["CLASS_USERS"]->SQUID_INSTALLED){if($GLOBALS["VERBOSE"]){echo __FUNCTION__." squid is not installed\n";}return null;}else{if($GLOBALS["VERBOSE"]){echo __FUNCTION__." squid is installed\n";}}
$SQUIDEnable=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
if($SQUIDEnable==null){$SQUIDEnable=1;$GLOBALS["CLASS_SOCKETS"]->SET_INFO("SQUIDEnable",1);}
$EnableSquidClamav=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableSquidClamav");
if($SQUIDEnable==0){$EnableSquidClamav=0;}
$master_pid=trim(@file_get_contents("/etc/artica-postfix/exec.squid-clamav-tail.php.pid"));
$version=trim(@implode("",$results));
$l[]="[APP_SQUID_CLAMAV_TAIL]";
$l[]="service_name=APP_SQUID_CLAMAV_TAIL";
$l[]="master_version=".GetVersionOf("artica");
$l[]="service_cmd=squidclamav-tail";
$l[]="service_disabled=$EnableSquidClamav";
$l[]="watchdog_features=1";
if($EnableSquidClamav==0){$l[]="running=0\ninstalled=1";return implode("\n",$l);return;}
if(!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)){
WATCHDOG("APP_SQUID_CLAMAV_TAIL","squidclamav-tail");
$l[]="running=0\ninstalled=1";
$l[]="";
return implode("\n",$l);return;
}
$l[]="running=1";
$l[]=GetMemoriesOf($master_pid);
$l[]="";
return implode("\n",$l);return;
}
// ========================================================================================================================================================
function WATCHDOG($APP_NAME,$cmd){
if($GLOBALS["DISABLE_WATCHDOG"]){return null;}
if($GLOBALS["ArticaWatchDogList"][$APP_NAME]==null){$GLOBALS["ArticaWatchDogList"][$APP_NAME]=1;}
if($GLOBALS["ArticaWatchDogList"][$APP_NAME]==1){
events("WATCHDOG: running $APP_NAME ($cmd)",basename(__FILE__));
exec("/etc/init.d/artica-postfix start $cmd 2>&1",$results);
if($GLOBALS["VERBOSE"]){echo "\n".@implode("\n",$results)."\n";return;}
$GLOBALS["CLASS_UNIX"]->send_email_events("$APP_NAME stopped","Artica tried to start it:\n".@implode("\n",$results),"system");
}
}
function c_icap_master_status(){
if(!$GLOBALS["CLASS_USERS"]->SQUID_INSTALLED){return null;}
if(!$GLOBALS["CLASS_USERS"]->C_ICAP_INSTALLED){return null;}
$SQUIDEnable=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
if($SQUIDEnable==null){$SQUIDEnable=1;$GLOBALS["CLASS_SOCKETS"]->SET_INFO("SQUIDEnable",1);}
$CicapEnabled=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("CicapEnabled");
if($SQUIDEnable==0){$CicapEnabled=0;}
$master_pid=trim(@file_get_contents("/var/run/c-icap.pid"));
$l[]="[C-ICAP]";
$l[]="service_name=APP_C_ICAP";
$l[]="master_version=".GetVersionOf("c-icap");
$l[]="service_cmd=cicap";
$l[]="service_disabled=$CicapEnabled";
$l[]="pidpath=/var/run/c-icap.pid";
$l[]="explain=enable_c_icap_text";
$l[]="family=squid";
if($CicapEnabled==0){
return implode("\n",$l);return;
}
$binpath=$GLOBALS["CLASS_UNIX"]->find_program("c-icap");
$l[]="binpath=$binpath";
if($master_pid==null){$master_pid=$GLOBALS["CLASS_UNIX"]->PIDOF($binpath);}
if(!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)){
$l[]="running=0\ninstalled=1";
$l[]="";
return implode("\n",$l);return;
}
$l[]="running=1";
$l[]=GetMemoriesOf($master_pid);
$l[]="";
return implode("\n",$l);return;
}
// ========================================================================================================================================================
function dansguardian_master_status(){
if(!$GLOBALS["CLASS_USERS"]->SQUID_INSTALLED){return null;}
if(!$GLOBALS["CLASS_USERS"]->DANSGUARDIAN_INSTALLED){return null;}
$SQUIDEnable=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
if($SQUIDEnable==null){$SQUIDEnable=1;}
$enabled=$GLOBALS["CLASS_SOCKETS"]->GET_INFO("DansGuardianEnabled");
if($SQUIDEnable==0){$enabled=0;}
if($enabled==null){$enabled=0;}
$l[]="[DANSGUARDIAN]";
$l[]="service_name=APP_DANSGUARDIAN";
$l[]="master_version=".GetVersionOf("dansguardian");
$l[]="service_cmd=dansguardian";
$l[]="service_disabled=$enabled";
$l[]="remove_cmd=--dansguardian-remove";
$l[]="explain=enable_dansguardian_text";
$l[]="family=squid";
if($enabled==0){return implode("\n",$l);return;}
$master_pid=trim(@file_get_contents("/var/run/dansguardian.pid"));
if($master_pid==null){
$master_pid=$GLOBALS["CLASS_UNIX"]->PIDOF($GLOBALS["CLASS_UNIX"]->find_program("dansguardian"));
}
if(!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)){$l[]="running=0\ninstalled=1";$l[]="";return implode("\n",$l);return;}
$l[]="running=1";
$l[]=GetMemoriesOf($master_pid);
$l[]="";
return implode("\n",$l);return;
}
// ========================================================================================================================================================
function dansguardian_tail_status(){
if(!$GLOBALS["CLASS_USERS"]->SQUID_INSTALLED){return null;}