Skip to content

Commit b442016

Browse files
author
gau1991
committed
FQDN check for mail
1 parent d8a8b1b commit b442016

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

ee/cli/plugins/stack.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ee.core.mysql import EEMysql
1313
from ee.core.addswap import EESwap
1414
from ee.core.git import EEGit
15+
from ee.core.checkfqdn import check_fqdn
1516
from pynginxconfig import NginxConfig
1617
from ee.core.services import EEService
1718
import 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'],
@@ -588,6 +591,20 @@ def post_pref(self, apt_packages, packages):
588591
out=ee_amavis)
589592
ee_amavis.close()
590593

594+
# Amavis ViMbadmin configuration
595+
if os.path.isfile("/etc/postfix/mysql/virtual_alias_maps.cf"):
596+
vm_host = os.popen("grep hosts /etc/postfix/mysql/virtual_"
597+
"alias_maps.cf | awk \'{ print $3 }\' |"
598+
" tr -d '\\n'").read()
599+
vm_pass = os.popen("grep password /etc/postfix/mysql/"
600+
"virtual_alias_maps.cf | awk \'{ print "
601+
"$3 }\' | tr -d '\\n'").read()
602+
603+
data = dict(host=vm_host, password=vm_pass)
604+
vm_config = open('/etc/amavis/conf.d/50-user', 'w')
605+
self.app.render((data), '50-user.mustache', out=vm_config)
606+
vm_config.close()
607+
591608
# Amavis postfix configuration
592609
EEShellExec.cmd_exec(self, "postconf -e \"content_filter = "
593610
"smtp-amavis:[127.0.0.1]:10024\"")
@@ -948,7 +965,8 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
948965
(not self.app.pargs.php) and (not self.app.pargs.mysql) and
949966
(not self.app.pargs.postfix) and (not self.app.pargs.wpcli) and
950967
(not self.app.pargs.phpmyadmin) and
951-
(not self.app.pargs.adminer) and (not self.app.pargs.utils)):
968+
(not self.app.pargs.adminer) and (not self.app.pargs.utils) and
969+
(not self.app.pargs.mailscanner)):
952970
self.app.pargs.web = True
953971

954972
if self.app.pargs.web:
@@ -975,6 +993,8 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
975993
self.app.pargs.postfix = True
976994

977995
if not EEAptGet.is_installed(self, 'dovecot-core'):
996+
check_fqdn(self,
997+
os.popen("hostname -f | tr -d '\n'").read())
978998
Log.debug(self, "Setting apt_packages variable for mail")
979999
apt_packages = apt_packages + EEVariables.ee_mail
9801000
packages = packages + [["https://github.com/opensolutions/"
@@ -990,8 +1010,11 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
9901010
"Roundcube"]]
9911011

9921012
if EEVariables.ee_ram > 1024:
993-
apt_packages = (apt_packages +
994-
EEVariables.ee_mailscanner)
1013+
self.app.pargs.mailscanner = True
1014+
else:
1015+
Log.info(self, "System RAM is less than 1GB\nMail "
1016+
"scanner packages are not going to install"
1017+
" automatically")
9951018
else:
9961019
Log.info(self, "Mail server is already installed")
9971020

@@ -1050,6 +1073,9 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
10501073
"htdocs/db/adminer/index.php",
10511074
"Adminer"]]
10521075

1076+
if self.app.pargs.mailscanner:
1077+
apt_packages = (apt_packages + EEVariables.ee_mailscanner)
1078+
10531079
if self.app.pargs.utils:
10541080
Log.debug(self, "Setting packages variable for utils")
10551081
packages = packages + [["http://phpmemcacheadmin.googlecode"
@@ -1149,6 +1175,9 @@ def remove(self):
11491175
EEMysql.execute(self, "drop database IF EXISTS vimbadmin")
11501176
EEMysql.execute(self, "drop database IF EXISTS roundcubemail")
11511177

1178+
if self.app.pargs.mailscanner:
1179+
apt_packages = (apt_packages + EEVariables.ee_mailscanner)
1180+
11521181
if self.app.pargs.nginx:
11531182
Log.debug(self, "Removing apt_packages variable of Nginx")
11541183
apt_packages = apt_packages + EEVariables.ee_nginx
@@ -1225,6 +1254,9 @@ def purge(self):
12251254
EEMysql.execute(self, "drop database IF EXISTS vimbadmin")
12261255
EEMysql.execute(self, "drop database IF EXISTS roundcubemail")
12271256

1257+
if self.app.pargs.mailscanner:
1258+
apt_packages = (apt_packages + EEVariables.ee_mailscanner)
1259+
12281260
if self.app.pargs.nginx:
12291261
Log.debug(self, "Purge apt_packages variable of Nginx")
12301262
apt_packages = apt_packages + EEVariables.ee_nginx

ee/cli/templates/50-user.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $final_spam_destiny = D_PASS;
88

99
# We need to provide list of domains for which filtering need to be done
1010
@lookup_sql_dsn = (
11-
['DBI:mysql:database=vimbadmin;host=127.0.0.1;port=3306',
11+
['DBI:mysql:database=vimbadmin;host={{host}};port=3306',
1212
'vimbadmin',
1313
'{{password}}']);
1414

ee/core/checkfqdn.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from ee.core.shellexec import EEShellExec
2+
from ee.core.variables import EEVariables
3+
import os
4+
5+
6+
def check_fqdn(self, ee_host):
7+
#ee_host=os.popen("hostname -f | tr -d '\n'").read()
8+
if '.' in ee_host:
9+
EEVariables.ee_fqdn = ee_host
10+
with open('/etc/hostname', 'w') as hostfile:
11+
hostfile.write(ee_host)
12+
13+
EEShellExec.cmd_exec(self, "sed -i \"1i\\127.0.0.1 {0}\" /etc/hosts"
14+
.format(ee_host))
15+
if EEVariables.ee_platform_distro == 'debian':
16+
EEShellExec.cmd_exec(self, "/etc/init.d/hostname.sh start")
17+
else:
18+
EEShellExec.cmd_exec(self, "service hostname restart")
19+
20+
else:
21+
ee_host = input("Enter hostname [fqdn]:")
22+
check_fqdn(self, ee_host)

0 commit comments

Comments
 (0)