HEX
Server: LiteSpeed
System: Linux melbournecleaninggroup 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: www-data (33)
PHP: 7.3.33-1+focal
Disabled: 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/wp-content/plugins/backup-guard-security-platinum/com/lib/ReloadHandler.php
<?php

namespace BackupGuard\Security;

class ReloadHandler
{
	private $host;
	private $uri;
	private $scheme;
	private $port;
	private $reloadMethod;
	private $selectedReloadMethod;

	public function __construct($url)
	{
		$this->host = @$_SERVER['HTTP_HOST'];
		$this->url = $url;
		$this->port = @$_SERVER['SERVER_PORT'];
		$this->scheme = Helper::getCurrentUrlScheme();

		$this->selectedReloadMethod = Config::get('BGS_BACKGROUND_RELOAD_METHOD');

		if (!$this->port) {
			$this->port = 80;
		}

		$this->reloadMethod = Config::get('BGS_RELOAD_METHOD');
		if ($this->reloadMethod === null || $this->reloadMethod == BGS_RELOAD_METHOD_AJAX) {
			$this->setBestReloadMethod();
		}
	}

	public function reload()
	{
		switch ($this->reloadMethod) {
			case BGS_RELOAD_METHOD_STREAM:
				$this->reloadUsingStream();
				break;
			case BGS_RELOAD_METHOD_CURL:
				$this->reloadUsingCurl();
				break;
			case BGS_RELOAD_METHOD_SOCKET:
				$this->reloadUsingSocket();
				break;
		}
	}

	public function canReload()
	{
		return ($this->reloadMethod && $this->reloadMethod != BGS_RELOAD_METHOD_NONE);
	}

	public function setBestReloadMethod()
	{
		$method = BGS_RELOAD_METHOD_NONE;
		if ($this->selectedReloadMethod) {
			if ($this->selectedReloadMethod == BGS_RELOAD_METHOD_CURL) {
				if (function_exists('curl_version')) {
					$method = BGS_RELOAD_METHOD_CURL;
				}
				else {
					$method = $this->getBestAvailableMethod();
				}
			}
			else if ($this->selectedReloadMethod == BGS_RELOAD_METHOD_STREAM) {
				if ($this->testStreamConnection()) {
					$method = BGS_RELOAD_METHOD_STREAM;
				}
				else {
					$method = $this->getBestAvailableMethod();
				}
			}
			else if ($this->selectedReloadMethod == BGS_RELOAD_METHOD_SOCKET && $this->testSocketConnection()) {
				if ($this->testSocketConnection()) {
					$method = BGS_RELOAD_METHOD_SOCKET;
				}
				else {
					$method = $this->getBestAvailableMethod();
				}
			}
		}
		else {
			$method = $this->getBestAvailableMethod();
		}

		$this->reloadMethod = $method;
	}

	private function getBestAvailableMethod()
	{
		if (function_exists('curl_version')) {
			return BGS_RELOAD_METHOD_CURL;
		}
		else if ($this->testStreamConnection()) {
			return BGS_RELOAD_METHOD_STREAM;
		}
		else if ($this->testSocketConnection()) {
			return BGS_RELOAD_METHOD_SOCKET;
		}

		return BGS_RELOAD_METHOD_NONE;
	}

	private function reloadUsingStream()
	{
		$transport = $this->scheme=='http'?'tcp':'ssl';
		$addr = $this->host;

		if ($transport == 'ssl') {
			$context = stream_context_create();
			stream_context_set_option($context, 'ssl', 'verify_host', true);
			stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
			$fp = @stream_socket_client("$transport://$addr:".$this->port, $errno, $errstr, 15, STREAM_CLIENT_CONNECT, $context);
		}
		else {
			$fp = @stream_socket_client("$transport://$addr:".$this->port, $errno, $errstr, 15, STREAM_CLIENT_CONNECT);
		}

		if ($fp === false) {
			return false;
		}

		$out = "GET ".$this->url." HTTP/1.1\r\n";
		$out .= "Host: ".$this->host."\r\n";
		$out .= "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8\r\n";
		$out .= "Connection: Close\r\n\r\n";

		@fwrite($fp, $out);
		sleep(1);
		@fclose($fp);
	}

	private function reloadUsingCurl()
	{
		$url = $this->scheme.'://'.$this->host.$this->url;

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPGET, true);
		curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'doNothing');
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8');
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_exec($ch);
		sleep(1);
		curl_close($ch);
	}

	private function reloadUsingSocket()
	{
		$addr = @gethostbyname($this->host);
		$transport = $this->scheme == 'http'?'tcp':'ssl';

		$fp = @fsockopen("$transport://$addr", $this->port, $errno, $errstr, 15);

		if ($fp === false) {
			return false;
		}

		$out = "GET ".$this->url." HTTP/1.1\r\n";
		$out .= "Host: ".$this->host."\r\n";
		$out .= "Connection: Close\r\n\r\n";

		@fwrite($fp, $out);
		sleep(1);
		@fclose($fp);
	}

	private function testStreamConnection()
	{
		$addr = @gethostbyname($this->host);
		$fp = @stream_socket_client("tcp://$addr:".$this->port, $errno, $errstr);

		if ($fp === false) {
			return false;
		}

		@fclose($fp);
		return true;
	}

	private function testSocketConnection()
	{
		$fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10);

		if ($fp === false) {
			return false;
		}

		@fclose($fp);
		return true;
	}
}

function doNothing($curl, $input)
{
	return 0;
}