@@ -74,6 +74,9 @@ function simplerisk_health_check()
7474 // Check the SimpleRisk Base URL
7575 $ check_simplerisk_base_url = check_simplerisk_base_url ();
7676
77+ // Check the SimpleRisk Base URL DNS
78+ $ check_simplerisk_base_url_dns = check_simplerisk_base_url_dns ();
79+
7780 // Check the SimpleRisk database connectivity
7881 $ check_database_connectivity = check_database_connectivity ();
7982
@@ -204,7 +207,7 @@ function simplerisk_health_check()
204207 else health_check_bad ("Extras " );
205208
206209 // Connectivity Summary
207- if ($ check_simplerisk_base_url ['result ' ] === 1 && $ check_database_connectivity ['result ' ] === 1 && $ check_api_connectivity ['result ' ] === 1 && $ check_web_connectivity_result === 1 )
210+ if ($ check_simplerisk_base_url ['result ' ] === 1 && $ check_simplerisk_base_url_dns [ ' result ' ] === 1 && $ check_database_connectivity ['result ' ] === 1 && $ check_api_connectivity ['result ' ] === 1 && $ check_web_connectivity_result === 1 )
208211 {
209212 health_check_good ("Connectivity " );
210213 }
@@ -282,6 +285,7 @@ function simplerisk_health_check()
282285 echo " <div id= \"connectivity \" style= \"display: none; \" class= \"settings_tab \"> \n" ;
283286 echo "<b><u>Connectivity</u></b><br /> " ;
284287 display_health_check_results ($ check_simplerisk_base_url );
288+ display_health_check_results ($ check_simplerisk_base_url_dns );
285289 display_health_check_results ($ check_database_connectivity );
286290 display_health_check_results ($ check_api_connectivity );
287291 display_health_check_array_results ($ check_web_connectivity );
@@ -1098,6 +1102,55 @@ function check_php_max_input_vars()
10981102 }
10991103}
11001104
1105+ /*******************************************
1106+ * FUNCTION: CHECK SIMPLERISK BASE URL DNS *
1107+ *******************************************/
1108+ function check_simplerisk_base_url_dns ()
1109+ {
1110+ // Get the server name
1111+ $ server_name = $ _SERVER ['SERVER_NAME ' ];
1112+
1113+ // Regular expression to match a domain
1114+ $ domain_regex = "/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/ " ;
1115+
1116+ // If the server name is a domain
1117+ if (filter_var ($ server_name , FILTER_VALIDATE_DOMAIN ))
1118+ {
1119+ // See if we can get a DNS record for the domain
1120+ $ result = dns_get_record ($ server_name );
1121+
1122+ // If a result was not returned
1123+ if ($ result === false )
1124+ {
1125+ return array ("result " => 0 , "text " => "The detected server name is a valid domain, but a DNS lookup was not successful. " );
1126+ }
1127+ else
1128+ {
1129+ return array ("result " => 1 , "text " => "The detected server name is a valid domain and a DNS lookup was successful. " );
1130+ }
1131+ }
1132+ // If the server name is an IP address
1133+ else if (filter_var ($ server_name , FILTER_VALIDATE_IP ))
1134+ {
1135+ return array ("result " => 1 , "text " => "The detected server name is an IP address. " );
1136+ }
1137+ else
1138+ {
1139+ // This is not a domain or IP and should be rejected
1140+ return array ("result " => 0 , "text " => "The detected server name is not a valid domain or IP address. " );
1141+ }
1142+
1143+ // If the base URL stored in settings and the one we are using are the same
1144+ if ($ simplerisk_base_url == $ base_url )
1145+ {
1146+ return array ("result " => 1 , "text " => "Your SimpleRisk Base URL matches the URL you are using to connect to SimpleRisk. " );
1147+ }
1148+ else
1149+ {
1150+ return array ("result " => 0 , "text " => "Your SimpleRisk Base URL does not match the URL you are using to connect to SimpleRisk. " );
1151+ }
1152+ }
1153+
11011154/*************************************************
11021155 * FUNCTION: UNABLE TO COMMUNICATE WITH DATABASE *
11031156 *************************************************/
0 commit comments