Skip to content

Commit

Permalink
webui: add console controller to api module
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Apr 17, 2023
1 parent 00efe0c commit 89f20b0
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions webui/module/Api/src/Api/Controller/ConsoleController.php
@@ -0,0 +1,85 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2023 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* 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 Api\Controller;

use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\Json\Json;
use Exception;

class ConsoleController extends AbstractRestfulController
{
protected $bsock = null;
protected $directorModel = null;
protected $result = null;

public function create($data)
{
$this->RequestURIPlugin()->setRequestURI();

if (!$this->SessionTimeoutPlugin()->isValid()) {
return $this->redirect()->toRoute(
'auth',
array(
'action' => 'login'
),
array(
'query' => array(
'req' => $this->RequestURIPlugin()->getRequestURI(),
'dird' => $_SESSION['bareos']['director']
)
)
);
}

$this->bsock = $this->getServiceLocator()->get('director');
$command = $this->params()->fromPost('command');

try{
$this->result = $this->getDirectorModel()->sendDirectorCommand($this->bsock, $command);
} catch(Exception $e) {
$this->getResponse()->setStatusCode(500);
error_log($e);
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

if (isset($this->result)) {
$response->setContent(JSON::encode($this->result));
}

return $response;
}

public function getDirectorModel()
{
if (!$this->directorModel) {
$sm = $this->getServiceLocator();
$this->directorModel = $sm->get('Director\Model\DirectorModel');
}
return $this->directorModel;
}
}

0 comments on commit 89f20b0

Please sign in to comment.