PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hosts/upload/rapidshare.com_2GB.php

http://rapidleech.googlecode.com/
PHP | 218 lines | 181 code | 24 blank | 13 comment | 25 complexity | 381c4e7b88099acf37ef6c55b19a35ac MD5 | raw file
  1. <?php
  2. //If you don't submit form logins when uploading, and these values are set, these default values will be used, otherwise the values you enter to the form will override what's set here
  3. //For auto-upload, you MUST set these values here
  4. //According to RSM2, only **Rapidshare Premium** account is allowed to upload files > 500MB (up to 2GB), whereas non-premium accounts can only upload up to 500MB (even with RSM2)
  5. $site_login = '';
  6. $site_pass = '';
  7. $carrier = 'l3'; //which upload carrier to use depending on your location, usually 'l3' (Level3) is most suitable
  8. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. if (!($_REQUEST['action'] == 'COMMENCEUPLOAD') && !isset($_REQUEST['auul']))
  10. {
  11. echo <<<HTML
  12. <div id='login' width='100%' align='center'>Enter your Rapidshare Login Details</div><br />
  13. <table border='0' style="width:350px;" cellspacing='0' align='center'>
  14. <form action='' method='post'>
  15. <input type='hidden' name='action' value='COMMENCEUPLOAD' />
  16. <tr><td nowrap>&nbsp;Username*</td><td>&nbsp;<input type='text' name='my_login' value='' style="width:160px;" />&nbsp;</td></tr>
  17. <tr><td nowrap>&nbsp;Password*</td><td>&nbsp;<input type='password' name='my_pass' value='' style="width:160px;" />&nbsp;</td></tr>
  18. <tr><td nowrap>&nbsp;Upload Carrier</td><td>&nbsp;
  19. <select style="width:160px;" name='carrier'>
  20. <option value='l3'/>Level 3 (default)</option>
  21. <option value='tl'/>Telia</option>
  22. <option value='tl2'/>Telia2</option>
  23. <option value='cg'/>Cogent</option>
  24. </select>
  25. </td></tr>
  26. <tr><td colspan='2' align='center'><input type='submit' value='Upload' onclick='$(this).fadeOut();'></td></tr>
  27. <tr><td align='center' colspan='2'><small>Submit the form without logins to use default values stored in rapidshare.com_2GB.php</small></td></tr>
  28. </form>
  29. </table>
  30. HTML;
  31. exit;
  32. }
  33. else
  34. {
  35. if (empty($_REQUEST['my_login']) || empty($_REQUEST['my_pass']))
  36. {
  37. if ($site_login && $site_pass)
  38. {
  39. $_REQUEST['my_login'] = $site_login;
  40. $_REQUEST['my_pass'] = $site_pass;
  41. $_REQUEST['carrier'] = $carrier;
  42. $_REQUEST['action'] = 'COMMENCEUPLOAD';
  43. echo "<center><b>Use Default login/pass...</b></center>\n";
  44. }
  45. else html_error('Not all required values were set. Either enter your user and pass and account type, or enter them inside the file.');
  46. }
  47. else
  48. {
  49. $_REQUEST['action'] = 'COMMENCEUPLOAD';
  50. }
  51. }
  52. try
  53. {
  54. //initiate the RS uploader class
  55. $rs = new RS($lfile, $_REQUEST['carrier']);
  56. //upload the file
  57. $rs->upload();
  58. echo "<script>document.getElementById('progressblock').style.display='none';</script>";
  59. $download_link = $rs->download_link;
  60. $delete_link = $rs->delete_link;
  61. }
  62. catch (Exception $e)
  63. {
  64. html_error($e->getMessage());
  65. }
  66. class RS
  67. {
  68. /////Only change the values below if you know what you are doing, or if you want to experiment!
  69. public $file; // the full path to the file we want to upload
  70. public $uploadpath = 'l3'; // depending on your [server|pc] location you can change this to any of the carriers rs.com uses such as 'cg' or others
  71. public $download_link;
  72. public $delete_link;
  73. private $filename; // extracted from $this->file ( see getfilesize() )
  74. private $login;
  75. private $password;
  76. private $uploadserver; // This is the next upload server number e.g. 530. Don't confuse with $uploadpath!
  77. private $fulluploadserver = array(); // an array resulting from a parse_url of the combined details above
  78. private $fsize; // the size of the file we're uploading
  79. private $wantchunksize = 1000000; // you might want to leave this as default! (rapidshare don't allow anything below this anyway, but you could try increasing it if you have very large files to upload)
  80. private $contentheader;
  81. private $boundary = '---------------------632865735RS4EVER5675865';
  82. private $useragent = 'RAPIDSHARE MANAGER Application Version: NOT INSTALLED VERSION STARTED';
  83. private $resumed = 0;
  84. private $complete = 0;
  85. private $fileid;
  86. private $killcode;
  87. public function __construct($file, $carrier)
  88. {
  89. $this->login = trim($_REQUEST['my_login']);
  90. $this->password = trim($_REQUEST['my_pass']);
  91. if ($carrier) $this->uploadpath = $carrier;
  92. $this->getfilesize($file);
  93. $this->getuploadserver();
  94. }
  95. private function getfilesize($file)
  96. {
  97. $this->file = realpath($file);
  98. if (!($this->fsize = filesize($this->file))) throw new Exception('Filesize not obtained - upload halted.'); //("File $this->file is empty or does not exist!\r\n");
  99. #if (($this->fsize > 500*pow(1024, 2)) && $this->zone == 'col') throw new Exception('FILE TOO BIG - Only premium accounts can upload files over 500MB in size');
  100. $this->filename = basename($this->file);
  101. echo "<center><b>Total Filesize (bytes): " . $this->fsize . '</b></center>';
  102. }
  103. private function getuploadserver()
  104. {
  105. if (!($data = file_get_contents('http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1'))) throw new Exception("Unable to get next upload server!");
  106. if (!preg_match('/(\d+)/', $data, $uploadserver)) throw new Exception("Uploadserver invalid? Internal error!");
  107. $this->uploadserver = $uploadserver[1];
  108. $this->fulluploadserver = parse_url('http://rs' . $this->uploadserver . $this->uploadpath . '.rapidshare.com');
  109. }
  110. public function upload()
  111. {
  112. require (TEMPLATE_DIR . '/uploadui.php');
  113. $timeStart = getmicrotime();
  114. if (!($fh = fopen($this->file, 'r'))) throw new Exception('Unable to open file: ' . $this->filename);
  115. $rsip = gethostbyname($this->fulluploadserver['host']);
  116. $cursize = 0;
  117. while ($cursize < $this->fsize)
  118. {
  119. if ($this->fsize > $this->wantchunksize)
  120. {
  121. $chunksize = $this->fsize - $cursize;
  122. if ($chunksize > $this->wantchunksize)
  123. {
  124. $chunksize = $this->wantchunksize;
  125. }
  126. else
  127. {
  128. $this->complete = 1;
  129. }
  130. }
  131. else
  132. {
  133. $chunksize = $this->fsize;
  134. $this->complete = 1;
  135. }
  136. //echo "Upload chunk is $chunksize bytes starting at $cursize...<br />";
  137. $this->contentheader = "$this->boundary\r\nContent-Disposition: form-data; name=\"rsapi_v1\"\r\n\r\n1\r\n";
  138. if ($this->resumed)
  139. {
  140. $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"fileid\"\r\n\r\n$this->fileid\r\n";
  141. $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"killcode\"\r\n\r\n$this->killcode\r\n";
  142. if ($this->complete) $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"complete\"\r\n\r\n1\r\n";
  143. }
  144. if (!$this->resumed && $this->login && $this->password)
  145. {
  146. $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"login\"\r\n\r\n$this->login\r\n";
  147. $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n$this->password\r\n";
  148. }
  149. if (!$this->complete) $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"incomplete\"\r\n\r\n1\r\n";
  150. $this->contentheader .= "$this->boundary\r\nContent-Disposition: form-data; name=\"filecontent\"; filename=\"$this->filename\"\r\n\r\n";
  151. $contenttail = "\r\n$this->boundary--\r\n";
  152. $contentlength = strlen($this->contentheader) + $chunksize + strlen($contenttail);
  153. $header = 'POST /cgi-bin/' . ($this->resumed ? 'uploadresume.cgi' : 'upload.cgi') . " HTTP/1.1\r\nHost: {$this->fulluploadserver[host]}\r\nContent-Type: multipart/form-data; boundary={$this->boundary}\r\nContent-Length: $contentlength\r\nUser-Agent: {$this->useragent}\r\n\r\n";
  154. if (!($socket = fsockopen($rsip, 80, $errno, $errstr, 30))) throw new Exception("Unable to open socket: $errstr");
  155. fwrite($socket, "$header$this->contentheader");
  156. $buffer = fread($fh, $this->wantchunksize);
  157. $bufferlen = strlen($buffer);
  158. $cursize += $bufferlen;
  159. $sentbytes = fwrite($socket, "$buffer");
  160. //echo "Bytes written: $sentbytes<br />";
  161. $time = getmicrotime () - $timeStart;
  162. $chunkTime = $time - $lastChunkTime;
  163. $chunkTime = $chunkTime ? $chunkTime : 1;
  164. $lastChunkTime = $time;
  165. $speed = round ( $sentbytes / 1024 / $chunkTime, 2 );
  166. $percent = round ( $cursize / $this->fsize*100, 2 );
  167. fwrite($socket, $contenttail);
  168. fflush($socket);
  169. $result = '';
  170. while(!feof($socket)) $result .= fgets($socket, 16384);
  171. //file_put_contents('rsresult.log', $result . "\r\n\r\n", FILE_APPEND);
  172. if (preg_match('#(ERROR: .+)#', $result, $errmat)) throw new Exception($errmat[1]);
  173. if (!$this->resumed)
  174. {
  175. preg_match('#/files/(\d+)/#', $result, $fileid);
  176. preg_match('#killcode=(\d+)\r?\n#', $result, $killcode);
  177. preg_match('%http://rapidshare\.com/((?!killcode).)+$%mi', $result, $flink);
  178. preg_match('%http://rapidshare\.com/.*killcode.*%i', $result, $dlink);
  179. $this->download_link = trim($flink[0]);
  180. $this->delete_link = trim($dlink[0]);
  181. $this->fileid = $fileid[1];
  182. $this->killcode = $killcode[1];
  183. $this->resumed = 1;
  184. }
  185. fclose($socket);
  186. echo "<script type='text/javascript' language='javascript'>pr('" . $percent . "', '" . bytesToKbOrMb ( $cursize ) . "', '" . $speed . "');</script>\n";
  187. flush();
  188. }
  189. fclose($fh);
  190. }
  191. }
  192. //created by rapidleech 2009
  193. //latest update 26 November 2010 r8 beta
  194. ?>