Proyectos de Subversion LeadersLinked - Services

Rev

Rev 754 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 754 Rev 764
Línea 177... Línea 177...
177
            return new JsonModel($data);
177
            return new JsonModel($data);
178
        }
178
        }
179
    }
179
    }
Línea -... Línea 180...
-
 
180
 
-
 
181
 
-
 
182
    public function dataStorageAction()
-
 
183
    {
-
 
184
        $request = $this->getRequest();
-
 
185
        if ($request->isGet()) {
-
 
186
            
-
 
187
            $type = $this->params()->fromRoute('type');
-
 
188
            $uuid = $this->params()->fromRoute('uuid');
-
 
189
            $filename = $this->params()->fromRoute('filename');
-
 
190
            
-
 
191
            if(empty($type) || empty($uuid) || empty($filename)) {
-
 
192
                return $this->getResponse()->setStatusCode(404);
-
 
193
            }
-
 
194
            
-
 
195
            // Map type to config key
-
 
196
            $configKey = 'leaderslinked.fullpath.' . $type;
-
 
197
            if(!isset($this->config[$configKey])) {
-
 
198
                return $this->getResponse()->setStatusCode(404);
-
 
199
            }
-
 
200
            
-
 
201
            // Build the file path using the configured base path
-
 
202
            $basePath = $this->config[$configKey];
-
 
203
            $filePath = $basePath . $uuid . DIRECTORY_SEPARATOR . $filename;
-
 
204
            
-
 
205
            // Security check: ensure the path is within the allowed directory
-
 
206
            $realFilePath = realpath($filePath);
-
 
207
            $realBasePath = realpath($basePath);
-
 
208
            if(!$realFilePath || !$realBasePath || strpos($realFilePath, $realBasePath) !== 0) {
-
 
209
                return $this->getResponse()->setStatusCode(403);
-
 
210
            }
-
 
211
            
-
 
212
            if(file_exists($realFilePath)) {
-
 
213
                
-
 
214
                // Try to open file
-
 
215
                if (!is_readable($realFilePath)) {
-
 
216
                    return $this->getResponse()->setStatusCode(500);
-
 
217
                }
-
 
218
                
-
 
219
                // Get file size in bytes.
-
 
220
                $fileSize = filesize($realFilePath);
-
 
221
                
-
 
222
                // Get MIME type of the file.
-
 
223
                $mimeType = mime_content_type($realFilePath);
-
 
224
                if($mimeType===false) {
-
 
225
                    $mimeType = 'application/octet-stream';
-
 
226
                }
-
 
227
                
-
 
228
                $fileContent = file_get_contents($realFilePath);
-
 
229
                
-
 
230
                $response = $this->getResponse();
-
 
231
                $headers = $response->getHeaders();
-
 
232
                $headers->addHeaderLine('Content-type: ' . $mimeType);
-
 
233
                $headers->addHeaderLine('Content-length: ' . $fileSize);
-
 
234
                
-
 
235
                if($fileContent!==false) {
-
 
236
                    $response->setContent($fileContent);
-
 
237
                    return $response;
-
 
238
                } else {
-
 
239
                    return $this->getResponse()->setStatusCode(500);
-
 
240
                }
-
 
241
            } else {
-
 
242
                return $this->getResponse()->setStatusCode(404);
-
 
243
            }
-
 
244
        
-
 
245
        } else {
-
 
246
            $data = [
-
 
247
                'success' => false,
-
 
248
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
249
            ];
-
 
250
            
-
 
251
            return new JsonModel($data);
-
 
252
        }
-
 
253
    }
180
 
254
 
181
 
255
 
182
    public function indexAction()
256
    public function indexAction()
183
    {
257
    {