1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2017 Viktar Dubiniuk <[email protected]> |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. |
6
|
|
|
* See the COPYING-README file. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OCA\Files_Antivirus; |
10
|
|
|
|
11
|
|
|
use \OCP\IRequest; |
12
|
|
|
|
13
|
|
|
class RequestHelper { |
14
|
|
|
|
15
|
|
|
/** @var IRequest */ |
16
|
|
|
private $request; |
17
|
|
|
|
18
|
|
|
public function __construct(IRequest $request) { |
19
|
|
|
$this->request = $request; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $path |
24
|
|
|
* @return int|null |
25
|
|
|
*/ |
26
|
|
|
public function getUploadSize($path) { |
27
|
|
|
$uploadSize = null; |
28
|
|
|
|
29
|
|
|
try { |
30
|
|
|
$requestMethod = $this->request->getMethod(); |
31
|
|
|
$isRemoteScript = $this->isScriptName('remote.php'); |
32
|
|
|
// Are we uploading anything? |
33
|
|
|
if (in_array($requestMethod, ['MOVE', 'PUT']) && $isRemoteScript) { |
34
|
|
|
$pathInfo = $this->request->getPathInfo(); |
35
|
|
|
|
36
|
|
|
// Chunks are not scanned |
37
|
|
|
$isChunk = \OC_FileChunking::isWebdavChunk() |
38
|
|
|
|| ($requestMethod === 'PUT' && strpos($path, 'uploads/') === 0); |
39
|
|
|
if ($isChunk) { |
40
|
|
|
return null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$isDavPathV1 = $pathInfo === '/webdav' || strpos($pathInfo, '/webdav/') === 0; |
|
|
|
|
44
|
|
|
$isDavPathV2 = $pathInfo === '/dav/files' |
|
|
|
|
45
|
|
|
|| strpos($pathInfo, '/dav/files/') === 0 |
46
|
|
|
|| strpos($pathInfo, '/dav/uploads/') === 0; |
47
|
|
|
|
48
|
|
|
if ($requestMethod === 'PUT') { |
49
|
|
|
$uploadSize = (int)$this->request->getHeader('CONTENT_LENGTH'); |
50
|
|
|
} else { |
51
|
|
|
$uploadSize = (int)$this->request->getHeader('OC_TOTAL_LENGTH'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} catch (\Exception $e) { |
55
|
|
|
// Happens in CLI mode |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $uploadSize; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
* @param $string |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function isScriptName($string) { |
67
|
|
|
$pattern = sprintf('|/%s|', preg_quote($string)); |
68
|
|
|
return preg_match($pattern, $this->request->getScriptName()) === 1; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.