FAILED' : 'PASSED';
return theme('image', drupal_get_path('module','subdomain') ."/images/icon_$file_suffix.png",NULL,NULL,array('style'=>"float:left;margin-right:5px;")) ." $suffix";
}
function subdomain_check_server() {
$output = "SUBDOMAIN TEST\n";
$output.= $_SERVER['HTTP_HOST'] ."\n";
$output.= ltrim(request_uri(),'/') ."\n"; // Use Drupal API's request URI, since REQUEST_URI Apache only
$output.= ltrim($_SERVER['QUERY_STRING'], 'q=') ."\n";
$output.= $_SERVER['SCRIPT_FILENAME'];
print $output;
exit;
}
function subdomain_check_apache_details($url, $results) {
$rows[] = array('HTTP_HOST:', $results[1]);
$rows[] = array('QUERY_STRING:', $results[2]);
$rows[] = array('REQUEST_URI:', $results[3]);
$rows[] = array('SCRIPT_FILENAME:', $results[4]);
$output = "
HTTP request to $url returned the following result:
";
$output.= theme('table', array(), $rows);
return $output;
}
function subdomain_check_watchdog_lastid() {
return db_result(db_query("SELECT max(wid) FROM {watchdog}"));
}
function subdomain_check_apache() {
$domain = subdomain_base_domain();
$host = "subdomain-test.$domain";
$url = "http://$host/subdomain/test";
// Store watchdog count so we can check for errors after http attempt
$old_watchdog_lastid = subdomain_check_watchdog_lastid();
$page = file_get_contents($url,"r");
// Check for any errors (assumes 1 error for now)
$new_watchdog_lastid = subdomain_check_watchdog_lastid();
if ($new_watchdog_lastid > $old_watchdog_count) {
$error = db_result(db_query("SELECT message FROM {watchdog} WHERE wid = %d AND type = 'php'", $new_watchdog_lastid));
$error404 = strpos($error, '404') !== FALSE ? TRUE : FALSE;
}
$lines = explode("\n", $page);
$result = subdomain_check_apache_details($url, $lines);
if ($lines[0] == 'SUBDOMAIN TEST' && $lines[1] == $host && $lines[3] == '~subdomain-test/subdomain/test') {
return array('error' => FALSE, 'output' => $result);
}
else {
if ($lines[0] != 'SUBDOMAIN TEST') {
if ($error404) {
$output = "$url returned a '404 Page not found' error.
";
}
else {
$output.= $error . $result;
}
$output.= 'Your web server is not routing subdomains to your Drupal directory.
';
$output.= "Possible Solutions:";
$output.= "- If you're running Apache, confirm you have the wildcard directive, ServerAlias *.$domain, in the VirtualHost declaration in your Apache configuration";
$output.= "
- Confirm there are no rogue URL rewrite rules in your Apache configuration or .htaccess file
";
}
elseif ($lines[1] != $host) {
$output = $result;
$output.= "Your web server erased the subdomain and rewrote $host as $domain.";
$output.= "Possible solutions:
";
$output.= "- Check your web server configuration and/or .htaccess for renegade redirect or urlrewrite statements";
$output.= "
- The subdomain module's .htaccess patch conflicts with the globalredirect module. You may need to disable one or the other if you are using Apache and globalredirect.";
}
elseif ($lines[3] != '~subdomain-test/subdomain/test') {
$output = $result ."The REQUEST_URI should have been rewritten as '~subdomain-test/subdomain/test'.";
$output.= "
Your web server is not rewriting your URLs correctly.
";
$output.= "Possible solutions:
";
$output.= "- Confirm that you correctly patched your .htaccess file, if you're using Apache, or setup the appropriate URL rewrite rules in your web server configuration file if you're using a web server other than Apache";
$output.= "
- Read through Readme.txt and make sure you've completed all the installation steps correctly
";
}
return array('error' => TRUE, 'output' => $output);
}
}
function subdomain_check_url_rewrite() {
$domain = subdomain_base_domain();
$correct_url = "http://subdomain-test.$domain/subdomain/test";
$drupal_url = url('~subdomain-test/subdomain/test');
if ($drupal_url == $correct_url) {
$output = "Drupal API: url('~subdomain-test/subdomain/test') returned '$drupal_url'";
return array('error' => FALSE, 'output' => $output);
}
else {
$output = "Drupal API: url('~subdomain-test/subdomain/test') returned '$drupal_url' but should have returned '$correct_url'";
if (!function_exists('custom_url_rewrite_outbound')) {
return array('error' => TRUE, 'output' => $output .'The custom_url_rewrite_outbound() function is missing from settings.php. It appears you haven\'t yet patched settings.php. See readme.txt for instructions.');
}
else {
return array('error' => TRUE, 'output' => $output .'The custom_url_rewrite_outbound() function in settings.php is rewriting subdomains incorrectly. Did you patch settings.php? See readme.txt for instructions.');
}
}
}
function subdomain_check_cookie_domain() {
$settings = file_get_contents(conf_path() . '/settings.php');
$settings = str_replace(chr(13).chr(10), "\n", $settings);
$settings = explode("\n",$settings);
foreach ($settings as $setting) {
if (strpos($setting, '$cookie_domain') !== FALSE) {
eval($setting);
break;
}
}
if (isset($cookie_domain)) {
return array('error' => FALSE, 'output' => 'The $cookie_domain variable in settings.php is set to \''. $cookie_domain .'\'');
}
else {
return array('error' => TRUE, 'output' => 'The $cookie_domain variable in settings.php is not set. Uncomment and set the $cookie_domain variable to your base domain (e.g. "example.com")');
}
}
function subdomain_toggle_link($title, $id) {
return l($title,'',array('onclick'=>'$("#'. $id .'").toggle("slow");return false;'));
}
function subdomain_check_show_details($show) {
if (!$show) {
return 'style="display:none"';
}
}
function subdomain_check_requirements() {
// theme_status_report relies on constants in install.inc
include_once './includes/install.inc';
$data = subdomain_check_wildcard_dns();
$requirements[SUBDOMAIN_CHECK_DNS] = array(
'title' => 'DNS server - '. subdomain_toggle_link('show/hide details', 'check-dns'),
'error' => $data['error'],
'value' => $data['error'] ? 'Not working yet' : 'Working',
'severity' => $data['error'] ? 2 : 0,
'description' => ''. $data['output'] .'
',
);
if ($requirements[SUBDOMAIN_CHECK_DNS]['error']) {
$requirements[SUBDOMAIN_CHECK_APACHE] = array(
'title' => 'Web server',
'value' => 'unable to test',
'severity' => 1,
'description' => "Unable to test Apache settings until DNS wildcard subdomains are working",
);
}
else {
$data = subdomain_check_apache();
$requirements[SUBDOMAIN_CHECK_APACHE] = array(
'title' => 'Web server - '. subdomain_toggle_link('show/hide details', 'check-apache'),
'value' => $data['error'] ? 'Not working yet' : 'Working',
'severity' => $data['error'] ? 2 : 0,
'description' => ''. $data['output'] .'
',
);
}
$data = subdomain_check_url_rewrite();
$requirements[SUBDOMAIN_CHECK_URL_REWRITE] = array(
'title' => "Drupal's URL function - ". subdomain_toggle_link('show/hide details', 'check-url-rewrite'),
'value' => $data['error'] ? 'Not working yet' : 'Working',
'severity' => $data['error'] ? 2 : 0,
'description' => ''. $data['output'] .'
',
);
$data = subdomain_check_cookie_domain();
$requirements[SUBDOMAIN_CHECK_COOKIE_DOMAIN] = array(
'title' => '$cookie_domain in settings.php - '. subdomain_toggle_link('show/hide details', 'check-cookie-domain'),
'value' => $data['error'] ? 'Not yet set' : 'Set',
'severity' => $data['error'] ? 2 : 0,
'description' => ''. $data['output'] .'
',
);
return theme('status_report', $requirements);
}
function subdomain_check_wildcard_dns() {
$error = FALSE;
$base_domain = subdomain_base_domain();
$domains_to_test = array("test-1.$base_domain","test-2.$base_domain", "test-3.$base_domain");
foreach($domains_to_test as $subdomain) {
$result = gethostbyname($subdomain);
if ($result === $subdomain) {
$output.= "$subdomain failed to resolve
";
$error = TRUE;
}
else {
$output.= "$subdomain successfully resolved to $result
";
}
}
if ($error) {
$output.= "It appears your DNS server is not setup to handle wildcard subdomains (*.$base_domain) for $base_domain. Edit the DNS zone file or settings for your server to fix.
";
$output.= "PHP caches DNS lookups, so you'll want to restart your web server after making changes to your DNS server to see the results of your changes on this page.
";
}
return array('error' => $error, 'output' => $output);
}