#!/usr/bin/env bash working_dir="$(dirname $(realpath $0))" conf_file="${working_dir}/conf/create_summary_websites.conf" # ------------- # - Variable settings # ------------- declare -a apache_vhost_dir_arr declare -a _all_vhost_files_arr declare -a _all_document_root_dirs_arr PHP_VERIONS_SUPPORTED="5.3 5.4 5.5 5.6 7.0.7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3" declare -i number_websites_53=0 declare -i number_websites_54=0 declare -i number_websites_55=0 declare -i number_websites_56=0 declare -i number_websites_70=0 declare -i number_websites_71=0 declare -i number_websites_72=0 declare -i number_websites_73=0 declare -i number_websites_74=0 declare -i number_websites_80=0 declare -i number_websites_81=0 declare -i number_websites_82=0 declare -i number_websites_83=0 declare -i number_redirected=0 declare -i number_parked=0 declare -i number_mod_php=0 declare -i number_php_fpm=0 declare -i number_php_fcgid=0 declare -i number_overall=0 declare -i number_no_php_assigned=0 declare -i number_not_considered=0 # ------------- # --- Some functions # ------------- clean_up() { # Perform program exit housekeeping rm -f $_tmp_filename_summary rm -f $_tmp_filename_redirected rm -f $_tmp_filename_parked rm -f $_tmp_filename_mod_php rm -f $_tmp_filename_php_fpm rm -f $_tmp_filename_php_fcgid rm -f $_tmp_filename_php_53 rm -f $_tmp_filename_php_54 rm -f $_tmp_filename_php_55 rm -f $_tmp_filename_php_56 rm -f $_tmp_filename_php_70 rm -f $_tmp_filename_php_71 rm -f $_tmp_filename_php_72 rm -f $_tmp_filename_php_73 rm -f $_tmp_filename_php_74 rm -f $_tmp_filename_php_80 rm -f $_tmp_filename_php_81 rm -f $_tmp_filename_php_82 rm -f $_tmp_filename_php_83 rm -f $_tmp_filename_not_considered rm -f $_tmp_filename_no_php_assigned exit $1 } # - Check if a given array (parameter 2) contains a given string (parameter 1) # - containsElement () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } stringContain() { [ -z "${2##*$1*}" ] && [ -z "$1" -o -n "$2" ] } # - Remove leading/trailling whitespaces # - trim() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters echo -n "$var" } fatal(){ echo "" echo -e " [ Fatal ] $*" echo "" echo -e "\tScript terminated.." echo "" clean_up 1 } trap clean_up SIGHUP SIGINT SIGTERM # ------------- # - Load Settings from configuration file get_summary_websites.conf # ------------- if [[ -f "$conf_file" ]]; then source "$conf_file" > /dev/null 2>&1 if [[ $? -ne 0 ]]; then fatal "Reading Configuration '$conf_file' failed!" fi fi if [[ -z "$WEB_DOCROOT" ]]; then fatal "Missing value for variable 'WEB_DOCROOT'!" fi if [[ -z "$DST_PATH_STATS" ]]; then DST_PATH_STATS="${WEB_DOCROOT}/website-stats" fi if [[ ! -d "$DST_PATH_STATS" ]]; then mkdir "$DST_PATH_STATS" > /dev/null 2>&1 if [[ $? -ne 0 ]]; then fatal "Creation of directory '$DST_PATH_STATS' failed!" fi fi if [[ -z "$DST_PATH_STATS" ]]; then fatal "Destination Path for statistics (parameter 'DST_PATH_STATS') not found!" fi if [[ -z "$DST_DIR_CSV" ]] ; then DST_DIR_CSV="${DST_PATH_STATS}/csv-files-website-stats" fi if [[ ! -d "$DST_DIR_CSV" ]]; then mkdir $DST_DIR_CSV > /dev/null 2>&1 if [[ $? -ne 0 ]]; then fatal "Creation of directory '$DST_DIR_CSV' failed!" fi fi if [[ -z "${WEB_DIR_CSV}" ]]; then WEB_DIR_CSV="/website-stats/csv-files-website-stats" fi _tmp_filename_summary=$(mktemp) filename_summary="${DST_DIR_CSV}/WEBSITES_SUMMARY.csv" cat < ${DST_PATH_STATS}/websites_summary.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_summary echo ";" >> $filename_summary _tmp_filename_redirected=$(mktemp) filename_redirected="${DST_DIR_CSV}/WEBSITES_REDIRECTED.csv" cat < ${DST_PATH_STATS}/websites_redirected.php EOF echo "Website; ;Alias; ;Redirected to; ;VHost file" > $filename_redirected echo ";" >> $filename_redirected _tmp_filename_parked=$(mktemp) filename_parked="${DST_DIR_CSV}/WEBSITES_PARKED.csv" cat < ${DST_PATH_STATS}/websites_parked.php EOF echo "Website; ;Alias; ;VHost file" > $filename_parked echo ";" >> $filename_parked _tmp_filename_mod_php=$(mktemp) filename_mod_php="${DST_DIR_CSV}/WEBSITES_MOD_PHP.csv" cat < ${DST_PATH_STATS}/websites_mod_php.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_mod_php echo ";" >> $filename_mod_php _tmp_filename_php_fpm=$(mktemp) filename_php_fpm="${DST_DIR_CSV}/WEBSITES_PHP_FPM.csv" cat < ${DST_PATH_STATS}/websites_php_fpm.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_fpm echo ";" >> $filename_php_fpm _tmp_filename_php_fcgid=$(mktemp) filename_php_fcgid="${DST_DIR_CSV}/WEBSITES_PHP_FCGID.csv" cat < ${DST_PATH_STATS}/websites_php_fcgid.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_fcgid echo ";" >> $filename_php_fcgid _tmp_filename_php_53=$(mktemp) filename_php_53="${DST_DIR_CSV}/WEBSITES_PHP_53.csv" cat < ${DST_PATH_STATS}/websites_php_53.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_53 echo ";" >> $filename_php_53 _tmp_filename_php_54=$(mktemp) filename_php_54="${DST_DIR_CSV}/WEBSITES_PHP_54.csv" cat < ${DST_PATH_STATS}/websites_php_54.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_54 echo ";" >> $filename_php_54 _tmp_filename_php_55=$(mktemp) filename_php_55="${DST_DIR_CSV}/WEBSITES_PHP_55.csv" cat < ${DST_PATH_STATS}/websites_php_55.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_55 echo ";" >> $filename_php_55 _tmp_filename_php_56=$(mktemp) filename_php_56="${DST_DIR_CSV}/WEBSITES_PHP_56.csv" cat < ${DST_PATH_STATS}/websites_php_56.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_56 echo ";" >> $filename_php_56 _tmp_filename_php_70=$(mktemp) filename_php_70="${DST_DIR_CSV}/WEBSITES_PHP_70.csv" cat < ${DST_PATH_STATS}/websites_php_70.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_70 echo ";" >> $filename_php_70 _tmp_filename_php_71=$(mktemp) filename_php_71="${DST_DIR_CSV}/WEBSITES_PHP_71.csv" cat < ${DST_PATH_STATS}/websites_php_71.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_71 echo ";" >> $filename_php_71 _tmp_filename_php_72=$(mktemp) filename_php_72="${DST_DIR_CSV}/WEBSITES_PHP_72.csv" cat < ${DST_PATH_STATS}/websites_php_72.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_72 echo ";" >> $filename_php_72 _tmp_filename_php_73=$(mktemp) filename_php_73="${DST_DIR_CSV}/WEBSITES_PHP_73.csv" cat < ${DST_PATH_STATS}/websites_php_73.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_73 echo ";" >> $filename_php_73 _tmp_filename_php_74=$(mktemp) filename_php_74="${DST_DIR_CSV}/WEBSITES_PHP_74.csv" cat < ${DST_PATH_STATS}/websites_php_74.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_74 echo ";" >> $filename_php_74 _tmp_filename_php_80=$(mktemp) filename_php_80="${DST_DIR_CSV}/WEBSITES_PHP_80.csv" cat < ${DST_PATH_STATS}/websites_php_80.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_80 echo ";" >> $filename_php_80 _tmp_filename_php_81=$(mktemp) filename_php_81="${DST_DIR_CSV}/WEBSITES_PHP_81.csv" cat < ${DST_PATH_STATS}/websites_php_81.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_81 echo ";" >> $filename_php_81 _tmp_filename_php_82=$(mktemp) filename_php_82="${DST_DIR_CSV}/WEBSITES_PHP_82.csv" cat < ${DST_PATH_STATS}/websites_php_82.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_82 echo ";" >> $filename_php_82 _tmp_filename_php_83=$(mktemp) filename_php_83="${DST_DIR_CSV}/WEBSITES_PHP_83.csv" cat < ${DST_PATH_STATS}/websites_php_83.php EOF echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost file; ;Server Alias(es)" > $filename_php_83 echo ";" >> $filename_php_83 _tmp_filename_not_considered=$(mktemp) filename_not_considered="${DST_DIR_CSV}/VHOST_FILES_NOT_CONSIDERED.csv" cat < ${DST_PATH_STATS}/vhost_files_not_considered.php EOF echo "VHost file" > $filename_not_considered echo ";" >> $filename_not_considered _tmp_filename_no_php_assigned=$(mktemp) filename_no_php_assigned="${DST_DIR_CSV}/WEBSITES_NO_PHP_FOUND.csv" cat < ${DST_PATH_STATS}/websites_no_php_found.php EOF echo "VHost file" > $filename_no_php_assigned echo ";" >> $filename_no_php_assigned # ----- # - Gathering global settings # ----- # - Check if mod_php is installed. # - mod_php_installed=false if $(httpd -M | grep -q -E "php[5-9]?_module" 2>/dev/null) ; then mod_php_installed=true if $(apachectl status | grep -q "PHP/" 2>/dev/null) ; then MOD_PHP_VERSION="$(trim $(apachectl status | grep "PHP/" | cut -d '/' -f2))" else MOD_PHP_VERSION=" UNKNOWN" warn "'mod_php' ist running, but i cannot dermin the PHP Version.\n 'apachectl status' does not work on this server." fi fi # - Try to find apache vhost configuration directories # - if [[ -d "/usr/local/apache2/conf/vhosts" ]]; then apache_vhost_dir_arr+=("/usr/local/apache2/conf/vhosts") #if [[ -d "/usr/local/apache2/conf/vhosts/0" ]]; then while IFS='' read -r -d '' dirname ; do if ! containsElement "$(realpath $dirname)" "${apache_vhost_dir_arr[@]}" ; then apache_vhost_dir_arr+=("$(realpath $dirname)") fi done < <(find /usr/local/apache2/conf/vhosts -mindepth 1 -maxdepth 1 -type d -print0) #else #fi elif [[ -d "/etc/apache2/sites-enabled" ]]; then apache_vhost_dir_arr+=("/etc/apache2/sites-enabled") fi # - Create Array of all active VHost configurations # - for apache_vhost_dir in ${apache_vhost_dir_arr[@]} ; do # - Collect all VHost files # - while IFS='' read -r -d '' filename ; do if ! containsElement "$(realpath $filename)" "${_all_vhost_files_arr[@]}" ; then _all_vhost_files_arr+=("$(realpath $filename)") fi done < <(find $apache_vhost_dir -mindepth 1 -maxdepth 1 -name '*.conf' -print0) done # - Create summary files # - for _vhost_file in ${_all_vhost_files_arr[@]} ; do [[ "$(basename $(dirname "$_vhost_file"))" == "DELETED" ]] && continue [[ "$(basename $(dirname "$_vhost_file"))" == "BAK" ]] && continue _documentroot="" _vhost_file_not_considered=false # - Get Server Name # - _server_name=$(grep -i -E "^\s*ServerName" $_vhost_file | sed -e "s/ServerName//" | sed "s/^\s*//" | sed "s/\s*$//" | sort -u) if [[ $_server_name =~ localhost ]]; then _vhost_file_not_considered=true fi if [[ $_server_name =~ ^dummy ]]; then _vhost_file_not_considered=true fi ((number_overall++)) if ! $_vhost_file_not_considered ; then # - Get documetroot of current VHost configuration file # - _documentroot=$(grep -E "^\s*DocumentRoot" $_vhost_file 2> /dev/null | awk '{print$2}' | sed 's/"//g' | sed 's/\/$//' | sort -u) fi # - Get Server Aliase # - _server_aliases=$(grep -i -E "^\s*ServerAlias" $_vhost_file | sed -e "s/ServerAlias//" | sed "s/^\s*//" | sed "s/\s*$//" | sort -u) server_aliases="" if [[ -n "$_server_aliases" ]] ; then for _server_alias in $_server_aliases ; do server_aliases="$server_aliases $_server_alias" done fi server_aliases="$(echo "$(trim $server_aliases)" | tr '\n' ' ')" if [[ $_documentroot =~ /var/www/html/projekte/PARKED/htdocs ]] \ || [[ $_documentroot =~ /var/www/PARKED/htdocs ]]; then echo "$_server_name;;$server_aliases;;$_vhost_file" >> $_tmp_filename_parked ((number_parked++)) elif [[ -n $_documentroot ]]; then # --- # - Get databases amd type of CMS # --- site_cms="Unknown" database="Not found" cms_version="Unkown" file_to_check="$(dirname $_documentroot)/db.inc.php" file_to_check_mediawiki="${_documentroot}/LocalSettings.php" file_to_check_wordpress="${_documentroot}/wp-config.php" file_to_check_drupal="${_documentroot}/sites/default/settings.php" file_to_check_typo3="${_documentroot}/typo3conf/LocalConfiguration.php" file_to_check_redaxo="${_documentroot}/redaxo/include/master.inc.php" _found=false if [[ -r "$file_to_check_mediawiki" ]] && [[ ! -d "$file_to_check_mediawiki" ]] ; then db_search_string='\$wgDBname' #db_search_string='\$wgEnableUserEmail' _found=false if grep -i -q "$db_search_string" $file_to_check_mediawiki > /dev/null 2>&1 ; then database="$(grep -i "$db_search_string" $file_to_check_mediawiki 2> /dev/null \ | awk -F '=' '{print$2}' \ | awk -F ';' '{print$1}'\ | tail -1)" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Remove leading single quote database="${database#"${database%%[!\']*}"}" # - Remove trailing single quote database="${database%"${database##*[!\']}"}" # - Remove leading double quote database="${database#"${database%%[!\"]*}"}" # - Remove trailing double quote database="${database%"${database##*[!\"]}"}" _found=true fi _found_mediawiki_version=false if [[ -f "${_documentroot}/includes/Defines.php" ]]; then version_search_string="define\(\\s*'MW_VERSION'" cms_version="$(grep -i -E "^\s*$version_search_string" ${_documentroot}/includes/Defines.php 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" [[ -n "$cms_version" ]] && _found_mediawiki_version=true fi if ! $_found_mediawiki_version && [[ -f "${_documentroot}/includes/DefaultSettings.php" ]]; then version_search_string='\$wgVersion\s+=' cms_version="$(grep -i -E "^\s*$version_search_string" "${_documentroot}/includes/DefaultSettings.php" 2> /dev/null \ | awk -F '=' '{print$2}' \ | awk -F ';' '{print$1}'\ | tail -1)" [[ -n "$cms_version" ]] && _found_mediawiki_version=true fi if $_found_mediawiki_version ; then # - Remove leading whitespace characters cms_version="${cms_version#"${cms_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters cms_version="${cms_version%"${cms_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters cms_version="${cms_version%"${cms_version##*[!;]}"}" # - Remove trailing whitespace characters cms_version="${cms_version#"${cms_version%%[!\']*}"}" # - Remove trailing inverted comma characters cms_version="${cms_version%"${cms_version##*[!\']}"}" fi site_cms="MediaWiki $cms_version" elif [[ -r "$file_to_check_wordpress" ]] && [[ ! -d "$file_to_check_wordpress" ]] ; then db_search_string="define\(\\s*'DB_NAME'" _found=false if grep -i -q -E "^\s*$db_search_string" $file_to_check_wordpress > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$db_search_string" $file_to_check_wordpress 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true fi if [[ -f "${_documentroot}/wp-includes/version.php" ]]; then version_search_string='\$wp_version\s+=' cms_version="$(grep -i -E "^\s*$version_search_string" ${_documentroot}/wp-includes/version.php 2> /dev/null \ | awk -F '=' '{print$2}' \ | tail -1 )" # - Remove leading whitespace characters cms_version="${cms_version#"${cms_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters cms_version="${cms_version%"${cms_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters cms_version="${cms_version%"${cms_version##*[!;]}"}" # - Remove trailing whitespace characters cms_version="${cms_version#"${cms_version%%[!\']*}"}" # - Remove trailing inverted comma characters cms_version="${cms_version%"${cms_version##*[!\']}"}" fi site_cms="WordPress $cms_version" elif [[ -r "$file_to_check_drupal" ]] && [[ ! -d "$file_to_check_drupal" ]] ; then db_search_string="'database'\s+=>" _found=false if grep -i -q -E "^\s*$db_search_string" $file_to_check_drupal > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$db_search_string" $file_to_check_drupal 2> /dev/null \ | awk -F '=>' '{print$2}' \ | awk -F ',' '{print$1}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true fi _found_drupal_version=false if [[ -f "${_documentroot}/modules/system/system.module" ]] ; then version_search_string="define\\s*\(\\s*'VERSION'" cms_version="$(grep -i -E "^\s*$version_search_string" ${_documentroot}/modules/system/system.module 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" [[ -n "$cms_version" ]] && _found_drupal_version=true fi if ! $_found_drupal_version && [[ -f "${_documentroot}/includes/bootstrap.inc" ]] ; then version_search_string="define\\s*\(\\s*'VERSION'" cms_version="$(grep -i -E "^\s*$version_search_string" ${_documentroot}/includes/bootstrap.inc 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" [[ -n "$cms_version" ]] && _found_drupal_version=true fi if ! $_found_drupal_version && [[ -f "${_documentroot}/core/lib/Drupal.php" ]] ; then version_search_string="const\\s+VERSION\\s+=" cms_version="$(grep -i -E "^\s*$version_search_string" "${_documentroot}/core/lib/Drupal.php" 2> /dev/null \ | awk -F ' ' '{print$4}' \ | tail -1 )" [[ -n "$cms_version" ]] && _found_drupal_version=true fi if $_found_drupal_version ; then # - Remove leading whitespace characters cms_version="${cms_version#"${cms_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters cms_version="${cms_version%"${cms_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters cms_version="${cms_version%"${cms_version##*[!;]}"}" # - Remove trailing whitespace characters cms_version="${cms_version#"${cms_version%%[!\']*}"}" # - Remove trailing inverted comma characters cms_version="${cms_version%"${cms_version##*[!\']}"}" fi site_cms="Drupal $cms_version" elif [[ -r "$file_to_check_typo3" ]] && [[ ! -d "$file_to_check_typo3" ]] ; then db_search_string="'database'\s+=>" _found=false if grep -i -q -E "^\s*$db_search_string" $file_to_check_typo3 > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$db_search_string" $file_to_check_typo3 2> /dev/null \ | awk -F '=>' '{print$2}' \ | awk -F ',' '{print$1}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true fi if [[ -f "${_documentroot}/typo3_src/ChangeLog" ]] ; then version_search_string='\[RELEASE\]\s+Release\s+of\s+TYPO3' cms_version="$(grep -i -m 1 -E "$version_search_string" ${_documentroot}/typo3_src/ChangeLog 2> /dev/null \ | grep -o -E "\s+[0-9]+.[0-9]+.[0-9]+\s+")" # - Remove leading whitespace characters cms_version="${cms_version#"${cms_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters cms_version="${cms_version%"${cms_version##*[![:space:]]}"}" fi site_cms="Typo3 $cms_version" elif [[ -r "$file_to_check_redaxo" ]] && [[ ! -d "$file_to_check_redaxo" ]] ; then db_search_string="\\\$REX\['DB'\]\['1'\]\['NAME'\]\s+=" _found=false if grep -i -q -E "^\s*$db_search_string" $file_to_check_redaxo > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$db_search_string" $file_to_check_redaxo 2> /dev/null \ | awk -F '=' '{print$2}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true fi main_version_search_string="\\\$REX\['VERSION'\]\s+=" if grep -i -q -E "^\s*$main_version_search_string" $file_to_check_redaxo > /dev/null 2>&1 ; then main_version="$(grep -i -E "^\s*$main_version_search_string" $file_to_check_redaxo 2> /dev/null \ | awk -F '=' '{print$2}' \ | tail -1 )" # - Remove leading whitespace characters main_version="${main_version#"${main_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters main_version="${main_version%"${main_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters main_version="${main_version%"${main_version##*[!;]}"}" # - Remove trailing whitespace characters main_version="${main_version#"${main_version%%[!\']*}"}" # - Remove trailing inverted comma characters main_version="${main_version%"${main_version##*[!\']}"}" # - Remove leading single quote main_version="${main_version#"${main_version%%[!\']*}"}" # - Remove trailing single quote main_version="${main_version%"${main_version##*[!\']}"}" # - Remove leading double quote main_version="${main_version#"${main_version%%[!\"]*}"}" # - Remove trailing double quote main_version="${main_version%"${main_version##*[!\"]}"}" sub_version_search_string="\\\$REX\['SUBVERSION'\]\s+=" if grep -i -q -E "^\s*$sub_version_search_string" $file_to_check_redaxo > /dev/null 2>&1 ; then sub_version="$(grep -i -E "^\s*$sub_version_search_string" $file_to_check_redaxo 2> /dev/null \ | awk -F '=' '{print$2}' \ | tail -1 )" # - Remove leading whitespace characters sub_version="${sub_version#"${sub_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters sub_version="${sub_version%"${sub_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters sub_version="${sub_version%"${sub_version##*[!;]}"}" # - Remove trailing whitespace characters sub_version="${sub_version#"${sub_version%%[!\']*}"}" # - Remove trailing inverted comma characters sub_version="${sub_version%"${sub_version##*[!\']}"}" # - Remove leading single quote sub_version="${sub_version#"${sub_version%%[!\']*}"}" # - Remove trailing single quote sub_version="${sub_version%"${sub_version##*[!\']}"}" # - Remove leading double quote sub_version="${sub_version#"${sub_version%%[!\"]*}"}" # - Remove trailing double quote sub_version="${sub_version%"${sub_version##*[!\"]}"}" minor_version_search_string="\\\$REX\['MINORVERSION'\]\s+=" if grep -i -q -E "^\s*$minor_version_search_string" $file_to_check_redaxo > /dev/null 2>&1 ; then minor_version="$(grep -i -E "^\s*$minor_version_search_string" $file_to_check_redaxo 2> /dev/null \ | awk -F '=' '{print$2}' \ | tail -1 )" # - Remove leading whitespace characters minor_version="${minor_version#"${minor_version%%[![:space:]]*}"}" # - Remove trailing whitespace characters minor_version="${minor_version%"${minor_version##*[![:space:]]}"}" # - Rmove trailing semicolon characters minor_version="${minor_version%"${minor_version##*[!;]}"}" # - Remove trailing whitespace characters minor_version="${minor_version#"${minor_version%%[!\']*}"}" # - Remove trailing inverted comma characters minor_version="${minor_version%"${minor_version##*[!\']}"}" # - Remove leading single quote minor_version="${minor_version#"${minor_version%%[!\']*}"}" # - Remove trailing single quote minor_version="${minor_version%"${minor_version##*[!\']}"}" # - Remove leading double quote minor_version="${minor_version#"${minor_version%%[!\"]*}"}" # - Remove trailing double quote minor_version="${minor_version%"${minor_version##*[!\"]}"}" else minor_version="?" fi else sub_version="?" minor_version="?" fi cms_version="${main_version}.${sub_version}.$minor_version" fi site_cms="REDAXO $cms_version" elif [[ -r "$file_to_check" ]] && [[ ! -d "$file_to_check" ]]; then db_search_strings=('\$db_name' '\$mysql_db') _found=false for _string in ${db_search_strings[@]} ; do if grep -i -q -E "^\s*$_string" $file_to_check > /dev/null 2>&1 ; then database="$(grep -i -E "^\s*$_string" $file_to_check 2> /dev/null | awk -F '=' '{print$2}' | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Rmove trailing semicolon characters database="${database%"${database##*[!;]}"}" # - Remove trailing whitespace characters database="${database#"${database%%[!\']*}"}" # - Remove trailing inverted comma characters database="${database%"${database##*[!\']}"}" _found=true break fi done if ! $_found ; then file_to_check="${_documentroot}/includes/config.inc.php" if [[ -f "$file_to_check" ]]; then if grep -i -q -E "^\s*define\s*\(\s*'DB_DATABASE'" $file_to_check > /dev/null 2>&1 ; then database="$(grep -i -m 1 -E "^\s*define\s*\(\s*'DB_DATABASE'" $file_to_check 2> /dev/null \ | awk -F ',' '{print$2}' \ | awk -F ')' '{print$1}' \ | tail -1 )" # - Remove leading whitespace characters database="${database#"${database%%[![:space:]]*}"}" # - Remove trailing whitespace characters database="${database%"${database##*[![:space:]]}"}" # - Remove leading single quote database="${database#"${database%%[!\']*}"}" # - Remove trailing single quote database="${database%"${database##*[!\']}"}" # - Remove leading double quote database="${database#"${database%%[!\"]*}"}" # - Remove trailing double quote database="${database%"${database##*[!\"]}"}" _found=true fi fi fi site_cms="Kontext" fi # - Get PHP version of current vhost configuration file # - _php_engine="" _php_version="" CUR_IFS=$IFS IFS='' if grep -q -E "^\s*(ProxyPassMatch|SetHandler).*php-[5-9]\.[0-9]+-" $_vhost_file 2> /dev/null ; then _php_engine="PHP FPM" if grep -q -E "^\s*(SetHandler).*php-[5-9]\.[0-9]+-" $_vhost_file 2> /dev/null ; then _php_fpm_socket="$(grep -E "^\s*(SetHandler).*php-[5-9]\.[0-9]+-" $_vhost_file 2> /dev/null \ | head -1 | cut -d ':' -f3 | cut -d'|' -f1)" else _php_fpm_socket= fi if [[ -S "$_php_fpm_socket" ]] ; then _php_version="$(exec /usr/local/php-$(echo "$_php_fpm_socket" | grep -o -E "[5-9]\.[0-9]")/bin/php -v \ | head -1 | awk '{print$2}')" else _php_version="UNKNOWN" fi echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_fpm ((number_php_fpm++)) elif grep -d skip -q -E "^\s*FCGIWrapper\s+.*\.php" $_vhost_file 2> /dev/null ; then _php_engine="PHP FastCGI" _fcgid_file="$(grep -E "^\s*FCGIWrapper\s+.*\.php" $_vhost_file 2> /dev/null \ | head -1 | awk '{print$2}')" if [[ -f "$_fcgid_file" ]] ; then _php_version="$($(grep "exec" $_fcgid_file | awk '{print$2}') -v | head -1 | awk '{print$2}')" [[ -z "$_php_version" ]] && _php_version="unknown Version" else _php_version="UNKNOWN" fi echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_fcgid ((number_php_fcgid++)) elif $mod_php_installed ; then _php_engine="Apache Handler" _php_version="$MOD_PHP_VERSION" echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_mod_php ((number_mod_php++)) else _php_version="No PHP assigned" _php_engine="" echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_no_php_assigned ((number_no_php_assigned++)) fi echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_summary if [[ "$_php_version" =~ ^5.3 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_53 ((number_websites_53++)) fi if [[ "$_php_version" =~ ^5.4 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_54 ((number_websites_54++)) fi if [[ "$_php_version" =~ ^5.5 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_55 ((number_websites_55++)) fi if [[ "$_php_version" =~ ^5.6 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_56 ((number_websites_56++)) fi if [[ "$_php_version" =~ ^7.0 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_70 ((number_websites_70++)) fi if [[ "$_php_version" =~ ^7.1 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_71 ((number_websites_71++)) fi if [[ "$_php_version" =~ ^7.2 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_72 ((number_websites_72++)) fi if [[ "$_php_version" =~ ^7.3 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_73 ((number_websites_73++)) fi if [[ "$_php_version" =~ ^7.4 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_74 ((number_websites_74++)) fi if [[ "$_php_version" =~ ^8.0 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_80 ((number_websites_80++)) fi if [[ "$_php_version" =~ ^8.1 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_81 ((number_websites_81++)) fi if [[ "$_php_version" =~ ^8.2 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_82 ((number_websites_82++)) fi if [[ "$_php_version" =~ ^8.3 ]]; then echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_83 ((number_websites_83++)) fi elif ! $_vhost_file_not_considered ; then _redirect_site="" _redirect_site=$(grep -E "^\s*RewriteRule" $_vhost_file 2> /dev/null | awk '{print$3}' | sed 's/"//g' | sed 's/\/$//' | sed 's/https\?:\/\///g' | sed 's/\$1//g' | sort -u) if [[ -n "$_redirect_site" ]] ; then echo "$_server_name;;$server_aliases;;$_redirect_site;;$_vhost_file" >> $_tmp_filename_redirected ((number_redirected++)) else _vhost_file_not_considered=true fi fi if $_vhost_file_not_considered ; then echo "$_vhost_file" >> $_tmp_filename_not_considered ((number_not_considered++)) ((number_overall--)) fi done cat $_tmp_filename_summary | sort >> $filename_summary cat $_tmp_filename_redirected | sort >> $filename_redirected cat $_tmp_filename_parked | sort >> $filename_parked cat $_tmp_filename_mod_php | sort >> $filename_mod_php cat $_tmp_filename_php_fpm | sort >> $filename_php_fpm cat $_tmp_filename_php_fcgid | sort >> $filename_php_fcgid cat $_tmp_filename_php_53 | sort >> $filename_php_53 cat $_tmp_filename_php_54 | sort >> $filename_php_54 cat $_tmp_filename_php_55 | sort >> $filename_php_55 cat $_tmp_filename_php_56 | sort >> $filename_php_56 cat $_tmp_filename_php_70 | sort >> $filename_php_70 cat $_tmp_filename_php_71 | sort >> $filename_php_71 cat $_tmp_filename_php_72 | sort >> $filename_php_72 cat $_tmp_filename_php_73 | sort >> $filename_php_73 cat $_tmp_filename_php_74 | sort >> $filename_php_74 cat $_tmp_filename_php_80 | sort >> $filename_php_80 cat $_tmp_filename_php_81 | sort >> $filename_php_81 cat $_tmp_filename_php_82 | sort >> $filename_php_82 cat $_tmp_filename_not_considered | sort >> $filename_not_considered cat $_tmp_filename_no_php_assigned | sort >> $filename_no_php_assigned # ----- # - Create summary file index.php # ----- if [[ -f "${DST_PATH_STATS}/index.php" ]]; then rm "${DST_PATH_STATS}/index.php" fi cat < ${DST_PATH_STATS}/index.html Statistics websites $(hostname -f)

$(hostname -f)

    EOF if [[ $number_overall -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • full summary of all hosted websites: $number_overall
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • full summary of all hosted websites: $number_overall
  • EOF fi cat <> ${DST_PATH_STATS}/index.html
    EOF if [[ $number_redirected -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • redirected websites: $number_redirected
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • redirected websites: $number_redirected
  • EOF fi if [[ $number_parked -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • parked websites: $number_parked
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • parked websites: $number_parked
  • EOF fi cat <> ${DST_PATH_STATS}/index.html
    EOF if [[ $number_mod_php -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites mod_php: $number_mod_php
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • websites mod_php: $number_mod_php
  • EOF fi if [[ $number_php_fpm -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP-FPM: $number_php_fpm
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • websites PHP-FPM: $number_php_fpm
  • EOF fi if [[ $number_php_fcgid -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites FastCGI: $number_php_fcgid
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • websites FastCGI: $number_php_fcgid
  • EOF fi cat <> ${DST_PATH_STATS}/index.html
    EOF if [[ $number_no_php_assigned -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites no PHP assigned: $number_no_php_assigned
  • EOF else cat <> ${DST_PATH_STATS}/index.html
  • websites no PHP assigned: $number_no_php_assigned
  • EOF fi cat <> ${DST_PATH_STATS}/index.html


PHP versions supported by this script:
    $PHP_VERIONS_SUPPORTED
    EOF if [[ $number_websites_53 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v5.3: $number_websites_53
  • EOF fi if [[ $number_websites_54 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v5.4: $number_websites_54
  • EOF fi if [[ $number_websites_55 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v5.5: $number_websites_55
  • EOF fi if [[ $number_websites_56 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v5.6: $number_websites_56
  • EOF fi if [[ $number_websites_70 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v7.0: $number_websites_70
  • EOF fi if [[ $number_websites_71 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v7.1: $number_websites_71
  • EOF fi if [[ $number_websites_72 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v7.2: $number_websites_72
  • EOF fi if [[ $number_websites_73 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v7.3: $number_websites_73
  • EOF fi if [[ $number_websites_74 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v7.4: $number_websites_74
  • EOF fi if [[ $number_websites_80 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v8.0: $number_websites_80
  • EOF fi if [[ $number_websites_81 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v8.1: $number_websites_81
  • EOF fi if [[ $number_websites_82 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v8.2: $number_websites_82
  • EOF fi if [[ $number_websites_83 -gt 0 ]]; then cat <> ${DST_PATH_STATS}/index.html
  • websites PHP v8.3: $number_websites_83
  • EOF fi cat <> ${DST_PATH_STATS}/index.html
EOF clean_up