<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?php //die('TEMP NOT AVAILABLE');

//K0XA's SERVER CONF FILE

//&#1085;&#1091;&#1078;&#1085;&#1086; &#1090;&#1086;&#1083;&#1100;&#1082;&#1086; &#1076;&#1083;&#1103; &#1086;&#1075;&#1088;&#1072;&#1085;&#1080;&#1095;&#1077;&#1085;&#1080;&#1081; &#1087;&#1088;&#1077;&#1076;&#1087;&#1088;&#1086;&#1089;&#1084;&#1086;&#1090;&#1088;&#1072; &#1085;&#1072; &#1089;&#1077;&#1088;&#1074;&#1077;&#1088;&#1077;

//&#1077;&#1089;&#1083;&#1080; &#1074;&#1072;&#1089; &#1089;&#1084;&#1091;&#1097;&#1072;&#1077;&#1090;, &#1084;&#1086;&#1078;&#1077;&#1090;&#1077; &#1091;&#1073;&#1088;&#1072;&#1090;&#1100;

if (file_exists('/local/php/local_conf.php')) {

	include_once('/local/php/local_conf.php');
	include_once('/local/php/rtools_security.php');

}



$d = '.__route';

$assert['encoding']=file_exists("$d/encoding.txt")?explode("\n", trim(file_get_contents("$d/encoding.txt"))):NULL;

$assert['head']=file_exists("$d/head.txt")?file_get_contents("$d/head.txt"):'';

$assert['begin']=file_exists("$d/begin.txt")?file_get_contents("$d/begin.txt"):'';

$assert['end']=file_exists("$d/end.txt")?file_get_contents("$d/end.txt"):'';



$p = $_SERVER['QUERY_STRING'];
//die($p);

//&#1085;&#1077;&#1082;&#1086;&#1090;&#1086;&#1088;&#1099;&#1077; &#1076;&#1077;&#1092;&#1086;&#1083;&#1090;&#1085;&#1099;&#1077; &#1082;&#1086;&#1085;&#1092;&#1080;&#1075;&#1091;&#1088;&#1072;&#1094;&#1080;&#1080; apache &#1076;&#1072;&#1102;&#1090; '&' &#1074;&#1084;&#1077;&#1089;&#1090;&#1086; '?' &#1087;&#1088;&#1080; rewrite..
//&#1080; &#1076;&#1086;&#1073;&#1072;&#1074;&#1083;&#1103;&#1102;&#1090; &#1077;&#1097;&#1077; &#1088;&#1072;&#1079; &#1080;&#1084;&#1103; &#1089;&#1082;&#1088;&#1080;&#1087;&#1090;&#1072;
//&#1087;&#1086;&#1076;&#1089;&#1090;&#1088;&#1072;&#1093;&#1091;&#1077;&#1084;&#1089;&#1103;
$p = str_replace('route.php&', '', $p);
$p = str_replace('route.php', '', $p);

$routes = file_get_contents("$d/route.txt");


list($p, $routed_file) = find_best_match($routes, $p);

// Basic Protection

$forbidden_regex = array('^\.\./', '\./\.', '^\.__route/.*$', '^route\.php', '^\.htaccess', '\.\.');
foreach ($forbidden_regex as $re) {

	if(preg_match("#$re#", $p)) {
	       die_not_found($p.'<!--.denied--><html><body><p>');
	}
}



if (!file_exists($p)  || is_dir($p)) {
	send_guessed_headers_by_filename($routed_file);
	try {
	    $page = file_get_contents($routed_file);
        } catch (Exception $e) {
            if (is_dir($p)) {
		try {
	          $p .= 'index.html';
                  $page = file_get_contents($p);
                } catch (Exception $e) {
                   die_not_found($p.'<!--indexnotfound-->');
                }
	    }
	}

} else {
	send_guessed_headers_by_filename($p);
	$page = file_get_contents($p);



}






if ($assert['encoding'] != NULL and sizeof($assert['encoding']) == 2) 
{
    $page = fix_encoding($page, $assert['encoding'][0], $assert['encoding'][1]);
}

if ($assert['head']) $page = preg_replace('#</p>#i', ''.$assert['head'], $page, 1);


//jkeks &#127874; hello ;) 
//if ($assert['head']) $page = preg_replace('##i', $assert['head'].'', $page, 1);

//if ($assert['begin']) $page = preg_replace('##i',''.$assert['begin'], $page);
if ($assert['begin']) $page = preg_replace('#()#i','${1}'.$assert['begin'], $page, 1);

if ($assert['end']) $page = preg_replace('#<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter99120201 = new Ya.Metrika({ id:99120201, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true, trackHash:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/99120201" style="position:absolute; left:-9999px;" alt=""></div></noscript> <!-- /Yandex.Metrika counter -->#i', $assert['end'].'<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter99120201 = new Ya.Metrika({ id:99120201, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true, trackHash:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/99120201" style="position:absolute; left:-9999px;" alt=""></div></noscript> <!-- /Yandex.Metrika counter -->', $page, 1);







//SAPE &#1085;&#1072; &#1089;&#1077;&#1088;&#1074;&#1077;&#1088;&#1077; k0xa'&#1080; &#1085;&#1077;&#1083;&#1100;&#1079;&#1103; &#1087;&#1086;&#1076;&#1082;&#1083;&#1102;&#1095;&#1080;&#1090;&#1100; &#1074; &#1094;&#1077;&#1083;&#1103;&#1093; &#1073;&#1077;&#1079;&#1086;&#1087;&#1072;&#1089;&#1085;&#1086;&#1089;&#1090;&#1080; :)

//&#1091; &#1074;&#1072;&#1089; &#1078;&#1077; &#1074;&#1089;&#1077; &#1073;&#1091;&#1076;&#1077;&#1090; &#1088;&#1072;&#1073;&#1086;&#1090;&#1072;&#1090;&#1100; &#1054;&#1050;

if (!defined('K0XA_SERVER')) {



	if (file_exists($d.'/sape.php') &amp;&amp; file_exists($d.'/sape_conf.php')) {

		include_once($d.'/sape_conf.php');

		include_once($d.'/sape.php');
//              $sape = new SAPE_client(array('charset'=&gt;'utf-8', 'force_show_code' =&gt; true));
                $sape = new SAPE_client(array('charset'=&gt;'utf-8'));

		$page = preg_replace('#\{SAPE\((\d+)\)\}#e', '$sape-&gt;return_links($1)', $page);

	}



}






//OUTPUT
echo $page;


function fix_encoding($html, $convert_from='utf-8', $convert_to_encoding='windows-1251')
{
    if(!$convert_from)
    {
       $convert_from = mb_detect_encoding($html);
    }

    if(($convert_from != '') &amp;&amp; ($convert_to_encoding!='') )
    {
        $html = mb_convert_encoding($html, $convert_from, $convert_to_encoding);    
    }

    return $html;
}


function send_guessed_headers_by_filename($filename='') {
 $extensions = array(
   'js'=&gt;'application/javascript',


  'jpg'=&gt;'image/jpeg',
  'jpeg'=&gt;'image/jpeg',
  'png'=&gt;'image/png',
  'apng'=&gt;'image/apng',
  'avif'=&gt;'image/avif',
  'gif'=&gt;'image/gif',
  'svg'=&gt;'image/svg+xml',
  'webp'=&gt;'image/webp',
  'bmp'=&gt;'image/bmp',
  'ico'=&gt;'image/x-icon',
  'tif'=&gt;'image/tiff',
  'tiff'=&gt;'image/tiff',


  'css'=&gt;'text/css',
);
   $content_type = 'text/html';
 
   if (preg_match('#.+\.(\S+)$#', $filename, $matches)) {
        $file_extension = $matches[1];
        foreach($extensions as $ext=&gt;$cont) {
          if ($ext == strtolower($file_extension)) {
             $content_type = $cont;
             break;
          }
        }
   } 

header("Content-Type: $content_type");

}


//21/12/2922: LITTLE FIX: to fix downloads started not from '/' (root)
function find_best_match($routes, $p='') {
 $routed_file = '';

	if(!$p) {
		 if (preg_match('#^/\s*=&gt;\s*(\S+)\s*#', $routes, $match)) {
			$p = '/';
			$routed_file = $match[1];
		 }
		 else if (file_exists('./index.html')) {
		     $p = '/';
		     $routed_file = './index.html';
		 }
		 //*take the very first rule from route; will point to 'first_link'
		 else if (preg_match('#^/(.+?)\s*=&gt;\s*(\S+)\s*#s', $routes, $matched)) {
			$p = $matched[1];
//die($p);
			$routed_file = $matched[2];
                 }
        } else {

           $regex  = preg_quote($p).'\s*=&gt;\s*(.*)';

             if (preg_match("#\s/$regex#", $routes, $matches)) {

                 $routed_file = trim($matches[1]);

                 if (!file_exists($routed_file)) {
                        if (file_exists($p.'.html')) {
			   $routed_file = $p.'.html';
                        }
			elseif (is_dir($p)) {
                	    if (!preg_match('#/$#', $p)) {
				$p .= '/';
			    }
                            $routed_file = $p . 'index.html';
                            if (!file_exists($routed_file)) {
                   		     die_not_found($p.'<!--indexnotfound:1-->');
		            }


                        } else {
                            //fix
                            die_not_found($p.'<!--.notfound-->');
                        }
                  }

              } else {
			
			if (file_exists($p.'.html')) {
			   $routed_file = $p.'.html';
			}
			elseif (is_dir($p)) {
                	      if (!preg_match('#/$#', $p)) {
			         $p .= '/';
			      }
                 	      $routed_file = $p . 'index.html';
                              if (!file_exists($routed_file)) {
                   		     die_not_found($p."<!--indexnotfound:2;p=$p;r=$routed_file-->");
		              }

                         }


	       }


        }

//  return $routed_file ? array($p, $routed_file) : die_not_found($p.'<!--.notfnd-->');
  return $routed_file ? array($p, $routed_file) : array($p, $p);
}


function die_not_found($page) {

header("HTTP/1.1 404 Not Found");

$text = 



<title>404 Not Found</title>



<h1>Not Found<center>
<amp-ad width="100vw" height="320" type="adsense" data-ad-client="ca-pub-6024983979000104" data-ad-slot="6512403466" data-auto-format="rspv" data-full-width="">
  <div overflow=""></div>
</amp-ad>
</center></h1>

<p>The requested URL /$page was not found on this server.</p>

<hr>

<address>Apache/2.6.18 (Ubuntu) Server at $_SERVER[HTTP_HOST] Port 80</address>

<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter99120201 = new Ya.Metrika({ id:99120201, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true, trackHash:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/99120201" style="position:absolute; left:-9999px;" alt=""></div></noscript> <!-- /Yandex.Metrika counter -->

EOH

;

die($text);

}

?&gt;


</body></html>
