function system_ban_ip_settings_form

7.x system.module system_ban_ip_settings_form()

This form allows the user (an administrator) to configure how FlightPath bans IP addresses.

File

modules/system/system.module, line 640

Code

function system_ban_ip_settings_form() {

  $form = array();

  $ban_ip_file_path = fp_get_files_path() . '/private/banned_ips.txt';

  $contents = 'File not found. Save form to create file.';
  if (file_exists($ban_ip_file_path)) {
    $contents = file_get_contents($ban_ip_file_path);
  }
  $form ['mark_top'] = array(
    'type' => 'markup',
    'value' => "<p>" . t('FlightPath is able to ban visitors by their IP addresses. Use this form to configure which
                   IP addresses you wish to ban.') . "</p>
                <p>                
                  " . fp_render_c_fieldset("<strong>" . t("Ban IP file path:") . "</strong> $ban_ip_file_path</b>
                                            <br><textarea class='readonly' readonly=readonly rows='10' cols='80'>$contents</textarea>
                                            ", "Current contents of Ban IP file", TRUE) . "
                                  
                
                
                  " . fp_render_c_fieldset("
                  <code>
                    sudo apt install php8.2-apcu   (or use whichever version of PHP you are using. Ex: 8.3, 8.1, etc.)
                    <br>sudo systemctl restart apache2
                  </code><br><br>Be sure to restart Apache once this change is in place, and ensure evertyhing still works correctly.
                ", "Install the PHP APCu package for best performance (see Debian/Ubuntu instructions)", TRUE) . "
                  
                </p>
                <p><b>You must save this form to create the banned_ips.txt file.</b></p>",
  );





  $form ['ban_ip_file_path'] = array(
    'type' => 'value',
    'value' => $ban_ip_file_path,
  );


  // auto-ban settings.
  $form ['system_enable_autoban_ip'] = array(
    'type' => 'checkbox',
    'label' => 'Enable auto-ban functionality?',
    'value' => variable_get('system_enable_autoban_ip', TRUE),
    'description' => t('If checked, FlightPath will automatically ban IP addresses which
                        trigger too many (7) page_not_found or access_denied events within a given
                        time period (2 seconds).'),
  );



  $form ['system_manually_add_ip'] = array(
    'label' => t('Manually add an IP address to the ban list:'),
    'type' => 'text',
  );



  $options = array('never' => 'Never (permanently ban IP addresses)');
  $options ["1 HOUR"] = "1 hour";
  for ($t = 2; $t <= 22; $t = $t + 2) {
    $options ["$t HOURS"] = "$t hours";
  }
  $options ["1 DAY"] = "1 day";
  for ($t = 2; $t <= 6; $t = $t + 1) {
    $options ["$t DAYS"] = "$t days";
  }
  $options ["1 WEEK"] = "1 week";
  for ($t = 2; $t <= 100; $t = $t + 2) {
    $options ["$t WEEKS"] = "$t weeks";
  }

  $form ['system_ban_ip_expire'] = array(
    'label' => t('How long to wait until we remove a banned IP address?'),
    'type' => 'select',
    'hide_please_select' => 'TRUE',
    'options' => $options,
    'value' => variable_get('system_ban_ip_expire', '2 WEEKS'),
  );







  return $form;

}