HEX
Server: Apache
System: Linux web2213.uni5.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64
User: clinicamaciel (596848)
PHP: 7.3.33
Disabled: apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,eval,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv
Upload Files
File: /home/clinicamaciel/www/wp-content/plugins/w3-total-cache/Cdnfsd_LimeLight_Api.php
<?php
namespace W3TC;



class Cdnfsd_LimeLight_Api {
	private $url_base;



	public function __construct( $short_name, $username, $api_key ) {
		$this->url_base = 'https://purge.llnw.com/purge/v1/account/' .
			$short_name . '/requests';
		$this->username = $username;
		$this->api_key = $api_key;
	}



	public function purge( $items ) {
		$body = json_encode( array( 'patterns' => $items ) );
		return $this->_wp_remote_post( '', $body );
	}



	public function get( $uri ) {
		return $this->_wp_remote_get( $uri );
	}



	private function _wp_remote_get( $uri, $body = '', $headers = array() ) {
		$url = $this->url_base . $uri;
		$headers = $this->_add_headers( $headers, $url, 'GET', $body );

		$result = wp_remote_get( $url, array(
				'headers' => $headers,
				'body' => $body
			) );

		return $this->_decode_response( $result );
	}



	private function _wp_remote_post( $uri, $body, $headers = array() ) {
		$url = $this->url_base . $uri;
		$headers = $this->_add_headers( $headers, $url, 'POST', $body );

		$result = wp_remote_post( $url, array(
				'headers' => $headers,
				'body' => $body
			) );

		return $this->_decode_response( $result );
	}



	private function _add_headers( $headers, $url, $method, $body ) {
		$timestamp = '' . ( time() * 1000 );

		$headers['Content-Type'] = 'application/json';
		$headers['X-LLNW-Security-Principal'] = $this->username;
		$headers['X-LLNW-Security-Timestamp'] = $timestamp;
		$headers['X-LLNW-Security-Token'] = hash_hmac( 'sha256',
			$method . $url . $timestamp . $body, pack( 'H*', $this->api_key ) );

		return $headers;
	}



	private function _decode_response( $result ) {
		if ( is_wp_error( $result ) )
			throw new \Exception( 'Failed to reach API endpoint' );

		$response_json = @json_decode( $result['body'], true );
		if ( is_null( $response_json ) ) {
			throw new \Exception(
				'Failed to reach API endpoint, got unexpected response ' .
				$result['body'] );
		}

		if ( $result['response']['code'] != '200' &&
			$result['response']['code'] != '201' &&
			$result['response']['code'] != '202' &&
			$result['response']['code'] != '204' ) {
			if ( isset( $response_json['errors'] ) &&
				isset( $response_json['errors'][0]['description'] ) ) {
				throw new \Exception( $response_json['errors'][0]['description'] );
			}

			throw new \Exception( $result['body'] );
		}


		return $response_json;
	}
}