SHARE
TWEET

Ubuntu 14.04 and Maia Mailguard 1.0.4 [Updated]

a guest Jul 3rd, 2016 665 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Written by Chris.boyle.1978@gmail.com, based on previous script by mr88talent at yahoo dot com
  3. # NOTE: ONLY FOR USE ON A FRESH UBUNTU 14.04 SERVER. USE AT YOUR OWN RISK.
  4. #
  5. # This is for debug purposes below. Only uncomment if you know why you're doing it.
  6. # echo "Press CTRL+C to proceed."
  7. # trap "pkill -f 'sleep 1h'" INT
  8. # trap "set +x ; sleep 1h ; set -x" DEBUG
  9. #
  10. # Variables that you need to change!
  11. ROOTS_MYSQL_PASSWORD=PASSWORDHERE
  12. MAIA_MYSQL_PASSWORD=PASSWORDHERE
  13. HOSTNAME=SHORTHOSTNAMEHERE # Ex: spam
  14. DOMAIN_NAME=DOMAINNAMEHERE # Ex: somecompany.com
  15. RELAY_SERVER_IP=IPOFMAILSERVERHERE # Ex: 172.16.0.2
  16. NETWORK_ADDRESS=SUBNETHERE # Ex: 172.16.0.0
  17. HELP_ME_EMAIL_ADDRESS=EMAILADDRESSHERE # Ex: support@somecompany.com
  18.  
  19. # Change to /root and download some needed files.
  20. cd
  21. mkdir .maia
  22. cd .maia
  23. wget http://www.iscg.net/maia/maia_files.tar.gz
  24. tar zxvf maia_files.tar.gz
  25.  
  26. # Update Package Lists and install needed software
  27. cd
  28. apt-get update
  29. apt-get -y install libperl5.18 libpq5 amavisd-new spamassassin razor pyzor libnet-cidr-lite-perl libmail-dkim-perl clamav clamav-daemon dnsutils flex bison gdb arj unrar-free nomarch lzop libimage-info-perl libdbd-mysql-perl curl rsync debconf-utils patch libossp-uuid-perl libtemplate-perl libtext-csv-perl libwww-perl cabextract php5 php-pear php5-common php5-mysql php5-gd php5-sqlite libmail-dkim-perl libencode-detect-perl libforks-perl php5-imap php5-ldap php5-mcrypt smarty3 apache2 libapache2-mod-php5 git rar unrar unzip zip zoo fail2ban php5-dev
  30.  
  31. # Configure Host Name
  32. echo "$HOSTNAME.$DOMAIN_NAME" > /etc/hostname
  33.  
  34. # Install MySQL
  35. cd
  36. echo "mysql-server-5.5 mysql-server/root_password password $ROOTS_MYSQL_PASSWORD" > mysql.preseed
  37. echo "mysql-server-5.5 mysql-server/root_password_again password $ROOTS_MYSQL_PASSWORD" >> mysql.preseed
  38. echo "mysql-server-5.5 mysql-server/start_on_boot boolean true" >> mysql.preseed
  39. cat mysql.preseed | debconf-set-selections
  40. apt-get -y install mysql-server
  41. chmod 0600 mysql.preseed
  42.  
  43. # MySQL Configuration
  44. /etc/init.d/mysql stop
  45. sleep 10
  46. cp /etc/mysql/my.cnf /etc/mysql/my.cnf.original
  47. patch /etc/mysql/my.cnf</root/.maia/my.cnf.5.1.patch.txt
  48. mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/iblogfile0-old
  49. mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/iblogfile1-old
  50. /etc/init.d/mysql start
  51.  
  52. # Install Postfix with very base config
  53. cd
  54. echo "postfix postfix/mailname string $HOSTNAME.$DOMAIN_NAME" > postfix.preseed
  55. echo "postfix postfix/main_mailer_type string 'Internet Site'" >> postfix.preseed
  56. cat postfix.preseed | debconf-set-selections
  57. apt-get install -y postfix postfix-pcre postfix-mysql postfix-ldap
  58. chmod 0600 postfix.preseed
  59.  
  60. # Install more stuff with pear
  61. pear channel-update pear.php.net
  62. pear install Mail_Mime-1.8.1
  63. pear install Mail_mimeDecode-1.5.5
  64. pear install Log-1.12.6
  65. pear install Pager-2.4.8
  66. pear install Image_Color-1.0.4
  67. pear install Image_Canvas-0.3.4
  68. pear install Image_Graph-0.8.0
  69. pear install Numbers_Roman-1.0.2
  70. pear install Numbers_Words-0.16.1
  71. pear install Auth_SASL-1.0.4
  72. pear install Net_Socket-1.0.10
  73. pear install Net_IMAP-1.1.0
  74. pear install Net_POP3-1.3.8
  75. pear install DB-1.7.13
  76. pear install Net_SMTP-1.4.4
  77. pear channel-discover htmlpurifier.org
  78. pear install hp/HTMLPurifier
  79. pear install MDB2
  80. pear install MDB2#mysql
  81.  
  82. # Update ClamAV, Install Scrypt, set /etc/mailname
  83. freshclam
  84. pecl install scrypt
  85. echo "extension=scrypt.so" >> /etc/php5/apache2/php.ini
  86. echo "$HOSTNAME.$DOMAIN_NAME" > /etc/mailname
  87.  
  88. # Download Maia Mailguard from GitHub
  89. cd /usr/local/src
  90. git clone git://github.com/technion/maia_mailguard.git
  91.  
  92. # Remove AppArmor
  93. /etc/init.d/apparmor stop
  94. update-rc.d -f apparmor remove
  95. aptitude remove apparmor apparmor-utils
  96.  
  97. # SpamAssassin Configuration
  98. sed -i 's/ENABLED=0/ENABLED=1/' /etc/default/spamassassin
  99. cp /root/.maia/sa-update1.sh.txt /usr/sbin/sa-update.sh
  100. chmod +x /usr/sbin/sa-update.sh
  101. sa-update.sh
  102. cd /var/lib/amavis
  103. cp /root/.maia/sample-spam.txt .
  104. sa-learn --spam sample-spam.txt
  105. sed -i "s/#loadplugin Mail::SpamAssassin::Plugin::DKIM/loadplugin Mail::SpamAssassin::Plugin::DKIM/" /etc/spamassassin/v312.pre
  106. sed -i "s/# lock_method flock/lock_method flock/" /etc/spamassassin/local.cf
  107. sed -i "s/# trusted_networks 212.17.35./trusted_networks $NETWORK_ADDRESS/" /etc/spamassassin/local.cf
  108. su amavis -c 'spamassassin --lint'
  109. gpasswd -a clamav amavis
  110. freshclam
  111. cd
  112.  
  113. # Configure Pyzor and Razor
  114. rm /etc/razor/razor-agent.conf
  115. razor-admin -create
  116. razor-admin -create
  117. razor-admin -register
  118. razor-admin -register
  119. sed -i 's/= 3/= 0/' /root/.razor/razor-agent.conf
  120. cp -r /root/.razor /var/lib/amavis
  121. chown -R amavis:amavis /var/lib/amavis
  122. cat /var/lib/amavis/.razor/razor-agent.conf | grep debuglevel
  123. cd /usr/bin
  124. cp /usr/bin/pyzor /usr/bin/pyzor.original
  125. patch /usr/bin/pyzor</root/.maia/pyzor.deprecation.txt
  126. sleep 4
  127. su amavis -c 'pyzor discover'
  128. su amavis -c 'pyzor ping'
  129.  
  130. # Configuring DCC
  131. cd /usr/local/src
  132. cp /root/.maia/dcc-1.3.142.tar.Z .
  133. tar xzf dcc-1.3.142.tar.Z
  134. cd dcc-1.3.142
  135. ./configure --with-uid=amavis && make && make install
  136. ln -s /var/dcc/libexec/cron-dccd /usr/bin/cron-dccd
  137. chown -R amavis:amavis /var/dcc
  138. cdcc info
  139. echo "dcc_home /var/dcc" >> /etc/spamassassin/local.cf
  140. sed -i 's/DCCIFD_ENABLE=off/DCCIFD_ENABLE=on/' /var/dcc/dcc_conf
  141. sed -i 's/DBCLEAN_LOGDAYS=14/DBCLEAN_LOGDAYS=1/' /var/dcc/dcc_conf
  142. sed -i 's/DCCIFD_LOGDIR/#DCCIFD_LOGDIR/' /var/dcc/dcc_conf
  143. cp /var/dcc/libexec/rcDCC /etc/init.d/adcc
  144. sed -i 's/# Default-Start:     3 5/# Default-Start:     2 3 4 5/' /etc/init.d/adcc
  145. sed -i 's/# Default-Stop:/# Default-Stop:      0 1 6/' /etc/init.d/adcc
  146. update-rc.d adcc defaults
  147. /etc/init.d/adcc start
  148. sed -i 's/#loadplugin Mail::SpamAssassin::Plugin::DCC/loadplugin Mail::SpamAssassin::Plugin::DCC/' /etc/spamassassin/v310.pre
  149.  
  150. # Configuring SaneSecurity
  151. cp /root/.maia/clamav-unofficial-sigs.8.gz.b /usr/share/man/man8/clamav-unofficial-sigs.8.gz
  152. cp /root/.maia/clamav-unofficial-sigs.conf.txt /etc/clamav-unofficial-sigs.conf
  153. cp /root/.maia/clamd-status.sh.txt /usr/sbin/clamd-status.sh
  154. chmod +x /usr/sbin/clamd-status.sh
  155. cp /root/.maia/clamav-unofficial-sigs.sh.txt /usr/sbin/clamav-unofficial-sigs.sh
  156. chmod +x /usr/sbin/clamav-unofficial-sigs.sh
  157. cp /root/.maia/clamav-unofficial-sigs-logrotate.txt /etc/logrotate.d/clamav-unofficial-sigs
  158. clamav-unofficial-sigs.sh
  159. ls -l /var/lib/clamav
  160. cp /root/.maia/amavis-sanesecurity_v2.cf /etc/spamassassin
  161. spamassassin --lint
  162.  
  163. # Configuring Amavis-New
  164. sed -i "s/ --name \${DAEMONNAME}//" /etc/init.d/amavis
  165. /etc/init.d/amavis restart
  166. cd /var/lib/amavis
  167. su amavis -c 'spamassassin <sample-spam.txt'
  168. amavisd-new reload
  169. sed -i "s/#@bypass_virus/ @bypass_virus/" /etc/amavis/conf.d/15-content_filter_mode
  170. sed -i "s/#   \\\%bypass_virus/    \\\%bypass_virus/" /etc/amavis/conf.d/15-content_filter_mode
  171. sed -i "s/#@bypass_spam/ @bypass_spam/" /etc/amavis/conf.d/15-content_filter_mode
  172. sed -i "s/#   \\\%bypass_spam/    \\\%bypass_spam/" /etc/amavis/conf.d/15-content_filter_mode
  173. cat /etc/amavis/conf.d/15-content_filter_mode
  174. mv /etc/amavis/conf.d/50-user /etc/amavis/conf.d/50-user.original.disabled
  175. cp /root/.maia/amavis-50-user.txt /etc/amavis/conf.d/50-user
  176. sed -i "s/host.example.tld/$HOSTNAME.$DOMAIN_NAME/" /etc/amavis/conf.d/50-user
  177. sed -i "s/example.tld/$DOMAIN_NAME/" /etc/amavis/conf.d/50-user
  178. /etc/init.d/amavis stop
  179. /etc/init.d/clamav-daemon restart
  180. /etc/init.d/amavis start
  181. cp /root/.maia/rmvirusquar.txt /etc/cron.daily/rmvirusquar
  182. chmod +x /etc/cron.daily/rmvirusquar
  183. /etc/cron.daily/rmvirusquar
  184.  
  185. # Configuring Postfix
  186. /etc/init.d/postfix stop
  187. cp /etc/postfix/main.cf /etc/postfix/main.cf-original-$(date +%Y%m%d)
  188. cp /etc/postfix/master.cf /etc/postfix/master.cf-original-$(date +%Y%m%d)
  189. grep 'smtp-amavis' /etc/postfix/master.cf || cat /root/.maia/amavis-transport.txt >> /etc/postfix/master.cf
  190. sed -i '/pickup/s|$| -o content_filter= |' /etc/postfix/master.cf
  191. postconf -e "mydomain = $DOMAIN_NAME"
  192. postconf -e "myorigin = $DOMAIN_NAME"
  193. postconf -e "myhostname = $HOSTNAME.$DOMAIN_NAME"
  194. postconf -e "mydestination = "
  195. postconf -e "recipient_delimiter = "
  196. postconf -e "relayhost = "
  197. postconf -e "local_transport = error:no local mail delivery"
  198. postconf -e "local_recipient_maps = "
  199. postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
  200. touch /etc/postfix/virtual
  201. postmap /etc/postfix/virtual
  202. # This was if we were not using MySQL for the lookups:
  203. # postconf -e "relay_domains = $DOMAIN_NAME"
  204. postconf -e "relay_domains = mysql:/etc/postfix/mysql-relay.cf"
  205. postconf -e "smtpd_helo_required = yes"
  206. postconf -e "smtpd_data_restrictions = reject_unauth_pipelining"
  207. postconf -e "smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"
  208. touch /etc/postfix/transport
  209. cp /etc/postfix/transport /etc/postfix/transport-original-$(date +%Y%m%d)
  210. # This was if we were not using MySQL for the lookups:
  211. #postconf -e "transport_maps = hash:/etc/postfix/transport"
  212. postconf -e "transport_maps = mysql:/etc/postfix/mysql-transport.cf"
  213. echo "$DOMAIN_NAME relay:[$RELAY_SERVER_IP]" >> /etc/postfix/transport
  214. postmap /etc/postfix/transport
  215. postconf -e "content_filter = smtp-amavis:[127.0.0.1]:10024"
  216. postconf -e "message_size_limit = 26214400"
  217. postconf -e "disable_vrfy_command = yes"
  218. # Disabling Recipient Verification for now. Here's how you'd enable it later:
  219. # postconf -e "address_verify_transport_maps = hash:/etc/postfix/probe_transport"
  220. # postconf -e "unverified_recipient_reject_code = 550"
  221. # echo "$DOMAIN_NAME smtp:[$RELAY_SERVER_IP]" > /etc/postfix/probe_transport
  222. postconf -e "smtpd_helo_restrictions = check_helo_access hash:/etc/postfix/helo_access, reject_invalid_hostname, reject_non_fqdn_hostname"
  223. postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access, reject_non_fqdn_sender, reject_unknown_sender_domain"
  224. postconf -e "smtpd_recipient_restrictions = reject_non_fqdn_recipient,reject_unknown_recipient_domain, reject_unverified_recipient, permit_mynetworks, reject_unauth_destination, check_recipient_access hash:/etc/postfix/recipient_access"
  225. postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/client_access, check_client_access cidr:/etc/postfix/client_access_cidr, reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net, reject_rbl_client zz.countries.nerd.dk=127.0.0.156, reject_rbl_client zz.countries.nerd.dk=127.0.1.152, reject_rbl_client zz.countries.nerd.dk=127.0.1.154, reject_rbl_client zz.countries.nerd.dk=127.0.1.100, reject_rbl_client zz.countries.nerd.dk=127.0.2.74, reject_rbl_client zz.countries.nerd.dk=127.0.2.131, reject_rbl_client zz.countries.nerd.dk=127.0.3.24, reject_rbl_client zz.countries.nerd.dk=127.0.3.36, reject_rbl_client zz.countries.nerd.dk=127.0.3.94, reject_rbl_client zz.countries.nerd.dk=127.0.2.192"
  226. echo "root $HELP_ME_EMAIL_ADDRESS" > /etc/postfix/virtual
  227. echo "postmaster $HELP_ME_EMAIL_ADDRESS" >> /etc/postfix/virtual
  228. echo "$DOMAIN_NAME REJECT" > /etc/postfix/helo_access
  229. touch /etc/postfix/client_access
  230. touch /etc/postfix/client_access_cidr
  231. touch /etc/postfix/sender_access
  232. touch /etc/postfix/recipient_access
  233. touch /etc/postfix/probe_transport
  234. newaliases
  235. postmap /etc/postfix/virtual
  236. postmap /etc/postfix/recipient_access
  237. postmap /etc/postfix/helo_access
  238. postmap /etc/postfix/client_access
  239. postmap /etc/postfix/client_access_cidr
  240. postmap /etc/postfix/transport
  241. postmap /etc/postfix/sender_access
  242. postmap /etc/postfix/probe_transport
  243. touch /etc/postfix/mysql-transport.cf
  244. touch /etc/postfix/mysql-relay.cf
  245. echo "host=localhost" >> /etc/postfix/mysql-transport.cf
  246. echo "dbname=maia" >> /etc/postfix/mysql-transport.cf
  247. echo "user=maia" >> /etc/postfix/mysql-transport.cf
  248. echo "password=$MAIA_MYSQL_PASSWORD" >> /etc/postfix/mysql-transport.cf
  249. echo "query=SELECT transport FROM maia_domains WHERE routing_domain = '%s';" >> /etc/postfix/mysql-transport.cf
  250. echo "host=localhost" > /etc/postfix/mysql-relay.cf
  251. echo "dbname=maia" >> /etc/postfix/mysql-relay.cf
  252. echo "user=maia" >> /etc/postfix/mysql-relay.cf
  253. echo "password=$MAIA_MYSQL_PASSWORD" >> /etc/postfix/mysql-relay.cf
  254. echo "query=SELECT 'OK' FROM maia_domains WHERE routing_domain = '%s';" >> /etc/postfix/mysql-relay.cf
  255. /etc/init.d/postfix start
  256.  
  257. # Configuring Maia Mailguard and Replace Amavis-New
  258. echo "amavisd-new hold" | dpkg --set-selections
  259. adduser --group --system --home /var/lib/maia --shell /bin/sh maia
  260. mkdir /var/virusmails
  261. chmod 0750 /var/virusmails
  262. chown maia:maia /var/virusmails
  263. mkdir /etc/maia
  264. mkdir /var/run/maia
  265. chown maia:root /var/run/maia
  266. mkdir /var/lock/maia
  267. chown maia:root /var/lock/maia
  268. test -e /var/lib/maia || mkdir /var/lib/maia
  269. mkdir /var/lib/maia/tmp
  270. mkdir /var/lib/maia/db
  271. mkdir /var/lib/maia/scripts
  272. chown -R maia:maia /var/lib/maia
  273. chmod -R 0750 /var/lib/maia
  274. mkdir /var/log/maia
  275. touch /var/log/maia/process-quarantine.log
  276. chown -R maia:maia /var/log/maia
  277. cp /root/.maia/maia.txt /etc/logrotate.d/maia
  278. dpkg-statoverride --add maia maia 770 /var/lib/maia/tmp
  279. dpkg-statoverride --add maia maia 750 /var/virusmails
  280. dpkg-statoverride --add maia maia 755 /var/run/maia
  281. dpkg-statoverride --add maia maia 755 /var/lock/maia
  282. dpkg-statoverride --add maia maia 750 /var/lib/maia/db
  283. dpkg-statoverride --add maia maia 750 /var/lib/maia
  284. cp /usr/local/src/maia_mailguard/scripts/* /var/lib/maia/scripts
  285. test -e /etc/maia/maia.conf && mv /etc/maia/maia.conf /etc/maia/maia.conf-backup-$(date +%Y%m%d)
  286. cp /usr/local/src/maia_mailguard/maia.conf.dist /etc/maia/maia.conf
  287. sed -i "s|'password'|'$MAIA_MYSQL_PASSWORD'|" /etc/maia/maia.conf
  288. chmod 0640 /etc/maia/maia.conf
  289. chgrp maia /etc/maia/maia.conf
  290. cp /usr/local/src/maia_mailguard/*.cf /etc/spamassassin
  291. cp -r /usr/local/src/maia_mailguard/templates /etc/maia
  292. chmod 640 /etc/maia/templates/*.tpl
  293. chown -R maia:maia /etc/maia/templates
  294. cp /usr/local/src/maia_mailguard/maiad /usr/sbin
  295. gpasswd -a clamav maia
  296. /etc/init.d/clamav-daemon stop
  297. /etc/init.d/clamav-daemon start
  298. sed -i 's/le.com/le.tld/' /etc/maia/maia.conf
  299. sed -i "s|http://example.tld/|http://$HOSTNAME.$DOMAIN_NAME/mail|" /etc/maia/maia.conf
  300. /etc/init.d/mysql restart
  301. cd
  302. echo "CREATE DATABASE maia;" >sql.tmp
  303. echo "USE maia;" >>sql.tmp
  304. echo "SOURCE /usr/local/src/maia_mailguard/maia-mysql.sql;" >>sql.tmp
  305. echo "GRANT CREATE, DROP, ALTER, SELECT, INSERT, UPDATE, DELETE ON maia.* TO maia@localhost IDENTIFIED BY '$MAIA_MYSQL_PASSWORD';" >>sql.tmp
  306. echo "FLUSH PRIVILEGES;" >>sql.tmp
  307. echo "DELETE FROM bayes_seen;" >>sql.tmp
  308. echo 'ALTER TABLE bayes_seen ADD lastupdate timestamp default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;' >>sql.tmp
  309. echo "OPTIMIZE TABLE bayes_seen;" >>sql.tmp
  310. echo "UPDATE maia.maia_config SET reminder_template_file = '/etc/maia/templates/reminder.tpl' WHERE maia_config.id = 0;" >>sql.tmp
  311. echo "UPDATE maia.maia_config SET newuser_template_file = '/etc/maia/templates/newuser.tpl' WHERE maia_config.id = 0;" >>sql.tmp
  312. echo "UPDATE maia.maia_config SET admin_email = '"$HELP_ME_EMAIL_ADDRESS"' WHERE maia_config.id = 0;" >>sql.tmp
  313. echo "UPDATE maia.maia_config SET reminder_login_url = '"http://$HOSTNAME.$DOMAIN_NAME/mail"' WHERE maia_config.id = 0;" >>sql.tmp
  314. /usr/bin/mysql -uroot -p$ROOTS_MYSQL_PASSWORD < sql.tmp
  315. chmod 0600 sql.tmp
  316.  
  317. # Don't Need?
  318. #grep 46675 /usr/share/perl5/Mail/SpamAssassin/BayesStore/MySQL.pm || wget http://www.maiamailguard.com/maia/raw-attachment/ticket/565/mysql-bug-46675.patch
  319. #grep 46675 /usr/share/perl5/Mail/SpamAssassin/BayesStore/MySQL.pm || patch -d /usr/share/perl5/Mail/SpamAssassin/BayesStore MySQL.pm < mysql-bug-46675.patch
  320. #sleep 4
  321.  
  322. cp -r /root/.razor /var/lib/maia
  323. chown -R maia:maia /var/lib/maia
  324. cat /var/lib/maia/.razor/razor-agent.conf | grep debuglevel
  325. cd /var/lib/maia
  326. cp /root/.maia/sample-spam.txt .
  327. su maia -c 'sa-learn --spam sample-spam.txt'
  328. su maia -c 'spamassassin <sample-spam.txt'
  329. su maia -c 'spamassassin <sample-spam.txt'
  330. /var/lib/maia/scripts/load-sa-rules.pl
  331. mkdir /var/www/mail
  332. cp -r /usr/local/src/maia_mailguard/php/* /var/www/mail
  333. ln -s /usr/share/php/smarty3 /usr/share/php/Smarty
  334. cp /var/www/mail/config.php.dist /var/www/mail/config.php
  335. sed -i "s/:passwd/:$MAIA_MYSQL_PASSWORD/g" /var/www/mail/config.php
  336. chmod 0640 /var/www/mail/config.php
  337. chown root:www-data /var/www/mail/config.php
  338. for dir in /var/www/mail/themes/*/; do mkdir -- "$dir/compiled"; done
  339. chgrp maia /var/www/mail/themes/*/compiled
  340. chmod 775 /var/www/mail/themes/*/compiled
  341. mkdir /var/www/mail/purifier_cache
  342. chown www-data:www-data /var/www/mail/purifier_cache
  343. sed -i 's|purifier_cache = null;|purifier_cache = "/var/www/mail/purifier_cache";|' /var/www/mail/config.php
  344. gpasswd -a www-data maia
  345. sed -i "s/error_reporting = E_ALL \& ~E_DEPRECATED/error_reporting = E_ALL \& ~E_NOTICE \& ~E_DEPRECATED/" /etc/php5/apache2/php.ini
  346. sed -i "s/html/mail/" /etc/apache2/sites-enabled/000-default.conf
  347. sed -i "/127\.0\.1\.1/ s/$/ $HOSTNAME.$DOMAIN_NAME/" /etc/hosts
  348. sed -i "70i ServerName localhost" /etc/apache2/apache2.conf
  349. /etc/init.d/apache2 restart
  350. /etc/init.d/postfix restart
  351. cp /usr/local/src/maia_mailguard/maiad.conf.dist /etc/maia/maiad.conf
  352. sed -i "s/'password'/'$MAIA_MYSQL_PASSWORD'/" /etc/maia/maiad.conf
  353. sed -i "s/yourdomain.tld/$DOMAIN_NAME/" /etc/maia/maiad.conf
  354. sed -i "s/host.domain.tld/$HOSTNAME.$DOMAIN_NAME/" /etc/maia/maiad.conf
  355. sed -i "s|# qr'^MAIL$'| qr'^MAIL$'|" /etc/maia/maiad.conf
  356. sed -i "s/DO_SYSLOG = 0/DO_SYSLOG = 1/" /etc/maia/maiad.conf
  357. chmod 0640 /etc/maia/maiad.conf
  358. chgrp maia /etc/maia/maiad.conf
  359. /etc/init.d/amavis stop
  360.  
  361. # Disable Amavisd-New and enable Maia init script"
  362. echo "=============================================="
  363. cp -r /etc/init.d /etc/init.d-original
  364. sed -i "s/  \tcheck_noncompatible_upgrade/#  \tcheck_noncompatible_upgrade/" /etc/init.d/amavis
  365. cd /etc/init.d
  366. cp /root/.maia/maia.init.1581.txt .
  367. mv maia.init.1581.txt maia
  368. chmod +x maia
  369. update-rc.d -f amavis remove
  370. update-rc.d maia defaults
  371. sed -i "s/amavisd-new/maiad/" /usr/sbin/sa-update.sh
  372. sed -i "s/amavis/maia/" /usr/sbin/sa-update.sh
  373.  
  374. # Configure Bayes in MySQL"
  375. echo "bayes_store_module              Mail::SpamAssassin::BayesStore::MySQL" >>/etc/spamassassin/local.cf
  376. echo "bayes_sql_dsn                   DBI:mysql:maia:localhost" >>/etc/spamassassin/local.cf
  377. echo "bayes_sql_username              maia" >>/etc/spamassassin/local.cf
  378. echo "bayes_sql_password              $MAIA_MYSQL_PASSWORD" >>/etc/spamassassin/local.cf
  379. echo "bayes_sql_override_username         maia" >>/etc/spamassassin/local.cf
  380. chmod 0640 /etc/spamassassin/local.cf
  381. chown root:maia /etc/spamassassin/local.cf
  382. su maia -c 'spamassassin --lint'
  383. sed -i "s/^loadplugin Mail::SpamAssassin::Plugin::AWL/#loadplugin Mail::SpamAssassin::Plugin::AWL/" /etc/spamassassin/v310.pre
  384. cd /var/lib/maia
  385. sa-learn --spam sample-spam.txt
  386. sa-learn --dump magic
  387. spamassassin --lint
  388. cp /root/.maia/maia-trim-bayes.sql.txt /etc/maia-trim-bayes.sql
  389. cp /root/.maia/maia-trim-bayes.txt /usr/sbin/maia-trim-bayes
  390. sed -i "s/paSSw0rd/$MAIA_MYSQL_PASSWORD/" /usr/sbin/maia-trim-bayes
  391. chmod 0750 /usr/sbin/maia-trim-bayes
  392. cp /root/.maia/maia-trim-sql-bayes-monthly.txt /etc/cron.monthly/maia-trim-sql-bayes-monthly
  393. chmod +x /etc/cron.monthly/maia-trim-sql-bayes-monthly
  394. /etc/cron.monthly/maia-trim-sql-bayes-monthly
  395.  
  396. ## Raise $max_servers from 2 to 4 if we have enough RAM
  397. ##
  398. MemTot=`cat /proc/meminfo | grep MemTotal`
  399. MemTot=${MemTot:9:16}
  400. if [ $MemTot -gt 1700000 ]; then
  401.  sed -i "s/smtp-amavis unix -    -    n    -    2    smtp/smtp-amavis unix -    -    n    -    4    smtp/" /etc/postfix/master.cf
  402.  sed -i "s/max_servers = 2;/max_servers = 4;/" /etc/maia/maiad.conf
  403.  sed -i "s/max_servers = 2;/max_servers = 4;/" /etc/amavis/conf.d/50-user
  404. fi
  405. ##
  406. /etc/init.d/maia start
  407.  
  408. # Copy custom scripts to /usr/local/bin/
  409. cp /root/.maia/scripts/maia_* /usr/local/bin/
  410. chmod 750 /usr/local/bin/maia_*
  411.  
  412. # Running configtest to show any issues
  413. /var/lib/maia/scripts/configtest.pl
  414. cd
  415. echo "========================================================="
  416. echo "I suggest browsing to http://$HOSTNAME.$DOMAIN_NAME/admin/configtest.php"
  417. echo "Then:"
  418. echo "Please browse to http://$HOSTNAME.$DOMAIN_NAME/admin/internal-init.php"
  419. echo "in order to set the Super User. The password will be mailed to the Super User."
  420. echo "Then:"
  421. echo "Please browse to http://$HOSTNAME.$DOMAIN_NAME/login.php?super=register"
  422. echo "and log in as the Super User using the password that was sent."
  423. echo "Then:"
  424. echo "Log into http://$HOSTNAME.$DOMAIN_NAME"
  425. echo "At some point, remove the admin directory: rm -r /var/www/mail/admin/"
  426. echo "========================================================="
  427. echo "also please edit your crontab and insert these lines"
  428. in=$((RANDOM%59+1))
  429. min=$((RANDOM%11+1))
  430. dow=$((RANDOM%7+1))
  431. echo "$in $min * * $dow root /usr/sbin/sa-update.sh"
  432. echo "$in $min * * $dow root /var/lib/maia/scripts/load-sa-rules.pl"
  433. nta=$((RANDOM%59+1))
  434. echo "$nta */6 * * * root /usr/sbin/clamav-unofficial-sigs.sh"
  435. echo "*/6 * * * * root /usr/sbin/clamd-status.sh"
  436. echo "43 11 * * * root /usr/bin/cron-dccd"
  437. echo "30 * * * * root /bin/su maia -s /bin/bash -c '/var/lib/maia/scripts/process-quarantine.pl --learn --report'"
  438. echo "10 1 * * * root /bin/su maia -c '/var/lib/maia/scripts/expire-quarantine-cache.pl --quiet'"
  439. echo "10 2 * * 3 root /bin/su maia -c '/var/lib/maia/scripts/send-quarantine-reminders.pl'"
  440. echo "*/5 * * * * root /bin/su maia -c '/var/lib/maia/scripts/send-quarantine-digests.pl'"
  441. echo "0 * * * * root /bin/su maia -c '/var/lib/maia/scripts/stats-snapshot.pl' >/null"
  442. echo "========================================================="
  443. echo "You can run 'cat maia_info.txt' to see these instructions again"
  444. echo "=========================================================" > maia_info.txt
  445. echo "I suggest browsing to http://$HOSTNAME.$DOMAIN_NAME/admin/configtest.php" >> maia_info.txt
  446. echo "Then:" >> maia_info.txt
  447. echo "Please browse to http://$HOSTNAME.$DOMAIN_NAME/admin/internal-init.php" >> maia_info.txt
  448. echo "in order to set the Super User. The password will be mailed to the Super User."  >> maia_info.txt
  449. echo "Then:" >> maia_info.txt
  450. echo "Please browse to http://$HOSTNAME.$DOMAIN_NAME/login.php?super=register" >> maia_info.txt
  451. echo "and log in as the Super User using the password that was sent." >> maia_info.txt
  452. echo "Then:" >> maia_info.txt
  453. echo "Log into http://$HOSTNAME.$DOMAIN_NAME" >> maia_info.txt
  454. echo "At some point, remove the admin directory: rm -r /var/www/mail/admin/">> maia_info.txt
  455. echo "=========================================================" >> maia_info.txt
  456. echo "also please edit your crontab and insert these lines" >> maia_info.txt
  457. echo "$in $min * * $dow root /usr/sbin/sa-update.sh" >> maia_info.txt
  458. echo "$in $min * * $dow root /var/lib/maia/scripts/load-sa-rules.pl" >> maia_info.txt
  459. echo "$nta */6 * * * root /usr/sbin/clamav-unofficial-sigs.sh" >> maia_info.txt
  460. echo "*/6 * * * * root /usr/sbin/clamd-status.sh" >> maia_info.txt
  461. echo "43 11 * * * root /usr/bin/cron-dccd" >> maia_info.txt
  462. echo "30 * * * * root /bin/su maia -s /bin/bash -c '/var/lib/maia/scripts/process-quarantine.pl --learn --report'" >> maia_info.txt
  463. echo "10 1 * * * root /bin/su maia -c '/var/lib/maia/scripts/expire-quarantine-cache.pl --quiet'" >> maia_info.txt
  464. echo "10 2 * * 3 root /bin/su maia -c '/var/lib/maia/scripts/send-quarantine-reminders.pl'" >> maia_info.txt
  465. echo "*/5 * * * * root /bin/su maia -c '/var/lib/maia/scripts/send-quarantine-digests.pl'" >> maia_info.txt
  466. echo "0 * * * * root /bin/su maia -c '/var/lib/maia/scripts/stats-snapshot.pl' >/null" >> maia_info.txt
  467. echo "=========================================================" >> maia_info.txt
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top