PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/hosts/upload/vk.com.php

https://gitlab.com/dkiller1/rapidleech
PHP | 207 lines | 156 code | 29 blank | 22 comment | 54 complexity | b1947c1ccec5e5b8168899b71281bd26 MD5 | raw file
  1. <?php
  2. // ** VK (ВКонтакте) Upload Plugin by Th3-822 **
  3. // Create a Application at http://vk.com/editapp?act=create
  4. // Select "Web Site" and add your rapidleech url and the base domain.
  5. // After creating the app, copy the Application ID and the Secret key. and add them at $app.
  6. ######## Plugin's Info ########
  7. $app = array();
  8. $app['id'] = ''; //Application ID
  9. $app['secret'] = ''; //Application SecretKey
  10. $upload_audio_as_video = false; // Upload Audio files to "My Videos"...
  11. $upload_video_as_doc = false; // Upload original Video file as Doc (Limit 200 MB)...
  12. ########################
  13. if (empty($app['id']) || empty($app['secret'])) html_error('Application ID or SecretKey Empty. Please create a VK\'s app and add them at '.HOST_DIR.'upload/'.basename(__FILE__));
  14. $not_done = true;
  15. $_GET['proxy'] = isset($proxy) ? $proxy : (isset($_GET['proxy']) ? $_GET['proxy'] : '');
  16. $return_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?uploaded='.urlencode($_REQUEST['uploaded']).'&filename='.urlencode(base64_encode($lname));
  17. if (!empty($_GET['proxy'])) $return_url .= '&useuproxy=on&uproxy='.urlencode($_GET['proxy']);
  18. if (!empty($_REQUEST['pauth'])) $return_url .= '&upauth='.urlencode($pauth);
  19. if (!empty($_GET['save_style'])) $return_url .= '&save_style='.urlencode($_GET['save_style']);
  20. if (isset($_GET['auul'])) $return_url .= '&auul='.urlencode($_GET['auul']);
  21. $fileExts = array(
  22. 'video' => array('avi', 'mp4', '3gp', 'mpg', 'mpeg', 'mov', 'flv', 'wmv'),
  23. 'audio' => array('mp3'),
  24. 'block' => array('exe', 'scr', 'msi', 'com', 'cmd', 'bat', 'reg', 'pif', 'vbs', 'js', 'hta') /* Block non allowed fileExts (List May Be Incomplete) */
  25. );
  26. // File Ext Check
  27. $fExt = (strpos($lname, '.') !== false) ? strtolower(substr(strrchr($lname, '.'), 1)) : '';
  28. $type = 'doc';
  29. foreach ($fileExts as $t => $exts) {
  30. if (in_array($fExt, $exts)) {
  31. $type = $t;
  32. break;
  33. }
  34. }
  35. // Convert Upload Types
  36. if ($type == 'audio' && $upload_audio_as_video) $type = 'video';
  37. elseif ($type == 'video' && $upload_video_as_doc) $type = 'doc';
  38. // Check Type Limits
  39. switch ($type) {
  40. case 'block': html_error("This file ext. ($fExt) isn't allowed by VK.");
  41. case 'audio':
  42. case 'doc':
  43. if ($fsize > 200*1024*1024) html_error("You only can upload '$type' files up to 200 MB.");
  44. }
  45. // Check https support for login.
  46. $usecurl = $options['use_curl'] && extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_exec') ? true : false;
  47. $chttps = false;
  48. if ($usecurl) {
  49. $cV = curl_version();
  50. if (in_array('https', $cV['protocols'], true)) $chttps = true;
  51. }
  52. if (!extension_loaded('openssl') && !$chttps) html_error('You need to install/enable PHP\'s OpenSSL extension to support HTTPS connections.');
  53. elseif (!$chttps) $usecurl = false;
  54. $auth_url = 'https://oauth.vk.com/authorize?client_id='.urlencode($app['id']).'&display=popup&scope=audio,video,docs,offline&response_type=code&redirect_uri='.urlencode($return_url);
  55. if (empty($_REQUEST['code'])) {
  56. echo "\n<script type='text/javascript'>document.location = '$auth_url';</script>\n<h1 style='text-align:center'>You are being redirected to VK's oauth dialog...</h1><div style='text-align:center'>It doesn't redirect?, Click <a href='$auth_url'>here</a>.</div>\n";
  57. exit("</body>\n</html>");
  58. } else {
  59. $not_done = false;
  60. // Auth
  61. echo "<table style='width:600px;margin:auto;'>\n<tr><td align='center'>\n<div id='login' width='100%' align='center'>Authenticating</div>\n";
  62. $page = vk_GetPage('https://oauth.vk.com/access_token?client_id='.urlencode($app['id']).'&client_secret='.urlencode($app['secret']).'&code='.urlencode($_REQUEST['code']).'&redirect_uri='.urlencode($return_url));
  63. $json = Get_Reply($page);
  64. if (!empty($json['error']) && stripos($json['error'], 'REDIRECT_URI') === false) html_error("Auth Error: [{$json['error']}] ".(!empty($json['error_description'])?$json['error_description']:''));
  65. // Retrive upload ID
  66. echo "<script type='text/javascript'>document.getElementById('login').style.display='none';</script>\n<div id='info' width='100%' align='center'>Preparing Upload</div>\n";
  67. sleep(1); // They have a limit of 3 Request/Second... Let's wait a second :D
  68. $data = array();
  69. switch ($type) {
  70. case 'video':
  71. $data['method'] = 'video.save';
  72. $data['name'] = $lname;
  73. $data['description'] = 'Uploaded with Rapidleech';
  74. // $data['is_private'] = '1'; // Uncomment for upload videos as private. (Not Sure Yet How It Does Work)
  75. // $data['group_id'] = 1234567890; // ID of the community. (Positive Number)
  76. break;
  77. case 'audio':
  78. $data['method'] = 'audio.getUploadServer';
  79. break;
  80. case 'doc':
  81. $data['method'] = 'docs.getUploadServer';
  82. // $data['group_id'] = 1234567890; // ID of the community. (Positive Number)
  83. break;
  84. }
  85. $upsrv = vk_doApiReq($data);
  86. if (!empty($upsrv['error'])) {
  87. if ($upsrv['error'] == '204') html_error('Your account is banned for uploading.');
  88. html_error("{$data['method']} Error: [{$upsrv['error']['error_code']}] {$upsrv['error']['error_msg']}");
  89. }
  90. $post = array();
  91. $up_url = $upsrv['response']['upload_url'];
  92. // Uploading
  93. echo "<script type='text/javascript'>document.getElementById('info').style.display='none';</script>\n";
  94. $url = parse_url($up_url);
  95. $upfiles = upfile($url['host'], defport($url), $url['path'].($url['query'] ? '?'.$url['query'] : ''), '', '', $post, $lfile, $lname, ($type == 'video' ? 'video_file' : 'file'), '', $_GET['proxy'], $pauth, 0, $url['scheme']);
  96. // Upload Finished
  97. echo "<script type='text/javascript'>document.getElementById('progressblock').style.display='none';</script>\n";
  98. is_page($upfiles);
  99. $upres = Get_Reply($upfiles);
  100. if (!empty($upres['error'])) {
  101. if (is_array($upres['error'])) html_error("Upload $type Error: [{$upres['error']['error_code']}] " . $upres['error']['error_msg']);
  102. else if ($type == 'doc' && $upres['error'] == 'unknown error' && in_array($fExt, array('zip', 'zipx', 'rar', 'rar5', 'tar', 'gz', '7z', 'cab'))) html_error("Upload $type Error: Possible Forbidden File Type Inside Compressed File.");
  103. else html_error("Upload $type Error: " . $upres['error']);
  104. }
  105. if ($type != 'video') {
  106. sleep(1); // Let's wait another second :D
  107. $data = array();
  108. switch ($type) {
  109. case 'audio':
  110. $data['method'] = 'audio.save';
  111. $data['audio'] = $upres['audio'];
  112. $data['server'] = $upres['server'];
  113. $data['hash'] = $upres['hash'];
  114. break;
  115. case 'doc':
  116. $data['method'] = 'docs.save';
  117. $data['file'] = $upres['file'];
  118. $data['tags'] = 'Rapidleech';
  119. break;
  120. }
  121. $rply = vk_doApiReq($data);
  122. if (!empty($rply['error'])) {
  123. if (is_array($rply['error'])) html_error($data['method'] . " Error: [{$rply['error']['error_code']}] " . $rply['error']['error_msg']);
  124. else html_error($data['method'] . ' Error: ' . $rply['error']);
  125. }
  126. }
  127. if ($type == 'video') {
  128. if (!empty($upsrv['response']['vid'])) $download_link = 'https://vk.com/video' . $json['user_id'] . '_' . $upsrv['response']['vid'];
  129. else html_error('Your video will appear in your VK account after a while.');
  130. }
  131. elseif ($type == 'doc' && !empty($rply['response'][0]['did'])) $download_link = 'https://vk.com/doc' . $rply['response'][0]['owner_id'] . '_' . $rply['response'][0]['did'];
  132. else html_error('Check your VK account for see your new uploaded file.');
  133. }
  134. function vk_doApiReq($data) {
  135. global $app;
  136. $data['api_id'] = $app['id'];
  137. $data['format'] = 'json';
  138. $data['v'] = '3.0';
  139. $sig = '';
  140. ksort($data);
  141. foreach ($data as $k => $v) $sig .= "$k=$v";
  142. $sig = md5($sig.$app['secret']);
  143. $baseLink = 'https://api.vk.com/method/'.$data['method'].'?';
  144. unset($k, $v, $data['method']);
  145. return Get_Reply(vk_GetPage($baseLink . http_build_query($data) . "&sig=$sig&access_token=".$GLOBALS['json']['access_token']));
  146. }
  147. function Get_Reply($page) {
  148. if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
  149. $json = substr($page, strpos($page, "\r\n\r\n") + 4);
  150. $json = substr($json, strpos($json, '{'));$json = substr($json, 0, strrpos($json, '}') + 1);
  151. $rply = json_decode($json, true);
  152. if (!$rply || (is_array($rply) && count($rply) == 0)) html_error('Error getting json data.');
  153. return $rply;
  154. }
  155. function vk_GetPage($link, $cookie = 0, $post = 0, $referer = 0, $auth = 0, $XMLRequest = 0) {
  156. if (!$referer && !empty($GLOBALS['Referer'])) {
  157. $referer = $GLOBALS['Referer'];
  158. }
  159. if ($GLOBALS['usecurl']) {
  160. if ($XMLRequest) $referer .= "\r\nX-Requested-With: XMLHttpRequest";
  161. $page = cURL($link, $cookie, $post, $referer, $auth);
  162. } else {
  163. global $pauth;
  164. $Url = parse_url($link);
  165. $page = geturl($Url['host'], defport($Url), $Url['path'] . (!empty($Url['query']) ? '?' . $Url['query'] : ''), $referer, $cookie, $post, 0, !empty($_GET['proxy']) ? $_GET['proxy'] : '', $pauth, $auth, $Url['scheme'], 0, $XMLRequest);
  166. is_page($page);
  167. }
  168. return $page;
  169. }
  170. //[30-8-2012] Written by Th3-822.
  171. //[28-10-2012] Small fixes that i don't remember. - Th3-822
  172. //[24-11-2012] Now it shows video url & Fixed auul for this plugin. - Th3-822
  173. //[22-9-2013] Fixed mp3 upload & Other issues. - Th3-822
  174. //[15-12-2014] Fixed uploading (Now it requires support for HTTPS uploads). - Th3-822
  175. //[23-8-2015] Added Docs upload support. - Th3-822
  176. ?>