| Server IP : 3.96.16.70 / Your IP : 216.73.216.15 Web Server : Apache System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/innoceanapi.wondermakr.com/innocean-fifa-api/app/controller/ |
Upload File : |
<?php
if ( !is_https() ) {
respond(426, 'Upgrade required - Use HTTPS');
}
if ( check_method() != "POST" ) {
respond(405, 'Method not allowed');
}
$rawBody = file_get_contents('php://input');
verifySignedRequest($rawBody);
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (stripos($contentType, 'application/json') !== false) {
$input = json_decode($rawBody, true);
if (!is_array($input)) {
respond(400, 'Invalid JSON.');
}
} else {
$input = $_POST;
}
$action = $input['action'] ?? null;
if ( !is_string($action) || !in_array($action, $cfg['allowedActions'], true) ) {
respond(400, 'Invalid or missing action.');
}
$pin = null;
$pins = [];
$ids = [];
/*
$playmaker_pas = null;
$playmaker_int = null;
*/
if ($action === 'send_pin') {
$pin = validatePin($input['pin'] ?? null);
}
if ($action === 'check_pin_soundoff') {
$pins = validatePins($input['pins'] ?? null);
}
if ($action === 'check_pin_airfresh' || $action === 'check_pin_playmaker') {
$pin = validatePin($input['pin'] ?? null);
}
if ($action === 'update_pin_playmaker') {
$ids = validateIds($input['ids'] ?? null);
$pas = validateIntScore($input['pas'] ?? null, 'pas');
$int = validateIntScore($input['int'] ?? null, 'int');
}
if ($action === 'update_pin_soundoff') {
$ids = validateIds($input['ids'] ?? null);
$score = validateIntScore($input['score'] ?? null, 'score');
$file = validateVideoFilename($input['filename'] ?? null);
}
if ($action === 'update_pin_airfresh') {
$ids = validateIds($input['ids'] ?? null);
$file = validatePngFilename($input['filename'] ?? null);
}
//$pin = validatePin($input['pin'] ?? null);
switch ($action) {
case 'send_pin':
// Check if this PIN exists in the database
if (isDuplicatePin($pin)) {
respond(409, 'PIN already exists');
}
try {
$insert = $db->prepare("INSERT INTO pin (pin, pin_creation_time) VALUES (:pin, :time)");
$insert->execute([':pin' => $pin, ':time' => time()]);
respond(201, 'PIN stored');
} catch (PDOException $e) {
// MySQL duplicate key error code is 1062
if ($e->errorInfo[1] === 1062) {
respond(409, 'PIN already exists');
}
// Unknown DB error
respond(500, 'Database error.');
}
break;
case 'check_pin_soundoff':
try {
$placeholders = [];
$params = [];
foreach ($pins as $index => $pinValue) {
$key = ':pin' . $index;
$placeholders[] = $key;
$params[$key] = $pinValue;
}
$sql = "SELECT id, pin FROM pin WHERE pin IN (" . implode(', ', $placeholders) . ")";
$query = $db->prepare($sql);
$query->execute($params);
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
$foundPins = [];
foreach ($rows as $row) {
$foundPins[$row['pin']] = $row;
}
// Build response
$results = [];
foreach ($pins as $pinValue) {
if (isset($foundPins[$pinValue])) {
$results[] = [
'pin' => $pinValue,
'exists' => true,
'id' => $foundPins[$pinValue]['id']
];
} else {
$results[] = [
'pin' => $pinValue,
'exists' => false
];
}
}
respond(200, 'PIN check complete', $results);
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
case 'check_pin_airfresh':
try {
$query = $db->prepare("
SELECT
id,
pin,
soundoff_score,
playmaker_score_pas,
playmaker_score_int
FROM pin
WHERE pin = :pin
LIMIT 1
");
$query->execute([':pin' => $pin]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if ($result) {
respond(200, 'PIN found', [
'pin' => $result['pin'],
'exists' => true,
'id' => $result['id'],
'soundoff_score' => $result['soundoff_score'],
'playmaker_score_pas' => $result['playmaker_score_pas'],
'playmaker_score_int' => $result['playmaker_score_int']
]);
} else {
respond(404, 'PIN not found', [
'pin' => $pin,
'exists' => false
]);
}
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
case 'check_pin_playmaker':
try {
$query = $db->prepare("
SELECT id, pin
FROM pin
WHERE pin = :pin
LIMIT 1
");
$query->execute([':pin' => $pin]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if ($result) {
respond(200, 'PIN found', [
'pin' => $result['pin'],
'exists' => true,
'id' => $result['id']
]);
} else {
respond(404, 'PIN not found', [
'pin' => $pin,
'exists' => false
]);
}
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
case 'update_pin_playmaker':
try {
$check = $db->prepare("SELECT pin FROM pin WHERE id = :id LIMIT 1");
$update = $db->prepare("UPDATE pin SET playmaker_score_pas = :pas, playmaker_score_int = :int, playmaker_time = :time WHERE id = :id");
$results = [];
foreach ($ids as $idValue) {
$check->execute([':id' => $idValue]);
$row = $check->fetch(PDO::FETCH_ASSOC);
if (!$row) {
$results[] = [
'id' => $idValue,
'updated' => false,
'message' => 'ID not found'
];
continue;
}
$update->execute([
':pas' => $pas,
':int' => $int,
':time' => time(),
':id' => $idValue
]);
$results[] = [
'id' => $idValue,
'pin' => $row['pin'],
'updated' => true
];
}
respond(200, 'Playmaker scores saved', $results);
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
case 'update_pin_soundoff':
try {
$check = $db->prepare("SELECT pin FROM pin WHERE id = :id LIMIT 1");
$update = $db->prepare("UPDATE pin SET soundoff_score = :score, soundoff_file = :file, soundoff_time = :time WHERE id = :id");
$results = [];
foreach ($ids as $idValue) {
$check->execute([':id' => $idValue]);
$row = $check->fetch(PDO::FETCH_ASSOC);
if (!$row) {
$results[] = [
'id' => $idValue,
'updated' => false,
'message' => 'ID not found'
];
continue;
}
$update->execute([
':score' => $score,
':file' => $file,
':time' => time(),
':id' => $idValue
]);
$results[] = [
'id' => $idValue,
'pin' => $row['pin'],
'updated' => true
];
}
respond(200, 'Soundoff scores saved', $results);
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
case 'update_pin_airfresh':
try {
$check = $db->prepare("SELECT pin FROM pin WHERE id = :id LIMIT 1");
$update = $db->prepare("UPDATE pin SET airfresh_file = :file, airfresh_time = :time WHERE id = :id");
$results = [];
foreach ($ids as $idValue) {
$check->execute([':id' => $idValue]);
$row = $check->fetch(PDO::FETCH_ASSOC);
if (!$row) {
$results[] = [
'id' => $idValue,
'updated' => false,
'message' => 'ID not found'
];
continue;
}
$update->execute([
':file' => $file,
':time' => time(),
':id' => $idValue
]);
$results[] = [
'id' => $idValue,
'pin' => $row['pin'],
'updated' => true
];
}
respond(200, 'Air Freshener file saved', $results);
} catch (PDOException $e) {
respond(500, 'Database error.');
}
break;
default:
// Should never hit due to validation
respond(400, 'Unhandled action');
break;
}
?>