<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*$ips_permitidos = array("127.0.0.1");
$ip_acesso = $_SERVER["REMOTE_ADDR"];
if(!in_array($ip_acesso, $ips_permitidos)){
    exit();    
}*/

$acao = $_GET["acao"];
if ($acao === "info_servidor") {
    exit(json_encode($_SERVER));
}

if ($acao === "desativar") {
    require_once 'config.php';
    $db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
    if($db->query("DELETE FROM cmum_painel_ativacao")){
        echo $db->affected_rows;
    }
    
}

if ($acao === "ativar") {

    $chave1 = addslashes($_POST["chave1"]);
    $chave2 = addslashes($_POST["chave2"]);

    require_once 'config.php';
    $db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

    $stmt = $db->prepare("INSERT INTO cmum_painel_ativacao (chave1,chave2,created)"
            . "VALUES(?,?,NOW())");
    if ($stmt === false) {
        var_dump($db->error);
        exit();
    }

    $stmt->bind_param("ss", $chave1, $chave2);
    $stmt->execute();

    echo $stmt->affected_rows;
}

