Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/cookiead.../includes
File: scanner.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace CookieAdminPro;
[2] Fix | Delete
[3] Fix | Delete
if(!defined('COOKIEADMIN_PRO_VERSION') || !defined('ABSPATH')){
[4] Fix | Delete
die('Hacking Attempt');
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
class Scanner {
[8] Fix | Delete
[9] Fix | Delete
const SCAN_TIMEOUT = 55; // Seconds
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The main public method to start the scan.
[13] Fix | Delete
*
[14] Fix | Delete
* @param string $urls_to_scan The URLs of the site to scan.
[15] Fix | Delete
* @return array|\WP_Error The formatted array of cookies on success, or a WP_Error object on failure.
[16] Fix | Delete
*/
[17] Fix | Delete
public static function start_scan($urls_to_scan) {
[18] Fix | Delete
[19] Fix | Delete
global $cookieadmin;
[20] Fix | Delete
[21] Fix | Delete
$args = [
[22] Fix | Delete
'method' => 'POST',
[23] Fix | Delete
'timeout' => self::SCAN_TIMEOUT,
[24] Fix | Delete
'body' => [
[25] Fix | Delete
'urls' => $urls_to_scan
[26] Fix | Delete
]
[27] Fix | Delete
];
[28] Fix | Delete
[29] Fix | Delete
$api_url = cookieadmin_pro_api_url(-1);
[30] Fix | Delete
$url = $api_url.'scanner.php?license='.$cookieadmin['license']['license'].'&url='.rawurlencode(site_url());
[31] Fix | Delete
[32] Fix | Delete
// Use the built-in WordPress HTTP API to call your PHP endpoint.
[33] Fix | Delete
$response = wp_remote_post($url, $args);
[34] Fix | Delete
[35] Fix | Delete
// --- Handle the response from the scanner server ---
[36] Fix | Delete
[37] Fix | Delete
if (is_wp_error($response)) {
[38] Fix | Delete
// This catches network-level errors (e.g., DNS lookup failure, cURL error, timeout)
[39] Fix | Delete
error_log('CookieAdmin Pro Scanner: Network error - ' . $response->get_error_message());
[40] Fix | Delete
wp_send_json_error(array('message' =>__('Network error: ' . $response->get_error_message(), 'cookieadmin')));
[41] Fix | Delete
die;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
$status_code = wp_remote_retrieve_response_code($response);
[45] Fix | Delete
$body = wp_remote_retrieve_body($response);
[46] Fix | Delete
$data = json_decode($body, true);
[47] Fix | Delete
[48] Fix | Delete
// Handle specific errors from our endpoint
[49] Fix | Delete
if ($status_code !== 200) {
[50] Fix | Delete
$error_message = $data['error'] ?? 'An unknown error occurred on the scanner server.';
[51] Fix | Delete
error_log("CookieAdmin Pro Scanner: Server returned status {$status_code}. Message: {$error_message}");
[52] Fix | Delete
wp_send_json_error(array('message' =>__('Status Code: '.$status_code. ' ' . $error_message, 'cookieadmin')));
[53] Fix | Delete
die;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
if (json_last_error() !== JSON_ERROR_NONE) {
[57] Fix | Delete
error_log('CookieAdmin Pro Scanner: Invalid JSON response received.');
[58] Fix | Delete
wp_send_json_error(array('message' =>__('The scanner server returned an unreadable response.')));
[59] Fix | Delete
die;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
update_option('cookieadmin_pro_scanner', array('last_scan' => time()));
[63] Fix | Delete
[64] Fix | Delete
if(!empty($data['cookies'])){
[65] Fix | Delete
// Success! The data is valid. Now format it for our internal use.
[66] Fix | Delete
return self::format_scan_results($data['cookies']);
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
return array();
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Converts the cookie array from the API into our internal format.
[74] Fix | Delete
* This is the same formatting function you had before.
[75] Fix | Delete
*
[76] Fix | Delete
* @param array $scan_results The array of cookies from the scanner.
[77] Fix | Delete
* @return array The formatted array ready for the database.
[78] Fix | Delete
*/
[79] Fix | Delete
private static function format_scan_results(array $scan_results) {
[80] Fix | Delete
$formatted = [];
[81] Fix | Delete
foreach ($scan_results as $cookie) {
[82] Fix | Delete
$expires_datetime = ($cookie['expires'] && $cookie['expires'] != -1)
[83] Fix | Delete
? gmdate("Y-m-d H:i:s", (int)$cookie['expires'])
[84] Fix | Delete
: null;
[85] Fix | Delete
[86] Fix | Delete
$formatted[$cookie['name']] = [
[87] Fix | Delete
'name' => $cookie['name'],
[88] Fix | Delete
'value' => $cookie['value'],
[89] Fix | Delete
'expires' => $expires_datetime,
[90] Fix | Delete
'path' => $cookie['path'],
[91] Fix | Delete
'domain' => $cookie['domain'],
[92] Fix | Delete
'secure' => (bool)$cookie['secure'],
[93] Fix | Delete
'httponly' => (bool)$cookie['httpOnly'],
[94] Fix | Delete
'Max-Age' => null,
[95] Fix | Delete
'samesite' => $cookie['sameSite'] ?? null,
[96] Fix | Delete
];
[97] Fix | Delete
}
[98] Fix | Delete
return $formatted;
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function