postfix part 7 - Setting up Mailwatch for Mailscanner/postfix



MailWatch for MailScanner is a open source or free web-based front-end to Mailscanner that use to displays the inbound/outbound mail queue, spam, viruses and blocked content on each page header. MailWatch has been written in PHP, MySQL and JpGraph. By using Mailwatch, it allows you to delete, release or run sa-learn across any messages that was quarantined. This post describes how to setup MailWatch on CentOS 6.3 and assumed that you already installed MailScanner and postfix.

1. Install required php and mysql :
[root@mx1 ~]# yum install httpdphpmysql-server mysqlphp-gdphp-mysql -y

2. Modify the php.ini :
[root@mx1 ~]# vim /etc/php.ini

PHP should have the following set in php.ini
short_open_tag = On
safe_mode = Off
register_globals = Off
magic_quotes_gpc = On
magic_quotes_runtime = Off
session.auto_start = 0

3. Download the latest version from mailwatch.sourceforge.net :
[root@mx1 ~]# wget http://sourceforge.net/projects/mailwatch/files/mailwatch/1.1.5.1/mailwatch-1.1.5.1.tar.gz

4. Extract downloaded mailwatchpackage :
[root@mx1 ~]# tar xzvf mailwatch-1.1.5.1.tar.gz

5. Start mysqlservice :
[root@mx1 ~]# servicemysqld start

6. Enter extracted mailwatch-x.xdirectory :
[root@mx1 mailwatch-1.1.5.1]# ls
CHANGELOG   fix_quarantine_permissions  LICENSEmailscanner               Remote_DB.txt  upgrade.php  USER_FILTERS
create.sql  INSTALLluserMailScanner_perl_scripts  tools          UPGRADING
[root@mx1 mailwatch-1.1.5.1]# mysql -p <create.sql

7. Create the database and import create.sql. The following commands below should be run as the ‘root’ :
[root@mx1 mailwatch-1.1.5.1]# mysql -p <create.sql
Enter password:

8. Login to mysql as a root :
[root@mx1 mailwatch-1.1.5.1]# mysql -u root -p
Enter password:


9. Proceed to create a MySQL user and then set password and configure MailScanner for SQL logging :
mysql> GRANT ALL ON mailscanner.* TO mailwatch@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT FILE ON *.* TO mailwatch@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mailscanner        |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)


10. Edit MailWatch.pm and change the database values accordingly :
a. Enter to the perl_scripts’sfolder :
[root@mx1 mailwatch-1.1.5.1]# cdMailScanner_perl_scripts
[root@mx1 MailScanner_perl_scripts]# pwd
/root/mailwatch-1.1.5.1/MailScanner_perl_scripts
b. Edit MailWatch.pm :
[root@mx1 MailScanner_perl_scripts]# vim MailWatch.pm
c.Modify this as necessary for your configuration
my($db_name) = 'mailscanner';
my($db_host) = 'localhost';
my($db_user) = 'mailwatch';
my($db_pass) = 'password';
11. Move MailWatch.pm to /usr/lib/MailScanner/MailScanner/CustomFunctions :
[root@mx1 MailScanner_perl_scripts]# cp MailWatch.pm /usr/lib/MailScanner/MailScanner/CustomFunctions


12. Create a MailWatch web user. This user will able to monitor the mailscanner through MailWatch web interface.
[root@mx1 ~]# mysqlmailscanner -u mailwatch -p
Enter password:

mysql>INSERT INTO users SET username = 'admin', password = md5('password'), fullname = 'MAilwatch Administrator', type ='A';
 
Query OK, 1 row affected (0.00 sec)

13. Install &Configure MailWatch :
a. Enter to mailwatch directory :
[root@mx1 ~]# cd mailwatch-1.1.5.1
b. Move mailscanner folder for web root folder. For apache, default root folder is /var/www/html :
[root@mx1 mailwatch-1.1.5.1]# mvmailscanner /var/www/html/
c. Enter to mailscanner folder in web root directory :
[root@mx1 ~]# cd /var/www/html/mailscanner

d. Verify and check the permissions of /var/www/html/mailscanner/images and /var/www/html/images/cache. The permissions and ownerships should be as below :
[root@mx1 mailscanner]# chownroot:apache images
[root@mx1 mailscanner]# chmodug+rwx images
[root@mx1 mailscanner]# chownroot:apache images/cache
[root@mx1 mailscanner]# chmodug+rwx images/cache
14. Create conf.php by copying conf.php.example. Edit the values to any details as you created earlier :
a. Copy the conf.php :
[root@mx1 mailscanner]# cpconf.php.exampleconf.php
b. Open conf.php :
[root@mx1 mailscanner]# vimconf.php
c. Edit the details as below :
define('DB_TYPE', 'mysql');
define('DB_USER', 'mailwatch');
define('DB_PASS', 'password');
define('DB_HOST', 'localhost');
define('DB_NAME', 'mailscanner');
15. Before setup the mailscanner, make sure it’s Stopped. Run 3 to 4 times to ensure the mailscanner completely stop. The status will FAILED if mailscanner completely stop.
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [FAILED]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
16. Edit /etc/MailScanner/MailScanner.conf
[root@mx1 ~]# vim /etc/MailScanner/MailScanner.conf
Make sure that the following options are set:
 Always Looked Up Last = &MailWatchLogging
 Detailed Spam Report = yes
 Quarantine Whole Message = yes
 Quarantine Whole Message As Queue Files = no
 Include Scores InSpamAssassin Report = yes
 Quarantine User = root
 Quarantine Group = apache (this should be the same group as your web server)
 Quarantine Permissions = 0660
17. Start MailScanner :
[root@mx1 ~]# serviceMailScanner start
Starting MailScanner daemons:
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
MailScanner:                                      [  OK  ]
18. Restart httpdservice :
[root@mx1 ~]# servicehttpd restart
19. Make sure all the related service such as httpd, mysql and MailScanner configured to start at boot :
[root@mx1 ~]# chkconfigmysqld on
[root@mx1 ~]# chkconfighttpd on
[root@mx1 ~]# chkconfigMailScanner on
[root@mx1 ~]# chkconfigspamassassin on
[root@mx1 ~]# chkconfig postfix on
20. Check the mail log.
[root@mx1 ~]# tail -f /var/log/maillog
Mar  5 22:14:42 mx1 MailScanner[1718]: Using locktype = flock
Mar  5 22:14:43 mx1 MailScanner[1697]: Requeue: C297BA1C3F.AA850 to E7373A1DD6
Mar  5 22:14:43 mx1 postfix/qmgr[1687]: E7373A1DD6: from=<root@mx1.ehowstuff.local>, size=609, nrcpt=1 (queue active)
Mar  5 22:14:43 mx1 MailScanner[1697]: Uninfected: Delivered 1 messages
Mar  5 22:14:43 mx1 MailScanner[1697]: Deleted 1 messages from processing-database
Mar  5 22:14:43 mx1 MailScanner[1697]: Logging message C297BA1C3F.AA850 to SQL
Mar  5 22:14:43 mx1 postfix/local[1768]: E7373A1DD6: to=<root@mx1.ehowstuff.local>, orig_to=, relay=local, delay=166894, delays=166894/0.13/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)
Mar  5 22:14:43 mx1 postfix/qmgr[1687]: E7373A1DD6: removed
Mar  5 22:56:25 mx1 postfix/postfix-script[1869]: fatal: the Postfix mail system is already running
Mar  5 23:01:08 mx1 update.bad.phishing.sites: Delaying cron job up to 600 seconds

21. Login to mailwatch web interface :



5.9.240.232/mailscanner
 
                                 Solution   if you get error !!!  :-                   
Please verify read permissions on /var/spool/postfix/hold and /var/spool/postfix/incoming
Do-check permissions

sudo chown postfix:apache /var/spool/postfix/incoming
sudo chown postfix:apache /var/spool/postfix/hold
sudo chmod 740 /var/spool/postfix/incoming
sudo chmod 740 /var/spool/postfix/hold


cd /var/spool/MailScanner/

chown -R postfix.clam *
chmod -R 750 *

# ls -ltrh

total 12K
drwxr-x---  2 postfix  clam   4.0K Jul 16 06:11 spamassassin
drwxr-x--- 14 postfix  apache 4.0K Aug  5 01:58 quarantine
drwxr-x---  9 postfix  clam   4.0K Aug  5 01:59 incoming


For ubuntu 14.04LTS
# ls -l /var/spool/MailScanner
total 16
drwxrwx---  2 postfix clamav   4096 Apr  6 16:24 archive
drwxrwx--- 29 postfix clamav   4096 Jun  1 12:32 incoming
drwxr-x---  4 postfix www-data 4096 May 28 16:33 quarantine
drwxr-x---  2 postfix clamav   4096 Apr 12 01:39 spamassassin



http://www.netmium.com.au/category/how-tos/

Postfix ip rotation

[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.180
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.181
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.182
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.183
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.184
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.185
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.186

for 7 ip address 180-186
change --> every _#num of ip__

md5sum check compare

# md5sum  file_A file_B

lkjsdf98sd7fsdkjfnsdf98s7d    file_A
joiuiuyiuwe7weiury8iujsdCj    file_B      
 = = =  = = = = = = =  = = = = =   = = =  =
To check /verify the md5sum comparision
= = = = ==  = = =  == = =  = = =  = =  = =
# md5sum  file_A file_B  > md5summary.file


#md5sum -c md5summary.file

file_A:  OK
file_B:  OK

displays ok if md5sum matches.

Linux boot process and Grub2 Fundas

Highlevel boot stages:-

  1. The machine’s BIOS or boot firmware loads and runs a boot loader.
  2. The boot loader finds the kernel image on disk, loads kernel into memory and starts it. 
  3. The kernel initializes the devices and its drivers. 
  4. The kernel mounts the root filesystem.
  5. The kernel starts a program called init with a process ID of 1. This point is the user space start.
  6. init sets the rest of the system processes in motion. 
  7. init starts a process allowing you to log in, usually at the end or near the end of the boot sequence.

Running journalctl -k displays the messages from the current boot, but you can view previous boots with the -b

grub2 supports various filesystems like Linux ext2/ext3/ext4, LVM ,btrfs, zfs etc.(reference) with the help of its own drivers. GRUB2 disk drivers are essential for the boot loader's functionality. They allow GRUB2 to access configuration files, such as the grub.cfg file, which contains important boot configuration parameters. Additionally, the disk drivers enable GRUB2 to locate and load the kernel image, initial RAM disk (initrd), and any other necessary boot files.

To determine if your system uses a BIOS or UEFI, run command efibootmgr. If you get a list of boot targets, your system has UEFI otherwise its bios.

GRUB2 uses its own set of drivers to enable communication with various hardware components during the boot process. These drivers are specifically designed for GRUB and are responsible for tasks such as reading the filesystem, accessing storage devices, and interacting with input/output devices. GRUB2 drivers are typically lightweight and have limited functionality compared to the drivers used by the kernel.

  1. Power-On: When the power button is pressed, the system's power supply is activated, and the firmware (UEFI or BIOS) initializes the hardware components.
  2. Firmware Initialization: The firmware performs a Power-On Self-Test (POST) to check the hardware components' functionality, such as the CPU, memory, storage devices, and peripherals. It also initializes system buses and interfaces.
  3. Boot Firmware: If the system uses UEFI firmware, the UEFI firmware takes control. It loads UEFI drivers, initializes hardware, and prepares the system for the boot process. If the system uses legacy BIOS, the BIOS performs similar tasks.
  4. Bootloader: The bootloader, usually GRUB2 (Grand Unified Bootloader), is loaded. GRUB2 presents a boot menu to the user if multiple operating systems are installed. The user can select the desired entry, or the default entry is automatically booted.
  5. Kernel Loading: The bootloader locates and loads the Linux kernel (vmlinuz) into memory. The kernel is the core of the operating system that manages hardware resources, provides system services, and initializes essential components.
  6. Initial RAM Disk (initrd): The bootloader also loads an initial RAM disk (initrd or initramfs) into memory. The initrd contains essential modules, drivers, and scripts required for early system initialization. It allows the kernel to access necessary drivers and file systems to mount the root file system.
  7. Kernel Initialization: The kernel is decompressed and starts executing. It initializes the system by setting up various components, such as the memory manager, CPU scheduler, device drivers,  and file systems.
  8. udev: The kernel starts udev (userspace device manager), which detects and configures hardware devices in the system. udev assigns device names (like /dev/sda for storage devices) and loads the necessary device drivers.
  9. Mounting the Root File System: The kernel mounts the root file system, which contains the main Ubuntu installation. The root file system can be on a variety of storage devices, such as hard drives, solid-state drives, or network-mounted storage.
  10. Init System: The init system is started, which is responsible for initializing user-space processes and managing system services. In modern distro, the default init system is systemd. The init system executes a series of startup scripts and starts essential system services.
  11. User Space Initialization: Once the init system completes its tasks, user-space processes are started, including essential system daemons and services. These processes provide various functionalities, such as networking, logging, time synchronization, and graphical interface management (if a desktop environment is installed).
  12. Login Prompt or Graphical Display Manager: Finally, the system is ready to present a login prompt in the console or a graphical login screen through a display manager