<?php
require_once "/var/www/html/config.database.php";

header("Content-Type: application/json");

$conn = new mysqli(
    FXH_DB_HOST,
    FXH_DB_USER,
    FXH_DB_PASS,
    FXH_DB_NAME
);

$key = $_GET['license'] ?? "";
$mt5 = $_GET['mt5'] ?? "";

if ($key == "" || $mt5 == "") {
    exit(json_encode(["status"=>"ERR","msg"=>"PARAMS"]));
}

$stmt = $conn->prepare("
    INSERT INTO fxh_license_activations
        (license_key, mt5_account, last_seen)
    VALUES
        (?, ?, NOW())
    ON DUPLICATE KEY UPDATE
        mt5_account = VALUES(mt5_account),
        last_seen  = NOW()
");

$stmt->bind_param("ss", $key, $mt5);
$stmt->execute();

echo json_encode(["status"=>"OK"]);
