Guest User

Untitled

a guest
Jun 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 90.77 KB | None | 0 0
  1. <?
  2.  
  3. $GLOBALS['_1175134457_']=Array();
  4.  
  5. function _638390381($i){$a=Array();
  6. return base64_decode($a[$i]);
  7. }
  8.  
  9.  
  10.  
  11. timer::start();
  12. error_reporting(E_ERROR);
  13. define('HTTP_HOST',$_SERVER['HTTP_HOST']);
  14. define('ROOT_DIR',$_SERVER['DOCUMENT_ROOT']);
  15. class _File{public static function Open($file_name,$mode){self::MakePath($file_name);
  16. if(!file_exists($file_name))$fp=fopen($file_name,'w+');
  17. else $fp=fopen($file_name,$mode);
  18. flock($fp,LOCK_EX);
  19. return $fp;
  20. }public static function Close($Handle){flock($Handle,LOCK_UN);
  21. fclose($Handle);
  22. }public static function Write($Handle,$String){fwrite($Handle,$String);
  23. }public static function PutContent($Path,$Content){self::MakePath($Path);
  24. file_put_contents($Path,$Content);
  25. }public static function MakePath($path){if(file_exists($path))return;
  26. $path_arr=split('[\\/]',$path);
  27. $path=array_shift($path_arr);
  28. $file=array_pop($path_arr);
  29. if(!preg_match('~\.[^.]+$~ism',$file))$path[]=$file;
  30. foreach($path_arr as $folder){$path=self::MakeDirectory($path,$folder);
  31. }}public static function MakeDirectory($path,$folder=false){if($folder)$path=$path .'/' .$folder;
  32. $path=preg_replace('~[\\/]+~','/',$path);
  33. if(!file_exists($path))mkdir($path);
  34. return $path;
  35. }public static function RemoveDir($path){if(file_exists($path)&& is_dir($path)){$dirHandle=opendir($path);
  36. while(false !==($file=readdir($dirHandle))){if($file!='.'&& $file!='..'){$tmpPath=$path .'/' .$file;
  37. chmod($tmpPath,0777);
  38. if(is_dir($tmpPath)){self::RemoveDir($tmpPath);
  39. }else{if(file_exists($tmpPath)){unlink($tmpPath);
  40. }}}}closedir($dirHandle);
  41. if(file_exists($path)){rmdir($path);
  42. }}}}class SM_Pattern{public $Pattern;
  43. public $FilePath;
  44. public $RelativePath;
  45. public $URL;
  46. public $Links;
  47. private $Template;
  48. private $fopen;
  49. private $Host;
  50. public function SetMapTemplate($Template){if(is_file($Template)&& file_exists($Template))$Template=file_get_contents($Template);
  51. $this->Template=$Template;
  52. }public function SM_Pattern($Pattern,$RelativePath,$Host=false){$this->Pattern=$Pattern;
  53. $this->RelativePath=$RelativePath;
  54. $this->Host=$Host;
  55. $this->FilePath=str_replace('{ROOT_DIR}',$_SERVER['DOCUMENT_ROOT'],$RelativePath);
  56. $this->URL=$Host?str_replace('{ROOT_DIR}',"http://{$Host}",$RelativePath):str_replace('{ROOT_DIR}','',$RelativePath);
  57. }public function SetNewPath($NewRelativePath){$this->FilePath=str_replace('{ROOT_DIR}',$_SERVER['DOCUMENT_ROOT'],$NewRelativePath);
  58. $this->URL=$this->Host?str_replace('{ROOT_DIR}',"http://{$this->Host}",$NewRelativePath):str_replace('{ROOT_DIR}','',$NewRelativePath);
  59. }public function AddLink($Keyword,$Link){if(!$this->fopen)$this->fopen=_File::Open($this->FilePath,'a+');
  60. $link=strtr($this->Pattern,array('{KEYWORD}'=> $Keyword,'{LINK}'=> $Link));
  61. _File::Write($this->fopen,$link ."\n");
  62. }public function Close(){if($this->fopen)_File::Close($this->fopen);
  63. }public function AddLinkToArray($Keyword,$Link){$this->Links[]=strtr($this->Pattern,array('{KEYWORD}'=> $Keyword,'{LINK}'=> $Link));
  64. }public function SaveArrayInFile($shuffle=false){if(!count($this->Links))return false;
  65. if($shuffle)shuffle($this->Links);
  66. $links=implode('',$this->Links);
  67. $content=$this->Template?str_replace('{MAP}',$links,$this->Template):$links;
  68. _File::PutContent($this->FilePath,$content);
  69. }public function Count(){return count($this->Links);
  70. }public function GetSitemapUrl(){return $this->URL;
  71. }public function Clear(){$this->Links=array();
  72. }public function DeleteSiteMap(){if(file_exists($this->FilePath))unlink($this->FilePath);
  73. }}class SM_Patterns{public $List;
  74. private $Host;
  75. public function SM_Patterns($Host){$this->Host=$Host;
  76. }public function SetHost($Host){$this->Host=$Host;
  77. }public function Add($Pattern,$RelativePath){$this->List[]=new SM_Pattern($Pattern,$RelativePath,$this->Host);
  78. }public function AddLinkInSM($Keyword,$Link){if(!count($this->List))return;
  79. foreach($this->List as $pattern){$pattern->AddLink($Keyword,$Link);
  80. }}public function DeleteSiteMaps(){if(!count($this->List))return;
  81. foreach($this->List as $id => $pattern){$pattern->DeleteSiteMap();
  82. }}public function Close(){if(!count($this->List))return;
  83. foreach($this->List as $pattern){$pattern->Close();
  84. }}}class Sitemap{const SM_ONLY_SUBDOMAINS=1;
  85. const SM_SUBDOMAINS_WITH_INNER_LINKS=2;
  86. const SM_DOMAIN_WITH_INNER_LINKS=3;
  87. const SM_ALL=4;
  88. const SM_DOMAIN_WITH_FOLDER_AND_INNER_LINKS=5;
  89. private $MainHost;
  90. public function SetMainHost($MainHost){$this->MainHost=$MainHost;
  91. $this->SM_Patterns->SetHost($MainHost);
  92. }private $Mode=self::SM_SUBDOMAINS_WITH_INNER_LINKS;
  93. public function SetMode($value){$this->Mode=$value;
  94. }private $CountInnerLinksInCurrentMap=0;
  95. private $CountInnerLinksInMap=300;
  96. public function SetCountInnerLinksInMap($value){if($this->Mode != self::SM_ONLY_SUBDOMAINS){$this->CountInnerLinksInMap=$value;
  97. }else $this->CountInnerLinksInMap=0;
  98. }private $CountSubdomainLinksInCurrentMap=0;
  99. private $CountMainPagesLinksInCurrentMap=0;
  100. private $CountMainPagesLinksInMap=0;
  101. public function SetCountMainPagesLinksInMap($value){if($this->Mode != self::SM_DOMAIN_WITH_INNER_LINKS){$this->CountMainPagesLinksInMap=$value;
  102. }else $this->CountMainPagesLinksInMap=0;
  103. }private $MainSMPattern;
  104. public function SetMainSMPattern($Pattern,$FolderPath){$this->MainSMPattern=new SM_Pattern($Pattern,$FolderPath,$this->MainHost);
  105. }public function SetMainSM_Pattern($SM_Pattern){$this->MainSMPattern=$SM_Pattern;
  106. }private $Template;
  107. public function SetMapTemplate($Template,$Folder=false){$file_name=preg_replace('~[\\/]+~','/',$Folder .$Template);
  108. if(is_file($file_name)&& file_exists($file_name)){$Template=file_get_contents(preg_replace('~[\\/]+~','/',$Folder .$Template));
  109. }$this->Template=$Template;
  110. }public function GetSitemapURL(){return $this->MainSMPattern->GetSitemapUrl();
  111. }public $SM_Patterns;
  112. public function SetSM_Patterns($SM_Patterns){$this->SM_Patterns=$SM_Patterns;
  113. }public function Sitemap($Host){$this->MainHost=$Host;
  114. $this->SM_Patterns=new SM_Patterns($Host);
  115. }public function Make($RequestURI=false){if(stristr($_SERVER['REQUEST_URI'],($RequestURI?$RequestURI:'make_sitemaps'))){$this->SM_Patterns->DeleteSiteMaps();
  116. $this->MakeSiteMaps();
  117. exit;
  118. }}public function MakeSiteMaps(){$keywords=file(keywords::$binary_keywords_path);
  119. shuffle($keywords);
  120. $count_urls_in_map=$this->CountInnerLinksInMap+$this->CountMainPagesLinksInMap;
  121. if($this->Mode == self::SM_DOMAIN_WITH_FOLDER_AND_INNER_LINKS)$count_urls_in_map=$this->CountInnerLinksInMap;
  122. $max=max(array($this->CountInnerLinksInMap,$this->CountMainPagesLinksInMap));
  123. $maps_count=floor(sizeof($keywords)/$max);
  124. $SM_Relative_Path=$this->MainSMPattern->RelativePath;
  125. $SM_folder_path=$this->MainSMPattern->FilePath;
  126. $this->SM_Patterns->AddLinkInSM($this->MainHost,"http://{$this->MainHost}/");
  127. for($sm_num=1;
  128. $sm_num <= $maps_count;
  129. $sm_num++){$this->MainSMPattern->SetNewPath("{$SM_Relative_Path}{$sm_num}.php");
  130. $this->SM_Patterns->AddLinkInSM("Sitemap $sm_num",$this->MainSMPattern->URL);
  131. }$map_number=1;
  132. $MS_MainPage=new SM_Pattern($this->MainSMPattern->Pattern,$SM_Relative_Path .'index.php',$this->MainHost);
  133. $MS_MainPage->SetMapTemplate($this->Template);
  134. for($i=0;
  135. $i<sizeof($keywords);
  136. $i++){$keyword=explode('||',$keywords[$i]);
  137. $temp_sub_keyword=isset($keyword[$i+5])?$keywords[$i+5]:$keywords[$i-5];
  138. $sub_keyword=explode('||',$temp_sub_keyword);
  139. $keyword=new keyword(trim($keyword[1]),trim($keyword[0]),new positions($i,$i*strlen($keywords[$i])));
  140. $sub_keyword=new keyword(trim($sub_keyword[1]),trim($sub_keyword[0]),new positions($i,$i*strlen($temp_sub_keyword)));
  141. $subdomain=$this->MakeSubdomain($keyword);
  142. $inner_link=$this->MakeInnerLink($keyword,$sub_keyword);
  143. if($subdomain)$this->SM_Patterns->AddLinkInSM($subdomain->anchor,$subdomain->url);
  144. if($inner_link)$this->SM_Patterns->AddLinkInSM($inner_link->anchor,$inner_link->url);
  145. $this->MainSMPattern->SetNewPath("{$SM_Relative_Path}{$map_number}.php");
  146. if($subdomain)$this->MainSMPattern->AddLinkToArray($subdomain->anchor,$subdomain->url);
  147. if($inner_link)$this->MainSMPattern->AddLinkToArray($inner_link->anchor,$inner_link->url);
  148. if($this->MainSMPattern->Count()>= $count_urls_in_map){$this->MainSMPattern->SetMapTemplate($this->Template);
  149. $this->MainSMPattern->SaveArrayInFile(true);
  150. $this->MainSMPattern->Clear();
  151. $MS_MainPage->AddLinkToArray("Main page $map_number",$this->MainSMPattern->URL);
  152. $map_number++;
  153. $this->CountSubdomainLinksInCurrentMap=0;
  154. $this->CountInnerLinksInCurrentMap=0;
  155. }}$MS_MainPage->SaveArrayInFile();
  156. $SM_Url=$MS_MainPage->GetSitemapURL();
  157. $this->SM_Patterns->Close();
  158. $MS_MainPage->Close();
  159. echo"<a href=\"{$SM_Url}\">Sitemap</a>";
  160. }function MakeSubdomain($keyword){if($this->Mode == self::SM_ALL || $this->Mode == self::SM_SUBDOMAINS_WITH_INNER_LINKS || $this->Mode == self::SM_ONLY_SUBDOMAINS){if($this->CountMainPagesLinksInMap>$this->CountSubdomainLinksInCurrentMap){$this->CountSubdomainLinksInCurrentMap++;
  161. return new link($keyword,"http://{$keyword->link_body}.{$this->MainHost}/");
  162. }}return false;
  163. }function MakeDomainWithLink($keyword,$keyword_on_sub=null){if($this->Mode == self::SM_ALL || $this->Mode == self::SM_DOMAIN_WITH_INNER_LINKS){if($this->CountInnerLinksInMap>$this->CountInnerLinksInCurrentMap){$this->CountInnerLinksInCurrentMap++;
  164. return new link($keyword,"http://{$this->MainHost}/$keyword->link_body.php");
  165. }}return false;
  166. }function MakeFolderWithLink($keyword,$keyword_on_sub=null){if($this->Mode == self::SM_DOMAIN_WITH_FOLDER_AND_INNER_LINKS){if($this->CountInnerLinksInMap>$this->CountInnerLinksInCurrentMap){$this->CountInnerLinksInCurrentMap++;
  167. if(!$keyword_on_sub)return new link($keyword,"http://{$this->MainHost}/{$keyword->link_body}/");
  168. return new link($keyword,"http://{$this->MainHost}/{$keyword_on_sub->link_body}/$keyword->link_body.php");
  169. }}return false;
  170. }function MakeSubdomainWithLink($keyword,$keyword_on_sub=null){if($this->Mode == self::SM_ALL || $this->Mode == self::SM_SUBDOMAINS_WITH_INNER_LINKS){if($this->CountInnerLinksInMap>$this->CountInnerLinksInCurrentMap){$this->CountInnerLinksInCurrentMap++;
  171. if(!$keyword_on_sub)return new link($keyword,"http://{$keyword->link_body}.{$this->MainHost}/$keyword->link_body.php");
  172. return new link($keyword,"http://{$keyword_on_sub->link_body}.{$this->MainHost}/$keyword->link_body.php");
  173. }}return false;
  174. }function MakeInnerLink($keyword,$keyword_on_sub=null){if($this->Mode == self::SM_ALL){if(mt_rand(0,1))return $this->MakeSubdomainWithLink($keyword,$keyword_on_sub);
  175. else return $this->MakeDomainWithLink($keyword,$keyword_on_sub);
  176. }elseif($this->Mode == self::SM_SUBDOMAINS_WITH_INNER_LINKS){return $this->MakeSubdomainWithLink($keyword,$keyword_on_sub);
  177. }elseif($this->Mode == self::SM_DOMAIN_WITH_INNER_LINKS){return $this->MakeDomainWithLink($keyword,$keyword_on_sub);
  178. }elseif($this->Mode == self::SM_DOMAIN_WITH_FOLDER_AND_INNER_LINKS){if(mt_rand(0,1))return $this->MakeFolderWithLink($keyword);
  179. else return $this->MakeFolderWithLink($keyword,$keyword_on_sub);
  180. }return false;
  181. }}class Install{private $KeywordsPath;
  182. public function SetKeywordsPath($value){$this->KeywordsPath=preg_replace('~[\\/]+~','/',$value);
  183. }private $BinaryKeywordsPath;
  184. public function SetBinaryKeywordsPath($value){$this->BinaryKeywordsPath=preg_replace('~[\\/]+~','/',$value);
  185. }public function Install($KeywordsPath=false,$BinaryKeywordsPath=false){$this->SetKeywordsPath($KeywordsPath);
  186. $this->SetBinaryKeywordsPath($BinaryKeywordsPath);
  187. $this->Textmaker=new Textmaker();
  188. }private $Textmaker;
  189. public function SetBaseContentPath($value){$this->Textmaker->SetBasePath($value);
  190. }public function SetInnerContentPath($value){$this->Textmaker->SetInnerTextPath($value);
  191. }private function make_htaccess(){file_put_contents($_SERVER['DOCUMENT_ROOT'] .'/.htaccess',"PHP_VALUE default_charset windows-1251
  192. RewriteEngine on
  193. Options +FollowSymlinks
  194.  
  195. #Редирект www
  196. RewriteBase /
  197. RewriteCond %{HTTP_HOST} ^www.{$_SERVER['HTTP_HOST']}$
  198. RewriteRule ^ http://{$_SERVER['HTTP_HOST']}%{REQUEST_URI} [R=301,L]
  199.  
  200. #Базовое перенаправление
  201. RewriteCond %{REQUEST_FILENAME} !-f
  202. RewriteCond %{REQUEST_FILENAME} !-d
  203. RewriteRule ^(.*)$ index.php [L,QSA]");
  204. }private function make_keywords(){$keywords=file($this->KeywordsPath);
  205. $keywords=array_unique($keywords);
  206. $data=array();
  207. foreach($keywords as $key){$key=trim($key);
  208. if(strlen($key)>50)continue;
  209. $key_translate=translate::eng($key);
  210. $key_translate=preg_replace('~[^a-z0-9_\- ]+~ism','',$key_translate);
  211. $key_translate=preg_replace('~[\s\-]+~ism','-',$key_translate);
  212. $key=preg_replace('~[\s]+~ism',' ',$key);
  213. $key=preg_replace('~[\-]+~ism','-',$key);
  214. $data[]=array($key_translate,trim($key));
  215. }$search=new binary_search_col($this->BinaryKeywordsPath,0,'||');
  216. $search->make_indexed_file($data);
  217. }public function Run($request_uri_in=false,$request_uri_out=false){set_time_limit(0);
  218. if(!stristr($_SERVER['REQUEST_URI'],($request_uri_in?$request_uri_in:'install')))return;
  219. if(!file_exists($this->KeywordsPath)|| file_exists($this->BinaryKeywordsPath))return;
  220. $this->Textmaker->MakeBase();
  221. $this->make_keywords();
  222. $this->make_htaccess();
  223. if($request_uri_out)$_SERVER['REQUEST_URI']=$request_uri_out;
  224. else exit;
  225. }}class Encoding{static public function Encode($text,$output_charset){mb_internal_encoding($output_charset);
  226. $encode=self::DetectHTMLDocEncoding($text);
  227. $encode=$encode?$encode:self::DetectTextEncoding($text);
  228. return mb_convert_encoding($text,$output_charset,$encode);
  229. }static public function DetectHTMLDocEncoding($content){if(!$content)return false;
  230. preg_match("/charset=(['\"]|)(.*?)(\n|'|\"|>)/ism",$content,$charset);
  231. $charset=@trim($charset[2]);
  232. if(preg_match("~(windows-1251|1251)~ism",$charset))return 'Windows-1251';
  233. elseif(preg_match("~(koi8|iso-ir-111)~ism",$charset))return 'KOI8-R';
  234. elseif(preg_match("~iso-8859-5~ism",$charset))return 'ISO-8889-5';
  235. elseif(preg_match("~ibm866~ism",$charset))return 'ibm866';
  236. elseif(preg_match("~x-mac-(cyrillic|ukrainian)~ism",$charset))return 'x-mac-(cyrillic|ukrainian)';
  237. elseif(preg_match("~ibm855~ism",$charset))return 'Windows-1251';
  238. elseif(preg_match("~utf-8~ism",$charset))return 'UTF-8';
  239. }public static function DetectTextEncoding($text){setlocale(LC_CTYPE,'ru_RU');
  240. $x_win=array('а'=>'0.07890365448505','б'=>'0.013981173864895','в'=>'0.043050941306755','г'=>'0.018687707641196','д'=>'0.027685492801772','е'=>'0.089285714285714','ж'=>'0.0094130675526024','з'=>'0.01578073089701','и'=>'0.071151716500554','й'=>'0.013427464008859','к'=>'0.038898117386489','л'=>'0.044435215946844','м'=>'0.032392026578073','н'=>'0.072120708748616','о'=>'0.11600221483942','п'=>'0.024363233665559','р'=>'0.040420819490587','с'=>'0.054817275747508','т'=>'0.063538205980066','у'=>'0.024363233665559','ф'=>'0.0016611295681063','х'=>'0.0080287929125138','ц'=>'0.0038759689922481','ч'=>'0.017303433001107','ш'=>'0.008859357696567','щ'=>'0.0024916943521595','ъ'=>'0.00027685492801772','ы'=>'0.018410852713178','ь'=>'0.017995570321152','э'=>'0.002906976744186','ю'=>'0.0065060908084164','я'=>'0.018964562569214');
  241. $x_koi=array('б'=>'0.07890365448505','в'=>'0.013981173864895','Ч'=>'0.043050941306755','з'=>'0.018687707641196','д'=>'0.027685492801772','е'=>'0.089285714285714','Ц'=>'0.0094130675526024','Ъ'=>'0.01578073089701','й'=>'0.071151716500554','к'=>'0.013427464008859','л'=>'0.038898117386489','м'=>'0.044435215946844','н'=>'0.032392026578073','о'=>'0.072120708748616','п'=>'0.11600221483942','Р'=>'0.024363233665559','Т'=>'0.040420819490587','У'=>'0.054817275747508','Ф'=>'0.063538205980066','Х'=>'0.024363233665559','ж'=>'0.0016611295681063','и'=>'0.0080287929125138','г'=>'0.0038759689922481','Ю'=>'0.017303433001107','Ы'=>'0.008859357696567','Э'=>'0.0024916943521595','Я'=>'0.00027685492801772','Щ'=>'0.018410852713178','Ш'=>'0.017995570321152','Ь'=>'0.002906976744186','а'=>'0.0065060908084164','С'=>'0.018964562569214');
  242. $x_iso=array('Р'=>'0.07890365448505','С'=>'0.013981173864895','Т'=>'0.043050941306755','У'=>'0.018687707641196','Ф'=>'0.027685492801772','Х'=>'0.089285714285714','Ц'=>'0.0094130675526024','Ч'=>'0.01578073089701','Ш'=>'0.071151716500554','Щ'=>'0.013427464008859','Ъ'=>'0.038898117386489','Ы'=>'0.044435215946844','Ь'=>'0.032392026578073','Э'=>'0.072120708748616','Ю'=>'0.11600221483942','Я'=>'0.024363233665559','а'=>'0.040420819490587','б'=>'0.054817275747508','в'=>'0.063538205980066','г'=>'0.024363233665559','д'=>'0.0016611295681063','е'=>'0.0080287929125138','ж'=>'0.0038759689922481','з'=>'0.017303433001107','и'=>'0.008859357696567','й'=>'0.0024916943521595','к'=>'0.00027685492801772','л'=>'0.018410852713178','м'=>'0.017995570321152','н'=>'0.002906976744186','о'=>'0.0065060908084164','п'=>'0.018964562569214');
  243. $x_dos=array(' '=>'0.07890365448505','с'=>'0.013981173864895','т'=>'0.043050941306755','у'=>'0.018687707641196','ф'=>'0.027685492801772','х'=>'0.089285714285714','ц'=>'0.0094130675526024','ч'=>'0.01578073089701','ш'=>'0.071151716500554','щ'=>'0.013427464008859','ъ'=>'0.038898117386489','ы'=>'0.044435215946844','ь'=>'0.032392026578073','_'=>'0.072120708748616','ю'=>'0.11600221483942','я'=>'0.024363233665559','а'=>'0.040420819490587','б'=>'0.054817275747508','в'=>'0.063538205980066','г'=>'0.024363233665559','д'=>'0.0016611295681063','е'=>'0.0080287929125138','ж'=>'0.0038759689922481','з'=>'0.017303433001107','и'=>'0.008859357696567','й'=>'0.0024916943521595','к'=>'0.00027685492801772','л'=>'0.018410852713178','м'=>'0.017995570321152','н'=>'0.002906976744186','о'=>'0.0065060908084164','п'=>'0.018964562569214');
  244. $text=substr($text,0,1000);
  245. $len=strlen($text);
  246. for($i=0;
  247. $i<$len;
  248. $i++){@$let=strtolower($text[$i]);
  249. @$t[$let]++;
  250. }if(is_array($t))foreach($t as $k => $v){@$t_win += $v*$x_win[$k];
  251. @$t_koi += $v*$x_koi[$k];
  252. @$t_iso += $v*$x_iso[$k];
  253. @$t_dos += $v*$x_dos[$k];
  254. }$r='none';
  255. $tmp=max($t_win,$t_koi,$t_iso,$t_dos);
  256. if($t_win == $tmp)$r='Windows-1251';
  257. if($t_koi == $tmp)$r='KOI8-R';
  258. if($t_iso == $tmp)$r='ISO-8889-5';
  259. if($t_dos == $tmp)$r='Windows-1251';
  260. return $r;
  261. }}class WebProxy{public $adress;
  262. public $port;
  263. public $login;
  264. public $password;
  265. public $ISLocalIP;
  266. public function ISLocalIP($ISLocalIP=true){$this->ISLocalIP=$ISLocalIP;
  267. }public function WebProxy($adress=null,$port=null,$login=null,$password=null){$this->adress=$adress;
  268. $this->port=$port;
  269. $this->login=$login;
  270. $this->password=$password;
  271. }public function FromString($proxy){$proxy=split("[:\t;
  272. ]",$proxy);
  273. $this->adress=trim($proxy[0]);
  274. $this->port=isset($proxy[1])?trim($proxy[1]):80;
  275. $this->login=isset($proxy[2])?trim($proxy[2]):null;
  276. $this->password=isset($proxy[3])?trim($proxy[3]):null;
  277. }}class ProxyData{public $Proxy;
  278. public $IsBad;
  279. public $LastUseTime;
  280. public function ProxyData($Proxy,$IsBad,$LastUseTime){$this->Proxy=$Proxy;
  281. $this->IsBad=$IsBad;
  282. $this->LastUseTime=$LastUseTime;
  283. }}class ProxyManager{public $UseProxyTimeout;
  284. public $BadProxyTimeout;
  285. public $DeleteBadProxy;
  286. public $Enabled;
  287. protected $ISLocalIP=false;
  288. public function ProxyManager($Enabled=true,$UseProxyTimeout=60,$BadProxyTimeout=200,$DeleteBadProxy=true){$this->Enabled=$Enabled;
  289. $this->UseProxyTimeout=$UseProxyTimeout;
  290. $this->BadProxyTimeout=$BadProxyTimeout;
  291. $this->DeleteBadProxy=$DeleteBadProxy;
  292. }public function UpdateProxyList(){foreach($this->ProxyList as $index => $_Proxy){if($_Proxy->IsBad && $_Proxy->LastUseTime<time()-$this->BadProxyTimeout){$this->ProxyList[$index]->IsBad=false;
  293. }}}public function GetValidProxyList(){$this->UpdateProxyList();
  294. $time=$this->UseProxyTimeout;
  295. $ValidProxyList=array();
  296. foreach($this->ProxyList as $index => $_Proxy){if(!$_Proxy->IsBad && $_Proxy->LastUseTime<time()-$this->UseProxyTimeout){$ValidProxyList[]=$_Proxy;
  297. }}return $ValidProxyList;
  298. }public function RemoveProxy($Proxy){foreach($this->ProxyList as $index => $_Proxy){if($_Proxy == $Proxy){unset($this->ProxyList[$index]);
  299. return;
  300. }}}public function StopBadProxy($Proxy){if($this->DeleteBadProxy){$this->RemoveProxy($Proxy);
  301. return;
  302. }foreach($this->ProxyList as $index => $_Proxy){if($_Proxy == $Proxy){$this->ProxyList[$index]->LastUseTime=time();
  303. $this->ProxyList[$index]->IsBad=true;
  304. return;
  305. }}}private $Proxy=null;
  306. public function GetCurrentProxy(){if(!$this->Enabled)return null;
  307. if($_Proxy == null)return $this->RandomProxy();
  308. else return $_Proxy;
  309. }public function SetCurrentProxy($value){$_Proxy=$value;
  310. }public function ProxyFromString($string){$_Proxy=new WebProxy();
  311. $_Proxy->FromString($string);
  312. }public function RandomProxy(){if(!$this->Enabled)return null;
  313. if(!$this->ProxyList)return null;
  314. if(count($this->ProxyList)== 0)return null;
  315. $_Proxy=$this->ProxyList[mt_rand(0,count($this->ProxyList))];
  316. return $_Proxy;
  317. }public function RandomValidProxy(){if(!$this->Enabled)return null;
  318. if(!$this->ProxyList)return null;
  319. if(count($this->ProxyList)== 0)return null;
  320. $ValidProxyList=$this->GetValidProxyList();
  321. return $ValidProxyList[mt_rand(0,count($ValidProxyList)-1)]->Proxy;
  322. }public function ClearCurrentProxy(){$this->_Proxy=null;
  323. }public function RemoveCurrentProxy(){if($this->_Proxy != null)$this->RemoveProxy($this->_Proxy);
  324. }public $ProxyList;
  325. public function SetProxyList($proxy_list){if(is_file($proxy_list)&& file_exists($proxy_list))$proxy_list=file_get_contents($proxy_list);
  326. if(is_string($proxy_list))$proxy_list=split("[\r\n]",$proxy_list);
  327. foreach($proxy_list as $proxy){$this->AddProxy($proxy);
  328. }}public function AddProxy($WebProxy){if($this->ProxyList == null)$this->ProxyList=array();
  329. if(is_string($WebProxy)){if(!trim($WebProxy))return;
  330. $proxy=new WebProxy();
  331. $proxy->ISLocalIP($this->ISLocalIP);
  332. $proxy->FromString($WebProxy);
  333. $this->AddProxy($proxy);
  334. }else $this->ProxyList[]=new ProxyData($WebProxy,false,time()-100*60*60*24);
  335. }public function Clear(){$this->ProxyList=array();
  336. }}class LocalIpAsProxyManager extends ProxyManager{public function LocalIpAsProxyManager($UseIpTimeout=60,$BadIpTimeout=200){$this->Enabled=true;
  337. $this->UseProxyTimeout=$UseIpTimeout;
  338. $this->BadProxyTimeout=$BadIpTimeout;
  339. $this->DeleteBadProxy=false;
  340. $this->ISLocalIP=true;
  341. }}class UserAgentsManager{public $UserAgentsList=array('Mozilla/5.0 (Windows;
  342. U;
  343. Windows NT 5.1;
  344. ru;
  345. rv:1.8.1.18)','Mozilla/2.0 (Windows;
  346. U;
  347. Windows NT 5.1;
  348. ru;
  349. rv:1.8.1.19)','Mozilla/3.0 (Windows;
  350. U;
  351. Windows NT 5.1;
  352. ru;
  353. rv:1.8.1.11)','Mozilla/5.0 (Windows;
  354. U;
  355. Windows NT 5.1;
  356. ru;
  357. rv:1.8.1.12)','Mozilla/4.7 (Windows;
  358. U;
  359. Windows NT 5.1;
  360. ru;
  361. rv:1.8.1.13)','Opera/9.15 (Windows;
  362. U;
  363. Windows NT 5.1;
  364. ru;
  365. rv:1.8.1.11)','Opera/9.20 (Windows;
  366. U;
  367. Windows NT 5.1;
  368. ru;
  369. rv:1.8.1.19)','Opera/9.40 (Windows;
  370. U;
  371. Windows NT 5.1;
  372. ru;
  373. rv:1.8.1.18)','Opera/8.2beta (Windows;
  374. U;
  375. Windows NT 5.1;
  376. ru;
  377. rv:1.8.2.44)','Opera/9.16 (Windows;
  378. U;
  379. Windows NT 5.1;
  380. ru;
  381. rv:1.8.1.10)','Opera/7.15 (Windows;
  382. U;
  383. Windows NT 5.1;
  384. ru;
  385. rv:1.8.1.28)','Opera/8.92 (Windows;
  386. U;
  387. Windows NT 5.1;
  388. ru;
  389. rv:1.8.1.38)','Opera/8.95 (Windows;
  390. U;
  391. Windows NT 5.1;
  392. ru;
  393. rv:1.8.1.48)','Opera/9.33 (Windows;
  394. U;
  395. Windows NT 5.1;
  396. ru;
  397. rv:1.8.1.58)','Opera/9.45 (Windows;
  398. U;
  399. Windows NT 5.1;
  400. ru;
  401. rv:1.8.1.68)','Opera/9.55 (Windows;
  402. U;
  403. Windows NT 5.1;
  404. ru;
  405. rv:1.8.1.78)','Opera/9.62 (Windows;
  406. U;
  407. Windows NT 5.1;
  408. ru;
  409. rv:1.8.1.88)','IE 4.0 (Windows;
  410. U;
  411. Windows NT 5.1;
  412. ru;
  413. rv:1.8.2.18)','IE 5.0 (Windows;
  414. U;
  415. Windows NT 5.1;
  416. ru;
  417. rv:1.8.3.18)','IE 6.0 (Windows;
  418. U;
  419. Windows NT 5.1;
  420. ru;
  421. rv:1.8.4.18)','IE 7.0 (Windows;
  422. U;
  423. Windows NT 5.1;
  424. ru;
  425. rv:1.8.5.18)','IE 5.5 (Windows;
  426. U;
  427. Windows NT 5.1;
  428. ru;
  429. rv:1.8.6.18)','Mozilla/5.0 (Windows;
  430. U;
  431. Windows NT 5.1;
  432. en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.78 Safari/532.5','Mozilla/5.0 (X11;
  433. U;
  434. Linux i686;
  435. en-US;
  436. rv:1.8.0.7) Gecko/20061031 Firefox/1.5.0.7 Flock/0.7.7','Mozilla/5.0 (X11;
  437. U;
  438. Linux i686;
  439. en-US;
  440. rv:1.8.0.7) Gecko/20060928 (Debian|Debian-1.8.0.7-1) Epiphany/2.14','Mozilla/5.0 (compatible;
  441. MSIE 9.0;
  442. Windows NT 6.1;
  443. Trident/5.0)','Mozilla/5.0 (X11;
  444. U;
  445. Linux i686;
  446. cs-CZ;
  447. rv:1.7.12) Gecko/20050929','Mozilla/5.0 (Windows;
  448. I;
  449. Windows NT 5.1;
  450. ru;
  451. rv:1.9.2.13) Gecko/20100101 Firefox/4.0','Mozilla/5.0 (Windows;
  452. U;
  453. Windows NT 5.1;
  454. en-US;
  455. rv:1.7.5) Gecko/20060127 Netscape/8.1','Opera/9.80 (Windows NT 6.1;
  456. U;
  457. ru) Presto/2.8.131 Version/11.10','Opera/9.80 (Macintosh;
  458. Intel Mac OS X 10.6.7;
  459. U;
  460. ru) Presto/2.8.131 Version/11.10','Mozilla/5.0 (Macintosh;
  461. I;
  462. Intel Mac OS X 10_6_7;
  463. ru-ru) AppleWebKit/534.31+ (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1');
  464. private $CurrentUserAgent;
  465. public function CurrentUserAgent(){if(!$this->CurrentUserAgent)return $this->RrandomUserAgent();
  466. else return $this->CurrentUserAgent;
  467. }public function SetCurrentUserAgent($user_agent){if(!in_array($user_agent,$this->UserAgentsList))$this->Add($user_agent);
  468. $this->CurrentUserAgent=$user_agent;
  469. }public function RrandomUserAgent(){$key=mt_rand(0,count($this->UserAgentsList)-1);
  470. return $this->UserAgentsList[$key];
  471. }public function SetUserAgents($user_agents){if(is_file($user_agents)&& file_exists($user_agents))$user_agents=file_get_contents($user_agents);
  472. if(is_string($user_agents))$user_agents=split("[\r\n]",$user_agents);
  473. foreach($user_agents as $user_agent){if(!$this->Add($user_agent))continue;
  474. }}public function Add($user_agent){if(!trim($user_agent))return false;
  475. $this->UserAgentsList[]=trim($user_agent);
  476. return true;
  477. }public function clear(){$this->UserAgentsList=array();
  478. }}class PostData{public $Multipart='multipart/form-data';
  479. public $Variables;
  480. public $UseMultipart;
  481. }class RequestData{const METHOD_GET='get';
  482. const METHOD_POST='post';
  483. const STATE_FAILED="Failed";
  484. const STATE_RETRIEVING="Retrieving";
  485. const STATE_FINISHED="Finished";
  486. const STATE_TIMEOUT="Timeout";
  487. public $Url;
  488. public $Host;
  489. public $Port;
  490. public $Proxy;
  491. public $UserAgent;
  492. public $PathQuery;
  493. public $State;
  494. public $RequestMethod;
  495. public $Referer;
  496. public $Content='';
  497. public $Size=0;
  498. public $ConnectTimeout=0;
  499. public $Timeout=0;
  500. public $Request;
  501. public $PostData=null;
  502. private $Boundary;
  503. public $OtherData;
  504. public function SetOtherData($OtherData){$this->OtherData=$OtherData;
  505. }public function RequestData($url){$this->SetUrl($url);
  506. $this->Referer='http://' .$this->Host .'/';
  507. $this->Boundary="NEXT" .md5(uniqid(microtime()));
  508. }public function SetUrl($url){$url_data=parse_url($url);
  509. $url_data['path']=@$url_data['path']?$url_data['path']:'/';
  510. $this->Url=$url;
  511. $this->Host=$url_data['host'];
  512. $this->Port=empty($url_data['port'])?80:$url_data['port'];
  513. $this->PathQuery=empty($url_data['query'])?$url_data['path']:$url_data['path'] .'?' .$url_data['query'];
  514. }public function SetState($State){$this->State=$State;
  515. }public function SetProxy($WebProxy){if(!$WebProxy)return false;
  516. $this->Proxy=$WebProxy;
  517. }public function SetUserAgent($UserAgent){$this->UserAgent=$UserAgent;
  518. }public function SetPostData($PostData,$UseMultipart=false){$this->PostData->Variables=$PostData;
  519. $this->PostData->UseMultipart=$UseMultipart;
  520. }public function SetRequestMethod($RequestMethod){$this->RequestMethod=$RequestMethod;
  521. }public function SetReferer($Referer){if(!trim($Referer))return;
  522. $this->Referer=$Referer;
  523. }public function SetConnectTimeout($Value){$this->ConnectTimeout=$Value;
  524. }public function SetContent($Content){$this->Content=$Content;
  525. }public function AddContent($Content){$this->Content .= $Content;
  526. }public function GetRequest(){if(!$this->Request)return $this->Request;
  527. return $this->MakeRequest();
  528. }function RequestWithProxy($method){if(!$this->Proxy)return false;
  529. $this->Request="{$method} {$this->Url} HTTP/1.0\r\n";
  530. $this->Request .="Host: {$this->Proxy->adress}\r\n";
  531. if($this->Proxy->login && $this->Proxy->password)$this->Request .= "Proxy-Authorization: Basic " .base64_encode("{$this->Proxy->login}:{$this->Proxy->password}") ."\r\n\r\n";
  532. }function RequestWithoutProxy($method){if($this->Proxy)return false;
  533. $this->Request="{$method} {$this->PathQuery} HTTP/1.0\r\n";
  534. $this->Request .="Host: {$this->Host}\r\n";
  535. }public function MakeRequest(){switch($this->RequestMethod){case self::METHOD_GET:$this->RequestWithProxy('GET');
  536. $this->RequestWithoutProxy('GET');
  537. $this->Request .="Referer: {$this->Referer}\r\n";
  538. $this->Request .= "Accept: text/html, application/xml;
  539. q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;
  540. q=0.1\r\n";
  541. $this->Request .= "Accept-Language: ru\r\n";
  542. $this->Request .= "Accept-Charset: windows-1251, utf-8;
  543. q=0.6, *;
  544. q=0.1\r\n";
  545. $this->Request .= "Expires: no-store, no-cache, must-revalidate\r\n";
  546. $this->Request .= "Cache-Control: no-cache\r\n";
  547. $this->Request .="User-Agent: {$this->UserAgent}\r\n";
  548. $this->Request .= "Connection: close\r\n";
  549. $this->Request .= "\r\n";
  550. break;
  551. case self::METHOD_POST:$this->RequestWithProxy('POST');
  552. $this->RequestWithoutProxy('POST');
  553. switch(strtolower($this->PostData->UseMultipart)){case true:parse_str($variables,$variables);
  554. while(list($key,$key)=key){$query_data .= "--" .$this->boundary ."\r\n";
  555. $query_data .="Content-Disposition: form-data;
  556. name=\"{$key}\"\r\n\r\n";
  557. $query_data .="{$value}\r\n";
  558. }$query_data .= "--" .$this->boundary ."--\r\n";
  559. $this->Request .="User-Agent: {$this->UserAgent}\r\n" ."Referer: {$this->Referer}\r\n" ."Content-Type: multipart/form-data;
  560. boundary=" .$this->boundary ."\r\n" ."Content-Length: " .strlen($query_data) ."\r\n" ."Connection: close\r\n" ."\r\n" .$query_data;
  561. break;
  562. default:$query_data=$variables;
  563. $this->Request .="User-Agent: {$this->UserAgent}\r\n" ."Referer: {$this->Referer}\r\n" ."Content-Type: application/x-www-form-urlencoded\r\n" ."Content-Length: " .strlen($query_data) ."\r\n" ."Connection: close\r\n" ."\r\n" .$query_data;
  564. break;
  565. }}}}class UrlWithOtherData{public $Url;
  566. public $OtherData;
  567. public function UrlWithOtherData($Url,$OtherData){$this->Url=$Url;
  568. $this->OtherData=$OtherData;
  569. }}class HTTP_Request{const CURL='Curl';
  570. const SOCKETS='Sockets';
  571. const SOCKS5='SOCKS5';
  572. const SOCKS4='SOCKS4';
  573. const HTTP=false;
  574. public $RequestType=self::SOCKETS;
  575. public function SetRequestType($value){$this->RequestType=$value;
  576. }public $ProxyType;
  577. public function SetProxyType($value){$this->ProxyType=$value;
  578. }private $text_output_charset='UTF-8';
  579. public function set_output_charset($charset){$this->text_output_charset=$charset;
  580. }public $UserAgentsManager;
  581. public function SetUserAgentsManager($user_agents_manager){$this->UserAgentsManager=$user_agents_manager;
  582. }public function SetUserAgents($user_agents){$this->UserAgentsManager->SetUserAgents($user_agents);
  583. }public $ProxyManager;
  584. public function SetProxyManager($ProxyManager){if($ProxyManager)$this->ProxyManager=$ProxyManager;
  585. }public $LocalIpManager;
  586. public function SetLocalIpManager($local_ip_manager){if($local_ip_manager)$this->LocalIpManager=$local_ip_manager;
  587. }public $StreanCunt;
  588. public function SetStreamCount($count){$this->StreamCount=$count;
  589. }public $MaxTimeout=100;
  590. public function SetMaxTimeout($value){$this->MaxTimeout=$value;
  591. }var $max_uptime=30;
  592. var $max_size=1024000;
  593. private $time_start=0;
  594. private $time_total=0;
  595. private $_pool=array();
  596. private $_sockets=array();
  597. private $boundary="";
  598. private $pool_count=0;
  599. public function HTTP_Request($charset='UTF-8'){$this->text_output_charset=$charset;
  600. $this->boundary="NEXT" .md5(uniqid(microtime()));
  601. $this->UserAgentsManager=new UserAgentsManager();
  602. $this->ProxyManager=new ProxyManager();
  603. $this->LocalIpManager=new LocalIpAsProxyManager();
  604. }public function AddUrl($Url,$Referer=false,$OtherData=false){if(!$Url)return false;
  605. $RequestData=new RequestData($Url);
  606. $RequestData->SetState(RequestData::STATE_RETRIEVING);
  607. $RequestData->SetUserAgent($this->UserAgentsManager->RrandomUserAgent());
  608. $proxy=$this->LocalIpManager->RandomValidProxy();
  609. $proxy=$proxy?$proxy:$this->ProxyManager->RandomValidProxy();
  610. $RequestData->SetProxy($proxy);
  611. $RequestData->SetReferer($Referer);
  612. $RequestData->SetRequestMethod(RequestData::METHOD_GET);
  613. $RequestData->SetOtherData($OtherData);
  614. $RequestData->MakeRequest();
  615. $this->_pool[$this->pool_count++]=$RequestData;
  616. }public function AddUrlWithPostData($Url,$PostData,$UseMultipart=false,$Referer="",$OtherData=false){if(!$url)return false;
  617. $RequestData=new RequestData($url);
  618. $RequestData->SetState(RequestData::STATE_RETRIEVING);
  619. $RequestData->SetUserAgent($this->UserAgentsManager->RrandomUserAgent());
  620. $proxy=$this->LocalIpManager->RandomValidProxy();
  621. $proxy=$proxy?$proxy:$this->ProxyManager->RandomValidProxy();
  622. $RequestData->SetProxy($proxy);
  623. $RequestData->SetReferer($referer);
  624. $RequestData->SetRequestMethod(RequestData::METHOD_POST);
  625. $RequestData->SetPostData($PostData,$UseMultipart);
  626. $RequestData->SetOtherData($OtherData);
  627. $RequestData->MakeRequest();
  628. $this->_pool[$this->pool_count++]=$RequestData;
  629. }public function AddUrls($UrlList){if(is_string($UrlList))$UrlList=split("[\r\n]",$UrlList);
  630. foreach($UrlList as $Url){$this->AddUrl(trim($Url));
  631. }}public function AddUrlsWithOtherData($UrlListWithOtherData){foreach($UrlListWithOtherData as $UrlWithOtherData){$this->AddUrl(trim($UrlWithOtherData->Url),false,$UrlWithOtherData->OtherData);
  632. }}public function GetResponses($only_content=false){if($this->RequestType == self::SOCKETS){return $this->GetResponsesWithSockets($only_content);
  633. }else{return $this->GetResponsesWithCurl($only_content);
  634. }}public function GetResponsesWithCurl($only_content=false){set_time_limit($this->MaxTimeout);
  635. $this->time_start=time();
  636. $timer=new RequestTimer();
  637. $timer->start();
  638. $mh=curl_multi_init();
  639. foreach($this->_pool as $thread_index => $RequestData){$this->_sockets[$thread_index]=curl_init(trim($RequestData->Url));
  640. $this->_pool[$thread_index]->State == RequestData::STATE_RETRIEVING;
  641. curl_setopt($this->_sockets[$thread_index],CURLOPT_RETURNTRANSFER,1);
  642. curl_setopt($this->_sockets[$thread_index],CURLOPT_HEADER,1);
  643. curl_setopt($this->_sockets[$thread_index],CURLOPT_FOLLOWLOCATION,1);
  644. curl_setopt($this->_sockets[$thread_index],CURLOPT_URL,$RequestData->Url);
  645. curl_setopt($this->_sockets[$thread_index],CURLOPT_REFERER,$RequestData->Referer);
  646. curl_setopt($this->_sockets[$thread_index],CURLOPT_USERAGENT,$RequestData->UserAgent);
  647. curl_setopt($this->_sockets[$thread_index],CURLOPT_TIMEOUT,$RequestData->Timeout);
  648. if($this->ProxyType == self::SOCKS4){curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS4);
  649. }elseif($this->ProxyType == self::SOCKS5){curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
  650. }if($RequestData->Proxy){if($RequestData->Proxy->ISLocalIP){curl_setopt($this->_sockets[$thread_index],CURLOPT_INTERFACE,$RequestData->Proxy->adress);
  651. }else{curl_setopt($this->_sockets[$thread_index],CURLOPT_PROXY,$RequestData->Proxy->adress .':' .$RequestData->Proxy->port);
  652. if($RequestData->Proxy->login && $RequestData->Proxy->password)curl_setopt($this->_sockets[$thread_index],CURLOPT_PROXYUSERPWD,$RequestData->Proxy->login .':' .$RequestData->Proxy->password);
  653. }}curl_setopt($this->_sockets[$thread_index],CURLOPT_MAXREDIRS,10);
  654. curl_multi_add_handle($mh,$this->_sockets[$thread_index]);
  655. $this->_pool[$thread_index]->SetConnectTimeout($timer->timeout());
  656. }do{$x=curl_multi_exec($mh,$active);
  657. }while($active);
  658. $done=0;
  659. foreach($this->_sockets as $thread_index => $socket){$timeout=$this->_pool[$thread_index]->Timeout;
  660. $temp=curl_multi_getcontent($this->_sockets[$thread_index]);
  661. $temp=Encoding::Encode($temp,$this->text_output_charset);
  662. $this->_pool[$thread_index]->Content=preg_replace("~[\n]+~ism","\n",$temp);
  663. $this->_pool[$thread_index]->Timeout=$timeout+$timer->timeout();
  664. $this->_pool[$thread_index]->SetState(RequestData::STATE_FINISHED);
  665. }curl_multi_close($mh);
  666. foreach($this->_sockets as $thread_index => $socket){curl_close($this->_sockets[$thread_index]);
  667. }$this->time_total=time()-$this->time_start;
  668. if($only_content){$result="";
  669. foreach($this->_pool as $thread_index => $url){$result .= $RequestData->Content;
  670. }$this->Clean();
  671. return $result;
  672. }return $this->_pool;
  673. }public function GetResponsesWithSockets($only_content=false){set_time_limit($this->MaxTimeout);
  674. $this->time_start=time();
  675. $timer=new RequestTimer();
  676. $timer->start();
  677. foreach($this->_pool as $thread_index => $RequestData){if(@$RequestData->Proxy->ISLocalIP){$Host=$RequestData->Host;
  678. $Port=$RequestData->Proxy?$RequestData->Proxy->port:$RequestData->Port;
  679. }else{$Host=$RequestData->Proxy?$RequestData->Proxy->adress:$RequestData->Host;
  680. $Port=$RequestData->Proxy?$RequestData->Proxy->port:$RequestData->Port;
  681. }@$socket=fsockopen($Host,$Port,$errno,$errstr,5);
  682. if($socket){$this->_sockets[$thread_index]=$socket;
  683. socket_set_blocking($socket,FALSE);
  684. socket_set_timeout($socket,$this->max_uptime);
  685. fputs($socket,$RequestData->Request);
  686. }else{$this->_pool[$thread_index]->SetState(RequestData::STATE_FAILED);
  687. }$this->_pool[$thread_index]->SetConnectTimeout($timer->timeout());
  688. }$done=0;
  689. while($done<count($this->_sockets)){foreach($this->_sockets as $thread_index => $socket){if($this->_pool[$thread_index]->State == RequestData::STATE_RETRIEVING){$timeout=$this->_pool[$thread_index]->Timeout;
  690. if($timeout<$this->max_uptime){$size=strlen($this->_pool[$thread_index]->Content);
  691. if($size<$this->max_size &&!feof($socket)){$content=fgets($socket,1024);
  692. $this->_pool[$thread_index]->AddContent($content);
  693. }else{$this->_pool[$thread_index]->SetState(RequestData::STATE_FINISHED);
  694. ++$done;
  695. }}else{$this->_pool[$thread_index]->SetState(RequestData::STATE_TIMEOUT);
  696. ++$done;
  697. }$this->_pool[$thread_index]->Timeout=$timeout+$timer->timeout();
  698. $this->_pool[$thread_index]->Size=strlen($this->_pool[$thread_index]->Content);
  699. }}$this->_pool[$thread_index]->Content=preg_replace("~[\n]+~ism","\n",$this->_pool[$thread_index]->Content);
  700. }foreach($this->_sockets as $thread_index => $socket){fclose($socket);
  701. }$this->time_total=time()-$this->time_start;
  702. foreach($this->_pool as $key=>$value){$this->_pool[$key]->Content=Encoding::Encode($this->_pool[$key]->Content,$this->text_output_charset);
  703. }if($only_content){$result="";
  704. foreach($this->_pool as $thread_index => $url){$result .= $RequestData->Content;
  705. }$this->Clean();
  706. return $result;
  707. }return $this->_pool;
  708. }private function Clean(){$this->_pool=array();
  709. $this->_sockets=array();
  710. }}class RequestTimer{var $time_start=0;
  711. function getmicrotime(){list($usec,$sec)=explode(' ',microtime());
  712. return (double)$usec+(double)$sec;
  713. }function start(){$this->time_start=$this->getmicrotime();
  714. }function timeout(){$timeout=$this->getmicrotime()-$this->time_start;
  715. $this->start();
  716. return $timeout;
  717. }}class Rings{private $list;
  718. public function Add($count){$this->list[]=$count;
  719. }public function GetRings(){return $this->list;
  720. }}class Parser{public $RequestType;
  721. public $ProxyType;
  722. public $ContentCount;
  723. public $MaxParsedPagesCount;
  724. public $MinSnippetLenght;
  725. public $OutputCharset;
  726. public $SnippetsCount;
  727. public $StreamCount;
  728. public $ProxyList;
  729. public $LocalIPList;
  730. public $Enabled;
  731. }class Links{public $OutPrevLinkMode;
  732. public $TotalLnksCount;
  733. public function Links(){$this->Rings=new Rings();
  734. }}class DoorInstall{public $LinksMode;
  735. public $SetCountMainPagesLinksInMap;
  736. public $CountInnerLinksInMap;
  737. public $SiteMapPatterns;
  738. public $SiteMapMainPattern;
  739. public $SiteMapTemplate;
  740. public $KeywordsFile;
  741. public $ContentFile;
  742. public function SetSiteMapPattern($Pattern,$RelativePath){$host=Config::$Doorgen->MainHost?Config::$Doorgen->MainHost:Config::GetAutoMainHost();
  743. $this->SiteMapMainPattern=new SM_Pattern($Pattern,$RelativePath,$host);
  744. }public function AddSiteMapPattern($Pattern,$RelativePath){$this->SiteMapPatterns->Add($Pattern,$RelativePath);
  745. }public function DoorInstall(){$host=Config::$Doorgen->MainHost?Config::$Doorgen->MainHost:Config::GetAutoMainHost();
  746. $this->SiteMapPatterns=new SM_Patterns($host);
  747. }}class Doorgen{public $MainHost;
  748. public $TemplateFolder;
  749. public $TemplateFile;
  750. public $MainPageFile;
  751. public $MinContentLenght;
  752. public $MaxContentLenght;
  753. public $HeadersCount;
  754. public $ContentPattern;
  755. }class Redirect{public $IncludingScriptMode;
  756. public $RedirectURL;
  757. public $CheckEngineMode;
  758. public $Enabled;
  759. }class Config{public static $Doorgen;
  760. public static $Parser;
  761. public static $Links;
  762. public static $Install;
  763. public static $Redirect;
  764. public static $TDS_Link;
  765. public static function Init(){self::$Links=new Links();
  766. self::$Parser=new Parser();
  767. self::$Doorgen=new Doorgen();
  768. self::$Redirect=new Redirect();
  769. self::$Install=new DoorInstall();
  770. }public static function GetAutoMainHost($DomainLevel=2){if(!in_array($DomainLevel,array(2,3)))die('Вы указали не верный уровень домена в настройках, поддерживаемые уровни - 2 и 3!');
  771. switch($DomainLevel){case 2:preg_match('~^.*?([^\.]+\.[^\.]+)$~ism',@$_SERVER['HTTP_HOST'],$domain);
  772. break;
  773. case 3:preg_match('~^.*?([^\.]+\.[^\.]+\.[^\.]+)$~ism',@$_SERVER['HTTP_HOST'],$domain);
  774. break;
  775. }if(isset($domain[1]))$domain=$domain[1];
  776. else die('Не удалось автоматически определить основной домен! Укажите домен вручную!');
  777. return $domain;
  778. }}Config::Init();
  779. class _ListItem{public $Key;
  780. public $Value;
  781. public function _ListItem($key,$value){$this->Key=$key;
  782. $this->Value=$value;
  783. }}class _List{public $list=array();
  784. private $current_index=0;
  785. public function SetListFromArray($list){if(is_string($list))$list=split("\n",$list);
  786. foreach($list as $index => $item){$this->Add($item,$index);
  787. }}public function Add($object,$index=null){if(is_string($object))$object=trim($object);
  788. if(!$object)return false;
  789. if($index){if(key_exists($index,$this->list))return false;
  790. $this->list[$index]=$object;
  791. }else $this->list[]=$object;
  792. return true;
  793. }public function Shuffle($srand=false){if($srand)srand($srand);
  794. else srand(microtime()*10000);
  795. shuffle($this->list);
  796. return $this->list;
  797. }public function RandomItem($srand=0){if(!count($this->list))return;
  798. if($srand)srand($srand);
  799. else srand(microtime()*10000);
  800. $index=array_rand($this->list);
  801. $item=$this->list[$index];
  802. return new _ListItem(key($this->list),$item);
  803. }public function RandomItems($count,$srand=0){if($srand)srand($srand);
  804. else srand(microtime()*10000);
  805. $indexes=array_rand($this->list,$count);
  806. $items=array();
  807. foreach($indexes as $key => $index){$items[$key]=$this->list[$index];
  808. }return $items;
  809. }public function Current(){if(!$item=current($this->list))return false;
  810. return new _ListItem(key($this->list),$item);
  811. }public function Count(){return count($this->list);
  812. }public function Next(){if(!$item=next($this->list))return false;
  813. return new _ListItem(key($this->list),$item);
  814. }public function Prev(){if(!$item=prev($this->list))return false;
  815. return new _ListItem(key($this->list),$item);
  816. }public function Reset(){reset($this->list);
  817. }public function First(){if(!$item=reset($this->list))return false;
  818. return new _ListItem(key($this->list),$item);
  819. }public function Last(){if(!$item=end($this->list))return false;
  820. return new _ListItem(key($this->list),$item);
  821. }public function Clear(){$this->list=array();
  822. }}class Markers{public $Query;
  823. public $Num;
  824. public $Page;
  825. public $Start;
  826. public $BasePage;
  827. }class ValueChecker{public function CheckValue($value,$message=''){$value=trim($value);
  828. if(!$value)return false;
  829. return true;
  830. }}class EngineSnippetsData extends ValueChecker{public $Name;
  831. public $URL;
  832. public $SnippetPatterns;
  833. public $NumValues;
  834. public $Formula;
  835. public $LastPage=1;
  836. public function EngineSnippetsData(){$this->SnippetPatterns=new _List();
  837. }public function SetName($value){if(!$this->CheckValue($value,"Вы не указали название поисковой системы"))return false;
  838. $this->Name=trim($value);
  839. return true;
  840. }public function SetURL($value){if(!$this->CheckValue($value,"Вы не указали URL поисковой системы"))return false;
  841. $this->URL=$value;
  842. return true;
  843. }public function AddSnippetPattern($value){$this->SnippetPatterns->Add($value);
  844. return true;
  845. }public function SetNumValues($value){if(is_string($value))$value=explode("\n",$value);
  846. if(is_int($value))$value=array($value);
  847. $nums=array();
  848. foreach($value as $num){if($num*1)$nums[]=$num*1;
  849. }$this->NumValues=$nums;
  850. return true;
  851. }public function SetFormula($value){if(!$this->CheckValue($value,"Вы не указали формулу расчета номера страницы!"))return false;
  852. $this->Formula=$value;
  853. return true;
  854. }public function SetLastPage($value){$this->LastPage=$value*1;
  855. return true;
  856. }public function MakeURL($Markers){$query=urlencode(trim(iconv('cp1251','utf8',$Markers->Query)));
  857. $Formules=new Formules();
  858. $start_or_page=$Formules->Calculation($this->Formula,$Markers->BasePage,$Markers->Num);
  859. return strtr($this->URL,array('{QUERY}'=> $query,'{NUM}'=> $Markers->Num,'{PAGE}'=> $start_or_page,'{START}'=> $start_or_page));
  860. }}class Formules{const PAGE="{PAGE} = {BASE-PAGE}";
  861. const PAGEMINUS1="{PAGE} = {BASE-PAGE} - 1";
  862. const START="{START} = {BASE-PAGE} * {NUM} - {NUM}";
  863. const STARTPLUS1="{START} = {BASE-PAGE} * {NUM} + 1 - {NUM}";
  864. private $List;
  865. public $Start;
  866. public $Page;
  867. public function Formules(){$this->List=new _List();
  868. $this->List->Add(new _ListItem(self::PAGE,'PAGE'));
  869. $this->List->Add(new _ListItem(self::PAGEMINUS1,'PAGEMINUS1'));
  870. $this->List->Add(new _ListItem(self::START,'START'));
  871. $this->List->Add(new _ListItem(self::STARTPLUS1,'STARTPLUS1'));
  872. }public function Calculation($Formula,$BasePage,$Num){switch($Formula){case self::PAGE:$this->Page=$Result=$BasePage;
  873. break;
  874. case self::PAGEMINUS1:$this->Page=$Result=$BasePage-1;
  875. break;
  876. case self::START:$this->Start=$Result=$BasePage*$Num-$Num;
  877. break;
  878. case self::STARTPLUS1:$this->Start=$Result=$BasePage*$Num+1-$Num;
  879. break;
  880. default:$this->Page=$Result=$BasePage;
  881. break;
  882. }return $Result;
  883. }}class EngineSnippetsParser{public $SnippetsList;
  884. private $ContentLenght=0;
  885. public $RequestType=HTTP_Request::SOCKETS;
  886. public function SetRequestType($value){$this->RequestType=$value;
  887. }public $ProxyType;
  888. public function SetProxyType($value){$this->ProxyType=$value;
  889. }private $ProxyManager;
  890. public function SetProxyManager($ProxyManager){$this->ProxyManager=$ProxyManager;
  891. }public function SetProxyList($ProxyList){$this->ProxyManager=new ProxyManager();
  892. $this->ProxyManager->SetProxyList($ProxyList);
  893. }private $LocalIpManager;
  894. public function SetLocalIpManager($LocalIpManager){$this->LocalIpManager=$LocalIpManager;
  895. }public function SetLocalIpList($LocalIpList){$this->LocalIpManager=new LocalIpAsProxyManager();
  896. $this->LocalIpManager->SetProxyList($LocalIpList);
  897. }private $SnippetsCount=0;
  898. public function SetSnippetsCount($SnippetsCount){$this->SnippetsCount=intval($SnippetsCount);
  899. }private $ContentCount=0;
  900. public function SetContentCount($ContentCount){$this->ContentCount=intval($ContentCount)*1024;
  901. }private $MaxParsedPagesCount;
  902. public function SetMaxParsedPagesCount($MaxParsedPagesCount){$this->MaxParsedPagesCount=intval($MaxParsedPagesCount);
  903. }private $MinSnippetLenght=30;
  904. public function SetMinSnippetLenght($MinSnippetLenght){$this->MinSnippetLenght=intval($MinSnippetLenght);
  905. }private $StreamCount;
  906. public function SetStreamCount($StreamCount){$this->StreamCount=intval($StreamCount);
  907. }private $OutputCharset='cp1251';
  908. public function SetOutputCharset($OutputCharset){$this->OutputCharset=trim($OutputCharset);
  909. }public $error_content;
  910. protected $error_message;
  911. public $EnginesList;
  912. public function SetEnginesList($EnginesList){if(is_array($EnginesList)){foreach($EnginesList as $engine){$this->EnginesList->Add($engine);
  913. }}else $this->EnginesList=$EnginesList;
  914. }public $ExactResult=false;
  915. public function EngineSnippetsParser($ExactResult=false){$this->EnginesList=new _List();
  916. $this->SnippetsList=new _List();
  917. $this->ExactResult=$ExactResult;
  918. }public function AddEngine($Engine){if(!$this->EnginesList->Add($Engine,$Engine->Name))die('Не удалось добавить поисковую систему, возможно ПС с таким названием уже существует в списке!');
  919. }function MakeUrls($query,$count){$UrlList=array();
  920. while($count){$Engine=$this->EnginesList->RandomItem()->Value;
  921. $Markers=new Markers();
  922. $Markers->BasePage=$Engine->LastPage++;
  923. $Markers->Num=max($Engine->NumValues);
  924. $Markers->Query=$query;
  925. $UrlList[]=new UrlWithOtherData($Engine->MakeURL($Markers),$Engine);
  926. $count--;
  927. }return $UrlList;
  928. }function GetSnippets($Query){if(!trim($Query))return;
  929. $content_count=0;
  930. $snippets_count=0;
  931. $pages_count=0;
  932. if(!$this->ContentCount &&!$this->SnippetsCount &&!$this->MaxParsedPagesCount)$this->SnippetsCount=500;
  933. while(1){if($this->ContentCount && $this->ContentCount <= $this->ContentLenght)break;
  934. if($this->SnippetsCount && $this->SnippetsCount <= $this->SnippetsList->Count())break;
  935. if($this->MaxParsedPagesCount && $this->MaxParsedPagesCount <= $pages_count)break;
  936. $count=$this->MaxParsedPagesCount-$pages_count<$this->StreamCount && $this->MaxParsedPagesCount?$this->MaxParsedPagesCount-$pages_count:$this->StreamCount;
  937. $UrlList=$this->MakeUrls($Query,$count);
  938. $responses=$this->GetResponses($UrlList);
  939. $count=$this->ParseSnippetsFromResponses($responses);
  940. if($count === false)return false;
  941. $pages_count+$count;
  942. }return true;
  943. }function GetResponses($UrlList){$request=new HTTP_Request($this->OutputCharset);
  944. $request->SetRequestType($this->RequestType);
  945. if($this->ProxyManager)$request->SetProxyManager($this->ProxyManager);
  946. if($this->LocalIpManager)$request->SetLocalIpManager($this->LocalIpManager);
  947. $request->AddUrlsWithOtherData($UrlList);
  948. $result=$request->GetResponses(false);
  949. return $result;
  950. }private function ParseSnippetsFromResponses($Responses){$pages_count=0;
  951. foreach($Responses as $response){if($this->ParseSnippets($response))$pages_count++;
  952. }if(!$this->SnippetsList->Count())return false;
  953. $this->SnippetsList->Shuffle();
  954. return $pages_count;
  955. }private function ParseSnippets($response){$content=$response->Content;
  956. $_snippets=array();
  957. foreach($response->OtherData->SnippetPatterns->list as $pattern){if(!preg_match_all("~{$pattern}~ism",$content,$temp_snippets))continue;
  958. $_snippets=array_merge($temp_snippets[1],$_snippets);
  959. }$snippet_count=0;
  960. foreach($_snippets as $snippet){if($this->ExactResult){if($this->ContentCount && $this->ContentCount <= $this->ContentLenght)break;
  961. if($this->SnippetsCount && $this->SnippetsCount <= $this->SnippetsList->Count())break;
  962. if($this->MaxParsedPagesCount && $this->MaxParsedPagesCount <= $pages_count)break;
  963. }
  964. $snippet=preg_replace('~<[^>]+>~ism',' ',$snippet);
  965. $snippet=preg_replace('~[\s]+~ism',' ',$snippet);
  966. $snippet=preg_replace('~ ([\.,!\?\%])~ism','\\1',$snippet);
  967. $snippet=preg_replace('~\.\.\.~ism','.',$snippet);
  968. $snippet=preg_replace('~[/]~ism','',$snippet);
  969. $snippet=preg_replace('~(www|http)[^ ]+~ism','',$snippet);
  970. $snippet=preg_replace('~\.[a-zрф0-9]{2,5}~ism','',$snippet);
  971. $snippet=preg_replace('~^[\.,!\?\%]+~ism','',$snippet);
  972. $snippet=preg_replace('~[\s]+~ism',' ',$snippet);
  973.  
  974. if(strlen($snippet)<$this->MinSnippetLenght)continue;
  975. $snippet=trim($snippet);
  976. $this->SnippetsList->Add($snippet);
  977. $this->ContentLenght += strlen($snippet);
  978. $snippet_count++;
  979. }if($snippet_count)return true;
  980. return false;
  981. }public function error($error_message){$this->error_message=$error_message;
  982. return RESULT_ERROR;
  983. }public function error_message(){if($this->error_message)return $this->error_message;
  984. }}class keyword{public $link_body;
  985. public $anchor;
  986. public $positions;
  987. public function keyword($anchor,$link_body,$positions){$this->anchor=trim(text::format($anchor));
  988. $this->anchor_to_lower=trim(text::format($anchor,true));
  989. $this->link_body=trim($link_body);
  990. $this->positions=$positions;
  991. }}final class keywords{static public $binary_keywords_path;
  992. static public $binary_searcher;
  993. static public function init($binary_keywords_path=null,$sort_item=null,$delimiter=null){if(!file_exists($binary_keywords_path))die('Не найдена основная база данных, повторите инсталяцию!');
  994. self::$binary_keywords_path=$binary_keywords_path;
  995. self::$binary_searcher=new binary_search_col($binary_keywords_path,$sort_item,$delimiter);
  996. }static public function get_keyword($string){$string=preg_replace('~([/]+|\.[^\.]+$)~','',$string);
  997. $result=self::$binary_searcher->search($string);
  998. if(!$result)return false;
  999. $keyword=new keyword($result->result[1],$result->result[0],$result->positions);
  1000. return $keyword;
  1001. }static public function get_keyword_by_position($position){if(!$position*1)return false;
  1002. $result=self::$binary_searcher->get_string_by_position($position);
  1003. $keyword=new keyword($result->result[1],$result->result[0],$result->positions);
  1004. return $keyword;
  1005. }static public function get_keyword_by_string_position($string_position){if(!$string_position*1)return false;
  1006. $keyword=self::get_keyword_by_position($string_position*self::$binary_searcher->string_lenght);
  1007. return $keyword;
  1008. }}final class text{static public function format($string,$all_to_lower=false){$first_letter=!$all_to_lower?strtr(substr($string,0,1),'йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnm','ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNM'):'';
  1009. $string=$all_to_lower?strtr($string,'ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNM','йцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnm'):trim(substr_replace($string,$first_letter,0,1));
  1010. $string=strtr($string,array('--'=>'-'));
  1011. return $string;
  1012. }}final class Path{public function StripSlashes($path){return preg_replace('~[\\/]+~','/',$path);
  1013. }}final class translate{static public function eng($string){$string=strtr($string,'абвгдеёзийклмнопрстуфхъыэ','abvgdeeziyklmnoprstufh’ie');
  1014. $string=strtr($string,'АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ','abvgdeeziyklmnoprstufh’ie');
  1015. $string=strtr($string,array('ж'=>'zh','ц'=>'ts','ч'=>'ch','ш'=>'sh','щ'=>'shch','ь'=>'','ю'=>'yu','я'=>'ya','Ж'=>'zh','Ц'=>'ts','Ч'=>'ch','Ш'=>'sh','Щ'=>'shch','Ь'=>'','Ю'=>'yu','Я'=>'ya','ї'=>'i','Ї'=>'yi','є'=>'ie','Є'=>'ie'));
  1016. return $string;
  1017. }}class binary_search{const ALGORITM_ONE=1;
  1018. const ALGORITM_TWO=2;
  1019. private $binary_file;
  1020. private $algoritm=self::ALGORITM_ONE;
  1021. public function binary_search($binary_file,$algoritm=self::ALGORITM_ONE){$this->binary_file=$binary_file;
  1022. $this->algoritm=$algoritm;
  1023. }public function search($string){if($this->algoritm == self::ALGORITM_ONE){return $this->search_with_algoritm_one($string);
  1024. }else{return $this->search_with_algoritm_two($string);
  1025. }}public function make_indexed_file($file_name){$data=file($file_name);
  1026. sort($data);
  1027. $result=array();
  1028. $strlen=0;
  1029. foreach($data as $str){if(trim($str)){$str=trim(strtolower($str));
  1030. $result[]=$str;
  1031. $len=strlen($str);
  1032. $strlen=$strlen<$len?$len:$strlen;
  1033. }}$data=array_unique($result);
  1034. $result='';
  1035. foreach($data as $str){$len=strlen($str);
  1036. $len=$strlen-$len;
  1037. $hvost='';
  1038. while($len--){$hvost .= ' ';
  1039. }$result .= $str .$hvost ."\r\n";
  1040. }file_put_contents($this->binary_file,$result);
  1041. }private function search_with_algoritm_one($string){$fp=fopen($this->binary_file,'r');
  1042. $size=filesize($this->binary_file);
  1043. $strlen=strlen(fgets($fp));
  1044. $count=floor($size/$strlen);
  1045. $middle=floor(($count)/2);
  1046. $result=$this->bin_find($fp,$string,0,$middle,$count,$strlen);
  1047. fclose($fp);
  1048. return $result;
  1049. }private function bin_find($fp,$string,$first,$middle,$last,$strlen,$laststring=false){$string=trim($string);
  1050. if(!$string)return false;
  1051. fseek($fp,$middle*$strlen);
  1052. $str=trim(fgets($fp));
  1053. if($laststring == $str){if($str != $string){fseek($fp,$middle-5000);
  1054. $i=0;
  1055. while($i<100){if(trim(fgets($fp))== $string)return $string;
  1056. $i++;
  1057. }return false;
  1058. }}if($str>$string){$result=$this->bin_find($fp,$string,$first,floor($middle/2),$middle,$strlen,$str);
  1059. }elseif($str<$string){$result=$this->bin_find($fp,$string,$middle,floor(($last+$middle)/2),$last,$strlen,$str);
  1060. }elseif($str == $string){$result=$str;
  1061. }else $result=false;
  1062. return $result;
  1063. }private function search_with_algoritm_two($string){$fp=fopen($this->binary_file,'r');
  1064. $size=filesize($this->binary_file);
  1065. $middle=floor(($size)/2);
  1066. $result=$this->bin_find_algoritm_two($fp,$string,0,$middle,$size);
  1067. fclose($fp);
  1068. return $result;
  1069. }private function bin_find_algoritm_two($fp,$string,$first,$middle,$last,$laststring=false){$string=trim($string);
  1070. fseek($fp,$middle);
  1071. while(fgetc($fp)!= "\n")fseek($fp,$middle--);
  1072. $str=trim(fgets($fp));
  1073. if($laststring == $str){if($str != $string){fseek($fp,$middle-5000);
  1074. $i=0;
  1075. while($i<100){if(trim(fgets($fp))== $string)return $string;
  1076. $i++;
  1077. }return false;
  1078. }}if($str>$string){$result=$this->bin_find_algoritm_two($fp,$string,$first,floor($middle/2),$middle,$str);
  1079. }elseif($str<$string){$result=$this->bin_find_algoritm_two($fp,$string,$middle,floor(($last+$middle)/2),$last,$str);
  1080. }elseif($str == $string){$result=$str;
  1081. }else $result=false;
  1082. return $result;
  1083. }}class positions{public $char_position;
  1084. public $string_position;
  1085. public function positions($char_position,$string_position){$this->char_position=$char_position;
  1086. $this->string_position=$string_position;
  1087. }}class binary_search_col_result{public $result;
  1088. public $positions;
  1089. public function binary_search_col_result($result,$char_position,$string_position){$this->result=$result;
  1090. $this->positions=new positions($char_position,$string_position);
  1091. }}class binary_search_col{private $binary_file;
  1092. private $base_file;
  1093. private $sort_item;
  1094. private $delimiter;
  1095. public $string_lenght;
  1096. public $string_count;
  1097. public function binary_search_col($binary_file,$sort_item,$delimiter){$this->base_file=$binary_file;
  1098. $this->binary_file=preg_replace('~\.[^\.$]+$~ism','.index',$binary_file);
  1099. $this->sort_item=$sort_item;
  1100. $this->delimiter=$delimiter;
  1101. if(file_exists($this->base_file)){$fp=fopen($this->base_file,'r');
  1102. $size=filesize($this->base_file);
  1103. $this->string_lenght=strlen(fgets($fp));
  1104. $this->string_count=floor($size/$this->string_lenght);
  1105. fclose($fp);
  1106. }}private function sort($a,$b){return strcmp($a[$this->sort_item],$b[$this->sort_item]);
  1107. }private function def_sort($a,$b){return strcmp($a[0],$b[0]);
  1108. }public function make_indexes_file($data){$strlen=0;
  1109. usort($data,array("binary_search_col","def_sort"));
  1110. foreach($data as $item){$len=strlen(implode($this->delimiter,$item));
  1111. $strlen=$strlen<$len?$len:$strlen;
  1112. }foreach($data as $item){$str=implode($this->delimiter,$item);
  1113. $len=strlen($str);
  1114. $len=$strlen-$len;
  1115. $hvost='';
  1116. while($len--){$hvost .= ' ';
  1117. }$result[]=$str .$hvost ."\r\n";
  1118. }file_put_contents($this->binary_file,$result);
  1119. }public function make_indexed_file($data){$strlen=0;
  1120. shuffle($data);
  1121. $i=0;
  1122. $index_data=array();
  1123. foreach($data as $item){$index_data[]=array($item[$this->sort_item],$i++);
  1124. $len=strlen(implode($this->delimiter,$item));
  1125. $strlen=$strlen<$len?$len:$strlen;
  1126. }foreach($data as $item){$str=implode($this->delimiter,$item);
  1127. $len=strlen($str);
  1128. $len=$strlen-$len;
  1129. $hvost='';
  1130. while($len--){$hvost .= ' ';
  1131. }$result[]=$str .$hvost ."\r\n";
  1132. }file_put_contents($this->base_file,$result);
  1133. $this->make_indexes_file($index_data);
  1134. }public function search($string){$fp=fopen($this->binary_file,'r');
  1135. $middle=floor(($this->string_count)/2);
  1136. $string_lenght=strlen(fgets($fp));
  1137. $result=$this->bin_find($fp,$string,0,$middle,$this->string_count,$string_lenght);
  1138. fclose($fp);
  1139. if(!$result)return false;
  1140. $pos=$result[1];
  1141. $fp=fopen($this->base_file,'r');
  1142. fseek($fp,$pos*$this->string_lenght);
  1143. $res=explode($this->delimiter,fgets($fp));
  1144. $out_result=new binary_search_col_result($res,$pos*$this->string_lenght,$pos);
  1145. $r=$this->get_string_by_position($pos*$this->string_lenght);
  1146. fclose($fp);
  1147. return $out_result;
  1148. }public function get_string_by_position($position){if(!($position*1))return false;
  1149. $fp=fopen($this->base_file,'r');
  1150. if(!$fp)return false;
  1151. fseek($fp,$position);
  1152. $res=explode($this->delimiter,fgets($fp));
  1153. $out_result=new binary_search_col_result($res,$position,$position/$this->string_lenght);
  1154. fclose($fp);
  1155. return $out_result;
  1156. }private function bin_find($fp,$string,$first,$middle,$last,$strlen,$laststring=false){$string=trim($string);
  1157. if(!$string)return false;
  1158. fseek($fp,$middle*$strlen);
  1159. $res=explode($this->delimiter,fgets($fp));
  1160. $str=trim($res[0]);
  1161. if($laststring == $str){if($str != $string){fseek($fp,$middle-5000);
  1162. $i=0;
  1163. while($i<100){if(trim(fgets($fp))== $string)return $string;
  1164. $i++;
  1165. }return false;
  1166. }}if($str>$string){$result=$this->bin_find($fp,$string,$first,floor($middle/2),$middle,$strlen,$str);
  1167. }elseif($str<$string){$result=$this->bin_find($fp,$string,$middle,floor(($last+$middle)/2),$last,$strlen,$str);
  1168. }elseif($str == $string){$result=$res;
  1169. }else $result=false;
  1170. return $result;
  1171. }}class link{public $anchor;
  1172. public $anchor_to_lower;
  1173. public $url;
  1174. public $id;
  1175. public function link($keyword,$url){$this->id=$keyword->positions->string_position;
  1176. $this->anchor=$keyword->anchor;
  1177. $this->anchor_to_lower=$keyword->anchor_to_lower;
  1178. $this->url=$url;
  1179. }}class linked{private $host;
  1180. public function set_host($value){$this->host=$value;
  1181. }const MODE_ONLY_SUBDOMAINS=1;
  1182. const MODE_SUBDOMAINS_WITH_INNER_LINKS=2;
  1183. const MODE_DOMAIN_WITH_INNER_LINKS=3;
  1184. const MODE_ALL=4;
  1185. const MODE_DOMAIN_WITH_FOLDER_AND_INNER_LINKS=5;
  1186. const RINGS_MODE_ONLY_SUBDOMAINS=1;
  1187. const RINGS_MODE_ONLY_INNER_LINKS=2;
  1188. const RINGS_MODE_INNER_LINKS_AND_FOLDERS=3;
  1189. private $mode=self::MODE_SUBDOMAINS_WITH_INNER_LINKS;
  1190. public function set_mode($value){if($value == self::MODE_ALL || $value == self::MODE_DOMAIN_WITH_INNER_LINKS){$this->rings_mode=self::RINGS_MODE_ONLY_INNER_LINKS;
  1191. }elseif($value == self::MODE_DOMAIN_WITH_FOLDER_AND_INNER_LINKS){$this->rings_mode=self::RINGS_MODE_INNER_LINKS_AND_FOLDERS;
  1192. }else $this->rings_mode=self::RINGS_MODE_ONLY_SUBDOMAINS;
  1193. $this->mode=$value;
  1194. }private $rings_mode=self::RINGS_MODE_ONLY_INNER_LINKS;
  1195. public function set_rings_mode($value){$this->rings_mode=$value;
  1196. }private $main_keyword;
  1197. public function set_main_keyword($value){$this->main_keyword=$value;
  1198. }private $request_code;
  1199. public function set_request_code($value){$this->request_code=$value;
  1200. }private $total_links_count=50;
  1201. public function set_total_links_count($value){$this->total_links_count=$value;
  1202. }private $rings;
  1203. public function add_ring($count_links_in_ring){$this->rings[]=$count_links_in_ring;
  1204. }public function set_rings($rings){$this->rings=$rings;
  1205. }private $out_prev_link_mode;
  1206. public function set_out_prev_link_mode($value){$this->out_prev_link_mode=$value;
  1207. }private $used_keyword;
  1208. private function add_used_keyword($keyword){if(!$keyword)return;
  1209. $this->used_keyword[$keyword->positions->string_position]=$keyword->anchor;
  1210. }private function is_used_keyword($keyword){if(@$this->used_keyword[$keyword->positions->string_position]== $keyword->anchor)return true;
  1211. return false;
  1212. }private $links_stack;
  1213. private $keywords_stack;
  1214. private function enqueue_links_stack($link){if(isset($this->links_stack[$link->id]))return false;
  1215. $this->links_stack[$link->id]=$link;
  1216. $this->keywords_stack[]=$link->anchor;
  1217. return true;
  1218. }private function dequeue_links_stack(){if(count($this->links_stack)== 0)return false;
  1219. $link=array_shift($this->links_stack);
  1220. return $link;
  1221. }private function get_keyword($number){if($number >= count($this->keywords_stack))return false;
  1222. return $this->keywords_stack[$number-1];
  1223. }public function out(&$tpl){$this->add_used_keyword($this->main_keyword);
  1224. foreach($this->rings as $count_links_in_ring){$this->make_ring_links($count_links_in_ring);
  1225. }$this->make_random_links();
  1226. $this->out_meta_keywords($tpl);
  1227. $this->out_numeric_keywords($tpl);
  1228. $this->out_links($tpl);
  1229. $this->out_links_boxes($tpl);
  1230. }public function make_ring_links($count_links){if(!$this->main_keyword)return;
  1231. $ring_data=$this->get_ring_data($count_links,$this->main_keyword);
  1232. if($this->out_prev_link_mode)$this->enqueue_ring_link($ring_data['prev_key'],$ring_data['next_key']);
  1233. $this->enqueue_ring_link($ring_data['next_key'],$ring_data['prev_key']);
  1234. }public function make_random_links(){$i=0;
  1235. while(1){$count=count($this->links_stack);
  1236. if($count>$this->total_links_count)break;
  1237. srand($this->request_code+$i+++$count);
  1238. $keyword=keywords::get_keyword_by_string_position(rand(0,keywords::$binary_searcher->string_count-1));
  1239. $_keyword=keywords::get_keyword_by_string_position(rand(0,keywords::$binary_searcher->string_count-1));
  1240. if($keyword == $this->main_keyword){continue;
  1241. }if(!$this->enqueue_random_link($keyword,$_keyword)){continue;
  1242. }}}function enqueue_ring_link($keyword,$dop_keyword=null){switch($this->rings_mode){case self::RINGS_MODE_ONLY_INNER_LINKS:$result=$this->enqueue_links_stack($this->make_link($keyword));
  1243. break;
  1244. break;
  1245. case self::RINGS_MODE_ONLY_SUBDOMAINS:$result=$this->enqueue_links_stack($this->make_subdomain($keyword));
  1246. break;
  1247. break;
  1248. case self::RINGS_MODE_INNER_LINKS_AND_FOLDERS:switch(rand(0,1)){case 0:$result=$this->enqueue_links_stack($this->make_folder($keyword));
  1249. break;
  1250. case 1:$result=$this->enqueue_links_stack($this->make_folder_with_link($keyword,$dop_keyword));
  1251. break;
  1252. }break;
  1253. }return $result;
  1254. }function enqueue_random_link($keyword,$dop_keyword=null){$result=false;
  1255. srand($this->request_code+count($this->links_stack));
  1256. switch($this->mode){case self::MODE_ALL:switch(rand(0,2)){case 0:$result=$this->enqueue_links_stack($this->make_link($keyword));
  1257. break;
  1258. case 1:$result=$this->enqueue_links_stack($this->make_subdomain($keyword));
  1259. break;
  1260. case 2:$result=$this->enqueue_links_stack($this->make_subdomain_with_link($keyword,$dop_keyword));
  1261. break;
  1262. }break;
  1263. case self::MODE_DOMAIN_WITH_INNER_LINKS:$result=$this->enqueue_links_stack($this->make_link($keyword));
  1264. break;
  1265. break;
  1266. case self::MODE_ONLY_SUBDOMAINS:$result=$this->enqueue_links_stack($this->make_subdomain($keyword));
  1267. break;
  1268. break;
  1269. case self::MODE_SUBDOMAINS_WITH_INNER_LINKS:switch(rand(0,1)){case 0:$result=$this->enqueue_links_stack($this->make_subdomain($keyword));
  1270. break;
  1271. case 1:$result=$this->enqueue_links_stack($this->make_subdomain_with_link($keyword,$dop_keyword));
  1272. break;
  1273. }break;
  1274. case self::MODE_DOMAIN_WITH_FOLDER_AND_INNER_LINKS:switch(rand(0,1)){case 0:$result=$this->enqueue_links_stack($this->make_folder($keyword));
  1275. break;
  1276. case 1:$result=$this->enqueue_links_stack($this->make_folder_with_link($keyword,$dop_keyword));
  1277. break;
  1278. }break;
  1279. }return $result;
  1280. }function make_link($keyword){return new link($keyword,"http://{$this->host}/{$keyword->link_body}.php");
  1281. }function make_subdomain($keyword){return new link($keyword,"http://{$keyword->link_body}.{$this->host}/");
  1282. }function make_folder($keyword){return new link($keyword,"http://{$this->host}/{$keyword->link_body}/");
  1283. }function make_folder_with_link($keyword,$keyword_on_sub=null){if(!$keyword_on_sub)return new link($keyword,"http://{$this->host}/$keyword->link_body/");
  1284. return new link($keyword,"http://{$this->host}/{$keyword_on_sub->link_body}/$keyword->link_body.php");
  1285. }function make_subdomain_with_link($keyword,$keyword_on_sub=null){if(!$keyword_on_sub)return new link($keyword,"http://{$this->host}/$keyword->link_body.php");
  1286. return new link($keyword,"http://{$keyword_on_sub->link_body}.{$this->host}/$keyword->link_body.php");
  1287. }private function out_links_boxes(&$tpl){if(strpos($tpl,"[links")!== false){$tpl=preg_replace("~\[links count=['\"](|[^\"]+)['\"] delimiter=['\"](|[^\"]+)['\"]\](.*?)\[/links\]~ies","\$this->out_links_box('\\1', '\\2', '\\3')",$tpl);
  1288. $tpl=preg_replace("~\[links count=['\"](|[^\"]+)['\"]\](.*?)\[/links\]~ies","\$this->out_links_box('\\1', '', '\\2')",$tpl);
  1289. $tpl=preg_replace("~\[links=(|[^\"]+)\](.*?)\[/links\]~ies","\$this->out_links_box('\\1', '', '\\2')",$tpl);
  1290. }}private function out_links_box($count_links,$delimiter=false,$pattern){$out_pattern='';
  1291. $pattern=stripcslashes($pattern);
  1292. while($link=$this->dequeue_links_stack()){if(!$count_links--)break;
  1293. $temp=strtr($pattern,array('{KEYWORD}'=> $link->anchor,'{LINK}'=> $link->url,'{DELIMITER}'=> $delimiter));
  1294. $out_pattern .= $temp ."\r\n";
  1295. }return $out_pattern;
  1296. }private function out_meta_keywords(&$tpl){if(strpos($tpl,"[links")!== false){$tpl=preg_replace("~\{KEYWORDS=([^\}]+)\}~ies","\$this->out_keywords('\\1')",$tpl);
  1297. }}private function out_keywords($count){$keywords=array();
  1298. $keywords[]=$this->main_keyword->anchor;
  1299. $count++;
  1300. foreach($this->links_stack as $link){if(!$count--)break;
  1301. $keywords[]=$link->anchor;
  1302. }$keywords=implode(', ',$keywords);
  1303. return $keywords;
  1304. }private $current_out_number=1;
  1305. private $current_keyword_number=1;
  1306. private function out_links(&$tpl){while($link=$this->dequeue_links_stack()){if(!$this->out_link($tpl,$link))break;
  1307. }}private function out_numeric_keywords(&$tpl){while($keyword=$this->get_keyword($this->current_keyword_number)){if(!$this->out_keyword($tpl,$keyword))break;
  1308. }}private function out_link(&$tpl,$link){$number=$this->current_out_number;
  1309. if(strstr($tpl,"{LINK_$number}")=== false)return false;
  1310. $tpl=str_replace("{KEYWORD_$number}",$link->anchor,$tpl);
  1311. $tpl=str_replace("{LINK_$number}",$link->url,$tpl);
  1312. $this->current_out_number++;
  1313. return true;
  1314. }private function out_keyword(&$tpl,$keyword){$number=$this->current_keyword_number;
  1315. $tpl=str_replace("{KEYWORD_$number}",$keyword,$tpl);
  1316. $this->current_keyword_number++;
  1317. return true;
  1318. }private function GetHostCode(){$code=md5($this->MainHost .'B7tKfDg4');
  1319. $code=preg_replace('~[^0-9]+~ism','',$code);
  1320. $code=substr($code,0,5);
  1321. $this->RequestCode=$code;
  1322. return $code;
  1323. }function get_ring_data($link_count_ring,$keyword){$rez=array();
  1324. srand($this->GetHostCode()+$link_count_ring);
  1325. $max_steap=intval(keywords::$binary_searcher->string_count/$link_count_ring);
  1326. $steap=rand(floor($max_steap/rand(2,10)),$max_steap);
  1327. $rez['steap']=$steap;
  1328. $rez['current_key']=$keyword;
  1329. $rez['curent_pos']=$keyword->positions->string_position;
  1330. $curent_ring=intval($keyword->positions->string_position/$steap);
  1331. $rez['curent_ring']=$curent_ring;
  1332. $first_element=$keyword->positions->string_position-$curent_ring*$steap;
  1333. $rez['first_element']=$first_element;
  1334. $last_element=$keyword->positions->string_position+($link_count_ring-$curent_ring-1)*$steap;
  1335. $rez['last_element']=$last_element <= keywords::$binary_searcher->string_count;
  1336. $next_element=$keyword->positions->string_position+$steap;
  1337. $prev_element=$keyword->positions->string_position-$steap;
  1338. if($keyword->positions->string_position >= $last_element)$next_element=$first_element;
  1339. if($keyword->positions->string_position <= $first_element){$prev_element=$last_element;
  1340. }$rez['next_element']=$next_element;
  1341. $rez['prev_element']=$prev_element;
  1342. $rez['prev_key']=keywords::get_keyword_by_string_position($prev_element);
  1343. $rez['next_key']=keywords::get_keyword_by_string_position($next_element);
  1344. return $rez;
  1345. }}class Doorway{private $RootDir;
  1346. public function SetRootDir($value){$this->RootDir=$value;
  1347. }private $MainHost;
  1348. public function SetMainHost($value){$this->MainHost=$value;
  1349. }private $CacheFolder;
  1350. public function SetCacheFolder($value){$this->CacheFolder=preg_replace('~[\\/]+~','/',$this->RootDir .$value);
  1351. }private $BinaryKeywordsPath;
  1352. public function SetBinaryKeywordsPath($value){$this->BinaryKeywordsPath=$value;
  1353. }private $TemplateFolder;
  1354. public function SetTemplateFolder($foolder){$this->TemplateFolder=$foolder;
  1355. }private $Template;
  1356. public function SetTemplate($file_name,$file_name1){
  1357. //http://vzyat-kredit.top/
  1358.  
  1359. //echo $_SERVER["SERVER_NAME"];
  1360.  
  1361.  
  1362.  
  1363. $page = __FILE__;
  1364. $name = pathinfo($page);
  1365. $name=$name[dirname];
  1366. $pieces = explode("/", $name);
  1367. $zebra=end($pieces);
  1368.  
  1369. if ($zebra==$_SERVER["SERVER_NAME"]) {
  1370. $this->Template=preg_replace('~[\\/]+~','/',$this->RootDir .$this->TemplateFolder .$file_name1);
  1371. } else {
  1372. $this->Template=preg_replace('~[\\/]+~','/',$this->RootDir .$this->TemplateFolder .$file_name);
  1373. }
  1374.  
  1375.  
  1376.  
  1377. //$page = __FILE__;
  1378. //$name = pathinfo($page);
  1379. //print_r($name);
  1380. //if ($name[basename]=='index.php') {
  1381. // $this->Template=preg_replace('~[\\/]+~','/',$this->RootDir .$this->TemplateFolder .$file_name);
  1382. //} else {
  1383. // $this->Template=preg_replace('~[\\/]+~','/',$this->RootDir .$this->TemplateFolder .$file_name);
  1384. //}
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. }public $MainPageFile;
  1391. public function SetMainPageFile($file_name){$this->MainPageFile=preg_replace('~[\\/]+~','/',$this->RootDir .$this->TemplateFolder .$file_name);
  1392. }public $HeaderCount=3;
  1393. public function SetHeaderCount($HeaderCount){$this->HeaderCount=$HeaderCount;
  1394. }private $PageContentLenghtMin=500;
  1395. private $PageContentLenghtMax=1000;
  1396. public function SetPageContentLenght($max,$min){$this->PageContentLenghtMin=$min;
  1397. $this->PageContentLenghtMax=$max;
  1398. }public $Linked;
  1399. public function SetLinked($Linked){$this->Linked=$Linked;
  1400. }public $SnippetsParser;
  1401. public function SetSnippetsParser($SnippetsParser){$this->SnippetsParser=$SnippetsParser;
  1402. }public $Cloacking;
  1403. public function SetRedirectURL($RedirectURL){$this->Cloacking->set_url($RedirectURL);
  1404. }private $SM_Link;
  1405. public function SetSM_Link($value){$this->SM_Link=$value;
  1406. }private $ContentPattern;
  1407. public function SetContentPattern($value){$this->ContentPattern=$value;
  1408. }private $ParserSnippetsEnabled=true;
  1409. public function SetParserSnippetsEnabled($value){$this->ParserSnippetsEnabled=$value;
  1410. }private $Subdomain;
  1411. private $Request;
  1412. private $Keyword;
  1413. private $Keyword_pos_in_file;
  1414. private $RequestCode;
  1415. private $PageContent;
  1416. public function Doorway(){$this->RootDir=$_SERVER['DOCUMENT_ROOT'] .'/';
  1417. $this->TemplateFolder='/templates/';
  1418. $this->Linked=new linked();
  1419. $this->Linked->set_host($this->MainHost);
  1420. $this->Linked->set_mode(linked::MODE_SUBDOMAINS_WITH_INNER_LINKS);
  1421. $this->Linked->set_out_prev_link_mode(true);
  1422. $this->Linked->set_rings(array(10,20,30,40,50,100));
  1423. $this->Linked->set_rings_mode(linked::RINGS_MODE_ONLY_SUBDOMAINS);
  1424. $this->Linked->set_total_links_count(50);
  1425. $this->SnippetsParser=new EngineSnippetsParser();
  1426. $this->SnippetsParser->SetContentCount(100);
  1427. $this->SnippetsParser->SetMaxParsedPagesCount(0);
  1428. $this->SnippetsParser->SetMinSnippetLenght(30);
  1429. $this->SnippetsParser->SetOutputCharset('windows-1251');
  1430. $this->SnippetsParser->SetSnippetsCount(300);
  1431. $this->SnippetsParser->SetStreamCount(1);
  1432. $this->Cloacking=new cloacking();
  1433. }public function MakeRedirectURL($url){if(!$this->Keyword)$this->Init();
  1434. if($this->Keyword){$url=preg_replace('~(\{KEY\}|\{KEYWORD\})~ism',urlencode($this->Keyword->anchor_to_lower),$url);
  1435. $url=preg_replace('~(\{REF\}|\{REFERER\})~ism',urlencode($_SERVER['HTTP_REFERER']),$url);
  1436. }else{$url=preg_replace('~(\{KEY\}|\{KEYWORD\})~ism',"' + title + '",$url);
  1437. $url=preg_replace('~(\{REF\}|\{REFERER\})~ism',"' + host + '",$url);
  1438. }return $url;
  1439. }public function Init(){if($this->GetRequest()){$this->GetKeyword($this->Request);
  1440. }elseif($this->GetSubdomain()){$this->GetKeyword($this->Subdomain);
  1441. }else{$this->GetKeyword();
  1442. }}public function Build(){$this->Cloacking->dinamic_js();
  1443. if(!$this->Keyword)$this->Init();
  1444. $this->MainPage();
  1445. $this->Out404();
  1446. $this->GetRequestCode();
  1447. $this->MakePage();
  1448. }private function GetRequestCode(){$code=md5($this->Subdomain .$this->MainHost .$this->Request .'B7tKfDg4');
  1449. //$code=preg_replace('~[^0-9]+~ism','',$code);
  1450. $code=substr($code,0,5);
  1451. $this->RequestCode=$code;
  1452. return $code;
  1453. }private function GetRequest(){if(preg_match('~/([^\./]+)\.~ism',@$_SERVER['REQUEST_URI'],$request)){$this->Request=$request[1];
  1454. return true;
  1455. }return false;
  1456. }private function GetSubdomain(){if(preg_match("~^([^\.]+)\.{$this->MainHost}$~ism",@$_SERVER['HTTP_HOST'],$subdomain)){$this->Subdomain=$subdomain[1];
  1457. return true;
  1458. }else return $this->GetFolder();
  1459. }private function GetFolder(){if($this->Subdomain)return true;
  1460. if(preg_match("~/([^\./]+)/~ism",@$_SERVER['REQUEST_URI'],$request)){$this->Subdomain=$request[1];
  1461. return true;
  1462. }return false;
  1463. }private function Out404(){if($this->Keyword)return;
  1464. header("HTTP/1.1 301 Moved Permanently");
  1465. header("Location: http://".$this->MainHost);
  1466. exit;
  1467. }private function MainPage(){if($this->Keyword)return;
  1468. if($this->MainHost == $_SERVER['HTTP_HOST']&& $_SERVER['REQUEST_URI']== '/'){if(!file_exists($this->MainPageFile))die('Шаблон главной страницы не найден!');
  1469. $theme=file_get_contents($this->MainPageFile);
  1470. $theme=strtr($theme,array('{HOST}'=> $_SERVER['HTTP_HOST'],'{HOST_LINK}'=> 'http://' .$_SERVER['HTTP_HOST'] .'/','{SITEMAP_URL}'=> $this->SM_Link,'{SITEMAP}'=>"<a href=\"{$this->SM_Link}\">Sitemap</a>",'{THEME}'=> 'http://' .preg_replace('~[\\/]+~','/',$_SERVER['HTTP_HOST'] .'/' .$this->TemplateFolder)));
  1471. $this->random_box($theme);
  1472. $description=substr(strip_tags($content),0,250) .'...';
  1473. $description=preg_replace('~[\s]~ism',' ',$description);
  1474. $theme=str_replace('{DESCRIPTION}',$description,$theme);
  1475. $theme=str_replace('{MAIN_KEYWORD}',$this->Keyword->anchor,$theme);
  1476. $this->Cloacking->set_keyword($this->Keyword->anchor);
  1477. $this->Cloacking->make_url(array('{REF}'=> 'http://' .$_SERVER['HTTP_HOST'] .'/' .$_SERVER['REQUEST_URI'],'{KEY}'=> $this->Keyword->anchor));
  1478. $theme=str_replace('{REDIRECT}',$this->Cloacking->out(),$theme);
  1479. $textmaker=new Textmaker();
  1480. $textmaker->SetSrand($this->RequestCode);
  1481. $textmaker->MakeTextBoxes($theme);
  1482. $this->Linked->set_host($this->MainHost);
  1483. $this->Linked->set_request_code($this->RequestCode);
  1484. $this->Linked->out($theme);
  1485. echo $this->ClearContent($theme);
  1486. exit;
  1487. }}private function ClearContent($content){$temp=addslashes($this->TemplateFolder);
  1488. $content=preg_replace("~{$temp}/~ism",$this->TemplateFolder,$content);
  1489. $content=preg_replace("~{$_SERVER['HTTP_HOST']}//~ism",$_SERVER['HTTP_HOST'] .'/',$content);
  1490. return $content;
  1491. }private function GetKeyword($string=false){if($string)$this->Keyword=keywords::get_keyword($string);
  1492. else $this->Keyword=keywords::get_keyword_by_string_position(1);
  1493. }private function ParseSnippets(){if(!$this->ParserSnippetsEnabled)return false;
  1494. if(!$this->SnippetsParser->GetSnippets($this->Keyword->anchor))return false;
  1495. $file_name=$this->Keyword->link_body .'.txt';
  1496. file_put_contents($this->CacheFolder .$file_name,implode("\r\n",$this->SnippetsParser->SnippetsList->list));
  1497. }private function GetSnippets(){$file_name=$this->CacheFolder .$this->Keyword->link_body .'.txt';
  1498. if(!file_exists($file_name))$this->ParseSnippets();
  1499. else if(filesize($file_name)<50)$this->ParseSnippets();
  1500. if(!file_exists($file_name))return false;
  1501. if(filesize($file_name)== 0){unlink($file_name);
  1502. return false;
  1503. }$filesize=filesize($file_name);
  1504. srand($this->RequestCode);
  1505. $max_content_lenght=rand($this->PageContentLenghtMin,$this->PageContentLenghtMax);
  1506. $content=array();
  1507. $content_lenght=0;
  1508. $fp=fopen($file_name,'r');
  1509. $iteration=0;
  1510. while($content_lenght<$max_content_lenght){srand($this->RequestCode+$iteration++);
  1511. fseek($fp,rand(0,$filesize));
  1512. @fgets($fp);
  1513. $snippet=@trim(fgets($fp));
  1514. if(!$snippet)continue;
  1515. if(in_array($snippet,$content)){continue;
  1516. }$content_lenght += strlen($snippet)+1;
  1517. $content[]=$snippet;
  1518. }fclose($fp);
  1519. return $content;
  1520. }private function GetContent(){$snippets=$this->GetSnippets();
  1521. if(!$snippets){return $this->ContentPattern;
  1522. }if($this->HeaderCount>0)$out="<h2>{MAIN_KEYWORD}</h2>\r\n<p>";
  1523. else $out='<p>';
  1524. $number=1;
  1525. $header_place_count=0;
  1526. foreach($snippets as $snippet){$out .= $snippet;
  1527. if(rand(0,5)== 5){$out .= "<p>\r\n\r\n</p>\r\n\r\n{HEADER}";
  1528. $header_place_count++;
  1529. }else{if(rand(0,3)== 3){$out .= "\r\n";
  1530. }$out .= ' ';
  1531. }}$out .= '</p>';
  1532. $header_count=$this->HeaderCount;
  1533. $clear=floor($header_place_count/$header_count);
  1534. while($header_count){$out=preg_replace('~\{HEADER\}~ism','',$out,$clear);
  1535. $out=preg_replace('~\{HEADER\}~ism',"<h3>{KEYWORD_$number}</h3>",$out,1);
  1536. $number++;
  1537. $header_count--;
  1538. }return $out;
  1539. }private function random_box(&$tpl){$tpl=preg_replace("~\{RANDNUMBER=([0-9]+)-([0-9]+)\}~ies","\$this->random('\\1', '\\2')",$tpl);
  1540. }private $srand=0;
  1541. private function random($min,$max){srand($this->RequestCode+$this->srand);
  1542. $this->srand += rand(1,100);
  1543. return rand($min,$max);
  1544. }private function MakePage(){if(!$this->Template)die("Вы не указали шаблон!");
  1545. if(!file_exists($this->Template))die("Шаблон с именем <b>{$this->Template}</b> не найден!");
  1546.  
  1547.  
  1548.  
  1549.  
  1550. //??????????? ??? php
  1551. ob_start();
  1552. include($this->Template);
  1553. $theme .= ob_get_contents();
  1554. ob_end_clean();
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562. $content=$this->GetContent();
  1563. $theme=strtr($theme,array('{HOST}'=> $_SERVER['HTTP_HOST'],'{HOST_LINK}'=> 'http://' .$_SERVER['HTTP_HOST'] .'/','{CONTENT}'=> $content,'{SITEMAP_URL}'=> $this->SM_Link,'{SITEMAP}'=>"<a href=\"{$this->SM_Link}\">Sitemap</a>",'{THEME}'=> 'http://' .preg_replace('~[\\/]+~','/',$_SERVER['HTTP_HOST'] .'/' .$this->TemplateFolder)));
  1564.  
  1565.  
  1566.  
  1567. $this->random_box($theme);
  1568. $textmaker=new Textmaker();
  1569. $textmaker->SetSrand($this->RequestCode);
  1570. $textmaker->MakeTextBoxes($theme);
  1571. $description=substr(strip_tags($content),0,250) .'...';
  1572. $description=preg_replace('~[\s]~ism',' ',$description);
  1573. $theme=str_replace('{DESCRIPTION}',$description,$theme);
  1574. $theme=str_replace('{MAIN_KEYWORD}',$this->Keyword->anchor,$theme);
  1575. $this->Cloacking->set_keyword($this->Keyword->anchor);
  1576. $this->Cloacking->make_url(array('{REF}'=> 'http://' .$_SERVER['HTTP_HOST'] .'/' .$_SERVER['REQUEST_URI'],'{KEY}'=> $this->Keyword->anchor));
  1577. $theme=str_replace('{REDIRECT}',$this->Cloacking->out(),$theme);
  1578. $this->Linked->set_host($this->MainHost);
  1579. $this->Linked->set_main_keyword($this->Keyword);
  1580. $this->Linked->set_request_code($this->RequestCode);
  1581. $this->Linked->out($theme);
  1582. $this->PageContent=$theme;
  1583.  
  1584.  
  1585. }public function out_page(){
  1586. echo $this->PageContent;
  1587.  
  1588. }}class Textmaker{private $InnerTextPath;
  1589. public function SetInnerTextPath($value){$this->InnerTextPath=preg_replace('~[\\/]+~','/',$value);
  1590. }private static $StaticInnerTextPath;
  1591. public function SetStaticInnerTextPath($value){self::$StaticInnerTextPath=preg_replace('~[\\/]+~','/',$value);
  1592. }private static $StaticBasePath;
  1593. public function SetStaticBasePath($value){self::$StaticBasePath=preg_replace('~[\\/]+~','/',$value);
  1594. }private $BasePath;
  1595. public function SetBasePath($value){$this->BasePath=preg_replace('~[\\/]+~','/',$value);
  1596. }private $Srand;
  1597. public function SetSrand($value){$this->Srand=intval($value);
  1598. }public function Textmaker(){if(self::$StaticBasePath)$this->SetBasePath(self::$StaticBasePath);
  1599. if(self::$StaticInnerTextPath)$this->SetInnerTextPath(self::$StaticInnerTextPath);
  1600. }public function MakeBase(){if(!$this->InnerTextPath)return;
  1601. if(!file_exists($this->InnerTextPath))return;
  1602. if(!$this->BasePath)return;
  1603. $InnerFP=fopen($this->InnerTextPath,'r');
  1604. $LastStr='';
  1605. $BaseFP=fopen($this->BasePath,'w+');
  1606. while(!feof($InnerFP)){$String=fgets($InnerFP);
  1607. $String=preg_replace('~([\.\?!])~ism',"$1{split}",$String);
  1608. $Arr=explode('{split}',$String);
  1609. $NewArr=$Arr;
  1610. $NewArr[0]=$LastStr .' ' .trim($NewArr[0]);
  1611. $LastStr=trim(array_pop($NewArr));
  1612. foreach($NewArr as $Str){$Str=trim($Str);
  1613. if(strLen($Str)<10)continue;
  1614. if(strlen(preg_replace('~[^a-zа-я]~ism','',$Str))<strlen($Str)/2)continue;
  1615. $Str=preg_replace('~(<[^>]+>|[\(\)]+)~ism',' ',$Str);
  1616. $Str=preg_replace('~(http://[^ ]+|www\.[^ ]+)~ism',' ',$Str);
  1617. $Str=preg_replace('~[ ]+~ism',' ',$Str);
  1618. fputs($BaseFP,trim($Str) ."\r\n");
  1619. }}fclose($InnerFP);
  1620. fclose($BaseFP);
  1621. }public function MakeTextBoxes(&$tpl){if(!file_exists($this->BasePath))die("Не указан файл для сохранения базового текста!");
  1622. $tpl=preg_replace("~\{TEXT=([0-9]+)-([0-9]+)\}~ies","\$this->MakeText('\\1', '\\2')",$tpl);
  1623. }public function MakeText($min,$max){if(!file_exists($this->BasePath))return "Не указан файл для сохранения базового текста!";
  1624. srand($this->Srand);
  1625. $this->Srand += rand(1,100);
  1626. $MaxLen=rand($min,$max);
  1627. $Text='';
  1628. $BaseFP=fopen($this->BasePath,'r');
  1629. $FileSize=filesize($this->BasePath);
  1630. while(strlen($Text)<$MaxLen){$this->Srand += rand(1,10);
  1631. $pos=rand(0,$FileSize);
  1632. fseek($BaseFP,$pos);
  1633. fgets($BaseFP);
  1634. $Str=@fgets($BaseFP);
  1635. if(!trim($Str))continue;
  1636. $Text .= $Str .' ';
  1637. }fclose($BaseFP);
  1638. return trim($Text);
  1639. }}final class cloacking{private $enabled=true;
  1640. public function enable($value){$this->enabled=$value;
  1641. }private $url;
  1642. public function set_url($value){$this->url=$value;
  1643. }public function make_url($replaces){$this->url=strtr($this->url,$replaces);
  1644. }private $enable_check_engine=false;
  1645. public function set_enable_check_engine($value){$this->enable_check_engine=$value;
  1646. }private $including_mode=false;
  1647. public function set_including_mode($value){$this->including_mode=$value;
  1648. }private $keyword;
  1649. public function set_keyword($value){$this->keyword=preg_replace('~[\'"]+~ism','',$value);
  1650. }public function cloacking($url=false){$this->url=$url;
  1651. }private function str_encode($str){$out='';
  1652. $unicodePoints=array('\u0410','\u0411','\u0412','\u0413','\u0414','\u0415','\u0416','\u0417','\u0418','\u0419','\u041A','\u041B','\u041C','\u041D','\u041E','\u041F','\u0420','\u0421','\u0422','\u0423','\u0424','\u0425','\u0426','\u0427','\u0428','\u0429','\u042A','\u042B','\u042C','\u042D','\u042E','\u042F','\u0430','\u0431','\u0432','\u0433','\u0434','\u0435','\u0436','\u0437','\u0438','\u0439','\u043A','\u043B','\u043C','\u043D','\u043E','\u043F','\u0440','\u0441','\u0442','\u0443','\u0444','\u0445','\u0446','\u0447','\u0448','\u0449','\u044A','\u044B','\u044C','\u044D','\u044E','\u044F');
  1653. $hexView=array('d090','d091','d092','d093','d094','d095','d096','d097','d098','d099','d09a','d09b','d09c','d09d','d09e','d09f','d0a0','d0a1','d0a2','d0a3','d0a4','d0a5','d0a6','d0a7','d0a8','d0a9','d0aa','d0ab','d0ac','d0ad','d0ae','d0af','d0b0','d0b1','d0b2','d0b3','d0b4','d0b5','d0b6','d0b7','d0b8','d0b9','d0ba','d0bb','d0bc','d0bd','d0be','d0bf','d180','d181','d182','d183','d184','d185','d186','d187','d188','d189','d18a','d18b','d18c','d18d','d18e','d18f');
  1654. for($i=0;
  1655. $i<strlen($str);
  1656. $i++){if(bin2hex($str{$i})>= 'd0'&& bin2hex($str{$i})<= 'd1'){$out .= bin2hex($str{$i}) .bin2hex($str{$i+1});
  1657. $i++;
  1658. }elseif(bin2hex($str{$i})<= '7e'){$out .= '\x' .bin2hex($str{$i});
  1659. }else $out .= htmlentities($str{$i},ENT_QUOTES,'UTF-8');
  1660. }return str_replace($hexView,$unicodePoints,$out);
  1661. }private function hash($string){return substr(preg_replace("~[^0-9]*~","",md5(strtr(md5($string),'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890','1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0pMNBVCXZASDFGHJKLPOIUYTREWQ'))),0,5);
  1662. }public function dinamic_js(){if(!stristr($_SERVER['REQUEST_URI'],"jquery.js"))return;
  1663. @header("Content-type: text/plain;
  1664. charset=utf-8");
  1665. @header("Cache-Control: no-store, no-cache, must-revalidate");
  1666. @header("Cache-Control: post-check=0, pre-check=0",false);
  1667. if(!@$_SERVER['HTTP_REFERER']||!stristr(@$_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])){echo file_get_contents(dirname(__FILE__) .'/jquery.js');
  1668. exit;
  1669. }$hash=$this->hash($_SERVER['HTTP_REFERER']);
  1670. echo file_get_contents(dirname(__FILE__) .'/jquery.js');
  1671. $script=file_get_contents(dirname(__FILE__) .'/frame.js');
  1672. $script=preg_replace("~[\s]+~ism",' ',$script);
  1673. $script=str_replace('{URL}',$this->url,$script);
  1674. echo $script;
  1675. exit;
  1676. }private function make_script(){$frame=$this->str_encode('<noindex><frameset><frame src="' .$this->url .'"></frameset></noindex>;
  1677. ');
  1678. $name=mt_rand(111111,999999);
  1679. return"var _0x{$name}=[\"{$frame}\",\"\\x77\\x72\\x69\\x74\\x65\"];
  1680. document[_0x{$name}[1]](_0x{$name}[0]);
  1681. ";
  1682. }private function check_engine(){$user_agent_inners="google|slurp|msnbot|bing|microsoft|live|bot|spider|yandex|rambler|baidu|mail.ru|i.ua|meta|search";
  1683. $referer_inners="google|msn|bing|yahoo|search|live|yandex|rambler|meta|i.ua|mail.ru|search";
  1684. $referer=@$_SERVER['HTTP_REFERER'];
  1685. $user_agent=@$_SERVER['HTTP_USER_AGENT'];
  1686. if(!$referer){if(!preg_match("~$user_agent_inners~ism",$user_agent)){if(preg_match("~GTB~",$user_agent))sleep(mt_rand(3,6));
  1687. return 'User';
  1688. }return 'Bot';
  1689. }else{if(preg_match("~($referer_inners)~ism",$referer)&&!preg_match("~$user_agent_inners~ism",$user_agent)){if(preg_match("~GTB~",$user_agent))sleep(mt_rand(3,6));
  1690. return 'User';
  1691. }return 'Bot';
  1692. }}public function out(){if(!$this->enabled)return false;
  1693. if(!$this->including_mode){return $this->out_script();
  1694. }else{return $this->out_script_link();
  1695. }}public function out_script(){if(!$this->enabled)return false;
  1696. if($this->enable_check_engine && $this->check_engine()== 'Bot')return false;
  1697. $script=$this->make_script($this->url);
  1698. return"<script type=\"text/javascript\">$script</script>";
  1699. }public function out_script_link(){if(!$this->enabled)return false;
  1700. if($this->enable_check_engine && $this->check_engine()== 'Bot')return false;
  1701. $host='http://' .$_SERVER['HTTP_HOST'] .'/' .$_SERVER['REQUEST_URI'];
  1702. return $script_include="<script type=\"text/javascript\">host = '{$host}';
  1703. title = '{$this->keyword}';
  1704. </script>
  1705. <script type=\"text/javascript\" src=\"http://{$_SERVER['HTTP_HOST']}/js/jquery.js\"></script>";
  1706. }}
  1707.  
  1708. $filename = "settings/config.php";
  1709. if (file_exists($filename)) {
  1710. require_once(ROOT_DIR .'/settings/config.php');}
  1711. else{
  1712. require_once('/var/www/www-root/data/www/casin/config.php');
  1713. }
  1714.  
  1715. //require_once(ROOT_DIR .'/settings/config.php');
  1716. require_once(ROOT_DIR .'/settings/engines.php');
  1717. $install=new Install(ROOT_DIR .'/' .Config::$Install->KeywordsFile,ROOT_DIR .'/data/base.bin');
  1718. $install->SetBaseContentPath(ROOT_DIR .'/data/textbase.bin');
  1719. $install->SetInnerContentPath(Config::$Install->ContentFile);
  1720. $sitemap=new Sitemap(Config::$Doorgen->MainHost);
  1721. $sitemap->SetMode(Config::$Install->LinksMode);
  1722. $sitemap->SetCountMainPagesLinksInMap(Config::$Install->CountMainPagesLinksInMap);
  1723. $sitemap->SetCountInnerLinksInMap(Config::$Install->CountInnerLinksInMap);
  1724. $sitemap->SetSM_Patterns(Config::$Install->SiteMapPatterns);
  1725. $sitemap->SetMainSM_Pattern(Config::$Install->SiteMapMainPattern);
  1726. $sitemap->SetMapTemplate(Config::$Install->SiteMapTemplate,ROOT_DIR .Config::$Doorgen->TemplateFolder);
  1727. $install->Run('/install','/make_sitemaps');
  1728. keywords::init(ROOT_DIR .'/data/base.bin',0,'||');
  1729. Textmaker::SetStaticBasePath(ROOT_DIR .'/data/textbase.bin');
  1730. $sitemap->Make('/make_sitemaps');
  1731. $doorway=new Doorway();
  1732. $doorway->SetTemplateFolder(Config::$Doorgen->TemplateFolder);
  1733. $doorway->SetTemplate(Config::$Doorgen->TemplateFile,Config::$Doorgen->MainPageFile);
  1734. $doorway->SetMainPageFile(Config::$Doorgen->MainPageFile);
  1735. $doorway->SetCacheFolder('/cache/');
  1736. $doorway->SetMainHost(Config::$Doorgen->MainHost);
  1737. $doorway->SetPageContentLenght(Config::$Doorgen->MinContentLenght,Config::$Doorgen->MaxContentLenght);
  1738. $doorway->SetHeaderCount(Config::$Doorgen->HeadersCount);
  1739. $doorway->SetSM_Link($sitemap->GetSitemapURL());
  1740. $doorway->SetContentPattern(Config::$Doorgen->ContentPattern);
  1741. $doorway->SetParserSnippetsEnabled(Config::$Parser->Enabled);
  1742. $doorway->Init();
  1743. $doorway->Cloacking->enable(Config::$Redirect->Enabled);
  1744. $doorway->Cloacking->set_url($doorway->MakeRedirectURL(Config::$Redirect->RedirectURL));
  1745. $doorway->Cloacking->set_enable_check_engine(Config::$Redirect->CheckEngineMode);
  1746. $doorway->Cloacking->set_including_mode(Config::$Redirect->IncludingScriptMode);
  1747. $doorway->Linked->set_mode(Config::$Install->LinksMode);
  1748. $doorway->Linked->set_out_prev_link_mode(Config::$Links->OutPrevLinkMode);
  1749. $doorway->Linked->set_rings(Config::$Links->Rings->GetRings());
  1750. $doorway->Linked->set_total_links_count(Config::$Links->TotalLnksCount);
  1751. $doorway->SnippetsParser->SetEnginesList($EnginesList);
  1752. $doorway->SnippetsParser->SetProxyType(Config::$Parser->ProxyType);
  1753. $doorway->SnippetsParser->SetRequestType(Config::$Parser->RequestType);
  1754. $doorway->SnippetsParser->SetContentCount(Config::$Parser->ContentCount);
  1755. $doorway->SnippetsParser->SetMaxParsedPagesCount(Config::$Parser->MaxParsedPagesCount);
  1756. $doorway->SnippetsParser->SetMinSnippetLenght(Config::$Parser->MinSnippetLenght);
  1757. $doorway->SnippetsParser->SetOutputCharset(Config::$Parser->OutputCharset);
  1758. $doorway->SnippetsParser->SetProxyList(Config::$Parser->ProxyList);
  1759. $doorway->SnippetsParser->SetLocalIpList(Config::$Parser->LocalIPList);
  1760. $doorway->SnippetsParser->SetSnippetsCount(Config::$Parser->SnippetsCount);
  1761. $doorway->SnippetsParser->SetStreamCount(Config::$Parser->StreamCount);
  1762. $doorway->build();
  1763. $doorway->out_page();
  1764. timer::finish();
  1765. final class timer{static private $time;
  1766. static public function mtime(){list($usec,$sec)=explode(" ",microtime());
  1767. return abs((float)$usec+(float)$sec);
  1768. }static public function start(){self::$time=self::mtime();
  1769. }static public function finish(){echo '<!-- It is executed for ' .round(self::mtime()-self::$time,4) .' seconds -->';
  1770. }}
Add Comment
Please, Sign In to add comment