WordPress.org

Make WordPress Core

Changeset 15911


Ignore:
Timestamp:
10/22/10 10:27:35 (6 years ago)
Author:
dd32
Message:

Support wildcard domains in WP_PROXY_BYPASS_HOSTS and WP_ACCESSIBLE_HOSTS. Fixes #14636

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-http.php

    r15362 r15911  
    541541     * file and this will only allow localhost and your blog to make requests. The constant 
    542542     * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the 
    543      * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow. 
     543     * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains 
     544     * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted. 
    544545     * 
    545546     * @since 2.8.0 
    546547     * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. 
     548     * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS 
    547549     * 
    548550     * @param string $uri URI of url. 
     
    578580 
    579581        static $accessible_hosts; 
    580         if ( null == $accessible_hosts ) 
     582        static $wildcard_regex = false; 
     583        if ( null == $accessible_hosts ) { 
    581584            $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS); 
    582585 
    583         return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it. 
     586            if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { 
     587                $wildcard_regex = array(); 
     588                foreach ( $accessible_hosts as $host ) 
     589                    $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/')); 
     590                $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; 
     591            } 
     592        } 
     593 
     594        if ( !empty($wildcard_regex) ) 
     595            return !preg_match($wildcard_regex, $check['host']); 
     596        else 
     597            return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it. 
     598 
     599 
     600 
    584601    } 
    585602} 
     
    14791496 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. 
    14801497 * You do not need to have localhost and the blog host in this list, because they will not be passed 
    1481  * through the proxy. The list should be presented in a comma separated list</li> 
     1498 * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li> 
    14821499 * </ol> 
    14831500 * 
     
    14861503 * define('WP_PROXY_HOST', '192.168.84.101'); 
    14871504 * define('WP_PROXY_PORT', '8080'); 
    1488  * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com'); 
     1505 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org'); 
    14891506 * </code> 
    14901507 * 
    14911508 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress. 
     1509 * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS 
    14921510 * @since 2.8 
    14931511 */ 
     
    16291647 
    16301648        static $bypass_hosts; 
    1631         if ( null == $bypass_hosts ) 
     1649        static $wildcard_regex = false; 
     1650        if ( null == $bypass_hosts ) { 
    16321651            $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); 
    16331652 
    1634         return !in_array( $check['host'], $bypass_hosts ); 
     1653            if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { 
     1654                $wildcard_regex = array(); 
     1655                foreach ( $bypass_hosts as $host ) 
     1656                    $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/')); 
     1657                $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; 
     1658            } 
     1659        } 
     1660 
     1661        if ( !empty($wildcard_regex) ) 
     1662            return !preg_match($wildcard_regex, $check['host']); 
     1663        else 
     1664            return !in_array( $check['host'], $bypass_hosts ); 
    16351665    } 
    16361666} 
Note: See TracChangeset for help on using the changeset viewer.