There was a problem loading the comments.

Find All Joomla Installations and Versions and Mail CSV to yourself

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

This Script will search your hosting server for all Joomla installations. 
It then compiles them into a sorted list which can be emailed to you.

This version of the script is meant to reside in /root/scripts and to be run from the command-line.

The script may be easily modified to run from cron. You can also keep it updated with latest Joomla Versions.

If you would like the indented/easy-to-read version open a support ticket.


SCRIPT:

 

#!/bin/bash

###################################################################
# #
# Joomla Version Detection Script #
# 8Dweb LLC (https://8dweb.com) #
# Original Script by HowtoForge (broken after 3.2) #
# Modified & Updated 04-12-2016 by MJS #
# FREELY DISTRIBUTABLE - Use and Modify as you see fit! #
# Major Changes: #
# - Cleaned search to only find Joomla folders #
# - Updated to Work with Joomla 1.5, 1.6, 1.7 2.5 3.x #
# - Added Color to Echo for easier reading #
# - Added Input Routines for: #
# * Base Directory (where websites are stored) #
# * output file name #
# * Email address to which a Sorted CSV file may be sent #
# - Changed Joomla Installation Detection Logic #
# - Added Sort Routine (uses joomla.sorted.csv) #
# - Changed Joomla Version Detection Logic #
# - Added / Changed Status Options for Joomla Versions #
# - Added Mail Routine (requires Mutt) for CSV File #
# #
# Script runs fine on Centos & Debian flavors #
# Script currently designed to run from /root/scripts #
# modify as required to run from another directory #
# Script requires mutt installed for outgoing email #
# Sort currently only sorts on OUTPUT file named #
# joomla - which is then processed into #
# joomla.sorted.csv and mailed out #
# #
# This script makes use of color using \e[xxm codes #
# which requires the use of echo -e for statements #
# that utilize the color #
##################################################################

echo ""
echo ""
echo -e "\e[32m\e[1m|==========================================|"
echo "| |"
echo "| //Find Joomla Script Initializing// |"
echo "| |"
echo -e "|==========================================|\e[0m"

# The LAST version 1.5.x (Currently unused in Script)
LASTSUB15=26

# The LAST version 2.5.x (Currently unused in Script)
LASTSUB25=28

# The LAST version 3.4.x
# We Treat 3.4.latest as OK until further notice (04-09-2016 mjs)
LASTSUB34=8

# Current Joomla Version - 3.5.x
LATEST=3.5

# Current Version 3 SubVersion 3.5.x
CURSUB3=1

# Three Inputs are allowed to the Script
# Added mjs (04-12-2016) - Code to allow BASEPATH; OUTFILE and EMAIL to be entered by user
echo ""
echo ""
echo "Please Enter the base path for websites. " ;
echo -e "Leave blank for default path \e[36m\e[1m/chroot/home\e[0m:" ;
read BASEPATHINPUT
if [[ -d "$BASEPATHINPUT" ]] ; then
echo -e "\e[36m\e[1m$BASEPATHINPUT \e[0mseems to be a " ;
echo "legitimate directory on this server." ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
BASEPATH=$BASEPATHINPUT ;
else
# default base path of the websites on YOUR server
# Edit Line 58 If you want to set a different default base path
echo -e "Your directory entry \e[31m\e[1m$BASEPATHINPUT is empty or invalid.\e[0m" ;
echo -e "Now using default \e[36m\e[1m/chroot/home\e[0m" ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
BASEPATH="/chroot/home/" ;
fi

# Added mjs (04-12-2016) - Obtain a filename for sorting and CSV output
echo ""
echo ""
echo "Please Enter the filename for output from this script." ;
echo -e "Leave Blank for default filename \e[36m\e[1m>>joomla<<\e[0m to be used:" ;
read OUTFILEINPUT
if [[ "$OUTFILEINPUT" != "" ]] ; then
echo "File \"$OUTFILEINPUT\" will be used by this script." ;
echo "If you used "joomla" a sorted CSV will be emailed to you." ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
OUTFILE=$OUTFILEINPUT ;
else
echo "No output file specified." ;
echo -e "Using default \e[36m\e[1mjoomla\e[0m filename." ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
OUTFILE="joomla" ;
fi

# Added mjs (04-12-2016) - Obtain Email Address to which CSV can be sent
echo ""
echo ""

# Added mjs (04-12-2016) - Getmail Function - called by while loop...
getemail() {
echo "Please Enter a valid Email Address:" ;
echo "Example: joe@somedomain.com" ;
echo -e "Type \e[36m\e[1mNO\e[0m to bypass..." ;
read EMAIL
}

# Added mjs (04-12-2016) - While Loop checks for SIMPLE validation of email (i.e. jo@domain.com)
# Thanks to Stackoverflow.com for REGEX Ideas for simple email validation
# The regex is not perfect, but works for admins because we are supposed to be more intelligent....
mailregex="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$"

# While Loop to make sure a good email address is entered
while :; do
getemail
#echo $EMAIL
if [[ $EMAIL == "NO" ]] ; then
echo "" ;
echo "" ;
echo "You have chosen to NOT" ;
echo "enter an Email address." ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
break ;
elif [[ $EMAIL =~ $mailregex ]] ; then
echo ""
echo ""
echo -e "Email address \e[36m\e[1m>> $EMAIL <<\e[0m seems valid. " ;
echo -e "\e[32m\e[1mProceeding....\e[0m" ;
break ;
else
echo "" ;
echo "" ;
echo -e "Email address \e[31m\e[1m>> $EMAIL << is INVALID.\e[0m" ;
echo "Please try again!" ;
fi
done

# First If statement checks to see if output filename was supplied when script was run
# Special checking for file named joomla so extra processing can occur
# for sorting and mailing of results as CSV file
# Cleanup any old files - remember you can place this in any folder so you need to
# Change the /root/scripts/ to what meets your requirements...
if [ -f /root/scripts/joomla ] ; then
echo "" ;
echo "" ;
echo "Cleaing up old output files..." ;
echo " -Removing File\: /root/scripts/joomla..." ;
echo " -Removing File\: joomla.sorted.csv..." ;

# If you run from another directory please change rm statement
# These files are created on a stock run-through so should be deleted
# automatically each time. Removal of files from previous runs
# Handled Here
rm -f /root/scripts/joomla /root/scripts/joomla.sorted.csv ;
echo "Finished Cleaning up old files..." ;
echo -e "\e[32m\e[1mProceeding...\e[0m" ;
fi

if [[ "$OUTFILE" != "" ]] ; then
# empty CSV file
echo -n "" > $OUTFILE ;
fi

# Change mjs (04-09-2016) Add Counter Option for easy "line numbers" later...
# Counter also is checked so that first line(s) of output are correct.
# Set Counter to One (not zero)
COUNTER=1

echo ""
echo ""
echo "Searching for Joomla Installs" ;
echo -e "\e[35m\e[1mPlease Wait...\e[0m" ;
echo ""
echo ""

# Primary If statment that recurses and finds all current Joomla Installs on Server
# Updated by MJS from original so that Drupal, Wordpress and certain Joomla folders are excluded
# This script **DOES** find joomla installs above webroots and secondary or backup installations
# We are checking for "components" folder. Since many templates and Plugins have this folder
# We need to eliminate them to speed and tighten search to legitimate Joomla installations.
for L in `find ${BASEPATH} -type d -name 'components' ! -wholename '**/app/*' ! -wholename '**/administrator/components' ! -wholename '**/administrator/*/components' ! -wholename '**/templates/*' ! -wholename '**/pagekit/*' ! -wholename '**/images/*' ! -wholename '**/media/*' ! -wholename '**/sites/*' ! -wholename '**/globalreleases/*' ! -wholename '**/wp-content/*' ! -wholename '**/concrete/*' ! -wholename '**/typo3/*' ! -wholename '**/plugins/*' ! -wholename '**/libraries/*' | grep -v '/tmp/'` ; do

# Get the base directory name for the Joomla installation
D=`dirname $L` ;

# Now that we have the correct directory for this Joomla install
# Check to see which version by testing for directory and existence of version.php
# For Joomla 1.5.x and 1.6 (We do not care about 1.x version of Joomla)
F=$D/libraries/joomla/version.php ;
# For Joomla 2.5.x and 3.x.x
F2=$D/libraries/cms/version/version.php ;

# Extract the Site from full directory... (testing)
# Works for /chroot/home - cut -d"/" -f5 may need adjusting if
# other directory depths occur (possibly script this...)
SITE=$( echo $D | cut -d"/" -f5) ;
#echo $SITE ;

# Set/Reset Variables that display findings later in script
ISOK=0 ; # ISOK holds value of whether version is Up-to-date or not
SHOWNEWEST="" ; # SHOWNEWEST holds value of latest Joomla Version (needs further work)
IMPORTANCE=0 ; # IMPORTANCE used previously - needs updating (mjs)

##BEGIN MAIN IF BLOCK
# Nested If that checks for existence of version.php
# And then Assigns F to path plus filename
# Updated mjs (04-09-2016) - F is for Joomla 1.5, 1.6, 1.7 - F2 is for Joomla 2.5 up
if [[ -e "$F" || -e "$F2" ]] ; then
##BEGIN IF BLOCK SET F VARIABLE
if [[ -e "$F" ]] ; then
F=$F ;
elif [[ -e "$F2" ]] ; then
F=$F2 ;
fi
##END IF BLOCK SET F VARIABLE

##BEGIN IF BLOCK TEST FOR RELEASE AND SUB VARIABLES
# Changed mjs (04-09-2016) - Added code to parse for const RELEASE for Joomla 3.5 and up (PHP7 compatible)
# For Joomla 1.5 through 3.4.x
if [[ `grep '$RELEASE' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ]] ; then
VERSION=`grep '$RELEASE' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ;
SUBVERSION=`grep '$DEV_LEVEL' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ;

# For Joomla 3.5 and up
elif [[ `grep 'const RELEASE' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ]] ; then
VERSION=`grep 'const RELEASE' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ;
SUBVERSION=`grep 'const DEV_LEVEL' $F | sed -r "s/^.*=\s*'(.*)'.*$/\1/g"` ;
fi
##END IF BLOCK TEST FOR RELEASE AND SUB VARIABLES

##BEGIN IF BLOCK TEST VERSION and SUBVERSION AND DECIDE ACTION Found in F (version.php)
# Rewritten mjs (04-09-2016) - Original code complex and wonky
# We want all versions under 3.4.8 Marked, Sorted and a Warning Given
echo "Version is: ${VERSION}" ;
if [ "${VERSION}" == "" ] ; then
ISOK="NOTJOOMLA" ;
echo "Site is Not Joomla! " ;

elif [ "${VERSION}" \< "2.5" ] ; then
#Version is 1.5.xx
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="EOL-1.5.xx-ARE-U-FREAKIN-NUTS?" ;
ISOK=0 ;

elif [ "${VERSION}" \< "3.0" ] ; then
# version is 2.5.xx
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="EOL-2.5.xx-UPGrade-CRITICAL" ;
ISOK=0 ;

elif [ "${VERSION}" \< "3.4" ] ; then
# version is 3.x.x but lower than 3.4
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="EOL-3.x.x-UPGrade-IMPORTANT" ;
ISOK=0 ;

elif [ "${VERSION}" == '3.4' ] && [ "${SUBVERSION}" \< "${LASTSUB34}" ] ; then
# version is 3.4 but is not latest 3.4.8 (as of 04-11-2016)
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="3.4.x-UPDate-IMPORTANT" ;
ISOK=0 ;

elif [ "${VERSION}.${SUBVERSION}" == '3.4.8' ] ; then
# version is 3.4.8 Special IMPORTANCE as of 04-11-2016
# 3.4.8 is not EOL So OK - Consider Upgrading to 3.5.x
# If you want users on 3.5.x release change SHOWNEWEST and IMPORTANCE here
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
# Important to Keep CURSUB3 variable updated in this script
IMPORTANCE="3.4.8-UPGradeE-TO-3.5.${CURSUB3}-AVAIL" ;
ISOK=0 ;

elif [ "${VERSION}" == '3.5' ] && [ "${SUBVERSION}" \< "${CURSUB3}" ] ; then
# version is 3.5 but lower than Latest
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="3.5.x-UPDate-TO-3.5.${CURSUB3}-AVAIL" ;
ISOK=0 ;

# Changed mjs (04-11-2016) - If Latest Version set ISOK=1
# rewrite status output for better SORT options later
# Also Added Output file logic (was missing in original)
# Output file is setup as CSV with Headers
else
ISOK=1 ;
SHOWNEWEST="${LATEST}.${CURSUB3}" ;
IMPORTANCE="OK" ;
# Echo out to Screen
# If This is the first time through lool then output header text to screen
if [ "${COUNTER}" == "1" ] ; then
echo "" ;
echo -e "\e[32m\e[1m*************************************" ;
echo "* Joomla Installations Found *" ;
echo -e "*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*\e[0m" ;
echo "" ;
fi
#Echo Joomla Information to Screen
echo -e "$COUNTER \e[31m\e[1m$VERSION.$SUBVERSION\e[0m found in $SITE Latest=$SHOWNEWEST Status=$IMPORTANCE" ;

# Output to File if one is supplied when the script is run
if [[ "$OUTFILE" != "" ]] ; then
echo $VERSION.$SUBVERSION,$SITE,$SHOWNEWEST,$IMPORTANCE >> $OUTFILE ;
# Increase Counter (Screen Output only)
fi

fi
##END IF BLOCK TEST VERSION AND SUBVERSION AND DECIDE ACTION

fi ;
##END MAIN IF BLOCK

##BEGIN IF BLOCK ISOK is TRUE - Writes Out-of-Date Joomla Info to Screen & OUTFILE
if [ "${ISOK}" == "NOTJOOMLA" ] ; then
echo
elif [[ $ISOK -eq 0 ]] ; then

#If This is the first time through Loop then Output Header to Screen
if [ "${COUNTER}" == "1" ] ; then
echo "" ;
echo -e "\e[32m\e[1m*************************************" ;
echo "* Joomla Installations Found *" ;
echo -e "*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*\e[0m" ;
echo "" ;
fi

# Echo Joomla Information Out to Screen
echo -e "$COUNTER \e[31m\e[1m$VERSION.$SUBVERSION\e[0m found in $SITE Latest=$SHOWNEWEST Status=$IMPORTANCE" ;

# Output to File if one is supplied when the script is run
if [[ "$OUTFILE" != "" ]] ; then
# write CSV file
echo $VERSION.$SUBVERSION,$SITE,$SHOWNEWEST,$IMPORTANCE >> $OUTFILE ;
fi

fi
##END IF BLOCK ISOK is FALSE

# Reset Variables for Next Loop
IMPORTANCE=""
# Increase Counter
((COUNTER++))

done

# Added mjs (04-10-2016)Sorting Routine to Make Output file easier to read/use
# Take OUTFILE name and add .sorted.csv for easy Excel / Spreadsheet manipulation
# Check if OUTFILE is available (remember it was added at beginning)
if [[ "$OUTFILE" != "" ]] ; then
# Echo Headers for CSV/EXCEL
echo Version,Site,Latest,Status >> $OUTFILE.sorted.csv ;

#Sort on 1st(Joomla Version) and 2nd (directory listing) Column and write out to *.sorted.csv
sort -k1 -k2 $OUTFILE >> $OUTFILE.sorted.csv ;
fi

# If output file is named joomla then email joomla.sorted.csv file using mutt (must be installed)
if [ -f "/root/scripts/joomla.sorted.csv" ] ; then

##BEGIN MAIL ROUTINE IF BLOCK
# Check to see if user set EMAIL to NO - if so then do not send email...
if [[ $EMAIL == "NO" ]] ; then
echo "" ;
echo "" ;
echo -e "\e[33m\e[1mNo Email will be sent...\e[0m" ;

else
echo "" ;
echo "" ;
echo -e "\e[32m\e[1mEmailing CSV File to \e[36m\e[1m>>$EMAIL<<\e[0m" ;
echo "Joomla Version Listing from CP1." | mutt -s "Joomla Version List" $EMAIL -a /root/scripts/joomla.sorted.csv ;
fi
##END MAIL ROUTINE IF BLOCK
fi

echo ""
echo ""
echo -e "\e[31m\e[1m************************************************************"
echo -e "\e[31m\e[1m* //Find Joomla Installs SCRIPT FINISHED PROCESSING// *"
echo -e "\e[31m\e[1m************************************************************\e[0m"

# End of Script - Exit Properly...
exit 0 ;


Share via

Related Articles

© 8Dweb LLC