Excessive mail sent by an user alert for cPanel

If you need a simple script to alert you by mail when a user exceeds a predefined mail rate limit, then check this out.

========================================================================

1# mailflag=0
2# limit=5
3# mailid=mailaddresshere
4# chkdate=`date -d “60 minute ago” +%Y-%m-%d\ %k`
5# #chkdate=2009-11-10
6# mailfile=$(mktemp)
7# for i in `mysql –batch –skip-column-names -e ” use eximstats; select user,email,msgid from sends where \
8# mailtime like ‘$chkdate%’;” | awk ‘{print $1}’ | sort | uniq -c | sort -n | sed ’s/^ *//’| sed ’s/ /:/’`
9# do
10# k=`echo $i | cut -d ‘:’ -f1`
11# username=`echo $i | cut -d ‘:’ -f2`
12i# f [ "$k" -gt "$limit" ]
13# then
14# mailflag=1
15# echo -e “\n\n\n Excessive mail sent by user : $username \n\n” >> $mailfile
16# echo -e “==============================================================
===========” >> $mailfile
17# echo “ mailtime msgid email processed user size ip auth” >> $mailfile
18# mysql –batch –skip-column-names -e ” use eximstats; select * from sends where mailtime like ‘$chkdate%’ and \
19# user like ‘$username’;” >> $mailfile
20# echo -e “===============================================================
========” >> $mailfile
21# fi
21# done
22# if [ "$mailflag" == 1 ]
23# then
24# cat $mailfile | mail -s “Excessive mail sent by user” $mailid
25# fi
26# rm -rf $mailfile
==========================================================================

You need to edit the limit and mailid variables according to your requirement.
eg:
limit=300
mailid=test@live.com

Suggestions, questions are welcome.

/var patition full ? How to change Mysql database directory to another partition in cPanel ?

Hi guys,

you might have faced the issue of /var partition gettting full regularly due to database directory. If you have a larger partition with free space, then it is possible to move the database directory to the larger partition.

Here are the steps

Switch off the database server while we are moving the databases.

/etc/rc.d/init.d/mysql stop

I am considering that I have enough space in /home partition. Here goes my new database data directory as /home/mysql

Now it is better to copy the database first, rather than move.

cp -pr /var/lib/mysql /home
mv /var/lib/mysql /var/lib/mysql-bk

We are copying the database to the new location since it is better to revert back the settings with minimum downtime, if anything goes wrong.

move to /tmp

cd /tmp
unlink mysql.sock
ln -s /home/mysql/mysql.sock /tmp/mysql.sock

Take a backup of /etc/my.cnf

Now edit /etc/my.cnf

vi /etc/my.cnf

add the line
datadir=/home/mysql

If the socket file is specified, comment it out.

Now move to /var/lib/mysql and create a symblink

ln -s /home/mysql /var/lib/mysql

(Please note that you don’t specify the socket file location in my.cnf since it causes issues with phpMyadmin)

For, cPanel server, edit the phpMyadmin configuration
take a backup of “/usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php”

edit this file /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php
vi /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php

add the following lines. If they already exist, edit as below.
(the connect_type usually exist at “tcp” change it to “socket”)

$cfg['Servers'][$i]['socket'] = ‘/home/mysql/mysql.sock’;
$cfg['Servers'][$i]['connect_type'] = ’socket’;

Now start the database server.

/etc/rc.d/ini.d/mysql start

If it starts fine, you are done. Check the database connections of your site.
You can now remove the directory /var/lib/mysql-bk

Suggestions, questions are welcome.

cPanel shows wrong quota for database.

Getting 0.00MB disk quota for databases in cpanel ?

Here is the answer ::

The disk quota for MySQL databases will show 0.00 in cPanel > MySQL Databases area unless this option is selected in WHM's Tweak Settings area:
------------------------
When displaying disk usage in cPanel/WHM include Postgresql and MySQL® disk usage. [Requires MySQL® 5+] (SQL disk usage is only updated every four hours)
------------------------

So go ahead and enable this in Tweak Settings, then manually run the command to update the quotas:

/scripts/update_db_cache

This command will run by cron every 4 hours now that the Tweak Settings option has been enabled.

Thanks

You need to install the LWP perl module (libwww-perl) and then install csf

On installing csf firewall, got following error.

[root@server22 csf]# sh install.sh

Configuring for OS

Checking for perl modulesfailed
You need to install the LWP perl module (libwww-perl) and then install csf
[root@server22 csf]#

To fix the error, install libwww-perl

yum install perl-libwww-perl

That's it!!

Upgrading PHP4 to PHP5 pn directadmin server.

To update to php5, the build script will still work. All that you need to do is swap out the version, compile normally and make a few modifications to your /etc/httpd/conf/httpd.conf file.

1) download the php-5.2.4.tar.gz from php.net into your customapache directory:

cd /usr/local/directadmin/customapache
wget http://files.directadmin.com/services/customapache/php-5.2.4.tar.gz

2) change your build script for the new version:

nano build
change: PHP_VER=4.4.4
to: PHP_VER=5.2.4

3) build php normally:

./build clean
./build php n
If you're using apache 2.x, use

./build clean
./build php_ap2 n
instead.

4) edit /etc/httpd/conf/httpd.conf
Remove any referce of:

LoadModule php4_module modules/libphp4.so

and make sure they're replaced with:

LoadModule php5_module modules/libphp5.so

Remove any reference of:

AddModule mod_php4.c
and replace with:

AddModule mod_php5.c


5) find this piece of code:


DirectoryIndex index.html index.htm index.shtml index.php index.php4 index.php3 index.phtml index.cgi


replace with:


DirectoryIndex index.html index.htm index.shtml index.php index.php4 index.php5 index.php3 index.phtml index.cgi


Find this:


AddType application/x-httpd-php .inc .php .php4 .php3 .phtml
AddType application/x-httpd-php-source .phps

(it might have AddHandler instead of AddType)
replace with:


AddHandler application/x-httpd-php .inc .php .php5 .php4 .php3 .phtml
AddHandler application/x-httpd-php-source .phps

Then restart apache.

If you get the following error while compiling php:

checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2
installation.

*** There was an error while trying to configure php. Check the configure.php file
Then edit the configure.php file (or configure.php_ap2 if you're using apache 2), and change:

--with-xml \
to:

--disable-libxml \
--disable-dom \
--disable-xml \
--disable-simplexml \
--disable-xmlreader \
--disable-xmlwriter \
or else install the missing rpms/packages for xml. (libxml2-dev and libxml2-utils on debian). Redhats:

yum -y install libxml2-devel libxslt-devel
FreeBSD:

pkg_add -r libxml2
pkg_add -r libxslt
On debian systems if using apt-get to install libxml2-dev and libxml2-utils doesn't work, then install from source:

wget http://files.directadmin.com/services/customapache/libxml2-2.6.30.tar.gz
tar xvzf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure
make && make install
then recompile php as usual.

Note: If you want the latest version of php and apache, it's recommended you use custombuild:
http://files.directadmin.com/services/custombuild/1.1

The Above guide is only to be used if if you still want to use the old apache versions... basically, only if you still need FrontPage.

Apache interneal dummy connections for localhost (127.0.0.1 - - [] "OPTIONS * HTTP/1.0" 200 -)

For anyone interested in this, here's what I did:

1 -- Backed up the httpd.conf file.

2 -- Pico-ed into the httpd.conf file and scrolled down to the LogFormat section.

3 -- You will see a section that starts with this:


LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

CustomLog logs/access_log common

Just change the CustomLog line, and enter a new line just above it. So your final will look like this:



LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

SetEnvIf Remote_Addr "127\.0\.0\.1" exclude_from_log
CustomLog logs/access_log common env=!exclude_from_log



4 -- Restart Apache and now you should see no such entires when tailing /usr/local/apache/logs/access_log

Please note, that on one of our servers I had to use the following line instead, because the localhost entries were starting with ::1 rather than 127.0.0.1

SetEnvIf Remote_Addr "\:\:1" exclude_from_log

Also note ---> If you try this and it screws something up (it shouldn't), I take absolutely no responsibility. Again, be sure to backup your httpd.conf file before doing ANY work with this.

This removed the entries from the whm apache status as well as the logs.
Its nice not having the logs so large for something so silly.

Thank You.

Here are some useful links regarding this post:
http://forums.cpanel.net/f5/apache-strange-request-78449.html
http://www.linuxquestions.org/questions/linux-software-2/apache-...-internal-dummy-connection-506054/

AntiDOS Configuration in APF on cPanel web server

It is assumed that you have already installed APF (Advanced policy firewall) on your cPanel dedicated web server. Once, APF is installed do the following:

Edit the antidos configuration file of APF with the command:

nano /etc/apf/ad/conf.antidos

Find the string LP_KLOG=”0″ and change it to LP_KLOG=”1″

Now, find for CONAME=”Your Company”

Enter your company name within quotes for example

CONAME=”SupportFacility.Com”

Now find for the string USR_ALERT=”0″ and change it to USR_ALERT=”1″

This is so that you can receive email alerts.

Now enter your email address here:

USR=”something@yourdomain.com”

Now you have to set it in cron for this give the following command:

crontab –e

*/5 * * * * root /etc/apf/ad/antidos -a >> /dev/null 2>&1

This will run antidos every five minutes.

Plesk : Configure qmail to use alternate SMTP port 26

You have a plesk dedicated server and having issues related to SMTP port 25. There are issues where ISP blocks SMTP port 25, in this case we can use alternate port (I will use port 26).
Kindly follow the below steps to change SMTP port on your plesk dedicated (linux) server to 26.

Login to your server as root

root# cd /etc/xinetd.d

root# ls -l | grep smtp*

root# cat smtp_psa
service smtp
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}

root# nano /etc/services

Add the below lines

smtp_psa_new 26/tcp mail
smtp_psa_new 26/udp mail

root# cp smtp_psa smtp_psa_new

Change the service line in the new file “smtp_psa_new” to be this:

service smtp_psa_new
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}

root# /etc/init.d/xinetd restart

And you should see smtp listening on ports 25, and 26:

root# netstat -anp | grep xinetd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6989/xinetd
tcp 0 0 0.0.0.0:26 0.0.0.0:* LISTEN 6989/xinetd

That’s it!

Mailbox quota shown wrong on cPanel

On your cPanel dedicated server, for an email the mailbox quota is displayed wrong – follow the below steps:

Login to your server as root
cd /home/username/mail/domain.com/emailaccount
rm -rf maildirsize

Now, login to cPanel
Go to email account and change the quota for particular email account.
(Once you change quota, it will recreate file maildirsize automatically)

You can also delete maildirsize file from cpanel > file manager

That’s it!

Plesk backup and restoring the domain or whole server

How to backup and restore in plesk linux based servers..

BACKUP

/usr/local/psa/bin/pleskbackup -v domains domainname.com backupfilename

RESTORE

CREATING MAPFILE

/usr/local/psa/bin/pleskrestore --create-map backupfilename -map yourmapfilename


yourmapfilename = any name

To restore an domain edit the map

vi yourmapfilename
the map file would be like this

yourdomainname.com 11.22.33.44 # IP address
mysql::@localhost:3306

comment the unwanted domain and save the file

Restoring the domain form mapfile

/usr/local/psa/bin/pleskrestore --restore backupfilename -level domains -map yourmapfilename

This will restore the complete domain