Server IP : 172.67.157.199 / Your IP : 18.222.162.212 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/plugins/defender-security/src/integrations/ |
Upload File : |
<?php /** * Handles interactions with Block list API. * * @package WP_Defender\Integrations */ namespace WP_Defender\Integrations; if ( ! defined( 'ABSPATH' ) ) { die; } use WP_Error; use WP_Defender\Behavior\WPMUDEV; /** * Block list API client. * * @since 4.7.1 */ class Blocklist_Client { /** * The base URL of the Blocklist API service. * * @var string */ private $base_url = 'https://staging-api.blocklist-service.com'; // TODO: Change this to the production API URL. /** * The WPMUDEV instance. * * @var WPMUDEV */ private $wpmudev; /** * Constructor for the Blocklist_Client class. * * @param WPMUDEV $wpmudev The WPMUDEV object. */ public function __construct( WPMUDEV $wpmudev ) { $this->wpmudev = $wpmudev; } /** * Get the base URL of the Blocklist API service. * * @return string */ private function get_base_url(): string { $base_url = defined( 'BLOCKLIST_CUSTOM_API_SERVER' ) && BLOCKLIST_CUSTOM_API_SERVER ? BLOCKLIST_CUSTOM_API_SERVER : $this->base_url; return $base_url . '/api'; } /** * Send firewall logs to blocklist API. * * @param array $data The firewall logs. * * @return array|WP_Error */ public function send_reports( $data ) { return $this->make_request( 'POST', '/report', $data ); } /** * Make a request to the Blocklist API service. * * @param string $method The HTTP method to use. * @param string $endpoint The API endpoint to request. * @param array $data The data to send with the request. * * @return array|WP_Error */ private function make_request( $method, $endpoint, $data = array() ) { $apikey = $this->wpmudev->get_apikey(); if ( ! $apikey ) { return new WP_Error( 'no_api_key', 'No API key provided' ); } $response = wp_remote_request( $this->get_base_url() . $endpoint, array( 'method' => $method, 'headers' => array( 'x-blocklist-auth' => $apikey, 'Content-Type' => 'application/json', ), 'body' => wp_json_encode( $data ), ) ); if ( is_wp_error( $response ) ) { return $response; } return json_decode( wp_remote_retrieve_body( $response ), true ); } }