<?php
//Verificar se o Terminal está na lista de terminais
include("include/config.inc.php");
$ip = $_SERVER['REMOTE_ADDR'];  


$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://localhost:888/Jocolor/verificaDispositivo?ip='.$ip,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  
));

$response = curl_exec($curl);
curl_close($curl);



if($response != "[-1]"){
    $_SESSION['ip'] = $ip;
    $terminal = substr($response, 1);
    $terminal = substr($terminal, 0, -1);
   
    $_SESSION['numTerminal'] = $terminal;
}
else{
    echo "INVALID IP - ACESSO NÃO AUTORIZADO";
    die();
}

?>



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="mobile-web-app-capable" content="yes">
    <title>Login</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/extras.css">

</head>
<body>
    <div class="container mt-3">
        <div class="text-center">
        <h1 class="">LOGIN</h1>
        <hr>
        </div>
        <form action="include/verificaLogin.php">
            <div class="form-group">
            <label for="user">Utilizador</label>
            <input class="form-control" type="number" name="user" id="user" pattern="\d*">
            </div>
            <div class="form-group mt-2">
            <label for="pass">Palavra-Passe</label>
            <input class="form-control" type="number" name="pass" id="pass" pattern="\d*">
            </div>
            
            <div class="container mt-4">
                <div class="row col-5 justify-content-center">
            <input class="btn btn-secondary" type="submit" name="login" id="login" value="LOGIN">
           
            </div>
            </div>
        </form>
    </div>
    <?php include("include/footer.inc.php"); ?>
</body>
</html>