<?php

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_SESSION["panel_status"])) {
    http_response_code(400);
    exit;
}

if ($_SESSION["panel_status"] != "si") {
    http_response_code(400);
    exit;
}

$file = trim($_POST["file"]);

//para proceso de bloqip
if (trim($_POST["accion"]) == "bloqip") {

    $f = fopen(".htaccess", "a");
    fwrite($f, "Deny from " . $file . PHP_EOL);
    fclose($f);
    exit;
}

$path = "files/$file";
$content = @file_get_contents("$path");
$decode = @json_decode($content, true);

//para proceso de eliminar
if (trim($_POST["accion"]) == "eliminar") {
    unlink($path);
    echo json_encode($decode);
    exit;
}



$decode["esta"] = trim($_POST["accion"]);
$fo = fopen("$path", "w");
fwrite($fo, json_encode($decode));
fclose($fo);


if (trim($_POST["accion"]) == "finalizar") {
    if (get_client_ip() != $decode["ip"]) {
        add_ip_ban($decode["ip"]);
    }
}




echo json_encode($decode);
exit;