You are here

function drd_server_server_check_host in Drupal Remote Dashboard Server 7.2

Same name and namespace in other branches
  1. 6.2 drd_server.server.inc \drd_server_server_check_host()
  2. 6 drd_server.server.inc \drd_server_server_check_host()
  3. 7 drd_server.server.inc \drd_server_server_check_host()

Function called by drd_server_server_domains() to check a specific URL if it really exists and if the module drd_server is installed.

Parameters

string $url: The url that should be checked.

bool $uses_ssl: A variable reference to hold the information if the URL uses SSL.

Return value

boolean TRUE if domain is reachable, FALSE otherwise.

1 call to drd_server_server_check_host()
drd_server_server_domains in ./drd_server.server.inc
DRD Action to find out all domains on this Drupal installation.

File

./drd_server.server.inc, line 56
Provides core related functionality triggered by DRD.

Code

function drd_server_server_check_host($url, &$uses_ssl) {
  $info = array();
  $options = array(
    'headers' => array(
      'User-Agent' => 'Drupal Remote Dashboard',
      'Accept' => 'text/plain',
      'Accept-Encoding' => 'utf-8',
    ),
  );
  try {
    $id = rand();
    $info[] = 'ID: ' . $id;
    $check_url = 'http://' . $url;
    $check = drupal_http_request($check_url . '/?q=admin/drd_server/' . $id, $options);
    $ok = $check->code == 200 && trim($check->data) == _drd_server_get_check_token($check_url, $id);
    $info[] = array(
      'url' => $check_url,
      'ok' => $ok ? 'yes' : 'no',
      'result' => $check,
    );
    if (!$ok) {

      // Maybe the url is running https only, so we try that as well.
      $check_url = 'https://' . $url;
      $check = drupal_http_request($check_url . '/?q=admin/drd_server/' . $id, $options);
      $ok = $check->code == 200 || in_array($check->code, array(
        301,
        302,
        307,
      )) && $check->redirect_code == 200;
      $info[] = array(
        'url' => $check_url,
        'ok' => $ok ? 'yes' : 'no',
        'result' => $check,
      );
      if ($ok) {
        $uses_ssl = TRUE;
      }
    }
    if ($ok && trim($check->data) == _drd_server_get_check_token($check_url, $id)) {
      $info[] = 'Host OK!';
      $result = TRUE;
    }
    else {
      $info[] = 'Host result: ' . $check->code;
      $result = $check->code;
    }
  } catch (Exception $e) {
    $info[] = array(
      'Exception' => $e,
    );
    $result = FALSE;
  }
  _drd_server_watchdog('Checking host @name (@result): <pre>!info</pre>', array(
    '@result' => (string) $result,
    '@name' => $url,
    '!info' => print_r($info, TRUE),
  ));
  return $result;
}