2021-07-05 14:39:51 +02:00
|
|
|
<?php
|
|
|
|
|
2022-11-27 19:30:41 +01:00
|
|
|
use Formwork\Formwork;
|
2022-12-11 16:48:45 +01:00
|
|
|
use Formwork\Panel\Security\CSRFToken;
|
2022-11-27 19:30:41 +01:00
|
|
|
use Formwork\Response\JSONResponse;
|
2022-11-28 23:05:44 +01:00
|
|
|
use Formwork\Response\RedirectResponse;
|
|
|
|
use Formwork\Utils\FileSystem;
|
2022-11-27 19:30:41 +01:00
|
|
|
use Formwork\Utils\HTTPRequest;
|
|
|
|
use Formwork\Utils\Session;
|
|
|
|
|
2021-07-05 14:39:51 +02:00
|
|
|
return [
|
|
|
|
'routes' => [
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.index' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => fn () => new RedirectResponse(Formwork::instance()->panel()->uri('/dashboard/')),
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.login' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/login/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\\Panel\\Controllers\\AuthenticationController@login',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.logout' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/logout/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\\Panel\\Controllers\\AuthenticationController@logout',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.backup.make' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/backup/make/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\\Panel\\Controllers\\BackupController@make',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.backup.download' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/backup/download/{backup}/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\\Panel\\Controllers\\BackupController@download',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.cache.clear' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/cache/clear/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\\Panel\\Controllers\\CacheController@clear',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.dashboard' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/dashboard/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\DashboardController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.system' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/system/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@systemOptions',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.site' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/site/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@siteOptions',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.updates' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/updates/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@updates',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.info' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/info/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@info',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.new' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/new/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@create',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.edit' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/edit/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@edit',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.edit.lang' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/edit/language/{language}/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@edit',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.reorder' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/reorder/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@reorder',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.uploadfile' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/file/upload/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@uploadFile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.deletefile' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/file/{filename}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@deleteFile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.delete' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.delete.lang' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/delete/language/{language}/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.updates.check' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/updates/check/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UpdatesController@check',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.updates.update' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/updates/update/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UpdatesController@update',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.new' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/new/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@create',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.delete' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/{user}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.profile' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/{user}/profile/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@profile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2022-11-23 22:50:16 +01:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-28 23:05:44 +01:00
|
|
|
'panel.register' => [
|
|
|
|
'path' => '/register/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\RegisterController@register',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2022-11-28 23:05:44 +01:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.errors.notfound' => [
|
2022-12-11 16:48:45 +01:00
|
|
|
'path' => '/{route}/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\ErrorsController@notFound',
|
|
|
|
],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2021-07-05 14:39:51 +02:00
|
|
|
'filters' => [
|
2022-12-06 21:26:54 +01:00
|
|
|
'request.validateSize' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'action' => static function () {
|
2022-11-28 23:05:44 +01:00
|
|
|
// Validate HTTP request Content-Length according to `post_max_size` directive
|
|
|
|
if (HTTPRequest::contentLength() !== null) {
|
|
|
|
$maxSize = FileSystem::shorthandToBytes(ini_get('post_max_size'));
|
|
|
|
|
|
|
|
if (HTTPRequest::contentLength() > $maxSize && $maxSize > 0) {
|
|
|
|
$panel = Formwork::instance()->panel();
|
|
|
|
$panel->notify(
|
2022-12-06 21:26:54 +01:00
|
|
|
Formwork::instance()->translations()->getCurrent()->translate('panel.request.error.postMaxSize'),
|
2022-11-28 23:05:44 +01:00
|
|
|
'error'
|
|
|
|
);
|
|
|
|
return new RedirectResponse($panel->uri());
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2022-12-06 21:26:54 +01:00
|
|
|
'request.validateCsrf' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'action' => static function () {
|
|
|
|
// Validate CSRF token
|
|
|
|
try {
|
2022-11-27 19:30:41 +01:00
|
|
|
CSRFToken::validate();
|
2021-07-05 14:39:51 +02:00
|
|
|
} catch (RuntimeException $e) {
|
2022-11-27 19:30:41 +01:00
|
|
|
CSRFToken::destroy();
|
|
|
|
Session::remove('FORMWORK_USERNAME');
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
$panel = Formwork::instance()->panel();
|
|
|
|
$panel->notify(
|
2022-12-06 21:26:54 +01:00
|
|
|
Formwork::instance()->translations()->getCurrent()->translate('panel.login.suspiciousRequestDetected'),
|
2022-11-28 23:05:44 +01:00
|
|
|
'warning'
|
|
|
|
);
|
|
|
|
|
2022-11-27 19:30:41 +01:00
|
|
|
if (HTTPRequest::isXHR()) {
|
|
|
|
return JSONResponse::error('Bad Request: the CSRF token is not valid', 400);
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
return new RedirectResponse($panel->uri('/login/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['HTTP', 'XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.register' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'action' => static function () {
|
2022-11-27 21:21:19 +01:00
|
|
|
$panel = Formwork::instance()->panel();
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
// Register panel if no user exists
|
|
|
|
if ($panel->users()->isEmpty()) {
|
2022-11-27 19:30:41 +01:00
|
|
|
if (!HTTPRequest::isLocalhost()) {
|
2022-11-28 23:05:44 +01:00
|
|
|
return new RedirectResponse(Formwork::instance()->site()->uri());
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
if ($panel->route() !== '/register/') {
|
|
|
|
return new RedirectResponse($panel->uri('/register/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2022-12-06 21:26:54 +01:00
|
|
|
'panel.redirectToLogin' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'action' => static function () {
|
2022-11-27 21:21:19 +01:00
|
|
|
$panel = Formwork::instance()->panel();
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2021-07-05 14:39:51 +02:00
|
|
|
// Redirect to login if no user is logged
|
2022-11-28 23:05:44 +01:00
|
|
|
if (!$panel->users()->isEmpty() && !$panel->isLoggedIn() && $panel->route() !== '/login/') {
|
2022-11-27 21:21:19 +01:00
|
|
|
Session::set('FORMWORK_REDIRECT_TO', $panel->route());
|
2022-11-28 23:05:44 +01:00
|
|
|
return new RedirectResponse($panel->uri('/login/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2023-05-20 21:26:49 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2021-07-05 14:39:51 +02:00
|
|
|
];
|