All rights reserved. For LICENSE see license.txt =============================================================== (kukutz@npj) */ //Конфигурация и библиотека функций require("config.php"); //Замеры времени $tick0 = timer_init(); $tick = timer_init(); //Вам это, скорее всего, не нужно :) $debug = 0; //Инициализация переменных $debug_output=""; $nothtml = 0; $user = ""; $preres = ""; //Как зовут текущего юзера if ($_COOKIE["ljsession"]) $user = preg_replace("/^.*?\:(.*?)\:.*$/", "\\1", $_COOKIE["ljsession"]); $req_method = $_SERVER["REQUEST_METHOD"]; //Конструируем запрос debug("begin-Url-Constr"); $req = &new HTTP_Request("http://".$baseurl); $req->setMethod($req_method); if ($prox_host) $req->setProxy($prox_host, $prox_port, $prox_user, $prox_pass); $req->addHeader('Cookie', $cookies); $req->addHeader('User-Agent', "Mozilla/5.0 lj-php/".VERSION." (http://wackowiki.com/LjPhp)"); $req->addHeader('Accept', 'application/xhtml+xml,text/html,text/plain'); $req->addHeader('Accept-Language', 'ru, en-us, en'); $req->addHeader('Accept-Charset', 'windows-1251, utf-8'); if ($_SERVER["HTTP_IF_MODIFIED_SINCE"]) $req->addHeader('If-Modified-Since', $_SERVER["HTTP_IF_MODIFIED_SINCE"]); if ($_SERVER["HTTP_IF_NONE_MATCH"]) $req->addHeader('If-None-Match', $_SERVER["HTTP_IF_NONE_MATCH"]); if (isset($_GET["lpurl"])) { debug("Страницу набрали в поле 'Открыть'"); if ($debug>=2) $debug_output.='Страницу набрали в поле "Открыть"
'; $url = parse_url($_GET["lpurl"]); $url_original = "http://".$baseurl."/".ltrim($url["path"], "/")."?".$url["query"]; $req->setURL($url_original); $lppage = $req->_url->path; } else if (!isset($_REQUEST["lppage"]) && $_SERVER["REQUEST_URI"]!=$_SERVER["PHP_SELF"]) { debug("обработчик 404й"); if ($debug>=2) $debug_output.='обработчик 404й
'; $uri = str_replace($root,"",$_SERVER["REQUEST_URI"]); $ps = strpos($uri, "?"); if ($ps===false) { $lppage = $uri; $query = ""; } else { $lppage = substr($uri,0,$ps); $query = substr($uri,$ps+1,strlen($_SERVER["REQUEST_URI"])-$ps+1); } $url_original="http://".$baseurl.$lppage."?".$query; $req->setURL($url_original); } else { debug("к нам пришли по ссылке"); if ($debug>=2) $debug_output.='к нам пришли по ссылке
'; $lppage = urldecode($_REQUEST["lppage"]); if (strpos($lppage, "/")!==0) $lppage = "/".$lppage; // $ps = strpos($lppage, "?"); // if ($ps!==false) $lppage = substr($lppage,0,$ps); $ps = strpos($lppage, "?"); if ($ps!==false) $lppage = rtrim($lppage, "&")."&"; else $lppage .= "?"; // $query = ""; //die(print_r($_GET)); foreach ($_GET as $key => $value) if ($key!="lppage") // $query = $query.$key."=".urlencode($value)."&"; $lppage .= $key."=".urlencode($value)."&"; // $url_original = "http://".$baseurl.$lppage."?".$query; $url_original = "http://".$baseurl.$lppage; $url_original = rtrim($url_original, "&?"); $req->setURL($url_original); if ($req_method=="POST") foreach ($_POST as $key => $value) $req->addPostData($key, utf_encode($value), true); } //д.б. установлены переменные $url_original, $lppage if (stristr($lppage, ".js")) { $debug = 0; $debug_output = ""; } $tu = parse_url($_SERVER["HTTP_REFERER"]); if ($is_service && $_COOKIE["_ljphp"]!=1 && $tu["host"]!=$_SERVER["SERVER_NAME"] && $lppage!="" && $lppage!="/" && !stristr($lppage, "login.bml")) { header("Location: ".$url_original); die(); } //Можно ли текущему юзеру быть здесь if (is_array($allowed_logins) && ($user=="" || !in_array($user, $allowed_logins)) && !stristr($lppage, "login.bml") && !stristr($lppage, ".js")) { if ($o404!=1) $url = "http://".$_SERVER["HTTP_HOST"].$root."/?lppage=login.bml"; else $url = "http://".$_SERVER["HTTP_HOST"].$root."/login.bml"; //echo "

Go off =)

to ".$lppage; header("Location: ".$url); die(); } //Добавляем язык и схему $req->_url->removeQueryString("usescheme"); $req->_url->removeQueryString("uselang"); if (strpos($req->_url->path, "/js/")!==0) { //$req->_url->addQueryString("usescheme", $scheme, true); $req->addCookie("BMLschemepref", $scheme); $req->_url->addQueryString("uselang", $lang, true); if ($s2sucks) $req->_url->addQueryString("style", "mine", true); //Буферизация вывода if ($debug<3) ob_start("ob_gzhandler"); } debug("end-Url-Constr"); //HTTP-Request debug("begin-Download"); dtime("URL: ".$req->_url->GetUrl()."
Method: ".$req->_method."
Setted method: ".$req_method); if ($req_method=="POST" && $debug==3) { echo "POST DATA:
"; print_r($req->_postData); echo "
"; } $req->sendRequest(); $res = $req->getResponseBody(); if ($req->getResponseCode()!="200") { header("HTTP/1.x ".$req->getResponseCode()." Smart"); $nothtml = 1; } else header("HTTP/1.x 200 Ok"); $in_cookies = explode("\n", $req->getRawResponseCookies()); foreach ($in_cookies as $value) if ($value!='') { $value=preg_replace("/; domain.*/", "", $value); if (is_array($allowed_logins) && ($user=="" || !in_array($user, $allowed_logins)) && stristr($value, "ljsession")) { $userstr = preg_replace("/^.*?\:(.*?)\:.*$/", "\\1", $value); if (!in_array($userstr, $allowed_logins)) { $preres = "

Извините, но ваш логин не входит в список разрешённых на данном узле.

"; } else header("Set-Cookie: ".$value); } else header("Set-Cookie: ".$value); } // preg_replace("/domain=.*?; /","",$value)); dtime("Время закачки"); debug("end-Download"); if (!stristr($req->_response->_headers["content-type"],"text/html")) { $nothtml = 1; if (stristr($req->_response->_headers["content-type"],"text/xml")) { $isxml =1; header ("Content-Type: text/xml"); } else header ("Content-Type: ".$req->_response->_headers["content-type"]); } if ($req->_response->_headers["last-modified"]) header ("Last-Modified: ".$req->_response->_headers["last-modified"]); if ($req->_response->_headers["etag"]) header ("ETag: ".$req->_response->_headers["etag"]); //Сохранение в файл - DEBUG if ($debug>=2) { debug("begin-Save"); $f=@fopen('debug.html', 'w'); @fwrite($f, $res); @fclose($f); dtime("Время сохранения"); debug("end-Save"); } if (!$nothtml) { setcookie ("_ljphp", 1, time()+31536000, "/"); //Парсинг debug("begin-Parse"); $res = preg_replace("/\]*?utf-8[^>]*?\>/i","",$res); $res = str_replace("","",$res); $res = R_absurl($res); debug("end-Parse"); dtime("Время парсинга"); //Перекодировка $res = utf_encode($res, "decode"); debug("end-Recode"); dtime("Время перекодировки"); } if ($isxml) { //Парсинг debug("begin-Parse"); $res = str_replace("","",$res); debug("end-Parse"); dtime("Время парсинга"); //Перекодировка $res = utf_encode($res, "decode"); debug("end-Recode"); dtime("Время перекодировки"); } //Сохранение в файл - DEBUG if ($debug>=2) { debug("begin-Save"); $f=@fopen('debug2.html', 'w'); @fwrite($f, $res); @fclose($f); dtime("Время сохранения"); debug("end-Save"); } //HTML-вывод debug("begin-Output"); if (!$nothtml && $a = strpos(strtoupper ($res), "", $a); $res = substr($res,0,$b+1).$panel.' | URL'.$panel2.substr($res,$b+1); } echo $preres.$res; if ($debug) $debug_output .= "

current user is ".$user."

"; $tick1=timer_init(); if ($debug) $debug_output .= "

Общее время работы: ".(number_format(($tick1-$tick0),3))." секунд
"; if ($debug && !$nothtml) echo "".$debug_output.""; debug("end-Output"); //Отправка клиенту if ($debug<3) ob_end_flush(); ?>