Wednesday, December 10, 2014

How to find the Outdated Wordpress Versions serverwide and send email to domain users ?


Hi, 
Here is the perl script doing it.

#!/usr/bin/perl -w
use HTML::Template;
use MIME::Lite;
 
my $email;
my $domains;
my @locate;
my @s;
my $emails;
my @d;
my $currentversion;
my $latestversion="3.5.1";
my @current;
my $installdir;
 
@locate=`/usr/bin/locate wp-includes/version.php | grep -v virtfs | xargs grep "wp_version = " 2>/dev/null | grep -v " = '3.5.1'"`;
 
foreach my $k (@locate){
        chomp($k);
 
        @s=split(/\//, $k);
 
        $emails=`/bin/grep -i contactemail /var/cpanel/users/$s[2] |/bin/grep \@`;
 
        chomp($emails);
        @e=split(/\=/,$emails);
 
        $email=$e[1] if $e[1]=~/\@/i;
 
        $domains=`/bin/grep -i dns\= /var/cpanel/users/$s[2]`;
        chomp($domains);
 
        @d=split(/\=/, $domains);
 
        $domain=$d[1] if $d[1];
 
        @current=split(/\s+/, $k);
 
$currentversion=$current[$#current];
 
        $currentversion=~s#;##g;
 
        $installdir=$current[0];
 
        $installdir=~s#wp-includes/version.php:\$wp_version##g;
 
        print "$k , $domain , $email\n";
 
$template = HTML::Template->new(filename =>"/scripts/wpemail.tmpl");
$template->param(
                domain=>$domain,
                installdir=>$installdir,
                currentversion=>$currentversion,
                latestversion=>$latestversion
                );
 
        my $msg2 = MIME::Lite->new(
                        From    =>"info\@domain.com",
                        To      =>"desination\@emailaddress.com",
                        Subject =>"Your Wordpress Outdated notice for $domain",
                        Type    =>'multipart/related'
                        );
 
                $msg2->attach(Type => 'text/html',
                             Data =>$template->output
                            );
 
#                $msg2->send();
 
}

How to remove a physcal volume/drive from a Volumegroup or How to move a root volume group to new drive

Scenario

The root VG needs to be moved to a different physical disk (e.g. to convert from ATA to SATA drives).

Assumptions

  1. You know how to partition disks using fdisk and can edit /etc/fstab with a text editor (such as vim).
  2. Your /boot filesystem is on a separate partition, and your root filesystem is part of an LVM VG.
  3. Your root VG contains only one PV.

Environment

This procedure was developed on a system with an Intel Core i5 3.2 GHz CPU with 4 GB RAM. The source disk is a Seagate ST3802110A (80 GB ATA), and the destination is a Maxtor 7Y250M0 (250 GB SATA). The Linux distribution used was CentOS 5.4, but these commands should apply to nearly all Linux distributions which support LVM.

Special note

Because LVM is below the filesystem layer (see filesystem layers overview for more information), all of the following operations (with the exceptions of the reboots in the first and last steps) may be done online, without unmounting any filesystems. However, this work should be scheduled for non-peak times, because there is no way (to my knowledge) to control the rate at which pvmove copies data. Therefore, it will usually utilise almost all of your disk's I/O bandwidth.

Procedure

  1. Connect the new disk to the system. Depending on your hardware and kernel version, you may need to reboot your system to detect it.
  2. Check the partition structure on the source drive. In this case, it has one partition for /boot and the rest of the drive is LVM (output from fdisk -l):
    Disk /dev/hde: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
       Device Boot      Start         End      Blocks   Id  System
    /dev/hde1   *           1          13      104391   83  Linux
    /dev/hde2              14        9729    78043770   8e  Linux LVM
  3. Create partitions on the destination drive to match the source drive. It's OK if they are larger than their equivalents on the source drive. In this scenario, i've increased /boot to 1 GB, and used the remainder of the 250 GB drive forLVM. Here's the final partition setup:
    Disk /dev/sdb: 250.0 GB, 250058268160 bytes
    255 heads, 63 sectors/track, 30401 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1   *           1         123      987966   83  Linux
    /dev/sdb2             124       30401   243208035   8e  Linux LVM
  4. Create the boot filesystem on the new drive:
    mkfs -t ext3 -L /boot /dev/sdb1
  5. Mount it on /mnt:
    mount /dev/sdb1 /mnt
  6. Change /etc/fstab to use label rather than path to mount the disk. The line should look something like this when you're done:
    LABEL=/boot  /boot  ext3  defaults  1 2
  7. Copy files from the existing /boot to the new /boot (mounted on /mnt):
    cd /mnt
    dump -0 -b 1024 -f - /boot/ | restore -r -f - -b 1024
  8. Unmount the new /boot filesystem:
    umount /mnt
  9. Install GRUB to the new drive:
    grub
    grub> device (hd1) /dev/sdb
    device (hd1) /dev/sdb
    grub> root (hd1,0)
    root (hd1,0)
     Filesystem type is ext2fs, partition type 0x83
    grub> setup (hd1)
    setup (hd1)
     Checking if "/boot/grub/stage1" exists... no
     Checking if "/grub/stage1" exists... yes
     Checking if "/grub/stage2" exists... yes
     Checking if "/grub/e2fs_stage1_5" exists... yes
     Running "embed /grub/e2fs_stage1_5 (hd1)"...  15 sectors are embedded.
    succeeded
     Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
    Done.
    grub> quit                                                                                             
  10. Set up the other partition on your new root disk as an LVM PV:
    pvcreate /dev/sdb2
  11. Find your current root VG and PV names:
    vgdisplay -v
  12. Add the new PV to your root VG (substitute vg00 for the name of your VG):
    vgextend /dev/vg00 /dev/sdb2
  13. Now comes the LVM magic to move the LVs on your current root PV to the new PV. First, test the operation we're about to commence:
    pvmove --test --verbose /dev/hde2 /dev/sdb2

    Then run it:
    pvmove --verbose /dev/hde2 /dev/sdb2
  14. This operation will take some time, depending on the size of your data and the speed of your disks. (The system with which i tested this article (see above for specifications) completed the move in approximately 45 minutes.) Pvmove will keep you up-to-date with its progress, but i like to also see how it's performing by running iostat in another terminal:
    iostat -dkx 30

    Iostat is part of the sysstat package on most Linux distributions. It is not installed by default.
  15. When the pvmove is complete, remove the old root disk from the VG (once again, substitute the name of your VGfor vg00):
    vgreduce /dev/vg00 /dev/hde2
  16. Shut down your system, disconnect the old drive, and reboot using your new drive.

Miscellaneous notes

  • If something has gone wrong with your /boot copy or GRUB install, you can boot your system by installing the old disk again, because the old disk contains a fully functional /boot partition, and the LVM VG will be found regardless of which drive it resides upon.
  • It is possible to interrupt pvmove with Ctrl-C and resume it by re-running the same command.
  • I have never seen pvmove fail if its test run succeeds, so i have no idea what to do if this happens. :-)

Neighbour table overflow ?

If you have a big network with the hundreds of hosts you can expect “Neighbour table overflow” error which occurs in large networks when there are two many ARP requests which the server is not able to reply. For example you’re using server as a DHCP server, cable modems provisioning, etc.
Nov 10 03:18:17 myhost Neighbour table overflow.
Nov 10 03:18:23 myhost printk: 12 messages suppressed.

Of curse, this can be fixed. The solution is to increase the threshhold values in /etc/sysctl.conf. Add following lines to /etc/sysctl.conf (RH based distros)
net.ipv4.neigh.default.gc_thresh1 = 4096
net.ipv4.neigh.default.gc_thresh2 = 8192
net.ipv4.neigh.default.gc_thresh3 = 8192
net.ipv4.neigh.default.base_reachable_time = 86400
net.ipv4.neigh.default.gc_stale_time = 86400
Save sysctl.conf and exec sysctl -p. You can also reboot but it isn’t necessary.
The default sysctl.conf file
net.ipv4.ip_forward=0
kernel.shmmax=68719476736
kernel.msgmax=65536
kernel.msgmnb=65536
net.ipv4.conf.default.rp_filter=1
kernel.sysrq=0
net.ipv4.conf.default.accept_source_route=0
kernel.shmall=4294967296
kernel.core_uses_pid=1
net.ipv4.tcp_syncookies=1
“Tuned” systctl.conf
net.ipv4.ip_forward=0
kernel.shmmax=4294967295
kernel.msgmax=65536
kernel.msgmnb=65536
net.ipv4.conf.default.rp_filter=1
kernel.sysrq=0
net.ipv4.conf.default.accept_source_route=0
kernel.shmall=268435456
kernel.core_uses_pid=1
net.ipv4.tcp_syncookies=1
net.ipv4.neigh.default.gc_thresh1 = 4096
net.ipv4.neigh.default.gc_thresh2 = 8192
net.ipv4.neigh.default.gc_thresh3 = 8192
net.ipv4.neigh.default.base_reachable_time = 86400
net.ipv4.neigh.default.gc_stale_time = 86400
Explanation…
The neighbour table is generally known as ARP table and the default value for gc_thresh1 is 128 (Adjust where the gc will leave arp table alone)
[root@myServer ~]# cat /proc/sys/net/ipv4/neigh/default/gc_thresh1
128
which is not enough for large networks (more than 128 hosts). Thats why we need to tune this value. The gc_thresh2 is a soft limit (Tell the gc when to become aggressive with arp table cleaning.) and the gc_thresh3 is a hard limit (Don’t allow the arp table to become bigger than this).
To enlarge the ARP cache table on the live system run:
# sysctl -w net.ipv4.neigh.default.gc_thresh3=8192
# sysctl -w net.ipv4.neigh.default.gc_thresh2=8192
# sysctl -w net.ipv4.neigh.default.gc_thresh1=4096
It is possible that after distro update your systctl.conf will be replaced with the default values. Check this file periodically..

how to configure mod_geoip in nginx?



1. Make sure nginx is compiled with --with-http_geoip_moduleoption. you can cehcking by running the command "nginx -V"
If its not compiled, then recompile nginx with the option--with-http_geoip_module along with the existing options.
2. Add the below setting in nginx.cong under http header.

In this example we enabled access from India only
======================
 geoip_country /usr/share/GeoIP/GeoIP.dat;
 map $geoip_country_code $allowed_country {
         default no;
         IN yes;  # Allow India only
}
# Below is to exclude ips.. for example exclude google bots
geo $mygeo {  # Specify IP ranges to exclude from the deny list
        ranges;
      default  0;
        64.233.160.0-64.233.191.255 1;
        66.102.0.0-66.102.15.255 1;
        66.249.64.0-66.249.95.255 1;
        72.14.192.0-72.14.255.255 1;
        74.125.0.0-74.125.255.255 1;
        209.85.128.0-209.85.255.255 1;
        216.239.32.0-216.239.63.255 1;
        70.34.205.74-70.34.205.78 1;
}
=======================================
3. Add the below entries in the specific domain vhosts entry
==============================
      set $my_var 0;

        if ($allowed_country = "no") {
                set $my_var P;
        }
        if ($mygeo = "0") {
                set $my_var "${my_var}C";
        }
        if ($my_var = PC)
        {
                return 403;
        }
===============================
So, pages will return 403 page if anyone access site from other than the granted locations.

What will do if openssh demon not started?

If we face an issue with ssh demon as,

#/etc/init.d/sshd start --showing as service started
But

#/etc/init.d/sshd status --showing status as service is not running .

Ex:

-bash-3.2# /etc/init.d/sshd start
Starting sshd: [ OK ]
-bash-3.2# /etc/init.d/sshd status
openssh-daemon is stopped

We can found an error as below in /var/log/secure,

#vps sshd[18431]: fatal: daemon() failed: No such device

The reason for this is ,its related to /dev/null which is suppossed to be
a proper character device and not a regular file.

In this case we can move it or remove it and then recreate file as below,

-bash-3.2# rm -f /dev/null
-bash-3.2# mknod /dev/null c 1 3
Once character device is created ,permission is like below,

-bash-3.2# ls -lh /dev/null
crw-rw-rw- 1 root root 1, 3 Jan 12 16:07 /dev/null
-bash-3.2#

fter this was confirmed that /dev/null is a proper character device , and
the sshd service will start now,

-bash-3.2# /etc/init.d/sshd start
Starting sshd: [ OK ]
-bash-3.2# /etc/init.d/sshd status
openssh-daemon (pid 27662) is running...
-bash-3.2#

Postfix mail server commands

View the postfix version :
#  postconf  mail_version
mail_version = 2.3.3
Check the postfix installation :
#  postfix check
Show default postfix values :
#  postconf -d
To show non default postfix values :
#  postconf -n
To restart postfix mail server  :
postfix reload
Flush the mail queue :
#  postfix  flush
Or you can use:
#  postfix  -f
To see mail queue :
#  mailq
in send mail sendmail -bp )
#  mailq | wc -l
(will give the total no of mails in queue )
To remove all mail from the queue :
#  postsuper -d ALL
To remove all mails in the deferred queue :
#  postsuper -d ALL deferred
To see the mails in a tree structure :
#  qshape
View the mail content :
 postcat -q  AFD4A228 37C
You will get the above id from mailq . Or you can view the mails from postfix mail spool. Usually postfix will store the mails in /var/spool/postfix/active/ from this location also you can view the mails .  We can change the queue directory from the postfix conf.
Sort by from address :
 #  mailq | awk '/^[0-9,A-F]/ {print $7}' | sort | uniq -c | sort -n
To remove all mails sent by user@adminlogs.info from the queue :
mailq| grep '^[A-Z0-9]'|grep user@adminlogs.info|cut -f1 -d' ' |tr -d \*|postsuper -d -
To remove all mails being sent using the From address “user@adminlogs.info” :
mailq | awk '/^[0-9,A-F].*user@adminlogs.info / {print $1}' | cut -d '!' -f 1 | postsuper -d -
To remove all mails sent by the domain adminlogs.info from the queue :
mailq| grep '^[A-Z0-9]'|grep @adminlogs.info|cut -f1 -d' ' |tr -d \*|postsuper -d -
Test your own Mailserver against attacks :
telnet mail-abuse.org

Exim mail server useful commands

Common Exim Commands:

exim -bpc                       - Print a count of the messages in the queue
exim -bp                       - Print a listing of the messages in the queue (time queued, size, message-id,
exim -M emailID                 - force delivery of one message
exim -Mvl messageID             - View Log for message
exim -Mvb messageID             - View Body for message

Clear the mail queue in terminal:

exim -bpr | grep '<>' | awk '{print $3}' | xargs exim -Mrm

exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash

Check how may frozen emails in the queue:

exim -bpr | grep frozen | xargs exim -Mrm wc -l

How to Check the total number of emails sent to particular domain in mail queue ?

exim -bp | exiqsumm | grep 'gmail.com'

Find spammers:

grep "cwd=" /var/log/exim_mainlog|awk '{for(i=1;i<=10;i++){print $i}}'|sort|uniq -c|grep cwd|sort -n

To display the IP and no of tries done bu the IP to send mail but rejected by the server:

tail -3000 /var/log/exim_mainlog |grep 'rejected RCPT' |awk '{print$4}'|awk -F\[ '{print $2}'|awk -F\] '{print $1} '|sort | uniq -c | sort -k 1 -nr | head -n 5

Dual PHP installation on cPanel server

Here, we are installing the PHP 5.2.17 version as second PHP on server. 


Download PHP 5.2.17 under /usr/src directory.
 

wget http://museum.php.net/php5/php-5.2.17.tar.bz2
tar -jxvf php-5.2.17.tar.bz2
cd php-5.2.17

Use the below command to check the modules configured with the current PHP version.
php -i | grep configure
 

Configure Command =>  './configure'  '--disable-cgi' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--enable-zip' '--prefix=/usr/local' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--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-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-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

You will get a output with quotes. You need to remove the quotes from the output and the configure command should look like below.

Required output:

./configure  --disable-cgi --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo=shared --enable-sockets --enable-zip --prefix=/usr/local --with-bz2 --with-curl=/opt/curlssl/ --with-freetype-dir=/usr --with-gd --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-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-ttf --with-xmlrpc --with-xpm-dir=/usr --with-xsl=/opt/xslt/ --with-zlib --with-zlib-dir=/usr

Add the below entry next to the prefix option: 

--with-config-file-path=/opt/php52/lib --with-config-file-scan-dir=/opt/php52/lib/php.ini.d


Execute the configure command now: 

./configure  --disable-cgi --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo=shared --enable-sockets --enable-zip --prefix=/opt/php52 --with-config-file-path=/opt/php52/lib --with-config-file-scan-dir=/opt/php52/lib/php.ini.d --with-bz2 --with-curl=/opt/curlssl/
--with-freetype-dir=/usr --with-gd --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-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-ttf --with-xmlrpc --with-xpm-dir=/usr --with-xsl=/opt/xslt/ --with-zlib --with-zlib-dir=/usr


The config command will complete successfully.

make

You may face the below error while running the make command:

/usr/src/php-5.2.17/ext/dom/node.c: In function ‘dom_canonicalization’:
/usr/src/php-5.2.17/ext/dom/node.c:1953: error: dereferencing pointer to incomplete type
/usr/src/php-5.2.17/ext/dom/node.c:1955: error: dereferencing pointer to incomplete type
make: *** [ext/dom/node.lo] Error 1

Use the below steps to overcome this error.

wget https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
patch -p0 -b < txtbgxGXAvz4N.txt

Now you need to run the make command once again. Once it completed follow the below steps.

make install

cp php.ini-recommended /opt/php52/lib/php.ini


Add the below entry under the [handlers] section at the end of the file.

vi /opt/suphp/etc/suphp.conf

application/x-httpd-php52="php:/opt/php52/bin/php-cgi"

vi /usr/local/apache/conf/php.conf

suPHP_AddHandler application/x-httpd-php52

/etc/init.d/httpd restart 



 Add the below entry in the domain .htaccess file for which you need to use the PHP 5.2.17 version:


AddHandler application/x-httpd-php52 .php

To compile the additional modules with the PHP 5.2.17 version:

Add extension Directory on server.
echo 'extension_dir="/opt/php52/lib/php/extensions/no-debug-non-zts-20060613"' >> /opt/php52/lib/php.ini

Ioncube Installation: 

Download link: http://www.ioncube.com/loaders.php
wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
cp -rpf ioncube/ioncube_loader_lin_5.2.so /opt/php52/lib/php/extensions/no-debug-non-zts-20060613/
echo 'zend_extension="/opt/php52/lib/php/extensions/no-debug-non-zts-20060613/ioncube_loader_lin_5.2.so"' >> /opt/php52/lib/php.ini

Zend_Optimizer Installation:

wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
cp -rpf ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /opt/php52/lib/php/extensions/no-debug-non-zts-20060613/
echo 'zend_extension="/opt/php52/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so"' >> /opt/php52/lib/php.ini

Then, add extension directive for the below modules which are already compliled.

PDO
pdo_mysql
pdo_sqlite
SQLite

echo 'extension = "pdo.so"' >> /opt/php52/lib/php.ini
echo 'extension = "pdo_mysql.so"' >> /opt/php52/lib/php.ini
echo 'extension = "pdo_sqlite.so"' >> /opt/php52/lib/php.ini
echo 'extension = "sqlite.so"' >> /opt/php52/lib/php.ini