|
| 1 | +#!/bin/bash |
| 2 | +systemctl stop firewalld |
| 3 | + |
| 4 | +MAILSCANNER=/etc/MailScanner |
| 5 | + |
| 6 | +if [ -d $MAILSCANNER ];then |
| 7 | + |
| 8 | +echo "MailScanner found. If you wish to reinstall then remove the package and revert" |
| 9 | +echo "Postfix back to its original config at /etc/postfix/main.cf and remove" |
| 10 | +echo "/etc/MailScanner and /usr/share/MailScanner directories" |
| 11 | +exit |
| 12 | +fi |
| 13 | + |
| 14 | +if [ -f /etc/os-release ];then |
| 15 | + ./etc/os-release |
| 16 | +OS=$NAME |
| 17 | +fi |
| 18 | + |
| 19 | +if [ "$OS" == "CentOS Linux" ];then |
| 20 | + |
| 21 | +setenforce 0 |
| 22 | + |
| 23 | +yum install -y yum-utils perl-CPAN 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)" |
| 24 | + |
| 25 | +rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm |
| 26 | + |
| 27 | +export PERL_MM_USE_DEFAULT=1 |
| 28 | +curl -L https://cpanmin.us | perl - App::cpanminus |
| 29 | +cpanm Encoding::FixLatin |
| 30 | +cpanm Digest::SHA1 |
| 31 | +cpanm Geo::IP |
| 32 | +cpanm Razor2::Client::Agent |
| 33 | +cpanm Net::Patricia |
| 34 | + |
| 35 | +freshclam -v |
| 36 | + |
| 37 | +DIR=/etc/mail/spamassassin |
| 38 | + |
| 39 | +if [ -d "$DIR" ]; then |
| 40 | +sa-update |
| 41 | + |
| 42 | +else |
| 43 | + |
| 44 | +echo "Please install spamassassin through the CyberPanel interface before proceeding" |
| 45 | + |
| 46 | +exit |
| 47 | +fi |
| 48 | + |
| 49 | +else |
| 50 | + |
| 51 | +apt-get install -y libmysqlclient-dev |
| 52 | + |
| 53 | +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 libclamunrar7 |
| 54 | + |
| 55 | +cpanm Encoding::FixLatin |
| 56 | +cpanm Digest::SHA1 |
| 57 | +cpanm Geo::IP |
| 58 | +cpanm Razor2::Client::Agent |
| 59 | +cpanm Net::Patricia |
| 60 | +cpanm Net::CIDR |
| 61 | + |
| 62 | +sudo systemctl stop clamav-freshclam.service |
| 63 | + |
| 64 | +freshclam |
| 65 | + |
| 66 | +sudo systemctl start clamav-freshclam.service |
| 67 | + |
| 68 | +DIR=/etc/spamassassin |
| 69 | +if [ -d "$DIR" ]; then |
| 70 | + |
| 71 | +apt-get -y install razor pyzor libencode-detect-perl libgeo-ip-perl libnet-patricia-perl |
| 72 | +sa-update |
| 73 | +else |
| 74 | +echo "Please install spamassassin through the CyberPanel interface before proceeding" |
| 75 | +exit |
| 76 | +fi |
| 77 | +fi |
| 78 | + |
| 79 | + |
| 80 | +echo "header_checks = regexp:/etc/postfix/header_checks" >> /etc/postfix/main.cf |
| 81 | +echo "/^Received:/ HOLD" >> /etc/postfix/header_checks |
| 82 | + |
| 83 | +systemctl restart postfix |
| 84 | + |
| 85 | +wget https://github.com/MailScanner/v5/archive/master.zip |
| 86 | +unzip master.zip |
| 87 | + |
| 88 | +cd /root/v5-master/builds |
| 89 | + |
| 90 | +if [ "$OS" == "CentOS Linux" ];then |
| 91 | +rpm -Uvh *.rhel.noarch.rpm |
| 92 | +else |
| 93 | +dpkg -i *.noarch.deb |
| 94 | + |
| 95 | + |
| 96 | +mkdir /var/run/MailScanner |
| 97 | +mkdir /var/lock/subsys |
| 98 | +mkdir /var/lock/subsys/MailScanner |
| 99 | +chown -R postfix:postfix /var/run/MailScanner |
| 100 | +chown -R postfix:postfix /var/lock/subsys/MailScanner |
| 101 | +chown -R postfix:postfix /var/spool/MailScanner |
| 102 | +fi |
| 103 | +mkdir /var/spool/MailScanner/spamassassin |
| 104 | + |
| 105 | +chown postfix.mtagroup /var/spool/MailScanner/spamassassin |
| 106 | +chown root.mtagroup /var/spool/MailScanner/incoming/ |
| 107 | +chown postfix.mtagroup /var/spool/MailScanner/milterin |
| 108 | +chown postfix.mtagroup /var/spool/MailScanner/milterout |
| 109 | +chown postfix.mtagroup /var/spool/postfix/hold |
| 110 | +chown postfix.mtagroup /var/spool/postfix/incoming |
| 111 | +usermod -a -G mtagroup nobody |
| 112 | + |
| 113 | +chmod g+rx /var/spool/postfix/incoming |
| 114 | +chmod g+rx /var/spool/postfix/hold |
| 115 | +chmod -R 0775 /var/spool/postfix/incoming |
| 116 | +chmod -R 0775 /var/spool/postfix/hold |
| 117 | + |
| 118 | +sed -i 's/^Run As User =.*/& postfix/' /etc/MailScanner/MailScanner.conf |
| 119 | +sed -i 's/^Run As Group =.*/& postfix/' /etc/MailScanner/MailScanner.conf |
| 120 | +sed -i 's/^Incoming Queue Dir =.*/Incoming Queue Dir = \/var\/spool\/postfix\/hold/' /etc/MailScanner/MailScanner.conf |
| 121 | +sed -i 's/^Outgoing Queue Dir =.*/Outgoing Queue Dir = \/var\/spool\/postfix\/incoming/' /etc/MailScanner/MailScanner.conf |
| 122 | +sed -i 's/^MTA =.*/MTA = postfix/' /etc/MailScanner/MailScanner.conf |
| 123 | +sed -i 's/^Quarantine User =.*/& postfix/' /etc/MailScanner/MailScanner.conf |
| 124 | +sed -i 's/^Quarantine Group =.*/& mtagroup/' /etc/MailScanner/MailScanner.conf |
| 125 | +sed -i 's/^Quarantine Permissions =.*/Quarantine Permissions = 640/' /etc/MailScanner/MailScanner.conf |
| 126 | +sed -i 's/^Virus Scanners =.*/Virus Scanners = clamav/' /etc/MailScanner/MailScanner.conf |
| 127 | +sed -i 's/^Is Definitely Not Spam =.*/Is Definitely Not Spam = \&SQLWhitelist/' /etc/MailScanner/MailScanner.conf |
| 128 | +sed -i 's/^Is Definitely Spam =.*/Is Definitely Spam = \&SQLBlacklist/' /etc/MailScanner/MailScanner.conf |
| 129 | +sed -i 's/^SpamAssassin User State Dir =.*/& \/var\/spool\/MailScanner\/spamassassin/' /etc/MailScanner/MailScanner.conf |
| 130 | +sed -i 's/^Always Looked Up Last =.*/Always Looked Up Last = \&MailWatchLogging/' /etc/MailScanner/MailScanner.conf |
| 131 | +sed -i 's/^Quarantine Whole Message =.*/Quarantine Whole Message = yes/' /etc/MailScanner/MailScanner.conf |
| 132 | +sed -i 's/^Spam List =.*/Spam List = SBL + XBL/' /etc/MailScanner/MailScanner.conf |
| 133 | + |
| 134 | +mkdir /usr/local/CyberCP/public/mailwatch |
| 135 | + |
| 136 | +cd /usr/local/CyberCP/public/mailwatch |
| 137 | + |
| 138 | +git clone --depth=1 https://github.com/mailwatch/MailWatch.git --branch 1.2 --single-branch |
| 139 | + |
| 140 | +mv /usr/local/CyberCP/public/mailwatch/MailWatch/* /usr/local/CyberCP/public/mailwatch/ |
| 141 | + |
| 142 | +PASSWORD=$(cat /etc/cyberpanel/mysqlPassword) |
| 143 | +USER=root |
| 144 | +DATABASE=mailscanner |
| 145 | +ADMINPASS=$(cat /etc/cyberpanel/adminPass) |
| 146 | +mysql -u${USER} -p${PASSWORD} < "/usr/local/CyberCP/public/mailwatch/create.sql" |
| 147 | +mysql -u${USER} -p${PASSWORD} -e "use mailscanner"; |
| 148 | +mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "GRANT ALL ON mailscanner.* TO root@localhost IDENTIFIED BY '${PASSWORD}';" |
| 149 | +mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "FLUSH PRIVILEGES;" |
| 150 | +mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "INSERT INTO mailscanner.users SET username = 'admin', password = MD5('${ADMINPASS}'), fullname = 'admin', type = 'A';" |
| 151 | + |
| 152 | +cp /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php.example /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php |
| 153 | + |
| 154 | +sed -i "s/^define('DB_USER',.*/define('DB_USER','root');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php |
| 155 | +sed -i "s/^define('DB_PASS',.*/define('DB_PASS','${PASSWORD}');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php |
| 156 | +sed -i "s/^define('MAILWATCH_HOME',.*/define(\'MAILWATCH_HOME\', \'\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php |
| 157 | +sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults |
| 158 | + |
| 159 | +cp /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatchConf.pm /usr/share/MailScanner/perl/custom/ |
| 160 | +sed -i 's/^my (\$db_user) = .*/my (\$db_user) = \x27'${USER}'\x27;/' /usr/share/MailScanner/perl/custom/MailWatchConf.pm |
| 161 | +sed -i 's/^my (\$db_pass) = .*/my (\$db_pass) = \x27'${PASSWORD}'\x27;/' /usr/share/MailScanner/perl/custom/MailWatchConf.pm |
| 162 | +ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatch.pm /usr/share/MailScanner/perl/custom |
| 163 | +ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/SQLBlackWhiteList.pm /usr/share/MailScanner/perl/custom |
| 164 | +ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/SQLSpamSettings.pm /usr/share/MailScanner/perl/custom |
| 165 | +sed -i "s/^\$pathToFunctions =.*/\$pathToFunctions = '\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner\/functions.php';/" /usr/local/CyberCP/public/mailwatch/upgrade.php |
| 166 | + |
| 167 | +php /usr/local/CyberCP/public/mailwatch/upgrade.php |
| 168 | +systemctl enable mailscanner |
| 169 | +systemctl restart mailscanner |
| 170 | + |
| 171 | +IPADDRESS=$(cat /etc/cyberpanel/machineIP) |
| 172 | + |
| 173 | +echo "MailScanner successfully installed. MailWatch successfully installed." |
| 174 | +echo "Visit https://${IPADDRESS}:8090/mailwatch/mailscanner" |
| 175 | +echo "Username: admin" |
| 176 | +echo "Password: ${ADMINPASS}" |
| 177 | +echo "If you wish mailscanner/spamassassin to send spam email to a spam folder please follow the tutorial on the Cyberpanel Website" |
| 178 | +echo "Firewalld is stopped. Either enable, install CSF or use an alternative!" |
| 179 | +echo "Optional cpan/cpanm modules are available for MailScanner. Cronjobs and further postfix tools are available for MailWatch" |
| 180 | +echo "See https://www.mailwatch.org and https://docs.mailwatch.org/install/optional-setup.html" |
| 181 | +exit |
| 182 | + |
0 commit comments