Пример #1
0
 /**
  * Test for \core\ip_utils::is_ipv6_address().
  *
  * @param string $address the address to validate.
  * @param bool $expected the expected result.
  * @dataProvider ipv6_address_data_provider
  */
 public function test_is_ipv6_address($address, $expected)
 {
     $this->assertEquals($expected, \core\ip_utils::is_ipv6_address($address));
 }
 /**
  * Helper to get all entries from the admin setting, as an array, sorted by classification.
  * Classifications include 'ipv4', 'ipv6', 'domain', 'domainwildcard'.
  *
  * @return array of host/domain/ip entries from the 'curlsecurityblockedhosts' config.
  */
 protected function get_blacklisted_hosts_by_category()
 {
     // For each of the admin setting entries, check and place in the correct section of the config array.
     $config = ['ipv6' => [], 'ipv4' => [], 'domain' => [], 'domainwildcard' => []];
     $entries = $this->get_blacklisted_hosts();
     foreach ($entries as $entry) {
         if (ip_utils::is_ipv6_address($entry) || ip_utils::is_ipv6_range($entry)) {
             $config['ipv6'][] = $entry;
         } else {
             if (ip_utils::is_ipv4_address($entry) || ip_utils::is_ipv4_range($entry)) {
                 $config['ipv4'][] = $entry;
             } else {
                 if (ip_utils::is_domain_name($entry)) {
                     $config['domain'][] = $entry;
                 } else {
                     if (ip_utils::is_domain_matching_pattern($entry)) {
                         $config['domainwildcard'][] = $entry;
                     }
                 }
             }
         }
     }
     return $config;
 }