View source
<?php
function drd_server_server_domains() {
$sites = drd_server_read_sites();
$output = array();
$error = array();
foreach ($sites as $url => $id) {
if (isset($output[$id])) {
$output[$id]['aliases'][] = $url;
}
else {
if (isset($error[$id])) {
}
else {
$uses_ssl = FALSE;
$code = drd_server_server_check_host($url, $uses_ssl);
if ($code === FALSE) {
$error[$id] = TRUE;
}
else {
$output[$id] = array(
'url' => $url,
'aliases' => array(),
'drd installed' => $code === TRUE,
'uses ssl' => $uses_ssl,
);
}
}
}
}
return drd_server_result('server.domains', $output);
}
function drd_server_server_check_host($url, &$uses_ssl) {
$info = 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, $headers);
$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) {
$check_url = 'https://' . $url;
$check = drupal_http_request($check_url . '/?q=admin/drd_server/' . $id, $headers);
$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;
}
function drd_server_server_php_error_log($max_length = 5000) {
$log_file = ini_get('error_log');
if (!file_exists($log_file)) {
return drd_server_error(t('PHP Error Log does not exist.'), DRD_ERROR_NO_LOG_PHP);
}
$offset = max(-1, filesize($log_file) - $max_length);
$log = file_get_contents($log_file, FILE_BINARY, NULL, $offset);
$result['cache']['php_error_log']['server'] = array(
'title' => 'PHP Error Log',
'callback' => 'drupal_render',
'arguments' => array(
'data' => array(
'#markup' => '<pre>' . $log . '</pre>',
),
),
);
return drd_server_result('server.php.error.log', $result);
}