Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Stine committed Apr 24, 2021
1 parent 7b8bc16 commit a78eb74
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# wordpress-network-plugin-finder
See README.

A very simple shell script to scan for WordPress Multisite network activated plugins. Compatible with Linux and MySQL. This script will not check every sub site, just network wide plugins. The script will use wp_sitemeta to search in by default. You can change optional params as outlined below.

## To Use

First of all, if you are not comfortable around the command line, don't use this script as it requires some manual editing.

1. Clone the repo or download the .zip from the Releases tab.
2. Extract the .zip if you went that direction.
3. Open network-plugin-finder.sh to edit the following values.
- base_path: set this to the base directory path of your script. For example, /home/user/subdirectory.
- The default logfile will output to base_path/output.log. You can change this if you wish.
- The default save file will output to base_path/save.log. You can change this if you wish.
- dbhost: set to localhost by default. Enter your database host value here.
- dbuser: set to user by default. Enter your database username here.
- dbpass: set to arg by default. Enter the database password as the first arg while executing the script or manually fill it in.
- dbprefix: default is wp_. Only change if your WordPress database prefix is different. You can find your database prefix in your wp-config.php file.
- plugin: default set to some-plugin. Change this to the name of the plugin directory. E.g. /wp-content/plugins/plugin-directory/plugin-file.php. The part you want is plugin-directory.

## Running the Script

To run the script, execute the following.

/path/to/script/network-plugin-finder.sh 'db_password_here'

### Support

If you spot an issue or have a question, open an issue. I hope this script serves useful.
37 changes: 37 additions & 0 deletions network-plugin-finder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
base_path="/home/user/subdir" # Base path of script directory.
logfile="${base_path}/output.log" # Base path plus log file.
rm -f "$logfile" # Start with a fresh log file.
save="${base_path}/save.log" # A place to save our results.
echo "Starting: $(date)..." | tee -a "$logfile"
if [ -z "$1" ]; then
echo "Provide DB password as first script arg. Exiting..." | tee -a "$logfile"
exit 1
fi
dbhost="localhost" # Database host.
dbuser="user" # Database username.
dbpass="$1" # Database password or filled from command arg.
dbprefix="wp_" # The WordPress database prefix. Default is set to wp_.
plugin="some-plugin" # Plugin we're searching for.
for database in $(mysql -h"$dbhost" -u"$dbuser" -p"$dbpass" -e "show databases;" | tail -n +2 | grep -v 'information_schema' | grep -v 'performance_schema' | grep -v 'mysql' ); do # Creating a loop of databases.
if ! mysql -h"$dbhost" -u"$dbuser" -p"$dbpass" "$database" -e "show tables;" | grep -q "${dbprefix}sitemeta"; then # Checking to make sure our database table exists. If not, continue the loop.
echo "${dbprefix}sitemeta table doesn't exist for ${database}. Next..." | tee -a "$logfile"
continue
fi
if ! mysql -h"$dbhost" -u"$dbuser" -p"$dbpass" "$database" -e "select meta_value from ${dbprefix}sitemeta where meta_key = 'active_sitewide_plugins';" | grep -q "$plugin"; then # Check to see if our plugin exists. If not, continue the loop.
echo "Skipping ${database}. ${plugin} not found." | tee -a "$logfile"
sleep 5
continue
fi
echo "$database" >> "$save" # Write our database to the save file.
echo "Saving ${database} because ${plugin} was found." | tee -a "$logfile"
sleep 5 # Wait a few seconds to not overload database server.
done
if [ -r "$save" ]; then
total_records=$(wc -l "$save") # Get the total lines of our save file.
echo "Total records saved: ${total_records}." | tee -a "$logfile"
else
echo "The script came up empty." | tee -a "$logfile"
fi
echo "Completed: $(date)." | tee -a "$logfile"
exit 0

0 comments on commit a78eb74

Please sign in to comment.