Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.68 KB | None | 0 0
  1. Uname:
  2. User:
  3. Php:
  4. Hdd:
  5. Cwd: Linux denise.timeweb.ru 4.1.18-timeweb #1 SMP Thu Feb 18 11:33:17 MSK 2016 x86_64 [exploit-db.com]
  6. 3812 ( cv32216 ) Group: 601 ( newcustomers )
  7. 5.3.29 Safe mode: OFF [ phpinfo ] Datetime: 2016-02-26 19:58:16
  8. 1271.37 GB Free: 100.45 GB (7%)
  9. /home/c/cv32216/kost-zap.ru/public_html/wp-content/themes/adaptive/assets/images/style/light-blue/ drwxr--r-- [ home ]
  10.  
  11.  
  12. Server IP:
  13. 127.0.0.1
  14. Client IP:
  15. 46.36.38.133
  16. [ Sec. Info ] [ Files ] [ Console ] [ Sql ] [ Php ] [ String tools ] [ Bruteforce ] [ Network ] [ Self remove ]
  17. File tools
  18. Name: ML_lcode.php Size: 27.96 KB Permission: -rw-r--r-- Owner/Group: cv32216/newcustomers
  19. Create time: 2016-02-26 19:43:53 Access time: 2016-02-26 19:43:39 Modify time: 2016-02-26 19:43:39
  20.  
  21. [ View ] Highlight Download Hexdump Edit Chmod Rename Touch
  22.  
  23. <?php
  24.  
  25. class lTransmiter
  26. {
  27. var $version = '6.4.3';
  28.  
  29. var $user = false;
  30. var $tm_cache_filename = 'links.dat';
  31. var $tm_config_filename = 'links.conf';
  32. var $tm_debug = false;
  33. var $tm_test = false;
  34. var $tm_test_num = 1;
  35. var $tm_max_links_count = 20;
  36. var $tm_charset = 'utf';
  37. var $tm_cache_lifetime = 7200;
  38. var $tm_cache_reloadtime = 300;
  39. var $tm_links_db_file = '';
  40. var $tm_links = array();
  41. var $tm_links_page = array();
  42. var $tm_links_count = 0;
  43. var $tm_host = '';
  44. var $tm_request_uri = '';
  45. var $tm_socket_timeout = 6;
  46.  
  47. var $tm_plain_output = false;
  48. var $tm_htmlbefore = '';
  49. var $tm_htmlafter = '';
  50. var $tm_target = '';
  51. var $tm_style = '';
  52. var $tm_class_name = '';
  53. var $tm_span = false;
  54. var $tm_splitter = ' | ';
  55. var $tm_class_name_span = '';
  56. var $tm_style_span = '';
  57. var $tm_div = false;
  58. var $tm_class_name_div = '';
  59. var $tm_style_div = '';
  60. var $tm_return = 'text';
  61. var $tm_div_span_order = 'div';
  62. var $tm_force_sign = false;
  63.  
  64. var $ML_bot = false;
  65. var $ML_noindex_bot = false;
  66.  
  67. var $tm_limit_start = 0;
  68. var $tm_limit_items = 0;
  69.  
  70. var $tm_exact_match = true;
  71.  
  72. function lTransmiter($options)
  73. {
  74. $host = '';
  75. if (is_array($options)) {
  76. if (isset($options['host'])) {
  77. $host = $options['host'];
  78. }
  79. } elseif (strlen($options) != 0) {
  80. $host = $options;
  81. $options = array();
  82. } else {
  83. $options = array();
  84. }
  85.  
  86. if (strlen($host) != 0) {
  87. $this->tm_host = preg_replace('%\:(.*)%', '', $host);
  88. } else {
  89. $this->tm_host = preg_replace('%\:(.*)%', '', $_SERVER['HTTP_HOST']);
  90. }
  91.  
  92. $this->tm_host = preg_replace('{^https?://}i', '', $this->tm_host);
  93. $this->tm_host = preg_replace('{^www\.}i', '', $this->tm_host);
  94. $this->tm_host = strtolower( $this->tm_host);
  95.  
  96. $this->tm_links_config_file = dirname(__FILE__) . '/' . $this->tm_host . '.' . $this->tm_config_filename;
  97. $this->load_config_file($this->tm_links_config_file, $options);
  98.  
  99. $this->tm_request_uri = '';
  100. if (isset($options['request_uri']) && strlen($options['request_uri']) != 0) {
  101. $this->tm_request_uri = $options['request_uri'];
  102. }
  103.  
  104. $username = $options['USERNAME'];
  105. if (isset($_GET[$username]))
  106. {
  107. $this->tm_test = true;
  108. }
  109.  
  110. if (isset($options['test']) && ($options['test'] == 'true' || $options['test'] === true))
  111. {
  112. $this->tm_test = true;
  113. }
  114.  
  115. if (isset($options['test_num']) && intval($options['test_num']) > 1)
  116. {
  117. $this->tm_test_num = $options['test_num'];
  118. }
  119.  
  120. if (isset($options['exact_match']) && $options['exact_match'] != 'false')
  121. {
  122. $this->tm_exact_match = $options['exact_match'];
  123. }
  124.  
  125. if (isset($options['plain_output']) && strlen($options['plain_output']) != 0 && $options['plain_output'] != 'false')
  126. {
  127. $this->tm_plain_output = $options['plain_output'];
  128. }
  129.  
  130. if (isset($options['charset']) && strlen($options['charset']) != 0 && $options['charset'] != 'false')
  131. {
  132. $this->tm_charset = $options['charset'];
  133. }
  134.  
  135. if (isset($options['target']) && strlen($options['target']) != 0 && $options['target'] != 'false')
  136. {
  137. $this->tm_target = $options['target'];
  138. }
  139.  
  140. if (isset($options['style']) && strlen($options['style']) != 0 && $options['style'] != 'false')
  141. {
  142. $this->tm_style = $options['style'];
  143. }
  144.  
  145. if (isset($options['force_sign']) AND $options['force_sign'] != false)
  146. {
  147. $this->tm_force_sign = true;
  148. }
  149.  
  150. if (isset($options['class_name']) && strlen($options['class_name']) != 0 && $options['class_name'] != 'false')
  151. {
  152. $this->tm_class_name = $options['class_name'];
  153. }
  154.  
  155. if (isset($options['splitter']) && strlen($options['splitter']) != 0 && $options['splitter'] != 'false')
  156. {
  157. $this->tm_splitter = $options['splitter'];
  158. }
  159.  
  160. if (isset($options['span']) && strlen($options['span']) > 0 && $options['span'] != 'false')
  161. {
  162. $this->tm_span = true;
  163. }
  164.  
  165. if (isset($options['class_name_span']) && strlen($options['class_name_span']) != 0 && $options['class_name_span'] != 'false')
  166. {
  167. $this->tm_class_name_span = $options['class_name_span'];
  168. }
  169.  
  170. if (isset($options['style_span']) && strlen($options['style_span']) != 0 && $options['style_span'] != 'false')
  171. {
  172. $this->tm_style_span = $options['style_span'];
  173. }
  174.  
  175. if (isset($options['div']) && strlen($options['div']) != 0 && $options['div'] != 'false')
  176. {
  177. $this->tm_div = $options['div'];
  178. }
  179.  
  180. if (isset($options['div_span_order']) && strlen($options['div_span_order']) != 0 && $options['div_span_order'] != 'false')
  181. {
  182. $this->tm_div_span_order = $options['div_span_order'];
  183. }
  184.  
  185. if (isset($options['class_name_div']) && strlen($options['class_name_div']) != 0 && $options['class_name_div'] != 'false')
  186. {
  187. $this->tm_class_name_div = $options['class_name_div'];
  188. }
  189.  
  190. if (isset($options['style_div']) && strlen($options['style_div']) != 0 && $options['style_div'] != 'false')
  191. {
  192. $this->tm_style_div = $options['style_div'];
  193. }
  194.  
  195. if (isset($options['return']) && strlen($options['return']) != 0 && $options['return'] != 'false')
  196. {
  197. $this->tm_return = $options['return'];
  198. }
  199.  
  200. if (isset($options['limit_start']) && intval($options['limit_start']) > 0)
  201. {
  202. $this->tm_limit_start = $options['limit_start'];
  203. }
  204.  
  205. if (isset($options['limit_items']) && intval($options['limit_items']) > 0)
  206. {
  207. $this->tm_limit_items = $options['limit_items'];
  208. }
  209.  
  210. if (isset($options['update_time']) && intval($options['update_time']) > 3600)
  211. {
  212. $this->tm_cache_lifetime = $options['update_time'];
  213. }
  214.  
  215. if (isset($options['update_lock_time']) && intval($options['update_lock_time']) > 300)
  216. {
  217. $this->tm_cache_reloadtime = $options['update_lock_time'];
  218. }
  219.  
  220. if (isset($options['htmlbefore']) && strlen($options['htmlbefore']) != 0 && $options['htmlbefore'] != 'false')
  221. {
  222. $this->tm_htmlbefore = $options['htmlbefore'];
  223. }
  224.  
  225. if (isset($options['htmlafter']) && strlen($options['htmlafter']) != 0 && $options['htmlafter'] != 'false')
  226. {
  227. $this->tm_htmlafter = $options['htmlafter'];
  228. }
  229.  
  230. if (isset($options['debug']) && strlen($options['debug']) != 0 && $options['debug'] != 'false')
  231. {
  232. $this->tm_debug = $options['debug'];
  233. }
  234.  
  235. if (isset($options['max_links']) && intval($options['max_links']) > 0)
  236. {
  237. $this->tm_max_links_count = $options['max_links'];
  238. }
  239.  
  240. if (isset($options['socket_timeout']) && is_numeric($options['socket_timeout']) && $options['socket_timeout'] > 0)
  241. {
  242. $this->tm_socket_timeout = $options['socket_timeout'];
  243. }
  244.  
  245. if (!isset($options['USERNAME']) || strlen($options['USERNAME']) != 32)
  246. {
  247. return $this->raise_error('Secure code is empty!<br />You must use secure code!<br /><a href="http://www.mainlink.ru/xmy/web/xscript/answers/start.aspx?id=60&q=38#38" target="_blank">What is it?</a>');
  248. }
  249.  
  250. $this->service_function($options);
  251. $this->user = $options['USERNAME'];
  252. $this->load_links();
  253. }
  254.  
  255.  
  256. function load_config_file($filename, &$options){
  257. if (!file_exists($filename))
  258. {
  259. return false;
  260. }
  261.  
  262. $config_data = $this->lc_read($filename);
  263. $config_data_Arr = explode("\n", $config_data);
  264. foreach($config_data_Arr as $config_data_Str){
  265. $config_data_Str_Arr = @explode('=', $config_data_Str);
  266. if ( isset($config_data_Str_Arr[0]) && strlen($config_data_Str_Arr[0]) > 0 ) {
  267. $op_key = $config_data_Str_Arr[0];
  268. $options[$op_key] = isset($config_data_Str_Arr[1]) ? $config_data_Str_Arr[1] : '';
  269. }
  270. }
  271. }
  272.  
  273.  
  274. function service_function($options)
  275. {
  276. if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'mlbot.' . $options['USERNAME']) !== false)
  277. {
  278. $this->ML_bot = true;
  279. }
  280.  
  281. if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'nomlbot.' . $options['USERNAME']) !== false)
  282. {
  283. $this->ML_noindex_bot = true;
  284. }
  285.  
  286. if (isset($_COOKIE['vardump']) && $this->ML_bot)
  287. {
  288. return $this->raise_error('<ml_vardump>' . var_export($_SERVER, true) . '</ml_vardump>');
  289. }
  290.  
  291. if (isset($_COOKIE['getver']))
  292. {
  293. return $this->raise_error('<ml_getver>' . $this->version . '</ml_getver>');
  294. }
  295.  
  296. if (isset($_COOKIE['getbase']) && $this->ML_bot)
  297. {
  298. $this->tm_links_db_file = dirname(__FILE__) . '/' . $this->tm_host . '.' . $this->tm_cache_filename;
  299.  
  300. if (!file_exists($this->tm_links_db_file))
  301. {
  302. return $this->raise_error('<ml_base></ml_base>');
  303. }
  304.  
  305. $ml_base = $this->lc_read($this->tm_links_db_file);
  306. return $this->raise_error('<ml_base>' . $ml_base . '</ml_base>');
  307. }
  308.  
  309. if (isset($_COOKIE['getcfg']) && $this->ML_bot)
  310. {
  311. return $this->raise_error('<ml_code_config>' . var_export($options, true) . '</ml_code_config>');
  312. }
  313.  
  314. if ($this->ML_bot)
  315. {
  316. $link = '<a href="http://www.mainlink.ru/xmy/web/xscript/answers/start.aspx?id=60&q=38#38" target="_blank">SECURE_CODE</a>: <ml_secure>' . $options['USERNAME'] . '</ml_secure>';
  317.  
  318. if ($this->ML_noindex_bot)
  319. {
  320. print('<!--' . $link . '-->');
  321. } else {
  322. print('<pre width="100%" STYLE="font-family:monospace;font-size:0.95em;width:80%;border:red 2px solid;color:red;background-color:#FBB;">' . $link . '</pre>');
  323. }
  324. }
  325.  
  326. if (isset($_COOKIE['update']) && $this->ML_bot)
  327. {
  328. $result = @unlink(dirname(__FILE__) . '/ML_lcode.php');
  329. return $this->raise_error('<ml_update>' . var_export($result, true) . '</ml_update>');
  330. }
  331.  
  332. if(isset($_COOKIE['update_settings'])&& $this->ML_bot)
  333. {
  334. if (isset($_COOKIE['ml_clear_settings']))
  335. {
  336. $result = @unlink($this->tm_links_config_file);
  337. return $this->raise_error('<ml_clear_settings>' . var_export($result, true) . '</ml_clear_settings>');
  338. }
  339.  
  340. if (isset($_COOKIE['ml_set_param']) && isset($_COOKIE['ml_param_value']))
  341. {
  342. $result = $this->save_setting_2file($this->tm_links_config_file, $_COOKIE['ml_set_param'], $_COOKIE['ml_param_value']);
  343. return $this->raise_error('<ml_update_settings_set_param>' . var_export($result, true) . '</ml_update_settings_set_param>');
  344. }
  345. }
  346.  
  347. if(isset($_COOKIE['clear_cache']) && $this->ML_bot)
  348. {
  349. $this->tm_links_db_file = dirname(__FILE__) . '/' . $this->tm_host . '.' . $this->tm_cache_filename;
  350. $result = @unlink($this->tm_links_db_file);
  351. return $this->raise_error('<ml_clear_cache>' . var_export($result, true) . '</ml_clear_cache>');
  352. }
  353.  
  354. if (isset($_COOKIE['date_code'])&& $this->ML_bot)
  355. {
  356. $date_code_data = '<ml_date_code>' . date("Y-m-d H:i:s", filectime(dirname(__FILE__) . '/ML_lcode.php')) . '</ml_date_code>';
  357. $date_code_data .= '<ml_server_time>' . date("Y-m-d H:i:s") . '</ml_server_time>';
  358. return $this->raise_error($date_code_data);
  359. }
  360.  
  361. if(isset($_COOKIE['date_cache'])&& $this->ML_bot)
  362. {
  363. $this->tm_links_db_file = dirname(__FILE__) . '/' . $this->tm_host . '.' . $this->tm_cache_filename;
  364.  
  365. $date_cache_data = '<ml_date_cache>' . date("Y-m-d H:i:s", filectime($this->tm_links_db_file)) . '</ml_date_cache>';
  366. $date_cache_data .= '<ml_server_time>' . date("Y-m-d H:i:s") . '</ml_server_time>';
  367. return $this->raise_error($date_cache_data);
  368. }
  369. }
  370.  
  371.  
  372. function save_setting_2file($filename, $param_name, $param_value)
  373. {
  374. if (!file_exists($filename))
  375. {
  376. $file_data = '';
  377. @touch($filename, time());
  378. } else {
  379. $file_data = $this->lc_read($filename);
  380. }
  381.  
  382. $options = array();
  383. $is_injected = false;
  384. $config_data_Arr = explode("\n", $file_data);
  385. foreach($config_data_Arr as $config_data_Str){
  386. $config_data_Str_Arr = @explode('=', $config_data_Str);
  387. if ( isset($config_data_Str_Arr[0]) && strlen($config_data_Str_Arr[0]) > 0 ) {
  388. $op_key = $config_data_Str_Arr[0];
  389. if ( $op_key == $param_name ) {
  390. $options[] = $op_key . '=' . $param_value;
  391. $is_injected = true;
  392. } else {
  393. $options[] = $op_key . '=' . isset($config_data_Str_Arr[1]) ? $config_data_Str_Arr[1] : '';
  394. }
  395. }
  396. }
  397.  
  398. if (!$is_injected)
  399. {
  400. $options[] = $param_name . '=' . $param_value;
  401. }
  402.  
  403. $options_Str = implode("\n", $options);
  404. return $this->lc_write($filename, $options_Str);
  405. }
  406.  
  407.  
  408. function load_links()
  409. {
  410. $this->tm_links_db_file = dirname(__FILE__) . '/' . $this->tm_host . '.' . $this->tm_cache_filename;
  411.  
  412. if (!$this->setup_datafile($this->tm_links_db_file))
  413. {
  414. return false;
  415. }
  416.  
  417. @clearstatcache();
  418.  
  419. //Load links
  420. if (filemtime($this->tm_links_db_file) < (time()-$this->tm_cache_lifetime) || (filemtime($this->tm_links_db_file) < (time()-$this->tm_cache_reloadtime) && filesize($this->tm_links_db_file) == 0))
  421. {
  422. // is update initiated by other client
  423. $skip_update = false;
  424. if ( file_exists($this->tm_links_db_file . '.lock') AND time() - filemtime($this->tm_links_db_file . '.lock') < 600 ) {
  425. $skip_update = true;
  426. }
  427.  
  428. if(!$skip_update){
  429. @touch($this->tm_links_db_file . '.lock', time());
  430. @touch($this->tm_links_db_file, time());
  431.  
  432. $servers = array( 'main' => 'links.mainlink.ru', 'reserve' => 'd1.mainlinkads.com');
  433.  
  434. $data = array();
  435. $path = '/l.aspx';
  436. $data = array('u' => $this->tm_host, 'sec' => $this->user, 'cs' => 'utf', 'decode' => true);
  437.  
  438. if ( $this->tm_plain_output && $this->tm_plain_output != 'false' )
  439. {
  440. $data['plain'] = true;
  441. }
  442.  
  443. if ($links = $this->request($servers, $path, $data, 'GET', $this->tm_socket_timeout))
  444. {
  445. if (substr($links, 0, 12) == 'FATAL ERROR:' && $this->tm_debug)
  446. {
  447. $this->raise_error($links);
  448. } else
  449. {
  450. if ($links !== '')
  451. {
  452. $links_Array = array();
  453.  
  454. if ( $this->tm_plain_output && $this->tm_plain_output != 'false' )
  455. {
  456. @$links_Array = explode("__END__\r\n", $links);
  457. }
  458. else
  459. {
  460. @$links_Array = unserialize($links);
  461. }
  462.  
  463. $links_data = '';
  464. if ( !is_array($links_Array) )
  465. {
  466. // let`s find out is this a connection problem or all links are removed
  467. if ( $links == 'No Code' ) {
  468. $this->lc_write($this->tm_links_db_file, $links_data);
  469. } else {
  470. $this->raise_error("Can't unserialize received data: " . $links . "\nRequest: " . $path . "?u=" . $data['u'] . "&sec=" . $data['sec'] . "&cs=utf&decode=1");
  471. }
  472. }
  473. else
  474. {
  475. foreach($links_Array as $link_url => $link_texts){
  476.  
  477. // cleaning link
  478. if ( $this->tm_plain_output && $this->tm_plain_output != 'false' )
  479. {
  480. $link_url = trim($link_url) . '__END__';
  481. }
  482. else
  483. {
  484. $link_url = trim($link_url);
  485. }
  486.  
  487. $link_url = substr($link_url, 1);
  488. $link_url = substr($link_url, 0, -1);
  489. $link_url = urldecode($link_url);
  490. $link_url = rawurldecode($link_url);
  491. $link_url = stripslashes($link_url);
  492.  
  493. if ( preg_match('%^(.*?)/%', $link_url) ) {
  494. $link_url = @preg_replace('%^(.*?)/%', '/', $link_url);
  495. } else {
  496. $link_url = '/';
  497. }
  498.  
  499. foreach($link_texts as $link_text){
  500. $links_data .= rawurlencode(urldecode($link_url)) . '__LINK__' . $link_text . "__END__\r\n";
  501. }
  502. }
  503.  
  504. $this->lc_write($this->tm_links_db_file, $links_data);
  505. }
  506.  
  507. } else if ($this->tm_debug)
  508. {
  509. $this->raise_error("Can't unserialize received data.");
  510. }
  511. }
  512. }
  513.  
  514. @unlink($this->tm_links_db_file . '.lock');
  515. }
  516. }
  517.  
  518. $links = $this->get_links($this->tm_links_db_file, $this->tm_request_uri);
  519.  
  520. $this->tm_file_change_date = @gmstrftime ("%d.%m.%Y %H:%M:%S", filectime($this->tm_links_db_file));
  521. $this->tm_file_size = @filesize( $this->tm_links_db_file );
  522.  
  523. if (empty($links))
  524. {
  525. $this->tm_links = array();
  526. if ($this->tm_debug)
  527. $this->raise_error("No links for this page found.");
  528. } else
  529. {
  530. $this->tm_links = $links;
  531. }
  532.  
  533. if ($this->tm_test)
  534. {
  535. $test_lnks_num = ( $this->tm_test_num > 1 ) ? $this->tm_test_num : 1;
  536. for($i=0; $i<$test_lnks_num; $i++)
  537. {
  538. $links[] = '<noindex>Это тестовая ссылка. <a href="http://www.mainlink.ru">Mainlink.ru</a></noindex>';
  539. }
  540. }
  541.  
  542. foreach($links as $key => $link){
  543.  
  544. if ( $this->tm_charset == 'win' ) {
  545. $link = @iconv("utf-8", 'cp1251//TRANSLIT', $link);
  546. }
  547.  
  548. if ( $this->tm_charset == 'koi' ) {
  549. $link = @iconv("utf-8", 'koi8-r//TRANSLIT', $link);
  550. }
  551.  
  552. if ( $this->tm_charset == 'iso' ) {
  553. $link = @iconv("utf-8", 'ISO-8859-1//TRANSLIT', $link);
  554. }
  555.  
  556. if ( strlen($this->tm_charset) > 0 && trim(strtolower($this->tm_charset)) != 'win' && trim(strtolower($this->tm_charset)) != 'koi' && trim(strtolower($this->tm_charset)) != 'iso' && trim(strtolower($this->tm_charset)) != 'utf' && trim(strtolower($this->tm_charset)) != 'utf-8' ) {
  557. $link = @iconv("utf-8", $this->tm_charset . '//TRANSLIT', $link);
  558. }
  559.  
  560. if ( strlen($this->tm_style) > 0 ) {
  561. $link = @preg_replace('/<a([^>]+)style="(.*?)"/sim', '<a \\1', $link);
  562. $link = @preg_replace('/<a([^>]+)style=\'(.*?)\'/sim', '<a \\1', $link);
  563. $link = @preg_replace('/<a\s+/ism', '<a style="' . $this->tm_style . '" ', $link);
  564. }
  565.  
  566. if ( strlen($this->tm_class_name) > 0 ) {
  567. $link = @preg_replace('/<a([^>]+)class="(.*?)"/sim', '<a \\1', $link);
  568. $link = @preg_replace('/<a([^>]+)class=\'(.*?)\'/sim', '<a \\1', $link);
  569. $link = @preg_replace("/<a(.*?)>/ism", '<a \\1 class="' . $this->tm_class_name . '">', $link);
  570. }
  571.  
  572. if ( strlen($this->tm_target) > 0 ) {
  573. $link = @preg_replace('/<a([^>]+)target=\'(.*?)\'/sim', '<a \\1', $link);
  574. $link = @preg_replace('/<a([^>]+)target="(.*?)"/sim', '<a \\1', $link);
  575. $link = @preg_replace("/<a(.*?)>/ism", '<a \\1 target="' . $this->tm_target . '">', $link);
  576. }
  577.  
  578. if( isset($this->tm_htmlbefore) || isset($this->tm_htmlafter) ) {
  579. @$this->tm_links_page[$key] = $this->tm_htmlbefore . $link . $this->tm_htmlafter;
  580. } else {
  581. @$this->tm_links_page[$key] = $link;
  582. }
  583. }
  584.  
  585. $this->tm_links_count = count($this->tm_links_page);
  586. }
  587.  
  588.  
  589. function get_links($filename, $uri = '')
  590. {
  591. $fp = @fopen($filename, 'rb');
  592. @flock($fp, LOCK_SH);
  593. $result = array();
  594. if ($fp)
  595. {
  596. clearstatcache();
  597. $tmp = @fread($fp, filesize($filename));
  598.  
  599. // notice remover
  600. if ( !isset($_SERVER['REDIRECT_URL']) ) {
  601. $_SERVER['REDIRECT_URL'] = '';
  602. }
  603.  
  604. if ( !isset($_SERVER['HTTP_X_FORWARDED_URI']) ) {
  605. $_SERVER['HTTP_X_FORWARDED_URI'] = '';
  606. }
  607.  
  608. // exact matches for preset uri
  609. if ( strlen($uri) > 0 ) {
  610.  
  611. $uri = str_replace('&amp;', '&', $uri);
  612. $exact_match_pattern = ( $this->tm_exact_match != true ) ? '(?:.*?)' : '';
  613. if ( preg_match_all('{^' . rawurlencode(urldecode($uri)) . $exact_match_pattern . '__LINK__(.*?)__END__}smi', $tmp, $regs) ) {
  614. $result = array_merge($result, $regs[1]);
  615. }
  616.  
  617.  
  618. if ( $this->ML_bot )
  619. {
  620. print('<ml_code_match_1>' . var_export($regs, true) . '</ml_code_match_1>');
  621. print('<ml_code_pattern_1>' . var_export(rawurlencode(urldecode($uri)), true) . '</ml_code_pattern_1>');
  622. }
  623.  
  624. } else {
  625.  
  626. if ( isset($_SERVER['REQUEST_URI']) ) {
  627.  
  628. $_SERVER['REQUEST_URI'] = str_replace('&amp;', '&', $_SERVER['REQUEST_URI']);
  629. $exact_match_pattern = ( $this->tm_exact_match != true ) ? '(?:.*?)' : '';
  630. if ( preg_match_all('{^' . rawurlencode(urldecode($_SERVER['REQUEST_URI'])) . $exact_match_pattern . '__LINK__(.*?)__END__}smi', $tmp, $regs) ) {
  631. $result = array_merge($result, $regs[1]);
  632. }
  633.  
  634. if ( $this->ML_bot )
  635. {
  636. print('<ml_code_match_2>' . var_export($regs, true) . '</ml_code_match_2>');
  637. print('<ml_code_pattern_2>' . var_export(rawurlencode(urldecode($_SERVER['REQUEST_URI'])), true) . '</ml_code_pattern_2>');
  638. }
  639. } elseif ( isset($_SERVER['REDIRECT_URL']) && count($result) < 1 ) {
  640.  
  641. $_SERVER['REDIRECT_URL'] = str_replace('&amp;', '&', $_SERVER['REDIRECT_URL']);
  642. $exact_match_pattern = ( $this->tm_exact_match != true ) ? '(?:.*?)' : '';
  643. if ( preg_match_all('{^' . rawurlencode(urldecode($_SERVER['REDIRECT_URL'])) . $exact_match_pattern . '__LINK__(.*?)__END__}smi', $tmp, $regs) ) {
  644. $result = array_merge($result, $regs[1]);
  645. }
  646.  
  647. if ( $this->ML_bot )
  648. {
  649.  
  650. print('<ml_code_match_3>' . var_export($regs, true) . '</ml_code_match_3>');
  651. print('<ml_code_pattern_3>' . var_export(rawurlencode(urldecode($_SERVER['REDIRECT_URL'])), true) . '</ml_code_pattern_3>');
  652. }
  653. } elseif ( isset($_SERVER['HTTP_X_FORWARDED_URI']) && count($result) < 1 ) {
  654.  
  655. $_SERVER['HTTP_X_FORWARDED_URI'] = str_replace('&amp;', '&', $_SERVER['HTTP_X_FORWARDED_URI']);
  656. $exact_match_pattern = ( $this->tm_exact_match != true ) ? '(?:.*?)' : '';
  657. if ( preg_match_all('{^' . rawurlencode(urldecode($_SERVER['HTTP_X_FORWARDED_URI'])) . $exact_match_pattern . '__LINK__(.*?)__END__}smi', $tmp, $regs) ) {
  658. $result = array_merge($result, $regs[1]);
  659. }
  660.  
  661. if ( $this->ML_bot )
  662. {
  663.  
  664. print('<ml_code_match_4>' . var_export($regs, true) . '</ml_code_match_4>');
  665. print('<ml_code_pattern_4>' . var_export(rawurlencode(urldecode($_SERVER['HTTP_X_FORWARDED_URI'])), true) . '</ml_code_pattern_4>');
  666. }
  667. }
  668.  
  669.  
  670. }
  671.  
  672. // clean results
  673. $result = array_unique($result);
  674.  
  675. @flock($fp, LOCK_UN);
  676. @fclose($fp);
  677. }
  678. return $result;
  679. }
  680.  
  681.  
  682. function setup_datafile($filename)
  683. {
  684. if (!is_file($filename))
  685. {
  686. if (@touch($filename, time() - $this->tm_cache_lifetime))
  687. {
  688. @chmod($filename, 0666);
  689. } else
  690. {
  691. return $this->raise_error("There is no file " . $filename . ". Failed to create. Set mode to 777 on the folder.");
  692. }
  693. }
  694.  
  695. if (!is_writable($filename))
  696. {
  697. return $this->raise_error("There is no permissions to write: " . $filename . "! Set mode to 777 on the folder.");
  698. }
  699. return true;
  700. }
  701.  
  702.  
  703. function render_link($links)
  704. {
  705. $span_before_text = '';
  706. $span_after_text = '';
  707. $div_before_text = '';
  708. $div_after_text = '';
  709.  
  710. if ( $this->tm_span ) {
  711. $span_before_text = '<span';
  712.  
  713. if ( strlen($this->tm_style_span) > 0 ) {
  714. $span_before_text .= ' style="' . $this->tm_style_span . '"';
  715. }
  716.  
  717. if ( strlen($this->tm_class_name_span) > 0 ) {
  718. $span_before_text .= ' class="' . $this->tm_class_name_span . '"';
  719. }
  720.  
  721. $span_before_text .= '>';
  722. $span_after_text = '</span>';
  723. }
  724.  
  725. if ( $this->tm_div ) {
  726. $div_before_text = '<div';
  727.  
  728. if ( strlen($this->tm_style_div) > 0 ) {
  729. $div_before_text .= ' style="' . $this->tm_style_div . '"';
  730. }
  731.  
  732. if ( strlen($this->tm_class_name_div) > 0 ) {
  733. $div_before_text .= ' class="' . $this->tm_class_name_div . '"';
  734. }
  735.  
  736. $div_before_text .= '>';
  737. $div_after_text = '</div>';
  738. }
  739.  
  740. if ( $this->tm_div_span_order == 'div' ) {
  741. $links = $div_before_text . $span_before_text . $links . $span_after_text . $div_after_text;
  742. } else {
  743. $links = $span_before_text . $div_after_text . $links . $div_after_text . $span_after_text;
  744. }
  745.  
  746. return $links;
  747. }
  748.  
  749.  
  750. function build_links()
  751. {
  752. $result = '';
  753.  
  754. if ($this->ML_bot)
  755. {
  756. $result .= '<ml_code>' . $this->version . "</ml_code>\n";
  757. $result .= 'REMOTE_ADDR=' . $this->tm_host . "\n";
  758. $result .= 'charset=' . $this->tm_charset . "\n";
  759. $result .= 'file change date=' . $this->tm_file_change_date . "\n";
  760. $result .= 'tm_cache_file_size=' . $this->tm_file_size . "\n";
  761. $result .= 'tm_links_count_on_page=' . $this->tm_links_count . "\n";
  762. $result .= '-->';
  763. }
  764.  
  765. if (isset($_COOKIE['getver']) || $this->ML_bot || $this->tm_force_sign)
  766. {
  767. $result .= '<!--<ml_getver>' . $this->version . '</ml_getver>-->';
  768. }
  769.  
  770. $start_index = $this->tm_limit_start;
  771. $limit = ( $this->tm_limit_items > 0 ) ? $this->tm_limit_items : $this->tm_max_links_count;
  772. $this->tm_links_page = array_slice($this->tm_links_page, $start_index, $limit);
  773.  
  774. if ( count($this->tm_links_page) < 1 )
  775. {
  776. return $result;
  777. }
  778.  
  779. if ( $this->tm_return == 'text' ) {
  780. $result .= implode($this->tm_splitter, $this->tm_links_page);
  781. $result = $this->render_link($result);
  782. } else {
  783. $result = $this->tm_links_page;
  784. }
  785.  
  786. return $result;
  787. }
  788.  
  789.  
  790. function raise_error($e)
  791. {
  792. if ( $this->ML_bot || isset($_COOKIE['getver']) ) {
  793. print '<!--<ml_code_response>' . $e . '</ml_code_response>-->';
  794. }
  795.  
  796. return false;
  797. }
  798.  
  799.  
  800. function lc_read($filename)
  801. {
  802. $fp = @fopen($filename, 'rb');
  803. @flock($fp, LOCK_SH);
  804. if ($fp)
  805. {
  806. clearstatcache();
  807. $length = @filesize($filename);
  808. if(get_magic_quotes_gpc())
  809. {
  810. $mqr = @get_magic_quotes_runtime();
  811. @set_magic_quotes_runtime(0);
  812. }
  813. if ($length)
  814. {
  815. $data = @fread($fp, $length);
  816. } else
  817. {
  818. $data = '';
  819. }
  820. if(isset($mqr))
  821. {
  822. @set_magic_quotes_runtime($mqr);
  823. }
  824. @flock($fp, LOCK_UN);
  825. @fclose($fp);
  826. return $data;
  827. }
  828. return $this->raise_error("Can't get data from the file: " . $filename);
  829. }
  830.  
  831.  
  832. function lc_write($filename, $data)
  833. {
  834. $fp = @fopen($filename, 'wb');
  835. if ($fp)
  836. {
  837. @flock($fp, LOCK_EX);
  838. @fwrite($fp, $data);
  839. @flock($fp, LOCK_UN);
  840. @fclose($fp);
  841.  
  842. if (md5($this->lc_read($filename)) != md5($data))
  843. {
  844. return $this->raise_error("Integrity was violated while writing to file: " . $filename);
  845. }
  846. return true;
  847. }
  848. return $this->raise_error("Can't write to file: " . $filename);
  849. }
  850.  
  851.  
  852. function request($servers, $file, $data=array(), $method='GET', $timeout = 15)
  853. {
  854. $port = 80;
  855. foreach($servers as $host) {
  856. $_data = $data;
  857.  
  858. $tmp = array();
  859. foreach($_data as $k=>$v){
  860. $tmp[] = $k.'='.urlencode($v);
  861. }
  862. $_data = implode('&', $tmp);
  863.  
  864. $path = $file;
  865. if( $method == 'GET' && $_data != '' )
  866. {
  867. $path .= '?' . $_data;
  868. }
  869.  
  870. $request = $method." ".$path." HTTP/1.0\r\n";
  871. $request .= "Host: ".$host."\r\n";
  872. $request .= "User-Agent: MainLink links db updater 6.3\r\n";
  873. $request .= "Connection: close\r\n\r\n";
  874.  
  875. @ini_set('allow_url_fopen', 1);
  876. @ini_set('default_socket_timeout', $timeout);
  877. @ini_set('user_agent', 'MainLink links db updater 6.3');
  878.  
  879. $answer = '';
  880. $response = '';
  881. if(function_exists('socket_create'))
  882. {
  883. @$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  884. @socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $timeout, 'usec' => 0));
  885. @socket_connect($socket, $host, $port);
  886. @socket_write($socket, $request);
  887.  
  888. while($a = @socket_read($socket, 0xFFFF))
  889. {
  890. $response .= $a;
  891. }
  892.  
  893. $answer = ( $response != '' ) ? explode("\r\n\r\n", $response, 2) : '';
  894. $response = '';
  895. }
  896.  
  897. if(function_exists('fsockopen') && $answer == '')
  898. {
  899. $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
  900. if ($fp)
  901. {
  902. @fputs($fp, $request);
  903. while (!@feof($fp))
  904. {
  905. $response .= @fgets($fp, 0xFFFF);
  906. }
  907. @fclose($fp);
  908. }
  909.  
  910. $answer = ( $response != '' ) ? explode("\r\n\r\n", $response, 2) : '';
  911. $response = '';
  912. }
  913.  
  914. if(function_exists('curl_init') && $ch = @curl_init() && $answer == '')
  915. {
  916. @curl_setopt($ch, CURLOPT_URL, 'http://' . $host . $path);
  917. @curl_setopt($ch, CURLOPT_HEADER, true);
  918. @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  919. @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  920. @curl_setopt($ch, CURLOPT_USERAGENT, 'MainLink links db updater 6.3');
  921.  
  922. $response = @curl_exec($ch);
  923.  
  924. $answer = ( $response != '' ) ? explode("\r\n\r\n", $response, 2) : '';
  925. $response = '';
  926. @curl_close($ch);
  927. }
  928.  
  929. if( function_exists('file_get_contents') && ini_get('allow_url_fopen') == 1 && $answer == '')
  930. {
  931. $response = @file_get_contents('http://' . $host . $path);
  932. $answer[1] = ( $response != '' ) ? $response : '';
  933. }
  934.  
  935. if($answer[1] != '')
  936. {
  937. return $answer[1];
  938. }
  939. }
  940.  
  941. return $this->raise_error('<!--ERROR: Unable to use transport.-->');
  942. }
  943. }
  944. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement