mirror of
https://github.com/filegator/filegator.git
synced 2025-08-10 19:54:33 +02:00
initial commit
This commit is contained in:
119
backend/Controllers/AdminController.php
Normal file
119
backend/Controllers/AdminController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Services\Auth\AuthInterface;
|
||||
use Filegator\Services\Auth\User;
|
||||
use Filegator\Services\Storage\Filesystem;
|
||||
use Rakit\Validation\Validator;
|
||||
|
||||
class AdminController
|
||||
{
|
||||
protected $auth;
|
||||
|
||||
protected $storage;
|
||||
|
||||
public function __construct(AuthInterface $auth, Filesystem $storage)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
public function listUsers(Request $request, Response $response)
|
||||
{
|
||||
return $response->json($this->auth->allUsers());
|
||||
}
|
||||
|
||||
public function storeUser(User $user, Request $request, Response $response, Validator $validator)
|
||||
{
|
||||
$validator->setMessage('required', 'This field is required');
|
||||
$validation = $validator->validate($request->all(), [
|
||||
'name' => 'required',
|
||||
'username' => 'required',
|
||||
'homedir' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$errors = $validation->errors();
|
||||
|
||||
return $response->json($errors->firstOfAll(), 422);
|
||||
}
|
||||
|
||||
if ($this->auth->find($request->input('username'))) {
|
||||
return $response->json(['username' => 'Username already taken'], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$user->setName($request->input('name'));
|
||||
$user->setUsername($request->input('username'));
|
||||
$user->setHomedir($request->input('homedir'));
|
||||
$user->setRole($request->input('role', 'user'));
|
||||
$user->setPermissions($request->input('permissions'));
|
||||
$ret = $this->auth->add($user, $request->input('password'));
|
||||
} catch (\Exception $e) {
|
||||
return $response->json($e->getMessage(), 422);
|
||||
}
|
||||
|
||||
return $response->json($ret);
|
||||
}
|
||||
|
||||
public function updateUser($username, Request $request, Response $response, Validator $validator)
|
||||
{
|
||||
$user = $this->auth->find($username);
|
||||
|
||||
if (! $user) {
|
||||
return $response->json('User not found', 422);
|
||||
}
|
||||
|
||||
$validator->setMessage('required', 'This field is required');
|
||||
$validation = $validator->validate($request->all(), [
|
||||
'name' => 'required',
|
||||
'username' => 'required',
|
||||
'homedir' => 'required',
|
||||
]);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$errors = $validation->errors();
|
||||
|
||||
return $response->json($errors->firstOfAll(), 422);
|
||||
}
|
||||
|
||||
if ($username != $request->input('username') && $this->auth->find($request->input('username'))) {
|
||||
return $response->json(['username' => 'Username already taken'], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$user->setName($request->input('name'));
|
||||
$user->setUsername($request->input('username'));
|
||||
$user->setHomedir($request->input('homedir'));
|
||||
$user->setRole($request->input('role', 'user'));
|
||||
$user->setPermissions($request->input('permissions'));
|
||||
|
||||
return $response->json($this->auth->update($username, $user, $request->input('password', '')));
|
||||
} catch (\Exception $e) {
|
||||
return $response->json($e->getMessage(), 422);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteUser($username, Request $request, Response $response)
|
||||
{
|
||||
$user = $this->auth->find($username);
|
||||
|
||||
if (! $user) {
|
||||
return $response->json('User not found', 422);
|
||||
}
|
||||
|
||||
return $response->json($this->auth->delete($user));
|
||||
}
|
||||
}
|
76
backend/Controllers/AuthController.php
Normal file
76
backend/Controllers/AuthController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Services\Auth\AuthInterface;
|
||||
use Filegator\Services\Logger\LoggerInterface;
|
||||
use Rakit\Validation\Validator;
|
||||
|
||||
class AuthController
|
||||
{
|
||||
protected $logger;
|
||||
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function login(Request $request, Response $response, AuthInterface $auth)
|
||||
{
|
||||
$username = $request->input('username');
|
||||
$password = $request->input('password');
|
||||
|
||||
if ($auth->authenticate($username, $password)) {
|
||||
$this->logger->log("Logged in {$username} from IP ".$request->getClientIp());
|
||||
|
||||
return $response->json($auth->user());
|
||||
}
|
||||
|
||||
$this->logger->log("Login failed for {$username} from IP ".$request->getClientIp());
|
||||
|
||||
return $response->json('Login failed, please try again', 422);
|
||||
}
|
||||
|
||||
public function logout(Response $response, AuthInterface $auth)
|
||||
{
|
||||
return $response->json($auth->forget());
|
||||
}
|
||||
|
||||
public function getUser(Response $response, AuthInterface $auth)
|
||||
{
|
||||
$user = $auth->user() ?: $auth->getGuest();
|
||||
|
||||
return $response->json($user);
|
||||
}
|
||||
|
||||
public function changePassword(Request $request, Response $response, AuthInterface $auth, Validator $validator)
|
||||
{
|
||||
$validator->setMessage('required', 'This field is required');
|
||||
$validation = $validator->validate($request->all(), [
|
||||
'oldpassword' => 'required',
|
||||
'newpassword' => 'required',
|
||||
]);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$errors = $validation->errors();
|
||||
|
||||
return $response->json($errors->firstOfAll(), 422);
|
||||
}
|
||||
|
||||
if (! $auth->authenticate($auth->user()->getUsername(), $request->input('oldpassword'))) {
|
||||
return $response->json(['oldpassword' => 'Wrong password'], 422);
|
||||
}
|
||||
|
||||
return $response->json($auth->update($auth->user()->getUsername(), $auth->user(), $request->input('newpassword')));
|
||||
}
|
||||
}
|
133
backend/Controllers/DownloadController.php
Normal file
133
backend/Controllers/DownloadController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Config\Config;
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Kernel\StreamedResponse;
|
||||
use Filegator\Services\Archiver\ArchiverInterface;
|
||||
use Filegator\Services\Auth\AuthInterface;
|
||||
use Filegator\Services\Session\SessionStorageInterface as Session;
|
||||
use Filegator\Services\Storage\Filesystem;
|
||||
use Filegator\Services\Tmpfs\TmpfsInterface;
|
||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||
|
||||
class DownloadController
|
||||
{
|
||||
protected $auth;
|
||||
|
||||
protected $session;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $storage;
|
||||
|
||||
public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->config = $config;
|
||||
$this->auth = $auth;
|
||||
|
||||
$user = $this->auth->user() ?: $this->auth->getGuest();
|
||||
|
||||
$this->storage = $storage;
|
||||
$this->storage->setPathPrefix($user->getHomeDir());
|
||||
}
|
||||
|
||||
public function download($path_encoded, Request $request, Response $response, StreamedResponse $streamedResponse)
|
||||
{
|
||||
try {
|
||||
$file = $this->storage->readStream(base64_decode($path_encoded));
|
||||
} catch (\Exception $e) {
|
||||
return $response->redirect('/');
|
||||
}
|
||||
|
||||
$streamedResponse->setCallback(function () use ($file) {
|
||||
// @codeCoverageIgnoreStart
|
||||
set_time_limit(0);
|
||||
if ($file['stream']) {
|
||||
while (! feof($file['stream'])) {
|
||||
echo fread($file['stream'], 1024 * 8);
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
fclose($file['stream']);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
});
|
||||
|
||||
$streamedResponse->headers->set(
|
||||
'Content-Disposition',
|
||||
HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $file['filename'])
|
||||
);
|
||||
|
||||
// close session so we can continue streaming, note: dev is single-threaded
|
||||
$this->session->save();
|
||||
|
||||
$streamedResponse->send();
|
||||
}
|
||||
|
||||
public function batchDownloadCreate(Request $request, Response $response, ArchiverInterface $archiver)
|
||||
{
|
||||
$items = $request->input('items', []);
|
||||
|
||||
$uniqid = $archiver->createArchive($this->storage);
|
||||
|
||||
// close session
|
||||
$this->session->save();
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->type == 'dir') {
|
||||
$archiver->addDirectoryFromStorage($item->path);
|
||||
}
|
||||
if ($item->type == 'file') {
|
||||
$archiver->addFileFromStorage($item->path);
|
||||
}
|
||||
}
|
||||
|
||||
$archiver->closeArchive();
|
||||
|
||||
return $response->json(['uniqid' => $uniqid]);
|
||||
}
|
||||
|
||||
public function batchDownloadStart(Request $request, StreamedResponse $streamedResponse, TmpfsInterface $tmpfs)
|
||||
{
|
||||
$uniqid = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('uniqid'));
|
||||
|
||||
$streamedResponse->setCallback(function () use ($tmpfs, $uniqid) {
|
||||
// @codeCoverageIgnoreStart
|
||||
set_time_limit(0);
|
||||
$tmp_file = $tmpfs->readStream($uniqid);
|
||||
while (! feof($tmp_file['stream'])) {
|
||||
echo fread($tmp_file['stream'], 1024 * 8);
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
fclose($tmp_file['stream']);
|
||||
$tmpfs->remove($uniqid);
|
||||
// @codeCoverageIgnoreEnd
|
||||
});
|
||||
|
||||
$streamedResponse->headers->set(
|
||||
'Content-Disposition',
|
||||
HeaderUtils::makeDisposition(
|
||||
HeaderUtils::DISPOSITION_ATTACHMENT,
|
||||
$this->config->get('frontend_config.default_archive_name')
|
||||
)
|
||||
);
|
||||
|
||||
// close session so we can continue streaming, note: dev is single-threaded
|
||||
$this->session->save();
|
||||
|
||||
$streamedResponse->send();
|
||||
}
|
||||
}
|
34
backend/Controllers/ErrorController.php
Normal file
34
backend/Controllers/ErrorController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
|
||||
class ErrorController
|
||||
{
|
||||
protected $request_type;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request_type = $request->getContentType();
|
||||
}
|
||||
|
||||
public function notFound(Response $response)
|
||||
{
|
||||
return $this->request_type == 'json' ? $response->json('Not Found', 404) : $response->html('Not Found', 404);
|
||||
}
|
||||
|
||||
public function methodNotAllowed(Response $response)
|
||||
{
|
||||
return $this->request_type == 'json' ? $response->json('Not Allowed', 401) : $response->html('Not Found', 401);
|
||||
}
|
||||
}
|
173
backend/Controllers/FileController.php
Normal file
173
backend/Controllers/FileController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Config\Config;
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Services\Archiver\ArchiverInterface;
|
||||
use Filegator\Services\Auth\AuthInterface;
|
||||
use Filegator\Services\Session\SessionStorageInterface as Session;
|
||||
use Filegator\Services\Storage\Filesystem;
|
||||
|
||||
class FileController
|
||||
{
|
||||
const SESSION_CWD = 'current_path';
|
||||
|
||||
protected $session;
|
||||
|
||||
protected $auth;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $storage;
|
||||
|
||||
protected $separator;
|
||||
|
||||
public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->config = $config;
|
||||
$this->auth = $auth;
|
||||
|
||||
$user = $this->auth->user() ?: $this->auth->getGuest();
|
||||
|
||||
$this->storage = $storage;
|
||||
$this->storage->setPathPrefix($user->getHomeDir());
|
||||
|
||||
$this->separator = $this->storage->getSeparator();
|
||||
}
|
||||
|
||||
public function changeDirectory(Request $request, Response $response)
|
||||
{
|
||||
$path = $request->input('to', $this->separator);
|
||||
|
||||
$this->session->set(self::SESSION_CWD, $path);
|
||||
|
||||
return $response->json($this->storage->getDirectoryCollection($path));
|
||||
}
|
||||
|
||||
public function getDirectory(Request $request, Response $response)
|
||||
{
|
||||
$path = $request->input('dir', $this->session->get(self::SESSION_CWD, $this->separator));
|
||||
|
||||
$content = $this->storage->getDirectoryCollection($path);
|
||||
|
||||
return $response->json($content);
|
||||
}
|
||||
|
||||
public function createNew(Request $request, Response $response)
|
||||
{
|
||||
$type = $request->input('type', 'file');
|
||||
$name = $request->input('name');
|
||||
$path = $this->session->get(self::SESSION_CWD, $this->separator);
|
||||
|
||||
if ($type == 'dir') {
|
||||
$this->storage->createDir($path, $request->input('name'));
|
||||
}
|
||||
if ($type == 'file') {
|
||||
$this->storage->createFile($path, $request->input('name'));
|
||||
}
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function copyItems(Request $request, Response $response)
|
||||
{
|
||||
$items = $request->input('items', []);
|
||||
$destination = $request->input('destination', $this->separator);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->type == 'dir') {
|
||||
$this->storage->copyDir($item->path, $destination);
|
||||
}
|
||||
if ($item->type == 'file') {
|
||||
$this->storage->copyFile($item->path, $destination);
|
||||
}
|
||||
}
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function moveItems(Request $request, Response $response)
|
||||
{
|
||||
$items = $request->input('items', []);
|
||||
$destination = $request->input('destination', $this->separator);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$full_destination = trim($destination, $this->separator)
|
||||
.$this->separator
|
||||
.ltrim($item->name, $this->separator);
|
||||
$this->storage->move($item->path, $full_destination);
|
||||
}
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function zipItems(Request $request, Response $response, ArchiverInterface $archiver)
|
||||
{
|
||||
$items = $request->input('items', []);
|
||||
$destination = $request->input('destination', $this->separator);
|
||||
$name = $request->input('name', $this->config->get('frontend_config.default_archive_name'));
|
||||
|
||||
$archiver->createArchive($this->storage);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->type == 'dir') {
|
||||
$archiver->addDirectoryFromStorage($item->path);
|
||||
}
|
||||
if ($item->type == 'file') {
|
||||
$archiver->addFileFromStorage($item->path);
|
||||
}
|
||||
}
|
||||
|
||||
$archiver->storeArchive($destination, $name);
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function unzipItem(Request $request, Response $response, ArchiverInterface $archiver)
|
||||
{
|
||||
$source = $request->input('item');
|
||||
$destination = $request->input('destination', $this->separator);
|
||||
|
||||
$archiver->uncompress($source, $destination, $this->storage);
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function renameItem(Request $request, Response $response)
|
||||
{
|
||||
$destination = $request->input('destination', $this->separator);
|
||||
$from = $request->input('from');
|
||||
$to = $request->input('to');
|
||||
|
||||
$this->storage->rename($destination, $from, $to);
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
|
||||
public function deleteItems(Request $request, Response $response)
|
||||
{
|
||||
$items = $request->input('items', []);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->type == 'dir') {
|
||||
$this->storage->deleteDir($item->path);
|
||||
}
|
||||
if ($item->type == 'file') {
|
||||
$this->storage->deleteFile($item->path);
|
||||
}
|
||||
}
|
||||
|
||||
return $response->json('Done');
|
||||
}
|
||||
}
|
119
backend/Controllers/UploadController.php
Normal file
119
backend/Controllers/UploadController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Config\Config;
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Services\Auth\AuthInterface;
|
||||
use Filegator\Services\Storage\Filesystem;
|
||||
use Filegator\Services\Tmpfs\TmpfsInterface;
|
||||
|
||||
class UploadController
|
||||
{
|
||||
protected $auth;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $storage;
|
||||
|
||||
protected $tmpfs;
|
||||
|
||||
public function __construct(Config $config, AuthInterface $auth, Filesystem $storage, TmpfsInterface $tmpfs)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->auth = $auth;
|
||||
$this->tmpfs = $tmpfs;
|
||||
|
||||
$user = $this->auth->user() ?: $this->auth->getGuest();
|
||||
|
||||
$this->storage = $storage;
|
||||
$this->storage->setPathPrefix($user->getHomeDir());
|
||||
}
|
||||
|
||||
public function chunkCheck(Request $request, Response $response)
|
||||
{
|
||||
$file_name = $request->input('resumableFilename', 'file');
|
||||
$identifier = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('resumableIdentifier'));
|
||||
$chunk_number = (int) $request->input('resumableChunkNumber');
|
||||
|
||||
$chunk_file = 'multipart_'.$identifier.$file_name.'.part'.$chunk_number;
|
||||
|
||||
if ($this->tmpfs->exists($chunk_file)) {
|
||||
return $response->json('Chunk exists', 200);
|
||||
}
|
||||
|
||||
return $response->json('Chunk does not exists', 204);
|
||||
}
|
||||
|
||||
public function upload(Request $request, Response $response)
|
||||
{
|
||||
$file_name = $request->input('resumableFilename', 'file');
|
||||
$destination = $request->input('resumableRelativePath');
|
||||
$chunk_number = (int) $request->input('resumableChunkNumber');
|
||||
$total_chunks = (int) $request->input('resumableTotalChunks');
|
||||
$total_size = (int) $request->input('resumableTotalSize');
|
||||
$identifier = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('resumableIdentifier'));
|
||||
|
||||
$file = $request->files->get('file');
|
||||
|
||||
if (! $file || ! $file->isValid() || $file->getSize() > $this->config->get('frontend_config.upload_max_size')) {
|
||||
return $response->json('Bad file', 422);
|
||||
}
|
||||
|
||||
$prefix = 'multipart_'.$identifier;
|
||||
|
||||
if ($this->tmpfs->exists($prefix.'_error')) {
|
||||
return $response->json('Chunk too big', 422);
|
||||
}
|
||||
|
||||
$stream = fopen($file->getPathName(), 'r');
|
||||
|
||||
$this->tmpfs->write($prefix.$file_name.'.part'.$chunk_number, $stream);
|
||||
|
||||
// check if all the parts present, and create the final destination file
|
||||
$chunks_size = 0;
|
||||
foreach ($this->tmpfs->findAll($prefix.'*') as $chunk) {
|
||||
$chunks_size += $chunk['size'];
|
||||
}
|
||||
|
||||
// file too big, cleanup to protect server, set error trap
|
||||
if ($chunks_size > $this->config->get('frontend_config.upload_max_size')) {
|
||||
foreach ($this->tmpfs->findAll($prefix.'*') as $tmp_chunk) {
|
||||
$this->tmpfs->remove($tmp_chunk['name']);
|
||||
}
|
||||
$this->tmpfs->write($prefix.'_error', '');
|
||||
|
||||
return $response->json('Chunk too big', 422);
|
||||
}
|
||||
|
||||
// if all the chunks are present, create final file and store it
|
||||
if ($chunks_size >= $total_size) {
|
||||
for ($i = 1; $i <= $total_chunks; ++$i) {
|
||||
$part = $this->tmpfs->readStream($prefix.$file_name.'.part'.$i);
|
||||
$this->tmpfs->write($file_name, $part['stream']);
|
||||
}
|
||||
|
||||
$final = $this->tmpfs->readStream($file_name);
|
||||
$res = $this->storage->store($destination, $final['filename'], $final['stream']);
|
||||
|
||||
// cleanup
|
||||
$this->tmpfs->remove($file_name);
|
||||
foreach ($this->tmpfs->findAll($prefix.'*') as $expired_chunk) {
|
||||
$this->tmpfs->remove($expired_chunk['name']);
|
||||
}
|
||||
|
||||
return $res ? $response->json('Stored') : $response->json('Error storing file');
|
||||
}
|
||||
|
||||
return $response->json('Uploaded');
|
||||
}
|
||||
}
|
28
backend/Controllers/ViewController.php
Normal file
28
backend/Controllers/ViewController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Controllers;
|
||||
|
||||
use Filegator\Config\Config;
|
||||
use Filegator\Kernel\Response;
|
||||
use Filegator\Services\View\ViewInterface;
|
||||
|
||||
class ViewController
|
||||
{
|
||||
public function index(Response $response, ViewInterface $view)
|
||||
{
|
||||
return $response->html($view->getIndexPage());
|
||||
}
|
||||
|
||||
public function getFrontendConfig(Response $response, Config $config)
|
||||
{
|
||||
return $response->json($config->get('frontend_config'));
|
||||
}
|
||||
}
|
259
backend/Controllers/routes.php
Normal file
259
backend/Controllers/routes.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/', '\Filegator\Controllers\ViewController@index',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/login', '\Filegator\Controllers\AuthController@login',
|
||||
],
|
||||
'roles' => [
|
||||
'guest',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/logout', '\Filegator\Controllers\AuthController@logout',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/getuser', '\Filegator\Controllers\AuthController@getUser',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/changepassword', '\Filegator\Controllers\AuthController@changePassword',
|
||||
],
|
||||
'roles' => [
|
||||
'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/getconfig', '\Filegator\Controllers\ViewController@getFrontendConfig',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/changedir', '\Filegator\Controllers\FileController@changeDirectory',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/getdir', '\Filegator\Controllers\FileController@getDirectory',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/copyitems', '\Filegator\Controllers\FileController@copyItems',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/moveitems', '\Filegator\Controllers\FileController@moveItems',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/renameitem', '\Filegator\Controllers\FileController@renameItem',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/zipitems', '\Filegator\Controllers\FileController@zipItems',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write', 'zip',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/unzipitem', '\Filegator\Controllers\FileController@unzipItem',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write', 'zip',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/deleteitems', '\Filegator\Controllers\FileController@deleteItems',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/createnew', '\Filegator\Controllers\FileController@createNew',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'write',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/upload', '\Filegator\Controllers\UploadController@chunkCheck',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'upload',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/upload', '\Filegator\Controllers\UploadController@upload',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'upload',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/download/{path_encoded}', '\Filegator\Controllers\DownloadController@download',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'download',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/batchdownload', '\Filegator\Controllers\DownloadController@batchDownloadCreate',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'download', 'batchdownload',
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/batchdownload', '\Filegator\Controllers\DownloadController@batchDownloadStart',
|
||||
],
|
||||
'roles' => [
|
||||
'guest', 'user', 'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
'read', 'download', 'batchdownload',
|
||||
],
|
||||
],
|
||||
// admins
|
||||
[
|
||||
'route' => [
|
||||
'GET', '/listusers', '\Filegator\Controllers\AdminController@listUsers',
|
||||
],
|
||||
'roles' => [
|
||||
'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/storeuser', '\Filegator\Controllers\AdminController@storeUser',
|
||||
],
|
||||
'roles' => [
|
||||
'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/updateuser/{username}', '\Filegator\Controllers\AdminController@updateUser',
|
||||
],
|
||||
'roles' => [
|
||||
'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => [
|
||||
'POST', '/deleteuser/{username}', '\Filegator\Controllers\AdminController@deleteUser',
|
||||
],
|
||||
'roles' => [
|
||||
'admin',
|
||||
],
|
||||
'permissions' => [
|
||||
],
|
||||
],
|
||||
];
|
Reference in New Issue
Block a user