ban.module 2.04 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Allows to ban individual IP addresses.
6
7
8
9
10
11
12
13
14
15
 */

/**
 * Implements hook_help().
 */
function ban_help($path, $arg) {
  switch ($path) {
    case 'admin/help#ban':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
16
      $output .= '<p>' . t('The Ban module allows administrators to ban visits to their site from individual IP addresses. For more information, see <a href="!url">the online documentation for the Ban module</a>.', array('!url' => 'https://drupal.org/documentation/modules/ban')) . '</p>';
17
18
19
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Banning IP addresses') . '</dt>';
20
      $output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href="!bans">IP address bans</a> page.', array('!bans' => \Drupal::url('ban.admin_page'))) . '</dd>';
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      $output .= '</dl>';
      return $output;

    case 'admin/config/people/ban':
      return '<p>' . t('IP addresses listed here are banned from your site. Banned addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '</p>';
  }
}

/**
 * Implements hook_permission().
 */
function ban_permission() {
  return array(
    'ban IP addresses' => array(
      'title' => t('Ban IP addresses'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function ban_menu() {
  $items['admin/config/people/ban'] = array(
    'title' => 'IP address bans',
    'description' => 'Manage banned IP addresses.',
47
    'route_name' => 'ban.admin_page',
48
49
    'weight' => 10,
  );
50
  $items['admin/config/people/ban/delete/%'] = array(
51
    'title' => 'Delete IP address',
52
    'route_name' => 'ban.delete',
53
54
55
  );
  return $items;
}
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

/**
 * Implements hook_menu_link_defaults().
 */
function ban_menu_link_defaults() {
  $links['ban.admin.config.people'] = array(
    'link_title' => 'IP address bans',
    'description' => 'Manage banned IP addresses.',
    'route_name' => 'ban.admin_page',
    'weight' => 10,
    'parent' => 'user.admin.config.people',
  );

  return $links;
}