1 | <?php |
||
31 | class Operation implements IOperation{ |
||
32 | /** @var IManager */ |
||
33 | protected $manager; |
||
34 | |||
35 | /** @var IL10N */ |
||
36 | protected $l; |
||
37 | |||
38 | /** @var int */ |
||
39 | protected $nestingLevel = 0; |
||
40 | |||
41 | /** |
||
42 | * @param IManager $manager |
||
43 | * @param IL10N $l |
||
44 | */ |
||
45 | public function __construct(IManager $manager, IL10N $l) { |
||
49 | |||
50 | /** |
||
51 | * @param IStorage $storage |
||
52 | * @param string $path |
||
53 | * @throws ForbiddenException |
||
54 | */ |
||
55 | public function checkFileAccess(IStorage $storage, $path) { |
||
76 | |||
77 | /** |
||
78 | * @param IStorage $storage |
||
79 | * @param string $path |
||
80 | * @return bool |
||
81 | */ |
||
82 | protected function isBlockablePath(IStorage $storage, $path) { |
||
83 | if (property_exists($storage, 'mountPoint')) { |
||
84 | $hasMountPoint = $storage instanceof StorageWrapper; |
||
85 | if (!$hasMountPoint) { |
||
86 | $ref = new \ReflectionClass($storage); |
||
87 | $prop = $ref->getProperty('mountPoint'); |
||
88 | $hasMountPoint = $prop->isPublic(); |
||
89 | } |
||
90 | |||
91 | if ($hasMountPoint) { |
||
92 | /** @var StorageWrapper $storage */ |
||
93 | $fullPath = $storage->mountPoint . $path; |
||
94 | } else { |
||
95 | $fullPath = $path; |
||
96 | } |
||
97 | } else { |
||
98 | $fullPath = $path; |
||
99 | } |
||
100 | |||
101 | if (substr_count($fullPath, '/') < 3) { |
||
102 | return false; |
||
103 | } |
||
104 | |||
105 | // '', admin, 'files', 'path/to/file.txt' |
||
106 | $segment = explode('/', $fullPath, 4); |
||
107 | |||
108 | return isset($segment[2]) && in_array($segment[2], [ |
||
109 | 'files', |
||
110 | 'thumbnails', |
||
111 | 'files_versions', |
||
112 | ]); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * For thumbnails and versions we want to check the tags of the original file |
||
117 | * |
||
118 | * @param IStorage $storage |
||
119 | * @param string $path |
||
120 | * @return bool |
||
121 | */ |
||
122 | protected function translatePath(IStorage $storage, $path) { |
||
123 | if (substr_count($path, '/') < 1) { |
||
124 | return $path; |
||
125 | } |
||
126 | |||
127 | // 'files', 'path/to/file.txt' |
||
128 | list($folder, $innerPath) = explode('/', $path, 2); |
||
129 | |||
130 | if ($folder === 'files_versions') { |
||
131 | $innerPath = substr($innerPath, 0, strrpos($innerPath, '.v')); |
||
132 | return 'files/' . $innerPath; |
||
133 | } else if ($folder === 'thumbnails') { |
||
134 | list($fileId,) = explode('/', $innerPath, 2); |
||
135 | $innerPath = $storage->getCache()->getPathById($fileId); |
||
136 | |||
137 | if ($innerPath !== null) { |
||
138 | return 'files/' . $innerPath; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | return $path; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Check if we are in the LoginController and if so, ignore the firewall |
||
147 | * @return bool |
||
148 | */ |
||
149 | protected function isCreatingSkeletonFiles() { |
||
150 | $exception = new \Exception(); |
||
151 | $trace = $exception->getTrace(); |
||
152 | |||
153 | foreach ($trace as $step) { |
||
154 | if (isset($step['class']) && $step['class'] === 'OC\Core\Controller\LoginController' && |
||
155 | isset($step['function']) && $step['function'] === 'tryLogin') { |
||
156 | return true; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | return false; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @param string $name |
||
165 | * @param array[] $checks |
||
166 | * @param string $operation |
||
167 | * @throws \UnexpectedValueException |
||
168 | */ |
||
169 | public function validateOperation($name, array $checks, $operation) { |
||
174 | } |
||
175 |