1212from ee .core .mysql import EEMysql
1313from ee .core .addswap import EESwap
1414from ee .core .git import EEGit
15+ from ee .core .checkfqdn import check_fqdn
1516from pynginxconfig import NginxConfig
1617from ee .core .services import EEService
1718import random
@@ -44,6 +45,8 @@ class Meta:
4445 dict (help = 'Install admin tools stack' , action = 'store_true' )),
4546 (['--mail' ],
4647 dict (help = 'Install mail server stack' , action = 'store_true' )),
48+ (['--mailscanner' ],
49+ dict (help = 'Install mail scanner stack' , action = 'store_true' )),
4750 (['--nginx' ],
4851 dict (help = 'Install Nginx stack' , action = 'store_true' )),
4952 (['--php' ],
@@ -82,7 +85,8 @@ def pre_pref(self, apt_packages):
8285 EERepo .add (self , repo_url = EEVariables .ee_mysql_repo )
8386 Log .debug (self , 'Adding key for {0}'
8487 .format (EEVariables .ee_mysql_repo ))
85- EERepo .add_key (self , '1C4CBDCDCD2EFD2A' )
88+ EERepo .add_key (self , '1C4CBDCDCD2EFD2A' ,
89+ keyserver = "subkeys.pgp.net" )
8690 chars = '' .join (random .sample (string .ascii_letters , 8 ))
8791 Log .info (self , "Pre-seeding MySQL" )
8892 EEShellExec .cmd_exec (self , "echo \" percona-server-server-5.6 "
@@ -466,13 +470,26 @@ def post_pref(self, apt_packages, packages):
466470 "/dovecot.pem" )
467471
468472 # Custom Dovecot configuration by EasyEngine
469- data = dict ()
473+ data = dict (email = EEVariables . ee_email )
470474 Log .debug (self , "Writting configuration into file"
471475 "/etc/dovecot/conf.d/99-ee.conf " )
472476 ee_dovecot = open ('/etc/dovecot/conf.d/99-ee.conf' , 'w' )
473477 self .app .render ((data ), 'dovecot.mustache' , out = ee_dovecot )
474478 ee_dovecot .close ()
475479
480+ EEShellExec .cmd_exec (self , "sed -i \" s/\\ !include "
481+ "auth-system.conf.ext/#\\ !include "
482+ "auth-system.conf.ext/\" "
483+ "/etc/dovecot/conf.d/10-auth.conf" )
484+
485+ EEShellExec .cmd_exec (self , "sed -i \" s\' /etc/dovecot/"
486+ "dovecot.pem\' /etc/ssl/certs/dovecot.pem"
487+ "\' \" /etc/dovecot/conf.d/10-ssl.conf" )
488+ EEShellExec .cmd_exec (self , "sed -i \" s\' /etc/dovecot/"
489+ "private/dovecot.pem\' /etc/ssl/private"
490+ "/dovecot.pem\' \" /etc/dovecot/conf.d/"
491+ "10-ssl.conf" )
492+
476493 # Custom Postfix configuration needed with Dovecot
477494 # Changes in master.cf
478495 # TODO: Find alternative for sed in Python
@@ -514,14 +531,14 @@ def post_pref(self, apt_packages, packages):
514531 "= static:5000\" " )
515532 EEShellExec .cmd_exec (self , "postconf -e \" "
516533 " virtual_mailbox_domains = "
517- " mysql:/etc/postfix/mysql/virtual_"
518- " domains_maps.cf\" " )
534+ "mysql:/etc/postfix/mysql/virtual_"
535+ "domains_maps.cf\" " )
519536 EEShellExec .cmd_exec (self , "postconf -e \" virtual_mailbox_maps"
520537 " = mysql:/etc/postfix/mysql/virtual_"
521538 "mailbox_maps.cf\" " )
522539 EEShellExec .cmd_exec (self , "postconf -e \" virtual_alias_maps "
523540 "= mysql:/etc/postfix/mysql/virtual_"
524- " alias_maps.cf\" " )
541+ "alias_maps.cf\" " )
525542 EEShellExec .cmd_exec (self , "openssl req -new -x509 -days "
526543 " 3650 -nodes -subj /commonName="
527544 "{HOSTNAME}/emailAddress={EMAIL}"
@@ -534,7 +551,7 @@ def post_pref(self, apt_packages, packages):
534551 EEShellExec .cmd_exec (self , "postconf -e \" smtpd_tls_cert_file "
535552 "= /etc/ssl/certs/postfix.pem\" " )
536553 EEShellExec .cmd_exec (self , "postconf -e \" smtpd_tls_key_file "
537- " = /etc/ssl/private/postfix.pem\" " )
554+ "= /etc/ssl/private/postfix.pem\" " )
538555
539556 # Sieve configuration
540557 if not os .path .exists ('/var/lib/dovecot/sieve/' ):
@@ -561,7 +578,7 @@ def post_pref(self, apt_packages, packages):
561578 "default.sieve" )
562579 EEGit .add (self , ["/etc/postfix" , "/etc/dovecot" ],
563580 msg = "Installed mail server" )
564- EEService .reload_service (self , 'dovecot' )
581+ EEService .restart_service (self , 'dovecot' )
565582 EEService .reload_service (self , 'postfix' )
566583
567584 if set (EEVariables .ee_mailscanner ).issubset (set (apt_packages )):
@@ -575,6 +592,20 @@ def post_pref(self, apt_packages, packages):
575592 out = ee_amavis )
576593 ee_amavis .close ()
577594
595+ # Amavis ViMbadmin configuration
596+ if os .path .isfile ("/etc/postfix/mysql/virtual_alias_maps.cf" ):
597+ vm_host = os .popen ("grep hosts /etc/postfix/mysql/virtual_"
598+ "alias_maps.cf | awk \' { print $3 }\' |"
599+ " tr -d '\\ n'" ).read ()
600+ vm_pass = os .popen ("grep password /etc/postfix/mysql/"
601+ "virtual_alias_maps.cf | awk \' { print "
602+ "$3 }\' | tr -d '\\ n'" ).read ()
603+
604+ data = dict (host = vm_host , password = vm_pass )
605+ vm_config = open ('/etc/amavis/conf.d/50-user' , 'w' )
606+ self .app .render ((data ), '50-user.mustache' , out = vm_config )
607+ vm_config .close ()
608+
578609 # Amavis postfix configuration
579610 EEShellExec .cmd_exec (self , "postconf -e \" content_filter = "
580611 "smtp-amavis:[127.0.0.1]:10024\" " )
@@ -598,7 +629,7 @@ def post_pref(self, apt_packages, packages):
598629 Log .debug (self , "Restarting clamav-daemon service" )
599630 EEShellExec .cmd_exec (self , "service clamav-daemon restart" )
600631 EEGit .add (self , ["/etc/amavis" ], msg = "Adding Amvis into Git" )
601- EEService .reload_service (self , 'dovecot' )
632+ EEService .restart_service (self , 'dovecot' )
602633 EEService .reload_service (self , 'postfix' )
603634 EEService .reload_service (self , 'amavis' )
604635
@@ -776,7 +807,13 @@ def post_pref(self, apt_packages, packages):
776807 Log .debug (self , "Creating directory "
777808 "/etc/postfix/mysql/" )
778809 os .makedirs ('/etc/postfix/mysql/' )
779- data = dict (password = vm_passwd , host = EEVariables .ee_mysql )
810+
811+ if EEVariables .ee_mysql_host is "localhost" :
812+ data = dict (password = vm_passwd , host = "127.0.0.1" )
813+ else :
814+ data = dict (password = vm_passwd ,
815+ host = EEVariables .ee_mysql_host )
816+
780817 vm_config = open ('/etc/postfix/mysql/virtual_alias_maps.cf' ,
781818 'w' )
782819 self .app .render ((data ), 'virtual_alias_maps.mustache' ,
@@ -817,7 +854,7 @@ def post_pref(self, apt_packages, packages):
817854 self .app .render ((data ), '50-user.mustache' ,
818855 out = vm_config )
819856 vm_config .close ()
820- EEService .reload_service (self , 'dovecot' )
857+ EEService .restart_service (self , 'dovecot' )
821858 EEService .reload_service (self , 'nginx' )
822859 EEService .reload_service (self , 'php5-fpm' )
823860 self .msg = (self .msg + ["Configure ViMbAdmin:\t https://{0}:"
@@ -870,8 +907,8 @@ def post_pref(self, apt_packages, packages):
870907 EEShellExec .cmd_exec (self , "bash -c \" sed -i \\ \" s:\$config\["
871908 "\' plugins\' \] "
872909 "= array(:\$config\['plugins'\] = "
873- "array(\n \' sieverules\' ,:\\ \" /var/www "
874- "/roundcubemail/htdocs/config"
910+ "array(\\ n \' sieverules\' ,:\\ \" "
911+ "/var/www/ roundcubemail/htdocs/config"
875912 "/config.inc.php\" " )
876913 EEShellExec .cmd_exec (self , "echo \" \$config['sieverules_port']"
877914 "=4190;\" >> /var/www/roundcubemail"
@@ -929,7 +966,8 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
929966 (not self .app .pargs .php ) and (not self .app .pargs .mysql ) and
930967 (not self .app .pargs .postfix ) and (not self .app .pargs .wpcli ) and
931968 (not self .app .pargs .phpmyadmin ) and
932- (not self .app .pargs .adminer ) and (not self .app .pargs .utils )):
969+ (not self .app .pargs .adminer ) and (not self .app .pargs .utils ) and
970+ (not self .app .pargs .mailscanner )):
933971 self .app .pargs .web = True
934972
935973 if self .app .pargs .web :
@@ -956,6 +994,8 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
956994 self .app .pargs .postfix = True
957995
958996 if not EEAptGet .is_installed (self , 'dovecot-core' ):
997+ check_fqdn (self ,
998+ os .popen ("hostname -f | tr -d '\n '" ).read ())
959999 Log .debug (self , "Setting apt_packages variable for mail" )
9601000 apt_packages = apt_packages + EEVariables .ee_mail
9611001 packages = packages + [["https://github.com/opensolutions/"
@@ -971,8 +1011,11 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
9711011 "Roundcube" ]]
9721012
9731013 if EEVariables .ee_ram > 1024 :
974- apt_packages = (apt_packages +
975- EEVariables .ee_mailscanner )
1014+ self .app .pargs .mailscanner = True
1015+ else :
1016+ Log .info (self , "System RAM is less than 1GB\n Mail "
1017+ "scanner packages are not going to install"
1018+ " automatically" )
9761019 else :
9771020 Log .info (self , "Mail server is already installed" )
9781021
@@ -1031,6 +1074,9 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
10311074 "htdocs/db/adminer/index.php" ,
10321075 "Adminer" ]]
10331076
1077+ if self .app .pargs .mailscanner :
1078+ apt_packages = (apt_packages + EEVariables .ee_mailscanner )
1079+
10341080 if self .app .pargs .utils :
10351081 Log .debug (self , "Setting packages variable for utils" )
10361082 packages = packages + [["http://phpmemcacheadmin.googlecode"
@@ -1130,6 +1176,9 @@ def remove(self):
11301176 EEMysql .execute (self , "drop database IF EXISTS vimbadmin" )
11311177 EEMysql .execute (self , "drop database IF EXISTS roundcubemail" )
11321178
1179+ if self .app .pargs .mailscanner :
1180+ apt_packages = (apt_packages + EEVariables .ee_mailscanner )
1181+
11331182 if self .app .pargs .nginx :
11341183 Log .debug (self , "Removing apt_packages variable of Nginx" )
11351184 apt_packages = apt_packages + EEVariables .ee_nginx
@@ -1206,6 +1255,9 @@ def purge(self):
12061255 EEMysql .execute (self , "drop database IF EXISTS vimbadmin" )
12071256 EEMysql .execute (self , "drop database IF EXISTS roundcubemail" )
12081257
1258+ if self .app .pargs .mailscanner :
1259+ apt_packages = (apt_packages + EEVariables .ee_mailscanner )
1260+
12091261 if self .app .pargs .nginx :
12101262 Log .debug (self , "Purge apt_packages variable of Nginx" )
12111263 apt_packages = apt_packages + EEVariables .ee_nginx
0 commit comments