PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/linkchecker.php

https://gitlab.com/dkiller1/rapidleech
PHP | 234 lines | 196 code | 2 blank | 36 comment | 17 complexity | b111ef42e07a50b3f49e0a625a1af32e MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require('../deny.php');
  4. exit;
  5. }
  6. //Copyright Dman :p this has been coded by dman biatches!!!
  7. //Optimized by zpikdum :D
  8. //Moded by eqbal ;)
  9. //Lets calulate the time required.
  10. $time = explode(' ', microtime());
  11. $time = $time[1] + $time[0];
  12. $begintime = $time;
  13. //User Enabled settings
  14. $debug = 0; // change it to one to enable it.
  15. //Override PHP's stardard time limit
  16. set_time_limit(120);
  17. $maxlinks = 300;
  18. $lcver = 301;
  19. if ($options['fgc'] != 1 && !extension_loaded('curl')) $options['fgc'] = 1;
  20. //$options['fgc'] = 1;
  21. //Lets use this as a function to visit the site.
  22. function curl($link, $post = 0, $cookie = 0, $follow = 1, $refer = 0, $header = 1) {
  23. global $options, $debug;
  24. if ($follow && ($follow > 9 || $follow < 1)) $follow = 1;
  25. if ($post && is_array($post)) {
  26. $POST = '';
  27. foreach ($post as $k => $v) $POST .= "$k=$v&";
  28. $post = substr($POST, 0, -1);
  29. unset($POST);
  30. }
  31. if ($cookie && is_array($cookie)) {
  32. if (count($cookie) > 0) {
  33. $cookies = '';
  34. foreach ($cookie as $k => $v) $cookies .= "$k=$v; ";
  35. $cookie = substr($cookies, 0, -2);
  36. unset($cookies);
  37. } else $cookie = 0;
  38. }
  39. if($options['fgc'] == 1) {
  40. // Using file_get_contents.
  41. $opt = array(
  42. 'method' => ($post != 0) ? 'POST' : 'GET',
  43. 'content' => ($post != 0) ? $post : '',
  44. 'max_redirects' => (!$follow) ? 1 : $follow + 1,
  45. 'header' => "Accept-language: en-us;q=0.7,en;q=0.3\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, */*;q=0.1\r\n" .
  46. ($refer ? "Referer: $refer\r\n" : "") .
  47. ($cookie ? "Cookie: $cookie\r\n" : "") .
  48. "User-Agent: Opera/9.80 (Windows NT 6.1; U; en-US) Presto/2.10.289 Version/12.02\r\n"
  49. );
  50. $context = stream_context_create(array('http' => $opt));
  51. $page = @file_get_contents($link, false, $context);
  52. if ($header != 0) {
  53. $headers = implode("\r\n", $http_response_header);
  54. $page = $headers . "\r\n\r\n" . $page;
  55. }
  56. } else {
  57. // Using cURL.
  58. $ch = curl_init($link);
  59. curl_setopt($ch, CURLOPT_HEADER, $header);
  60. if($cookie) {
  61. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  62. curl_setopt($ch, CURLOPT_COOKIEJAR, "1");
  63. curl_setopt($ch, CURLOPT_COOKIEFILE, "1");
  64. }
  65. if($follow) {
  66. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  67. curl_setopt($ch, CURLOPT_MAXREDIRS, $follow+1);
  68. }
  69. curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 6.1; U; en-US) Presto/2.10.289 Version/12.02');
  70. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: text/html, application/xml;q=0.9, application/xhtml+xml, */*;q=0.1','Accept-Language: en-us;q=0.7,en;q=0.3'));
  71. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  72. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  73. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  74. if (!empty($refer)) {
  75. $arr = explode("\r\n", $refer);
  76. $header = array();
  77. if (count($arr) > 1) {
  78. $refer = $arr[0];
  79. unset($arr[0]);
  80. $header = array_filter(array_map('trim', $arr));
  81. }
  82. curl_setopt($ch, CURLOPT_REFERER, $refer);
  83. if (count($header) > 0) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  84. }
  85. if($post != '0') {
  86. curl_setopt($ch, CURLOPT_POST, 1);
  87. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  88. }
  89. $page = curl_exec($ch);
  90. $errz = curl_errno($ch);
  91. $errz2 = curl_error($ch);
  92. $info = curl_getinfo($ch);
  93. curl_close($ch);
  94. }
  95. //if ($debug == 1 && !empty($_POST['debug'])){
  96. if ($debug == 1) {
  97. $debugtxt = "Request: $link\n";
  98. if ($refer) $debugtxt .= "Referer: $refer\n";
  99. if ($cookie) $debugtxt .= "Cookie: $cookie\n";
  100. if (isset($errz) && $errz != 0) $debugtxt .= "cURL($errz): $errz2\n";
  101. if ($post) $debugtxt .= 'POST: '.print_r($post, true)."\n";
  102. $debugtxt .= "\n" . $page;
  103. textarea($debugtxt, 170, 15);
  104. }
  105. return($page);
  106. }
  107. function check(&$link, $x, $regex, $szregex='', $pattern='', $replace='', $opt = array()) {
  108. if(!empty($pattern)) $link = preg_replace($pattern, $replace, $link);
  109. $cook = $ref = $bytes = $fixsize = $size = 0;
  110. $fol = $head = 1;
  111. if(!empty($opt)) {
  112. if (array_key_exists('bytes', $opt)) $bytes = ($opt['bytes']) ? 1 : 0;
  113. if (array_key_exists('fixsize', $opt)) {
  114. $fixsize = ($opt['fixsize']) ? 1 : 0;
  115. $fixsizeP = $fixsizeR = '';
  116. if ($fixsize && array_key_exists('fixsizeP', $opt)) {
  117. $fixsizeP = $opt['fixsizeP'];
  118. if (array_key_exists('fixsizeR', $opt)) $fixsizeR = $opt['fixsizeR'];
  119. }
  120. }
  121. if (array_key_exists('cookie', $opt) && $opt['cookie'] != false) $cookie = $opt['cookie'];
  122. if (array_key_exists('follow', $opt)) $fol = $opt['follow'];
  123. if (array_key_exists('referer', $opt) && $opt['referer'] != false) $ref = $opt['referer'];
  124. if (array_key_exists('header', $opt)) $head = ($opt['header']) ? 1 : 0;
  125. }
  126. $page = curl($link, 0, $cookie, $fol, $ref, $head);
  127. $link = htmlentities($link, ENT_QUOTES);
  128. if (($szregex !== true && preg_match('@'.$regex.'@i', $page)) || ($szregex === true && preg_match('@'.$regex.'@i', $page, $fz))) {
  129. if (!empty($fz) || (!empty($szregex) && preg_match('@'.$szregex.'@i', $page, $fz))) {
  130. if (!array_key_exists('size', $fz)) $fz['size'] = $fz[1];
  131. if ($bytes) $size = bytesToKbOrMbOrGb($fz['size']);
  132. else if ($fixsize) {
  133. if (!array_key_exists('XB', $fz)) $fz['XB'] = $fz[2];
  134. $fz['XB'] = str_replace(array('YTES', 'YTE'), '', strtoupper($fz['XB']));
  135. if (!empty($fixsizeP)) $fz['size'] = str_replace($fixsizeP, $fixsizeR, $fz['size']);
  136. $fz['size'] = str_replace(',', '.', $fz['size']);
  137. switch ($fz['XB']) { // KbOrMbOrGbToBytes :D
  138. case 'GB': $fz['size'] *= 1024;
  139. case 'MB': $fz['size'] *= 1024;
  140. case 'KB': $fz['size'] *= 1024;
  141. }
  142. $size = bytesToKbOrMbOrGb($fz['size']);
  143. } else {
  144. if (!array_key_exists('XB', $fz)) $fz['XB'] = strtoupper($fz[2]);
  145. $fz['size'] = str_replace(',', '.', $fz['size']);
  146. $size = $fz['size'].' '.$fz['XB'];
  147. }
  148. $size = explode(' ', $size);
  149. $size[0] = round($size[0], 2);
  150. $size = implode(' ', $size);
  151. }
  152. $chk = showlink($link, $size);
  153. } elseif (empty($page) || preg_match('@class="bott_p_access2?"@i', $page)) $chk = showlink($link, 0, 2);
  154. else $chk = showlink($link, 0, 0);
  155. return array($chk, $size);
  156. }
  157. function showlink($link, $size='', $chk=1, $title='') {
  158. global $x;
  159. switch ($chk) {
  160. case 1:
  161. $cl = 'g';
  162. $ret = "<a class='$cl' title='".lang(114)."' href='$link'><b>$link</b></a>";
  163. if (!$_POST['d']) $ret = "$x: ".lang(114).": $ret";
  164. if (!empty($size)) $ret .= " | <span title='".lang(56)."'>$size</span>";
  165. break;
  166. case 2:
  167. $cl = 'y';
  168. $ret = "<a class='$cl' title='".lang(115)."' href='$link'><b>$link</b></a>";
  169. if (!$_POST['d']) $ret = "$x: ".lang(115).": $ret";
  170. break;
  171. case 3:
  172. $cl = 'b';
  173. $ret = "<a class='$cl' title='".htmlentities($title, ENT_QUOTES)."' href='$link'><b>$link</b></a>";
  174. break;
  175. case 4:
  176. $cl = 'y';
  177. $ret = "<b>$link&nbsp;???</b>";
  178. break;
  179. default:
  180. $cl = 'r';
  181. $ret = "<a class='$cl' title='".lang(116)."' href='$link'><b>$link</b></a>";
  182. if (!$_POST['d']) $ret = "$x: ".lang(116).": $ret";
  183. break;
  184. }
  185. $ret = "<div class='$cl' style='text-align:left;'".(!empty($title)?" title='".htmlentities($title, ENT_QUOTES)."'":'').">$ret</div>\n";
  186. echo $ret;
  187. return $chk;
  188. }
  189. // Load /classes/http.php or paste the function?...
  190. function GetCookiesArr($content, $cookie=array(), $del=true, $dval=array('','deleted')) {
  191. if (!is_array($cookie)) $cookie = array();
  192. if (($hpos = strpos($content, "\r\n\r\n")) > 0) $content = substr($content, 0, $hpos); // We need only the headers
  193. if (empty($content) || stripos($content, "\r\nSet-Cookie: ") === false || !preg_match_all ('/\r\nSet-Cookie: (.*)(;|\r\n)/U', $content, $temp)) return $cookie;
  194. foreach ($temp[1] as $v) {
  195. $v = explode('=', $v, 2);
  196. $cookie[$v[0]] = $v[1];
  197. if ($del) {
  198. if (!is_array($dval)) $dval = array($dval);
  199. if (in_array($v[1], $dval)) unset($cookie[$v[0]]);
  200. }
  201. }
  202. return $cookie;
  203. }
  204. function debug() {
  205. echo '<div style="text-align:left; margin:0 auto; width:450px;">';
  206. if ( !extension_loaded("curl") )
  207. echo lang(117)."<br />";
  208. else
  209. echo "<b>".lang(118)."</b><br />";
  210. if( PHP_VERSION < 5 ){
  211. echo lang(119)."<br />";
  212. }
  213. echo lang(120)."<br />";
  214. echo "</div>";
  215. }
  216. ?>