<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15911] trunk/wp-includes/class-http.php:
  Support wildcard domains in WP_PROXY_BYPASS_HOSTS and WP_ACCESSIBLE_HOSTS.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15911">15911</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-10-22 10:27:35 +0000 (Fri, 22 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Support wildcard domains in WP_PROXY_BYPASS_HOSTS and WP_ACCESSIBLE_HOSTS. Fixes <a href="http://trac.wordpress.org/ticket/14636">#14636</a> </pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclasshttpphp">trunk/wp-includes/class-http.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclasshttpphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-http.php (15910 => 15911)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-http.php        2010-10-22 00:27:12 UTC (rev 15910)
+++ trunk/wp-includes/class-http.php        2010-10-22 10:27:35 UTC (rev 15911)
</span><span class="lines">@@ -540,10 +540,12 @@
</span><span class="cx">          * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true in your wp-config.php
</span><span class="cx">          * file and this will only allow localhost and your blog to make requests. The constant
</span><span class="cx">          * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
</span><del>-         * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
</del><ins>+         * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains
+         * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted.
</ins><span class="cx">          *
</span><span class="cx">          * @since 2.8.0
</span><span class="cx">          * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
</span><ins>+         * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS
</ins><span class="cx">          *
</span><span class="cx">          * @param string $uri URI of url.
</span><span class="cx">          * @return bool True to block, false to allow.
</span><span class="lines">@@ -577,10 +579,25 @@
</span><span class="cx">                         return true;
</span><span class="cx"> 
</span><span class="cx">                 static $accessible_hosts;
</span><del>-                if ( null == $accessible_hosts )
</del><ins>+                static $wildcard_regex = false;
+                if ( null == $accessible_hosts ) {
</ins><span class="cx">                         $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
</span><span class="cx"> 
</span><del>-                return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
</del><ins>+                        if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) {
+                                $wildcard_regex = array();
+                                foreach ( $accessible_hosts as $host )
+                                        $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/'));
+                                $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
+                        }
+                }
+
+                if ( !empty($wildcard_regex) )
+                        return !preg_match($wildcard_regex, $check['host']);
+                else
+                        return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
+
+
+
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1478,17 +1495,18 @@
</span><span class="cx">  * &lt;li&gt;WP_PROXY_PASSWORD - Proxy password, if it requires authentication.&lt;/li&gt;
</span><span class="cx">  * &lt;li&gt;WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
</span><span class="cx">  * You do not need to have localhost and the blog host in this list, because they will not be passed
</span><del>- * through the proxy. The list should be presented in a comma separated list&lt;/li&gt;
</del><ins>+ * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org&lt;/li&gt;
</ins><span class="cx">  * &lt;/ol&gt;
</span><span class="cx">  *
</span><span class="cx">  * An example can be as seen below.
</span><span class="cx">  * &lt;code&gt;
</span><span class="cx">  * define('WP_PROXY_HOST', '192.168.84.101');
</span><span class="cx">  * define('WP_PROXY_PORT', '8080');
</span><del>- * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
</del><ins>+ * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org');
</ins><span class="cx">  * &lt;/code&gt;
</span><span class="cx">  *
</span><span class="cx">  * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress.
</span><ins>+ * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS
</ins><span class="cx">  * @since 2.8
</span><span class="cx">  */
</span><span class="cx"> class WP_HTTP_Proxy {
</span><span class="lines">@@ -1628,10 +1646,22 @@
</span><span class="cx">                         return true;
</span><span class="cx"> 
</span><span class="cx">                 static $bypass_hosts;
</span><del>-                if ( null == $bypass_hosts )
</del><ins>+                static $wildcard_regex = false;
+                if ( null == $bypass_hosts ) {
</ins><span class="cx">                         $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
</span><span class="cx"> 
</span><del>-                return !in_array( $check['host'], $bypass_hosts );
</del><ins>+                        if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) {
+                                $wildcard_regex = array();
+                                foreach ( $bypass_hosts as $host )
+                                        $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/'));
+                                $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
+                        }
+                }
+
+                if ( !empty($wildcard_regex) )
+                        return !preg_match($wildcard_regex, $check['host']);
+                else
+                        return !in_array( $check['host'], $bypass_hosts );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>