Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ********************************************************************************************************
- // * *
- // * down.php v0.1.4 (Released 13.02.2010) *
- // * by JeFFrey © 2007–2010 *
- // * всё очень сыро и хреново... *
- // * *
- // * http://gameart.110mb.com/ *
- // * *
- // ********************************************************************************************************
- // ********************************************************************************************************
- // Настройки
- // Все настройки описаны в файле "readme.txt"
- $host="www.ag.ru";
- $page="/stats/";
- $local_folder="";
- $log_file="";
- $crc="";
- $username="downphp";
- $password="setitfree";
- $send_cards=true;
- $save_to_subfolders=false;
- $time_for_sleep=0;
- $time_offset=0;
- // ********************************************************************************************************
- // директива, снимающая ограничение выполнения скрипта по времени
- ini_set("max_execution_time",0);
- // ********************************************************************************************************
- // Собственно скрипт
- if(!$l=@file($crc)) $l="";
- $time_offset=$time_offset*3600;
- $traffic=0;
- $init_time=time();
- $i=1;
- $downloaded=1;
- $host="http://".$host;
- if ($send_cards)
- {
- while (!$mw=file_get_contents("http://gameart.110mb.com/most_wanted.txt"));
- $mw=explode("\n",trim($mw));
- }
- // вызов процедуры входа в AG.ru по указанным логину и паролю
- if (($username=="") || !$out=ag_login($username,$password))
- $out="GET /stats/ HTTP/1.0\r\nAccept: */*\r\nHost: www.ag.ru\r\n\r\n";
- while (true)
- {
- do
- {
- do
- $s=read($page,$out);
- while (!$s || $s=="");
- $traffic+=strlen($s);
- $link=substr(strtok(strstr(strstr($s,"<!-- GameArt -->"),"src="),">"),4);
- }
- while($link=="");
- $link=$host.$link;
- parse_str(substr(strstr($link,"?"),1));
- $file=strrev(strtok(strrev($f),"/"));
- // Вывод в лог
- // закомментируйте любую строку, просто предварив ее двумя слешами (//), чтобы отключить вывод того или иного параметра
- // дата/время:
- $log="";
- $log.=date("d-m-Y H:i:s",time()+$time_offset).": ".strtok($file,".").str_repeat(" ",(23-strlen($file)));
- // параметры url:
- //$log.=$x." ";
- //$log.=$t." ";
- //$log.=$e." ";
- //$log.=$h." ";
- // израсходаванный трафик:
- $log.=str_repeat(" ",(5-strlen(strlen($s)))).strlen($s);
- $result="";
- echo($log);
- if ($link!=$host)
- {
- if (strstr($file,".jpg"))
- {
- if ($save_to_subfolders)
- {
- $subfolder=str_pad(strtok($file,"_"),4,"S",STR_PAD_LEFT)."\\";
- if (!file_exists($local_folder.$subfolder))
- mkdir($local_folder.$subfolder);
- }
- else
- {
- $subfolder="";
- }
- if (!file_exists($local_folder.$subfolder.$file))
- {
- $downloaded=0;
- if (!$downloaded)
- {
- if ($link!="http://www.ag.ru/")
- {
- $img=read_card($link,"GET ".$link." HTTP/1.0\r\nAccept: */*\r\nHost: www.ag.ru\r\n\r\n");
- $traffic+=strlen($img);
- $result="Downloaded"." ".strlen($img);
- echo(": ".$result);
- $f=fopen($local_folder.$subfolder.$file,"w");
- fwrite($f,$img);
- fclose($f);
- }
- }
- if (check($file,$img,$crc))
- $i++;
- else
- {
- if (strlen($img)>58)
- {
- if (strlen($img)<70000)
- {
- if (crc($file,$crc)!="")
- {
- $result=$result.": Wrong CRC ".dechex(crc32($img))." (must be ".strtolower(crc($file,$crc)).")";
- echo(": Wrong CRC ".dechex(crc32($img))." (must be ".crc($file,$crc).")");
- if (!file_exists($local_folder.$subfolder."Wrong CRC\\".$file))
- {
- rename($local_folder.$subfolder.$file,$local_folder.$subfolder."Wrong CRC\\".$file);
- }
- else
- {
- if (file_exists($local_folder.$subfolder.$file))
- {
- unlink($local_folder.$subfolder.$file);
- }
- }
- }
- else
- {
- if ($crc!="")
- {
- $result=$result.": Unknown file ".dechex(crc32($img));
- echo(": Unknown file ".dechex(crc32($img)));
- if (!file_exists($local_folder.$subfolder."Unknown files\\"))
- mkdir($local_folder.$subfolder."Unknown files\\");
- if (!file_exists($local_folder.$subfolder."Unknown files\\".$file))
- {
- if (file_exists($local_folder.$subfolder."Unknown files\\"))
- {
- rename($local_folder.$subfolder.$file,$local_folder.$subfolder."Unknown files\\".$file);
- }
- else
- {
- mkdir($local_folder.$subfolder."Unknown files");
- }
- }
- else
- {
- unlink($local_folder.$subfolder."Unknown files\\".$file);
- }
- }
- if ($send_cards)
- {
- $send=false;
- for ($i=0;$i<count($mw);$i++)
- {
- if ($mw[$i]."_"==strtok($file,"_")."_")
- {
- $send=true;
- break;
- }
- }
- if ($send && send_card($file,$img))
- echo(". Card Sended.");
- }
- }
- }
- else
- {
- $result="AG Index";
- echo(": ".$result);
- }
- }
- else
- {
- $result="Time expired";
- echo(": ".$result);
- }
- }
- }
- else
- {
- $result="Already got";
- echo(": ".$result);
- }
- }
- else
- {
- $result="Bad format";
- echo(": ".$result);
- }
- if ($log!="")
- write_log($log_file,$log.": ".$result."\n");
- if ($time_for_sleep>0)
- for ($sl=0;$sl<3;$sl+=1)
- {
- usleep($time_for_sleep/3*1000000);
- echo ".";
- }
- echo("\n");
- }
- }
- // ********************************************************************************************************
- // Функции, необходимые для работы скрипта
- // функция входа в AG по логину и паролю
- // лучше ничего не менять — а вот проверить на вшивость советую — мало ли, кто чего сюда дописал...
- function ag_login($username,$password)
- {
- function read_index($file)
- {
- $f=@fopen($file,"r");
- if (!$f)
- return false;
- else
- {
- $s="";
- while(!feof($f))
- {
- $line=fgets($f,1024);
- $s.=$line;
- if ((substr(strtok(strstr(strstr($s,"<INPUT type=hidden value=\"0\" name=is_javascript>"),"src="),">"),5)!="") || (!$line))
- break;
- }
- fclose($f);
- return($s);
- }
- }
- function get_h($s)
- {
- if ($s)
- {
- $t=substr($s,0,strpos($s,"\" name=h"));
- $t=substr($t,strlen($t)-32,32);
- return($t);
- }
- else
- return(false);
- }
- function get_time($s)
- {
- if ($s)
- {
- $t=substr($s,0,strpos($s,"\" name=time"));
- $t=substr($t,strlen($t)-strlen(time()),strlen(time()));
- return($t);
- }
- else
- return(false);
- }
- function get_ip($s)
- {
- if ($s)
- {
- $t=substr($s,0,strpos($s,"\" name=ip"));
- $t=substr($t,strlen($t)-32,32);
- return($t);
- }
- else
- return(false);
- }
- function get_header($out,$all)
- {
- while (!$fp=@fsockopen("www.ag.ru",80,$errno,$errstr,30));
- @fwrite($fp, $out);
- $s="";
- while (!feof($fp) && (!strpos($s,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">") || $all))
- $s.=fgets($fp,1454);
- fclose($fp);
- if (!$all)
- $s=substr($s,0,strpos($s,"\r\n\r\n"))."\r\n\r\n";
- return $s;
- }
- $s=read_index("http://www.ag.ru/stats/");
- $h=get_h($s);
- $ip=get_ip($s);
- $time=get_time($s);
- $act="login";
- $code="do_login";
- $action="http://ag.ru/post/";
- $p = md5($password);
- $p = md5($p.$h);
- $p = md5($p.$ip);
- $p = md5($p.$time);
- $passwrd = $p;
- $is_javascript="1";
- $cookieneverexp="1";
- $rp="http://www.ag.ru/stats/";
- $post='act='.$act."&";
- $post.='code='.$code."&";
- $post.='h='.$h."&";
- $post.='ip='.$ip."&";
- $post.='time='.$time."&";
- $post.='is_javascript='.$is_javascript."&";
- $post.='cookieneverexp='.$cookieneverexp."&";
- $post.='rp='.$rp."&";
- $post.='username='.$username."&";
- $post.='passwrd='.$passwrd;
- $s="";
- $out="POST /post/ HTTP/1.0\r\n";
- $out.="Accept: */*\r\n";
- $out.="Referer: http://www.ag.ru/stats/\r\n";
- $out.="Content-Type: application/x-www-form-urlencoded\r\n";
- $out.="Host: ag.ru\r\n";
- $out.="Content-Length: ".strlen($post)."\r\n";
- $out.="Connection: close\r\n\r\n";
- $out.=$post;
- do
- {
- $s=get_header($out,0);
- //echo "<code>".str_replace("\r\n","<br>\r\n",$out)."<br>\r\n<br>\r\n";
- //echo "<b>".str_replace("\r\n","<br>\r\n",$s)."</b></code><hr>";
- $c=0;
- $line=explode("\r\n",$s);
- $error=strtok(substr($line[0],9)," ");
- for ($i=0;$i<count($line);$i++)
- {
- if (strstr($line[$i],"Set-Cookie: "))
- {
- $cookie[$c]=substr($line[$i],12);
- $c++;
- }
- if (strstr($line[$i],"Location: "))
- {
- $location=substr($line[$i],10);
- $n=strpos($location,"/",8);
- $host=substr($location,7,$n-7);
- $dir=substr($location,$n);
- }
- else
- {
- $host="www.ag.ru";
- $dir="/stats/";
- }
- }
- $out="GET ".$dir." HTTP/1.0\r\n";
- $out.="Accept: */*\r\n";
- $out.="Host: ".$host."\r\n";
- for ($i=0;$i<count($cookie);$i++)
- {
- $out.="Cookie: ".$cookie[$i]."\r\n";
- }
- $out.="\r\n";
- $s=get_header($out,0);
- }
- while(!$cookie);
- $cookies=implode("",$cookie);
- $ag_con="1";
- $ag_name=$username;
- $ag_pass=substr($cookies,strpos($cookies,"ag_pass=")+8,32);
- $ag_last=substr($cookies,strpos($cookies,"ag_last=")+8,10);
- $ag_lp=substr($cookies,strpos($cookies,"ag_lp=")+6,10);
- $ag_lp_next="0";
- $out="GET /stats/ HTTP/1.0\r\n";
- $out.="Accept: */*\r\n";
- $out.="Host: www.ag.ru\r\n";
- $out.="Cookie: ag_con=$ag_con; ag_name=$ag_name; ag_pass=$ag_pass; ag_last=$ag_last; ag_lp_next=$ag_lp_next; ag_lp=$ag_lp\r\n";
- $out.="\r\n";
- return $out;
- }
- // логгинг
- function write_log($log_file,$s)
- {
- $f=fopen($log_file,"a");
- @fwrite($f,$s);
- }
- // поиск строки с CRC данной карточки в файле
- function crc($file,$crc)
- {
- if (file_exists($crc))
- {
- $f=file($crc);
- $i=0;
- while (($i<count($f)) && (strtolower(strtok($f[$i]," "))!=strtolower($file)))
- $i++;
- return substr(strtok(strstr(strtok($f[$i],"\r\n")," ")," "),0,8);
- }
- else
- return '';
- }
- // проверка CRC, хранящейся в файле с фактической
- function check($file,$img,$crc)
- {
- $r=true;
- $crc32=crc($file,$crc);
- if (hexdec(dechex(crc32($img)))!=hexdec($crc32))
- {
- $r=false;
- }
- return $r;
- }
- // загрузка карточки по ссылке
- function read_card($file,$out)
- {
- if ($out=="")
- {
- $f=@fopen($file,"r");
- if (!$f)
- {
- return false;
- }
- else
- {
- $s="";
- while(!feof($f))
- {
- $line=fgets($f,1024);
- $s.=$line;
- if ((substr(strtok(strstr(strstr($s,"<!-- GameArt -->"),"src="),">"),5)!="") || (!$line))
- {
- break;
- }
- }
- fclose($f);
- return $s;
- }
- }
- else
- {
- while (!$fp=@fsockopen("www.ag.ru", 80, $errno, $errstr, 30));
- $s="";
- $file=substr($file,strpos($file,"http://www.ag.ru")+16);
- fwrite($fp, $out);
- while (!feof($fp) && ($line=fgets($fp, 1454)))
- {
- $s.=$line;
- }
- fclose($fp);
- $s=substr($s,strpos($s,"\r\n\r\n")+4);
- return $s;
- }
- }
- // загрузка данных по ссылке
- function read($file,$out)
- {
- if ($out=="")
- {
- $f=@fopen($file,"r");
- if (!$f)
- {
- return false;
- }
- else
- {
- $s="";
- while(!feof($f))
- {
- $line=fgets($f,1024);
- $s.=$line;
- if ((substr(strtok(strstr(strstr($s,"<!-- GameArt -->"),"src="),">"),5)!="") || (!$line))
- {
- break;
- }
- }
- fclose($f);
- return $s;
- }
- }
- else
- {
- while (!$fp=@fsockopen("www.ag.ru", 80, $errno, $errstr, 30));
- $s="";
- fwrite($fp, $out);
- while (!feof($fp) && (substr(strtok(strstr(strstr($s,"<!-- GameArt -->"),"src="),">"),5)=="") && ($line=fgets($fp,1024)))
- {
- $s.=$line;
- }
- fclose($fp);
- $s=substr($s,strpos($s,"<html>"));
- return $s;
- }
- }
- // отправка карты в проект на gameart.110mb.com
- function send_card($filename,$s)
- {
- $host="gameart.110mb.com";
- $source="/upload.php";
- $boundary="----------f1MiuqE2SmFuSNu3FP0IHz";
- $post="--".$boundary."\r\n";
- $post.="Content-Disposition: form-data; name=\"userfile\"; filename=\"".$filename."\"\r\n";
- $post.="Content-Type: application/octet-stream\r\n\r\n";
- $post.=$s."\r\n";
- $post.="--".$boundary."--\r\n";
- $out="POST ".$source." HTTP/1.0\r\n";
- $out.="Accept: */*\r\n";
- $out.="Host: ".$host."\r\n";
- $out.="Connection: close\r\n";
- $out.="Content-Length: ".strlen($post)."\r\n";
- $out.="Content-Type: multipart/form-data; boundary=".$boundary."\r\n\r\n";
- $out.=$post;
- while (!$fp=@fsockopen($host,80,$errno,$errstr,30)) ;
- fwrite($fp, $out);
- $s.=fgets($fp,1);
- fclose($fp);
- return true;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement