-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_lib.php
1423 lines (1105 loc) · 52.7 KB
/
install_lib.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
$ehcpversion="0.30.8";
# last modified by bvidinli on 13.11.2010 (d-m-y)
# include_once("config/dbutil.php"); # dbutil is being removed from project.
/*
notes to who want to change code, developers:
although this library uses functions and global variables,
this library is called by two different install routines, install_1.php and install_2.php
so, even global variables are not passed to install_2.php normal way.
you should put any variables that you want to pass to install_2.php in passvariablestoinstall2 function..
*/
include_once("config/adodb/adodb.inc.php");
include_once("classapp.php");
require_once('console.php');
error_reporting (E_ALL ^ E_NOTICE);
$header="From: [email protected]";
if(!function_exists("debugecho")){
function debugecho($str,$level=0) {
$currentlevel=4;
if($level>=$currentlevel) echo $str;
}
}
if(!function_exists("securefilename")){
function securefilename($fn){
$ret=trim($fn);
$ret=str_replace(array('..','%','&'),array('','',''),$fn);
#$ret=escapeshellarg($ret);
return $ret;
}
}
function installaptget(){
echo "now will try to install apt-get on your system. you need internet connection for this....\n";
echo "apt-get installation is not implemented yet \n\n";
}
function checkaptget(){
$cikti=system("which apt-get | wc -w");
if($cikti>0) {
echo "apt-get seems to be installed on your system.\n";
} else {
echo "apt-get is not installed.. \n";
installaptget();
}
}
function log_to_file($str){
writeoutput("install_log.txt",$str."\n",'a',false);
}
function aptget($arr){
/* this was like:
apt-get install build-essential dpkg-dev fakeroot debhelper libdb4.2-dev libgdbm-dev libldap2-dev libpcre3-dev libmysqlclient10-dev libssl-dev libsasl2-dev postgresql-dev po-debconf dpatch
but, when one package is not found, whole apt-get install was cancelling.
to avoid this, each is installed separately.
tr: herbirisi teker teker kuruluyor. yoksa hata verme ihtimali var.
iki tip kurulum uygulanabilir, biri hizli, tum apt ler tek seferde, digeri yavas, tek tek... ilk basta sorabilir..
* */
global $noapt;
if($noapt<>''){
echo "apt-get install of these skipped because of noapt parameter:";
print_r($arr);
return true;
}
foreach($arr as $prog) {
#
# first install try
# assumes yes, do not remove anything, allow any unauthenticated packages,
# do not remove: this is a security concern
$cmd="apt-get -y --no-remove --allow-unauthenticated install $prog";
log_to_file($cmd);
cizgi();
echo "Starting apt-get install for: $prog\n(cmd: $cmd)\n\n";
passthru($cmd,$ret);
writeoutput("ehcp-apt-get-install.log",$cmd,"a",false);
if($ret==0) continue;
# second install try, if first fails :
# usefull if first one has failed, for reason such as a package has to be removed, if first apt-get exited for any reason, this one executes apt-get with not options, so that user can decide...
# if first is successfull, this actually does nothing... only prints that those packages are already installed...
# this way a bit slower, calls apt-get twice, but most "secure and avoids user intervention"
$cmd="apt-get install $prog";
echo "\nTrying second installation type for: $prog (cmd: $cmd)\n";
passthru($cmd);
writeoutput("ehcp-apt-get-install.log",$cmd,"a",false);
}
}//endfunc
function bosluk() {
echo "\n\n\n";
}
function cizgi() {
echo "\n---------------------------------------------------------------------\n";
}
function bosluk2() {
bosluk();
cizgi();
}
function ehcpheader() {
global $ehcpversion;
cizgi();
echo "-----------------------EHCP MAIN INSTALLER---------------------------\n";
echo "------Easy Hosting Control Panel for Ubuntu, Debian and alikes ------\n";
echo "--------------------------www.ehcp.net-------------------------------\n";
cizgi();
echo "ehcp version $ehcpversion \n";
echo "ehcp installer version $ehcpversion\n";
}
function bekle($s='') { # wait
getInput("press enter to continue: $s\n");
}
function getInput($prompt='') {
if($prompt<>'') echo $prompt;
return $giris=trim(Console::GetLine());
}
if(!function_exists("arraytofile")){
function arraytofile($file,$lines) {
$new_content = join('',$lines);
$fp = fopen($file,'w');
$write = fwrite($fp, $new_content);
fclose($fp);
}
}
if(!function_exists("addifnotexists")){
function addifnotexists($what,$where) {
debugecho("\naddifnotexists: ($what) -> ($where) \n ",4);
#bekle(__FUNCTION__." basliyor..");
$what.="\n";
$filearr=@file($where);
if(!$filearr) {
echo "cannot open file, trying to setup: ($where)\n";
$fp = fopen($where,'w');
fclose($fp);
$filearr=file($where);
} //else print_r($file);
if(array_search($what,$filearr)===false) {
echo "dosyada bulamadı ekliyor: $where -> $what \n";
$filearr[]=$what;
arraytofile($where,$filearr);
} else {
//echo "buldu... sorun yok. \n";
// already found, so, do not add
}
#bekle(__FUNCTION__." bitti...");
}
}
function add_if_not_exists2($what,$where,$addfile_if_not_exists=False) {
# add a string/config value onto (at the end of) a file...
# difference from addifnotexists: it uses arrays, this will use string, so, main.cf and similar config files will be handled better.. i hope..
# the $what should include newline too..
# may raise error if file too big for php strings..
# get file
$file=@file_get_contents($where);
if($file===false) {
if($addfile_if_not_exists) file_put_contents($where,'');
else {
echo __FUNCTION__.": cannot open file...($where ) \n";
return false;
}
}
# add if not exist:
$bul=strstr($file,$what);
if($bul===false) $file.=$what;
#write back
$ret=file_put_contents($where,$file);
if($ret===false){
echo __FUNCTION__.": cannot write file back: ($where) \n";
return false;
}
echo __FUNCTION__.": success add strings to $where \n";
return true;
}
function replace_in_file($find,$replace,$sourcefile,$targetfile){
# open source/sample file, find $find, replace it to $replace, write result to $target file
# especially for editing config files, like replacing {ehcppassword} to real passwords..
# get file
$file=file_get_contents($sourcefile);
if($file===false) {
echo __FUNCTION__.": cannot open file...($sourcefile ) \n";
return false;
}
# $find->$replace
$file=str_replace($find,$replace,$file);
#write back
$ret=file_put_contents($targetfile,$file);
if($ret===false){
echo __FUNCTION__.": cannot write file back: ($targetfile) \n";
return false;
}
echo __FUNCTION__.": success replace $find in $sourcefile -> $targetfile \n";
return true;
}
if(!function_exists('replacelineinfile')){
function replacelineinfile($find,$replace,$where) {
// edit a line starting with $find, to edit especially conf files..
debugecho("\nreplaceline: ($find -> $replace) in ($where) \n ");
$filearr=@file($where);
//if($find=='$dbrootpass=') print_r($filearr);
if(!$filearr) {
echo "cannot open file... returning...\n";
return false;
} //else print_r($file);
$len=strlen($find);
$newfile=array();
foreach($filearr as $line){
$line=trim($line)."\n";
$sub=substr($line,0,$len);
if($sub==$find) $line=$replace."\n";
$newfile[]=$line;
}
/*if($find=='$dbrootpass=') {
echo "yeni dosya:\n";
print_r($newfile);
}*/
arraytofile($where,$newfile);
}
}
if(!function_exists("editlineinfile")){
function editlineinfile($find,$replace,$where) {
// edit a line containing $find, replace it... to edit especially /etc/apt/sour/sources.list file
debugecho("\n replaceline: ($find -> $replace) in ($where) \n ");
$filearr=@file($where);
if(!$filearr) {
echo "cannot open file... returning...\n";
return false;
} //else print_r($file);
$newfile=array();
foreach($filearr as $line){
$line=trim($line)."\n";
$line=str_replace($find,$replace,$line);
$newfile[]=$line;
}
arraytofile($where,$newfile);
}
}
if(!function_exists("writeoutput")){
function writeoutput($file, $string, $mode="w",$log=true) {
if (!($fp = fopen($file, $mode))) {
echo "hata: dosya acilamadi: $file (writeoutput) !";
return false;
}
if (!fputs($fp, $string . "\n")) {
fclose($fp);
echo "hata: dosyaya yazilamadi: $file (writeoutput) !";
return false;
}
fclose($fp);
if($log) echo "\n(".__FILE__.") file written successfully: $file, mode:$mode \n";
return true;
}
}
if(!function_exists('getlocalip')){
function getlocalip($interface='eth0') {
global $localip;
//$interface="eth0";
$ipline=exec("ifconfig $interface | grep \"inet addr\"");
// echo $ipline."\n\n";
$ipline=strstr($ipline,"addr:");
// echo $ipline."\n\n";
$pos=strpos($ipline," ");
$ipline=trim(substr($ipline,5,$pos-5));
// echo "($ipline)\n\n";
$localip=$ipline;
# echo "(getlocalip) your ip is determined to be ($localip) using interface $interface \n";
return $ipline;
}
}
function getlocalip2($interface='eth0') {
global $localip;
if($localip<>'') return $localip;
$ip=getlocalip($interface);
if($ip=='') $ip=getlocalip('eth1');
if($ip=='') $ip=getlocalip('eth2');
if($ip=='') {
$ipline=exec("ifconfig | grep 'inet ' | grep 'dres' | grep 255.255 | grep -v '127.0.0'");
$ipline=strstr($ipline,"addr:");
$pos=strpos($ipline," ");
$ip=trim(substr($ipline,5,$pos-5));
if($ip=='') echo "Your ip cannot be determined automatically... \n";
}
$localip=$ip;
return $ip;
}
function dovecot_install_configuration($params){
# use quide: http://workaround.org/articles/ispmail-etch/
# remove all courier
# install dovecot using apt-get
# configure dovecot using mysql auth....
}
function mailconfiguration($params) {
global $app,$ehcpinstalldir,$ip,$hostname,$user_email,$user_name,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass;
echo "configuring mail ... ".__FUNCTION__."\n";
# very similar to: https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto
#print_r($params);
# echo 'var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass);\n';
# var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass);
/*
courier'e alternatif: dovecot:
*
http://www.opensourcehowto.org/how-to/mysql/mysql-users-postfixadmin-postfix-dovecot--squirrelmail-with-userprefs-stored-in-mysql.html
http://www.howtoforge.com/virtual-users-and-domains-postfix-dovecot-mysql-centos4.5
http://workaround.org/articles/ispmail-etch/
Gerekli arama: /etc/dovecot-mysql.conf
files to edit:
/etc/postfix/mysql-virtual_domains.cf
/etc/postfix/mysql-virtual_forwardings.cf
/etc/postfix/mysql-virtual_mailboxes.cf
/etc/postfix/mysql-virtual_email2email.cf
/etc/postfix/mysql-virtual_mailbox_limit_maps.cf
/etc/postfix/mysql-virtual_transports.cf
maybe we can switch to dovecot, if i can, a good start: http://workaround.org/ispmail/etch
*/
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = domains
select_field = 'virtual'
where_field = domainname
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_domains.cf",$filecontent,"w");
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = forwardings
select_field = destination
where_field = source
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_forwardings.cf",$filecontent,"w");
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = emailusers
select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
where_field = email
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_mailboxes.cf",$filecontent,"w");
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = emailusers
select_field = email
where_field = email
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_email2email.cf",$filecontent,"w");
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = emailusers
select_field = quota
where_field = email
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_mailbox_limit_maps.cf",$filecontent,"w");
# autoreply configuration: coded like: http://www.progression-asia.com/node/87
/*
I used ehcp's own php application, autoreply.php, instead of yaa.pl, since yaa.pl failed somehow, I wrote autoreply simply..
required db tables:(these will be setup in sql section)
CREATE TABLE transport (
domainname varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domainname (domainname)
) TYPE=MyISAM;
*/
$filecontent="
user = ehcp
password = ".$params['ehcppass']."
dbname = ehcp
table = transport
select_field = transport
where_field = domainname
hosts = localhost
";
writeoutput("/etc/postfix/mysql-virtual_transports.cf",$filecontent,"w");
# edit main.cf:
$add="
# ehcp: autoresponder code:
ehcp_autoreply unix - n n - - pipe
user=vmail
argv=".$app->ehcpdir."/misc/autoreply.php \$sender \$recipient
";
add_if_not_exists2($add,'/etc/postfix/master.cf'); # this function may also be used to setup spamassassin and related stuff. soon to implement spamassassin support in ehcp automatically. (manually always possible..)
# classapp'da checktable yapılacak yenile..
# end autoreply configuration
if(!file_exists('/etc/postfix/main.cf')) passthru2("cp ".$app->ehcpdir."/etc/postfix/main.cf.sample /etc/postfix/main.cf"); # on some systems, this is deleted somehow.
addifnotexists("bind-address=127.0.0.1","/etc/mysql/my.cnf");
addifnotexists("skip-innodb","/etc/mysql/my.cnf"); # disable innodb by default, because it consumes a lot of memory
passthru3("chmod o= /etc/postfix/mysql-virtual_*.cf");
passthru3("chgrp postfix /etc/postfix/mysql-virtual_*.cf");
#Now we setup a user and group called vmail with the home directory /home/vmail. This is where all mail boxes will be stored.
passthru3("groupdel vmail");
passthru3("userdel vmail");
echo "----------- Other user/group with uid/gid of 5000, you need to delete them, if any -----------";
passthru3("grep 5000 /etc/passwd ");
passthru3("grep 5000 /etc/group ");
echo "----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------";
passthru3("groupadd -g 5000 vmail");
passthru3("useradd -g vmail -u 5000 vmail -d /home/vmail -m");
passthru3("chown -Rf vmail /home/vmail");
passthru3("adduser postfix sasl");
// burda input vardi... initialize a aktarildi..
$hostname=exec("hostname");
// ipnin ilk uc rakami alinip network alınacak
$ips=explode(".",$ip);
array_pop($ips);
$ips[]="0/24"; // calculate C class net number.
$net=implode(".",$ips);
passthru3("openssl req -new -config $ehcpinstalldir/LocalServer.cnf -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 365 -x509");
passthru3("chmod o= /etc/postfix/smtpd.key");
passthru3("openssl req -passout pass:$ehcpmysqlpass -new -x509 -keyout /etc/postfix/cakey.pem -out /etc/postfix/cacert.pem -days 3650 -config $ehcpinstalldir/LocalServer.cnf"); ## yeni 13.6.2009
passthru3("postconf -e \"myhostname = $hostname\"");
passthru3("postconf -e \"relayhost = \"");
passthru3("postconf -e \"mydestination = localhost, $ip \"");
passthru3("postconf -e 'mynetworks = 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/16, 10.0.0.0/8, $net '");
passthru3("postconf -e 'virtual_alias_domains ='");
passthru3("postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, proxy:mysql:/etc/postfix/mysql-virtual_email2email.cf'");
passthru3("postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'"); #autoresponder
passthru3("postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'");
passthru3("postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'");
passthru3("postconf -e 'virtual_mailbox_base = /home/vmail'");
passthru3("postconf -e 'virtual_uid_maps = static:5000'");
passthru3("postconf -e 'virtual_gid_maps = static:5000'");
passthru3("postconf -e 'smtpd_sasl_auth_enable = yes'");
passthru3("postconf -e 'smtpd_sasl_security_options = noanonymous'");
passthru3("postconf -e 'broken_sasl_auth_clients = yes'");
passthru3("postconf -e 'smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,check_client_access hash:/var/lib/pop-before-smtp/hosts,reject_unauth_destination'"); // this is used with pop-before-smtp
#passthru3("postconf -e 'smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination'"); // this is used with sasl authenticated
passthru3("postconf -e 'smtp_use_tls = yes'"); ## yeni
passthru3("postconf -e 'smtpd_use_tls = yes'");
passthru3("postconf -e 'smtpd_tls_auth_only = no'"); ## yeni
passthru3("postconf -e 'smtpd_tls_CAfile = /etc/postfix/cacert.pem'"); ## yeni 13.6, dd.mm
passthru3("postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'");
passthru3("postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'");
# this is partially taken from https://help.ubuntu.com/8.04/serverguide/C/postfix.html
passthru3("postconf -e 'smtpd_tls_loglevel = 1'"); ## yeni 13.6, dd.mm
passthru3("postconf -e 'smtpd_tls_received_header = yes'"); ## yeni 13.6, dd.mm
passthru3("postconf -e 'smtpd_tls_session_cache_timeout = 3600s'"); ## yeni 13.6, dd.mm
passthru3("postconf -e 'tls_random_source = dev:/dev/urandom'"); ## yeni 13.6, dd.mm
passthru3("postconf -e 'virtual_create_maildirsize = yes'");
passthru3("postconf -e 'virtual_mailbox_extended = yes'");
passthru3("postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'");
passthru3("postconf -e 'virtual_mailbox_limit_override = yes'");
passthru3("postconf -e 'virtual_maildir_limit_message = \"The user you are trying to reach is over quota.\"'");
passthru3("postconf -e 'virtual_overquota_bounce = yes'");
passthru3("postconf -e 'debug_peer_list = '");
passthru3("postconf -e 'sender_canonical_maps = '");
passthru3("postconf -e 'debug_peer_level = 1'");
passthru3("postconf -e 'virtual_overquota_bounce = yes'");
passthru3("postconf -e 'proxy_read_maps = \$local_recipient_maps \$mydestination \$virtual_alias_maps \$virtual_alias_domains \$virtual_mailbox_maps \$virtual_mailbox_domains \$relay_recipient_maps \$canonical_maps \$sender_canonical_maps \$recipient_canonical_maps \$relocated_maps \$mynetworks \$virtual_mailbox_limit_maps \$transport_maps'");
passthru3("postconf -e 'smtpd_banner =\$myhostname ESMTP \$mail_name powered by Easy Hosting Control Panel (ehcp) on Ubuntu, www.ehcp.net'");
# passthru3("dpkg-statoverride --force --update --add root sasl 755 /var/run/saslauthd"); # may be required on some systems...
echo "configuring saslauthd \n";
passthru3("mkdir -p /var/spool/postfix/var/run/saslauthd");
# here, both params, options added, in case it may be changed.
$filecontent="
NAME=\"saslauthd\"
START=yes
MECHANISMS=\"pam\"
PARAMS=\"-m /var/spool/postfix/var/run/saslauthd -r\"
OPTIONS=\"-m /var/spool/postfix/var/run/saslauthd -r\"
";
writeoutput("/etc/default/saslauthd",$filecontent,"w");
replacelineinfile("PIDFILE=","PIDFILE=\"/var/spool/postfix/var/run/\${NAME}/saslauthd.pid\"",'/etc/init.d/saslauthd');
configurepamsmtp(array('ehcppass'=>$ehcpmysqlpass));
echo "editing: /etc/postfix/sasl/smtpd.conf\n";
$filecontent="
pwcheck_method: saslauthd
mech_list: plain login
allow_plaintext: true
";
writeoutput("/etc/postfix/sasl/smtpd.conf",$filecontent,"w");
echo "Configuring Courier\n";
echo "Now configuring to tell Courier that it should authenticate against our MySQL database.";
addifnotexists("authmodulelist=\"authmysql\"","/etc/courier/authdaemonrc");
//** tablo ismi degisirse, asagidaki emailusers da degismeli
configureauthmysql(array('ehcppass'=>$ehcpmysqlpass));
passthru("chown -Rvf postfix /var/lib/postfix/");
passthru("chmod -R 755 /var/spool/postfix");
passthru("chmod 1733 /var/spool/postfix/maildrop");
passthru2("newaliases"); # on some systems, aliases.db is deleted by user or somehow, this fixes that.
passthru("cp -vf pop-before-smtp.conf /etc/pop-before-smtp/");
# adjust roundcube:
# adjust symlink for roundcube
passthru2("ln -s /usr/share/roundcube /var/www/new/ehcp/webmail2");
replacelineinfile("\$rcmail_config['default_host']","\$rcmail_config['default_host']='localhost';",'/etc/roundcube/main.inc.php');
# end adjust roundcube
foreach(array('pop-before-smtp','postfix','saslauthd','courier-authdaemon','courier-imap','courier-imap-ssl','courier-pop','courier-pop-ssl') as $service)
passthru("/etc/init.d/$service restart");
passthru("postfix check");
}# end mailconfiguration
function configurepamsmtp($params){
echo "editing: /etc/pam.d/smtp (".__FUNCTION__.")\n";
$filecontent="
auth required pam_mysql.so user=ehcp passwd=".$params['ehcppass']." host=127.0.0.1 db=ehcp table=emailusers usercolumn=email passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=ehcp passwd=".$params['ehcppass']." host=127.0.0.1 db=ehcp table=emailusers usercolumn=email passwdcolumn=password crypt=1
";
writeoutput("/etc/pam.d/smtp",$filecontent,"w");
}
function configureauthmysql($params){
echo "(".__FUNCTION__.")\n";
$filecontent="
MYSQL_SERVER localhost
MYSQL_USERNAME ehcp
MYSQL_PASSWORD ".$params['ehcppass']."
MYSQL_PORT 0
MYSQL_DATABASE ehcp
MYSQL_USER_TABLE emailusers
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD 5000
MYSQL_GID_FIELD 5000
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD \"/home/vmail\"
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
#MYSQL_NAME_FIELD
MYSQL_QUOTA_FIELD quota
";
writeoutput("/etc/courier/authmysqlrc",$filecontent,"w");
}
function installmailserver(){
global $app,$ehcpinstalldir,$ip,$hostname,$user_email,$user_name,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass;
echo "starting mail server installation (postfix and related programs)\n\n";
aptget(array('mysql-server'));
passthru2("killall mysqld_safe"); # because, after first install of mysql, this process somehow uses %100 of cpu, in an endless loop.. kill this and restart mysql..
passthru2("killall mysqld");
sleep(10);
passthru2("/etc/init.d/mysql restart ");
# aptget(array('postfix','postfix-mysql','postfix-doc','mysql-client','courier-authdaemon','courier-authmysql','courier-authlib-mysql','courier-pop','courier-pop-ssl','courier-imap','courier-imap-ssl','libsasl2-2','libsasl2','libsasl2-modules','libsasl2-modules-sql','sasl2-bin','libpam-mysql','openssl','phpmyadmin','pop-before-smtp','roundcube','roundcube-mysql')); # changed libsasl2-2 to libsasl2 **
aptget(array('postfix','postfix-mysql','postfix-doc','mysql-client','libsasl2-2','libsasl2','libsasl2-modules','libsasl2-modules-sql','sasl2-bin','libpam-mysql','openssl','phpmyadmin')); # changed libsasl2-2 to libsasl2 **
passthru2("cp -rf /usr/share/phpmyadmin /var/www/new");
# aptitude install postfix postfix-mysql postfix-doc mysql-client courier-authdaemon courier-authmysql courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin pop-before-smtp
#remove: apt-get remove postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authmysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin
bosluk2();
# all mail configuration should be moved into this function: bvidinli, to be able to re-configure mail later
mailconfiguration(array('ehcppass'=>$ehcpmysqlpass));
echo "\n\nfinished mail server,pop3,imap installation \n";
}
function rebuild_nginx_config2($mydir){
global $app;
passthru3("rm -rvf /etc/nginx/sites-enabled/*");
#passthru2("cp $mydir/etc/nginx/nginx.conf /etc/nginx/nginx.conf");
$conf=file_get_contents("$mydir/etc/nginx/nginx.conf"); # replace tags with actual values from class
$conf=str_replace(array('{wwwuser}','{wwwgroup}'),array($app->wwwuser,$app->wwwgroup),$conf);
file_put_contents("/etc/nginx/nginx.conf",$conf);
passthru2("cp $mydir/etc/nginx/default.nginx /etc/nginx/sites-enabled/default");
passthru2("cp $mydir/etc/nginx/apachetemplate.nginx $mydir/apachetemplate");
passthru2("cp $mydir/etc/nginx/apache_subdomain_template.nginx $mydir/apache_subdomain_template");
passthru2("/etc/init.d/php5-fpm restart"); # this does not work on some systems.. needs another binary to work
}
function install_nginx_webserver(){
# thanks to [email protected] for encourage of nginx integration
echo "\nStarting nginx webserver install (not default)\n";
#bekle();
aptget(array('nginx','php5-fpm','php5-cgi')); # apt-get install nginx php5-fpm php5-cgi
copy("$mydir/etc/nginx/mime.types","/etc/nginx/mime.types");
rebuild_nginx_config2(".");
passthru2("/etc/init.d/php5-fpm stop");
passthru2("update-rc.d -f nginx remove"); # apache is default
passthru2("/etc/init.d/nginx stop");
echo "\nEnd nginx install\n";
#bekle();
}
function installapacheserver($apacheconf=''){
global $app,$ehcpinstalldir;
echo "\nStarting apache2 webserver install (default webserver)\n";
#bekle(__FUNCTION__." basliyor..");
aptget(array('libapache2-mod-php5','php5'));
addifnotexists("Include $ehcpinstalldir/apachehcp_subdomains.conf ", "/etc/apache2/apache2.conf");
addifnotexists("Include $ehcpinstalldir/apachehcp_auth.conf ", "/etc/apache2/apache2.conf");
addifnotexists("Include $ehcpinstalldir/apachehcp_passivedomains.conf ", "/etc/apache2/apache2.conf");
addifnotexists("Include $ehcpinstalldir/apachehcp.conf", "/etc/apache2/apache2.conf");
#replacelineinfile('NameVirtualHost','NameVirtualHost *','/etc/apache2/ports.conf');
#editlineinfile("Options Indexes","Options -Indexes","/etc/apache2/sites-enabled/000-default");
addifnotexists("ServerName myserver", "/etc/apache2/apache2.conf");
if(file_exists("/etc/apache2/envvars")) {
replacelineinfile("export APACHE_RUN_USER=","export APACHE_RUN_USER=".$app->wwwuser,"/etc/apache2/envvars");
replacelineinfile("export APACHE_RUN_GROUP=","export APACHE_RUN_GROUP=".$app->wwwgroup,"/etc/apache2/envvars");
} else {
replacelineinfile("User ","User ".$app->wwwuser,"/etc/apache2/apache2.conf");
replacelineinfile("User ","Group ".$app->wwwgroup,"/etc/apache2/apache2.conf");
}
#replacelineinfile('DocumentRoot /','DocumentRoot /var/www','/etc/apache2/sites-available/default');
$tarih=exec('date +%Y%m%d%H%M%S');
passthru2("cp -vf /etc/apache2/sites-available/default /etc/apache2/sites-available/default.original.$tarih"); # backup original apache default conf
passthru2("cp -vf $ehcpinstalldir/etc/apache2/default /etc/apache2/sites-available/default"); # write new conf with new settings that has -Indexes and so on... may be disabled, may be incompatible with future versions of apache2
passthru2("cp -vf $ehcpinstalldir/etc/apache2/default /etc/apache2/sites-available/000-default");
passthru2("cp -vf $ehcpinstalldir/etc/apache2/ports.conf /etc/apache2/");
#passthru2("ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load");
passthru2("a2enmod rewrite");
passthru2("a2enmod php5");
passthru2("a2enmod expires");
passthru2("a2enmod headers");
passthru2("cp -vf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled/");
passthru("cp ./wwwindex.html /var/www/apache2-default/index.html");
passthru("cp -rvf ./images_default_index /var/www/apache2-default/");
# default apache setting
passthru("cp ./wwwindex.html /var/www/index.html");
passthru("cp -rvf ./images_default_index /var/www/");
# new ehcp setting since ver 0.29.15 - added at 13.11.2010
passthru2("mkdir -p /var/www/new");
passthru("cp ./wwwindex.html /var/www/new/index.html");
passthru("cp -rvf ./images_default_index /var/www/new/");
passthru("cp ./ehcp /etc/init.d/");
passthru("cp ./ehcp_daemon.py /etc/init.d/");
passthru("chmod a+r /var/www/apache2-default/index.html");
passthru("chmod a+r /var/www/index.html");
bosluk2();
}
function install_pure_ftpserver() {
global $app;
#----------------------start ftp install --------------------------------------
# this works on ubuntu, but not on debian, so, disabled at the moment
echo "Now, going to install pureftpd to your server,";
aptget(array('pure-ftpd-mysql'));
passthru("groupadd -g 2001 ftpgroup");
passthru("useradd -u 2001 -s /bin/false -d /bin/null -c \"pureftpd user\" -g ftpgroup ftpuser");
passthru("cp -rvf pureftpd_mysql.conf /etc/pure-ftpd/db/mysql.conf");
passthru("echo yes > /etc/pure-ftpd/conf/ChrootEveryone");
passthru("echo yes > /etc/pure-ftpd/conf/CreateHomeDir");
bosluk();
echo "you should manually uninstall any other ftp server from your system... \n";
passthru("/etc/init.d/pure-ftpd-mysql start");
echo "finished pureftpd installation. your ftp server now should be ready.\n";
#bekle();
bosluk2();
#----------------------end ftp install --------------------------------------
}
function remove_pure_ftpserver(){
// to be coded later, if needed.
}
function vsftpd_configuration($params){
global $app,$ip; #$ehcpinstalldir,$ip,$user_email,$user_name,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass;
# this function is written to allow changing password later, after install... it also makes configuration while install...
echo "configuring vsftpd: (".__FUNCTION__.")\n";
# burda sorun su: mysql password( fonksiyonu, mysqlde internal kullaniliyormus, bu yuzden normal programlarda kullanilmamaliymis..
# denedim, iki farklki mysqlde farkli sonuc uretebiliyor. bu nedenle, gercekten kullanilmamali..
$filecontent="
auth required pam_mysql.so user=ehcp passwd=".$params['ehcppass']." host=localhost db=ehcp table=ftpaccounts usercolumn=ftpusername passwdcolumn=password crypt=2
account required pam_mysql.so user=ehcp passwd=".$params['ehcppass']." host=localhost db=ehcp table=ftpaccounts usercolumn=ftpusername passwdcolumn=password crypt=2
";
writeoutput("/etc/pam.d/vsftpd",$filecontent,"w");
$filecontent="
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
nopriv_user=vsftpd
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
guest_enable=YES
guest_username=".$app->ftpuser."
local_root=".$app->conf['vhosts']."/\$USER
user_sub_token=\$USER
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd_user_conf
local_max_rate=2000000 # bytes per sec, 2Mbytes per sec
max_clients=50 # to avoid DOS attack, if you have a huge server, increase this..
ftpd_banner=Welcome to vsFTPd Server, managed by EHCP (Easy Hosting Control Panel, www.ehcp.net )
";
writeoutput("/etc/vsftpd.conf",$filecontent,"w");
passthru2("usermod -g $app->ftpgroup $app->ftpuser");
passthru("/etc/init.d/vsftpd restart");
}
function install_vsftpd_server(){
global $app,$ehcpinstalldir,$ip,$user_email,$user_name,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass;
passthru("apt-get remove proftpd");
aptget(array('vsftpd'));
passthru("useradd --home ".$app->conf['vhosts']." --gid ".$app->ftpgroup." -m --shell /bin/false ".$app->ftpuser);
passthru("cp /etc/vsftpd.conf /etc/vsftpd.conf_orig");
vsftpd_configuration(array('ehcppass'=>$ehcpmysqlpass));
}
function buildconfigphp(){
# to be filled later..
}
function installsql() {
global $app,$ehcpinstalldir,$ip,$lang,$user_email,$user_name,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass;
bosluk2();
if($newrootpass<>'') $tmprootpass=$newrootpass;
else $tmprootpass=$rootpass;
echo "extracting and importing sql to mysql:\n";
# check if ehcp db already exists...
$baglanti=@mysql_connect("localhost", "root", $tmprootpass);
$ret=mysql_select_db("ehcp",$baglanti);
if($ret===true){
echo "seems to found old ehcp db..(will try to backup existing ehcp db with timestamp... )";
echo "\nATTENTION ! EHCP DB WILL BE DROPPED IF EXISTS, EXIT NOW (by ctrl-C) if you don't want !\n\n";
sleep(10);
# backup any existing ehcp db, if any
#$ehcpdb="ehcpbackup".date("YmdHis"); # disabled because gives error on some systems: Fatal error: date(): Timezone database is corrupt - this should *never* happen! in ...
$ehcpdb="ehcpbackup".exec('date +%Y%m%d%H%M%S');
passthru("cp -Rf /var/lib/mysql/ehcp /var/lib/mysql/$ehcpdb");
passthru("chown -Rf mysql:mysql /var/lib/mysql/$ehcpdb");
#--end backup ehcp db
}
# end check..
# echo 'var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass);\n';
# var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass);
# burasi replace ile olacagina, writeoutput ile yapilabilir:
replacelineinfile('$dbrootpass=',"\$dbrootpass='$tmprootpass';",$ehcpinstalldir."/config.php");
replacelineinfile('$dbpass=',"\$dbpass='$ehcpmysqlpass';",$ehcpinstalldir."/config.php");
if($lang<>'en') replacelineinfile('$defaultlanguage=',"\$defaultlanguage='$lang';",$ehcpinstalldir."/config.php");
$filecontent="
drop database if exists ehcp;
create database ehcp;
grant all privileges on ehcp.* to ehcp@'localhost' identified by '$ehcpmysqlpass' with grant option;
grant all privileges on ehcp.* to ehcp@'127.0.0.1' identified by '$ehcpmysqlpass' with grant option;
grant all privileges on ehcp.* to ehcp@'127.0.1.1' identified by '$ehcpmysqlpass' with grant option;
";
if($newrootpass<>''){ # if we need to change root pass... in versions prior to 0.29, mysql root pass could be changed from within ehcp install.
$filecontent.="SET PASSWORD FOR 'root'@'localhost'=PASSWORD('$newrootpass');";
}
writeoutput($ehcpinstalldir."/ehcp1.sql",$filecontent,"w");
echo "executing: mysql -u root --password=$rootpass < $ehcpinstalldir/ehcp1.sql \n ";
passthru("mysql -u root --password=$rootpass < $ehcpinstalldir/ehcp1.sql"); # root pass changes here... if different , disabled
echo "importing ehcp sql: \n";
passthru("mysql -u root --password=$tmprootpass < $ehcpinstalldir/ehcp.sql");
passthru("mysql -u root --password=$tmprootpass < $ehcpinstalldir/ehcp_html.sql");
passthru("cp $ehcpinstalldir/config.php ./config.php");
passthru("rm $ehcpinstalldir/ehcp1.sql"); # removed for security, root pass was there..
$app = new Application();
$app->connecttodb();
$app->set_ehcp_dir($ehcpinstalldir);
$app->setConfigValue("ehcpdir",$ehcpinstalldir);
$app->setConfigValue("dnsip",$ip); // this configures dns ip to be used by ehcp, may be changed if using another dns server
$app->setConfigValue('adminname',$user_name);
$app->setConfigValue('adminemail',$user_email); // set email to send info about ehcp install to installer(admin)...
$app->executequery("UPDATE panelusers SET password=MD5('$ehcpadminpass'),email='$user_email' WHERE panelusername='admin'");
$app->commandline=true;
}
function checkmysqlpass($user,$pass){
echo "mysql root pass being checked ...\n";
$baglanti=@mysql_connect("localhost", $user, $pass);
if(!$baglanti){
return false;
} else return true;
}
function getGoodPassword(){
# The sign '#' has special meaning in Linux, and some passwords are written to some files on Ubuntu, which is broken, when you use a # , so avoid using # , this function checks this...
# i put this control, because /etc/pam.d/vsftpd is broken if # is used in ehcp pass.
$found=true;
while($found!==false){
$pass=getInput("\nPlease pay attention that, you cannot use sign # in your password:");
$found=strpos($pass,'#');
}
return $pass;
}
function getVerifiedInput($inputname,$defaultvalue){
# ask an input two times, to reduce possibility of error for user input
$input1='';
$input2='-';
while($input1<>$input2){
$input1=getInput("Enter $inputname (default $defaultvalue):");
if($input1==''){
echo "$inputname set as ($defaultvalue) (default) \n";
$input1=$input2=$defaultvalue;
} else {
$input2=getInput("Enter $inputname AGAIN:");
if($input1<>$input2) echo "\n\nTwo inputs are NOT THE SAME ! , Please try again \n";
}
}
return $input1;
}
function getinputs(){
global $ehcpinstalldir,$app,$ip,$hostname,$lang,$user_email,$user_name,$yesno,$ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass,$installextrasoftware;
# all inputs should be here...
echo "\n\n==========================================================================\n\n";
echo "EHCP INSTALL - INPUTS/SETTINGS SECTION:\n
THIS SECTION IS VERY IMPORTANT FOR YOUR EHCP SECURITY AND PASSWORD SETTINGS.
PLEASE ANSWER ALL QUESTIONS CAREFULLY \n\n";
$user_name=getInput("Please enter your name:");
$user_email=getInput("Please enter your/admin email (used to send your panel info, ehcp news)- Enter an already working email:");
#$command="wget -q -O /dev/null --timeout=15 \"http://www.ehcp.net/diger/ehcpemailregister.php?user_email=$user_email\"";
$url="http://www.ehcp.net/diger/ehcpemailregister.php?user_email=$user_email";
#passthru($command);
file_get_contents($url);
$emptypass=checkmysqlpass('root','');
if($emptypass){
echo "\nYour mysql root pass is identified as empty. ";