Bob Mottram 10 years ago
parent
commit
fb6a6a0bf0
1 changed files with 144 additions and 1 deletions
  1. 144
    1
      install-freedombone.sh

+ 144
- 1
install-freedombone.sh View File

@@ -374,13 +374,155 @@ function configure_email {
374 374
   sed "s/START=no/START=yes/g" /etc/default/saslauthd > /tmp/saslauthd
375 375
   cp -f /tmp/saslauthd /etc/default/saslauthd
376 376
   /etc/init.d/saslauthd start
377
+
378
+  # make a tls certificate for email
377 379
   makecert exim
378 380
   mv /etc/ssl/private/exim.key /etc/exim4
379 381
   mv /etc/ssl/certs/exim.crt /etc/exim4
380 382
   mv /etc/ssl/certs/exim.dhparam /etc/exim4
381 383
   chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
382 384
   chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
383
-#editor /etc/exim4/exim4.conf.template
385
+
386
+  sed '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template > /tmp/exim4.conf.template
387
+  cp -f /tmp/exim4.conf.template /etc/exim4/exim4.conf.template
388
+
389
+  sed '/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME = $DOMAIN_NAME\nMAIN_TLS_ENABLE = true' /etc/exim4/exim4.conf.template > /tmp/exim4.conf.template
390
+  cp -f /tmp/exim4.conf.template /etc/exim4/exim4.conf.template
391
+
392
+  sed "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4 > /tmp/exim4
393
+  cp -f /tmp/exim4 /etc/default/exim4
394
+
395
+  sed '/03_exim4-config_tlsoptions/a\tls_on_connect_ports=465' /etc/exim4/exim4.conf.template > /tmp/exim4.conf.template
396
+  cp -f /tmp/exim4.conf.template /etc/exim4/exim4.conf.template
397
+
398
+  adduser $MY_USERNAME sasl
399
+  addgroup Debian-exim sasl
400
+  /etc/init.d/exim4 restart
401
+  mkdir -m 700 /etc/skel/Maildir
402
+  mkdir -m 700 /etc/skel/Maildir/Sent
403
+  mkdir -m 700 /etc/skel/Maildir/Sent/tmp
404
+  mkdir -m 700 /etc/skel/Maildir/Sent/cur
405
+  mkdir -m 700 /etc/skel/Maildir/Sent/new
406
+  mkdir -m 700 /etc/skel/Maildir/.learn-spam
407
+  mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
408
+  mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
409
+  mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
410
+  mkdir -m 700 /etc/skel/Maildir/.learn-ham
411
+  mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
412
+  mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
413
+  mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
414
+  ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
415
+  ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
416
+
417
+  if [ ! -d /home/$MY_USERNAME/Maildir ]; then
418
+    mkdir -m 700 /home/$MY_USERNAME/Maildir
419
+    mkdir -m 700 /home/$MY_USERNAME/Maildir/cur
420
+    mkdir -m 700 /home/$MY_USERNAME/Maildir/tmp
421
+    mkdir -m 700 /home/$MY_USERNAME/Maildir/new
422
+    mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent
423
+    mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/cur
424
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/tmp
425
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/new
426
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam
427
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/cur
428
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/new
429
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/tmp
430
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham
431
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/cur
432
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/new
433
+	mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/tmp
434
+	ln -s /home/$MY_USERNAME/Maildir/.learn-spam /home/$MY_USERNAME/Maildir/spam
435
+	ln -s /home/$MY_USERNAME/Maildir/.learn-ham /home/$MY_USERNAME/Maildir/ham
436
+	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
437
+  fi
438
+}
439
+
440
+function spam_filtering {
441
+  apt-get -y install spamassassin exim4-daemon-heavy
442
+  sed 's/ENABLED=0/ENABLED=1/g' /etc/default/spamassassin > /tmp/spamassassin
443
+  cp -f /tmp/spamassassin /etc/default/spamassassin
444
+  sed 's/# spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 783/g' /etc/exim4/exim4.conf.template > /tmp/exim4.conf.template
445
+  cp -f /tmp/exim4.conf.template /etc/exim4/exim4.conf.template
446
+  # This configuration is based on https://wiki.debian.org/DebianSpamAssassin
447
+  sed 's/local_parts = postmaster/local_parts = postmaster:abuse/g' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt > /tmp/30_exim4-config_check_rcpt
448
+  cp -f /tmp/30_exim4-config_check_rcpt /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
449
+  sed '/domains = +local_domains : +relay_to_domains/a\    set acl_m0 = rfcnames' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt > /tmp/30_exim4-config_check_rcpt
450
+  cp -f /tmp/30_exim4-config_check_rcpt /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
451
+  sed 's/accept/accept condition = ${if eq{$acl_m0}{rfcnames} {1}{0}}/g' /etc/exim4/conf.d/acl/40_exim4-config_check_data > /tmp/40_exim4-config_check_data
452
+  cp -f /tmp/40_exim4-config_check_data /etc/exim4/conf.d/acl/40_exim4-config_check_data
453
+  echo "warn  message = X-Spam-Score: $spam_score ($spam_bar)" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
454
+  echo "      spam = nobody:true" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
455
+  echo "warn  message = X-Spam-Flag: YES" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
456
+  echo "      spam = nobody" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
457
+  echo "warn  message = X-Spam-Report: $spam_report" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
458
+  echo "      spam = nobody" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
459
+  echo "# reject spam at high scores (> 12)" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
460
+  echo "deny  message = This message scored $spam_score spam points." >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
461
+  echo "      spam = nobody:true" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
462
+  echo "      condition = ${if >{$spam_score_int}{120}{1}{0}}" >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
463
+  # procmail configuration
464
+  echo "MAILDIR=$HOME/Maildir" > /home/$MY_USERNAME/.procmailrc
465
+  echo "DEFAULT=$MAILDIR/" >> /home/$MY_USERNAME/.procmailrc
466
+  echo "LOGFILE=$HOME/log/procmail.log" >> /home/$MY_USERNAME/.procmailrc
467
+  echo "LOGABSTRACT=all" >> /home/$MY_USERNAME/.procmailrc
468
+  echo "# get spamassassin to check emails" >> /home/$MY_USERNAME/.procmailrc
469
+  echo ":0fw: .spamassassin.lock" >> /home/$MY_USERNAME/.procmailrc
470
+  echo "  * < 256000" >> /home/$MY_USERNAME/.procmailrc
471
+  echo "| spamc" >> /home/$MY_USERNAME/.procmailrc
472
+  echo "# strong spam are discarded" >> /home/$MY_USERNAME/.procmailrc
473
+  echo ":0" >> /home/$MY_USERNAME/.procmailrc
474
+  echo "  * ^X-Spam-Level: \*\*\*\*\*\*" >> /home/$MY_USERNAME/.procmailrc
475
+  echo "/dev/null" >> /home/$MY_USERNAME/.procmailrc
476
+  echo "# weak spam are kept just in case - clear this out every now and then" >> /home/$MY_USERNAME/.procmailrc
477
+  echo ":0" >> /home/$MY_USERNAME/.procmailrc
478
+  echo "  * ^X-Spam-Level: \*\*\*\*\*" >> /home/$MY_USERNAME/.procmailrc
479
+  echo ".0-spam/" >> /home/$MY_USERNAME/.procmailrc
480
+  echo "# otherwise, marginal spam goes here for revision" >> /home/$MY_USERNAME/.procmailrc
481
+  echo ":0" >> /home/$MY_USERNAME/.procmailrc
482
+  echo "  * ^X-Spam-Level: \*\*" >> /home/$MY_USERNAME/.procmailrc
483
+  echo ".spam/" >> /home/$MY_USERNAME/.procmailrc
484
+  chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.procmailrc
485
+  # filtering scripts
486
+  echo "#!/bin/bash" > /usr/bin/filterspam
487
+  echo "USERNAME=$1" >> /usr/bin/filterspam
488
+  echo "MAILDIR=/home/$USERNAME/Maildir/.learn-spam" >> /usr/bin/filterspam
489
+  echo "if [ ! -d \"$MAILDIR\" ]; then" >> /usr/bin/filterspam
490
+  echo "    exit" >> /usr/bin/filterspam
491
+  echo "fi" >> /usr/bin/filterspam
492
+  echo "for f in `ls $MAILDIR/cur`" >> /usr/bin/filterspam
493
+  echo "do" >> /usr/bin/filterspam
494
+  echo "    spamc -L spam < \"$MAILDIR/cur/$f\" > /dev/null" >> /usr/bin/filterspam
495
+  echo "    rm \"$MAILDIR/cur/$f\"" >> /usr/bin/filterspam
496
+  echo "done" >> /usr/bin/filterspam
497
+  echo "for f in `ls $MAILDIR/new`" >> /usr/bin/filterspam
498
+  echo "do" >> /usr/bin/filterspam
499
+  echo "    spamc -L spam < \"$MAILDIR/new/$f\" > /dev/null" >> /usr/bin/filterspam
500
+  echo "    rm \"$MAILDIR/new/$f\"" >> /usr/bin/filterspam
501
+  echo "done" >> /usr/bin/filterspam
502
+
503
+  echo "#!/bin/bash" > /usr/bin/filterham
504
+  echo "USERNAME=$1" >> /usr/bin/filterham
505
+  echo "MAILDIR=/home/$USERNAME/Maildir/.learn-ham" >> /usr/bin/filterham
506
+  echo "if [ ! -d \"$MAILDIR\" ]; then" >> /usr/bin/filterham
507
+  echo "    exit" >> /usr/bin/filterham
508
+  echo "fi" >> /usr/bin/filterham
509
+  echo "for f in `ls $MAILDIR/cur`" >> /usr/bin/filterham
510
+  echo "do" >> /usr/bin/filterham
511
+  echo "    spamc -L ham < \"$MAILDIR/cur/$f\" > /dev/null" >> /usr/bin/filterham
512
+  echo "    rm \"$MAILDIR/cur/$f\"" >> /usr/bin/filterham
513
+  echo "done" >> /usr/bin/filterham
514
+  echo "for f in `ls $MAILDIR/new`" >> /usr/bin/filterham
515
+  echo "do" >> /usr/bin/filterham
516
+  echo "    spamc -L ham < \"$MAILDIR/new/$f\" > /dev/null" >> /usr/bin/filterham
517
+  echo "    rm \"$MAILDIR/new/$f\"" >> /usr/bin/filterham
518
+  echo "done" >> /usr/bin/filterham
519
+
520
+  echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam $MY_USERNAME" >> /etc/crontab
521
+  echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham $MY_USERNAME" >> /etc/crontab
522
+  chmod 655 /usr/bin/filterspam /usr/bin/filterham
523
+  service spamassassin restart
524
+  service exim4 restart
525
+  service cron restart
384 526
 }
385 527
 
386 528
 initial_setup
@@ -401,3 +543,4 @@ save_firewall_settings
401 543
 configure_internet_protocol
402 544
 script_to_make_self_signed_certificates
403 545
 configure_email
546
+spam_filtering