diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 2fe7b5cc5a95a90cc4b3a80d533170fd2fed4d8d..9e58b25f304d5467443a0fc91f7cbdf5ef5bba46 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1390,8 +1390,12 @@ function system_modules_uninstall_submit($form, &$form_state) { /** * Menu callback. Display blocked IP addresses. + * + * @param $default_ip + * Optional IP address to be passed on to drupal_get_form() for + * use as the default value of the IP address form field. */ -function system_ip_blocking() { +function system_ip_blocking($default_ip = '') { $output = ''; $rows = array(); $header = array(t('IP address'), t('Operations')); @@ -1403,7 +1407,7 @@ function system_ip_blocking() { ); } - $build['system_ip_blocking_form'] = drupal_get_form('system_ip_blocking_form'); + $build['system_ip_blocking_form'] = drupal_get_form('system_ip_blocking_form', $default_ip); $build['system_ip_blocking_table'] = array( '#theme' => 'table', @@ -1421,13 +1425,13 @@ function system_ip_blocking() { * @see system_ip_blocking_form_validate() * @see system_ip_blocking_form_submit() */ -function system_ip_blocking_form($form, $form_state) { +function system_ip_blocking_form($form, $form_state, $default_ip) { $form['ip'] = array( '#title' => t('IP address'), '#type' => 'textfield', '#size' => 64, '#maxlength' => 32, - '#default_value' => arg(4), + '#default_value' => $default_ip, '#description' => t('Enter a valid IP address.'), ); $form['submit'] = array( diff --git a/modules/system/system.module b/modules/system/system.module index 9d89278a701dad759d419fb2393904b40dd71db2..465f6e266d2f77a03287093f464a19de442d6003 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -692,14 +692,6 @@ function system_menu() { 'access arguments' => array('block IP addresses'), 'file' => 'system.admin.inc', ); - $items['admin/config/people/ip-blocking/%'] = array( - 'title' => 'IP address blocking', - 'description' => 'Manage blocked IP addresses.', - 'page callback' => 'system_ip_blocking', - 'access arguments' => array('block IP addresses'), - 'type' => MENU_CALLBACK, - 'file' => 'system.admin.inc', - ); $items['admin/config/people/ip-blocking/delete/%blocked_ip'] = array( 'title' => 'Delete IP address', 'page callback' => 'drupal_get_form', diff --git a/modules/system/system.test b/modules/system/system.test index 9bdd3a5d6ae6a87a2b6f572d9fba73f617ac0a4c..cca0f6689e9d3626f30783cd16a292dcb1bffd3d 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -372,6 +372,13 @@ class IPAddressBlockingTestCase extends DrupalWebTestCase { $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save')); $this->assertText(t('Enter a valid IP address.')); + // Pass an IP address as a URL parameter and submit it. + $submit_ip = '1.2.3.4'; + $this->drupalPost('admin/config/people/ip-blocking/' . $submit_ip, NULL, t('Save')); + $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField(); + $this->assertTrue($ip, t('IP address found in database')); + $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $submit_ip)), t('IP address was blocked.')); + // Submit your own IP address. This fails, although it works when testing manually. // TODO: on some systems this test fails due to a bug or inconsistency in cURL. // $edit = array();