Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/php
File: elFinderConnector.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Default elFinder connector
[3] Fix | Delete
*
[4] Fix | Delete
* @author Dmitry (dio) Levashov
[5] Fix | Delete
**/
[6] Fix | Delete
class elFinderConnector
[7] Fix | Delete
{
[8] Fix | Delete
/**
[9] Fix | Delete
* elFinder instance
[10] Fix | Delete
*
[11] Fix | Delete
* @var elFinder
[12] Fix | Delete
**/
[13] Fix | Delete
protected $elFinder;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Options
[17] Fix | Delete
*
[18] Fix | Delete
* @var array
[19] Fix | Delete
**/
[20] Fix | Delete
protected $options = array();
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Must be use output($data) $data['header']
[24] Fix | Delete
*
[25] Fix | Delete
* @var string
[26] Fix | Delete
* @deprecated
[27] Fix | Delete
**/
[28] Fix | Delete
protected $header = '';
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* HTTP request method
[32] Fix | Delete
*
[33] Fix | Delete
* @var string
[34] Fix | Delete
*/
[35] Fix | Delete
protected $reqMethod = '';
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Content type of output JSON
[39] Fix | Delete
*
[40] Fix | Delete
* @var string
[41] Fix | Delete
*/
[42] Fix | Delete
protected static $contentType = 'Content-Type: application/json; charset=utf-8';
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Constructor
[46] Fix | Delete
*
[47] Fix | Delete
* @param $elFinder
[48] Fix | Delete
* @param bool $debug
[49] Fix | Delete
*
[50] Fix | Delete
* @author Dmitry (dio) Levashov
[51] Fix | Delete
*/
[52] Fix | Delete
public function __construct($elFinder, $debug = false)
[53] Fix | Delete
{
[54] Fix | Delete
[55] Fix | Delete
$this->elFinder = $elFinder;
[56] Fix | Delete
$this->reqMethod = strtoupper($_SERVER["REQUEST_METHOD"]);
[57] Fix | Delete
if ($debug) {
[58] Fix | Delete
self::$contentType = 'Content-Type: text/plain; charset=utf-8';
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Execute elFinder command and output result
[64] Fix | Delete
*
[65] Fix | Delete
* @return void
[66] Fix | Delete
* @throws Exception
[67] Fix | Delete
* @author Dmitry (dio) Levashov
[68] Fix | Delete
*/
[69] Fix | Delete
public function run()
[70] Fix | Delete
{
[71] Fix | Delete
$isPost = $this->reqMethod === 'POST';
[72] Fix | Delete
$src = $isPost ? array_merge($_GET, $_POST) : $_GET;
[73] Fix | Delete
$maxInputVars = (!$src || isset($src['targets'])) ? ini_get('max_input_vars') : null;
[74] Fix | Delete
if ((!$src || $maxInputVars) && $rawPostData = file_get_contents('php://input')) {
[75] Fix | Delete
// for max_input_vars and supports IE XDomainRequest()
[76] Fix | Delete
$parts = explode('&', $rawPostData);
[77] Fix | Delete
if (!$src || $maxInputVars < count($parts)) {
[78] Fix | Delete
$src = array();
[79] Fix | Delete
foreach ($parts as $part) {
[80] Fix | Delete
list($key, $value) = array_pad(explode('=', $part), 2, '');
[81] Fix | Delete
$key = rawurldecode($key);
[82] Fix | Delete
if (preg_match('/^(.+?)\[([^\[\]]*)\]$/', $key, $m)) {
[83] Fix | Delete
$key = $m[1];
[84] Fix | Delete
$idx = $m[2];
[85] Fix | Delete
if (!isset($src[$key])) {
[86] Fix | Delete
$src[$key] = array();
[87] Fix | Delete
}
[88] Fix | Delete
if ($idx) {
[89] Fix | Delete
$src[$key][$idx] = rawurldecode($value);
[90] Fix | Delete
} else {
[91] Fix | Delete
$src[$key][] = rawurldecode($value);
[92] Fix | Delete
}
[93] Fix | Delete
} else {
[94] Fix | Delete
$src[$key] = rawurldecode($value);
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
$_POST = $this->input_filter($src);
[98] Fix | Delete
$_REQUEST = $this->input_filter(array_merge_recursive($src, $_REQUEST));
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
if (isset($src['targets']) && $this->elFinder->maxTargets && count($src['targets']) > $this->elFinder->maxTargets) {
[103] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_MAX_TARGTES)));
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$cmd = isset($src['cmd']) ? $src['cmd'] : '';
[107] Fix | Delete
$args = array();
[108] Fix | Delete
[109] Fix | Delete
if (!function_exists('json_encode')) {
[110] Fix | Delete
$error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
[111] Fix | Delete
$this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if (!$this->elFinder->loaded()) {
[115] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
// telepat_mode: on
[119] Fix | Delete
if (!$cmd && $isPost) {
[120] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
[121] Fix | Delete
}
[122] Fix | Delete
// telepat_mode: off
[123] Fix | Delete
[124] Fix | Delete
if (!$this->elFinder->commandExists($cmd)) {
[125] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// collect required arguments to exec command
[129] Fix | Delete
$hasFiles = false;
[130] Fix | Delete
foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
[131] Fix | Delete
if ($name === 'FILES') {
[132] Fix | Delete
if (isset($_FILES)) {
[133] Fix | Delete
$hasFiles = true;
[134] Fix | Delete
} elseif ($req) {
[135] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
[136] Fix | Delete
}
[137] Fix | Delete
} else {
[138] Fix | Delete
$arg = isset($src[$name]) ? $src[$name] : '';
[139] Fix | Delete
[140] Fix | Delete
if (!is_array($arg) && $req !== '') {
[141] Fix | Delete
$arg = trim($arg);
[142] Fix | Delete
}
[143] Fix | Delete
if ($req && $arg === '') {
[144] Fix | Delete
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
[145] Fix | Delete
}
[146] Fix | Delete
$args[$name] = $arg;
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
[151] Fix | Delete
[152] Fix | Delete
$args = $this->input_filter($args);
[153] Fix | Delete
if ($hasFiles) {
[154] Fix | Delete
$args['FILES'] = $_FILES;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
try {
[158] Fix | Delete
$this->output($this->elFinder->exec($cmd, $args));
[159] Fix | Delete
} catch (elFinderAbortException $e) {
[160] Fix | Delete
// connection aborted
[161] Fix | Delete
// unlock session data for multiple access
[162] Fix | Delete
$this->elFinder->getSession()->close();
[163] Fix | Delete
// HTTP response code
[164] Fix | Delete
header('HTTP/1.0 204 No Content');
[165] Fix | Delete
// clear output buffer
[166] Fix | Delete
while (ob_get_level() && ob_end_clean()) {
[167] Fix | Delete
}
[168] Fix | Delete
exit();
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Sets the header.
[174] Fix | Delete
*
[175] Fix | Delete
* @param array|string $value HTTP header(s)
[176] Fix | Delete
*/
[177] Fix | Delete
public function setHeader($value)
[178] Fix | Delete
{
[179] Fix | Delete
$this->header = $value;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Output json
[184] Fix | Delete
*
[185] Fix | Delete
* @param array data to output
[186] Fix | Delete
*
[187] Fix | Delete
* @return void
[188] Fix | Delete
* @throws elFinderAbortException
[189] Fix | Delete
* @author Dmitry (dio) Levashov
[190] Fix | Delete
*/
[191] Fix | Delete
protected function output(array $data)
[192] Fix | Delete
{
[193] Fix | Delete
// unlock session data for multiple access
[194] Fix | Delete
$this->elFinder->getSession()->close();
[195] Fix | Delete
// client disconnect should abort
[196] Fix | Delete
ignore_user_abort(false);
[197] Fix | Delete
[198] Fix | Delete
if ($this->header) {
[199] Fix | Delete
self::sendHeader($this->header);
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
if (isset($data['pointer'])) {
[203] Fix | Delete
// set time limit to 0
[204] Fix | Delete
elFinder::extendTimeLimit(0);
[205] Fix | Delete
[206] Fix | Delete
// send optional header
[207] Fix | Delete
if (!empty($data['header'])) {
[208] Fix | Delete
self::sendHeader($data['header']);
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
// clear output buffer
[212] Fix | Delete
while (ob_get_level() && ob_end_clean()) {
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
$toEnd = true;
[216] Fix | Delete
$fp = $data['pointer'];
[217] Fix | Delete
$sendData = !($this->reqMethod === 'HEAD' || !empty($data['info']['xsendfile']));
[218] Fix | Delete
$psize = null;
[219] Fix | Delete
if (($this->reqMethod === 'GET' || !$sendData)
[220] Fix | Delete
&& (elFinder::isSeekableStream($fp) || elFinder::isSeekableUrl($fp))
[221] Fix | Delete
&& (array_search('Accept-Ranges: none', headers_list()) === false)) {
[222] Fix | Delete
header('Accept-Ranges: bytes');
[223] Fix | Delete
if (!empty($_SERVER['HTTP_RANGE'])) {
[224] Fix | Delete
$size = $data['info']['size'];
[225] Fix | Delete
$end = $size - 1;
[226] Fix | Delete
if (preg_match('/bytes=(\d*)-(\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) {
[227] Fix | Delete
if (empty($matches[3])) {
[228] Fix | Delete
if (empty($matches[1]) && $matches[1] !== '0') {
[229] Fix | Delete
$start = $size - $matches[2];
[230] Fix | Delete
} else {
[231] Fix | Delete
$start = intval($matches[1]);
[232] Fix | Delete
if (!empty($matches[2])) {
[233] Fix | Delete
$end = intval($matches[2]);
[234] Fix | Delete
if ($end >= $size) {
[235] Fix | Delete
$end = $size - 1;
[236] Fix | Delete
}
[237] Fix | Delete
$toEnd = ($end == ($size - 1));
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
$psize = $end - $start + 1;
[241] Fix | Delete
[242] Fix | Delete
header('HTTP/1.1 206 Partial Content');
[243] Fix | Delete
header('Content-Length: ' . $psize);
[244] Fix | Delete
header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size);
[245] Fix | Delete
[246] Fix | Delete
// Apache mod_xsendfile dose not support range request
[247] Fix | Delete
if (isset($data['info']['xsendfile']) && strtolower($data['info']['xsendfile']) === 'x-sendfile') {
[248] Fix | Delete
if (function_exists('header_remove')) {
[249] Fix | Delete
header_remove($data['info']['xsendfile']);
[250] Fix | Delete
} else {
[251] Fix | Delete
header($data['info']['xsendfile'] . ':');
[252] Fix | Delete
}
[253] Fix | Delete
unset($data['info']['xsendfile']);
[254] Fix | Delete
if ($this->reqMethod !== 'HEAD') {
[255] Fix | Delete
$sendData = true;
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
$sendData && !elFinder::isSeekableUrl($fp) && fseek($fp, $start);
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
}
[263] Fix | Delete
if ($sendData && is_null($psize)) {
[264] Fix | Delete
elFinder::rewind($fp);
[265] Fix | Delete
}
[266] Fix | Delete
} else {
[267] Fix | Delete
header('Accept-Ranges: none');
[268] Fix | Delete
if (isset($data['info']) && !$data['info']['size']) {
[269] Fix | Delete
if (function_exists('header_remove')) {
[270] Fix | Delete
header_remove('Content-Length');
[271] Fix | Delete
} else {
[272] Fix | Delete
header('Content-Length:');
[273] Fix | Delete
}
[274] Fix | Delete
}
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
if ($sendData) {
[278] Fix | Delete
if ($toEnd || elFinder::isSeekableUrl($fp)) {
[279] Fix | Delete
// PHP < 5.6 has a bug of fpassthru
[280] Fix | Delete
// see https://bugs.php.net/bug.php?id=66736
[281] Fix | Delete
if (version_compare(PHP_VERSION, '5.6', '<')) {
[282] Fix | Delete
file_put_contents('php://output', $fp);
[283] Fix | Delete
} else {
[284] Fix | Delete
if(function_exists('fpassthru')) {
[285] Fix | Delete
fpassthru($fp);
[286] Fix | Delete
} else {
[287] Fix | Delete
file_put_contents('php://output', $fp);
[288] Fix | Delete
}
[289] Fix | Delete
}
[290] Fix | Delete
} else {
[291] Fix | Delete
$out = fopen('php://output', 'wb');
[292] Fix | Delete
stream_copy_to_stream($fp, $out, $psize);
[293] Fix | Delete
fclose($out);
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
if (!empty($data['volume'])) {
[298] Fix | Delete
$data['volume']->close($fp, $data['info']['hash']);
[299] Fix | Delete
} else {
[300] Fix | Delete
fclose($fp);
[301] Fix | Delete
}
[302] Fix | Delete
exit();
[303] Fix | Delete
} else {
[304] Fix | Delete
self::outputJson($data);
[305] Fix | Delete
exit(0);
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Remove null & stripslashes applies on "magic_quotes_gpc"
[311] Fix | Delete
*
[312] Fix | Delete
* @param mixed $args
[313] Fix | Delete
*
[314] Fix | Delete
* @return mixed
[315] Fix | Delete
* @author Naoki Sawada
[316] Fix | Delete
*/
[317] Fix | Delete
protected function input_filter($args)
[318] Fix | Delete
{
[319] Fix | Delete
static $magic_quotes_gpc = NULL;
[320] Fix | Delete
[321] Fix | Delete
if ($magic_quotes_gpc === NULL)
[322] Fix | Delete
$magic_quotes_gpc = (version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc());
[323] Fix | Delete
[324] Fix | Delete
if (is_array($args)) {
[325] Fix | Delete
return array_map(array(& $this, 'input_filter'), $args);
[326] Fix | Delete
}
[327] Fix | Delete
$res = str_replace("\0", '', $args);
[328] Fix | Delete
$magic_quotes_gpc && ($res = stripslashes($res));
[329] Fix | Delete
$res = stripslashes($res);
[330] Fix | Delete
return $res;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* Send HTTP header
[335] Fix | Delete
*
[336] Fix | Delete
* @param string|array $header optional header
[337] Fix | Delete
*/
[338] Fix | Delete
protected static function sendHeader($header = null)
[339] Fix | Delete
{
[340] Fix | Delete
if ($header) {
[341] Fix | Delete
if (is_array($header)) {
[342] Fix | Delete
foreach ($header as $h) {
[343] Fix | Delete
header($h);
[344] Fix | Delete
}
[345] Fix | Delete
} else {
[346] Fix | Delete
header($header);
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
/**
[352] Fix | Delete
* Output JSON
[353] Fix | Delete
*
[354] Fix | Delete
* @param array $data
[355] Fix | Delete
*/
[356] Fix | Delete
public static function outputJson($data)
[357] Fix | Delete
{
[358] Fix | Delete
// send header
[359] Fix | Delete
$header = isset($data['header']) ? $data['header'] : self::$contentType;
[360] Fix | Delete
self::sendHeader($header);
[361] Fix | Delete
[362] Fix | Delete
unset($data['header']);
[363] Fix | Delete
[364] Fix | Delete
if (!empty($data['raw']) && isset($data['error'])) {
[365] Fix | Delete
$out = $data['error'];
[366] Fix | Delete
} else {
[367] Fix | Delete
if (isset($data['debug']) && isset($data['debug']['backendErrors'])) {
[368] Fix | Delete
$data['debug']['backendErrors'] = array_merge($data['debug']['backendErrors'], elFinder::$phpErrors);
[369] Fix | Delete
}
[370] Fix | Delete
$out = json_encode($data);
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
// clear output buffer
[374] Fix | Delete
while (ob_get_level() && ob_end_clean()) {
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
header('Content-Length: ' . strlen($out));
[378] Fix | Delete
[379] Fix | Delete
echo $out;
[380] Fix | Delete
[381] Fix | Delete
flush();
[382] Fix | Delete
}
[383] Fix | Delete
}// END class
[384] Fix | Delete
[385] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function