| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/plugins/wp-fastest-cache/inc/ |
Upload File : |
<?php
class VarnishWPFC{
public static function purge_cache($data = false) {
if(isset($GLOBALS["wpfc_varnish_purge_cache_executed"])){
return;
}else{
$GLOBALS["wpfc_varnish_purge_cache_executed"] = true;
}
if(gettype($data) == "array"){
// Clearing page cache action sends the data as Array
if(isset($data["status"]) && $data["status"] == "pause"){
return array("success" => true);
}
$server = $data["server"];
}else{
// Ajax request and save() function send the data as string
$server = $data;
}
$home = get_option('home');
$host = preg_replace("/(https?\:\/\/)(.+)/", "$2", $home);
$host = preg_replace("/\/.*/", "", $host);
$schema = preg_replace("/(https?\:\/\/).+/", "$1", $home);
$schema = strtolower($schema);
$ssl_verification = $schema == 'https://' ? true : false;
$request_url = $schema.$server."/.*";
$request_args = array(
'method' => "PURGE",
'headers' => array(
'Host' => $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',
),
'sslverify' => $ssl_verification,
);
$response = wp_remote_request($request_url, $request_args );
if(is_wp_error( $response ) || $response['response']['code'] != '200'){
if($schema === 'https://'){
$request_url = str_replace("https://", "http://", $request_url);
}else{
$request_url = str_replace("http://", "https://", $request_url);
}
$response = wp_remote_request($request_url, $request_args );
if(is_wp_error( $response ) || $response['response']['code'] != '200'){
if($response->get_error_messages()){
return array("success" => "", "message" => $response->get_error_message());
}
if($response['response']['code'] == "501"){
$text = '"Purge" method is not allowed';
if(isset($response['headers']['allow'])){
$text = $text.". The allowed methods are ".$response['headers']['allow'];
$text = $text.". Please contact your hosting provider";
}
return array("success" => "", "message" => $text);
}
}
}
return array("success" => true);
}
public static function save(){
if(!wp_verify_nonce($_POST["security"], 'wpfc-varnish-ajax-nonce')){
die( 'Security check' );
}
$_POST["server"] = sanitize_text_field($_POST["server"]);
$purce_res = self::purge_cache($_POST["server"]);
if(!$purce_res["success"]){
wp_send_json($purce_res);
}
$datas = get_option("WpFastestCacheVarnish");
if(!is_array($datas)){
$datas = array();
$datas["server"] = $_POST["server"];
add_option("WpFastestCacheVarnish", $datas, 1, "yes");
}else{
$datas["server"] = $_POST["server"];
update_option("WpFastestCacheVarnish", $datas, 1, "yes");
}
wp_send_json_success();
}
public static function status(){
$datas = get_option("WpFastestCacheVarnish");
if(is_array($datas)){
if(isset($datas["status"]) && $datas["status"] == "pause"){
echo "isConnected pause";
}else{
echo "isConnected";
}
}
}
public static function start(){
if(!wp_verify_nonce($_POST["security"], 'wpfc-varnish-ajax-nonce')){
die( 'Security check' );
}
$datas = get_option("WpFastestCacheVarnish");
if(is_array($datas)){
unset($datas["status"]);
$purce_res = self::purge_cache($datas);
if(!$purce_res["success"]){
wp_send_json($purce_res);
}
update_option("WpFastestCacheVarnish", $datas, 1, "yes");
}
wp_send_json_success();
}
public static function pause(){
if(!wp_verify_nonce($_POST["security"], 'wpfc-varnish-ajax-nonce')){
die( 'Security check' );
}
$datas = get_option("WpFastestCacheVarnish");
if(is_array($datas)){
$datas["status"] = "pause";
update_option("WpFastestCacheVarnish", $datas, 1, "yes");
}
wp_send_json_success();
}
public static function remove(){
if(!wp_verify_nonce($_POST["security"], 'wpfc-varnish-ajax-nonce')){
die( 'Security check' );
}
delete_option("WpFastestCacheVarnish");
wp_send_json_success();
}
}
?>