Skip to content

Instantly share code, notes, and snippets.

@juslintek
Created November 8, 2017 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juslintek/bce4bbe0ed68836b106ce9761a38a097 to your computer and use it in GitHub Desktop.
Save juslintek/bce4bbe0ed68836b106ce9761a38a097 to your computer and use it in GitHub Desktop.
Wordpress virus fix script on VestaCP
#!/bin/bash
## You will need pwgen in order for this to work
type pwgen > /dev/null 2>&1 || { sudo yum install pwgen; exit 1; }
webrootdir=/home/admin/web/
for domaindir in $(ls $webrootdir);
do
webdir="$webrootdir$domaindir/public_html";
echo "#############";
echo $webdir;
echo "#############";
cd $webdir;
ls -lha;
if $(wp core is-installed);
then
maindir="$webrootdir$domaindir";
multisite=$(grep "'MULTISITE'" wp-config.php | cut -d',' -f2 | sed -r "s/[\'\)\;]+//g" | sed 's/\s//g');
dbname=$(grep "DB_NAME" wp-config.php | cut -d',' -f2 | sed -r "s/['\)\;]+//g" | sed 's/\s//g');
dbuser=$(grep "DB_USER" wp-config.php | cut -d',' -f2 | sed -r "s/[\'\)\;]+//g" | sed 's/\s//g');
dbprefix=$(grep "\$table_prefix" wp-config.php | cut -d'=' -f2 | sed -r "s/[\'\)\;\"]+//g" | sed 's/\s//g');
dbpass=$(pwgen -ysBv 12 1);
echo "Database name: $dbname";
echo "Database user: $dbuser";
echo "Database password: $dbpass";
sudo /usr/local/vesta/bin/v-change-database-password admin $dbname $dbpass
if [[ $multisite = "true" ]] ;
then
domain=$(grep "DOMAIN_CURRENT_SITE" wp-config.php | cut -d',' -f2 | sed -r "s/[\'\)\;]+//g" | sed 's/\s//g');
fi
wp core verify-checksums
mv wp-content/ ..;
mv .user.ini ..;
find "$maindir/wp-content/uploads/" -type f -name "*.php" -exec rm -rf {} \; -print;
rm -rf "$maindir/wp-content/cache";
rm -rf *;
rm -rf .*;
wp core download;
rm -rf wp-content;
mv $maindir/wp-content $webdir/;
mv $maindir/.user.ini $webdir/;
if [[ $multisite = "true" ]] ;
then
wp config create --dbprefix=$dbprefix --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass --force --extra-php << PHP
define('WP_MEMORY_LIMIT', '256M');
//define('WP_MAX_MEMORY_LIMIT', '256M');
define( 'SUNRISE', 'on' );
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', '$domain' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
PHP
else
wp config create --dbprefix=$dbprefix --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass --force --extra-php << PHP
define('WP_MEMORY_LIMIT', '128M');
//define('WP_MAX_MEMORY_LIMIT', '256M');
PHP
fi
wp theme install $(wp theme list --field=name) --force;
wp tgmpa-plugin install --all --force
wp plugin install $(wp plugin list --field=name) --force;
wp plugin update-all;
wp theme update-all;
# /home/admin/php-malware-finder/php-malware-finder/phpmalwarefinder -t 2 -v -l php $webdir
wp user list
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment