Advertisement
Th3-822

[rapidleech][u] GenericXFSHost.inc.php

Aug 17th, 2012
1,734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.67 KB | None | 0 0
  1. <?php
  2. /*
  3.     /hosts/upload/GenericXFSHost.inc.php
  4.  
  5.         Do not edit this file directly
  6.         as it's used by many plugins.
  7.         - Th3-822
  8. */
  9. if (!defined('RAPIDLEECH')) exit;
  10.  
  11. // Check include
  12. if (!isset($_T8) || !is_array($_T8) || empty($_T8['domain']) || $_T8['domain'] == 'domain.tld' || empty($_T8['v'])) {
  13.     if (strtolower(basename(__FILE__)) == strtolower($page_upload[$_REQUEST['uploaded']])) html_error('This plugin can\'t be called directly.');
  14.     html_error('Error: Called from non configured plugin "' . htmlentities($page_upload[$_REQUEST['uploaded']]) . '".');
  15. }
  16. if ($_T8['v'] > 9) html_error('Error: '.basename(__FILE__).' is outdated, please install last version from: http://rapidleech.com/forum/viewtopic.php?f=17&t=80 or http://pastebin.com/E0z7qMU1 ');
  17.  
  18. /* # Default Settings # */
  19. $default = array();
  20. $default['port'] = 80; // Server's port, default: 80 | 443 = https.
  21. $default['path'] = '/'; // URL path to XFS script, default: '/'
  22. $default['xfsFree'] = false; // Change to true if the host is using XFS free.
  23. $default['sslLogin'] = false; // Force https on login.
  24. $default['opUploadName'] = 'upload'; // Custom ?op=value for checking upload page, default: 'upload'
  25. $default['anonUploadDisable'] = false; // Disallow non registered users upload. (XFS Pro)
  26. $default['anonUploadLimit'] = 0; // File-size limit for non registered users (MB) - 0 = Plugin's limit | (XFS Pro)
  27. $default['flashUpload'] = false; // Forces the use of flash upload method... Also filename for .cgi if it's a non empty string. (XFS Pro)
  28.  
  29. $_T8 = array_merge($default, array_filter($_T8)); // Merge default settings with loader's settings
  30.  
  31. $_GET['proxy'] = isset($_GET['proxy']) ? $_GET['proxy'] : '';
  32. $not_done = true;
  33.  
  34. if (!$_T8['xfsFree'] && !empty($upload_acc[$acc_key_name]['user']) && !empty($upload_acc[$acc_key_name]['pass'])) {
  35.     $_REQUEST['up_login'] = $upload_acc[$acc_key_name]['user'];
  36.     $_REQUEST['up_pass'] = $upload_acc[$acc_key_name]['pass'];
  37.     $_REQUEST['action'] = 'FORM';
  38.     echo "<b><center>Using Default Login.</center></b>\n";
  39. }
  40.  
  41. if (!$_T8['xfsFree'] && (empty($_REQUEST['action']) || $_REQUEST['action'] != 'FORM')) {
  42.     echo "<table border='0' style='width:270px;' cellspacing='0' align='center'>\n<form method='POST'>\n\t<input type='hidden' name='action' value='FORM' />\n\t<tr><td style='white-space:nowrap;'>&nbsp;Username*</td><td>&nbsp;<input type='text' name='up_login' value='' style='width:160px;' /></td></tr>\n\t<tr><td style='white-space:nowrap;'>&nbsp;Password*</td><td>&nbsp;<input type='password' name='up_pass' value='' style='width:160px;' /></td></tr>\n";
  43.     echo "\t<tr><td colspan='2' align='center'><br /><input type='submit' value='Upload' /></td></tr>\n";
  44.     echo "\t<tr><td colspan='2' align='center'><small>*You can set it as default in <b>".$page_upload[$_REQUEST['uploaded']]."</b></small></td></tr>\n";
  45.     echo "</form>\n</table>\n";
  46. } else {
  47.     $not_done = false;
  48.     if (substr($_T8['path'], 0, 1) != '/') $_T8['path'] = '/'.$_T8['path'];
  49.     if (substr($_T8['path'], -1) != '/') $_T8['path'] .= '/';
  50.     $_T8['port'] = (!empty($_T8['port']) && $_T8['port'] > 0 && $_T8['port'] < 65536) ? (int)$_T8['port'] : 80;
  51.     $scheme = ($_T8['port'] == 443) ? 'https' : 'http';
  52.     $referer = $scheme.'://'.$_T8['domain'].$_T8['path'];
  53.  
  54.     // Login
  55.     echo "<table style='width:600px;margin:auto;'>\n<tr><td align='center'>\n<div id='login' width='100%' align='center'>Login to ".str_ireplace('www.', '', $_T8['domain'])."</div>\n";
  56.  
  57.     $cookie = (!empty($cookie)) ? (is_array($cookie) ? $cookie : StrToCookies($cookie)) : array();
  58.     $cookie['lang'] = 'english';
  59.     if ($_T8['xfsFree']) $login = false;
  60.     elseif (!empty($_REQUEST['up_login']) && !empty($_REQUEST['up_pass'])) {
  61.         $post = array();
  62.         $post['op'] = 'login';
  63.         $post['redirect'] = '';
  64.         $post['login'] = urlencode($_REQUEST['up_login']);
  65.         $post['password'] = urlencode($_REQUEST['up_pass']);
  66.  
  67.         if (empty($_T8['fw_sendLogin']) || !is_callable($_T8['fw_sendLogin'])) {
  68.             $page = geturl($_T8['domain'], $_T8['port'], $_T8['path'].'?op=login', $referer, $cookie, $post, 0, $_GET['proxy'], $pauth, 0, ($_T8['sslLogin'] ? 'https' : $scheme));is_page($page);
  69.         } else $page = call_user_func($_T8['fw_sendLogin'], $post);
  70.         $header = substr($page, 0, strpos($page, "\r\n\r\n"));
  71.         if (stripos($header, "\nLocation: ") !== false && preg_match('@\nLocation: (https?://[^\r\n]+)@i', $header, $redir) && 'www.' . strtolower($_T8['domain']) == strtolower(parse_url($redir[1], PHP_URL_HOST))) html_error("Please set \$_T8['domain'] to 'www.{$_T8['domain']}'.");
  72.         if (preg_match('@Incorrect ((Username)|(Login)) or Password@i', $page)) html_error('Login failed: User/Password incorrect.');
  73.         is_present($page, 'op=resend_activation', 'Login failed: Your account isn\'t confirmed yet.');
  74.         is_present($page, 'Please%20enter%20your%20e-mail', "Login failed: Missing account's email, login at site and set the email.");
  75.         $cookie = GetCookiesArr($header, $cookie);
  76.         if (empty($cookie['xfss']) && empty($cookie['login'])) html_error('Error: Login cookies not found.');
  77.         $cookie['lang'] = 'english';
  78.         $login = true;
  79.     } else {
  80.         if ($_T8['anonUploadDisable']) html_error('Login failed: User/Password empty.');
  81.         echo "<b><center>Login not found or empty, using non member upload.</center></b>\n";
  82.         if ($_T8['anonUploadLimit'] > 0 && $fsize > $_T8['anonUploadLimit']*1024*1024) html_error('File is too big for anon upload');
  83.         $login = false;
  84.     }
  85.  
  86.     // Retrive upload ID
  87.     echo "<script type='text/javascript'>document.getElementById('login').style.display='none';</script>\n<div id='info' width='100%' align='center'>Retrive upload ID</div>\n";
  88.  
  89.     $page = geturl($_T8['domain'], $_T8['port'], $_T8['path'].'?op='.(empty($_T8['opUploadName']) ? 'upload' : $_T8['opUploadName']), $referer, $cookie, 0, 0, $_GET['proxy'], $pauth, 0, $scheme);is_page($page);
  90.     if (substr($page, 9, 3) != '200') {
  91.         $page = geturl($_T8['domain'], $_T8['port'], $_T8['path'], $referer, $cookie, 0, 0, $_GET['proxy'], $pauth, 0, $scheme);is_page($page);
  92.     }
  93.     $header = substr($page, 0, strpos($page, "\r\n\r\n"));
  94.     if (!$login && stripos($header, "\nLocation: ") !== false && preg_match('@\nLocation: (https?://[^\r\n]+)@i', $header, $redir) && 'www.' . strtolower($_T8['domain']) == strtolower(parse_url($redir[1], PHP_URL_HOST))) html_error("Please set \$_T8['domain'] to 'www.{$_T8['domain']}'.");
  95.  
  96.     if (preg_match('@var[\s\t]+max_upload_filesize[\s\t]*=[\s\t]*[\'\"]?(\d+)[\'\"]?[\s\t]*;@i', $page, $fzlimit) && $fzlimit[1] > 0 && $fsize > $fzlimit[1]*1024*1024) html_error('Error: '.lang(66)); // Max upload filesize test
  97.  
  98.     if (!preg_match('@action=["\']((https?://[^/"\']+)?/(?:[^\?"\'/]+/)*[\w\-]+(?:\.cgi)?)\?(?:\w+=\w+&)*(?:upload_id=|upload_type=file)@i', $page, $up) && (empty($_T8['flashUpload']) || !preg_match('@[\'"]?uploader[\'"]?\s*:\s*[\'"]((https?://[^/"\']+)?/(?:[^\?"\'/]+/)*'.preg_quote((is_string($_T8['flashUpload']) ? $_T8['flashUpload'] :'up_flash.cgi'), '@').')[\'"]@i', $page, $up))) {
  99.         is_present($page, 'We\'re sorry, there are no servers available for upload at the moment.', 'Site isn\'t accepting uploads.');
  100.         is_present($page, 'Uploads are disabled for your country:', 'Site isn\'t accepting uploads from your server\'s country.');
  101.         is_present($page, 'Uploads are disabled for your user type', 'Uploads are disabled for your account type.');
  102.         if (!$login) {
  103.             if (stripos($header, "\nLocation: ") !== false) is_present(cut_str($header, "\nLocation: ", "\n"), '?op=login', 'Please set '.($_T8['xfsFree'] ? '$_T8[\'xfsFree\'] to false and ' : '').'$_T8[\'anonUploadDisable\'] to true.');
  104.             is_present($page, '>Register on site to be able to upload files<', 'Please set '.($_T8['xfsFree'] ? '$_T8[\'xfsFree\'] to false and ' : '').'$_T8[\'anonUploadDisable\'] to true.');
  105.         }
  106.         html_error('Error: Cannot find upload server.');
  107.     }
  108.     $up_url = (empty($up[2])) ? $scheme.'://'.$_T8['domain'].$up[1] : $up[1];
  109.  
  110.     // File-ext checks
  111.     if (preg_match('@var[\s\t]+ext_allowed[\s\t]*=[\s\t]*[\'\"]\|?(\w+(?:\|\w+)*)\|?[\'\"][\s\t]*;@i', $page, $allowedExts) || preg_match('@var[\s\t]+ext_not_allowed[\s\t]*=[\s\t]*[\'\"]\|?(\w+(?:\|\w+)*)\|?[\'\"][\s\t]*;@i', $page, $notAllowedExts)) {
  112.         $fExt = (strpos($lname, '.') !== false) ? strtolower(substr(strrchr($lname, '.'), 1)) : '';
  113.         if (!empty($allowedExts[1])) {
  114.             $allowedExts = array_map('strtolower', array_filter(explode('|', $allowedExts[1])));
  115.             if (!in_array($fExt, $allowedExts)) html_error('Server doesn\'t allow upload of files with this ext: "'.htmlentities($fExt).'".');
  116.         }
  117.         if (!empty($notAllowedExts[1])) {
  118.             $notAllowedExts = array_map('strtolower', array_filter(explode('|', $notAllowedExts[1])));
  119.             if (in_array($fExt, $notAllowedExts)) html_error('Server doesn\'t allow upload of files with this ext: "'.htmlentities($fExt).'".');
  120.         }
  121.     }
  122.  
  123.     $post = array();
  124.     if (empty($_T8['flashUpload'])) {
  125.         $post['upload_type'] = 'file';
  126.         $post['sess_id'] = !empty($cookie['xfss']) ? $cookie['xfss'] : cut_str($page, 'name="sess_id" value="', '"');
  127.         foreach (array('srv_tmp_url', 'utype', 'srv_id', 'disk_id') as $tmpName) {
  128.             if (stripos($page, "name=\"$tmpName\" value=\"") !== false && ($tmp = cut_str($page, "name=\"$tmpName\" value=\"", '"'))) $post["$tmpName"] = $tmp;
  129.         }
  130.         $post['link_pass'] = $post['link_rcpt'] = '';
  131.         $post['file_descr'] = 'Uploaded with Rapidleech.';
  132.         $post['file_public'] = '1';
  133.         $post['tos'] = '1';
  134.         $post['submit_btn'] = ' Upload! ';
  135.  
  136.         $up_url .= '?upload_id=';
  137.         for ($i = 0; $i < 12; $i++) $up_url .= mt_rand(0,9);
  138.         $up_url .= '&js_on=1';
  139.         if (!$_T8['xfsFree']) {
  140.             if (empty($post['utype']) && ($tmp = cut_str($page, "var utype='", "'"))) $up_url .= "&utype=$tmp";
  141.             $up_url .= '&upload_type=file'.(!empty($post['disk_id']) ? '&disk_id=' . urlencode($post['disk_id']) : '');
  142.         }
  143.     } else {
  144.         $post['Filename'] = $lname;
  145.         if ($login) if (!($post['sess_id'] = cut_str($page, 'name="sess_id" value="', '"'))) {
  146.             if (!empty($cookie['xfss'])) $post['sess_id'] = $cookie['xfss'];
  147.             elseif (preg_match('@["\']sess_id["\']\s*:\s*["\'](\w+)["\']@i', $page, $sid)) $post['sess_id'] = $sid[1];
  148.             else html_error('Flash upload session key not found.');
  149.         }
  150.         $post['Upload'] = 'Submit Query';
  151.     }
  152.  
  153.     // Uploading
  154.     echo "<script type='text/javascript'>document.getElementById('info').style.display='none';</script>\n";
  155.  
  156.     $url = parse_url($up_url);
  157.     if (!empty($_T8['flashUpload'])) $url['path'] = substr($url['path'], 0, strrpos($url['path'], '/') + 1).(is_string($_T8['flashUpload']) ? $_T8['flashUpload'] : 'up_flash.cgi');
  158.     $upfiles = upfile($url['host'], defport($url), $url['path'].(!empty($url['query']) ? '?'.$url['query'] : ''), 0, $cookie, $post, $lfile, $lname,
  159.     (empty($_T8['flashUpload']) ? 'file' : 'Filedata'), '', $_GET['proxy'], $pauth, 0, $url['scheme']);
  160.  
  161.     // Upload Finished
  162.     echo "<script type='text/javascript'>document.getElementById('progressblock').style.display='none';</script>\n";
  163.  
  164.     is_page($upfiles);
  165.  
  166.     if (!$login && stripos($page, 'Uploads not enabled for this type of users') !== false) html_error('Please set '.($_T8['xfsFree'] ? '$_T8[\'xfsFree\'] to false and ' : '').'$_T8[\'anonUploadDisable\'] to true.');
  167.  
  168.     $statuscode = intval(substr($upfiles, 9, 3));
  169.     if ($statuscode >= 400 || preg_match('@<body><b>([^<>]+)</b></body></html>@i', $upfiles, $err)) html_error("Upload server isn't working or has failed (HTTP $statuscode)".(!empty($err[1]) ? ', response: ' . htmlspecialchars($err[1]) : '.'));
  170.  
  171.     $page = (empty($_T8['flashUpload']) ? cut_str($upfiles, '<Form name=\'F1\'', '</Form>') : false);
  172.     if (!empty($page)) {
  173.         // Normal Upload (F1 Form)
  174.         if (!preg_match_all('@<textarea [^<>]*name=\'([^\']+)\'[^<>]*>([^>]*)</textarea>@i', $page, $textareas)) html_error('Error: upload_result data not found.');
  175.         $post = array_map('urlencode', array_map('html_entity_decode', array_combine(array_map('trim', $textareas[1]), array_map('trim', $textareas[2]))));
  176.         if (empty($post['op']) || strtolower(urldecode($post['op'])) != 'upload_result') html_error('Error: "upload_result" value not found.');
  177.         if (empty($post['fn'])) html_error('Error: "fn" input not found.');
  178.         if (strtolower($post['st']) != 'ok') html_error('Upload failed, response: '.htmlspecialchars(urldecode($post['st'])));
  179.     } else if (!empty($_T8['flashUpload'])) {
  180.         // Flash Upload (EOL?)
  181.         $body = trim(substr($upfiles, strpos($upfiles, "\r\n\r\n") + 4));
  182.         if (strpos($body, ':') === false || !($reply = explode(':', $body, 6)) || strlen($reply[0]) != 12) html_error('Bad response from flash uploader, response: ' . htmlspecialchars($body));
  183.         //$download_link = $referer.$reply[0];
  184.         //return;
  185.         $post = array('op' => 'upload_result', 'fn' => urlencode($reply[0]), 'st' => 'OK');
  186.     } elseif (preg_match('@"file_status"\s*:\s*"([^\"\'\]\}]+)"@', $upfiles, $reply) && (strtolower($reply[1]) != 'ok' || preg_match('@"file_code"\s*:\s*"(\w{12})"@', $upfiles, $fileid))) {
  187.         // New JSON response.
  188.         if (empty($fileid)) html_error('Upload failed, json response: '.htmlspecialchars($reply[1]));
  189.         $post = array('op' => 'upload_result', 'fn' => urlencode($fileid[1]), 'st' => urlencode($reply[1]));
  190.     } else html_error('Error: upload_result form/json not found.');
  191.  
  192.     $page = geturl($_T8['domain'], $_T8['port'], $_T8['path'], $up_url, $cookie, $post, 0, $_GET['proxy'], $pauth, 0, $scheme);is_page($page);
  193.  
  194.     $host_rexexp = 'https?://(?:www\.)?'.preg_quote(str_ireplace('www.', '', $_T8['domain']).$_T8['path'], '@');
  195.     if (preg_match('@('.$host_rexexp.'\w{12}(?:/[^\?/<>\"\'\r\n]+)?(?:\.html?)?)\?killcode=\w+@i', $page, $lnk)) {
  196.         $download_link = $lnk[1];
  197.         $delete_link = $lnk[0];
  198.     } elseif (preg_match('@'.$host_rexexp.'del-(\w{12})-\w+/([^<>\"\'\r\n]+)@i', $page, $lnk)) {
  199.         $download_link = substr($lnk[0], 0, (stripos($lnk[0], '/del-') + 1)) . $lnk[2] . '/' . $lnk[3];
  200.         $delete_link = $lnk[0];
  201.     } elseif (preg_match('@'.$host_rexexp.'\w{12}(?:/[^\?/<>\"\'\r\n]+)?(?:\.html?)?(?=[\r\n\t\s\'\"<>])@i', $page, $lnk)) $download_link = $lnk[0];
  202.     else html_error('Download link not found.');
  203. }
  204.  
  205. //[17-8-2012] Written by Th3-822
  206. //[30-9-2012] Using ?op=upload for some sites that need it. - Th3-822
  207. //[17-10-2012] Added "domain requires the www." check. - Th3-822
  208. //[08-11-2012] Added XFS Free support. - Th3-822
  209. //[16-3-2013] Some updates, it should support more sites now & Added more error msgs. - Th3-822
  210. //[05-8-2013] Plugin rewritten for making it a include (for saving space) & Added file-ext check & Small edits. - Th3-822
  211. //[21-9-2013] Fixed upload url regexp (Now it will work on hosts that change upload.cgi filename/path) & Edits for allow extra cookies & Added support for XFS's flash upload. - Th3-822
  212. //[22-1-2014] Added support for custom port and https on whole site, login or upload. - Th3-822
  213. //[21-4-2014] Added urlencode on login $post. - Th3-822
  214. //[29-10-2015] Fixed upload server regexp & added callback for login post & fixed upload response. - Th3-822
  215.  
  216. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement