forked from poppyred/1.6.x
/
exec.nginx.php
executable file
·2617 lines (2075 loc) · 84.6 KB
/
exec.nginx.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
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
$GLOBALS["FORCE"]=false;
$GLOBALS["RECONFIGURE"]=false;
$GLOBALS["SWAPSTATE"]=false;
$GLOBALS["NOSQUIDOUTPUT"]=true;
$GLOBALS["VERBOSE"]=false;
$GLOBALS["RELOAD"]=false;
$GLOBALS["pidStampReload"]="/etc/artica-postfix/pids/".basename(__FILE__).".Stamp.reload.time";
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__).'/ressources/class.ldap.inc');
include_once(dirname(__FILE__).'/ressources/class.nginx.inc');
include_once(dirname(__FILE__).'/ressources/class.freeweb.inc');
include_once(dirname(__FILE__).'/framework/class.unix.inc');
include_once(dirname(__FILE__).'/ressources/class.squid.reverse.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__).'/framework/class.settings.inc');
include_once(dirname(__FILE__).'/ressources/class.resolv.conf.inc');
$GLOBALS["ARGVS"]=implode(" ",$argv);
if($argv[1]=="--dump-modules"){$GLOBALS["OUTPUT"]=true;dump_nginx_params();exit;}
if($argv[1]=="--reconfigure-all-reboot"){$GLOBALS["OUTPUT"]=true;reconfigure_all();exit;}
if($argv[1]=="--reconfigure"){$GLOBALS["OUTPUT"]=true;configure_single_website($argv[2]);die();}
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]=="--force-restart"){$GLOBALS["OUTPUT"]=true;force_restart();die();}
if($argv[1]=="--build"){$GLOBALS["OUTPUT"]=true;$GLOBALS["RECONFIGURE"]=true;build();die();}
if($argv[1]=="--main"){$GLOBALS["OUTPUT"]=true;$GLOBALS["RECONFIGURE"]=true;build(true);die();}
if($argv[1]=="--artica-web"){articaweb();exit;}
if($argv[1]=="--install-nginx"){install_nginx();exit;}
if($argv[1]=="--status"){status();exit;}
if($argv[1]=="--rotate"){rotate();exit;}
if($argv[1]=="--awstats"){awstats();exit;}
if($argv[1]=="--caches-status"){caches_status();exit;}
if($argv[1]=="--framework"){$GLOBALS["OUTPUT"]=true;framework();exit;}
if($argv[1]=="--tests-sources"){test_sources();exit;}
if($argv[1]=="--reconfigure-all"){$GLOBALS["OUTPUT"]=true;build_localhosts();exit;}
if($argv[1]=="--authenticator"){$GLOBALS["OUTPUT"]=true;authenticator(true);exit;}
if($argv[1]=="--purge-cache"){$GLOBALS["OUTPUT"]=true;purge_cache($argv[2]);exit;}
if($argv[1]=="--purge-all-caches"){$GLOBALS["OUTPUT"]=true;purge_all_caches();exit;}
if($argv[1]=="--import-file"){$GLOBALS["OUTPUT"]=true;import_file();exit;}
if($argv[1]=="--import-bulk"){$GLOBALS["OUTPUT"]=true;import_bulk();exit;}
if($argv[1]=="--mem"){$GLOBALS["OUTPUT"]=true;parse_memory();exit;}
if($argv[1]=="--mymem"){$GLOBALS["OUTPUT"]=true;max_memory();exit;}
if($argv[1]=="--mail"){$GLOBALS["OUTPUT"]=true;mail_protocols();exit;}
if($argv[1]=="--build-default"){$GLOBALS["OUTPUT"]=true;$GLOBALS["RELOAD"]=true;build_default();exit;}
echo "Unable to understand this command\n";
echo "Should be:\n";
echo "--framework...........: Build framework\n";
echo "--caches-status.......: Build caches status\n";
echo "--build-default.......: Build default website\n";
function mail_protocols(){
$sock=new sockets();
if(is_file("/etc/nginx/conf.d/mail.conf")){@unlink("/etc/nginx/conf.d/mail.conf");}
$EnableNginxMail=intval($sock->GET_INFO("EnableNginxMail"));
if($EnableNginxMail==0){
echo "Starting......: ".date("H:i:s")." [INIT]: EnableNginxMail: $EnableNginxMail, aborting\n";
return;}
$unix=new unix();
$hostname=$unix->hostname_g();
$f[]="mail {";
$f[]="\tserver_name $hostname;";
$f[]="\tauth_http unix:/usr/share/artica-postfix/ressources/web/framework.sock:/auth.unix.php;";
$f[]="";
$f[]="\timap_capabilities IMAP4rev1 UIDPLUS IDLE LITERAL+ QUOTA;";
$f[]="\timap_auth login plain cram-md5;";
$f[]="";
$f[]="\tpop3_auth plain apop cram-md5;";
$f[]="\tpop3_capabilities LAST TOP USER PIPELINING UIDL;";
$f[]="";
$f[]="\tsmtp_auth login plain cram-md5;";
$f[]="\tsmtp_capabilities \"SIZE 10485760\" ENHANCEDSTATUSCODES PIPELINING 8BITMIME DSN;";
$f[]="\txclient off;";
$f[]="\tproxy on;";
$f[]="";
$f[]="\tssl_prefer_server_ciphers on;";
$f[]="\tssl_protocols TLSv1 SSLv3;";
$f[]="\tssl_ciphers HIGH:!ADH:!MD5:@STRENGTH;";
$f[]="\tssl_session_cache shared:MAIL:10m;";
$nginx_certificate=new nginx_certificate();
$f[]=$nginx_certificate->GetConf();
$f[]="\tserver {";
$f[]="\t\tlisten 25;";
$f[]="\t\tprotocol smtp;";
$f[]="\t\ttimeout 120000;";
$f[]="\t\tsmtp_auth none;";
$f[]="\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 143;";
$f[]="\t\tprotocol imap;";
$f[]="\t\tproxy on;";
$f[]="\t\tproxy_pass_error_message on;";
$f[]="\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 465;";
$f[]="\t\tprotocol smtp;";
$f[]="\t\tssl on;";
$f[]="\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 587;";
$f[]="\t\tprotocol smtp;";
$f[]="\t\tstarttls on;";
$f[]="\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 110;";
$f[]="\t\tprotocol pop3;";
$f[]="\t\tstarttls on;";
$f[]="\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 995;";
$f[]="\t\tprotocol pop3;";
$f[]="\t\tssl on;";
$f[]="\t\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 143;";
$f[]="\t\tprotocol imap;";
$f[]="\t\tstarttls on;";
$f[]="\t\t}";
$f[]="";
$f[]="\tserver {";
$f[]="\t\tlisten 993;";
$f[]="\t\tprotocol imap;";
$f[]="\t\tssl on;";
$f[]="\t}";
$f[]="}";
return @implode("\n", $f);
}
function nginx_version(){
if(isset($GLOBALS["nginx_version"])){return $GLOBALS["nginx_version"];}
$unix=new unix();
$bin=$unix->find_program("nginx");
if(!is_file($bin)){return 0;}
exec("$bin -v 2>&1",$array);
while (list ($pid, $line) = each ($array) ){
if(preg_match("#\/([0-9\.\-]+)#i", $line,$re)){
$GLOBALS["nginx_version"]=$re[1];
return $re[1];}
if($GLOBALS['VERBOSE']){echo "nginx_version(), $line, not found \n";}
}
}
function dump_nginx_params(){
$unix=new unix();
$ARRAY=$unix->NGINX_COMPILE_PARAMS();
$nginx=new nginx();
while (list ($a, $b) = each ($ARRAY["MODULES"]) ){
echo "Module: \"$a\"\n";
}
echo "Substitutions: ".$nginx->IsSubstitutions()."\n";
}
function build($OnlySingle=false){
if(isset($GLOBALS[__FILE__.__FUNCTION__])){return;}
$GLOBALS[__FILE__.__FUNCTION__]=true;
$unix=new unix();
$php5=$unix->LOCATE_PHP5_BIN();
shell_exec("/etc/init.d/mysql start");
build_progress("{building_main_settings}",10);
if($unix->SQUID_GET_LISTEN_PORT()==80){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Squid listen 80, ports conflicts, change it\n";}
shell_exec("$php5 /usr/share/artica-postfix/exec.squid.php --build --force");
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Restarting Squid-cache..\n";}
shell_exec("/etc/init.d/squid restart --script=".basename(__FILE__));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: done...\n";}
}
if($unix->SQUID_GET_LISTEN_SSL_PORT()==443){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Squid listen 443, ports conflicts, change it\n";}
shell_exec("$php5 /usr/share/artica-postfix/exec.squid.php --build --force");
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Restarting Squid-cache..\n";}
shell_exec("/etc/init.d/squid restart --script=".basename(__FILE__));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: done...\n";}
}
$reconfigured=false;
if($unix->APACHE_GET_LISTEN_PORT()==80){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Apache listen 80, ports conflicts, change it\n";}
shell_exec("$php5 /usr/share/artica-postfix/exec.freeweb.php --build --force");
shell_exec("$php5 /usr/share/artica-postfix/exec.freeweb.php --stop --force");
shell_exec("$php5 /usr/share/artica-postfix/exec.freeweb.php --start --force");
$reconfigured=true;
}
if(!$reconfigured){
if($unix->APACHE_GET_LISTEN_PORT()==443){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Apache listen 443, ports conflicts, change it\n";}
shell_exec("$php5 /usr/share/artica-postfix/exec.freeweb.php --build --force");
}
}
$APACHE_USER=$unix->APACHE_SRC_ACCOUNT();
$APACHE_SRC_GROUP=$unix->APACHE_SRC_GROUP();
$NginxProxyStorePath="/home/nginx";
@mkdir("/etc/nginx/sites-enabled",0755,true);
@mkdir("/etc/nginx/local-sites",0755,true);
@mkdir("/etc/nginx/local-sslsites",0755,true);
@mkdir($NginxProxyStorePath,0755,true);
@mkdir($NginxProxyStorePath."/tmp",0755,true);
@mkdir($NginxProxyStorePath."/disk",0755,true);
@mkdir("/var/lib/nginx/fastcgi",0755,true);
@mkdir("/home/nginx/tmp",0755,true);
$Tempdir=$unix->TEMP_DIR()."/nginx";
@mkdir($Tempdir,0755,true);
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, $NginxProxyStorePath);
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, "/etc/nginx/sites-enabled");
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, $NginxProxyStorePath."/tmp");
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, $NginxProxyStorePath."/disk");
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, "/var/lib/nginx/fastcgi");
$unix->chown_func($APACHE_USER,$APACHE_SRC_GROUP, $Tempdir);
nginx_ulimit();
$workers=$unix->CPU_NUMBER();
build_progress("Building configuration",15);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Running $APACHE_USER:$APACHE_SRC_GROUP..\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Running $workers worker(s)..\n";}
if(is_file("/etc/nginx/sites-enabled/default")){@unlink("/etc/nginx/sites-enabled/default");}
if(is_link("/etc/nginx/sites-enabled/default")){@unlink("/etc/nginx/sites-enabled/default");}
if(is_link("/etc/nginx/conf.d/example_ssl.conf")){@unlink("/etc/nginx/conf.d/example_ssl.conf");}
$limit=4096*$workers;
if($limit>65535){$limit=65535;}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, Running limit of $limit open files\n";}
$L=explode("\n",@file_get_contents("/etc/security/limits.conf"));
$FOUNDL=false;
$T=array();
while (list ($index, $line) = each ($L)){
$line=trim($line);
if(trim($line)==null){continue;}
if(substr($line, 0,1)=="#"){continue;}
if(preg_match("#^$APACHE_USER#", $line)){continue;}
$T[]=$line;
}
if(!$FOUNDL){
$T[]="$APACHE_USER soft nofile $limit";
$T[]="$APACHE_USER hard nofile $limit";
}
@file_put_contents("/etc/security/limits.conf", @implode("\n", $T)."\n");
$L=array();
$T=array();
$MEMORY=$unix->MEM_TOTAL_INSTALLEE();
$server_names_hash_bucket_size=128;
$worker_connections=8192;
if($MEMORY<624288){
$server_names_hash_bucket_size=64;
$worker_connections=1024;
$workers=4;
}
$mail_protocols=mail_protocols();
//
$f[]="# Builded on ".date("Y-m-d H:i:s");
$f[]="user $APACHE_USER;";
$f[]="worker_processes $workers;";
$nginx_version=nginx_version();
preg_match("#^([0-9])+\.([0-9]+)\.#", $nginx_version,$re);
$re[1]=intval($re[1]);
$re[2]=intval($re[2]);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, Major {$re[1]} Minor:{$re[2]}\n";}
$syslog=false;
$f[]="worker_rlimit_nofile 16384;";
$f[]="timer_resolution 1ms;";
$f[]="";
if($re[1]>0){
if($re[2]>6){
$f[]="error_log syslog:server=127.0.0.1,facility=daemon info;";
$syslog=true;
}
}
$syslog=false;
if(!$syslog){
$f[]="error_log /var/log/nginx/error.log warn;";
}
$f[]="pid /var/run/nginx.pid;";
$f[]="";
$f[]="";
$f[]="events {";
$f[]=" worker_connections $worker_connections;";
$f[]=" multi_accept on;";
$f[]=" use epoll;";
$f[]=" accept_mutex_delay 1ms;";
$f[]="}";
$upstream=new nginx_upstream();
$upstreams_servers=$upstream->build();
$f[]="";
$f[]="";
$f[]="http {";
$f[]="\tinclude /etc/nginx/mime.types;";
$f[]="\tlimit_conn_zone \$binary_remote_addr zone=LimitCnx:10m;";
$q=new mysql_squid_builder();
$results=$q->QUERY_SQL("SELECT LimitReqs,servername FROM reverse_www WHERE LimitReqs > 0");
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$servername=$ligne["servername"];
$ZoneName=str_replace(".", "", $servername);
$ZoneName=str_replace("-", "", $servername);
$ZoneName=str_replace("_", "", $servername);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, limit $servername/$servername {$ligne["LimitReqs"]}r/s\n";}
$f[]="\tlimit_req_zone \$binary_remote_addr zone=$ZoneName:10m rate={$ligne["LimitReqs"]}r/s;";
}
$nginxClass=new nginx();
if($nginxClass->IsSubstitutions()){
$f[]="\tsubs_filter_types text/html text/css text/xml;";
}
@mkdir($Tempdir,0775,true);
$f[]="\tlimit_conn_log_level info;";
$f[]="\tclient_body_temp_path $Tempdir 1 2;";
$f[]="\tclient_header_timeout 5s;";
$f[]="\tclient_body_timeout 5s;";
$f[]="\tsend_timeout 10m;";
$f[]="\tconnection_pool_size 128k;";
$f[]="\tclient_header_buffer_size 16k;";
$f[]="\tlarge_client_header_buffers 1024 128k;";
$f[]="\trequest_pool_size 128k;";
$f[]="\tkeepalive_requests 1000;";
$f[]="\tkeepalive_timeout 10;";
$f[]="\tclient_max_body_size 10g;";
$f[]="\tclient_body_buffer_size 1m;";
$f[]="\tclient_body_in_single_buffer on;";
$f[]="\topen_file_cache max=10000 inactive=300s;";
$f[]="\treset_timedout_connection on;";
$f[]="\ttypes_hash_max_size 8192;";
$f[]="\tserver_names_hash_bucket_size 128;";
$f[]="\tserver_names_hash_max_size 512;";
$f[]="\tvariables_hash_max_size 512;";
$f[]="\tvariables_hash_bucket_size 128;";
$f[]="\tfastcgi_buffers 8 16k;";
$f[]="\tfastcgi_buffer_size 32k;";
$f[]="\tfastcgi_connect_timeout 300;";
$f[]="\tfastcgi_send_timeout 300;";
$f[]="\tfastcgi_read_timeout 300;";
$f[]="map \$scheme \$server_https {";
$f[]="default off;";
$f[]="https on;";
$f[]="} ";
$f[]="\tgzip on;";
$f[]="\tgzip_disable msie6;";
$f[]="\tgzip_static on;";
$f[]="\tgzip_min_length 1100;";
$f[]="\tgzip_buffers 16 8k;";
$f[]="\tgzip_comp_level 9;";
$f[]="\tgzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;";
$f[]="\tgzip_vary on;";
$f[]="\tgzip_proxied any;";
$f[]="\toutput_buffers 1000 128k;";
$f[]="\tpostpone_output 1460;";
$f[]="\tsendfile on;";
$f[]="\tsendfile_max_chunk 256k;";
$f[]="\ttcp_nopush on;";
$f[]="\ttcp_nodelay on;";
$f[]="\tserver_tokens off;";
$dns=new resolv_conf();
$sock=new sockets();
if($sock->dnsmasq_enabled()){
$resolver[]="127.0.0.1";
}
if($dns->MainArray["DNS1"]<>null){$resolver[]=$dns->MainArray["DNS1"];}
if($dns->MainArray["DNS2"]<>null){$resolver[]=$dns->MainArray["DNS2"];}
if($dns->MainArray["DNS3"]<>null){$resolver[]=$dns->MainArray["DNS3"];}
$f[]="\tresolver ". @implode(" ", $resolver).";";
$f[]="\tignore_invalid_headers on;";
$f[]="\tindex index.html;";
$f[]="\tadd_header X-CDN \"Served by myself\";";
$q=new mysql_squid_builder();
$sql="SELECT * FROM nginx_caches ORDER BY directory";
$results=$q->QUERY_SQL($sql);
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
$directory=$ligne["directory"];
@mkdir($directory,0755,true);
$unix->chown_func("www-data","www-data", $directory);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, cache `$directory`\n";}
$f[]="\tproxy_cache_path $directory levels={$ligne["levels"]} keys_zone={$ligne["keys_zone"]}:{$ligne["keys_zone_size"]}m max_size={$ligne["max_size"]}G inactive={$ligne["inactive"]} loader_files={$ligne["loader_files"]} loader_sleep={$ligne["loader_sleep"]} loader_threshold={$ligne["loader_threshold"]};";
}
$f[]="\tproxy_temp_path $NginxProxyStorePath/tmp/ 1 2;";
$f[]="\tproxy_cache_valid 404 10m;";
$f[]="\tproxy_cache_valid 400 501 502 503 504 1m;";
$f[]="\tproxy_cache_valid any 4320m;";
$f[]="\tproxy_cache_use_stale updating invalid_header error timeout http_404 http_500 http_502 http_503 http_504;";
$f[]="\tproxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504;";
$f[]="\tproxy_redirect off;";
$f[]="\tproxy_set_header Host \$http_host;";
$f[]="\tproxy_set_header Server Apache;";
$f[]="\tproxy_set_header Connection Close;";
$f[]="\tproxy_pass_header Set-Cookie;";
$f[]="\tproxy_pass_header User-Agent;";
$f[]="\tproxy_set_header X-Accel-Buffering on;";
$f[]="\tproxy_hide_header X-CDN;";
$f[]="\tproxy_hide_header X-Server;";
$f[]="\tproxy_intercept_errors off;";
$f[]="\tproxy_ignore_client_abort on;";
$f[]="\tproxy_connect_timeout 60s;";
$f[]="\tproxy_send_timeout 60s;";
$f[]="\tproxy_read_timeout 150s;";
$f[]="\tproxy_buffer_size 128k;";
$f[]="\tproxy_buffers 16384 128k;";
$f[]="\tproxy_busy_buffers_size 256k;";
$f[]="\tproxy_temp_file_write_size 128k;";
$f[]="\tproxy_headers_hash_bucket_size 128;";
$f[]="\tproxy_cache_min_uses 0;";
$f[]="";
$f[]="$upstreams_servers";
$f[]="\tlog_format aws_log";
$f[]="\t\t'\$remote_addr - \$remote_user [\$time_local] \$request '";
$f[]="\t\t'\"\$status\" \$body_bytes_sent \"\$http_referer\" '";
$f[]="\t\t'\"\$http_user_agent\" \"\$http_x_forwarded_for\" [\$upstream_cache_status]';";
$f[]="";
$f[]="\tlog_format awc_log";
$f[]="\t\t'[\$server_name] \$remote_addr - \$remote_user [\$time_local] \$request '";
$f[]="\t\t'\"\$status\" \$body_bytes_sent \"\$http_referer\" '";
$f[]="\t\t'\"\$http_user_agent\" \"\$http_x_forwarded_for\" [\$upstream_cache_status]';";
$f[]="";
$f[]="\tinclude /etc/nginx/sites-enabled/*.conf;";
$f[]="\tinclude /etc/nginx/local-sites/*.conf;";
$f[]="\tinclude /etc/nginx/conf.d/*.conf;";
$f[]="\t}";
$f[]=$mail_protocols;
$f[]="";
@copy("/etc/nginx/nginx.conf","/etc/nginx/nginx.bak");
@file_put_contents("/etc/nginx/nginx.conf", @implode("\n", $f));
if(!$OnlySingle){
if($GLOBALS["VERBOSE"]){echo __FUNCTION__.".".__LINE__.": OK...\n";}
build_progress("Building default configuration",10);
build_default(true);
build_localhosts();
if($GLOBALS["VERBOSE"]){echo __FUNCTION__.".".__LINE__.": OK...\n";}
}else{
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, Only single defined\n";}
}
if($GLOBALS["RECONFIGURE"]){
$pid=PID_NUM();
if(is_numeric($pid)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, reload pid $pid\n";}
$kill=$unix->find_program("kill");
unix_system_HUP($pid);
}else{
start(true);
}
}
build_progress("Building configuration done",10);
}
function configure_single_freeweb($servername){
$q=new mysql();
$unix=new unix();
$php=$unix->LOCATE_PHP5_BIN();
$ligne=mysql_fetch_array($q->QUERY_SQL("SELECT * from freeweb WHERE servername='$servername'","artica_backup"));
$free=new freeweb($servername);
$NginxFrontEnd=$free->NginxFrontEnd;
$groupware=$free->groupware;
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, $servername [$groupware]\n";}
$NOPROXY["SARG"]=true;
$NOPROXY["ARTICA_MINIADM"]=true;
$NOPROXY["WORDPRESS"]=true;
$NOPROXY[null]=true;
$q2=new mysql_squid_builder();
$ligne2=mysql_fetch_array($q2->QUERY_SQL("SELECT cacheid FROM reverse_www WHERE servername='{$ligne["servername"]}'"));
$host=new nginx($servername);
if(isset($NOPROXY[$groupware])){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, $servername compile as FRONT-END\n";}
$free->CheckWorkingDirectory();
$host->set_proxy_disabled();
$host->set_DocumentRoot($free->WORKING_DIRECTORY);
if($groupware=="SARG"){$host->SargDir();}
if($groupware=="WORDPRESS"){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,$php /usr/share/artica-postfix/exec.wordpress.php \"$servername\"\n";}
system("$php /usr/share/artica-postfix/exec.wordpress.php \"$servername\"");
$host->WORDPRESS=true;
$host->set_index_file("index.php");
}
}else{
$host->set_freeweb();
$host->set_storeid($ligne2["cacheid"]);
}
if($free->groupware=="Z-PUSH"){$host->NoErrorPages=true;}
if($free->groupware=="WORDPRESS"){$host->WORDPRESS=true;}
$host->set_servers_aliases($free->Params["ServerAlias"]);
if($groupware=="ZARAFA"){
if($free->NginxFrontEnd==1){
$host->groupware_zarafa_Frontend();
configure_single_website_rebuild();
configure_single_website_reload();
return;
}
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, $servername building configuration...\n";}
$host->build_proxy();
configure_single_website_rebuild();
configure_single_website_reload();
}
function configure_single_website_rebuild(){
LoadConfigs();
build(true);
}
function configure_single_website($servername,$noreload=false,$nopid=false){
$unix=new unix();
$sock=new sockets();
if(!$nopid){
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
$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]: Nginx Already Artica task running PID $pid since {$time}mn\n";}
return;
}
@file_put_contents($pidfile, getmypid());
}
$EnableFreeWeb=$sock->GET_INFO("EnableFreeWeb");
if(!is_numeric($EnableFreeWeb)){$EnableFreeWeb=0;}
$q=new mysql();
$sql="SELECT servername from freeweb WHERE servername='$servername'";
$q=new mysql();
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
if($ligne["servername"]<>null){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, $servername is a freeweb\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, *** NOTICE *** $servername is a freeweb\n";}
configure_single_freeweb($servername);
if(!$noreload){configure_single_website_reload(); }
return;
}
$q=new mysql_squid_builder();
$sql="SELECT * FROM `reverse_www` WHERE `enabled`=1 AND servername='$servername'";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql));
if(!$q->ok){if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,[".__LINE__."] $servername $q->mysql_error\n";}return;}
configure_single_website_rebuild();
BuildReverse($ligne,true);
if(!$noreload){configure_single_website_reload(); }
}
function configure_single_website_reload(){
$unix=new unix();
$pid=PID_NUM();
if(is_numeric($pid)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, reload pid $pid\n";}
$nginx=$unix->find_program("nginx");
shell_exec("$nginx -c /etc/nginx/nginx.conf -s reload >/dev/null 2>&1");
if($unix->process_exists($pid)){
nginx_admin_mysql(1, "Nginx Web service reload done [action=start]", null,__FILE__,__LINE__);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, Success service reloaded pid:$pid...\n";}
}
}else{
start(true);
}
}
function LoadConfigs(){
if(isset($GLOBALS["LoadConfigs"])){return;}
$GLOBALS["REMOVE_LOCAL_ADDR"]=false;
$unix=new unix();
$q=new mysql_squid_builder();
$ligne=mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(*) as tcount FROM reverse_www WHERE default_server=0"));
if(!$q->ok){if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, *** FATAL ** $q->mysql_error\n";}return;}
if($ligne["tcount"]>0){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx *** NOTICE *** Defaults websites as been defined, no IP addresses are allowed\n";}
$EnableArticaFrontEndToNGninx=0;$GLOBALS["REMOVE_LOCAL_ADDR"]=true;
}
if($GLOBALS["REMOVE_LOCAL_ADDR"]){$GLOBALS["IPADDRS"]=$unix->NETWORK_ALL_INTERFACES(true);unset($GLOBALS["IPADDRS"]["127.0.0.1"]);}
$GLOBALS["LoadConfigs"]=true;
}
function authenticator($alone=false){
if($alone){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
$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]: Nginx Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, Authenticate port /var/run/nginx-authenticator.sock\n";}
$host=new nginx("unix:/var/run/nginx-authenticator.sock");
$host->set_proxy_disabled();
$host->set_DocumentRoot("/usr/share/artica-postfix");
$host->set_index_file("authenticator.php");
$host->build_proxy();
if($alone){
stop(true);
start(true);
}
}
function build_localhosts(){
if($GLOBALS["VERBOSE"]){echo "\n############################################################\n\n".__FUNCTION__.".".__LINE__.":Start...\n";}
$squidR=new squidbee();
$rev=new squid_reverse();
$sock=new sockets();
$unix=new unix();
LoadConfigs();
$EnableArticaFrontEndToNGninx=$sock->GET_INFO("EnableArticaFrontEndToNGninx");
$EnableFreeWeb=$sock->GET_INFO("EnableFreeWeb");
if(!is_numeric($EnableArticaFrontEndToNGninx)){$EnableArticaFrontEndToNGninx=0;}
if(!is_numeric($EnableFreeWeb)){$EnableFreeWeb=0;}
$NginxAuthPort=$sock->GET_INFO("NginxAuthPort");
if($NginxAuthPort==null){
$NginxAuthPort="unix:/var/run/nginx-authenticator.sock";
$sock->SET_INFO("NginxAuthPort",$NginxAuthPort);
}
if($EnableArticaFrontEndToNGninx==1){
shell_exec("/etc/init.d/artica-webconsole stop >/dev/null 2>&1 &");
$ArticaHttpsPort=$sock->GET_INFO("ArticaHttpsPort");
$ArticaHttpUseSSL=$sock->GET_INFO("ArticaHttpUseSSL");
if(!is_numeric($ArticaHttpUseSSL)){$ArticaHttpUseSSL=1;}
if(!is_numeric($ArticaHttpsPort)){$ArticaHttpsPort=9000;}
$LighttpdArticaListenIP=$sock->GET_INFO('LighttpdArticaListenIP');
$host=new nginx($ArticaHttpsPort);
$host->set_ssl();
$host->set_listen_ip($LighttpdArticaListenIP);
$host->set_proxy_disabled();
$host->set_DocumentRoot("/usr/share/artica-postfix");
$host->set_index_file("admin.index.php");
$host->build_proxy();
}
$q=new mysql();
foreach (glob("/etc/nginx/sites-enabled-backuped/*") as $filename) {@unlink($filename);}
@mkdir("/etc/nginx/sites-enabled-backuped",0755,true);
$q=new mysql_squid_builder();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, scanning /etc/nginx/sites-enabled\n";}
build_progress("Backup old config",10);
foreach (glob("/etc/nginx/local-sites/*") as $filename) {
@unlink($filename);
}
foreach (glob("/etc/nginx/sites-enabled/*") as $filename) {
$file=basename($filename);
if(is_numeric($file)){@unlink($filename);continue;}
$filedetect=$file;
if(!preg_match("#freewebs-#", $file,$re)){continue;}
if(preg_match("#_default_#", $file)){@unlink($filename);continue;}
$filedetect=str_replace("freewebs-ssl-", "", $filedetect);
$filedetect=str_replace("freewebs-", "", $filedetect);
$filedetect=str_replace("freewebs-unix-", "", $filedetect);
if(preg_match("#([0-9])-(.+?)\.([0-9]+)\.conf$#",$filedetect,$re)){$filedetect="{$re[2]}.{$re[3]}.conf"; }
if(preg_match("#(.+?)\.[0-9]+\.conf$#",$filedetect,$re)){
$sitename=$re[1];
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, [$sitename] backup/remove $filename\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, backup \"$file\"\n";}
@copy($filename, "/etc/nginx/sites-enabled-backuped/$file");
@unlink($filename);
continue;
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, backup \"$file\"\n";}
@copy($filename, "/etc/nginx/sites-enabled-backuped/$file");
@unlink($filename);
}
$NOPROXY["SARG"]=true;
$NOPROXY["ARTICA_MINIADM"]=true;
build_progress("Building Artica in Nginx (if set)",10);
BuildArticaInNginx();
build_progress("Building authenticator",10);
authenticator(false);
}
function BuildArticaInNginx(){
$sock=new sockets();
$unix=new unix();
$BuildFrameWorkInNginx=false;
$EnableArticaFrontEndToNGninx=intval($sock->GET_INFO("EnableArticaFrontEndToNGninx"));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, EnableArticaFrontEndToNGninx = $EnableArticaFrontEndToNGninx\n";}
if($EnableArticaFrontEndToNGninx==0){return;}
$SargOutputDir=$sock->GET_INFO("SargOutputDir");
if($SargOutputDir==null){$SargOutputDir="/var/www/html/squid-reports";}
if(!is_dir($SargOutputDir)){@mkdir($SargOutputDir,0755,true);}
if(!is_file("$SargOutputDir/logo.gif")){@copy("/usr/share/artica-postfix/css/images/logo.gif", "$SargOutputDir/logo.gif");}
if(!is_file("$SargOutputDir/pattern.png")){@copy("/usr/share/artica-postfix/css/images/pattern.png", "$SargOutputDir/pattern.png");}
$phpfpm=$unix->APACHE_LOCATE_PHP_FPM();
$EnablePHPFPM=$sock->GET_INFO("EnablePHPFPM");
$EnableArticaApachePHPFPM=$sock->GET_INFO("EnableArticaApachePHPFPM");
if(!is_numeric($EnableArticaApachePHPFPM)){$EnableArticaApachePHPFPM=0;}
if($EnableArticaApachePHPFPM==0){$EnablePHPFPM=0;}
$EnableSargGenerator=$sock->GET_INFO("EnableSargGenerator");
if(!is_numeric($EnableSargGenerator)){$EnableSargGenerator=1;}
if(!is_numeric($EnablePHPFPM)){$EnablePHPFPM=0;}
if(!is_file($phpfpm)){$EnablePHPFPM=0;}
if($EnablePHPFPM==1){
ToSyslog("Restarting PHP5-FPM");
shell_exec("/etc/init.d/php5-fpm reload >/dev/null 2>&1");
}
$host=new nginx("0.0.0.0:9000");
$host->set_ssl();
$host->set_proxy_disabled();
$host->set_DocumentRoot("/usr/share/artica-postfix");
$host->set_index_file("admin.index.php");
$host->build_proxy();
$lighttpdbin=$unix->find_program("lighttpd");
if(!is_file($lighttpdbin)){$BuildFrameWorkInNginx=true;}
if(is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")){$BuildFrameWorkInNginx=true;}
if($EnableSargGenerator==1){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, SARG is enabled...\n";}
$host->SargDir();
$host->build_proxy();
}
if($BuildFrameWorkInNginx){
if(is_file("/etc/php5/fpm/pool.d/framework.conf")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, building framework...\n";}
$host=new nginx(47980);
$host->set_proxy_disabled();
$host->set_DocumentRoot("/usr/share/artica-postfix/framework");
$host->set_framework();
$host->set_listen_ip("127.0.0.1");
$host->set_servers_aliases(array("127.0.0.1"));
$host->build_proxy();
}
}
}
function BuildReverse($ligne,$backupBefore=false){
$q=new mysql_squid_builder();
$ligne["servername"]=trim($ligne["servername"]);
$IPADDRS=$GLOBALS["IPADDRS"];
$ligne["servername"]=trim($ligne["servername"]);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,[".__LINE__."] ************* {$ligne["servername"]}:{$ligne["port"]} / $DenyConf ************* \n";}
if($ligne["port"]==82){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,[".__LINE__."] 82 port is an apache port, SKIP\n";}
return;
}
if($GLOBALS["REMOVE_LOCAL_ADDR"]){
if(isset($IPADDRS[$ligne["servername"]])){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,[".__LINE__."] {$ligne["servername"]} *** SKIPPED ***\n";}
continue;
}
}
if(isset($ALREADYSET[$ligne["servername"]])){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx,[".__LINE__."] `{$ligne["servername"]}` Already defined, abort\n";}
continue;
}
$ListenPort=$ligne["port"];
$SSL=$ligne["ssl"];
$certificate=$ligne["certificate"];
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, protect remote web site `{$ligne["servername"]}:$ListenPort [SSL:$SSL]`\n";}
if($ligne["servername"]==null){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, skip it...\n";}
continue;
}
$cache_peer_id=$ligne["cache_peer_id"];
if($cache_peer_id>0){
$ligne2=mysql_fetch_array($q->QUERY_SQL("SELECT * FROM `reverse_sources` WHERE `ID`='$cache_peer_id'"));
}
$host=new nginx($ligne["servername"]);
if($ListenPort==80 && $SSL==1){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, HTTP/HTTPS Enabled...\n";}
$host->set_RedirectQueries($ligne["RedirectQueries"]);
$host->set_forceddomain($ligne2["forceddomain"]);
$host->set_ssl(0);
$host->set_proxy_port($ligne2["port"]);
$host->set_listen_port(80);
$host->set_poolid($ligne["poolid"]);
$host->set_owa($ligne["owa"]);
$host->set_storeid($ligne["cacheid"]);
$host->set_cache_peer_id($cache_peer_id);
$host->BackupBefore=$backupBefore;
$host->build_proxy();
$host=new nginx($ligne["servername"]);
$host->set_ssl_certificate($certificate);
$host->set_ssl_certificate($ligne2["ssl_commname"]);
$host->set_forceddomain($ligne2["forceddomain"]);
$host->BackupBefore=$backupBefore;
$host->set_ssl(1);
$host->set_proxy_port($ligne2["port"]);
$host->set_listen_port(443);
$host->set_poolid($ligne["poolid"]);
$host->set_owa($ligne["owa"]);
$host->set_storeid($ligne["cacheid"]);
$host->set_cache_peer_id($cache_peer_id);
$host->build_proxy();
}
if($ligne["ssl"]==1){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Nginx, SSL Enabled...\n";}
$ligne2["ssl"]=1;
}
if($ligne["port"]==443){
$ligne2["ssl"]=1;
}
$host->BackupBefore=$backupBefore;
$host->set_RedirectQueries($ligne["RedirectQueries"]);
$host->set_ssl_certificate($certificate);
$host->set_ssl_certificate($ligne2["ssl_commname"]);
$host->set_forceddomain($ligne2["forceddomain"]);
$host->set_ssl($ligne2["ssl"]);
$host->set_proxy_port($ligne2["port"]);
$host->set_listen_port($ligne["port"]);
$host->set_poolid($ligne["poolid"]);
$host->set_owa($ligne["owa"]);
$host->set_storeid($ligne["cacheid"]);
$host->set_cache_peer_id($cache_peer_id);
$host->build_proxy();
}
function ToSyslog($text){
$LOG_SEV=LOG_INFO;
if(function_exists("openlog")){openlog(basename(__FILE__), LOG_PID , LOG_SYSLOG);}
if(function_exists("syslog")){ syslog($LOG_SEV, $text);}
if(function_exists("closelog")){closelog();}
}
function rotate(){
$unix=new unix();