Site hosted by Angelfire.com: Build your free website today!
$value) { $_GET[$key] = $value; } if($_GET[act] == "ftpget") { /*------------------ | Download Handler | ------------------*/ /* @author Nguyen Quoc Bao visit http://en.vietapi.com/wiki/index.php/PHP:_HttpDownload for class information Please send me an email if you find some bug or it doesn't work with download manager. I've tested it with - Reget : http://reget.com - FDM : http://freefiledownloadmanager.org @version 1.2 @desc A simple object for processing download operation , support section downloading @distribution It's free as long as you keep this header . @sample 1: File Download $object = new httpdownload; $object->set_byfile($filename); //Download from a file $object->use_resume = true; //Enable Resume Mode $object->download(); //Download File 2: Data Download $object = new httpdownload; $object->set_bydata($data); //Download from php data $object->use_resume = true; //Enable Resume Mode $object->set_filename($filename); //Set download name $object->set_mime($mime); //File MIME (Default: application/otect-stream) $object->download(); //Download File 3: Manual Download $object = new httpdownload; $object->set_filename($filename); $object->download_ex($size); //output your data here , remember to use $this->seek_start and $this->seek_end value :) */ class httpdownload { /*---------------- | Class Variable | ----------------*/ /** $handler : Object Handler $use_resume : use section download $use_autoexit : auto stop after finishing download $use_auth : use authentication download $data : Download Data $data_len : Download Data Len $data_type : Download Data Type $data_mod : Last modified time $filename : Download File Name $mime : File mime $bufsize : BUFFER SIZE $seek_start : Start Seek $seek_end : End Seek **/ var $handler = array('auth' => false ,'header' => false,'fopen'=>false,'fclose'=>false,'fread'=>false,'fseek' => false); var $use_resume = true; var $use_autoexit = true; var $use_auth = false; var $data = null; var $data_len = 0; var $data_mod = 0; var $filename = null; var $mime = null; var $bufsize = 2048; var $seek_start = 0; var $seek_end = -1; /*------------------- | Download Function | -------------------*/ /** pre_download() : Pre Download Function download() : Download all file set_byfile() : Set data download by file set_bydata() : Set data download by data set_byurl() : Set data download by url set_filename() : Set file name set_mime() : Set file mime download_header() : Send header download_ex() : Manual Download **/ function pre_download() { global $HTTP_SERVER_VARS; if ($this->use_auth) { //use authentication if (!$this->_auth()) { //no authentication $this->_header('WWW-Authenticate: Basic realm="Please enter your username and password"'); $this->_header('HTTP/1.0 401 Unauthorized'); $this->_header('status: 401 Unauthorized'); if ($this->use_autoexit) exit(); return false; } } if ($this->mime == null) $this->mime = "application/octet-stream"; //default mime if (isset($_SERVER['HTTP_RANGE']) || isset($HTTP_SERVER_VARS['HTTP_RANGE'])) { if (isset($HTTP_SERVER_VARS['HTTP_RANGE'])) $seek_range = substr($HTTP_SERVER_VARS['HTTP_RANGE'] , strlen('bytes=')); else $seek_range = substr($_SERVER['HTTP_RANGE'] , strlen('bytes=')); $range = explode('-',$seek_range); if ($range[0] > 0) { $this->seek_start = intval($range[0]); } if ($range[1] > 0) $this->seek_end = intval($range[1]); else $this->seek_end = -1; } else { $this->seek_start = 0; $this->seek_end = -1; } if ($this->seek_start < 0 || !$this->use_resume) $this->seek_start = 0; // echo $this->seek_start."-".$this->seek_end; return true; } function download_ex($size) { if (!$this->pre_download()) return false; ignore_user_abort(true); @set_time_limit(0); //Use seek end here if ($this->seek_start > ($size - 1)) $this->seek_start = 0; if ($this->seek_end <= 0) $this->seek_end = $size - 1; $this->download_header($size,$this->seek_start,$this->seek_end); $this->data_mod = time(); return true; } function download() { if (!$this->pre_download()) return false; $seek = $this->seek_start; ignore_user_abort(true); @set_time_limit(0); $size = $this->data_len; if ($this->data_type == 0) { $size = filesize($this->data); if ($seek > ($size - 1)) $seek = 0; if ($this->filename == null) $this->filename = basename($this->data); $res =& $this->_fopen($this->data,'rb'); if ($seek) $this->_fseek($res , $seek); if ($this->seek_end < $seek) $this->seek_end = $size - 1; $this->download_header($size,$seek,$this->seek_end); //always use the last seek $size = $this->seek_end - $seek + 1; while (!connection_aborted() && $size > 0) { if ($size < $this->bufsize) echo $this->_fread($res , $size); else echo $this->_fread($res , $this->bufsize); $size -= $this->bufsize; } $this->_fclose($res); } else if ($this->data_type == 1) { if ($seek > ($size - 1)) $seek = 0; if ($this->seek_end < $seek) $this->seek_end = $this->data_len - 1; $this->data = substr($this->data , $seek , $this->seek_end - $seek + 1); if ($this->filename == null) $this->filename = time(); $size = strlen($this->data); $this->download_header($this->data_len,$seek,$this->seek_end); while (!connection_aborted() && $size > 0) { echo substr($this->data , 0 , $this->bufsize); $this->data = substr($this->data , $this->bufsize); $size -= $this->bufsize; } } else if ($this->data_type == 2) { //just send a redirect header header('location : ' . $this->data); } if ($this->use_autoexit) exit(); return true; } function download_header($size,$seek_start=null,$seek_end=null) { $this->_header('Content-type: ' . $this->mime); $this->_header('Content-Disposition: attachment; filename="' . $this->filename . '"'); $this->_header('Last-Modified: ' . date('D, d M Y H:i:s \G\M\T' , $this->data_mod)); if ($seek_start && $this->use_resume) { $this->_header("Content-Length: " . ($seek_end - $seek_start + 1)); $this->_header('Accept-Ranges: bytes'); $this->_header("HTTP/1.0 206 Partial Content"); $this->_header("status: 206 Partial Content"); $this->_header("Content-Range: bytes $seek_start-$seek_end/$size"); } else { $this->_header("Content-Length: $size"); } } function set_byfile($dir) { if (is_readable($dir) && is_file($dir)) { $this->data_len = 0; $this->data = $dir; $this->data_type = 0; $this->data_mod = filemtime($dir); return true; } else return false; } function set_bydata($data) { if ($data == '') return false; $this->data = $data; $this->data_len = strlen($data); $this->data_type = 1; $this->data_mod = time(); return true; } function set_byurl($data) { $this->data = $data; $this->data_len = 0; $this->data_type = 2; return true; } function set_filename($filename) { $this->filename = $filename; } function set_mime($mime) { $this->mime = $mime; } function set_lastmodtime($time) { $time = intval($time); if ($time <= 0) $time = time(); $this->data_mod = $time; } /*---------------- | Other Function | ----------------*/ /** header() : Send HTTP Header **/ function _header($var) { if ($this->handler['header']) return @call_user_func($this->handler['header'],$var); else return header($var); } function &_fopen($file,$mode) { if ($this->handler['fopen']) return @call_user_func($this->handler['fopen'],$file,$mode); else return fopen($file,$mode); } function _fclose($res) { if ($this->handler['fclose']) return @call_user_func($this->handler['fclose'],$res); else return fclose($res); } function _fseek($res,$len) { if ($this->handler['fseek']) return @call_user_func($this->handler['fseek'],$res,$len); else return fseek($res,$len); } function &_fread($file,$size) { if ($this->handler['fread']) return @call_user_func($this->handler['fread'],$file,$size); else return fread($file,$size); } function _auth() { if (!isset($_SERVER['PHP_AUTH_USER'])) return false; if ($this->handler['auth']) return @call_user_func($this->handler['auth'],$_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']); else return true; //you must use a handler } } if(!defined('CRLF')) define('CRLF',"\r\n"); if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1); if(!defined("FTP_BINARY")) define("FTP_BINARY", 1); if(!defined("FTP_ASCII")) define("FTP_ASCII", 0); if(!defined('FTP_FORCE')) define('FTP_FORCE', TRUE); define('FTP_OS_Unix','u'); define('FTP_OS_Windows','w'); define('FTP_OS_Mac','m'); class ftp_base { /* Public variables */ var $LocalEcho=FALSE; var $Verbose=FALSE; var $OS_local; /* Private variables */ var $_lastaction=NULL; var $_errors; var $_type; var $_umask; var $_timeout; var $_passive; var $_host; var $_fullhost; var $_port; var $_datahost; var $_dataport; var $_ftp_control_sock; var $_ftp_data_sock; var $_ftp_temp_sock; var $_login; var $_password; var $_connected; var $_ready; var $_code; var $_message; var $_can_restore; var $_port_available; var $_error_array=array(); var $AuthorizedTransferMode=array( FTP_AUTOASCII, FTP_ASCII, FTP_BINARY ); var $OS_FullName=array( FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS' ); var $NewLineCode=array( FTP_OS_Unix => "\n", FTP_OS_Mac => "\r", FTP_OS_Windows => "\r\n" ); var $AutoAsciiExt=array("ASP","BAT","C","CPP","CSV","H","HTM","HTML","SHTML","INI","LOG","PHP","PHP3","PL","PERL","SH","SQL","TXT"); /* Constructor */ function ftp_base($port_mode=FALSE) { $this->_port_available=($port_mode==TRUE); $this->SendMSG("Staring FTP client class with".($this->_port_available?"":"out")." PORT mode support"); $this->_connected=FALSE; $this->_ready=FALSE; $this->_can_restore=FALSE; $this->_code=0; $this->_message=""; $this->SetUmask(0022); $this->SetType(FTP_AUTOASCII); $this->SetTimeout(30); $this->Passive(!$this->_port_available); $this->_login="anonymous"; $this->_password="anon@ftp.com"; $this->OS_local=FTP_OS_Unix; if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows; elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac; } // // // function parselisting($list) { //Parses i line like:"drwxrwx--- 2 owner group 4096 Apr 23 14:57 text" if(preg_match("/^([-ld])([rwxst-]+)\s+(\d+)\s+([-_\w]+)\s+([-_\w]+)\s+(\d+)\s+(\w{3})\s+(\d+)\s+([\:\d]+)\s+(.+)$/i", $list, $ret)) { $v=array( "type"=> ($ret[1]=="-"?"f":$ret[1]), "perms"=> 0, "inode"=> $ret[3], "owner"=> $ret[4], "group"=> $ret[5], "size"=> $ret[6], "date"=> $ret[7]." ".$ret[8]." ".$ret[9], "name"=> $ret[10] ); $v["perms"]+=00400*(int)($ret[2]{0}=="r"); $v["perms"]+=00200*(int)($ret[2]{1}=="w"); $v["perms"]+=00100*(int)in_array($ret[2]{2}, array("x","s")); $v["perms"]+=00040*(int)($ret[2]{3}=="r"); $v["perms"]+=00020*(int)($ret[2]{4}=="w"); $v["perms"]+=00010*(int)in_array($ret[2]{5}, array("x","s")); $v["perms"]+=00004*(int)($ret[2]{6}=="r"); $v["perms"]+=00002*(int)($ret[2]{7}=="w"); $v["perms"]+=00001*(int)in_array($ret[2]{8}, array("x","t")); $v["perms"]+=04000*(int)in_array($ret[2]{2}, array("S","s")); $v["perms"]+=02000*(int)in_array($ret[2]{5}, array("S","s")); $v["perms"]+=01000*(int)in_array($ret[2]{8}, array("T","t")); } return $v; } function SendMSG($message = "", $crlf=true) { if ($this->Verbose) { echo $message.($crlf?CRLF:""); flush(); } return TRUE; } function SetType($mode=FTP_AUTOASCII) { if(!in_array($mode, $this->AuthorizedTransferMode)) { $this->SendMSG("Wrong type"); return FALSE; } $this->_type=$mode; $this->_data_prepare($mode); $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) ); return TRUE; } function Passive($pasv=NULL) { if(is_null($pasv)) $this->_passive=!$this->_passive; else $this->_passive=$pasv; if(!$this->_port_available and !$this->_passive) { $this->SendMSG("Only passive connections available!"); $this->_passive=TRUE; return FALSE; } $this->SendMSG("Passive mode ".($this->_passive?"on":"off")); return TRUE; } function SetServer($host, $port=21, $reconnect=true) { if(!is_long($port)) { $this->verbose=true; $this->SendMSG("Incorrect port syntax"); return FALSE; } else { $ip=@gethostbyname($host); $dns=@gethostbyaddr($host); if(!$ip) $ip=$host; if(!$dns) $dns=$host; if(ip2long($ip) === -1) { $this->SendMSG("Wrong host name/address \"".$host."\""); return FALSE; } $this->_host=$ip; $this->_fullhost=$dns; $this->_port=$port; $this->_dataport=$port-1; } $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\""); if($reconnect){ if($this->_connected) { $this->SendMSG("Reconnecting"); if(!$this->quit(FTP_FORCE)) return FALSE; if(!$this->connect()) return FALSE; } } return TRUE; } function SetUmask($umask=0022) { $this->_umask=$umask; umask($this->_umask); $this->SendMSG("UMASK 0".decoct($this->_umask)); return TRUE; } function SetTimeout($timeout=30) { $this->_timeout=$timeout; $this->SendMSG("Timeout ".$this->_timeout); if($this->_connected) if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE; return TRUE; } function connect() { $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]); if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) { $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\""); return FALSE; } $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting."); do { if(!$this->_readmsg()) return FALSE; if(!$this->_checkCode()) return FALSE; $this->_lastaction=time(); } while($this->_code<200); $this->_ready=true; return TRUE; } function quit($force=false) { if($this->_ready) { if(!$this->_exec("QUIT") and !$force) return FALSE; if(!$this->_checkCode() and !$force) return FALSE; $this->_ready=false; $this->SendMSG("Session finished"); } $this->_quit(); return TRUE; } function login($user=NULL, $pass=NULL) { if(!is_null($user)) $this->_login=$user; else $this->_login="anonymous"; if(!is_null($pass)) $this->_password=$pass; else $this->_password="anon@anon.com"; if(!$this->_exec("USER ".$this->_login, "login")) return FALSE; if(!$this->_checkCode()) return FALSE; if($this->_code!=230) { if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE; if(!$this->_checkCode()) return FALSE; } $this->SendMSG("Authentication succeeded"); $this->_can_restore=$this->restore(100); $this->SendMSG("This server can".($this->_can_restore?"":"'t")." resume broken uploads/downloads"); return TRUE; } function pwd() { if(!$this->_exec("PWD", "pwd")) return FALSE; if(!$this->_checkCode()) return FALSE; return ereg_replace("^[0-9]{3} \"(.+)\" .+".CRLF, "\\1", $this->_message); } function cdup() { if(!$this->_exec("CDUP", "cdup")) return FALSE; if(!$this->_checkCode()) return FALSE; return true; } function chdir($pathname) { if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function rmdir($pathname) { if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function mkdir($pathname) { if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function rename($from, $to) { if(!$this->_exec("RNFR ".$from, "rename")) return FALSE; if(!$this->_checkCode()) return FALSE; if($this->_code==350) { if(!$this->_exec("RNTO ".$to, "rename")) return FALSE; if(!$this->_checkCode()) return FALSE; } else return FALSE; return TRUE; } function filesize($pathname) { if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE; if(!$this->_checkCode()) return FALSE; return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message); } function mdtm($pathname) { if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE; if(!$this->_checkCode()) return FALSE; $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message); $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d"); $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]); return $timestamp; } function systype() { if(!$this->_exec("SYST", "systype")) return FALSE; if(!$this->_checkCode()) return FALSE; $DATA = explode(" ", $this->_message); return $DATA[1]; } function delete($pathname) { if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function site($command, $fnction="site") { if(!$this->_exec("SITE ".$command, $fnction)) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function chmod($pathname, $mode) { if(!$this->site("CHMOD ".decoct($mode)." ".$pathname, "chmod")) return FALSE; return TRUE; } function restore($from) { if(!$this->_exec("REST ".$from, "restore")) return FALSE; if(!$this->_checkCode()) return FALSE; return TRUE; } function features() { if(!$this->_exec("FEAT", "features")) return FALSE; if(!$this->_checkCode()) return FALSE; return preg_split("/[".CRLF."]+/", ereg_replace("[0-9]{3}[ -][^".CRLF."]*".CRLF, "", $this->_message), -1, PREG_SPLIT_NO_EMPTY); } function rawlist($arg="", $pathname="") { return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist"); } function nlist($arg="", $pathname="") { return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist"); } function is_exists($pathname) { if (!($remote_list = $this->nlist("-a", dirname($pathname)))) { $this->SendMSG("Error : Cannot get remote file list"); return -1; } reset($remote_list); while (list(,$value) = each($remote_list)) { if ($value == basename($pathname)) { $this->SendMSG("Remote file ".$pathname." exists"); return TRUE; } } $this->SendMSG("Remote file ".$pathname." does not exist"); return FALSE; } function get($remotefile, $localfile=NULL) { if(is_null($localfile)) $localfile=$remotefile; if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten"); $fp = @fopen($localfile, "w"); if (!$fp) { $this->PushError("get","can't open local file", "Cannot create \"".$localfile."\""); return FALSE; } $pi=pathinfo($remotefile); if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII; else $mode=FTP_BINARY; if(!$this->_data_prepare($mode)) { fclose($fp); return FALSE; } if($this->_can_restore) $this->restore(0); if(!$this->_exec("RETR ".$remotefile, "get")) { $this->_data_close(); fclose($fp); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); fclose($fp); return FALSE; } $out=$this->_data_read($mode, $fp); fclose($fp); $this->_data_close(); if(!$this->_readmsg()) return FALSE; if(!$this->_checkCode()) return FALSE; return $out; } function get2($remotefile, $from) { $mode=FTP_BINARY; if(!$this->_data_prepare($mode)) { return FALSE; } if($this->_can_restore) $this->restore($from); if(!$this->_exec("RETR ".$remotefile, "get")) { $this->_data_close(); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); return FALSE; } $out=$this->_data_read2(); $this->_data_close(); if(!$this->_readmsg()) return FALSE; if(!$this->_checkCode()) return FALSE; return $out; } function put($localfile, $remotefile=NULL) { if(is_null($remotefile)) $remotefile=$localfile; if (!@file_exists($localfile)) { $this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\""); return FALSE; } $fp = @fopen($localfile, "r"); if (!$fp) { $this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\""); return FALSE; } $pi=pathinfo($localfile); if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII; else $mode=FTP_BINARY; if(!$this->_data_prepare($mode)) { fclose($fp); return FALSE; } if($this->_can_restore) $this->restore(0); if(!$this->_exec("STOR ".$remotefile, "put")) { $this->_data_close(); fclose($fp); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); fclose($fp); return FALSE; } $ret=$this->_data_write($mode, $fp); fclose($fp); $this->_data_close(); if(!$this->_readmsg()) return FALSE; if(!$this->_checkCode()) return FALSE; return $ret; } // // // function _checkCode() { return ($this->_code<400 and $this->_code>0); } function _list($arg="", $cmd="LIST", $fnction="_list") { if(!$this->_data_prepare()) return FALSE; if(!$this->_exec($cmd.$arg, $fnction)) { $this->_data_close(); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); return FALSE; } $out=$this->_data_read(); $this->_data_close(); if(!$this->_readmsg()) return FALSE; if(!$this->_checkCode()) return FALSE; if($out === FALSE ) return FALSE; $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY); $this->SendMSG(implode($this->NewLineCode[$this->OS_local], $out)); return $out; } // // // // Genere une erreur pour traitement externe a la classe function PushError($fctname,$msg,$desc=false){ $error=array(); $error['time']=time(); $error['fctname']=$fctname; $error['msg']=$msg; $error['desc']=$desc; if($desc) $tmp=' ('.$desc.')'; else $tmp=''; $this->SendMSG($fctname.': '.$msg.$tmp); return(array_push($this->_error_array,$error)); } // Recupere une erreur externe function PopError(){ if(count($this->_error_array)) return(array_pop($this->_error_array)); else return(false); } } $mod_sockets=TRUE; if (!extension_loaded('sockets')) { $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : ''; if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE; } $mod_sockets=TRUE; if (!extension_loaded('sockets')) { $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : ''; if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE; } if($mod_sockets) { class ftp extends ftp_base { function ftp($verb=FALSE, $le=FALSE) { $this->LocalEcho = $le; $this->Verbose = $verb; $this->ftp_base(TRUE); } // // // function _settimeout($sock) { /*if(!@stream_set_timeout($sock, $this->_timeout)) { $this->PushError('_settimeout','socket set send timeout'); $this->_quit(); return FALSE; } *//*if(!@socket_set_option($sock, 1, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) { $this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock))); @socket_close($sock); return FALSE; } if(!@socket_set_option($sock, 1, SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) { $this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock))); @socket_close($sock); return FALSE; } */return true; } function _connect($host, $port) { $this->SendMSG("Creating socket"); $sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($sock < 0) { $this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock))); return FALSE; } if(!$this->_settimeout($sock)) return FALSE; $this->SendMSG("Connecting to \"".$host.":".$port."\""); if (!($res = @socket_connect($sock, $host, $port))) { $this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock))); @socket_close($sock); return FALSE; } $this->_connected=true; return $sock; } function _readmsg($fnction="_readmsg"){ if(!$this->_connected) { $this->PushError($fnction,'Connect first'); return FALSE; } $result=true; $this->_message=""; $this->_code=0; $go=true; do { $tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ); if($tmp===false) { $go=$result=false; $this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock))); } elseif($tmp=="") $go=false; else { $this->_message.=$tmp; //for($i=0; $i _message); $i++) //if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i]; //echo CRLF; if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false; } } while($go); if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF; $this->_code=(int)$regs[1]; return $result; } function _exec($cmd, $fnction="_exec") { if(!$this->_ready) { $this->PushError($fnction,'Connect first'); return FALSE; } if($this->LocalEcho) echo "PUT > ",$cmd,CRLF; $status=@socket_write($this->_ftp_control_sock, $cmd.CRLF); if($status===false) { $this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream))); return FALSE; } $this->_lastaction=time(); if(!$this->_readmsg($fnction)) return FALSE; return TRUE; } function _data_prepare($mode=FTP_ASCII) { if($mode==FTP_BINARY) { if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE; } else { if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE; } $this->SendMSG("Creating data socket"); $this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->_ftp_data_sock < 0) { $this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock))); return FALSE; } if(!$this->_settimeout($this->_ftp_data_sock)) { $this->_data_close(); return FALSE; } if($this->_passive) { if(!$this->_exec("PASV", "pasv")) { $this->_data_close(); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); return FALSE; } $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message)); $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3]; $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]); $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport); if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) { $this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock))); $this->_data_close(); return FALSE; } else $this->_ftp_temp_sock=$this->_ftp_data_sock; } else { if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) { $this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock))); $this->_data_close(); return FALSE; } if(!@socket_bind($this->_ftp_data_sock,$addr)){ $this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock))); $this->_data_close(); return FALSE; } if(!@socket_listen($this->_ftp_data_sock)) { $this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock))); $this->_data_close(); return FALSE; } if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) { $this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock))); $this->_data_close(); return FALSE; } if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) { $this->_data_close(); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); return FALSE; } } return TRUE; } function _data_read($mode=FTP_ASCII, $fp=NULL) { $NewLine=$this->NewLineCode[$this->OS_local]; if(is_resource($fp)) $out=0; else $out=""; if(!$this->_passive) { $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport); $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock); if($this->_ftp_temp_sock===FALSE) { $this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock))); $this->_data_close(); return FALSE; } } if($mode!=FTP_BINARY) { while(($tmp=@socket_read($this->_ftp_temp_sock, 8192, PHP_NORMAL_READ))!==false) { $line.=$tmp; if(!preg_match("/".CRLF."$/", $line)) continue; $line=rtrim($line,CRLF).$NewLine; if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line)); else $out.=$line; $line=""; } } else { while($block=@socket_read($this->_ftp_temp_sock, 8192, PHP_BINARY_READ)) { if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block)); else $out.=$line; } } return $out; } function _data_read2() { $NewLine=$this->NewLineCode[$this->OS_local]; $out=0; if(!$this->_passive) { $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport); $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock); if($this->_ftp_temp_sock===FALSE) { $this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock))); $this->_data_close(); return FALSE; } } while($block=@socket_read($this->_ftp_temp_sock, 8192, PHP_BINARY_READ)) { $out+=strlen($block); echo $block; } return $out; } function _data_write($mode=FTP_ASCII, $fp=NULL) { $NewLine=$this->NewLineCode[$this->OS_local]; if(is_resource($fp)) $out=0; else $out=""; if(!$this->_passive) { $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport); $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock); if($this->_ftp_temp_sock===FALSE) { $this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock))); $this->_data_close(); return FALSE; } } if(is_resource($fp)) { while(!feof($fp)) { $line=fgets($fp, 4096); if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF; do { if(($res=@socket_write($this->_ftp_temp_sock, $line))===FALSE) { $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock))); return FALSE; } $line=substr($line, $res); }while($line!=""); } } else { if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF; do { if(($res=@socket_write($this->_ftp_temp_sock, $fp))===FALSE) { $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock))); return FALSE; } $fp=substr($fp, $res); }while($fp!=""); } return TRUE; } function _data_close() { @socket_close($this->_ftp_temp_sock); @socket_close($this->_ftp_data_sock); $this->SendMSG("Disconnected data from remote host"); return TRUE; } function _quit() { if($this->_connected) { @socket_close($this->_ftp_control_sock); $this->_connected=false; $this->SendMSG("Socket closed"); } } } } else { class ftp extends ftp_base { function ftp($verb=FALSE, $le=FALSE) { $this->LocalEcho = $le; $this->Verbose = $verb; $this->ftp_base(); } // // // function _settimeout($sock) {echo"==="; /*if(!@stream_set_timeout($sock, $this->_timeout)) { $this->PushError('_settimeout','socket set send timeout'); $this->_quit(); return FALSE; } */return TRUE; } function _connect($host, $port) { $this->SendMSG("Creating socket"); $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout); if (!$sock) { $this->PushError('_connect','socket connect failed', $errstr." (".$errno.")"); return FALSE; } $this->_connected=true; return $sock; } function _readmsg($fnction="_readmsg"){ if(!$this->_connected) { $this->PushError($fnction, 'Connect first'); return FALSE; } $result=true; $this->_message=""; $this->_code=0; $go=true; do { $tmp=@fgets($this->_ftp_control_sock, 512); if($tmp===false) { $go=$result=false; $this->PushError($fnction,'Read failed'); } else { $this->_message.=$tmp; //for($i=0; $i_message); $i++) //if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i]; //echo CRLF; if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false; } } while($go); if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF; $this->_code=(int)$regs[1]; return $result; } function _exec($cmd, $fnction="_exec") { if(!$this->_ready) { $this->PushError($fnction,'Connect first'); return FALSE; } if($this->LocalEcho) echo "PUT > ",$cmd,CRLF; $status=@fputs($this->_ftp_control_sock, $cmd.CRLF); if($status===false) { $this->PushError($fnction,'socket write failed'); return FALSE; } $this->_lastaction=time(); if(!$this->_readmsg($fnction)) return FALSE; return TRUE; } function _data_prepare($mode=FTP_ASCII) { if($mode==FTP_BINARY) { if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE; } else { if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE; } if($this->_passive) { if(!$this->_exec("PASV", "pasv")) { $this->_data_close(); return FALSE; } if(!$this->_checkCode()) { $this->_data_close(); return FALSE; } $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message)); $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3]; $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]); $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport); $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout); if(!$this->_ftp_data_sock) { $this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")"); $this->_data_close(); return FALSE; } else $this->_ftp_data_sock; } else { $this->SendMSG("Only passive connections available!"); return FALSE; } return TRUE; } function _data_read($mode=FTP_ASCII, $fp=NULL) { $NewLine=$this->NewLineCode[$this->OS_local]; if(is_resource($fp)) $out=0; else $out=""; if(!$this->_passive) { $this->SendMSG("Only passive connections available!"); return FALSE; } if($mode!=FTP_BINARY) { while (!feof($this->_ftp_data_sock)) { $tmp=fread($this->_ftp_data_sock, 4096); $line.=$tmp; if(!preg_match("/".CRLF."$/", $line)) continue; $line=rtrim($line,CRLF).$NewLine; if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line)); else $out.=$line; $line=""; } } else { while (!feof($this->_ftp_data_sock)) { $block=fread($this->_ftp_data_sock, 4096); if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block)); else $out.=$line; } } return $out; } function _data_read2() { $NewLine=$this->NewLineCode[$this->OS_local]; $out=0; if(!$this->_passive) { $this->SendMSG("Only passive connections available!"); return FALSE; } while (!feof($this->_ftp_data_sock)) { $block=fread($this->_ftp_data_sock, 4096); $out+=strlen($block); echo $block; } return $out; } function _data_write($mode=FTP_ASCII, $fp=NULL) { $NewLine=$this->NewLineCode[$this->OS_local]; if(is_resource($fp)) $out=0; else $out=""; if(!$this->_passive) { $this->SendMSG("Only passive connections available!"); return FALSE; } if(is_resource($fp)) { while(!feof($fp)) { $line=fgets($fp, 4096); if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF; do { if(($res=@fwrite($this->_ftp_data_sock, $line))===FALSE) { $this->PushError("_data_write","Can't write to socket"); return FALSE; } $line=substr($line, $res); }while($line!=""); } } else { if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF; do { if(($res=@fwrite($this->_ftp_data_sock, $fp))===FALSE) { $this->PushError("_data_write","Can't write to socket"); return FALSE; } $fp=substr($fp, $res); }while($fp!=""); } return TRUE; } function _data_close() { @fclose($this->_ftp_data_sock); $this->SendMSG("Disconnected data from remote host"); return TRUE; } function _quit($force=FALSE) { if($this->_connected or $force) { @fclose($this->_ftp_control_sock); $this->_connected=false; $this->SendMSG("Socket closed"); } } } } $ftp = new ftp(FALSE, FALSE); //$ftp->Verbose = true; //$ftp->LocalEcho = true; if(!$ftp->SetServer($_GET[host], $_GET[port] ? (int)$_GET[port] : 21)) { //if(!$ftp->SetServer("mp3.int.ru", 2121)) { $ftp->quit(); die("Setting server failed"); } if (!$ftp->connect()) { die("Cannot connect"); } if (!$ftp->login($_GET[user], $_GET[pass])) { $ftp->quit(); die("Login failed"); } $ftp->Passive(FALSE); $tmp = explode("/", $_GET[path]); $ftp_file = array_pop($tmp); $ftp_dir = implode("/", $tmp); $ftp->chdir($ftp_dir); if(!$ftp->SetType(FTP_BINARY)) echo "SetType FAILS!n"; $size=$ftp->filesize($ftp_file); $object = new httpdownload; $object->set_filename($ftp_file); $object->use_resume=true; $object->download_ex($size); $ftp->get2($ftp_file,$object->seek_start); $ftp->quit(); die; } if($_COOKIE["clearsettings"]) { setcookie("domail", "", time() - 3600); setcookie("email", "", time() - 3600); setcookie("saveto", "", time() - 3600); setcookie("path", "", time() - 3600); setcookie("useproxy", "", time() - 3600); setcookie("proxy", "", time() - 3600); setcookie("split", "", time() - 3600); setcookie("partSize", "", time() - 3600); setcookie("savesettings", "", time() - 3600); setcookie("clearsettings", "", time() - 3600); } if(!$_GET[FileName] || !$_GET[host] || !$_GET[path]) { $LINK = $_GET[link]; if(!$LINK) { ?> RapidLeech v2.0


Rapid Leecher
currently works with
Rapidshare.de
Megaupload.com
MyTempDir.com
Getfile.biz
Webfile.ru
 Add Comments (E.g. File Passwords)

>
>  Send to Email   > Email: >
>  Split File   >
Method: 
Split Size:  >  Mb.
>  Use Proxy   > Proxy:  >
>  Save in...   > Path:  ">
onClick="javascript:var displ=this.checked?'':'none';document.getElementById('clearsettings').style.display=displ;">  Clear Settings   > Clear
switchCell(3);" : " "; ?>
$record) { foreach(unserialize($record) as $field => $value) { $listReformat[$key][$field] = $value; if($field == "date") { $date = $value; } } $list[$date] = $listReformat[$key]; unset($list[$key], $listReformat[$key]); } } switch($_GET["act"]) { case "delete": if(count($_GET["files"]) < 1) { echo "Select Atleast One File

"; } else { ?>
File 1 ? "Y" : ""; ?>: ">
Delete 1 ? " Files" : " this file"; ?>?
   
".$file["name"]." is removed.

"; unset($list[$_GET["files"][$i]]); } else { echo "Unable to Remove File!!!!! ".$file["name"]."!

"; } } else { echo "File ".$file["name"]." is not Found!

"; } } if(!updateListInFile($list)) { echo "Unable to renew the list!

"; } } else { ?>
"; } else { ?>
Mail 1 ? "" : ""; ?>: ">

Email: >
>File Split   >
Ìåòîä: 
Ðàçìåð ÷àñòè: > Ìá

"; } else { ?> mail('File ".basename($file["name"])." File is sent for the address ".$_GET["email"]."!', '".basename($file["name"])."');\r\n
"; } else { echo "Error with the sending of file!
"; } } else { echo "File ".$file["name"]." it is not found!

"; } } } break; case "split": if(count($_GET["files"]) < 1) { echo "Select one file at least.

"; } else { ?>
">
Part Size: >MB's
Save to: ">
".basename($file["name"])." Of Parts ".bytesToKbOrMb($partSize).", Method - Total Commander...
"; $totalParts = ceil($fileSize / $partSize); echo "Total Parts parts: ".$totalParts."

"; $fileTmp = $fileNamePerman = basename($file["name"]); while(strpos($fileTmp, ".")) { $fileName .= substr($fileTmp, 0, strpos($fileTmp, ".") + 1); $fileTmp = substr($fileTmp, strpos($fileTmp, ".") + 1); } $fileName = substr($fileName, 0, -1); $path = stripslashes($saveTo.(strstr(realpath("./"), ":") ? "\\\\" : "/")); for($j = 0; $j < $totalParts; $j++) { if($j == 0) { $fileChunk = substr($fileContents, 0, $partSize); if(!@write_file($path.$fileName.".crc", "filename=".basename($file["name"])."\r\n"."size=".$fileSize."\r\n"."crc32=".$crc."\r\n")) { echo "Unable to Save into File".$fileName.".crc"." !

"; } else { $time = explode(" ", microtime()); $time = str_replace("0.", $time[1], $time[0]); $list[$time] = array("name" => $path.$fileName.".crc", "size" => bytesToKbOrMb(strlen(read_file($path.$fileName.".crc"))), "date" => $time, "comment" => "Title part of the file ".$fileNamePerman); } if(!@write_file($path.$fileName.".001", $fileChunk)) { echo "Unable to Save into File ".$fileName.".001"." !

"; } else { $time = explode(" ", microtime()); $time = str_replace("0.", $time[1], $time[0]); $list[$time] = array("name" => $path.$fileName.".001", "size" => bytesToKbOrMb(strlen($fileChunk)), "date" => $time, "comment" => ($j + 1)." th part (from ".$totalParts.") parts of the file ".$fileNamePerman); } } elseif($j == $totalParts - 1) { $fileChunk = substr($fileContents, $j * $partSize); $num = strlen($j + 1) == 2 ? "0".($j + 1) : (strlen($j + 1) == 1 ? "00".($j + 1) : ($j + 1)); if(!@write_file($path.$fileName.".".$num, $fileChunk)) { echo "Unable to Save into File ".$fileName.".".$num." !

"; } else { $time = explode(" ", microtime()); $time = str_replace("0.", $time[1], $time[0]); $list[$time] = array("name" => $path.$fileName.".".$num, "size" => bytesToKbOrMb(strlen($fileChunk)), "date" => $time, "comment" => ($j + 1)."th part (from ".$totalParts.") parts of the file ".$fileNamePerman); } } else { $fileChunk = substr($fileContents, $j * $partSize, $partSize); $num = strlen($j + 1) == 2 ? "0".($j + 1) : (strlen($j + 1) == 1 ? "00".($j + 1) : ($j + 1)); if(!@write_file($path.$fileName.".".$num, $fileChunk)) { echo "Unable to Save into File ".$fileName.".".$num." !

"; } else { $time = explode(" ", microtime()); $time = str_replace("0.", $time[1], $time[0]); $list[$time] = array("name" => $path.$fileName.".".$num, "size" => bytesToKbOrMb(strlen($fileChunk)), "date" => $time, "comment" => ($j + 1)."th part (from ".$totalParts.") parts of the file ".$fileNamePerman); } } } unset($fileName); if(!updateListInFile($list)) { echo "Unbale to Update List!

"; } } //if(file_exists($file["name"])) } break; case "rename": if(count($_GET["files"]) < 1) { echo "Select one file at least.

"; } else { ?>
">
New name: ">
".$file["name"]." is Renamed to".basename($newName)."

"; $list[$_GET["files"][$i]]["name"] = $newName; } else { echo "Unable to Rename File.".$file["name"]."!

"; } } else { echo "File ".$file["name"]." Not Found!

"; } } if($smthExists) { if(!updateListInFile($list)) { echo "Unable to Update List!

"; } } break; } if($list) { ?>
Select All | Uncheck All | Invert Selection

$file) { if(file_exists($file["name"])) { $inCurrDir = strstr(dirname($file["name"]), realpath("./")) ? TRUE : FALSE; if($inCurrDir) { $Path = parse_url($SERVER[PHP_SELF]); $Path = substr($Path["path"], 0, strlen($Path["path"]) - strlen(strrchr($Path["path"], "/"))); } ?> ">
Name Size Comment Dated
"> ".basename($file["name"])."" : basename($file["name"]); ?> ", $file["comment"]) : ""; ?>
currently works with
© Original By Vyrus - Modifed By RapidLeech.com - Version 2.0 Working Beta
0) { setcookie("proxy", $_GET["proxy"]); } else { setcookie("proxy", "", time() - 3600); } } else { setcookie("useproxy", "", time() - 3600); } } if(isset($_GET[saveto]) & !$_GET[path]) { html_error("File Save Location Not Set!"); } if(isset($_GET[useproxy]) & (!$_GET[proxy] || !strstr($_GET[proxy], ":"))) { html_error("Proxy Server Address Not Indicated!"); } if(isset($_GET[domail]) & !checkmail($_GET[email])) { html_error("E-mail not set or Invalid !"); } elseif($_GET[domail] & $_GET[split] & !is_numeric($_GET[partSize])) { html_error("The size of the part is erroneously indicated"); } $Referer = $LINK; $Url = parse_url($LINK); if($Url[scheme] == "ftp") { $Url = parse_url($_SERVER[HTTP_REFERER]."?act=ftp_get&host=".$Url[host]."&port=".$Url[port]."&user=".$Url[user]."&pass=".$Url[pass]."&path=".str_replace("&", "%26", $Url[path])); } if(!in_array($Url[host], array("rapidshare.de", "www.megaupload.com", "www.upload2.net", "sr1.mytempdir.com", "www.mytempdir.com", "getfile.biz", "webfile.ru", "slil.ru", "zalil.ru"))) { $directLink = TRUE; } else { $page = geturl($Url[host], 80, $Url[path]."?".$Url[query], 0, 0, 0, 0, isset($_GET["useproxy"]) ? $_GET["proxy"] : ""); } if(!$page & !$directLink) { html_error("Error with obtaining of the page -> ".$LINK."
".$lastError); } else { if(!$directLink) { switch($Url[host]) { case "rapidshare.de": $post["uri"] = $Url[path]; //$post[hint] = cut_str($page, "name=\"hint\" value=\"", "\">"); //$post[letsgo] = "Free"; $post["dl.start"] = "Free"; $url = "/"; $countDownLeft = "var c = "; $countDownRight = ";"; break; case "www.megaupload.com": $noSecondPage = TRUE; $countDownLeft = "\t\t\t\r\n\t\t\t\t "); } if(strstr($page, "is not allowed to use the free-service anymore today")) { html_error("Per Day Download Limit Reached, Try using another proxy."); } if(strstr($page, "html not found.")) { html_error("Rapidshare Message -> This file is not found."); } /*if($Url["host"] == "rapidshare.de") { $Uuid = cut_str($page, "uuid=", ";"); if(!is_numeric($Uuid) || !$Uuid) { html_error("Îøèáêà ïðè ïîëó÷åíèè íîìåðà ñåññèè.".pre($page)); } } */ switch($Url["host"]) { case "rapidshare.de": $Href = cut_str(urldecode(cut_str($page, "unescape('", "')")), "href=\"", "\""); break; case "www.megaupload.com": $Href = cut_str($page, "document.getElementById(\"downloadhtml\").innerHTML = '

\n
RapidLeecher PHP v 1.5


"; echo "Connection Established -> ".(strstr(strtolower($_GET[path]), strtolower(basename(__FILE__))) ? cut_str($_GET[path], "&host=", "&port") : $_GET[host])."...
"; $file = geturl($_GET[host], 80, $_GET[path], $_GET[referer], ($_GET[uuid] ? "uuid=".$_GET[uuid] : ""), 0, $pathWithName, $_GET["proxy"]); if($lastError) { echo $lastError; } elseif($file[bytesReceived] == $file[bytesTotal]) { $inCurrDir = strstr(dirname($pathWithName), realpath("./")) ? TRUE : FALSE; if($inCurrDir) { $Path = parse_url($PHP_SELF); $Path = substr($Path["path"], 0, strlen($Path["path"]) - strlen(strrchr($Path["path"], "/"))); } echo " \r\n"; echo "File ".($inCurrDir ? "
" : "").$_GET[FileName].($inCurrDir ? "" : "")." (".$file[size].") is Saved!
Time: ".$file[time]."
Average Speed: ".$file[speed]." Kb/s
"; if(!$file["alreadyExisted"] || ($file["alreadyExisted"] & ($file["alreadyExistedMd5"] != md5_file($pathWithName)))) { if(!write_file("files.lst", serialize(array("name" => $pathWithName, "size" => $file["size"], "date" => time(), "link" => $_GET["link"], "comment" => str_replace("\n", "\\n", str_replace("\r", "\\r", $_GET["comment"]))))."\r\n", 0)) { echo "Unbale to Update the Downloaded File-List.
"; } } if($_GET["email"]) { $_GET[partSize] = (isset($_GET[partSize]) ? $_GET[partSize] * 1024 * 1024 : FALSE); if(xmail("me@sorry.com", $_GET["email"], "File ".basename($_GET["FileName"]), "File: ".basename($_GET["FileName"])."\r\n"."Link: ".$_GET["link"].($_GET["comment"]? "\r\n"."Comment: ".str_replace("\\r\\n", "\r\n", $_GET["comment"]) : ""), $pathWithName, $_GET["partSize"], $_GET["method"])) { echo " \r\n"; } else { echo "Error with the sending of the file!
"; } } $Path = parse_url($PHP_SELF); $Path = substr($Path["path"], 0, strlen($Path["path"]) - strlen(strrchr($Path["path"], "?"))); echo "
Back!"; } else { echo "Connection broken :-(
Re-Attempt"; } ?>
". "Please, Check whether proper rights are been provided to the script.". "Change save folder and script permission to 777 using CHMOD
". "Re-attempt"; return FALSE; } } flock($fs, LOCK_EX); $timeStart = getmicrotime(); } //socket_set_timeout($fp, 10); //$f = fopen("debug", "w"); while($data = fgets($fp, 128)) { //fwrite($f, $data); if($saveToFile) { if($headersReceived) { $bytesSaved = fwrite($fs, $data); if($bytesSaved > -1) { $bytesReceived += $bytesSaved; } else { echo "Unable to save to the file. ".$saveToFile; return false; } if($bytesReceived >= $bytesTotal) { $percent = 100; } else { $percent = round($bytesReceived / $bytesTotal * 100, 2); } if($bytesReceived > $last + $chunkSize) { $received = bytesToKbOrMb($bytesReceived); $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $lastChunkTime = $time; $speed = round($chunkSize / 1024 / $chunkTime, 2); //echo "Ñêà÷àíî ".$received."".$percent."%; âðåìÿ — ".$tmpTime."; ñêîðîñòü — ".$speed." Êá/ñ
"; echo " \r\n"; $last = $bytesReceived; } } else { $tmp .= $data; if(strstr($tmp, "\n\n")) { $det = "\n\n"; } elseif(strstr($tmp, $nn.$nn)) { $det = $nn.$nn; } if($det) { $tmp = explode($det, $tmp); $bytesSaved = fwrite($fs, $tmp[1]); if($bytesSaved > -1) { $bytesReceived += $bytesSaved; } else { echo "Unable to save to the file ".$saveToFile."
"; return FALSE; } $headersReceived = true; $redirect = cut_str($tmp[0], "Location:", "\n"); if($redirect) { $lastError = "Is obtained perenapravleniye to ".$redirect."
On the course of events, the reference became obsolete. So that from the beginning...

Main"; fclose($fs); unlink($saveToFile) ? "" : unlink($secondName); return FALSE; } $bytesTotal = cut_str($tmp[0], "Content-Length: ", "\n"); $fileSize = bytesToKbOrMb($bytesTotal); $chunkSize = round($bytesTotal / 333); echo "File Saved : ".$saveToFile.", Size : ".$fileSize."...
"; ?>
0 Êá 0% 0 Êá/ñ

is Link Valid?
Back"; fclose($fp); return FALSE; } } fclose($fp); if($saveToFile) { return array("time" => sec2time(round($time)), "speed" => round($bytesTotal / 1024 / (getmicrotime() - $timeStart), 2), "received" => true, "size" => $fileSize, "bytesReceived" => $bytesReceived, "bytesTotal" => $bytesTotal, "alreadyExisted" => $alreadyExisted, "alreadyExistedMd5" => $alreadyExistedMd5); } else { return $zapros.$nn.$nn.$page; } } function formpostdata($post) { global $postdata, $first; $first = ""; array_walk($post, "fpd_f"); return $postdata; } function fpd_f($value, $key) { global $postdata, $first; $postdata .= $first.$key."=".urlencode($value); $first = "&"; } function cut_str($str, $left, $right){ $str = substr(stristr($str, $left), strlen($left)); $leftLen = strlen(stristr($str, $right)); $leftLen = $leftLen ? -($leftLen) : strlen($str); $str = substr($str, 0, $leftLen); return $str; } function write_file ($file_name, $data, $trunk = 1) { if($trunk == 1) {$mode = "w";} elseif ($trunk == 0) {$mode = "a";} $fp = fopen($file_name, $mode); if(!$fp) { return FALSE; } else { if(!flock($fp, LOCK_EX)) { return FALSE; } else { if(!fwrite($fp, $data)) { return FALSE; } else { if(!flock($fp, LOCK_UN)) { return FALSE; } else { if(!fclose($fp)) { return FALSE; } } } } } return TRUE; } function read_file($file_name, $count = -1) { if($count == -1) {$count = filesize($file_name);} $fp = fopen($file_name, "r"); flock($fp, LOCK_SH); $ret = fread($fp, $count); flock($fp, LOCK_UN); fclose($fp); return $ret; } function pre($var) { echo "
";
print_r($var);
echo "
"; } function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function html_error($msg){ ?> RapidLeecher PHP v 1.5

Go Back
= 1) { $hour = floor($hour); $time -= $hour * 3600; } $min = round($time / 60, 2); if($min >= 1) { $min = floor($min); $time -= $min * 60; } $sec = $time; $hour = ($hour >= 1) ? $hour." hours." : ""; $min = ($min >= 1) ? $min." minutes." : ""; $sec = ($sec >= 1) ? $sec." seconds." : ""; return $hour.$min.$sec; } function bytesToKbOrMb($bytes){ $size = ($bytes > (1024 * 1024)) ? round($bytes / (1024 * 1024), 2)." Mb" : round($bytes / 1024, 2)." Kb"; return $size; } function checkmail($mail) { if(strlen($mail) == 0) { return false; } if(!preg_match("/^[a-z0-9_\.-]{1,20}@(([a-z0-9-]+\.)+(com|net|org|mil|". "edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-". "9]{1,3}\.[0-9]{1,3})$/is", $mail)) { return false; } return true; } function xmail($from, $to, $subj, $text, $filename, $partSize = FALSE, $method = FALSE) { global $un; $fileContents = read_file($filename); $fileSize = strlen($fileContents); if($method == "tc" & $partSize != FALSE) { $crc = strtoupper(dechex(crc32($fileContents))); $crc = str_repeat("0", 8 - strlen($crc)).$crc; } $file = base64_encode($fileContents); $file = chunk_split($file); if($method != "tc") { unset($fileContents); } if(!$file) { return FALSE; } else { echo "Sending file to Email...
"; for($i = 0; $i < strlen($subj); $i++) { $subzh .= "=".strtoupper(dechex(ord(substr($subj, $i, 1)))); } $subj = "=?Windows-1251?Q?".$subzh.'?='; $un = strtoupper(uniqid(time())); $head = "From: ".$from."\n". "X-Mailer: Rapid Leecher\n". "Reply-To: ".$from."\n". "Mime-Version: 1.0\n". "Content-Type: multipart/mixed; boundary=\"----------".$un."\"\n\n"; $zag = "------------".$un."\nContent-Type: text/plain; charset=Windows-1251\n". "Content-Transfer-Encoding: 8bit\n\n".$text."\n\n". "------------".$un."\n". "Content-Type: application/octet-stream; name=\"".basename($filename)."\"\n". "Content-Transfer-Encoding: base64\n". "Content-Disposition: attachment; filename=\"".basename($filename)."\"\n\n"; echo "
"; if($partSize) { $partSize = round($partSize); if($method == "rfc") { $multiHeadMain = "From: ".$from."\n". "X-Mailer: RapidLeecher\n". "Reply-To: ".$from."\n". "Mime-Version: 1.0\n". "Content-Type: message/partial; "; echo "Breakdown into parts on ".bytesToKbOrMb($partSize).", Method RFC 2046...
"; $totalParts = ceil(strlen($file) / $partSize); echo "Total Parts: ".$totalParts."
"; $mailed = TRUE; for($i = 0; $i < $totalParts; $i++) { $multiHead = $multiHeadMain."id=\"".$filename."\"; number=".($i + 1)."; total=".$totalParts."\n\n"; if($i == 0) { $multiHead = $multiHead.$head; $fileChunk = $zag.substr($file, 0, $partSize); } elseif($i == $totalParts - 1) { $fileChunk = substr($file, $i * $partSize); } else { $fileChunk = substr($file, $i * $partSize, $partSize); } echo " \r\n"; $mailed = $mailed & mail($to, $subj, $fileChunk, $multiHead); } } elseif($method == "tc") { echo "Breakdown into parts on ".bytesToKbOrMb($partSize).", Mathod Total Commander...
"; $totalParts = ceil($fileSize / $partSize); echo "Total Parts : ".$totalParts."
"; $mailed = TRUE; $fileTmp = $filename; while(strpos($fileTmp, ".")) { $fileName .= substr($fileTmp, 0, strpos($fileTmp, ".") + 1); $fileTmp = substr($fileTmp, strpos($fileTmp, ".") + 1); } $fileName = substr($fileName, 0, -1); for($i = 0; $i < $totalParts; $i++) { if($i == 0) { $fileChunk = substr($fileContents, 0, $partSize); $addHeads = addAdditionalHeaders(array("msg" => $text."\r\n"."File ".basename($filename)." (Part ".($i + 1)." Of ".$totalParts .").", "file" => array("filename" => $fileName.".crc", "stream" => chunk_split(base64_encode("filename=".basename($filename)."\r\n"."size=".$fileSize."\r\n"."crc32=".$crc."\r\n"))))); $addHeads .= addAdditionalHeaders(array("file" => array("filename" => $fileName.".001", "stream" => chunk_split(base64_encode($fileChunk))))); //write_file($fileName.".crc", "filename=".basename($filename)."\r\n"."size=".$fileSize."\r\n"."crc32=".$crc."\r\n"); //write_file($fileName.".001", $fileChunk); } elseif($i == $totalParts - 1) { $fileChunk = substr($fileContents, $i * $partSize); $addHeads = addAdditionalHeaders(array("msg" => "File ".basename($filename)." (Part ".($i + 1)." Of ".$totalParts .").", "file" => array("filename" => $fileName.".".(strlen($i + 1) == 2 ? "0".($i + 1) : (strlen($i + 1) == 1 ? "00".($i + 1) : ($i + 1))), "stream" => chunk_split(base64_encode($fileChunk))))); //write_file($fileName.".".(strlen($i + 1) == 2 ? "0".($i + 1) : (strlen($i + 1) == 1 ? "00".($i + 1) : ($i + 1))), $fileChunk); } else { $fileChunk = substr($fileContents, $i * $partSize, $partSize); $addHeads = addAdditionalHeaders(array("msg" => "File ".basename($filename)." (Part ".($i + 1)." Of ".$totalParts .").", "file" => array("filename" => $fileName.".".(strlen($i + 1) == 2 ? "0".($i + 1) : (strlen($i + 1) == 1 ? "00".($i + 1) : ($i + 1))), "stream" => chunk_split(base64_encode($fileChunk))))); //write_file($fileName.".".(strlen($i + 1) == 2 ? "0".($i + 1) : (strlen($i + 1) == 1 ? "00".($i + 1) : ($i + 1))), $fileChunk); } echo " \r\n"; $mailed = $mailed & mail($to, $subj, $addHeads, $head); } } } else { $mailed = mail($to, $subj, $zag.$file, $head); } if(!$mailed) { return FALSE; } else { return TRUE; } } } function addAdditionalHeaders($head) { global $un; if($head["msg"]) { $ret = "------------".$un. "\nContent-Type: text/plain; charset=Windows-1251\n". "Content-Transfer-Encoding: 8bit\n\n".$head["msg"]."\n\n"; } if($head["file"]["filename"]) { $ret .= "------------".$un."\n". "Content-Type: application/octet-stream; name=\"".basename($head["file"]["filename"])."\"\n". "Content-Transfer-Encoding: base64\n". "Content-Disposition: attachment; filename=\"".basename($head["file"]["filename"])."\"\n\n". $head["file"]["stream"]; } return $ret; } function updateListInFile($list) { if(count($list) > 0) { foreach($list as $key => $value) { $list[$key] = serialize($value); } if(!@write_file("files.lst", implode("\r\n", $list)."\r\n") & count($list) > 0) { return FALSE; } else { return TRUE; } } else { return unlink("files.lst"); } } ?>