mirror of
https://github.com/cosmocode/dokuwiki-plugin-farmer.git
synced 2025-07-22 18:27:56 +00:00
limit remote access to superuser
This commit is contained in:
23
remote.php
23
remote.php
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Extension\RemotePlugin;
|
||||
use dokuwiki\Remote\AccessDeniedException;
|
||||
|
||||
class remote_plugin_farmer extends RemotePlugin {
|
||||
/** @var helper_plugin_farmer hlp */
|
||||
@ -20,9 +21,11 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
* Get the configured farm host
|
||||
*
|
||||
* @return string
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function getFarmhost(): string
|
||||
{
|
||||
$this->ensureAdmin();
|
||||
return $this->helper->getConfig()['base']['farmhost'];
|
||||
}
|
||||
|
||||
@ -31,9 +34,11 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
* This could be an empty string, then farmhost will be used to determine an animal url
|
||||
*
|
||||
* @return string
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function getBaseDomain(): string
|
||||
{
|
||||
$this->ensureAdmin();
|
||||
return $this->helper->getConfig()['base']['basedomain'];
|
||||
}
|
||||
|
||||
@ -41,9 +46,11 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
* Get a list of all animal names
|
||||
*
|
||||
* @return array
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function listAnimals(): array
|
||||
{
|
||||
$this->ensureAdmin();
|
||||
return $this->helper->getAllAnimals();
|
||||
}
|
||||
|
||||
@ -51,9 +58,11 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
* Get a list of all animal urls
|
||||
*
|
||||
* @return array
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function listAnimalUrls(): array
|
||||
{
|
||||
$this->ensureAdmin();
|
||||
foreach($this->helper->getAllAnimals() as $animal) {
|
||||
$animalUrls[] = $this->helper->getAnimalURL($animal);
|
||||
}
|
||||
@ -64,9 +73,11 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
* Get configuration details of farmer plugin enriched by list of animals
|
||||
*
|
||||
* @return array
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function getFarmerConfig(): array
|
||||
{
|
||||
$this->ensureAdmin();
|
||||
$farmerConfig = $this->helper->getConfig();
|
||||
foreach($this->helper->getAllAnimals() as $index=>$animal) {
|
||||
$farmerConfig['animals'][$index]["name"] =$animal;
|
||||
@ -74,4 +85,16 @@ class remote_plugin_farmer extends RemotePlugin {
|
||||
}
|
||||
return $farmerConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
private function ensureAdmin() {
|
||||
if (!auth_isadmin()) {
|
||||
throw new AccessDeniedException(
|
||||
'You are not allowed to access farmer configuration, superuser permission is required',
|
||||
114
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user