Added maintenance mode (close #18)

Optimized release zip size
This commit is contained in:
Sergio Brighenti 2019-01-31 11:48:39 +01:00
parent c60e3d059e
commit 7b81478667
14 changed files with 106 additions and 20 deletions

View file

@ -1,8 +1,9 @@
## v2.5
+ Updated project license to <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU AGPLv3</a>.
+ Added self update feature.
+ **[BETA]** Added self update feature.
+ Added partial content implementation (stream seeking on chromium based browsers).
+ Improved video.js alignment with large videos.
+ Optimized output zip release size.
## v2.4.1
+ Fixed error message when the file is too large. (#15)

View file

@ -50,11 +50,37 @@ module.exports = function (grunt) {
copy: {
main: {
files: [
{expand: true, cwd: 'node_modules/@fortawesome/fontawesome-free', src: ['css/**', 'js/**'], dest: 'static/fontawesome'},
{expand: true, cwd: 'node_modules/bootstrap/dist', src: ['**'], dest: 'static/bootstrap'},
{expand: true, cwd: 'node_modules/clipboard/dist', src: ['**'], dest: 'static/clipboardjs'},
{expand: true, cwd: 'node_modules/video.js/dist', src: ['video.min.js', 'video-js.min.css'], dest: 'static/videojs'},
{expand: true, cwd: 'node_modules/highlightjs', src: ['styles/**/*', 'highlight.pack.min.js'], dest: 'static/highlightjs'},
{
expand: true,
cwd: 'node_modules/@fortawesome/fontawesome-free',
src: ['js/all.min.js'],
dest: 'static/fontawesome'
},
{
expand: true,
cwd: 'node_modules/bootstrap/dist/css',
src: ['bootstrap.min.css'],
dest: 'static/bootstrap/css'
},
{
expand: true,
cwd: 'node_modules/bootstrap/dist/js',
src: ['bootstrap.bundle.min.js'],
dest: 'static/bootstrap/js'
},
{expand: true, cwd: 'node_modules/clipboard/dist', src: ['clipboard.min.js'], dest: 'static/clipboardjs'},
{
expand: true,
cwd: 'node_modules/video.js/dist',
src: ['video.min.js', 'video-js.min.css'],
dest: 'static/videojs'
},
{
expand: true,
cwd: 'node_modules/highlightjs',
src: ['styles/**/*', 'highlight.pack.min.js'],
dest: 'static/highlightjs'
},
{expand: true, cwd: 'node_modules/jquery/dist', src: ['jquery.min.js'], dest: 'static/jquery'}
],
},

View file

@ -37,6 +37,11 @@ class LoginController extends Controller
return redirect($response, 'login');
}
if (isset($this->settings['maintenance']) && $this->settings['maintenance'] && !$result->is_admin) {
$this->session->alert(lang('maintenance_in_progress'), 'info');
return redirect($response, 'login');
}
if (!$result->active) {
$this->session->alert(lang('account_disabled'), 'danger');
return redirect($response, 'login');

View file

@ -26,6 +26,11 @@ class UploadController extends Controller
$json = ['message' => null];
if ($this->settings['maintenance'] && !$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) {
$json['message'] = 'Endpoint under maintenance.';
return $response->withJson($json, 503);
}
if ($request->getServerParam('CONTENT_LENGTH') > stringToBytes(ini_get('post_max_size'))) {
$json['message'] = 'File too large (post_max_size too low).';
return $response->withJson($json, 400);

View file

@ -18,9 +18,7 @@ class AdminMiddleware extends Middleware
public function __invoke(Request $request, Response $response, callable $next)
{
if (!$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) {
$this->session->alert('Your account is not admin anymore.', 'danger');
$this->session->set('admin', false);
$this->session->set('redirectTo', (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
throw new UnauthorizedException();
}

View file

@ -0,0 +1,26 @@
<?php
namespace App\Middleware;
use App\Exceptions\MaintenanceException;
use Slim\Http\Request;
use Slim\Http\Response;
class CheckForMaintenanceMiddleware extends Middleware
{
/**
* @param Request $request
* @param Response $response
* @param callable $next
* @return Response
* @throws MaintenanceException
*/
public function __invoke(Request $request, Response $response, callable $next)
{
if (isset($this->settings['maintenance']) && $this->settings['maintenance'] && !$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) {
throw new MaintenanceException();
}
return $next($request, $response);
}
}

View file

@ -39,7 +39,7 @@ $app->group('', function () {
$this->get('/upload/{id}/raw', \App\Controllers\UploadController::class . ':getRawById')->add(\App\Middleware\AdminMiddleware::class)->setName('upload.raw');
$this->post('/upload/{id}/delete', \App\Controllers\UploadController::class . ':delete')->setName('upload.delete');
})->add(\App\Middleware\AuthMiddleware::class);
})->add(App\Middleware\CheckForMaintenanceMiddleware::class)->add(\App\Middleware\AuthMiddleware::class);
$app->get('/', \App\Controllers\DashboardController::class . ':redirects')->setName('root');
$app->get('/login', \App\Controllers\LoginController::class . ':show')->setName('login.show');
@ -49,7 +49,7 @@ $app->map(['GET', 'POST'], '/logout', \App\Controllers\LoginController::class .
$app->post('/upload', \App\Controllers\UploadController::class . ':upload')->setName('upload');
$app->get('/{userCode}/{mediaCode}', \App\Controllers\UploadController::class . ':show')->setName('public');
$app->get('/{userCode}/{mediaCode}/delete/{token}', \App\Controllers\UploadController::class . ':show')->setName('public.delete.show');
$app->post('/{userCode}/{mediaCode}/delete/{token}', \App\Controllers\UploadController::class . ':deleteByToken')->setName('public.delete');
$app->get('/{userCode}/{mediaCode}/delete/{token}', \App\Controllers\UploadController::class . ':show')->setName('public.delete.show')->add(\App\Middleware\CheckForMaintenanceMiddleware::class);;
$app->post('/{userCode}/{mediaCode}/delete/{token}', \App\Controllers\UploadController::class . ':deleteByToken')->setName('public.delete')->add(\App\Middleware\CheckForMaintenanceMiddleware::class);;
$app->get('/{userCode}/{mediaCode}/raw', \App\Controllers\UploadController::class . ':showRaw')->setName('public.raw')->setOutputBuffering(false);
$app->get('/{userCode}/{mediaCode}/download', \App\Controllers\UploadController::class . ':download')->setName('public.download')->setOutputBuffering(false);

View file

@ -22,6 +22,7 @@ $config = array_replace_recursive([
'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'],
'storage_dir' => 'storage',
'displayErrorDetails' => false,
'maintenance' => false,
'db' => [
'connection' => 'sqlite',
'dsn' => __DIR__ . '/../resources/database/xbackbone.db',
@ -91,6 +92,10 @@ $container['view'] = function ($container) use (&$config) {
$container['errorHandler'] = function ($container) {
return function (\Slim\Http\Request $request, \Slim\Http\Response $response, $exception) use (&$container) {
if ($exception instanceof \App\Exceptions\MaintenanceException) {
return $container->view->render($response->withStatus(503), 'errors/maintenance.twig');
}
if ($exception instanceof \App\Exceptions\UnauthorizedException) {
return $container->view->render($response->withStatus(403), 'errors/403.twig');
}

17
composer.lock generated
View file

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "3ffe3637bbcca9dc78923aca4ffdbbe6",
"content-hash": "79d2941e9db0718ad1f2766ff912f324",
"packages": [
{
"name": "container-interop/container-interop",
@ -859,16 +859,16 @@
},
{
"name": "twig/twig",
"version": "v2.6.0",
"version": "v2.6.2",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "a11dd39f5b6589e14f0ff3b36675d06047c589b1"
"reference": "7d7342c8a4059fefb9b8d07db0cc14007021f9b7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/a11dd39f5b6589e14f0ff3b36675d06047c589b1",
"reference": "a11dd39f5b6589e14f0ff3b36675d06047c589b1",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/7d7342c8a4059fefb9b8d07db0cc14007021f9b7",
"reference": "7d7342c8a4059fefb9b8d07db0cc14007021f9b7",
"shasum": ""
},
"require": {
@ -922,7 +922,7 @@
"keywords": [
"templating"
],
"time": "2018-12-16T10:36:48+00:00"
"time": "2019-01-14T15:00:48+00:00"
}
],
"packages-dev": [],
@ -935,7 +935,8 @@
"php": ">=7.1",
"ext-json": "*",
"ext-gd": "*",
"ext-pdo": "*"
"ext-pdo": "*",
"ext-zip": "*"
},
"platform-dev": []
}

View file

@ -14,6 +14,7 @@ $config = [
'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'],
'storage_dir' => 'storage',
'displayErrorDetails' => true,
'maintenance' => false,
'db' => [
'connection' => 'sqlite',
'dsn' => 'resources/database/xbackbone.db',

View file

@ -93,4 +93,5 @@ return [
'check_for_updates' => 'Check for updates',
'upgrade' => 'Upgrade',
'updates' => 'Updates',
'maintenance_in_progress' => 'Platform under maintenance, try again later...',
];

View file

@ -93,4 +93,5 @@ return [
'check_for_updates' => 'Controllo aggiornamenti',
'upgrade' => 'Upgrade',
'updates' => 'Aggiornamenti',
'maintenance_in_progress' => 'Manutenzione in corso, riprova più tardi.',
];

View file

@ -76,7 +76,7 @@
</div>
</div>
<div class="card shadow-sm">
<div class="card-header"><i class="fas fa-cloud-download-alt fa-fw"></i> {{ lang('updates') }}</div>
<div class="card-header"><i class="fas fa-cloud-download-alt fa-fw"></i> {{ lang('updates') }} <b>[BETA]</b></div>
<div class="card-body">
<div class="row">
<div class="col">

View file

@ -0,0 +1,16 @@
{% extends 'base.twig' %}
{% block title %}Under maintenance{% endblock %}
{% block content %}
<div class="container-fluid mt-5">
<div class="text-center">
<div class="row">
<div class="col-md-12">
<h1 class="display-1">Under maintenance</h1>
<p class="lead">We'll be back very soon! :)</p>
</div>
</div>
</div>
</div>
{% endblock %}