You are here

function badbehavior_event in Bad Behavior 7.2

Same name and namespace in other branches
  1. 5.2 badbehavior.module \badbehavior_event()
  2. 6.2 badbehavior.admin.inc \badbehavior_event()
  3. 6 badbehavior.admin.inc \badbehavior_event()

Builds the "Details" table displaying data about an individual log entry

Parameters

string $id:

Return value

string The table in HTML format

1 string reference to 'badbehavior_event'
badbehavior_menu in ./badbehavior.module
Implements hook_menu().

File

./badbehavior.admin.inc, line 86
Admin page callbacks for the badbehavior module.

Code

function badbehavior_event($id = NULL) {
  if (!badbehavior_load_includes(array(
    'responses',
  ))) {
    return 'Bad Behavior is not installed correctly. See the README.txt for installation details.';
  }
  $output = '';
  $result = db_select('bad_behavior_log', 'b')
    ->fields('b')
    ->condition('id', $id, '=')
    ->execute();
  $rows = array();
  foreach ($result as $record) {
    $response = bb2_get_response($record->key);
    $record->localdate = bb2_convertdate($record->date);
    $output .= '<table border="1" cellpadding="2" cellspacing="2">';
    $output .= ' <tr><th>' . t('IP Addr') . '</th><td>';
    if ($record->ip) {
      $output .= $record->ip . '</td></tr>';
    }
    else {
      $output .= '<span style="color:red">Possible Proxy Settings Error:</span> No IP address reported</td></tr>';
    }
    $output .= ' <tr><th>' . t('Hostname') . '</th><td>';
    if ($record->ip) {
      $output .= gethostbyaddr($record->ip) . ' (' . l(t('whois'), 'http://www.whois.sc/' . $record->ip) . ')</td></tr>';
    }
    else {
      $output .= '<span style="color:red">Possible Proxy Settings Error:</span> No hostname reported</td></tr>';
    }
    $output .= ' <tr><th>' . t('Date') . '</th><td>' . $record->localdate . '</td></tr>';
    $output .= ' <tr><th>' . t('Request type') . '</th><td>' . $record->request_method . '</td></tr>';
    $output .= ' <tr><th>' . t('URI') . '</th><td>' . $record->request_uri . '</td></tr>';
    $output .= ' <tr><th>' . t('Protocol') . '</th><td>' . $record->server_protocol . '</td></tr>';
    $output .= ' <tr><th>' . t('User Agent') . '</th><td>' . $record->user_agent . '</td></tr>';
    $output .= ' <tr><th>' . t('Headers') . '</th><td>' . $record->http_headers . '</td></tr>';
    $output .= ' <tr><th>' . t('Request Entity') . '</th><td>' . $record->request_entity . '</td></tr>';
    $output .= ' <tr><th>' . t('Denied Reason') . '</th><td>' . $response['log'] . '</td></tr>';
    $output .= ' <tr><th>' . t('Explanation') . '</th><td>' . $response['explanation'] . '</td></tr>';
    $output .= ' <tr><th>' . t('Response') . '</th><td>' . $response['response'] . '</td></tr>';
    $output .= '</table>';
  }
  return $output;
}