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

Commit

Permalink
refactored native connectivity
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Bergkemper <frank.bergkemper@dass-it.de>
  • Loading branch information
fbergkemper committed Apr 8, 2015
1 parent 6648e39 commit 10d3f2d
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 131 deletions.
2 changes: 1 addition & 1 deletion module/Application/config/module.config.php
Expand Up @@ -58,13 +58,13 @@
'Zend\Log\LoggerAbstractServiceFactory',
),
'services' => array(
'bsock' => new Bareos\BSock\BareosBSock(),
),
'shared' => array(
),
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'director' => 'Bareos\BSock\BareosBSockServiceFactory',
),
'aliases' => array(
//'translator' => 'MvcTranslator',
Expand Down
37 changes: 10 additions & 27 deletions module/Auth/src/Auth/Controller/AuthController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2015 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
Expand Down Expand Up @@ -34,7 +34,7 @@
class AuthController extends AbstractActionController
{

protected $bsock;
protected $director;

public function indexAction()
{
Expand Down Expand Up @@ -70,29 +70,21 @@ public function loginAction()
$password = $form->getInputFilter()->getValue('password');

$config = $this->getServiceLocator()->get('Config');
$this->bsock = $this->getServiceLocator()->get('bsock');
$this->bsock->set_config($config['directors'][$director]);
$this->bsock->set_user_credentials($username, $password);
$this->director = $this->getServiceLocator()->get('director');
$this->director->set_config($config['directors'][$director]);
$this->director->set_user_credentials($username, $password);

if($this->bsock->auth($username, $password)) {
//$session = new Container('user');
if($this->director->auth($username, $password)) {
$_SESSION['bareos']['director'] = $director;
$_SESSION['bareos']['username'] = $username;
$_SESSION['bareos']['password'] = $password;
$_SESSION['bareos']['authenticated'] = true;
$_SESSION['bareos']['socket'] = $this->bsock;
$this->bsock->disconnect();
$this->director->disconnect();
return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
} else {

// todo - give user a message about what went wrong

// if we get false, wrong credentials(username, password) in this case, pass a message in auth action login and display
// if we get a exception the socket could not be initialized for whatever reason

$this->bsock->disconnect();
$this->director->disconnect();
session_destroy();
//return $this->redirect()->toRoute('auth', array('action' => 'login'));
$err_msg = "Sorry, can not authenticate. Wrong username and/or password.";
return new ViewModel(
array(
Expand All @@ -104,14 +96,10 @@ public function loginAction()

} else {

// todo - give user a message about what went wrong

// given credentials in login form could not be validated in this case
$err_msg = "Please provide a director, username and password.";

//$this->bsock->disconnect();
session_destroy();
//return $this->redirect()->toRoute('auth', array('action' => 'login'));

return new ViewModel(
array(
Expand All @@ -134,14 +122,9 @@ public function loginAction()

public function logoutAction()
{

// todo - ask user if he's really sure to logout!
// "Do you really want to logout?"

unset($_SESSION['user']);
// todo - ask user if he's really wants to log out!
unset($_SESSION['bareos']);
session_destroy();
//$this->bsock = $this->getServiceLocator()->get('bsock');
//$this->bsock->disconnect();
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}

Expand Down
10 changes: 3 additions & 7 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -4,13 +4,13 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BSock\BareosBSock;

class ClientController extends AbstractActionController
{

protected $clientTable;
protected $jobTable;
protected $director;

public function indexAction()
{
Expand Down Expand Up @@ -46,17 +46,13 @@ public function detailsAction()

$result = $this->getClientTable()->getClient($id);
$cmd = 'status client="' . $result->name . '"';
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');

return new ViewModel(
array(
'client' => $this->getClientTable()->getClient($id),
'job' => $this->getJobTable()->getLastSuccessfulClientJob($id),
'bconsoleOutput' => $bsock->send_command($cmd),
'bconsoleOutput' => $this->director->send_command($cmd),
)
);
}
Expand Down
44 changes: 12 additions & 32 deletions module/Director/src/Director/Controller/DirectorController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
Expand All @@ -28,24 +28,20 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BSock\BareosBSock;

class DirectorController extends AbstractActionController
{

protected $director = null;
protected $directorOutput = array();

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] == true) {
$cmd = "status director";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'directorOutput' => $bsock->send_command($cmd),
'directorOutput' => $this->director->send_command($cmd),
));
}
else {
Expand All @@ -57,13 +53,9 @@ public function messagesAction()
{
if($_SESSION['bareos']['authenticated'] == true) {
$cmd = "messages";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'directorOutput' => $bsock->send_command($cmd),
'directorOutput' => $this->director->send_command($cmd),
));
}
else {
Expand All @@ -75,13 +67,9 @@ public function scheduleAction()
{
if($_SESSION['bareos']['authenticated'] == true) {
$cmd = "show schedule";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'directorOutput' => $bsock->send_command($cmd),
'directorOutput' => $this->director->send_command($cmd),
));
}
else {
Expand All @@ -93,13 +81,9 @@ public function schedulerstatusAction()
{
if($_SESSION['bareos']['authenticated'] == true) {
$cmd = "status scheduler";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'directorOutput' => $bsock->send_command($cmd),
'directorOutput' => $this->director->send_command($cmd),
));
}
else {
Expand All @@ -111,13 +95,9 @@ public function versionAction()
{
if($_SESSION['bareos']['authenticated'] == true) {
$cmd = "version";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'directorOutput' => $bsock->send_command($cmd),
'directorOutput' => $this->director->send_command($cmd),
));
}
else {
Expand Down
14 changes: 5 additions & 9 deletions module/Fileset/src/Fileset/Controller/FilesetController.php
Expand Up @@ -3,9 +3,9 @@
/**
*
* bareos-webui - Bareos Web-Frontend
*
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2015 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
Expand All @@ -27,12 +27,12 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BSock\BareosBSock;

class FilesetController extends AbstractActionController
{

protected $filesetTable;
protected $director;

public function indexAction()
{
Expand Down Expand Up @@ -64,11 +64,7 @@ public function detailsAction()
$id = (int) $this->params()->fromRoute('id', 0);
$fset = $this->getFilesetTable()->getFileSet($id);
$cmd = 'show fileset="' . $fset->fileset . '"';
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');

if (!$id) {
return $this->redirect()->toRoute('fileset');
Expand All @@ -78,7 +74,7 @@ public function detailsAction()
array(
'fileset' => $this->getFilesetTable()->getFileset($id),
'history' => $this->getFilesetTable()->getFilesetHistory($id),
'configuration' => $bsock->send_command($cmd),
'configuration' => $this->director->send_command($cmd),
)
);
}
Expand Down
18 changes: 5 additions & 13 deletions module/Job/src/Job/Controller/JobController.php
Expand Up @@ -28,14 +28,14 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BSock\BareosBSock;

class JobController extends AbstractActionController
{

protected $jobTable;
protected $logTable;
protected $bconsoleOutput = array();
protected $director = null;

public function indexAction()
{
Expand Down Expand Up @@ -185,14 +185,10 @@ public function rerunAction()
if($_SESSION['bareos']['authenticated'] == true) {
$jobid = (int) $this->params()->fromRoute('id', 0);
$cmd = "rerun jobid=" . $jobid . " yes";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(
array(
'bconsoleOutput' => $bsock->send_command($cmd),
'bconsoleOutput' => $this->director->send_command($cmd),
'jobid' => $jobid,
)
);
Expand All @@ -207,14 +203,10 @@ public function cancelAction()
if($_SESSION['bareos']['authenticated'] == true) {
$jobid = (int) $this->params()->fromRoute('id', 0);
$cmd = "cancel jobid=" . $jobid . " yes";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(
array(
'bconsoleOutput' => $bsock->send_command($cmd)
'bconsoleOutput' => $this->director->send_command($cmd)
)
);
}
Expand Down
18 changes: 5 additions & 13 deletions module/Storage/src/Storage/Controller/StorageController.php
Expand Up @@ -27,13 +27,13 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BSock\BareosBSock;

class StorageController extends AbstractActionController
{

protected $storageTable;
protected $bconsoleOutput = array();
protected $director;

public function indexAction()
{
Expand Down Expand Up @@ -69,13 +69,9 @@ public function detailsAction()
}
$result = $this->getStorageTable()->getStorage($id);
$cmd = "status storage=" . $result->name;
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'bconsoleOutput' => $bsock->send_command($cmd),
'bconsoleOutput' => $this->director->send_command($cmd),
)
);
}
Expand All @@ -93,13 +89,9 @@ public function autochangerAction()
}
$result = $this->getStorageTable()->getStorage($id);
$cmd = "status storage=" . $result->name . " slots";
$config = $this->getServiceLocator()->get('Config');
$bsock = new BareosBSock();
$bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
$bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
$bsock->init();
$this->director = $this->getServiceLocator()->get('director');
return new ViewModel(array(
'bconsoleOutput' => $bsock->send_command($cmd),
'bconsoleOutput' => $this->director->send_command($cmd),
)
);
}
Expand Down

0 comments on commit 10d3f2d

Please sign in to comment.