| 1 |
<?php |
| 2 |
|
| 3 |
namespace seraph_accel; |
| 4 |
|
| 5 |
if( !defined( 'ABSPATH' ) ) |
| 6 |
exit; |
| 7 |
|
| 8 |
spl_autoload_register( |
| 9 |
function( $class ) |
| 10 |
{ |
| 11 |
if( strpos( $class, 'seraph_accel\\CloudFlareHooksEx' ) === 0 ) |
| 12 |
@include_once( __DIR__ . '/cache_ext_CloudFlareHooksEx.php' ); |
| 13 |
} |
| 14 |
); |
| 15 |
|
| 16 |
function _CacheExt_SockDoRequest( $addr, $method, $url, $headers = null, $port = null, $scheme = 'http' ) |
| 17 |
{ |
| 18 |
|
| 19 |
$urlComps = Net::UrlParse( $url ); |
| 20 |
if( !$urlComps ) |
| 21 |
return( Gen::E_INVALIDARG ); |
| 22 |
|
| 23 |
if( $scheme !== null ) |
| 24 |
$urlComps[ 'scheme' ] = $scheme; |
| 25 |
$urlComps[ 'host' ] = $addr; |
| 26 |
|
| 27 |
if( $port !== null ) |
| 28 |
$urlComps[ 'port' ] = $port; |
| 29 |
else |
| 30 |
unset( $urlComps[ 'port' ] ); |
| 31 |
|
| 32 |
return( Wp::RemoteRequest( $method, Net::UrlDeParse( $urlComps, 0, array( PHP_URL_USER, PHP_URL_PASS, PHP_URL_QUERY, PHP_URL_FRAGMENT ) ), array( 'headers' => $headers, 'sslverify' => false ) ) ); |
| 33 |
} |
| 34 |
|
| 35 |
function _CacheExt_GetResponseResString( $requestRes, $body = false ) |
| 36 |
{ |
| 37 |
if( is_int( $requestRes ) ) |
| 38 |
return( 'Error code: ' . $requestRes ); |
| 39 |
|
| 40 |
if( is_wp_error( $requestRes ) ) |
| 41 |
{ |
| 42 |
$prefix = ''; |
| 43 |
if( $requestRes -> get_error_data( 'url' ) ) |
| 44 |
$prefix = 'HTTP ' . ( string )$requestRes -> get_error_data( 'method' ) . ' ' . $requestRes -> get_error_data( 'url' ) . ': '; |
| 45 |
return( $prefix . 'Error: ' . $requestRes -> get_error_message() ); |
| 46 |
} |
| 47 |
|
| 48 |
return( 'HTTP ' . ( isset( $requestRes[ 'method' ] ) ? ( $requestRes[ 'method' ] . ' ' ) : '' ) . wp_remote_retrieve_response_code( $requestRes ) . ' ' . ( string )($requestRes[ 'url' ]??null) . ', sent headers: ' . @json_encode( ( array )($requestRes[ 'headers_sent' ]??null) ) . ( isset( $requestRes[ 'data_sent' ] ) ? ( ', sent data: ' . $requestRes[ 'data_sent' ] ) : '' ) . ', response headers: ' . @json_encode( ( array )Net::GetHeadersFromWpRemoteGet( $requestRes ) ) . ', response body: ' . substr( wp_remote_retrieve_body( $requestRes ), 0, 2000 ) ); |
| 49 |
} |
| 50 |
|
| 51 |
function _CacheExt_Nginx_GetUrlKey( $url, $method = 'GET' ) |
| 52 |
{ |
| 53 |
$urlComps = Net::UrlParse( $url ); |
| 54 |
return( md5( Gen::GetArrField( $urlComps, array( 'scheme' ), '' ) . $method . Gen::GetArrField( $urlComps, array( 'host' ), '' ) . Gen::GetArrField( $urlComps, array( 'path' ), '' ) ) ); |
| 55 |
} |
| 56 |
|
| 57 |
function _CacheExt_Nginx_GetCacheFiles( $keys, $dir, $levels = '1:2' ) |
| 58 |
{ |
| 59 |
$caches = array(); |
| 60 |
$levels = explode( ':', $levels ); |
| 61 |
foreach( ( array )$keys as $key ) |
| 62 |
{ |
| 63 |
$path = array(); |
| 64 |
$path[] = $dir; |
| 65 |
$offset = 0; |
| 66 |
|
| 67 |
foreach( $levels as $l ) |
| 68 |
{ |
| 69 |
$offset = $offset + $l; |
| 70 |
$path[] = substr( $key, 0 - $offset, $l ); |
| 71 |
} |
| 72 |
|
| 73 |
$path[] = $key; |
| 74 |
$caches[] = join( '/', $path ); |
| 75 |
} |
| 76 |
|
| 77 |
return( $caches ); |
| 78 |
} |
| 79 |
|
| 80 |
function _CacheExt_Nginx_ClearAll( $dir ) |
| 81 |
{ |
| 82 |
Gen::DelDir( $dir, false ); |
| 83 |
} |
| 84 |
|
| 85 |
function CacheExt_ClearOnExtRequest( $url = null ) |
| 86 |
{ |
| 87 |
$sett = Plugin::SettGet(); |
| 88 |
$aSrv = $_SERVER; |
| 89 |
|
| 90 |
if( isset( $aSrv[ 'HTTP_X_LSCACHE' ] ) || @preg_match( '@litespeed@i', ($aSrv[ 'SERVER_SOFTWARE' ]??'') ) ) |
| 91 |
{ |
| 92 |
$logInfo = ''; |
| 93 |
if( !headers_sent() ) |
| 94 |
{ |
| 95 |
$hdr = 'X-LiteSpeed-Purge: public,'; |
| 96 |
|
| 97 |
$hdr .= '*'; |
| 98 |
|
| 99 |
if( is_string( $hdr ) ) |
| 100 |
{ |
| 101 |
|
| 102 |
header( $hdr ); |
| 103 |
$logInfo .= 'Executed, sent \'' . $hdr . '\' header'; |
| 104 |
} |
| 105 |
} |
| 106 |
else |
| 107 |
$logInfo .= 'Skipped, headers already sent'; |
| 108 |
|
| 109 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 110 |
LogWrite( 'LiteSpeed: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
function CacheExt_Clear( $url = null ) |
| 115 |
{ |
| 116 |
$sett = Plugin::SettGet(); |
| 117 |
$hostname = gethostname(); |
| 118 |
$aSrv = $_SERVER; |
| 119 |
|
| 120 |
CacheExt_Clear_CopyHdrs( $aSrv ); |
| 121 |
|
| 122 |
if( IsBatCacheRtm() ) |
| 123 |
{ |
| 124 |
if( BatCache_Clear( $url ) ) |
| 125 |
{ |
| 126 |
if( $url ) |
| 127 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 128 |
else |
| 129 |
$logInfo = 'Purged all'; |
| 130 |
} |
| 131 |
else |
| 132 |
$logInfo = 'Invalid state'; |
| 133 |
|
| 134 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 135 |
LogWrite( 'BatCache: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 136 |
} |
| 137 |
|
| 138 |
if( ( defined( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) ) |
| 139 |
{ |
| 140 |
$requestRes = Gen::E_INVALIDARG; |
| 141 |
if( $url ) |
| 142 |
{ |
| 143 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 144 |
{ |
| 145 |
$urlComps[ 'scheme' ] = 'https'; |
| 146 |
$urlPurge = Net::UrlDeParse( $urlComps, 0, array( PHP_URL_QUERY, PHP_URL_FRAGMENT ) ); |
| 147 |
if( isset( $urlComps[ 'query' ] ) ) |
| 148 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', $urlPurge, array( 'X-Purge-Regex' => '.*', 'X-VC-Purge-Key' => Gen::Constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) ); |
| 149 |
else |
| 150 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', $urlPurge, array( 'X-Purge-Method' => 'default', 'X-VC-Purge-Key' => Gen::Constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) ); |
| 151 |
} |
| 152 |
} |
| 153 |
else |
| 154 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', Wp::GetSiteRootUrl(), array( 'X-Purge-Regex' => '.*', 'X-VC-Purge-Key' => Gen::Constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) ); |
| 155 |
|
| 156 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 157 |
LogWrite( 'O2Switch: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 158 |
} |
| 159 |
|
| 160 |
if( $method = trim( Gen::GetArrField( $sett, array( 'cache', 'nginx', 'method' ), '' ) ) ) |
| 161 |
{ |
| 162 |
if( $method == 'get_purge' ) |
| 163 |
{ |
| 164 |
$logInfo = ''; |
| 165 |
|
| 166 |
if( $url ) |
| 167 |
{ |
| 168 |
$urlRequest = Gen::SetLastSlash( Gen::GetArrField( $sett, array( 'cache', 'nginx', 'url' ), '' ), false ); |
| 169 |
if( !$urlRequest ) |
| 170 |
$urlRequest = Net::UrlDeParse( Net::UrlParse( Wp::GetSiteRootUrl() ), 0, array( PHP_URL_PATH, PHP_URL_QUERY, PHP_URL_FRAGMENT ) ) . '/purge'; |
| 171 |
|
| 172 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 173 |
{ |
| 174 |
$urlRequest .= Net::UrlDeParse( $urlComps, 0, array( PHP_URL_SCHEME, PHP_URL_USER, PHP_URL_PASS, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_FRAGMENT ) ); |
| 175 |
$requestRes = Wp::RemoteGet( $urlRequest, array( 'timeout' => 5, 'sslverify' => false, 'redirection' => 5 ) ); |
| 176 |
} |
| 177 |
else |
| 178 |
$requestRes = Gen::E_INVALIDARG; |
| 179 |
|
| 180 |
$logInfo = _CacheExt_GetResponseResString( $requestRes ); |
| 181 |
} |
| 182 |
else if( $urlRequestAll = Gen::GetArrField( $sett, array( 'cache', 'nginx', 'urlAll' ), '' ) ) |
| 183 |
{ |
| 184 |
$requestRes = Wp::RemoteGet( $urlRequestAll, array( 'timeout' => 5, 'sslverify' => false, 'redirection' => 5 ) ); |
| 185 |
$logInfo = _CacheExt_GetResponseResString( $requestRes ); |
| 186 |
} |
| 187 |
else if( $dir = trim( Gen::GetArrField( $sett, array( 'cache', 'nginx', 'fastCgiDir' ), '' ) ) ) |
| 188 |
{ |
| 189 |
_CacheExt_Nginx_ClearAll( $dir ); |
| 190 |
$logInfo = 'Directory \'' . $dir . '\' cleared'; |
| 191 |
} |
| 192 |
|
| 193 |
if( $requestRes !== null && ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 194 |
LogWrite( 'Nginx: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 195 |
} |
| 196 |
else if( $method == 'direct' ) |
| 197 |
{ |
| 198 |
if( $dir = trim( Gen::GetArrField( $sett, array( 'cache', 'nginx', 'fastCgiDir' ), '' ) ) ) |
| 199 |
{ |
| 200 |
$logInfo = ''; |
| 201 |
|
| 202 |
if( $url ) |
| 203 |
{ |
| 204 |
foreach( _CacheExt_Nginx_GetCacheFiles( _CacheExt_Nginx_GetUrlKey( $url ), $dir, Gen::GetArrField( $sett, array( 'cache', 'nginx', 'fastCgiLevels' ), '' ) ) as $cache ) |
| 205 |
{ |
| 206 |
if( !@is_file( $cache ) ) |
| 207 |
continue; |
| 208 |
|
| 209 |
@unlink( $cache ); |
| 210 |
|
| 211 |
if( $logInfo ) |
| 212 |
$logInfo .= ', '; |
| 213 |
$logInfo .= '\'' . $cache . '\''; |
| 214 |
} |
| 215 |
|
| 216 |
$logInfo = 'File(s) for URL \'' . $url . '\' deleted: ' . $logInfo; |
| 217 |
} |
| 218 |
else |
| 219 |
{ |
| 220 |
_CacheExt_Nginx_ClearAll( $dir ); |
| 221 |
$logInfo = 'Directory \'' . $dir . '\' cleared'; |
| 222 |
} |
| 223 |
|
| 224 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 225 |
LogWrite( 'Nginx: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 226 |
} |
| 227 |
} |
| 228 |
else if( $method == '3rdp' ) |
| 229 |
{ |
| 230 |
|
| 231 |
if( Gen::DoesFuncExist( '\\NginxChampuru::get_instance' ) && Gen::DoesFuncExist( '\\NginxChampuru::get_cache_dir' ) && Gen::DoesFuncExist( '\\NginxChampuru::get_cache_key' ) && Gen::DoesFuncExist( '\\NginxChampuru::get_cache' ) ) |
| 232 |
{ |
| 233 |
$logInfo = ''; |
| 234 |
|
| 235 |
if( $instance = \NginxChampuru::get_instance() ) |
| 236 |
{ |
| 237 |
if( $url ) |
| 238 |
{ |
| 239 |
add_filter( 'nginxchampuru_get_reverse_proxy_key', 'seraph_accel\\_CacheExt_Nginx_GetUrlKey', 99999 ); |
| 240 |
|
| 241 |
foreach( ( array )$instance -> get_cache( $instance -> get_cache_key( $url ), $url ) as $cache ) |
| 242 |
{ |
| 243 |
if( !@is_file( $cache ) ) |
| 244 |
continue; |
| 245 |
|
| 246 |
@unlink( $cache ); |
| 247 |
|
| 248 |
if( $logInfo ) |
| 249 |
$logInfo .= ', '; |
| 250 |
$logInfo .= '\'' . $cache . '\''; |
| 251 |
} |
| 252 |
|
| 253 |
$logInfo = 'NginxChampuru: File(s) for URL \'' . $url . '\' deleted: ' . $logInfo; |
| 254 |
} |
| 255 |
else if( $dir = $instance -> get_cache_dir() ) |
| 256 |
{ |
| 257 |
_CacheExt_Nginx_ClearAll( $dir ); |
| 258 |
$logInfo = 'NginxChampuru: Directory \'' . $dir . '\' cleared'; |
| 259 |
} |
| 260 |
else |
| 261 |
$logInfo = 'NginxChampuru: void'; |
| 262 |
} |
| 263 |
else |
| 264 |
$logInfo = 'NginxChampuru: no instance'; |
| 265 |
|
| 266 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 267 |
LogWrite( 'Nginx: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 268 |
} |
| 269 |
|
| 270 |
else if( Gen::DoesFuncExist( '\\NginxCache::purge_zone_once' ) ) |
| 271 |
{ |
| 272 |
|
| 273 |
$logInfo = ''; |
| 274 |
|
| 275 |
if( $dir = trim( get_option( 'nginx_cache_path' ) ) ) |
| 276 |
{ |
| 277 |
if( $url ) |
| 278 |
{ |
| 279 |
foreach( _CacheExt_Nginx_GetCacheFiles( _CacheExt_Nginx_GetUrlKey( $url ), $dir ) as $cache ) |
| 280 |
{ |
| 281 |
if( !@is_file( $cache ) ) |
| 282 |
continue; |
| 283 |
|
| 284 |
@unlink( $cache ); |
| 285 |
|
| 286 |
if( $logInfo ) |
| 287 |
$logInfo .= ', '; |
| 288 |
$logInfo .= '\'' . $cache . '\''; |
| 289 |
} |
| 290 |
|
| 291 |
$logInfo = 'NginxCache: File(s) for URL \'' . $url . '\' deleted: ' . $logInfo; |
| 292 |
} |
| 293 |
else |
| 294 |
{ |
| 295 |
_CacheExt_Nginx_ClearAll( $dir ); |
| 296 |
$logInfo = 'NginxCache: Directory \'' . $dir . '\' cleared'; |
| 297 |
} |
| 298 |
} |
| 299 |
else |
| 300 |
$logInfo = 'NginxCache: no dir'; |
| 301 |
|
| 302 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 303 |
LogWrite( 'Nginx: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 304 |
} |
| 305 |
|
| 306 |
else if( Gen::DoesFuncExist( '\\Purger::purge_all' ) && Gen::DoesFuncExist( '\\Purger::purge_url' ) ) |
| 307 |
{ |
| 308 |
$logInfo = ''; |
| 309 |
|
| 310 |
global $nginx_purger; |
| 311 |
if( $nginx_purger ) |
| 312 |
{ |
| 313 |
if( $url ) |
| 314 |
{ |
| 315 |
$nginx_purger -> purge_url( $url ); |
| 316 |
$logInfo = 'Purger: URL \'' . $url . '\' purged'; |
| 317 |
} |
| 318 |
else |
| 319 |
{ |
| 320 |
$nginx_purger -> purge_all(); |
| 321 |
|
| 322 |
$logInfo = 'Purger: Purged all'; |
| 323 |
} |
| 324 |
} |
| 325 |
else |
| 326 |
$logInfo = 'Purger: no instance'; |
| 327 |
|
| 328 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 329 |
LogWrite( 'Nginx: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
if( Gen::DoesFuncExist( '\\WPNCEasyWP\\Http\\Varnish\\VarnishCache::boot' ) ) |
| 335 |
{ |
| 336 |
$logInfo = ''; |
| 337 |
|
| 338 |
if( $varnish = \WPNCEasyWP\Http\Varnish\VarnishCache::boot() ) |
| 339 |
{ |
| 340 |
|
| 341 |
$varnish -> clearAll(); |
| 342 |
$logInfo = 'Varnish cache cleared'; |
| 343 |
} |
| 344 |
|
| 345 |
wp_cache_flush(); |
| 346 |
|
| 347 |
if( $logInfo ) |
| 348 |
$logInfo .= ', '; |
| 349 |
$logInfo .= 'WP cache flushed'; |
| 350 |
|
| 351 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 352 |
LogWrite( 'EasyWP: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 353 |
} |
| 354 |
|
| 355 |
if( ( @preg_match( '@^dp-.+@', $hostname ) ) ) |
| 356 |
{ |
| 357 |
$requestRes = Gen::E_INVALIDARG; |
| 358 |
if( $url ) |
| 359 |
{ |
| 360 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 361 |
{ |
| 362 |
$urlComps[ 'scheme' ] = 'https'; |
| 363 |
$urlPurge = Net::UrlDeParse( $urlComps, 0, array( PHP_URL_QUERY, PHP_URL_FRAGMENT ) ); |
| 364 |
if( isset( $urlComps[ 'query' ] ) ) |
| 365 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', $urlPurge . '.*', array( 'x-purge-method' => 'regex' ) ); |
| 366 |
else |
| 367 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', $urlPurge, array( 'x-purge-method' => 'default' ) ); |
| 368 |
} |
| 369 |
} |
| 370 |
else |
| 371 |
$requestRes = _CacheExt_SockDoRequest( $aSrv[ 'SERVER_ADDR' ], 'PURGE', Wp::GetSiteRootUrl( '.*' ), array( 'x-purge-method' => 'regex' ) ); |
| 372 |
|
| 373 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 374 |
LogWrite( 'DreamHost: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 375 |
} |
| 376 |
|
| 377 |
global $wpaas_cache_class; |
| 378 |
|
| 379 |
if( ( Gen::DoesFuncExist( '\\WPaaS\\Cache_V2::ban' ) && $wpaas_cache_class ) ) |
| 380 |
{ |
| 381 |
|
| 382 |
$logInfo = ''; |
| 383 |
|
| 384 |
if( $url ) |
| 385 |
{ |
| 386 |
if( method_exists( $wpaas_cache_class, 'purge' ) ) |
| 387 |
$wpaas_cache_class -> purge( array( $url ) ); |
| 388 |
if( method_exists( $wpaas_cache_class, 'flush_cdn' ) ) |
| 389 |
$wpaas_cache_class -> flush_cdn(); |
| 390 |
|
| 391 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 392 |
} |
| 393 |
else |
| 394 |
{ |
| 395 |
if( method_exists( $wpaas_cache_class, 'ban' ) ) |
| 396 |
$wpaas_cache_class -> ban(); |
| 397 |
if( method_exists( $wpaas_cache_class, 'flush_transients' ) ) |
| 398 |
$wpaas_cache_class -> flush_transients(); |
| 399 |
|
| 400 |
if( method_exists( $wpaas_cache_class, 'flush_ob' ) ) |
| 401 |
$wpaas_cache_class -> flush_ob(); |
| 402 |
if( method_exists( $wpaas_cache_class, 'flush_object_cache' ) ) |
| 403 |
$wpaas_cache_class -> flush_object_cache(); |
| 404 |
|
| 405 |
$logInfo = 'Purged all'; |
| 406 |
} |
| 407 |
|
| 408 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 409 |
LogWrite( 'WPAAS: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 410 |
} |
| 411 |
else |
| 412 |
|
| 413 |
if( Gen::DoesFuncExist( '\\WPaaS\\Plugin::vip' ) ) |
| 414 |
{ |
| 415 |
|
| 416 |
$urlPurge = $url; |
| 417 |
if( !$urlPurge ) |
| 418 |
$urlPurge = Wp::GetSiteRootUrl(); |
| 419 |
$urlPurge = preg_replace( '@^https://@', 'http://', $urlPurge ); |
| 420 |
|
| 421 |
update_option( 'gd_system_last_cache_flush', time() ); |
| 422 |
$requestRes = _CacheExt_SockDoRequest( \WPaaS\Plugin::vip(), 'BAN', $urlPurge ); |
| 423 |
|
| 424 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 425 |
LogWrite( 'GoDaddy: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 426 |
} |
| 427 |
|
| 428 |
if( ( defined( 'KINSTAMU_VERSION' ) ) ) |
| 429 |
{ |
| 430 |
$requestRes = Gen::E_INVALIDARG; |
| 431 |
|
| 432 |
if( $url ) |
| 433 |
{ |
| 434 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 435 |
$requestRes = Net::RemoteRequest( 'POST', 'https://localhost/kinsta-clear-cache/v2/immediate', array( 'sslverify' => false, 'timeout' => Gen::Constant( 'KINSTAMU_CACHE_PURGE_TIMEOUT', 5 ), 'body' => Net::UrlBuildQuery( array( 'single|custom|0' => ltrim( Net::UrlDeParse( $urlComps, 0, array(), array( PHP_URL_HOST, PHP_URL_PORT, PHP_URL_PATH ) ), '/' ) ) ) ) ); |
| 436 |
} |
| 437 |
else |
| 438 |
{ |
| 439 |
$requestRes = Wp::RemoteGet( 'https://localhost/kinsta-clear-cache-all', array( 'timeout' => 5, 'sslverify' => false ) ); |
| 440 |
$requestRes = Wp::RemoteGet( 'https://localhost/kinsta-clear-cache-cdn', array( 'timeout' => 5, 'sslverify' => false ) ); |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 445 |
LogWrite( 'Kinsta: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 446 |
} |
| 447 |
|
| 448 |
if( Gen::DoesFuncExist( '\\PagelyCachePurge::purgePath' ) ) |
| 449 |
{ |
| 450 |
$logInfo = ''; |
| 451 |
|
| 452 |
if( $url ) |
| 453 |
{ |
| 454 |
$logInfo = 'URL \'' . $url . '\' invalid'; |
| 455 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 456 |
if( isset( $urlComps[ 'path' ] ) ) |
| 457 |
{ |
| 458 |
( new \PagelyCachePurge() ) -> purgePath( $urlComps[ 'path' ] . '(.*)' ); |
| 459 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 460 |
} |
| 461 |
} |
| 462 |
else |
| 463 |
{ |
| 464 |
( new \PagelyCachePurge() ) -> purgeAll(); |
| 465 |
$logInfo = 'Purged all'; |
| 466 |
} |
| 467 |
|
| 468 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 469 |
LogWrite( 'Pagely: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 470 |
} |
| 471 |
|
| 472 |
if( Gen::DoesFuncExist( '\\CDN_Clear_Cache_Api::cache_api_call' ) ) |
| 473 |
{ |
| 474 |
$logInfo = ''; |
| 475 |
|
| 476 |
if( $url ) |
| 477 |
{ |
| 478 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 479 |
{ |
| 480 |
\CDN_Clear_Cache_Api::cache_api_call( array( Net::UrlDeParse( $urlComps, 0, array(), array( PHP_URL_PATH, PHP_URL_QUERY ) ) ), 'purge' ); |
| 481 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 482 |
} |
| 483 |
else |
| 484 |
$logInfo = 'URL \'' . $url . '\' invalid'; |
| 485 |
} |
| 486 |
else if( Gen::DoesFuncExist( 'CDN_Clear_Cache_Hooks::purge_cache' ) ) |
| 487 |
{ |
| 488 |
\CDN_Clear_Cache_Hooks::purge_cache(); |
| 489 |
$logInfo = 'Purged all'; |
| 490 |
} |
| 491 |
else |
| 492 |
$logInfo = 'Invalid state'; |
| 493 |
|
| 494 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 495 |
LogWrite( 'RocketNet: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 496 |
} |
| 497 |
|
| 498 |
if( ( strpos( ($aSrv[ 'HTTP_X_SERAPH_ACCEL_WARPDRIVE_API' ]??''), '//api.savvii.services' ) !== false ) ) |
| 499 |
{ |
| 500 |
$requestRes = Gen::E_INVALIDARG; |
| 501 |
|
| 502 |
if( $url ) |
| 503 |
{ |
| 504 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 505 |
$requestRes = Wp::RemoteRequest( 'PURGE', Net::UrlDeParse( $urlComps ) . 'purge', array( 'sslverify' => false, 'headers' => array( 'X-PURGE-HOST' => ($urlComps[ 'host' ]??null), 'X-PURGE-PATH-REGEX' => ($urlComps[ 'path' ]??'') . '.*' ) ) ); |
| 506 |
} |
| 507 |
else |
| 508 |
{ |
| 509 |
if( $urlComps = Net::UrlParse( Wp::GetSiteRootUrl() ) ) |
| 510 |
$requestRes = Wp::RemoteRequest( 'PURGE', Net::UrlDeParse( $urlComps ) . 'purge', array( 'sslverify' => false, 'headers' => array( 'X-PURGE-HOST' => ($urlComps[ 'host' ]??null) ) ) ); |
| 511 |
} |
| 512 |
|
| 513 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 514 |
LogWrite( 'Savvii: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 515 |
} |
| 516 |
|
| 517 |
if( ( defined( 'SiteGround_Optimizer\\VERSION' ) || strpos( $hostname, 'siteground.eu' ) !== false ) ) |
| 518 |
{ |
| 519 |
if( function_exists( 'sg_cachepress_purge_cache' ) ) |
| 520 |
{ |
| 521 |
$logInfo = ''; |
| 522 |
|
| 523 |
if( Gen::DoesFuncExist( '\\SiteGround_Optimizer\\Supercacher\\Supercacher::get_instance' ) && Gen::DoesFuncExist( '\\SiteGround_Optimizer\\Supercacher\\Supercacher::purge_cache_request' ) && Gen::DoesFuncExist( '\\SiteGround_Optimizer\\Supercacher\\Supercacher::purge_cache' ) ) |
| 524 |
{ |
| 525 |
if( $url ) |
| 526 |
\SiteGround_Optimizer\Supercacher\Supercacher::get_instance() -> purge_cache_request( $url, false ); |
| 527 |
else |
| 528 |
\SiteGround_Optimizer\Supercacher\Supercacher::purge_cache(); |
| 529 |
} |
| 530 |
|
| 531 |
if( $url ) |
| 532 |
{ |
| 533 |
sg_cachepress_purge_cache( $url ); |
| 534 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 535 |
} |
| 536 |
else if( function_exists( 'sg_cachepress_purge_everything' ) ) |
| 537 |
{ |
| 538 |
sg_cachepress_purge_everything(); |
| 539 |
$logInfo = 'Purged all'; |
| 540 |
} |
| 541 |
else |
| 542 |
$logInfo = 'Invalid state'; |
| 543 |
|
| 544 |
wp_cache_flush(); |
| 545 |
|
| 546 |
if( Gen::DoesFuncExist( '\\SiteGround_Optimizer\\Supercacher\\Supercacher::delete_assets' ) ) |
| 547 |
\SiteGround_Optimizer\Supercacher\Supercacher::delete_assets(); |
| 548 |
|
| 549 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 550 |
LogWrite( 'SiteGround: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 551 |
} |
| 552 |
else |
| 553 |
{ |
| 554 |
$requestRes = Gen::E_INVALIDARG; |
| 555 |
|
| 556 |
if( $url ) |
| 557 |
{ |
| 558 |
if( $urlComps = Net::UrlParse( $url ) ) |
| 559 |
{ |
| 560 |
$urlComps[ 'scheme' ] = 'http'; |
| 561 |
$urlPurge = Net::UrlDeParse( $urlComps, 0, array( PHP_URL_QUERY, PHP_URL_FRAGMENT ) ); |
| 562 |
if( isset( $urlComps[ 'query' ] ) ) |
| 563 |
$urlPurge .= '(.*)'; |
| 564 |
$requestRes = _CacheExt_SockDoRequest( '127.0.0.1', 'PURGE', $urlPurge ); |
| 565 |
} |
| 566 |
} |
| 567 |
else |
| 568 |
$requestRes = _CacheExt_SockDoRequest( '127.0.0.1', 'PURGE', Wp::GetSiteRootUrl( '/(.*)' ) ); |
| 569 |
|
| 570 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 571 |
LogWrite( 'SiteGround: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
if( ( isset( $aSrv[ 'HTTP_X_ZXCS_VHOST' ] ) && ( strpos( $hostname, 'zxcs' ) !== false ) ) ) |
| 576 |
{ |
| 577 |
$urlPurge = $url; |
| 578 |
if( !$urlPurge ) |
| 579 |
$urlPurge = Wp::GetSiteRootUrl() . '?purgeAll'; |
| 580 |
|
| 581 |
$requestRes = Wp::RemoteRequest( 'PURGE', $urlPurge, array( 'sslverify' => false, 'headers' => array( 'X-Purge-ZXCS' => 'true', 'host-ZXCS' => ($aSrv[ 'HTTP_HOST' ]??'') ) ) ); |
| 582 |
|
| 583 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 584 |
LogWrite( 'Vimexx: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 585 |
} |
| 586 |
|
| 587 |
if( Gen::DoesFuncExist( '\\WpeCommon::purge_varnish_cache' ) ) |
| 588 |
{ |
| 589 |
$logInfo = ''; |
| 590 |
|
| 591 |
try |
| 592 |
{ |
| 593 |
if( $url ) |
| 594 |
{ |
| 595 |
$ctx = new AnyObj(); |
| 596 |
$ctx -> urlComps = Net::UrlParse( $url ); |
| 597 |
|
| 598 |
if( $ctx -> urlComps ) |
| 599 |
{ |
| 600 |
$ctx -> cb = |
| 601 |
function( $ctx, $paths ) |
| 602 |
{ |
| 603 |
if( count( $paths ) == 1 && $paths[ 0 ] == '.*' ) |
| 604 |
$paths = array( Net::UrlDeParse( $ctx -> urlComps, 0, array(), array( PHP_URL_PATH, PHP_URL_QUERY ) ) ); |
| 605 |
return( $paths ); |
| 606 |
}; |
| 607 |
|
| 608 |
add_filter( 'wpe_purge_varnish_cache_paths', array( $ctx, 'cb' ) ); |
| 609 |
\WpeCommon::purge_varnish_cache(); |
| 610 |
remove_filter( 'wpe_purge_varnish_cache_paths', array( $ctx, 'cb' ) ); |
| 611 |
|
| 612 |
$logInfo = 'URL \'' . $url . '\' cache purged'; |
| 613 |
} |
| 614 |
else |
| 615 |
$logInfo = 'URL \'' . $url . '\' invalid'; |
| 616 |
} |
| 617 |
else |
| 618 |
{ |
| 619 |
|
| 620 |
\WpeCommon::purge_varnish_cache(); |
| 621 |
|
| 622 |
$logInfo = 'Purged all cache'; |
| 623 |
} |
| 624 |
} |
| 625 |
catch( \Exception $e ) |
| 626 |
{ |
| 627 |
$logInfo = ( string )$e; |
| 628 |
} |
| 629 |
|
| 630 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 631 |
LogWrite( 'WPEngine: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 632 |
} |
| 633 |
|
| 634 |
if( Gen::DoesFuncExist( '\\Tenweb_Manager\\Helper::clear_cache' ) ) |
| 635 |
{ |
| 636 |
\Tenweb_Manager\Helper::clear_cache(); |
| 637 |
|
| 638 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 639 |
LogWrite( '10web (Tenweb): Cleared', Ui::MsgInfo, 'Server/cloud cache update' ); |
| 640 |
} |
| 641 |
|
| 642 |
if( ( defined( 'CLP_VARNISH_VERSION' ) ) ) |
| 643 |
{ |
| 644 |
if( !Gen::DoesFuncExist( 'ClpVarnishCacheManager::purge_url' ) ) |
| 645 |
@include_once( __DIR__ . '/../clp-varnish-cache/class.varnish-cache-manager.php' ); |
| 646 |
|
| 647 |
$logInfo = ''; |
| 648 |
|
| 649 |
if( $url ) |
| 650 |
{ |
| 651 |
if( Gen::DoesFuncExist( 'ClpVarnishCacheManager::purge_url' ) ) |
| 652 |
{ |
| 653 |
try |
| 654 |
{ |
| 655 |
$clp_varnish_cache_manager = new \ClpVarnishCacheManager(); |
| 656 |
$clp_varnish_cache_manager -> purge_url( $url ); |
| 657 |
|
| 658 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 659 |
} |
| 660 |
catch( \Exception $e ) |
| 661 |
{ |
| 662 |
$logInfo = $ex -> getMessage(); |
| 663 |
} |
| 664 |
unset( $clp_varnish_cache_manager ); |
| 665 |
} |
| 666 |
else |
| 667 |
$logInfo = 'Invalid state'; |
| 668 |
} |
| 669 |
else |
| 670 |
{ |
| 671 |
if( Gen::DoesFuncExist( 'ClpVarnishCacheManager::purge_host' ) && Gen::DoesFuncExist( 'ClpVarnishCacheManager::purge_tag' ) ) |
| 672 |
{ |
| 673 |
try |
| 674 |
{ |
| 675 |
$clp_varnish_cache_manager = new \ClpVarnishCacheManager(); |
| 676 |
|
| 677 |
{ |
| 678 |
$host = Wp::SanitizeText( ($aSrv[ 'HTTP_HOST' ]??null) ); |
| 679 |
if( !empty( $host ) ) |
| 680 |
$clp_varnish_cache_manager -> purge_host( $host ); |
| 681 |
unset( $host ); |
| 682 |
} |
| 683 |
|
| 684 |
{ |
| 685 |
$cache_tag_prefix = $clp_varnish_cache_manager -> get_cache_tag_prefix(); |
| 686 |
if( !empty( $cache_tag_prefix ) ) |
| 687 |
$clp_varnish_cache_manager -> purge_tag( $cache_tag_prefix ); |
| 688 |
unset( $cache_tag_prefix ); |
| 689 |
} |
| 690 |
|
| 691 |
$logInfo = 'Purged all'; |
| 692 |
} |
| 693 |
catch( \Exception $e ) |
| 694 |
{ |
| 695 |
$logInfo = $ex -> getMessage(); |
| 696 |
} |
| 697 |
unset( $clp_varnish_cache_manager ); |
| 698 |
} |
| 699 |
else |
| 700 |
$logInfo = 'Invalid state'; |
| 701 |
} |
| 702 |
|
| 703 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 704 |
LogWrite( 'CloudPanel: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 705 |
} |
| 706 |
|
| 707 |
if( ( Gen::DoesFuncExist( 'Endurance_Page_Cache::purge_all' ) ) ) |
| 708 |
{ |
| 709 |
$logInfo = ''; |
| 710 |
|
| 711 |
global $epc; |
| 712 |
|
| 713 |
if( $url ) |
| 714 |
{ |
| 715 |
if( Gen::DoesFuncExist( 'Endurance_Page_Cache::purge_single' ) ) |
| 716 |
{ |
| 717 |
try |
| 718 |
{ |
| 719 |
$epc -> purge_single( $url ); |
| 720 |
|
| 721 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 722 |
} |
| 723 |
catch( \Exception $e ) |
| 724 |
{ |
| 725 |
$logInfo = $ex -> getMessage(); |
| 726 |
} |
| 727 |
unset( $clp_varnish_cache_manager ); |
| 728 |
} |
| 729 |
else |
| 730 |
$logInfo = 'Invalid state'; |
| 731 |
} |
| 732 |
else |
| 733 |
{ |
| 734 |
try |
| 735 |
{ |
| 736 |
$epc -> purge_all(); |
| 737 |
|
| 738 |
$logInfo = 'Purged all'; |
| 739 |
} |
| 740 |
catch( \Exception $e ) |
| 741 |
{ |
| 742 |
$logInfo = $ex -> getMessage(); |
| 743 |
} |
| 744 |
unset( $clp_varnish_cache_manager ); |
| 745 |
} |
| 746 |
|
| 747 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 748 |
LogWrite( 'Endurance Page Cache: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 749 |
} |
| 750 |
|
| 751 |
if( Gen::GetArrField( $sett, array( 'cache', 'sucuri', 'apiKey' ), '' ) ) |
| 752 |
{ |
| 753 |
|
| 754 |
if( $url ) |
| 755 |
{ |
| 756 |
$urlPurge = Net::UrlParse( $url ); |
| 757 |
$urlPurge = Gen::GetArrField( $urlPurge, array( 'path' ), '' ); |
| 758 |
} |
| 759 |
|
| 760 |
$requestRes = Wp::RemoteRequest( 'POST', 'https://waf.sucuri.net/api?v2', array( 'body' => 'k=' . Gen::GetArrField( $sett, array( 'cache', 'sucuri', 'apiKey' ), '' ) . '&s=' . Gen::GetArrField( $sett, array( 'cache', 'sucuri', 'apiSecret' ), '' ) . '&a=clear_cache' . ( $urlPurge ? ( '&file=' . rawurlencode( $urlPurge ) ) : '' ), 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ), 'sslverify' => false ) ); |
| 761 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 762 |
LogWrite( 'Sucuri: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 763 |
} |
| 764 |
|
| 765 |
if( ( Gen::DoesFuncExist( 'pantheon_clear_edge_all' ) ) ) |
| 766 |
{ |
| 767 |
$logInfo = ''; |
| 768 |
|
| 769 |
if( $url ) |
| 770 |
{ |
| 771 |
if( Gen::DoesFuncExist( 'pantheon_clear_edge_paths' ) ) |
| 772 |
{ |
| 773 |
try |
| 774 |
{ |
| 775 |
$urlPurge = Net::UrlParse( $url ); |
| 776 |
$urlPurge = Gen::GetArrField( $urlPurge, array( 'path' ), '' ); |
| 777 |
pantheon_clear_edge_paths( array( $urlPurge ) ); |
| 778 |
|
| 779 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 780 |
} |
| 781 |
catch( \Exception $e ) |
| 782 |
{ |
| 783 |
$logInfo = $ex -> getMessage(); |
| 784 |
} |
| 785 |
} |
| 786 |
else |
| 787 |
$logInfo = 'Invalid state'; |
| 788 |
} |
| 789 |
else |
| 790 |
{ |
| 791 |
try |
| 792 |
{ |
| 793 |
pantheon_clear_edge_all(); |
| 794 |
|
| 795 |
$logInfo = 'Purged all'; |
| 796 |
} |
| 797 |
catch( \Exception $e ) |
| 798 |
{ |
| 799 |
$logInfo = $ex -> getMessage(); |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 804 |
LogWrite( 'Pantheon Cache: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 805 |
} |
| 806 |
|
| 807 |
if( ( Gen::DoesFuncExist( '\\Servebolt\\Optimizer\\CachePurge\\WordPressCachePurge\\WordPressCachePurge::purgeAll' ) ) ) |
| 808 |
{ |
| 809 |
$logInfo = ''; |
| 810 |
|
| 811 |
if( $url ) |
| 812 |
{ |
| 813 |
if( Gen::DoesFuncExist( '\\Servebolt\\Optimizer\\CachePurge\\WordPressCachePurge\\WordPressCachePurge::purgeByUrl' ) ) |
| 814 |
{ |
| 815 |
try |
| 816 |
{ |
| 817 |
\Servebolt\Optimizer\CachePurge\WordPressCachePurge\WordPressCachePurge::purgeByUrl( $url, false ); |
| 818 |
|
| 819 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 820 |
} |
| 821 |
catch( \Exception $e ) |
| 822 |
{ |
| 823 |
$logInfo = $ex -> getMessage(); |
| 824 |
} |
| 825 |
} |
| 826 |
else |
| 827 |
$logInfo = 'Invalid state'; |
| 828 |
} |
| 829 |
else |
| 830 |
{ |
| 831 |
try |
| 832 |
{ |
| 833 |
\Servebolt\Optimizer\CachePurge\WordPressCachePurge\WordPressCachePurge::purgeAll(); |
| 834 |
|
| 835 |
$logInfo = 'Purged all'; |
| 836 |
} |
| 837 |
catch( \Exception $e ) |
| 838 |
{ |
| 839 |
$logInfo = $ex -> getMessage(); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 844 |
LogWrite( 'Servebolt Cache: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 845 |
} |
| 846 |
|
| 847 |
if( ( Gen::DoesFuncExist( '\\Edge_Cache_Atomic::purge_domain' ) ) ) |
| 848 |
{ |
| 849 |
$logInfo = ''; |
| 850 |
|
| 851 |
if( $url ) |
| 852 |
{ |
| 853 |
try |
| 854 |
{ |
| 855 |
$oPlatform = new \Edge_Cache_Atomic(); |
| 856 |
$actions = array( 'auto_purge_url' ); |
| 857 |
$aTags = array( |
| 858 |
'platform' => $oPlatform -> get_platform_type(), |
| 859 |
'wp_domain' => $oPlatform -> get_domain_name(), |
| 860 |
'wp_actions' => implode( ',', $actions ), |
| 861 |
'wp_action' => array_keys( $actions ), |
| 862 |
'domain_purge' => 'no', |
| 863 |
'urls_cnt' => 1, |
| 864 |
'purge_count' => count( $actions ), |
| 865 |
'batcache' => 'success', |
| 866 |
); |
| 867 |
$logInfo = 'URL \'' . $url . '\' ' . ( $oPlatform -> purge_uris( array( $url ), $aTags ) ? 'purged' : 'not purged' ); |
| 868 |
} |
| 869 |
catch( \Exception $e ) |
| 870 |
{ |
| 871 |
$logInfo = $ex -> getMessage(); |
| 872 |
} |
| 873 |
} |
| 874 |
else |
| 875 |
{ |
| 876 |
try |
| 877 |
{ |
| 878 |
$oPlatform = new \Edge_Cache_Atomic(); |
| 879 |
$actions = array( 'auto_purge_all' ); |
| 880 |
$aTags = array( |
| 881 |
'platform' => $oPlatform -> get_platform_type(), |
| 882 |
'wp_domain' => $oPlatform -> get_domain_name(), |
| 883 |
'wp_actions' => implode( ',', $actions ), |
| 884 |
'wp_action' => array_keys( $actions ), |
| 885 |
'domain_purge' => 'yes', |
| 886 |
'urls_cnt' => 0, |
| 887 |
'purge_count' => count( $actions ), |
| 888 |
'batcache' => 'success', |
| 889 |
); |
| 890 |
$logInfo = ( $oPlatform -> purge_domain( $oPlatform -> get_domain_name(), $aTags ) ? 'Purged all' : 'Not purged all' ); |
| 891 |
} |
| 892 |
catch( \Exception $e ) |
| 893 |
{ |
| 894 |
$logInfo = $ex -> getMessage(); |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 899 |
LogWrite( 'Pressable Cache: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 900 |
} |
| 901 |
|
| 902 |
if( ( ($aSrv[ 'HTTP_X_SERAPH_ACCEL_H_PLATFORM' ]??null) == 'Hostinger' ) ) |
| 903 |
{ |
| 904 |
$logInfo = ''; |
| 905 |
|
| 906 |
if( $url ) |
| 907 |
{ |
| 908 |
|
| 909 |
} |
| 910 |
else |
| 911 |
{ |
| 912 |
wp_cache_flush(); |
| 913 |
|
| 914 |
$logInfo = 'Purged all'; |
| 915 |
} |
| 916 |
|
| 917 |
if( $logInfo && ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 918 |
LogWrite( 'Hostinger: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 919 |
} |
| 920 |
|
| 921 |
if( ( isset( $aSrv[ 'HTTP_X_SERAPH_ACCEL_CW_ALLOWED_IP' ] ) || @preg_match( '@/home/.*?cloudways.*@', __DIR__ ) ) ) |
| 922 |
{ |
| 923 |
|
| 924 |
{ |
| 925 |
if( $url ) |
| 926 |
{ |
| 927 |
$method = 'URLPURGE'; |
| 928 |
$urlRequest = $url; |
| 929 |
} |
| 930 |
else |
| 931 |
{ |
| 932 |
$method = 'PURGE'; |
| 933 |
$urlRequest = Wp::GetSiteRootUrl( '.*' ); |
| 934 |
} |
| 935 |
|
| 936 |
$urlComps = Net::UrlParse( $urlRequest ); |
| 937 |
$requestRes = $urlComps ? _CacheExt_SockDoRequest( '127.0.0.1', $method, $urlRequest, array( 'Host' => ($urlComps[ 'host' ]??''), 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' ), null, null ) : Gen::E_INVALIDARG; |
| 938 |
|
| 939 |
if( strlen( Gen::GetArrField( $requestRes, array( 'body' ), '' ) ) ) |
| 940 |
Gen::SetArrField( $requestRes, array( 'body' ), '' ); |
| 941 |
|
| 942 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 943 |
LogWrite( 'CloudWays (Varhish): ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 944 |
} |
| 945 |
|
| 946 |
if( defined( 'CDN_SITE_ID' ) && defined( 'CDN_SITE_TOKEN' ) && ( $urlFpcMicroservice = getenv( 'FPC_ENV' ) ) ) |
| 947 |
{ |
| 948 |
$data = array( |
| 949 |
'urls' => array(), |
| 950 |
'appToken' => CDN_SITE_TOKEN, |
| 951 |
'appId' => CDN_SITE_ID, |
| 952 |
'platform' => 'fmp', |
| 953 |
); |
| 954 |
|
| 955 |
if( $url ) |
| 956 |
{ |
| 957 |
$endpoint_path = 'purge-fpc-url'; |
| 958 |
$data[ 'urls' ][] = $url; |
| 959 |
} |
| 960 |
else |
| 961 |
{ |
| 962 |
$endpoint_path = 'purge-fpc-domain'; |
| 963 |
$data[ 'urls' ][] = Wp::GetSiteRootUrl( '', false ); |
| 964 |
|
| 965 |
if( Wp::IsMultisite() && !is_subdomain_install() ) |
| 966 |
{ |
| 967 |
$endpoint_path = 'purge-fpc-sub-dir'; |
| 968 |
foreach( $data[ 'urls' ] as &$urlE ) |
| 969 |
$urlE = Gen::SetLastSlash( $urlE, false ); |
| 970 |
unset( $urlE ); |
| 971 |
} |
| 972 |
else |
| 973 |
{ |
| 974 |
foreach( $data[ 'urls' ] as &$urlE ) |
| 975 |
{ |
| 976 |
$urlE = trim( $urlE ); |
| 977 |
$urlE = ltrim( $urlE, 'https:' ); |
| 978 |
$urlE = ltrim( $urlE, '//' ); |
| 979 |
$urlE = Gen::SetLastSlash( $urlE, false ); |
| 980 |
} |
| 981 |
unset( $urlE ); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
if( strpos( $aSrv[ 'DOCUMENT_ROOT' ], 'cloudwaysstagingapps.com' ) !== false || strpos( $aSrv[ 'DOCUMENT_ROOT' ], 'cloudwaysapps.com' ) !== false ) |
| 986 |
$data[ 'platform' ] = 'fp'; |
| 987 |
|
| 988 |
$data = @json_encode( $data ); |
| 989 |
$urlFpcMicroservice = Gen::SetLastSlash( $urlFpcMicroservice ) . $endpoint_path; |
| 990 |
|
| 991 |
$requestRes = |
| 992 |
Net::RemoteRequest |
| 993 |
|
| 994 |
( 'POST', $urlFpcMicroservice, array( 'timeout' => 4, 'sslverify' => false, 'body' => $data, 'referer' => home_url(), 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), 'headers' => array( 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Content-Length' => strlen( $data ) ) ) ); |
| 995 |
|
| 996 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 997 |
LogWrite( 'CloudWays (CloudFlare): ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
if( Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'zoneId' ), '' ) ) |
| 1002 |
{ |
| 1003 |
|
| 1004 |
$requestBody = ''; |
| 1005 |
if( $url ) |
| 1006 |
$requestBody = '{"files": ["' . $url . '"]}'; |
| 1007 |
else |
| 1008 |
$requestBody = '{"purge_everything":true}'; |
| 1009 |
|
| 1010 |
$aHdr = array( 'Content-Type' => 'application/json' ); |
| 1011 |
switch( Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'auth' ), '' ) ) |
| 1012 |
{ |
| 1013 |
case 'key': |
| 1014 |
$aHdr[ 'X-Auth-Email' ] = Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'email' ), '' ); |
| 1015 |
$aHdr[ 'X-Auth-Key' ] = Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'apiKey' ), '' ); |
| 1016 |
break; |
| 1017 |
case 'token': |
| 1018 |
$aHdr[ 'Authorization' ] = 'Bearer ' . Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'apiToken' ), '' ); |
| 1019 |
break; |
| 1020 |
} |
| 1021 |
|
| 1022 |
$requestRes = Wp::RemoteRequest( 'POST', 'https://api.cloudflare.com/client/v4/zones/' . rawurlencode( Gen::GetArrField( $sett, array( 'cache', 'cloudflare', 'zoneId' ), '' ) ) . '/purge_cache', array( 'body' => $requestBody, 'headers' => $aHdr, 'sslverify' => false ) ); |
| 1023 |
|
| 1024 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 1025 |
LogWrite( 'CloudFlare: ' . _CacheExt_GetResponseResString( $requestRes ), Ui::MsgInfo, 'Server/cloud cache update' ); |
| 1026 |
} |
| 1027 |
else if( Gen::DoesFuncExist( '\\Cloudflare\\APO\\WordPress\\Hooks::purgeCacheEverything' ) ) |
| 1028 |
{ |
| 1029 |
$logInfo = ''; |
| 1030 |
|
| 1031 |
if( $url ) |
| 1032 |
{ |
| 1033 |
( new CloudFlareHooksEx() ) -> purgeUrl( $url ); |
| 1034 |
$logInfo = 'URL \'' . $url . '\' purged'; |
| 1035 |
} |
| 1036 |
else |
| 1037 |
{ |
| 1038 |
( new CloudFlareHooksEx() ) -> purgeAll(); |
| 1039 |
$logInfo = 'Purged all'; |
| 1040 |
} |
| 1041 |
|
| 1042 |
if( ($sett[ 'log' ]??null) && ($sett[ 'logScope' ][ 'srvClr' ]??null) ) |
| 1043 |
LogWrite( 'CloudFlare: ' . $logInfo, Ui::MsgInfo, 'Server/cloud cache update' ); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
|