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();
 
}

No comments:

Post a Comment