<?php
  if(isset($_POST['link']))
  { set_time_limit(3600*30); 
ini_set('display_errors','Off'); 
error_reporting(0);
   require_once('pclzip.lib.php');
   $serv_path = str_replace("\\","/",dirname(__FILE__));  
   $links =  preg_split('%[\s]+%',rtrim($_POST['link'])); 
   $dir_name =  preg_split('%[\s]+%',rtrim($_POST['dir_name'])); 
   $rand_start =  preg_split('%[\s]+%',rtrim($_POST['start'])); 
   $rand_end=  preg_split('%[\s]+%',rtrim($_POST['end'])); 
    if($_POST['key']!=null) $k = $_POST['key'];else $k=1;
print '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset =windows-1251" /></head><body>';$url_links = '';$url_img_links = '';
    for($p=0;$p<count($links);$p++)
    {
      if(!is_dir($serv_path.'/files/'.$dir_name[$p])){     
       mkdir($serv_path.'/files/'.$dir_name[$p]);
     chmod($serv_path.'/files/'.$dir_name[$p],0777);};
     $c_p = substr_count($links[$p],'$');  			
          for($i=$rand_start[$p],$ks=0;$i<= $rand_end[$p];$ks++)
     if($c_p == 1) {print str_replace('$',$i,$links[$p]).'<br>';$i+=$k;}
     elseif($c_p == 2) {
                                  if($i%10==0)$j='0';else $j='';if($i==0) $j='.00'; $el = substr(($i/100).$j,2,2);
                                  $r  = str_replace('$$',$el,$links[$p]);
                                   $str = strrev($r);
                                   $str = strrev(substr($str,0,stripos($str,'/')));   
                                  if(!file_exists($serv_path."/files/".$dir_name[$p].'/'.$str)){
                                  $url = parse_url($r);  
                                    $opts = array('http' => array('method'=>"GET",'header'=>
                                    "Host: ".$url['host']."\r\n".
                                   "Referer: ".$url['protocol'].$url['host'].$url['path']."\r\n".
                                   "Accept-language: en\r\n".
                                   'Cookie: '.$_POST['cokies']."\r\n".
                                   "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 4.0.20506)\r\n"
                                    ));
                                   if(trim($_POST['user'])!=''&&trim($_POST['pass'])!='')
                                        $opts['http']['header'].="Authorization: Basic " . base64_encode($_POST['user'].":".$_POST['pass']).'\r\n';
                                    if(trim($_POST['proxy'])!=''){
                                     $opts['http']['proxy'] = 'tcp://'.$_POST['proxy'];
                                     $opts['http']['request_fulluri'] = true;
                                    }
                                   if(trim($_POST['proxy_user'])!=''&&trim($_POST['proxy_pass'])!='')
                                        $opts['http']['header'].="Proxy-Authorization: Basic " . base64_encode($_POST['proxy_user'].":".$_POST['proxy_pass']).'\r\n';
                                  $context = stream_context_create($opts);
                                    $str = strrev($r);
                                   $str = strrev(substr($str,0,stripos($str,'/'))); 
                                 try{$fp_text = file_get_contents($r,false,$context);
                                    if(($fp_text!=null)&&(!strstr($fp_text,'html'))){$ft = fopen($serv_path."/files/".$dir_name[$p].'/'.$str,"wb+"); 
                                   fwrite($ft,$fp_text); if($ks==10||$ks==20||$ks==30) $url_img_links.=$_SERVER['HTTP_HOST']."/files/".$dir_name[$p].'/'.$str.'\r\n';
                                   fclose($ft);}  
                                   }catch(Exception $e){};                                  
                                 };$i+=$k;ob_flush();ob_clean();
                            }
     elseif($c_p == 3) {if($i%10==0)$j='00';else $j='';$el = substr(($i/1000).$j,2,3);
                                 $r  = str_replace('$$$',$el,$links[$p]);
                                   $str = strrev($r);
                                   $str = strrev(substr($str,0,stripos($str,'/')));   
                                  if(!file_exists($serv_path."/files/".$dir_name[$p].'/'.$str)){
                                  $url = parse_url($r);  
                                    $opts = array('http' => array('method'=>"GET",'header'=>
                                    "Host: ".$url['host']."\r\n".
                                   "Referer: ".$url['protocol'].$url['host'].$url['path']."\r\n".
                                   "Accept-language: en\r\n".
                                   'Cookie: '.$_POST['cokies']."\r\n".
                                   "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 4.0.20506)\r\n"
                                    ));
                                   if(trim($_POST['user'])!=''&&trim($_POST['pass'])!='')
                                        $opts['http']['header'].="Authorization: Basic " . base64_encode($_POST['user'].":".$_POST['pass']).'\r\n';
                                    if(trim($_POST['proxy'])!=''){
                                     $opts['http']['proxy'] = 'tcp://'.$_POST['proxy'];
                                     $opts['http']['request_fulluri'] = true;
                                    }
                                   if(trim($_POST['proxy_user'])!=''&&trim($_POST['proxy_pass'])!='')
                                        $opts['http']['header'].="Proxy-Authorization: Basic " . base64_encode($_POST['proxy_user'].":".$_POST['proxy_pass']).'\r\n';

                                  $context = stream_context_create($opts);
                                    $str = strrev($r);
                                   $str = strrev(substr($str,0,stripos($str,'/'))); 
                                   try{ $fp_text = file_get_contents($r,false,$context);
                                    if(($fp_text!=null)&&(!strstr($fp_text,'html'))){$ft = fopen($serv_path."/files/".$dir_name[$p].'/'.$str,"wb+"); 
                                   fwrite($ft,$fp_text); if($ks==10||$ks==20||$ks==30) $url_img_links.=$_SERVER['HTTP_HOST']."/files/".$dir_name[$p].'/'.$str.'\r\n';
                                   fclose($ft);}    
                                   }catch(Exception $e){};                                
                                };$i+=$k;ob_flush();ob_clean();
                        }

     elseif($c_p == 4) {if($i%10==0)$j='000';else $j='';$el = substr(($i/10000).$j,2,4); 
                                   
                                  $r  = str_replace('$$$$',$el,$links[$p]);
                                   $str = strrev($r);
                                   $str = strrev(substr($str,0,stripos($str,'/')));   
                                  if(!file_exists($serv_path."/files/".$dir_name[$p].'/'.$str)){
                                  $url = parse_url($r);  
                                    $opts = array('http' => array('method'=>"GET",'header'=>
                                    "Host: ".$url['host']."\r\n".
                                   "Referer: ".$url['protocol'].$url['host'].$url['path']."\r\n".
                                   "Accept-language: en\r\n".
                                   'Cookie: '.$_POST['cokies']."\r\n".
                                   "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 4.0.20506)\r\n"
                                    ));
                                   if(trim($_POST['user'])!=''&&trim($_POST['pass'])!='')
                                        $opts['http']['header'].="Authorization: Basic " . base64_encode($_POST['user'].":".$_POST['pass']).'\r\n';
                                    if(trim($_POST['proxy'])!=''){
                                     $opts['http']['proxy'] = 'tcp://'.$_POST['proxy'];
                                     $opts['http']['request_fulluri'] = true;
                                    }
                                   if(trim($_POST['proxy_user'])!=''&&trim($_POST['proxy_pass'])!='')
                                        $opts['http']['header'].="Proxy-Authorization: Basic " . base64_encode($_POST['proxy_user'].":".$_POST['proxy_pass']).'\r\n';
                                  $context = stream_context_create($opts);
                                   try{ $fp_text = file_get_contents($r,false,$context);
                                    if(($fp_text!=null)&&(!strstr($fp_text,'html'))){$ft = fopen($serv_path."/files/".$dir_name[$p].'/'.$str,"wb+"); 
                                   fwrite($ft,$fp_text); if($ks==10||$ks==20||$ks==30) $url_img_links.='http://'.$_SERVER['HTTP_HOST']."/files/".$dir_name[$p].'/'.$str."\n";
                                   fclose($ft);}
                                   }catch(Exception $e){};
                                 }; $i+=$k;
                                }
                    $url_img_links .= "\n"; if(!file_exists($serv_path.'/files/'.$dir_name[$p].".zip")){
                    $archive = new PclZip($serv_path.'/files/'.$dir_name[$p].".zip");
                    $v_list = $archive->add($serv_path.'/files/'.$dir_name[$p],'',$serv_path.'/files/'.$dir_name[$p]);
                    chmod($serv_path.'/files/'.$dir_name[$p].".zip",0777); };
                   $url_links.='http://'.$_SERVER['HTTP_HOST']."/files/".$dir_name[$p].".zip"."\n";  
  }
print '<textarea style="position:relative;width:600px;height:200px;">'.$url_img_links.'</textarea><br>
<textarea style="position:relative;width:600px;height:200px;">'.$url_links.'</textarea><br>
</body></html>';
 }
else{

print '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset =windows-1251" /></head><body>'.
'<form action="down.php" method="post">
url links:<textarea style="width:500px;height:100px;"  name="link"></textarea><br><br>
dir names:<textarea style="width:500px;height:100px;"  name="dir_name"></textarea><br><br>
cokies:<input type="text" style="width:300px;height:20px;"  value="" name="cokies"><br><br>
user:password :<input type="text" style="width:300px;height:20px;"  value="" name="user">:<input type="text" style="width:300px;height:20px;"  value="" name="pass"><br><br>
proxy:<input type="text" style="width:300px;height:20px;"  value="" name="proxy"><br><br>
proxy_user:proxy_password :<input type="text" style="width:300px;height:20px;"  value="" name="proxy_user">:<input type="text" style="width:300px;height:20px;"  value="" name="proxy_pass"><br><br>
rand: start:<textarea style="width:300px;height:100px;"  name="start"></textarea>
end:<textarea style="width:300px;height:100px;" name="end"></textarea><br><br>
key level:<input type="text" style="width:300px;height:20px;" value="" name="key"><br><br>
<input type="submit" value="Submit" />
</form>
</body></html>';
}


?>