cPanel/WHM mass add spf and domainkeys to all accounts

I am not really just now adding these, i merely ran some cleanups on the zones, removing obsolete ip’s and stuff like that, but i thought to share the script i used to reset the DKIM and SPF records for all accounts:

#!/bin/bash -x
for user in `ls -A /var/cpanel/users`;
do
/usr/local/cpanel/bin/dkim_keys_install $user && /usr/local/cpanel/bin/spf_installer $user;
done

Enjoy!

Previous value removed by cPanel transfer auto-merge

So i have been doing a hardware upgrade, and during the migration of the accounts, the target server named zone files got polluted with stuff like this:

; 86400 ;refresh ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 7200 ;retry ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 3600000 ;expire ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 86400 ) ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT

In order to clean things up, you can do something like this:

1 –  backup your named folder : cd /var;tar czf named.tgz named

2 – cd /var/named

perl -i.bak -ne ‘next if (/^; .+ ; Previous value removed by cPanel transfer auto-merge on/); print;’ /var/named/*.db

/scripts/restartsrv_named

Voila! Things should be clean.

Error from domain wrapper: Domain already exists, it was not added.: cPanel

So, today i had this guy that added some domain, a subdomain and then after removing, he wanted to add it once more, but got the error below:

Error from domain wrapper: Domain already exists, it was not added.

This means that after the deletion, there have been some bits and pieces of info that got left over at deletion. Doesn’t happen that often but here’s what you can do to fix it: (info provided by Tristan at the cPanel forums)

You would want to check the following locations:

/var/cpanel/userdata/username/main
/var/cpanel/userdata/username/sub.maindomain.com
/var/cpanel/users/username
/var/named/maindomain.com.db

Any of the above if it has traces of the subdomain will cause the subdomain to continue to be considered existing on the system. Simply make a copy of the file you are editing and then remove the subdomain. For the /var/cpanel/userdata/username/sub.maindomain.com file, simply move the file out of the way. For the /var/named/maindomain.com.db file, you could edit it in WHM > Edit a DNS zone if the subdomain is still there rather than edit that file directly.

If you did find the subdomain listed in any of the /var/cpanel/userdata/username files, you would need to run the following commands after removing it in the main file there and moving the sub.maindomain.com file there:

cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak110217
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

You would also likely want to run this script after that or possibly after editing /var/cpanel/users/username file:

/scripts/updateuserdomains

If you directly edited the /var/named/maindomain.com.db file rather than editing it in WHM > Edit a DNS Zone, you’d need to run this command:

rndc reload

In all of the above, username is the cPanel username, maindomain.com is the main domain name, andsub.maindomain.com is the subdomain name.

For me the problem was that /var/cpanel/users/username had 2 lines referring to the old domain. Removed those, updated userdomains as instructed, then rebuilt the httpd.conf, reload apache and there you go.

PHP 5.2 and PHP 5.3 side by side in cPanel servers

I just got a customer that needs both php 5.3 and php 5.2 in the server for various reasons, so here’s how it works:

1 – You need to compile php5.2 from EasyApache

2 – mkdir /usr/local/buildphp53/ ; cd /usr/local/buildphp53/ ; wget http://cz2.php.net/get/php-5.3.27.tar.gz/from/us1.php.net/mirror ; tar zxf php-5.3.27.tar.gz ; cd php-5.3.27/

3 – Modify the configure line below to suit you:

./configure –enable-bcmath \
–enable-cgi \
–enable-calendar \
–enable-exif \
–enable-ftp \
–enable-gd-native-ttf \
–enable-libxml \
–enable-magic-quotes \
–enable-mbstring \
–enable-pdo=shared \
–enable-sockets \
–enable-zip \
–prefix=/usr/local/php53 \
–with-bz2 \
–with-curl=/opt/curlssl/ \
–with-curlwrappers \
–with-freetype-dir=/usr \
–with-gd \
–with-gettext \
–with-imap=/opt/php_with_imap_client/ \
–with-imap-ssl=/usr \
–with-jpeg-dir=/usr \
–with-kerberos \
–with-libdir=lib64 \
–with-libexpat-dir=/usr \
–with-libxml-dir=/opt/xml2/ \
–with-mcrypt=/opt/libmcrypt/ \
–with-mhash=/opt/mhash/ \
–with-mysql=/usr \
–with-mysql-sock=/var/lib/mysql/mysql.sock \
–with-mysqli=/usr/bin/mysql_config \
–with-openssl=/usr \
–with-openssl-dir=/usr \
–with-pcre-regex=/opt/pcre \
–with-pdo-mysql=shared \
–with-pdo-sqlite=shared \
–with-pic \
–with-png-dir=/usr \
–with-sqlite=shared \
–with-tidy=/opt/tidy/ \
–with-xmlrpc \
–with-xpm-dir=/usr \
–with-zlib \
–with-zlib-dir=/usr

4 – make && make install

5 – Go to Apache configuration in WHM, and edit /usr/local/apache/conf/includes/pre_virtualhost_global.conf

Add the lines below, save and restart apache.

Action application/x-httpd-php53 /cgi-sys/php53

 AddType application/x-httpd-php53 .php53

6 – Have apache skip the htaccess scan and remove mine types:

/usr/local/cpanel/bin/apache_conf_distiller –update

touch /var/cpanel/easy_skip_update_php_mime_types

7 – Create a new file and add the lines below to it: /usr/local/cpanel/cgi-sys/php53

#!/bin/sh
 exec /usr/local/php53/bin/php-cgi

8 – Permissions:

chown root:wheel /usr/local/cpanel/cgi-sys/php53

chmod +x /usr/local/cpanel/cgi-sys/php53

9 – Linking:

 ln -s /usr/local/php53/bin/php-cgi /usr/local/bin/php53

10 – php.ini:

mv /usr/local/buildphp53/php-5.3.27/php.ini-production /usr/local/php53/lib/php.ini

Restart apache

Running php 5.3 :

Add this into a .htaccess file located in the public_html folder in the user’s account that you want it to run on.

AddHandler application/x-httpd-php53 .php

A running easyapache process was detected. Please wait for easyapache to finish before attempting to upgrade MySQL

I am just setting a new server up, and i upgraded apache first. Now i went to upgrade MySQL to 5.5, but when i am going in the interface, it says:

WARNING: A running easyapache process was detected. Please wait for easyapache to finish before attempting to upgrade MySQL.

If you are certain that the easyapache is no longer running, you may restart the MySQL upgrade by clicking the following button.
The “Ignore current upgrade button” is not working. What do we do?

 

What you can do, is to run:

ps aux | grep easyapache

If it doesn’t return any process running, then go delete the following file:
/usr/local/apache/AN_EASYAPACHE_BUILD_IS_CURRENTLY_RUNNING

Enjoy!

Find spammer scripts in Exim – useful commands

Had a customer the other day and he asked me to clear spammers on his server. Some of these commands came in handy:

 

1. To check the number of emails present in the queue:

# exim -bpc

2. To check the emails present in the queue with the mail id and sender ID:

# exim -bp
# exim -bp | less

3. To view the header of a particular email using mail ID:

# exim -MvH mail_id

4.  To view the body of a particular email using mail ID:

# exim -Mvb mail_id

5. To view a message’s logs:

# exim -Mvl mail_id

6. To trace path:

# exim -d -bt [email protected]

7. To get sorted list of email sender in exim queue:

# exim -bpr | grep “<” | awk {‘print $4’} |cut -d “<” -f 2 | cut -d “>” -f 1 | sort -n | uniq -c| sort -n

8. To check the script that will originate spam mails:

# grep “cwd=” /var/log/exim_mainlog|awk ‘{for(i=1;i<=10;i++){print $i}}’|sort| uniq -c|grep cwd|sort -n

9. If we need to find out exact spamming script. To do this, run following command:

# ps auxwwwe | grep user | grep –color=always “/home/user/public_html/templates/” | head

10.  To delete the emails of a specific user:

# grep -lr ‘[email protected]’ /var/spool/exim/input/ | sed -e ‘s/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g’ | xargs exim -Mrm

# exim -bp | grep “user_email-account” | awk ‘{print $3}’ | xargs exim -Mrm

11. To delete Frozen emails from the email queue:

# grep -R -l ‘*** Frozen’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm
# exim -bp| grep frozen | awk ‘{print $3}’| xargs exim -Mrm
# exiqgrep -z -i | xargs exim -Mrm

12.  To delete Spam emails from the email queue:

#  grep -R -l [SPAM] /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

13. To check the no. of frozen mails:

# exiqgrep -z -c

14. To check exim logs:

# tail -f /var/log/exim_mainlog

Freebsd / Drives larger than 1tb / gpart

This has taken me more than it should have.

Okay long story short: If you’re installing FreeBSD, then you should know that it doesn’t support drives larger than 1 tb drives by default from sysinstall / fdisk / label.
Quick and easy once you learn it, you realise that you can get the job done really quick by using gpart.

Problems you may encounter:

———————————————————–
??(~)->gpart create -s gpt aacd1
gpart: geom ‘aacd1’: File exists

^^ This happens if you already tried (like i did) to mount the big 9 tb raid array through fdisk. Solution – dd the drives, and then you will erase the mbr, and it’s good to go:

??(~)->gpart show aacd1
=> 63 19503513477 aacd1 MBR (9.1T)
63 19503513477 – free – (9.1T)

??(~)-> dd if=/dev/zero of=/dev/aacd1 bs=1k count=1

??(~)->gpart show aacd1
gpart: No such geom: aacd1.

??(~)->gpart create -s gpt aacd1
aacd1 created

^^ And it works like a charm.
———————————————————–
??(~)->gpart show aacd1
=> 34 19503513533 aacd1 GPT (9.1T)
34 19503513533 – free – (9.1T)

Time to make a partition and get this over with:

??(~)->gpart add -t freebsd-ufs -l bigraid aacd1
aacd1p1 added

??(~)->newfs aacd1p1

Once the partition is loaded, just add it to fstab:

/dev/aacd1p1 /var/www/html ufs rw 2 2

Then do a “mount -a” and it’s finished.

Took me a while to figure all this out. Hope it makes your life easier.

LE: for optimizing the block size: newfs -O2 -U -b 65536 -f 8192 -i 65536 /dev/ad5p1

LEE: for destroying partitions:

??(~)->gpart delete -i 1 ad7
??(~)->gpart destroy ad7

cpanel quota becomes unlimited

After migrating accounts to a new cPanel server, i noticed that all my accounts quota shows as unlimited.

As a solution, i had to run /scripts/fixquotas, but i got the following error message :

Unable to determine filesystems with quotas enabled

The problem here, usually seems to occur on FreeBSD systems, and it’s related to the file /etc/fstab.quota missing, so in order to fix that, you need to do:

touch /etc/fstab.quotas

And voila !

??([email protected])(09:32:23)
??(/etc)->/scripts/fixquotas
Installing Default Quota Databases……Done
Updating Quota Files……
*** Checking user quotas for /dev/mirror/gm0s1e (/home)
/home: unknown uid: 501
/home: unknown uid: 1000
/home: unknown uid: 106
/home: unknown uid: 146
/home: unknown uid: 12475
/home: unknown uid: 10090
/home: unknown uid: 100
/home: unknown uid: 502
/home: unknown uid: 500
/home: unknown uid: 1034
/home: unknown uid: 2525
/home: unknown uid: 10155
/home: unknown uid: 10008
/home: unknown uid: 2001
/home: unknown uid: 1023
/home: unknown uid: 31978
/home: unknown uid: 222
/home: unknown uid: 203
/home: unknown uid: 24032

….Done

cPanel force remove an ip address

If you want to remove an ip address in cPanel, and sometimes the remove button is not there, just edit the file /etc/ips, remove the ip address in question, and then do a restart of the system aliases.

/etc/rc.d/init.d/ipaliases restart

This will work on cPanel / linux/centos

Should save you some headaches.

kernel: ipfw: install_state: Too many dynamic rules

Okay this sucks. I am running FreeBSD 7 on a few servers, and i get a load of ddos  everyday. At some point, the server would stop accepting connections, but the already established connections would work just fine.

If you have to get rid of that message and restore services availability, then have fun with /etc/sysctl.conf, where you setup : net.inet.ip.fw.dyn_max=16384.

Now – that value may not be the same for everybody, but you can keep tweaking until you reach the sweet spot.

Save the changes by : sysctl -w net.inet.ip.fw.dyn_max=16384 on FreeBSD 7

Skip to toolbar Log Out