<?php session_start(); ?>
<?php

//echo session_save_path();
//exit;
require("config.php");
require("includes/settings.php");

if (!isset($_SESSION["srvbasename"])) {
    session_unset();
    session_destroy();
    print("<html><head>");
    print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
    print("<title>1</title>");
    print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
    print("<center><br><img src=\"images/stop.png\"><br><br>");
    print("<h1>Você não está autorizado.</h1>");
    print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
    print("</body></html>");
    exit;
} elseif ($_SESSION["srvbasename"] <> $_SERVER["SERVER_NAME"]) {
    session_unset();
    session_destroy();
    print("<html><head>");
    print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
    print("<title>2</title>");
    print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
    print("<center><br><img src=\"images/stop.png\"><br><br>");
    print("<h1>Você não está autorizado.</h1>");
    print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
    print("</body></html>");
    exit;
}

if (!isset($_SESSION["loginuser"]) || !isset($_SESSION["adminid"])) {
    session_unset();
    session_destroy();
    print("<html><head>");
    print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
    print("<title>3</title>");
    print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
    print("<center><br><img src=\"images/stop.png\"><br><br>");
    print("<h1>Você não está autorizado.</h1>");
    print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
    print("</body></html>");
    exit;
}
if (!isset($_SESSION["PASTARAIZ"]) || $_SESSION["PASTARAIZ"] != getenv("PASTARAIZ")) {
    session_unset();
    session_destroy();
    print("<html><head>");
    print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
    print("<title>4</title>");
    print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
    print("<center><br><img src=\"images/stop.png\"><br><br>");
    print("<h1>Você não está autorizado.</h1>");
    print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
    print("</body></html>");
    exit;
}
if (isset($_SESSION['token_acesso'])) {
    if ($_SESSION['token_acesso'] == "") {
        session_unset();
        session_destroy();
        print("<html><head>");
        print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
        print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
        print("<title>Sessão Expirada</title>");
        print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
        print("<center><br><img src=\"images/stop.png\"><br><br>");
        print("<h1>Sessão expirada. Faça o login o novamente.</h1>");
        print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
        print("</body></html>");
        exit();
    }
} else {
    session_unset();
    session_destroy();
    print("<html><head>");
    print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
    print("<title>Sessão Expirada</title>");
    print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
    print("<center><br><img src=\"images/stop.png\"><br><br>");
    print("<h1>Sessão expirada. Faça o login o novamente.</h1>");
    print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
    print("</body></html>");
    exit();
}
if (isset($_SESSION["timeout"])) {
    $session_life = time() - $_SESSION["timeout"];
    if ($session_life > $_SESSION["sessiontimeout"]) {
        session_unset();
        session_destroy();
        print("<html><head>");
        print("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
        print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $charset . "\">");
        print("<title>5</title>");
        print("<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>");
        print("<center><br><img src=\"images/stop.png\"><br><br>");
        print("<h1>Sessão expirada. Faça o login o novamente.</h1>");
        print("<a href=\"index.php\">Voltar a pagina de login</a></center>");
        print("</body></html>");
        exit;
    }
}

$_SESSION["timeout"] = time();
?>
