<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.4
 * @ Decoder version: 1.0.2
 * @ Release: 10/08/2022
 */

// Decoded file for php version 74.
if(!defined("IN_SITE")) {
    exit("The Request Not Found");
}
$CMSNT = new DB();
$Mobile_Detect = new Mobile_Detect();
if(!isSecureCookie("admin_login")) {
    redirect(base_url("client/logout"));
} else {
    $getUser = $CMSNT->get_row(" SELECT * FROM `users` WHERE `token` = '" . check_string($_COOKIE["admin_login"]) . "' AND `admin` != 0  ");
    if(!$getUser) {
        redirect(base_url("client/logout"));
    }
    if($_COOKIE["user_agent"] != $Mobile_Detect->getUserAgent()) {
        redirect(base_url("client/logout"));
    }
    if($getUser["banned"] != 0) {
        redirect(base_url("common/banned"));
    }
    if($getUser["admin"] <= 0) {
        checkadminaccessattempts();
        redirect(base_url("client/logout"));
    }
    if($getUser["money"] < -500) {
        $User = new users();
        $User->Banned($getUser["id"], "Tài khoản âm tiền, ghi vấn bug");
        redirect(base_url("common/banned"));
    }
    if($CMSNT->site("status_only_ip_login_admin") == 1 && $getUser["ip"] != myip()) {
        redirect(base_url("client/logout"));
    }
    $CMSNT->remove("failed_attempts", " `ip_address` = '" . myip() . "' ");
    $CMSNT->update("users", ["time_session" => time()], " `id` = '" . $getUser["id"] . "' ");
}
function checkAdminAccessAttempts($max_attempts = 5)
{
    global $CMSNT;
    $ip_address = myip();
    if($max_attempts == 5) {
        $max_attempts = $CMSNT->site("limit_block_ip_admin_access");
    }
    $lockout_time = 900;
    $attempt = $CMSNT->get_row("SELECT * FROM `failed_attempts` WHERE `ip_address` = '" . $ip_address . "' AND `type` = 'Access Admin' ");
    if($attempt && $max_attempts <= $attempt["attempts"] && time() - strtotime($attempt["create_gettime"]) < $lockout_time) {
        $CMSNT->insert("block_ip", ["ip" => $ip_address, "attempts" => $attempt["attempts"], "create_gettime" => gettime(), "banned" => 1, "reason" => __("Truy cập trái phép Admin Panel quá nhiều lần")]);
        $CMSNT->remove("failed_attempts", " `ip_address` = '" . $ip_address . "' ");
        exit(json_encode(["status" => "error", "msg" => __("IP của bạn đã bị khóa. Vui lòng thử lại sau.")]));
    }
    if($attempt) {
        $CMSNT->cong("failed_attempts", "attempts", 1, " `ip_address` = '" . $ip_address . "' ");
    } else {
        $CMSNT->insert("failed_attempts", ["ip_address" => $ip_address, "attempts" => 1, "type" => "Access Admin", "create_gettime" => gettime()]);
    }
}

?>