- Add CMS WordPress

- Some minor bug fixes
This commit is contained in:
Christoph 2017-09-19 13:41:24 +02:00
parent 3b30a7b170
commit ef7e3de3a5
2 changed files with 112 additions and 17 deletions

View File

@ -31,6 +31,7 @@ clean_up() {
rm -f $_tmp_filename_php_56
rm -f $_tmp_filename_php_70
rm -f $_tmp_filename_php_71
rm -f $_tmp_filename_not_considered
exit $1
}
@ -267,6 +268,21 @@ echo "Website; ;PHP Version; ;PHP Engine; ;Database; ;CMS; ;DocumentRoot; ;VHost
echo ";" >> $filename_php_71
_tmp_filename_not_considered=$(mktemp)
filename_not_considered="${DST_DIR_CSV}/VHOST_FILES_NOT_CONSIDERED.csv"
cat <<EOF > ${DST_PATH_PHP}/vhost_files_not_considered.php
<?php
header('Content-Type:application/csv ; charset=utf-8');
header("Content-Disposition: attachment; filename=\"$(basename $filename_not_considered)\"");
header('Pragma: no-cache');
header('Expires: 0');
readfile("$filename_not_considered");
?>
EOF
echo "VHost file" > $filename_not_considered
echo ";" >> $filename_not_considered
cat <<EOF > ${DST_PATH_PHP}/index.php
<html>
<head>
@ -275,16 +291,21 @@ cat <<EOF > ${DST_PATH_PHP}/index.php
<body>
<ul>
<li><a href="websites_summary.php">full summary of all hosted websites</a></li>
<br />
<li><a href="websites_redirected.php">redirected websites</a></li>
<br />
<li><a href="websites_mod_php.php">websites mod_php</a></li>
<li><a href="websites_php_fpm.php">websites PHP-FPM</a></li>
<li><a href="websites_php_fcgid.php">websites FastCGI</a></li>
<br />
<li><a href="websites_php_53.php">websites PHP v5.3</a></li>
<li><a href="websites_php_54.php">websites PHP v5.4</a></li>
<li><a href="websites_php_55.php">websites PHP v5.5</a></li>
<li><a href="websites_php_56.php">websites PHP v5.6</a></li>
<li><a href="websites_php_70.php">websites PHP v7.0</a></li>
<li><a href="websites_php_71.php">websites PHP v7.1</a></li>
<br />
<li><a href="vhost_files_not_considered.php"">vhost_files not considered</a></li>
</ul>
</body>
</html>
@ -345,10 +366,27 @@ done
# -
for _vhost_file in ${_all_vhost_files_arr[@]} ; do
_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 ! $_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
if [[ -n $_documentroot ]]; then
# - Get Server Aliase
# -
@ -364,13 +402,6 @@ for _vhost_file in ${_all_vhost_files_arr[@]} ; do
server_aliases="$(echo "$(trim $server_aliases)" | tr '\n' ' ')"
# - 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)
if [[ -n $_documentroot ]] ; then
# ---
# - Get databases amd type of CMS
# ---
@ -380,6 +411,7 @@ for _vhost_file in ${_all_vhost_files_arr[@]} ; do
file_to_check="$(dirname $_documentroot)/db.inc.php"
file_to_check_mediawiki="$(dirname $_documentroot)/htdocs/LocalSettings.php"
file_to_check_wordpress="$(dirname $_documentroot)/htdocs/wp-config.php"
_found=false
if [[ -r "$file_to_check_mediawiki" ]] && [[ ! -d "$file_to_check_mediawiki" ]] ; then
@ -411,6 +443,34 @@ for _vhost_file in ${_all_vhost_files_arr[@]} ; do
site_cms="MediaWiki"
elif [[ -r "$file_to_check_wordpress" ]] && [[ ! -d "$file_to_check_wordpress" ]] ; then
db_search_string="define\('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
site_cms="WordPress"
elif [[ -r "$file_to_check" ]] && [[ ! -d "$file_to_check" ]]; then
db_search_strings=('\$db_name' '\$mysql_db')
_found=false
@ -539,15 +599,20 @@ for _vhost_file in ${_all_vhost_files_arr[@]} ; do
echo "$_server_name;;$_php_version;;$_php_engine;;$database;;$site_cms;;$_documentroot;;$_vhost_file;;$server_aliases" >> $_tmp_filename_php_71
fi
else
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;;$_redirect_site;;$_vhost_file" >> $_tmp_filename_redirected
else
echo "$_vhost_file:UNKNOWN"
_vhost_file_not_considered=true
fi
fi
if $_vhost_file_not_considered ; then
echo "$_vhost_file" >> $_tmp_filename_not_considered
fi
done
cat $_tmp_filename_summary | sort >> $filename_summary
@ -561,5 +626,6 @@ 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_not_considered | sort >> $filename_not_considered
clean_up

View File

@ -710,6 +710,7 @@ for domain in "${domain_req_for_del_arr[@]}" ; do
file_to_check="$(dirname $_doc_root)/db.inc.php"
file_to_check_mediawiki="$(dirname $_doc_root)/htdocs/LocalSettings.php"
file_to_check_wordpress="$(dirname $_doc_root)/htdocs/wp-config.php"
_found=false
if [[ -r "$file_to_check_mediawiki" ]] && [[ ! -d "$file_to_check_mediawiki" ]] ; then
@ -741,6 +742,34 @@ for domain in "${domain_req_for_del_arr[@]}" ; do
site_cms="MediaWiki"
elif [[ -r "$file_to_check_wordpress" ]] && [[ ! -d "$file_to_check_wordpress" ]] ; then
db_search_string="define\('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
site_cms="WordPress"
elif [[ -r "$file_to_check" ]] && [[ ! -d "$file_to_check" ]]; then
db_search_strings=('\$db_name' '\$mysql_db')
_found=false