diff --git a/CPScripts/mailscannerinstaller.sh b/CPScripts/mailscannerinstaller.sh index da9a2490d..4a4f4e26e 100644 --- a/CPScripts/mailscannerinstaller.sh +++ b/CPScripts/mailscannerinstaller.sh @@ -2,22 +2,21 @@ #systemctl stop firewalld check_return() { -#check previous command result , 0 = ok , non-0 = something wrong. -if [[ $? -eq "0" ]] ; then - : -else - echo -e "\ncommand failed, exiting..." - exit -fi + #check previous command result , 0 = ok , non-0 = something wrong. + if [[ $? -eq "0" ]]; then + : + else + echo -e "\ncommand failed, exiting..." + exit + fi } -echo 'backup configs'; -cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); -cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); -cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S'); +echo 'backup configs' +cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S') +cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S') +cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S') cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext-bak_$(date '+%Y-%m-%d_%H_%M:%S') - ZONE=$(firewall-cmd --get-default-zone) firewall-cmd --zone=$ZONE --add-port=4190/tcp --permanent systemctl stop firewalld @@ -27,167 +26,158 @@ csf -x MAILSCANNER=/etc/MailScanner -if [ -d $MAILSCANNER ];then - -echo "MailScanner found. If you wish to reinstall then remove the package and revert" -echo "Postfix back to its original config at /etc/postfix/main.cf and remove" -echo "/etc/MailScanner and /usr/share/MailScanner directories" -exit +if [ -d $MAILSCANNER ]; then + echo "MailScanner found. If you wish to reinstall then remove the package and revert" + echo "Postfix back to its original config at /etc/postfix/main.cf and remove" + echo "/etc/MailScanner and /usr/share/MailScanner directories" + exit fi -if [ -f /etc/os-release ];then -OS=$(head -1 /etc/os-release) -UBUNTUVERSION=$(sed '6q;d' /etc/os-release) -CENTOSVERSION=$(sed '5q;d' /etc/os-release) -CLNVERSION=$(sed '3q;d' /etc/os-release) +if [ -f /etc/os-release ]; then + OS=$(head -1 /etc/os-release) + UBUNTUVERSION=$(sed '6q;d' /etc/os-release) + CENTOSVERSION=$(sed '5q;d' /etc/os-release) + CLNVERSION=$(sed '3q;d' /etc/os-release) fi -if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then +if [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then -setenforce 0 -yum install -y perl yum-utils perl-CPAN -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" + setenforce 0 + yum install -y perl yum-utils perl-CPAN + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" -rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Net::Patricia' + rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Net::Patricia' -freshclam -v -DIR=/etc/mail/spamassassin + freshclam -v + DIR=/etc/mail/spamassassin -if [ -d "$DIR" ]; then -sa-update + if [ -d "$DIR" ]; then + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi -else +elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then -echo "Please install spamassassin through the CyberPanel interface before proceeding" + setenforce 0 + yum install -y perl yum-utils perl-CPAN + dnf --enablerepo=powertools install -y perl-IO-stringy + dnf --enablerepo=PowerTools install -y perl-IO-stringy + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav clamav-update "perl(DBD::mysql)" -exit -fi + rpm -Uvh https://forensics.cert.org/centos/cert/8/x86_64/unrar-5.4.0-1.el8.x86_64.rpm -elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus -setenforce 0 -yum install -y perl yum-utils perl-CPAN -dnf --enablerepo=powertools install -y perl-IO-stringy -dnf --enablerepo=PowerTools install -y perl-IO-stringy -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav clamav-update "perl(DBD::mysql)" + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Sys::Hostname::Long' + perl -MCPAN -e 'install Sys::SigAction' -rpm -Uvh https://forensics.cert.org/centos/cert/8/x86_64/unrar-5.4.0-1.el8.x86_64.rpm + freshclam -v -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus + DIR=/etc/mail/spamassassin -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Sys::Hostname::Long' -perl -MCPAN -e 'install Sys::SigAction' + if [ -d "$DIR" ]; then + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi +elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then + setenforce 0 + yum install -y perl yum-utils perl-CPAN + yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" -freshclam -v + rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm + export PERL_MM_USE_DEFAULT=1 + curl -L https://cpanmin.us | perl - App::cpanminus + perl -MCPAN -e 'install Encoding::FixLatin' + perl -MCPAN -e 'install Digest::SHA1' + perl -MCPAN -e 'install Geo::IP' + perl -MCPAN -e 'install Razor2::Client::Agent' + perl -MCPAN -e 'install Net::Patricia' -DIR=/etc/mail/spamassassin + freshclam -v + DIR=/etc/mail/spamassassin -if [ -d "$DIR" ]; then -sa-update + if [ -d "$DIR" ]; then + sa-update -else + else -echo "Please install spamassassin through the CyberPanel interface before proceeding" + echo "Please install spamassassin through the CyberPanel interface before proceeding" -exit -fi + exit + fi -elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then +elif [ "$OS" = "NAME=\"Ubuntu\"" ]; then -setenforce 0 -yum install -y perl yum-utils perl-CPAN -yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)" + apt-get install -y libmysqlclient-dev -rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm -export PERL_MM_USE_DEFAULT=1 -curl -L https://cpanmin.us | perl - App::cpanminus -perl -MCPAN -e 'install Encoding::FixLatin' -perl -MCPAN -e 'install Digest::SHA1' -perl -MCPAN -e 'install Geo::IP' -perl -MCPAN -e 'install Razor2::Client::Agent' -perl -MCPAN -e 'install Net::Patricia' + apt-get install -y cpanminus gcc perl bzip2 zip make patch automake rpm libarchive-zip-perl libfilesys-df-perl libole-storage-lite-perl libsys-hostname-long-perl libsys-sigaction-perl libregexp-common-net-cidr-perl libmime-tools-perl libdbd-sqlite3-perl binutils build-essential libfilesys-df-perl zlib1g unzip mlocate clamav libdbd-mysql-perl unrar libclamav-dev libclamav-client-perl libclamunrar9 -freshclam -v -DIR=/etc/mail/spamassassin + cpanm Encoding::FixLatin + cpanm Digest::SHA1 + cpanm Geo::IP + cpanm Razor2::Client::Agent + cpanm Net::Patricia + cpanm Net::CIDR -if [ -d "$DIR" ]; then -sa-update + sudo systemctl stop clamav-freshclam.service -else + freshclam -echo "Please install spamassassin through the CyberPanel interface before proceeding" + sudo systemctl start clamav-freshclam.service -exit -fi + DIR=/etc/spamassassin + if [ -d "$DIR" ]; then -elif [ "$OS" = "NAME=\"Ubuntu\"" ];then - - apt-get install -y libmysqlclient-dev - - apt-get install -y cpanminus gcc perl bzip2 zip make patch automake rpm libarchive-zip-perl libfilesys-df-perl libole-storage-lite-perl libsys-hostname-long-perl libsys-sigaction-perl libregexp-common-net-cidr-perl libmime-tools-perl libdbd-sqlite3-perl binutils build-essential libfilesys-df-perl zlib1g unzip mlocate clamav libdbd-mysql-perl unrar libclamav-dev libclamav-client-perl libclamunrar9 - -cpanm Encoding::FixLatin -cpanm Digest::SHA1 -cpanm Geo::IP -cpanm Razor2::Client::Agent -cpanm Net::Patricia -cpanm Net::CIDR - -sudo systemctl stop clamav-freshclam.service - -freshclam - -sudo systemctl start clamav-freshclam.service - -DIR=/etc/spamassassin -if [ -d "$DIR" ]; then - -apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl -sa-update -else -echo "Please install spamassassin through the CyberPanel interface before proceeding" -exit -fi + apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl + sa-update + else + echo "Please install spamassassin through the CyberPanel interface before proceeding" + exit + fi fi -echo "header_checks = regexp:/etc/postfix/header_checks" >> /etc/postfix/main.cf -echo "/^Received:/ HOLD" >> /etc/postfix/header_checks +echo "header_checks = regexp:/etc/postfix/header_checks" >>/etc/postfix/main.cf +echo "/^Received:/ HOLD" >>/etc/postfix/header_checks systemctl restart postfix -if [ "$OS" = "NAME=\"Ubuntu\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.noarch.deb -dpkg -i *.noarch.deb +if [ "$OS" = "NAME=\"Ubuntu\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.noarch.deb + dpkg -i *.noarch.deb -mkdir /var/run/MailScanner -mkdir /var/lock/subsys -mkdir /var/lock/subsys/MailScanner -chown -R postfix:postfix /var/run/MailScanner -chown -R postfix:postfix /var/lock/subsys/MailScanner -chown -R postfix:postfix /var/spool/MailScanner + mkdir /var/run/MailScanner + mkdir /var/lock/subsys + mkdir /var/lock/subsys/MailScanner + chown -R postfix:postfix /var/run/MailScanner + chown -R postfix:postfix /var/lock/subsys/MailScanner + chown -R postfix:postfix /var/spool/MailScanner -elif [ "$OS" = "NAME=\"CentOS Linux\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm -rpm -Uvh *.rhel.noarch.rpm +elif [ "$OS" = "NAME=\"CentOS Linux\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm + rpm -Uvh *.rhel.noarch.rpm -elif [ "$OS" = "NAME=\"CloudLinux\"" ];then -wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm -rpm -Uvh *.rhel.noarch.rpm +elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then + wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm + rpm -Uvh *.rhel.noarch.rpm fi mkdir /var/spool/MailScanner/spamassassin @@ -234,8 +224,8 @@ PASSWORD=$(cat /etc/cyberpanel/mysqlPassword) USER=root DATABASE=mailscanner ADMINPASS=$(cat /etc/cyberpanel/adminPass) -mysql -u${USER} -p${PASSWORD} < "/usr/local/CyberCP/public/mailwatch/create.sql" -mysql -u${USER} -p${PASSWORD} -e "use mailscanner"; +mysql -u${USER} -p${PASSWORD} <"/usr/local/CyberCP/public/mailwatch/create.sql" +mysql -u${USER} -p${PASSWORD} -e "use mailscanner" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "GRANT ALL ON mailscanner.* TO root@localhost IDENTIFIED BY '${PASSWORD}';" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "FLUSH PRIVILEGES;" mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "INSERT INTO mailscanner.users SET username = 'admin', password = MD5('${ADMINPASS}'), fullname = 'admin', type = 'A';" @@ -247,11 +237,11 @@ sed -i "s/^define('DB_PASS',.*/define('DB_PASS','${PASSWORD}');/" /usr/local/Cyb sed -i "s/^define('MAILWATCH_HOME',.*/define(\'MAILWATCH_HOME\', \'\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php MSDEFAULT=/etc/MailScanner/defaults -if [ -f "$MSDEFAULT" ];then -sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults -elif [ ! -f "$MSDEFAULT" ];then -touch /etc/MailScanner/defaults -echo "run_mailscanner=1" >> /etc/MailScanner/defaults +if [ -f "$MSDEFAULT" ]; then + sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults +elif [ ! -f "$MSDEFAULT" ]; then + touch /etc/MailScanner/defaults + echo "run_mailscanner=1" >>/etc/MailScanner/defaults fi cp /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatchConf.pm /usr/share/MailScanner/perl/custom/ @@ -268,125 +258,121 @@ systemctl restart mailscanner IPADDRESS=$(cat /etc/cyberpanel/machineIP) +### Furhter onwards is sieve configurations -echo 'Setting up spamassassin and sieve to deliver spam to Junk folder by default' -#echo "If you wish mailscanner/spamassassin to send spam email to a spam folder please follow the tutorial on the Cyberpanel Website" -echo 'Fix protocols' -sed -i 's/^protocols =.*/protocols = imap pop3 lmtp sieve/g' /etc/dovecot/dovecot.conf - - -sed -i "s|^user_query.*|user_query = SELECT '5000' as uid, '5000' as gid, '/home/vmail/%d/%n' as home,mail FROM e_users WHERE email='%u';|g" /etc/dovecot/dovecot-sql.conf.ext - -if [ "$OS" = "NAME=\"Ubuntu\"" ];then -if [ "$UBUNTUVERSION" = "VERSION_ID=\"18.04\"" ];then - apt-get install -y dovecot-managesieved dovecot-sieve dovecot-lmtpd net-tools pflogsumm -elif [ "$UBUNTUVERSION" = "VERSION_ID=\"20.04\"" ];then - apt-get install -y libmysqlclient-dev - sed -e '/deb/ s/^#*/#/' -i /etc/apt/sources.list.d/dovecot.list - apt install -y dovecot-lmtpd dovecot-managesieved dovecot-sieve net-tools pflogsumm -fi - -elif [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then - - yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts - -elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then - - rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm - dnf --enablerepo=gf-plus upgrade -y dovecot23* - dnf --enablerepo=gf-plus install -y dovecot23-pigeonhole - dnf install -y net-tools postfix-perl-scripts - -elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then - - yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts -fi - - -# Create Sieve files -mkdir -p /etc/dovecot/sieve/global -touch /var/log/{dovecot-lda-errors.log,dovecot-lda.log} -touch /var/log/{dovecot-sieve-errors.log,dovecot-sieve.log} -touch /var/log/{dovecot-lmtp-errors.log,dovecot-lmtp.log} -touch /etc/dovecot/sieve/default.sieve -chown vmail: -R /etc/dovecot/sieve -chown vmail:mail /var/log/dovecot-* - -echo 'Create Sieve Default spam to Junk rule' -cat >> /etc/dovecot/sieve/default.sieve <> /etc/dovecot/dovecot.conf <>/etc/dovecot/sieve/default.sieve <>/etc/dovecot/dovecot.conf <