diff --git a/tests/tools/check_all_pages.sh b/tests/tools/check_all_pages.sh index ca5925932b..837b23e271 100755 --- a/tests/tools/check_all_pages.sh +++ b/tests/tools/check_all_pages.sh @@ -26,48 +26,76 @@ # can trigger with wget) as well. # ------------------------------------------------------------------------------ +start_time=$(date +%s.%3N) + echo "---------------------------------------------------------------------" -echo "NOTE: Check all Pages Script Starting" +echo "Check all Pages Script Starting" echo "---------------------------------------------------------------------" +# ------------------------------------------------------------------------------ # --- Website defaults +# ------------------------------------------------------------------------------ +# This script supports both http:// and https:// +# ------------------------------------------------------------------------------ WEBHOST="http://localhost/cacti"; WAUSER="admin"; WAPASS="admin"; +# ------------------------------------------------------------------------------ # --- Database defaults +# ------------------------------------------------------------------------------ DBFILE="./.my.cnf"; DBHOST="localhost"; DBNAME="cacti"; -DBPASS="cacti_user"; -DBUSER="cacti_user"; +DBPASS="cactiuser"; +DBUSER="cactiuser"; DBSLEEP=2 +# ------------------------------------------------------------------------------ # --- Shell defaults -WSOWNER="apache" -WSERROR="/var/log/httpd/error_log" -WSACCESS="/var/log/httpd/access_log" - -if id www-data > /dev/null 2>&1; then +# ------------------------------------------------------------------------------ +if id apache > /dev/null 2>&1; then + WSOWNER="apache" + WSFPM="/var/log/php-fpm/www-error.log" + case $WEBHOST in + *https*) + WSERROR="/var/log/httpd/ssl_error_log" + WSACCESS="/var/log/httpd/ssl_access_log" + ;; + *http*) + WSERROR="/var/log/httpd/error_log" + WSACCESS="/var/log/httpd/access_log" + ;; + esac +else WSOWNER="www-data" - WSERROR="/var/log/apache2/error.log" - WSACCESS="/var/log/apache2/access.log" + WSFPM="/var/log/php-fpm/www-error.log" + case $WEBHOST in + *https*) + WSERROR="/var/log/apache2/ssl_error.log" + WSACCESS="/var/log/apache2/ssl_access.log" + ;; + *http*) + WSERROR="/var/log/apache2/error.log" + WSACCESS="/var/log/apache2/access.log" + ;; + esac fi WGET_OUTPUT=$(wget 2>&1); WGET_RESULT=$? if [ $WGET_RESULT -eq 127 ]; then - echo "wget was not found, please install"; + echo "FATAL: wget was not found, please install"; #echo #echo "${WGET_OUTPUT}" exit 1 fi -while [ -n "$1" ]; do - case $1 in # ------------------------------------------------------------------------------ # Get inputs from user (Interactive mode) # ------------------------------------------------------------------------------ +while [ -n "$1" ]; do + case $1 in "--interactive") echo "Enter Database username" read -r DBUSER @@ -138,8 +166,8 @@ while [ -n "$1" ]; do done # --- Website defaults -echo "Using the following values:"; -for v in WEBHOST WAUSER WAPASS DBFILE DBHOST DBNAME DBPASS DBUSER DBSLEEP WSOWNER WSERROR WSACCESS; do +echo "NOTE: Using the following values:"; +for v in WEBHOST WAUSER WAPASS DBFILE DBHOST DBNAME DBPASS DBUSER DBSLEEP WSOWNER WSERROR WSACCESS WSFPM; do name="$v" if [[ $name == "WAPASS" || $name == "DBPASS" ]]; then value="*******" @@ -147,16 +175,19 @@ for v in WEBHOST WAUSER WAPASS DBFILE DBHOST DBNAME DBPASS DBUSER DBSLEEP WSOWNE value="${!v}" fi - printf "\t%10s | %s\n" "$name" "$value" + printf "NOTE: %-10s | %s\n" "$name" "$value" done +echo "---------------------------------------------------------------------" + export MYSQL_AUTH_USR="-u${DBUSER} -p${DBPASS}" if [ -f "$DBFILE" ]; then echo "NOTE: GitHub integration using ${DBFILE}" export MYSQL_AUTH_USR="--defaults-file=${DBFILE}" else - echo "NOTE: Script is running in non-interactive mode ensure you fill out the DB credentials!!!" + echo "NOTE: Script is running in non-interactive mode" + echo "NOTE: Ensure you've filled out the DB credentials correctly!!!" if [[ -n "${DBSLEEP}" ]]; then sleep "${DBSLEEP}" #Give user a chance to see the prompt fi @@ -193,13 +224,24 @@ if [ ! -d /tmp/check-all-pages ]; then mkdir /tmp/check-all-pages fi +# ------------------------------------------------------------------------------ +# Empty Log files +# ------------------------------------------------------------------------------ +empty_log_files() { + echo "NOTE: Emptying All Log Files" + + > "$CACTI_LOG" + > "$CACTI_ERRLOG" + > "$WSACCESS" + > "$WSFPM" + > "$WSERROR" +} + # ------------------------------------------------------------------------------ # Backup the error logs to capture what went wrong # ------------------------------------------------------------------------------ save_log_files() { - echo "---------------------------------------------------------------------" - echo "Saving All Log Files" - echo "---------------------------------------------------------------------" + echo "NOTE: Saving All Log Files" if [ $started == 1 ];then logBase="/tmp/check-all-pages/test.$(date +%s)" @@ -210,7 +252,7 @@ save_log_files() { cp "$CACTI_ERRLOG" "${logBase}/cacti_error.log" if [ -f "$WSACCESS" ] ; then - echo "NOTE: Copying {$WSACCESS} to artifacts" + echo "NOTE: Copying ${WSACCESS} to artifacts" cp "$WSACCESS" "${logBase}/apache_access.log" fi @@ -219,12 +261,17 @@ save_log_files() { cp -f "$WSERROR" "${logBase}/apache_error.log" fi + if [ -f "$WSFPM" ] ; then + echo "NOTE: Copying ${WSFPM} to artifacts" + cp "$WSFPM" "${logBase}/fpm_error.log" + fi + if [ -f "$logFile1" ]; then echo "NOTE: Copying ${logFile1} to artifacts" cp -f "$logFile1" "${logBase}/wget_error.log" fi - chmod a+r "${logBase}/*.log" + chmod a+r "${logBase}/*.log" 2>/dev/null if [ $DEBUG -eq 1 ];then echo "DEBUG: Dumping ${CACTI_LOG}" @@ -233,51 +280,59 @@ save_log_files() { cat "${CACTI_ERRLOG}" echo "DEBUG: Dumping ${WSACCESS}" cat "${WSACCESS}" + echo "DEBUG: Dumping ${WSFPM}" + cat "${WSFPM}" echo "DEBUG: Dumping ${WSERROR}" cat "${WSERROR}" fi fi } +if [ $(which mariadb) ]; then + mysql=$(which mariadb) +else + mysql=$(which mysql) +fi + # ------------------------------------------------------------------------------ # Some functions to handle settings consistently # ------------------------------------------------------------------------------ set_cacti_admin_password() { echo "NOTE: Setting Cacti admin password and unsetting forced password change" - mysql $MYSQL_AUTH_USR -e "UPDATE user_auth SET password=MD5('$WAPASS') WHERE id = 1 ;" "$DBNAME" - mysql $MYSQL_AUTH_USR -e "UPDATE user_auth SET password_change='', must_change_password='' WHERE id = 1 ;" "$DBNAME" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('secpass_forceold', '') ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "UPDATE user_auth SET password=MD5('$WAPASS') WHERE id = 1 ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "UPDATE user_auth SET password_change='', must_change_password='' WHERE id = 1 ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('secpass_forceold', '') ;" "$DBNAME" } enable_log_validation() { - echo "NOTE: Setting Cacti log validation to on to validate improperly validated variables" + echo "NOTE: Setting Cacti to log validation issues" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_validation','on') ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_validation','on') ;" "$DBNAME" } set_log_level_none() { echo "NOTE: Setting Cacti log verbosity to none" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '1') ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '1') ;" "$DBNAME" } set_log_level_normal() { echo "NOTE: Setting Cacti log verbosity to low" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '2') ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '2') ;" "$DBNAME" } set_log_level_debug() { echo "NOTE: Setting Cacti log verbosity to DEBUG" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '6') ;" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO settings (name, value) VALUES ('log_verbosity', '6') ;" "$DBNAME" } set_stderr_logging() { echo "NOTE: Setting Cacti standard error log location" - mysql $MYSQL_AUTH_USR -e "REPLACE INTO cacti.settings (name, value) VALUES ('path_stderrlog', '${CACTI_ERRLOG}');" "$DBNAME" + $mysql $MYSQL_AUTH_USR -e "REPLACE INTO cacti.settings (name, value) VALUES ('path_stderrlog', '${CACTI_ERRLOG}');" "$DBNAME" } allow_index_following() { @@ -320,10 +375,8 @@ echo "NOTE: Current Directory is $(pwd)" # ------------------------------------------------------------------------------ # Zero out the log files # ------------------------------------------------------------------------------ -> "$CACTI_LOG" -> "$CACTI_ERRLOG" -> "$WSERROR" -> "$WSACCESS" +empty_log_files + /bin/chown "$WSOWNER":"$WSOWNER" "$CACTI_LOG" /bin/chown "$WSOWNER":"$WSOWNER" "$CACTI_ERRLOG" @@ -355,20 +408,24 @@ echo "---------------------------------------------------------------------" echo "Starting Web Based Page Validation" echo "---------------------------------------------------------------------" echo "NOTE: Saving Cookie Data" -wget -q --keep-session-cookies --save-cookies "$cookieFile" --output-document="$tmpFile1" "$WEBHOST"/index.php +wget -q --no-check-certificate --keep-session-cookies --save-cookies "$cookieFile" --output-document="$tmpFile1" "$WEBHOST/index.php" -magic=$(grep "name='__csrf_magic' value=" "{$tmpFile1}" | sed "s/.*__csrf_magic' value=\"//" | sed "s/\" \/>//") +# ------------------------------------------------------------------------------ +# Prototype: var csrfMagicToken='sid:8ee86e9ddb8bcac8e377dfbb6c3d6d054854b6a9,1737054220'; +# ------------------------------------------------------------------------------ +magic=$(grep "var csrfMagicToken='" ${tmpFile1} | sed "s/.*var csrfMagicToken='//g" | sed "s/';//g") postData="action=login&login_username=${WAUSER}&login_password=${WAPASS}&__csrf_magic=${magic}" echo "NOTE: Logging into the Cacti User Interface" -wget -q $loadSaveCookie --post-data="${postData}" --output-document="${tmpFile2}" "${WEBHOST}"/index.php +wget -q --no-check-certificate $loadSaveCookie --post-data="${postData}" --output-document="${tmpFile2}" "${WEBHOST}/index.php" # ------------------------------------------------------------------------------ # Now loop over all the available links (but don't log out and don't delete or # remove, don't uninstall, enable or disable plugins stuff. # ------------------------------------------------------------------------------ -echo "NOTE: Recursively Checking all Base Pages - Note this will take several minutes!!!" -wget $loadSaveCookie --output-file="${logFile1}" --reject-regex="(logout\.php|remove|delete|uninstall|install|disable|enable)" --recursive --level=0 --execute=robots=off "${WEBHOST}"/index.php +echo "NOTE: Recursively Checking all Base and Enabled Plugin Pages" +echo "NOTE: This will take several minutes!!!" +wget --no-check-certificate $loadSaveCookie --output-file="${logFile1}" --reject-regex="(logout\.php|remove|delete|uninstall|install|disable|enable)" --recursive --level=0 --execute=robots=off "${WEBHOST}/index.php" error=$? if [ $error -eq 8 ]; then @@ -396,6 +453,10 @@ if [ $DEBUG -eq 1 ]; then echo "Output of Apache Access Log" echo "---------------------------------------------------------------------" cat "${WSACCESS}" + echo "---------------------------------------------------------------------" + echo "Output of Apache PHP-FPM Log" + echo "---------------------------------------------------------------------" + cat "${WSAFPM}" fi checks=$(grep -c "HTTP" "$logFile1") @@ -408,7 +469,7 @@ if [[ "${DEBUG}" -eq 1 ]];then fi echo "---------------------------------------------------------------------" -echo "NOTE: Displaying some page view statistics for PHP pages only" +echo "Displaying some page view statistics for PHP pages only" echo "---------------------------------------------------------------------" echo "NOTE: Page Clicks" echo "---------------------------------------------------------------------" @@ -418,7 +479,7 @@ echo "---------------------------------------------------------------------" # ------------------------------------------------------------------------------ # Finally check the cacti log for unexpected items # ------------------------------------------------------------------------------ -echo "NOTE: Checking Cacti Log for Errors" +echo "Checking Cacti Log for Errors" FILTERED_LOG="$(grep -v \ -e "AUTH LOGIN: User 'admin' authenticated" \ -e "WEBUI NOTE: Poller Resource Cache scheduled for rebuild by user admin" \ @@ -426,6 +487,9 @@ FILTERED_LOG="$(grep -v \ -e "WEBUI NOTE: Cacti DS Stats purged by user admin" \ -e "IMPORT NOTE: File is Signed Correctly" \ -e "MAILER INFO:" \ + -e "LMSENSORS" \ + -e "BOOST INFO:" \ + -e "PUSHOUT Child" \ -e "STATS:" \ -e "IMPORT Importing XML Data for " \ -e "CMDPHP SQL Backtrace: " \ @@ -434,6 +498,9 @@ FILTERED_LOG="$(grep -v \ save_log_files +end_time=$(date +%s.%3N) +total_time=$(echo "($end_time-$start_time)" | bc -l) + # ------------------------------------------------------------------------------ # Look for errors in the Log # ------------------------------------------------------------------------------ @@ -441,8 +508,10 @@ error=0 if [ -n "${FILTERED_LOG}" ] ; then echo "ERROR: Fail Unexpected output in ${CACTI_LOG}:" echo "${FILTERED_LOG}" + echo "NOTE: Total Time: $total_time seconds" exit 179 else echo "NOTE: Success No unexpected output in ${CACTI_LOG}" + echo "NOTE: Total Time: $total_time seconds" exit 0 fi