Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Required Command ACL validation
Browse files Browse the repository at this point in the history
This adds a new controller plugin to validate in each controller action
if all required commands to run the module properly are given in the
used Console/Profile Command ACL.

Additionally a new view helper is introduced to centralize the ACL alert
message which is displayed when the given Command ACL does not fit the
requirements.

This commit changes the views and controllers of the following modules:

- Dashboard
- Jobs
- Restore
- Clients
- Schedules
- Storages
- Pools
- Media/Volumes
- Director

Furthermore this commit removes some whitespace from the Director Model.
  • Loading branch information
fbergkemper committed Oct 12, 2016
1 parent cbcc032 commit 00439f5
Show file tree
Hide file tree
Showing 36 changed files with 533 additions and 3 deletions.
1 change: 1 addition & 0 deletions module/Application/config/module.config.php
Expand Up @@ -90,6 +90,7 @@
'invokables' => array (
//'printExample' => 'Application\View\Helper\Example', // Example ViewHelper
'UpdateAlert' => 'Application\View\Helper\UpdateAlert',
'ACLAlert' => 'Application\View\Helper\ACLAlert',
),
),
'view_manager' => array(
Expand Down
@@ -0,0 +1,24 @@
<?php

namespace Application\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\AbstractPlugin;

class CommandACLPlugin extends AbstractPlugin
{
private $commands = null;
private $required = null;

public function validate($commands=null, $required=null)
{
$this->commands = $commands;
$this->required = $required;

foreach($this->required as $cmd) {
if($this->commands[$cmd]['permission'] == 0) {
return false;
}
}
return true;
}
}
63 changes: 63 additions & 0 deletions module/Application/src/Application/View/Helper/ACLAlert.php
@@ -0,0 +1,63 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Application\View\Helper;

use Zend\View\Helper\AbstractHelper;

class ACLAlert extends AbstractHelper
{
private $required_commands = null;
private $alert = null;

public function __invoke($required_commands)
{
$msg_part_a = _('Sorry, it seems you are not authorized to run this module. If you think this is an error, please contact your local administrator.');
$msg_part_b = _('Please read the <a href="http://doc.bareos.org/master/html/bareos-manual-main-reference.html#sec:webui-console" target="_blank">Bareos documentation</a> for any additional information on how to configure the Command ACL directive of your Console/Profile resources. Following is a list of required commands which need to be in your Command ACL to run this module properly:');

$this->required_commands = $required_commands;

$this->alert = '<div class="container-fluid">';
$this->alert .= '<div class="row">';
$this->alert .= '<div class="col-md-6">';
$this->alert .= '<div class="alert alert-danger"><b>'.$msg_part_a.'</b></div>';
$this->alert .= $msg_part_b;

$this->alert .= '</br></br>';
$this->alert .= '<ul>';

foreach($this->required_commands as $cmd) {
$this->alert .= '<li>'.$cmd.'</li>';
}

$this->alert .= '</ul>';
$this->alert .= '</div>';
$this->alert .= '<div class="col-md-6"></div>';
$this->alert .= '</div>';
$this->alert .= '</div>';

return $this->alert;
}
}
27 changes: 26 additions & 1 deletion module/Auth/src/Auth/Controller/AuthController.php
Expand Up @@ -92,7 +92,6 @@ public function loginAction()

try {
$dird_version = $this->getDirectorModel()->getDirectorVersion($this->bsock);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
Expand Down Expand Up @@ -132,6 +131,30 @@ public function loginAction()
$_SESSION['bareos']['product-updates-status'] = false;
}

// Get available commands
try {
$commands = $this->getDirectorModel()->getAvailableCommands($this->bsock);
}
catch(Exception $e) {
echo $e->getMessage();
}

// Push available commands into SESSION context.
$_SESSION['bareos']['commands'] = $commands;

// Check if Command ACL has the minimal requirements
if($_SESSION['bareos']['commands']['.help']['permission'] == 0) {
$this->bsock->disconnect();
session_destroy();
$err_msg = 'Sorry, your Command ACL does not fit the minimal requirements. For further information, please read the <a href="http://doc.bareos.org/master/html/bareos-manual-main-reference.html" target="_blank">Bareos documentation</a>.';
return new ViewModel(
array(
'form' => $form,
'err_msg' => $err_msg,
)
);
}

// Get the config.
$configuration = $this->getServiceLocator()->get('configuration');

Expand All @@ -151,6 +174,8 @@ public function loginAction()
else {
return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
}

$this->bsock->disconnect();
} else {
$this->bsock->disconnect();
session_destroy();
Expand Down
21 changes: 21 additions & 0 deletions module/Auth/view/auth/auth/login.phtml
Expand Up @@ -161,6 +161,27 @@ $this->headTitle($title);

</diV>

<div class="row">

<!-- Left space -->
<div class="col-md-3">
</div>

<!-- ALERTS -->
<?php
if(!empty($this->err_msg)) {
echo '<div class="col-md-6 alert alert-danger" role="alert">';
echo $this->err_msg;
echo '</div>';
}
?>

<!-- Right space -->
<div class="col-md-3">
</div>

</div>

<script>

/*
Expand Down
39 changes: 39 additions & 0 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -35,6 +35,15 @@ class ClientController extends AbstractActionController
protected $clientModel = null;
protected $directorModel = null;
protected $bsock = null;
protected $acl_alert = false;

private $required_commands = array(
"llist",
"status",
"enable",
"disable",
"version"
);

public function indexAction()
{
Expand All @@ -44,6 +53,16 @@ public function indexAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

$result = null;

$action = $this->params()->fromQuery('action');
Expand Down Expand Up @@ -101,6 +120,16 @@ public function detailsAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

return new ViewModel(
array(
'client' => $this->params()->fromRoute('id')
Expand All @@ -116,6 +145,16 @@ public function statusAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

$result = null;

$clientname = $this->params()->fromQuery('client');
Expand Down
4 changes: 4 additions & 0 deletions module/Client/view/client/client/index.phtml
Expand Up @@ -34,6 +34,8 @@ $this->headTitle($title);

<br />

<?php if($this->acl_alert) : echo $this->ACLAlert($this->required_commands); elseif(!$this->acl_alert) : ?>

<div class="row">

<div class="col-md-8">
Expand Down Expand Up @@ -275,3 +277,5 @@ $(document).ready(function() {
} );

</script>

<?php endif; ?>
16 changes: 16 additions & 0 deletions module/Dashboard/src/Dashboard/Controller/DashboardController.php
Expand Up @@ -35,6 +35,12 @@ class DashboardController extends AbstractActionController
protected $jobModel = null;
protected $dashboardModel = null;
protected $bsock = null;
protected $acl_alert = false;

private $required_commands = array(
"list",
"llist"
);

public function indexAction()
{
Expand All @@ -44,6 +50,16 @@ public function indexAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

try {
$this->bsock = $this->getServiceLocator()->get('director');
$running = $this->getJobs("running", 1, null);
Expand Down
4 changes: 4 additions & 0 deletions module/Dashboard/view/dashboard/dashboard/index.phtml
Expand Up @@ -29,6 +29,8 @@ $this->headTitle($title);

?>

<?php if($this->acl_alert) : echo $this->ACLAlert($this->required_commands); elseif(!$this->acl_alert) : ?>

<div class="row">

<div class="col-md-4">
Expand Down Expand Up @@ -189,3 +191,5 @@ $this->headTitle($title);
);

</script>

<?php endif; ?>
38 changes: 38 additions & 0 deletions module/Director/src/Director/Controller/DirectorController.php
Expand Up @@ -33,6 +33,14 @@ class DirectorController extends AbstractActionController
{
protected $directorModel = null;
protected $bsock = null;
protected $acl_alert = false;

private $required_commands = array(
"list",
"llist",
"status",
"help"
);

public function indexAction()
{
Expand All @@ -42,6 +50,16 @@ public function indexAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getDirectorModel()->getDirectorStatus($this->bsock);
Expand All @@ -64,6 +82,16 @@ public function messagesAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

return new ViewModel();
}

Expand All @@ -75,6 +103,16 @@ public function consoleAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if(!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

return new ViewModel();
}

Expand Down
13 changes: 13 additions & 0 deletions module/Director/src/Director/Model/DirectorModel.php
Expand Up @@ -27,6 +27,19 @@

class DirectorModel
{
public function getAvailableCommands(&$bsock=null)
{
if(isset($bsock)) {
$cmd = '.help';
$result = $bsock->send_command($cmd, 2, null);
$messages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $messages['result'];
}
else {
throw new \Exception('Missing argument.');
}
}

public function getDirectorVersion(&$bsock=null)
{
if(isset($bsock)) {
Expand Down

0 comments on commit 00439f5

Please sign in to comment.