Nk_robots_check
Description
This function, nk_robots_check()
, generates a table with information about the robots.txt file
, xmlrpc-blocked status
, and wp-cron-disabled
status for each domain found on the server using the nk_list_all_domains() function.
The function calls several helper functions to find the status for each of these items, which are find_robot_status(), find_xmlrpc_status(), and find_wp_cron_status().
find_robot_status()
: finds whether a robots.txt file
exists in the domain’s document root directory.
find_xmlrpc_status()
: checks whether xmlrpc has been blocked
. It does this by checking if the site’s .htaccess
file has any xmlrpc lines in it. If it does not, it sets the result to “No”. If there is a serverwide block, it sets the result to “N/A”.
find_wp_cron_status()
: checks whether wp-cron has been disabled in the wp-config file
. If there is no wp-config.php
file in the domain’s document root, it sets the result to “N/A”. If “DISABLE_WP_CRON” is not inside of the wp-config.php file inside of the domain’s document root, it sets the result to “No”. Otherwise, it sets the result to “Yes”.
gen_robots_check()
: prints out a header for the table and then loops through each domain found on the server using nk_list_all_domains(). For each domain, it populates the variables docroot, robot_status, xmlrpc_blocked, and wp_cron using the helper functions, and then writes out a row in the table with these values.
Finally, the table is formatted using the column
-t command.
Example
[root@cloudvpsserver ~]# nk_robots_check Domain │ robots.txt xmlrpc-blocked wp-cron-disabled │ nkern.net │ No Yes N/A │
Code
nk_robots_check() { # nk_robots_check is basically just a wrapper for gen_robots_check that does some formatting. #### First we need to define some functions we'll use later. #### find_robot_status() { # Find whether a robots.txt file exists in the domains docroot. # Next we can determine where the robots.txt should be by appending it to docroot. robot_location="$docroot/robots.txt" # If a file exists in $robot_location. if [ -f "$robot_location" ]; then # Print Yes and exit. echo "Yes" return 0 fi # Otherwise print No. echo "No" } find_xmlrpc_status() { # Find whether xmlrpc has been blocked. # If the site's .htaccess doesn't have any xmlrpc lines in it if [ "$(grep -c "xmlrpc" "$docroot"/.htaccess 2>/dev/null)" = "0" ] ; then # Then set result to "No" result="No" else # Otherwise set the result to "Yes" result="Yes" fi # However it's possible there's a serverwide block. # Check if that's present. if [ "$(grep -c "xmlrpc" /etc/apache2/conf.d/includes/pre_virtualhost_global.conf )" != "0" ]; then # If it is then set the result to "N/A" result="N/A" fi # Then print out the value of result. echo "$result" } find_wp_cron_status() { # Find whether wp-cron has been disabled in the wp-config file. # If there is no wp-config.php file inside of docroot. if [ ! -f "$docroot"/wp-config.php ] ; then # Then it's probably not a WordPress site, print N/A and exit. echo "N/A" return 0 fi # If "DISABLE_WP_CRON" is not inside of the wp-config.php file inside of docroot. if [ "$(grep -ic "DISABLE_WP_CRON" "$docroot"/wp-config.php 2>/dev/null)" = "0" ]; then # Then print "No" and exit. echo "No" return 0 else # Otherwise print Yes and exit. echo "Yes" return 0 fi } # Now we can get started with the function to print table rows. gen_robots_check() { # First print out the header for the table. echo "Domain │ robots.txt xmlrpc-blocked wp-cron-disabled │" # Then for every sites found on the server using nk_list domains. for domain in $(nk_list_all_domains); do # Populate variables. # docroot is the result of running nk_docroot on the domain. This is needed for several of the functions to work. # robots_status is the result of find_robots_status # xmlrpc_blocked is the result of find_xmlrpc_status docroot="$(nk_docroot "$domain")" robot_status="$(find_robot_status)" xmlrpc_blocked="$(find_xmlrpc_status)" wp_cron="$(find_wp_cron_status)" # Now that the variables are populated. Write out the table row. echo "$domain │ $robot_status $xmlrpc_blocked $wp_cron │" done } # Lastly run gen_robots_check and format it as a table. gen_robots_check | column -t }