Skip to content

Commit

Permalink
[Bugfix] Fix the cloudflare domain search when saving setting with mo…
Browse files Browse the repository at this point in the history
…re than 50 domains under one account
  • Loading branch information
hi-hai committed Jan 8, 2018
1 parent 3a1949c commit da4ec5c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion litespeed-cache/inc/cdn.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,25 +677,41 @@ private function _cloudflare_zone()
*/
public function cloudflare_fetch_zone( $options )
{
$kw = $options[ LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE_NAME ] ;

$url = 'https://api.cloudflare.com/client/v4/zones?status=active&match=all' ;

// Try exact match first
if ( $kw && strpos( $kw, '.' ) ) {
$zones = $this->_cloudflare_call( $url . '&name=' . $kw, 'GET', false, $options, false ) ;
if ( $zones ) {
LiteSpeed_Cache_Log::debug( 'CDN: cloudflare_fetch_zone exact matched' ) ;
return $zones[ 0 ] ;
}
}

// Can't find, try to get default one
$zones = $this->_cloudflare_call( $url, 'GET', false, $options, false ) ;

if ( ! $zones ) {
LiteSpeed_Cache_Log::debug( 'CDN: cloudflare_fetch_zone no zone' ) ;
return false ;
}

$kw = $options[ LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE_NAME ] ;
if ( ! $kw ) {
LiteSpeed_Cache_Log::debug( 'CDN: cloudflare_fetch_zone no set name, use first one by default' ) ;
return $zones[ 0 ] ;
}

foreach ( $zones as $v ) {
if ( strpos( $v[ 'name' ], $kw ) !== false ) {
LiteSpeed_Cache_Log::debug( 'CDN: cloudflare_fetch_zone matched ' . $kw . ' [name] ' . $v[ 'name' ] ) ;
return $v ;
}
}

// Can't match current name, return default one
LiteSpeed_Cache_Log::debug( 'CDN: cloudflare_fetch_zone failed match name, use first one by default' ) ;
return $zones[ 0 ] ;
}

Expand Down

0 comments on commit da4ec5c

Please sign in to comment.