<?php

if (isset($_GET['check_ssl']) && $_GET['check_ssl'] == 'pbn') {
	die('OK');
}


$host = 'example.com';
if (!empty($_SERVER['HTTP_HOST'])) {
	$host = $_SERVER['HTTP_HOST'];
} elseif (!empty($_SERVER['SERVER_NAME'])) {
	$host = $_SERVER['SERVER_NAME'];
}

$banned_words = array(
	'sex', 'porn', 'seks', 'xxx', 'teen', 'cam', 'xxc',  'xlxx', 'saxy', 'xzxx', 'poran', 'freedesi', 'gay',
	'eoufaoeuhoauengi.su',
);
foreach ($banned_words as $word) {
	if (strpos($host, $word) !== false || strpos($_SERVER['REQUEST_URI'], $word) !== false) {
		header("HTTP/1.0 404 Not Found");
		exit;
	}
}

if (empty($_SERVER['HTTP_USER_AGENT'])) {
	exit;
}
$banned_agents = array(
	'DotBot',
);
foreach ($banned_agents as $agent) {
	if (strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== false) {
		header("HTTP/1.0 404 Not Found");
		exit;
	}
}

include '../configure.php';
include APPLICATION_PATH .'/configs/lb_templates.php';

$config = false;
while ($host) {
	if (isset($lb_templates[$host])) {
		$config = $lb_templates[$host];
		$config['domain'] = $host;
		break;
	}
	$parts = explode('.', $host);
	unset($parts[0]);
	$host = implode('.', $parts);
}

if ($config) {
	if (isset($config['redirect']) && ($_SERVER['REQUEST_URI'] != '/' || $_SERVER['HTTP_HOST'] != $config['domain'])) {
		header("HTTP/1.1 301 Moved Permanently");
		if (!empty($_SERVER['HTTPS'])) {
			header("Location: https://{$config['domain']}");
		} else {
			header("Location: http://{$config['domain']}");
		}
		exit;
	}
	include '../'. $config['template'] .'.php';
	exit;
}

if (isset($_GET['lbtemplate']) && preg_match('/^[a-z0-9\-]+$/', $_GET['lbtemplate']) && file_exists('../'.$_GET['lbtemplate'].'.php')) {
	include '../'. $_GET['lbtemplate'] .'.php';
	exit;
}

include '../default.php';