postfix header check

HEADER CHECKS
The first thing that needs to be done is to enable header checks in the Postfix main.cf configuration file. This will tell postfix where to look for the header checks file.
To do this, add the following lines to main.cf:
header_checks = regexp:/etc/postfix/maps/header_checks
mime_header_checks = regexp:/etc/postfix/maps/mime_header_checks

If you are using pcre instead of regexp, you will use:
header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks

The format for each line in the header_checks file is as follows:
/^HEADER: .*content_to_act_on/ ACTION
The HEADER listed can be any header available in an email. The Subject header is the most popular to reject on for key words or phrases in spam filtering, but others can be very useful as well. The X-Mailer header can be used to identify some software or mail clients that are used almost exclusively for spam. Please see the last version of the header checks file for more examples of header checks.
The content to act on is preceded by a .* which specifies that it doesn’t matter what characters were before the content to act on.
The ACTION that will be taken has a number of options available:
REJECT is the most common, and this will cause the email to be rejected by Postfix. In this case, the incoming email will be blocked before it can enter your server. As an option, you can add text after the work REJECT, whereas that text will appear in both your log and the bounce message to the sender of the email. It is a good practice to number your lines in any checks file, as you may sometimes have difficulty identifying which rule caused a particular email to be rejected. A sample reject is as follows:
/^Subject .*Free Money/ REJECT Spam Header Rule #42
This will cause any email that has the words “Free Money” in the subject line to be rejected. The bounce message to the sender and your mail log will both have the text “Spam Header Rule #42” in them. This will allow you to more efficiently find what rule is causing problems or false rejects.
IGNORE will cause that particular header to be removed from the email, and will continue to process the email as normal. This can be useful in some situations. Please seethe Header Removal Guide for more information.
WARN can be very useful when testing new spam filters. An entry will be made in your mail log with a warning on the header, as well as any text that you place after the word “WARN” like with REJECT. It is often advisable to test new filters for a day or two with WARN before implementing them in production. This especially applies to complex rules that could easily have errors.
HOLD will hold the email in a hold queue, so that the system administrator can later take action (delete or release the email).
DISCARD will cause the sending server to think that the email was sent properly, but your Postfix server will silently discard (delete) the email. This option is for instances where you don’t want the remote person or server to know that the email was deleted.
FILTER will allow you to specify another instance of postfix, filter, or server where to send the email. After the word FILTER, you will add an entry like in the transport map file of transport:nexthop. Please see the transport map documentation for more information.
As spammers have become a lot more devious in finding ways to slip their emails past filters, header_checks has become a lot more useful in defining complex filtering schemes. Following are a few examples.
/^Subject: .*        / REJECT Spam Header Many Spaces 1
In this example, any subject with more than eight spaces will be rejected. In normal circumstances, there are very few reasons for someone to put eight spaces in a subject. Many automates spam sending tools and systems will add spaces at the end of a subject, and then place a code identifying the message or some other details.
/^Date: .* 200[0-2]/ REJECT Spam Header Past Date 1
/^Date: .* 19[0-9][0-9]/ REJECT Spam Header Past Date 2

These two examples will reject emails that appear to have been sent in the past (it is currently 2003 as of the time of this writing). Many spammers use dates far in the past (or the future) to make their emails appear at the top of your list.
/^Subject: .*f[ _\.\*\-]+r[ _\.\*\-]+e[ _\.\*\-]+e/ REJECT Hidden Word 1
This example shows how some spammers use different characters in between words to slip their messages past filters. In this example, the word “free” can be disguised with various characters in between the letters, and the header check will still reject it.
MIME HEADER CHECKS
In the mime_header_checks file, you will place a restriction for any file extentsons that you do not want to have passing through your system. For example:
/name=[^>]*\.(bat|com|exe)/ REJECT
This will reject any messages that have attachments whose files end in .bat, .com, or .exe. There are many more file extensions that can be considered dangerous. Please see the latest mime_header_checks file for more information.
You will have to deal with false rejects now and again. Either when users complain that they are not getting email, or when in looking at the mail logs you find that there are apparently valid emails being rejected. In this case, it should not be difficult to find the culprit rule, as you’ve added a rule number to the end of the reject string.
As you can see, header checks are not just about the words in the subject. They can be detailed and granular enough to catch even the strangest spam headers.

postfix header check

HEADER CHECKS
The first thing that needs to be done is to enable header checks in the Postfix main.cf configuration file. This will tell postfix where to look for the header checks file.
To do this, add the following lines to main.cf:
header_checks = regexp:/etc/postfix/maps/header_checks
mime_header_checks = regexp:/etc/postfix/maps/mime_header_checks

If you are using pcre instead of regexp, you will use:
header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks

The format for each line in the header_checks file is as follows:
/^HEADER: .*content_to_act_on/ ACTION
The HEADER listed can be any header available in an email. The Subject header is the most popular to reject on for key words or phrases in spam filtering, but others can be very useful as well. The X-Mailer header can be used to identify some software or mail clients that are used almost exclusively for spam. Please see the last version of the header checks file for more examples of header checks.
The content to act on is preceded by a .* which specifies that it doesn’t matter what characters were before the content to act on.
The ACTION that will be taken has a number of options available:
REJECT is the most common, and this will cause the email to be rejected by Postfix. In this case, the incoming email will be blocked before it can enter your server. As an option, you can add text after the work REJECT, whereas that text will appear in both your log and the bounce message to the sender of the email. It is a good practice to number your lines in any checks file, as you may sometimes have difficulty identifying which rule caused a particular email to be rejected. A sample reject is as follows:
/^Subject .*Free Money/ REJECT Spam Header Rule #42
This will cause any email that has the words “Free Money” in the subject line to be rejected. The bounce message to the sender and your mail log will both have the text “Spam Header Rule #42” in them. This will allow you to more efficiently find what rule is causing problems or false rejects.
IGNORE will cause that particular header to be removed from the email, and will continue to process the email as normal. This can be useful in some situations. Please seethe Header Removal Guide for more information.
WARN can be very useful when testing new spam filters. An entry will be made in your mail log with a warning on the header, as well as any text that you place after the word “WARN” like with REJECT. It is often advisable to test new filters for a day or two with WARN before implementing them in production. This especially applies to complex rules that could easily have errors.
HOLD will hold the email in a hold queue, so that the system administrator can later take action (delete or release the email).
DISCARD will cause the sending server to think that the email was sent properly, but your Postfix server will silently discard (delete) the email. This option is for instances where you don’t want the remote person or server to know that the email was deleted.
FILTER will allow you to specify another instance of postfix, filter, or server where to send the email. After the word FILTER, you will add an entry like in the transport map file of transport:nexthop. Please see the transport map documentation for more information.
As spammers have become a lot more devious in finding ways to slip their emails past filters, header_checks has become a lot more useful in defining complex filtering schemes. Following are a few examples.
/^Subject: .*        / REJECT Spam Header Many Spaces 1
In this example, any subject with more than eight spaces will be rejected. In normal circumstances, there are very few reasons for someone to put eight spaces in a subject. Many automates spam sending tools and systems will add spaces at the end of a subject, and then place a code identifying the message or some other details.
/^Date: .* 200[0-2]/ REJECT Spam Header Past Date 1
/^Date: .* 19[0-9][0-9]/ REJECT Spam Header Past Date 2

These two examples will reject emails that appear to have been sent in the past (it is currently 2003 as of the time of this writing). Many spammers use dates far in the past (or the future) to make their emails appear at the top of your list.
/^Subject: .*f[ _\.\*\-]+r[ _\.\*\-]+e[ _\.\*\-]+e/ REJECT Hidden Word 1
This example shows how some spammers use different characters in between words to slip their messages past filters. In this example, the word “free” can be disguised with various characters in between the letters, and the header check will still reject it.
MIME HEADER CHECKS
In the mime_header_checks file, you will place a restriction for any file extentsons that you do not want to have passing through your system. For example:
/name=[^>]*\.(bat|com|exe)/ REJECT
This will reject any messages that have attachments whose files end in .bat, .com, or .exe. There are many more file extensions that can be considered dangerous. Please see the latest mime_header_checks file for more information.
You will have to deal with false rejects now and again. Either when users complain that they are not getting email, or when in looking at the mail logs you find that there are apparently valid emails being rejected. In this case, it should not be difficult to find the culprit rule, as you’ve added a rule number to the end of the reject string.
As you can see, header checks are not just about the words in the subject. They can be detailed and granular enough to catch even the strangest spam headers.

apt gpg key error on ubuntu 14.04.3

solution 1
==============
 # apt-get clean
 # cd /var/lib/apt
 # mv lists lists.old
 # mkdir -p lists/partial
 # apt-get clean
 # apt-get update

solution 2
===============
Run below script
===============
 #!/bin/bash

OLDIFS=$IFS
IFS=$'\n'

lines=`sudo apt-get update 2>&1 | grep "NO_PUBKEY"`

for line in $lines
do

        key=`echo $line | tail --bytes=17`

        sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key

        SOMETHINGDONE="true"

done

IFS=$OLDIFS

if [ $SOMETHINGDONE ]
then
        sudo apt-get update
fi

PYCURL ERROR Couldnt resolve proxy

Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was
14: PYCURL ERROR 5 - "Couldn't resolve proxy 'fe80::1%eth0]'"
Error: Cannot find a valid baseurl for repo: base

Solution:-

use   the below commands to see if any http variables are set

set | grep -i http
env | grep  -i http

# http_proxy='http://[fe80::1%eth0]:13128'
# unset http_proxy

problem resolved

Install Scrapy on Ubuntu 16.04 LTS

# Install dependencies

apt-get install -y libffi-dev
apt-get install libssl-dev
apt-get install  python-pip

# Install scrapy

pip install scrapy

grant create modify create procedure routines on linux

grant alter routine,create routine, execute on *.* to 'testuser'@'%' ;

mysql ndb cluster setup notes

Setup Overview

MySQL Cluster has one or more of several major components. Typically each component will have its own server (a node). Those components are

    sql node(front-end)
    data node (back-end)
    management node (central config,meta-data and etc)

Generally speaking, application requests are sent to the SQL nodes, which then talk to the data nodes and coordinates each other via management node(s) to actually recover the content you want.
For redundancy you need at least two data nodes.

MGM Node -  holds the configuration for MySQL Cluster in a file called config.ini. It also writes a cluster log, and takes part in arbitration to prevent split-brain or network partitioning.
You are recommended to have two MGM Nodes for redundancy. Since MGM hardly use any resources, and is not involved in query processing or routing of requests, it can be colocated with the SQL Nodes/Access Nodes.

SQL Node / Access Node - the most common way to read/write data to the Data Nodes is by using the MySQL Server (aka SQL Node). A query comes into the SQL Node. The SQL Node parses, optimizes and executes the query on the Data Nodes.You need at least two SQL Nodes for redundancy. Nodes in the access layer should have fast CPUs, disks are not important, fast network to the data nodes (same specs as for the data nodes), and about 2+ GB of RAM (depending on the number of connections, per thread buffers etc). Do not co-locate the SQL Nodes/Access Nodes with the Data Nodes.

Data nodes usually operate in pairs, so the number of data nodes would be two, four, six, etc. The data nodes should have many cores, fast cores, enough RAM to store your data, and fast disks.Distributing Data Nodes that belong to one cluster over WAN is generally not recommended, unless the WAN connection is very stable and the latency is very low (at most a few milliseconds). 

Note:- All cluster nodes are using centos 6.7 x64bit


Node Configuration

management node = 10.10.10.10

sql-node1= 10.10.10.20

sql-node2= 10.10.10.21

data-node1= 10.10.10.30

data-node2 = 10.10.10.31


                                 apache/php webserver
              _________________|_________________
            ||                                                                   ||
   Mgmt|Data|SQLnode                                   Data || SQLnode

   Let’s begin by disabling SELinux on all nodes.

   On management node:-


   iptables -A INPUT -p tcp --dport 1186 -j ACCEPT

   Download the MySQL cluster packages:-

   wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.3/MySQL-Cluster-gpl-7.3.12-1.el6.x86_64.rpm-bundle.tar  [New GA release might be available]

   [Download the latest GA version]

   tar xvf MySQL*.tar

   Install MySQL cluster server package:-[on all nodes]

   yum install libaio numactl perl-Class-MethodMaker rsync wget vim openssh-server -y
   yum remove -y mysql-libs

wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-server-gpl-7.4.11-1.el6.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-shared-compat-gpl-7.4.11-1.el6.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-client-gpl-7.4.11-1.el6.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.11-1.el6.x86_64.rpm
rpm -Uvh MySQL-Cluster-client-gpl-7.4.11-1.el6.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-compat-gpl-7.4.11-1.el6.x86_64.rpm

    install MySQL-Cluster-server-gpl-xxx on management node

   rpm -Uvh MySQL-Cluster-server-gpl-7.3.6-2.el6.x86_64.rpm

- create config.ini for initiating cluster nodes
- Recommeded way to Configure and deploy production-class database clusters for MySQL
- http://severalnines.com/cluster-configurator/

vim config.ini

[tcp default]
SendBufferMemory=128M
ReceiveBufferMemory=128M

[ndb_mgmd]
NodeId=10
hostname=100.126.1.101
datadir=/var/lib/mycluster

[ndbd default]
NoOfReplicas=2
LockPagesInMainMemory=1
DataMemory=10165M
IndexMemory=1271M
ServerPort=2202
ODirect=1
    #CompressedLCP=1
    #CompressedBackup=1
    #table related things

MaxNoOfConcurrentOperations=100000
MaxNoOfConcurrentTransactions=16384

StringMemory=25
MaxNoOfTables=4096
MaxNoOfAttributes=24756
MaxNoOfOrderedIndexes=2048
MaxNoOfUniqueHashIndexes=512
TimeBetweenLocalCheckpoints=30
    ### Params for BACKUP
BackupMaxWriteSize=1M
BackupDataBufferSize=24M
BackupLogBufferSize=16M
BackupMemory=40M

FragmentLogFileSize=256M
InitFragmentLogFiles=SPARSE
NoOfFragmentLogFiles=40
RedoBuffer=64M

TransactionBufferMemory=8M

TimeBetweenGlobalCheckpoints=1000
TimeBetweenEpochs=100

TimeBetweenEpochsTimeout=0

    ### Watchdog
TimeBetweenWatchdogCheckInitial=60000
    ### TransactionInactiveTimeout  - should be enabled in Production
TransactionInactiveTimeout=60000
    ### New 7.1.10 redo logging parameters
RedoOverCommitCounter=3
RedoOverCommitLimit=20

    ### DISK DATA
SharedGlobalMemory=20M
DiskPageBufferMemory=64M
BatchSizePerLocalScan=512
[ndbd]
NodeId=20
hostname=202.94.66.36
datadir=/var/lib/mycluster-data
     #BackupDataDir=/dir/to/backup

[ndbd]
NodeId=30
hostname=202.94.66.49
datadir=/var/lib/mycluster-data
    #BackupDataDir=/dir/to/backup

[mysqld]
NodeId=40
hostname=202.94.66.44

[mysqld]
NodeId=50
"config.ini" 90L, 1510C written
[root@mgmtsql ~]# cat config.ini
[tcp default]
SendBufferMemory=128M
ReceiveBufferMemory=128M

[ndb_mgmd]
NodeId=10
hostname=100.126.1.101
datadir=/var/lib/mycluster

[ndbd default]
NoOfReplicas=2
LockPagesInMainMemory=1
DataMemory=10165M
IndexMemory=1271M
ServerPort=2202
ODirect=1
    #CompressedLCP=1
    #CompressedBackup=1
    #table related things

MaxNoOfConcurrentOperations=100000
MaxNoOfConcurrentTransactions=16384

StringMemory=25
MaxNoOfTables=4096
MaxNoOfAttributes=24756
MaxNoOfOrderedIndexes=2048
MaxNoOfUniqueHashIndexes=512
TimeBetweenLocalCheckpoints=30
    ### Params for BACKUP
BackupMaxWriteSize=1M
BackupDataBufferSize=24M
BackupLogBufferSize=16M
BackupMemory=40M

FragmentLogFileSize=256M
InitFragmentLogFiles=SPARSE
NoOfFragmentLogFiles=40
RedoBuffer=64M

TransactionBufferMemory=8M

TimeBetweenGlobalCheckpoints=1000
TimeBetweenEpochs=100

TimeBetweenEpochsTimeout=0

    ### Watchdog
TimeBetweenWatchdogCheckInitial=60000
    ### TransactionInactiveTimeout  - should be enabled in Production
TransactionInactiveTimeout=60000
    ### New 7.1.10 redo logging parameters
RedoOverCommitCounter=3
RedoOverCommitLimit=20

    ### DISK DATA
SharedGlobalMemory=20M
DiskPageBufferMemory=64M
BatchSizePerLocalScan=512
[ndbd]
NodeId=20
hostname=202.94.66.36
datadir=/var/lib/mycluster-data
    #BackupDataDir=/dir/to/backup

[ndbd]
NodeId=30
hostname=202.94.66.49
datadir=/var/lib/mycluster-data
    #BackupDataDir=/dir/to/backup

[mysqld]
NodeId=40
hostname=202.94.66.44

[mysqld]
NodeId=50
hostname=202.94.66.45

[mysqld]            # this is kept empty for MySQL Cluster Native Backup Tool

[mysqld]            # this is kept empty for MySQL Cluster Native Backup Tool

    #empty api slots for multiple ndb cluster connection pool
    #for more info - https://dev.mysql.com/doc/mysql-cluster-excerpt/5.5/en/mysql-cluster-program-options-mysqld.html#option_mysqld_ndb-cluster-connection-pool

[api]

[api]

[api]

[api]


On Data Nodes [ run on both (2) data nodes ]


Download and extract the Mysql cluster rpm's and install below package
 
  yum install libaio numactl -y
  yum install perl-Class-MethodMaker    #needed for running perl scripts provided by mysqlcluster
  yum remove -y mysql-libs

  rpm -Uvh MySQL-Cluster-server-gpl-7.3.6-2.el6.x86_64.rpm


vim /etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=10.10.10.10

[mysql_cluster]
ndb-connectstring=10.10.10.10


Configure SQL Nodes[run on both of the 2 nodes]


Download and extract the Mysql cluster rpm's and install below package
 
  yum install libaio numactl -y
  yum install perl-Class-MethodMaker    #needed for running perl scripts provided by mysqlcluster
  yum remove -y mysql-libs

  rpm -Uvh  MySQL-Cluster-server-gpl-7.3.6-2.el6.x86_64.rpm
  rpm -Uvh  MySQL-Cluster-shared-compat-gpl-7.3.6-2.el6.x86_64.rpm
  rpm -Uvh  MySQL-Cluster-client-gpl-7.3.6-2.el6.x86_64.rpm

  vim /etc/my.cnf

  [mysqld]
ndbcluster
default-storage-engine=NDBCLUSTER
net_read_timeout=60000
connect_timeout=60000
max_allowed_packet=32M
max_connections=1000
query_cache_type=1
query_cache_size=37748736
query_cache_limit=2097152
ndb-cluster-connection-pool=2
slow-query-log=1
slow-query-log-file=/var/log/mysql/slowquery.log
long-query_time=2
log-queries-not-using-indexes
[mysql_cluster]
ndb-connectstring=10.10.10.10

Run mysql with below command to change mysql root password

   mysqld_safe &

your default root password is already set during installation and is stored in /root/.mysql_secret , copy it and use in next step
run below command to change root password and have recommended settings suggested during the process

# mysql_secure_installation

After setting the root password kill the mysql process

Starting the cluster first time
===============================

#on management node [10.10.10.10]:-

ndb_mgmd --config-file /root/config.ini  --config-dir /usr/mysql-cluster --initial

#on Data nodes [10.10.10.20-21]

ndbd --initial

#on SQL nodes [10.10.10.30-31]

service mysql start


# On any one of the SQL node
# Create database on any one of the node or import existing DB

The SQL engine will need to be set to ndbcluster. If you are importing an existing database, export it using mysqldump, then perform the following commands.


vim YourDB.sql

:%s/engine=InnoDB/engine=ndbcluster/g
   
:%s/engine=MyISAM/engine=ndbcluster/g
    

mysql -uroot -p [YourDB] < YourDB.sql

Enable remote mysql user to use YourDB database [Run on both SQL node]

mysql> GRANT ALL ON YourDB.* TO remoteuser@'202.54.10.20' IDENTIFIED BY 'PA$$WORD123';
mysql> flush privileges;








mount usb pendrive linux with read write privilege

To enable everyone rw access, the key is umask=0 option to mount command.

sudo mount -o umask=0,uid=nobody,gid=nobody /dev/something /mnt/somewhere

umask=0 is enough, uid and gid just for sake of clarity, so you don't see more 'root' owners than necessarily.

specify port for rsync

ubuntu 14.04.4
rsync  version 3.1.0

rsync -rvz -e 'ssh -p 2222' --progress --remove-sent-files ./dir user@host:/path
 
 
rsync --progress -avz -e 'ssh -p 44022' user1@100.126.1.106:/remoteshared /local/dir_A

mysql 5.5 install error on ubuntu 14.04.4 libdbi error hashsum mismatch

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libd/libdbi-perl/libdbi-perl_1.630-1_amd64.deb  Hash Sum mismatch


download libdbi...deb file from here
http://packages.ubuntu.com/trusty/amd64/libdbi-perl/download
or
http://cz.archive.ubuntu.com/ubuntu/pool/main/libd/libdbi-perl/libdbi-perl_1.630-1_amd64.deb

dpkg -i libdbi-perl_1.630-1_amd64.deb
apt-get install mysql-server