Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions v1/cleanjobs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@
$SOLR_USER = trim(getenv('SOLR_USER') ?: '');
$SOLR_PASS = trim(getenv('SOLR_PASS') ?: '');

// ----------------------------------------------------------------------
// AUDIT LOG: capture every hit to this endpoint, before any early exits,
// so failed/unauthorized attempts are visible too, not just successes.
// ----------------------------------------------------------------------
$auditRawBody = file_get_contents('php://input');
file_put_contents(
__DIR__ . '/cleanjobs.log',
date('Y-m-d H:i:s') .
' | IP=' . ($_SERVER['REMOTE_ADDR'] ?? '-') .
' | METHOD=' . ($_SERVER['REQUEST_METHOD'] ?? '-') .
' | URI=' . ($_SERVER['REQUEST_URI'] ?? '-') .
' | APIKEY=' . ($_SERVER['HTTP_X_API_KEY'] ?? '-') .
' | UA=' . ($_SERVER['HTTP_USER_AGENT'] ?? '-') .
' | BODY=' . $auditRawBody .
PHP_EOL,
FILE_APPEND | LOCK_EX
);

if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
http_response_code(405);
echo json_encode(["error" => "Only DELETE method allowed"]);
Expand Down Expand Up @@ -166,9 +184,9 @@ function solrEscape(string $value): string {
}

// Parse body - support JSON and form-encoded
$rawBody = file_get_contents('php://input');
$rawBody = $auditRawBody;
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';

error_log(
"CLEANJOBS REQUEST | IP=" .
($_SERVER['REMOTE_ADDR'] ?? '-') .
Expand Down Expand Up @@ -338,6 +356,19 @@ function solrEscape(string $value): string {

error_log("CLEANJOBS SUCCESS: company=$company cif=$cif brand=$brand jobsDeleted=$jobCount");

// Log the confirmed outcome too, so the audit file shows what actually happened
file_put_contents(
__DIR__ . '/cleanjobs.log',
date('Y-m-d H:i:s') .
' | RESULT=SUCCESS' .
' | company=' . ($company ?? '-') .
' | cif=' . ($cif ?? '-') .
' | brand=' . ($brand ?? '-') .
' | jobsDeleted=' . $jobCount .
PHP_EOL,
FILE_APPEND | LOCK_EX
);

http_response_code(200);
echo json_encode($response);

Expand Down
Loading