mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-05-05 19:35:38 +02:00
Add some missing authorizeTask() checks #1483
This commit is contained in:
@@ -876,6 +876,10 @@ class AdminController extends AdminBaseController
|
||||
|
||||
protected function taskGetNewsFeed()
|
||||
{
|
||||
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache = $this->grav['cache'];
|
||||
|
||||
if ($this->post['refresh'] === 'true') {
|
||||
@@ -924,6 +928,10 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function taskGetUpdates()
|
||||
{
|
||||
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->post;
|
||||
$flush = (isset($data['flush']) && $data['flush'] == true) ? true : false;
|
||||
|
||||
@@ -970,6 +978,10 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function taskGetNotifications()
|
||||
{
|
||||
if (!$this->authorizeTask('dashboard', ['admin.login', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache = $this->grav['cache'];
|
||||
if (!(bool)$this->grav['config']->get('system.cache.enabled') || !$notifications = $cache->fetch('notifications')) {
|
||||
//No notifications cache (first time)
|
||||
@@ -1009,6 +1021,10 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function taskProcessNotifications()
|
||||
{
|
||||
if (!$this->authorizeTask('notifications', ['admin.login', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache = $this->grav['cache'];
|
||||
|
||||
$data = $this->post;
|
||||
@@ -1217,6 +1233,15 @@ class AdminController extends AdminBaseController
|
||||
$package_name = isset($data['package_name']) ? $data['package_name'] : '';
|
||||
$current_version = isset($data['current_version']) ? $data['current_version'] : '';
|
||||
|
||||
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||
$json_response = [
|
||||
'status' => 'error',
|
||||
'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||
];
|
||||
echo json_encode($json_response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$url = "https://getgrav.org/download/{$type}s/$slug/$current_version";
|
||||
|
||||
$result = Gpm::directInstall($url);
|
||||
@@ -1845,9 +1870,9 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function taskProcessMarkdown()
|
||||
{
|
||||
/*if (!$this->authorizeTask('process markdown', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('process markdown', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
|
||||
try {
|
||||
$page = $this->admin->page(true);
|
||||
@@ -2174,6 +2199,10 @@ class AdminController extends AdminBaseController
|
||||
*/
|
||||
protected function taskSwitchlanguage()
|
||||
{
|
||||
if (!$this->authorizeTask('switch language', ['admin.pages', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = (array)$this->data;
|
||||
|
||||
if (isset($data['lang'])) {
|
||||
@@ -2199,6 +2228,56 @@ class AdminController extends AdminBaseController
|
||||
$this->setRedirect('/' . $language . $admin_route . '/' . $redirect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle direct install.
|
||||
*/
|
||||
protected function taskDirectInstall()
|
||||
{
|
||||
if (!$this->authorizeTask('install', ['admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_path = isset($this->data['file_path']) ? $this->data['file_path'] : null ;
|
||||
|
||||
if (isset($_FILES['uploaded_file'])) {
|
||||
|
||||
// Check $_FILES['file']['error'] value.
|
||||
switch ($_FILES['uploaded_file']['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR'), 'error');
|
||||
return false;
|
||||
default:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS'), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_path = $_FILES['uploaded_file']['tmp_name'];
|
||||
}
|
||||
|
||||
|
||||
$result = Gpm::directInstall($file_path);
|
||||
|
||||
if ($result === true) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info');
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result,
|
||||
'error');
|
||||
}
|
||||
|
||||
$this->setRedirect('/tools');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the current page in a different language. Automatically switches to that language.
|
||||
*
|
||||
@@ -2270,49 +2349,5 @@ class AdminController extends AdminBaseController
|
||||
return $filename . '.md';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle direct install.
|
||||
*/
|
||||
protected function taskDirectInstall()
|
||||
{
|
||||
$file_path = isset($this->data['file_path']) ? $this->data['file_path'] : null ;
|
||||
|
||||
if (isset($_FILES['uploaded_file'])) {
|
||||
|
||||
// Check $_FILES['file']['error'] value.
|
||||
switch ($_FILES['uploaded_file']['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT'), 'error');
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UPLOAD_ERR_NO_TMP_DIR'), 'error');
|
||||
return false;
|
||||
default:
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS'), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_path = $_FILES['uploaded_file']['tmp_name'];
|
||||
}
|
||||
|
||||
|
||||
$result = Gpm::directInstall($file_path);
|
||||
|
||||
if ($result === true) {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info');
|
||||
} else {
|
||||
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED') . ': ' . $result,
|
||||
'error');
|
||||
}
|
||||
|
||||
$this->setRedirect('/tools');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user