<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Ambil data dari permintaan POST
    include "../config/connect.php";
    $postData = file_get_contents('php://input');
    $data = json_decode($postData);
    
    $id     = $data->id;
    $pppa   = $data->pppa;
    $hsa    = $data->hsa;
    $ut     = $data->ut;
    $bm     = $data->bm;

    try {
        $waktu = date('Y-m-d H:i:s');
        // UPDATE setting
        $stmt = $pdo->prepare("UPDATE setting_mikrotik SET pppa = :pppa, hsa = :hsa, uptime = :ut, board_name = :bm, last_time = :lt WHERE board_id = :id");
        $stmt->execute([':pppa' => $pppa, ':hsa' => $hsa, ':ut' => $ut, ':bm' => $bm, ':lt' => $waktu, ':id' => $id]);

        // Logging data
        file_put_contents('apimik-log.log', $data);
    } catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
}
?>