You are here

function autoban_page in Automatic IP ban (Autoban) 7

Menu callback. Displays autoban rules list.

1 string reference to 'autoban_page'
autoban_menu in ./autoban.module
Implements hook_menu().

File

./autoban.admin.inc, line 11
Configuration for autoban module.

Code

function autoban_page() {
  $rows = array();
  $header = array(
    array(
      'data' => t('ID'),
      'field' => 'rid',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('Message pattern'),
      'field' => 'message',
    ),
    array(
      'data' => t('Threshold'),
      'field' => 'threshold',
    ),
    array(
      'data' => t('User type'),
      'field' => 'user_type',
    ),
    array(
      'data' => t('Referrer'),
      'field' => 'referer',
    ),
    array(
      'data' => t('IP type'),
      'field' => 'ip_type',
    ),
    t('Actions'),
  );
  $build = array();
  $autoban_list = autoban_get_rules(NULL, $header);
  if (!empty($autoban_list)) {
    foreach ($autoban_list as $rule) {

      // Actions.
      $actions = array();
      $actions[] = l(t('Edit'), AUTOBAN_BASE_URL . "/edit/{$rule->rid}");
      $actions[] = l(t('Delete'), AUTOBAN_BASE_URL . "/delete/{$rule->rid}");
      $options = array();
      $options['query'] = array(
        'type' => $rule->type,
        'message' => $rule->message,
        drupal_get_destination(),
      );
      $actions[] = l(t('Clone'), AUTOBAN_BASE_URL . "/add", $options);
      $actions[] = l(t('Export'), AUTOBAN_BASE_URL . "/export/{$rule->rid}");
      $actions[] = l(t('Test'), AUTOBAN_BASE_URL . "/test/{$rule->rid}");
      $rows[] = array(
        $rule->rid,
        filter_xss($rule->type),
        filter_xss($rule->message),
        $rule->threshold,
        _autoban_get_user_type_name($rule->user_type),
        filter_xss($rule->referer),
        _autoban_get_ip_type_name($rule->ip_type),
        implode(' ', $actions),
      );
    }
  }
  $build['autoban_form'] = drupal_get_form('autoban_form');
  $build['autoban_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('Table has no rows!'),
  );
  return $build;
}