diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index 10341ca5..e72e7631 100644 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -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', diff --git a/module/Auth/src/Auth/Controller/AuthController.php b/module/Auth/src/Auth/Controller/AuthController.php index b521ea7c..1a3c1046 100644 --- a/module/Auth/src/Auth/Controller/AuthController.php +++ b/module/Auth/src/Auth/Controller/AuthController.php @@ -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 @@ -34,7 +34,7 @@ class AuthController extends AbstractActionController { - protected $bsock; + protected $director; public function indexAction() { @@ -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( @@ -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( @@ -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')); } diff --git a/module/Client/src/Client/Controller/ClientController.php b/module/Client/src/Client/Controller/ClientController.php index 4f59d5b2..e5c036fa 100644 --- a/module/Client/src/Client/Controller/ClientController.php +++ b/module/Client/src/Client/Controller/ClientController.php @@ -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() { @@ -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), ) ); } diff --git a/module/Director/src/Director/Controller/DirectorController.php b/module/Director/src/Director/Controller/DirectorController.php index 1e2384f8..98f18a96 100644 --- a/module/Director/src/Director/Controller/DirectorController.php +++ b/module/Director/src/Director/Controller/DirectorController.php @@ -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 * @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/module/Fileset/src/Fileset/Controller/FilesetController.php b/module/Fileset/src/Fileset/Controller/FilesetController.php index ced7d7dc..591a9da0 100644 --- a/module/Fileset/src/Fileset/Controller/FilesetController.php +++ b/module/Fileset/src/Fileset/Controller/FilesetController.php @@ -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 @@ -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() { @@ -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'); @@ -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), ) ); } diff --git a/module/Job/src/Job/Controller/JobController.php b/module/Job/src/Job/Controller/JobController.php index 60a621a7..c364fb8a 100644 --- a/module/Job/src/Job/Controller/JobController.php +++ b/module/Job/src/Job/Controller/JobController.php @@ -28,7 +28,6 @@ use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; -use Bareos\BSock\BareosBSock; class JobController extends AbstractActionController { @@ -36,6 +35,7 @@ class JobController extends AbstractActionController protected $jobTable; protected $logTable; protected $bconsoleOutput = array(); + protected $director = null; public function indexAction() { @@ -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, ) ); @@ -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) ) ); } diff --git a/module/Storage/src/Storage/Controller/StorageController.php b/module/Storage/src/Storage/Controller/StorageController.php index d48532ed..43a20737 100644 --- a/module/Storage/src/Storage/Controller/StorageController.php +++ b/module/Storage/src/Storage/Controller/StorageController.php @@ -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() { @@ -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), ) ); } @@ -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), ) ); } diff --git a/vendor/Bareos/library/Bareos/BSock/BareosBSock.php b/vendor/Bareos/library/Bareos/BSock/BareosBSock.php index 280cc9f1..f148f89a 100644 --- a/vendor/Bareos/library/Bareos/BSock/BareosBSock.php +++ b/vendor/Bareos/library/Bareos/BSock/BareosBSock.php @@ -4,8 +4,8 @@ * * bareos-webui - Bareos Web-Frontend * - * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2014 Bareos GmbH & Co. KG + * @link https://github.com/bareos/bareos-webui for the canonical source repository + * @copyright Copyright (c) 2014-2015 Bareos GmbH & Co. KG * @license GNU Affero General Public License (http://www.gnu.org/licenses/) * * This program is free software: you can redistribute it and/or modify @@ -22,12 +22,10 @@ * along with this program. If not, see . * */ -namespace Bareos\BSock; -use Zend\ServiceManager\ServiceLocatorAwareInterface; -use Zend\ServiceManager\ServiceLocatorInterface; +namespace Bareos\BSock; -class BareosBSock implements ServiceLocatorAwareInterface +class BareosBSock implements BareosBSockInterface { const BNET_TLS_NONE = 0; /* cannot do TLS */ const BNET_TLS_OK = 1; /* can do, but not required on my end */ @@ -82,21 +80,10 @@ class BareosBSock implements ServiceLocatorAwareInterface 'allowed_cns' => null, ); - protected $serviceLocator; private $socket = null; - public function setServiceLocator(ServiceLocatorInterface $serviceLocator) - { - $this->serviceLocator = $serviceLocator; - } - - public function getServiceLocator() - { - return $this->serviceLocator; - } - /** - * Initialize the connection + * Initialize connection */ public function init() { @@ -107,6 +94,9 @@ public function init() } } + /** + * Authenticate + */ public function auth($console, $password) { if(self::connect($console, $password)) { @@ -116,6 +106,9 @@ public function auth($console, $password) } } + /** + * Set configuration + */ private function set_config_keyword($setting, $key) { if (array_key_exists($key, $this->config)) { @@ -125,6 +118,9 @@ private function set_config_keyword($setting, $key) } } + /** + * Set user credentials + */ public function set_user_credentials($username=null, $password=null) { $this->config['console_name'] = $username; @@ -149,7 +145,8 @@ public function set_config($config) } if($this->config['debug']) { - var_dump($this->config); + // extended debug: print config array + //var_dump($this->config); } } @@ -283,69 +280,144 @@ private function receive_message() // signal received switch ($len) { case self::BNET_EOD: - if($this->config['debug']) { + if ($this->config['debug']) { echo "Got BNET_EOD\n"; } - return $msg; + break; case self::BNET_EOD_POLL: + if ($this->config['debug']) { + echo "Got BNET_EOD_POLL\n"; + } break; case self::BNET_STATUS: + if ($this->config['debug']) { + echo "Got BNET_STATUS\n"; + } break; case self::BNET_TERMINATE: + if ($this->config['debug']) { + echo "Got BNET_TERMINATE\n"; + } break; case self::BNET_POLL: + if ($this->config['debug']) { + echo "Got BNET_POLL\n"; + } break; case self::BNET_HEARTBEAT: + if ($this->config['debug']) { + echo "Got BNET_HEARTBEAT\n"; + } break; case self::BNET_HB_RESPONSE: + if ($this->config['debug']) { + echo "Got BNET_HB_RESPONSE\n"; + } break; case self::BNET_xxxxxxPROMPT: + if ($this->config['debug']) { + echo "Got BNET_xxxxxxPROMPT\n"; + } break; case self::BNET_BTIME: + if ($this->config['debug']) { + echo "Got BNET_BTIME\n"; + } break; case self::BNET_BREAK: + if ($this->config['debug']) { + echo "Got BNET_BREAK\n"; + } break; case self::BNET_START_SELECT: + if ($this->config['debug']) { + echo "Got BNET_START_SELECT\n"; + } break; case self::BNET_END_SELECT: + if ($this->config['debug']) { + echo "Got BNET_END_SELECT\n"; + } break; case self::BNET_INVALID_CMD: + if ($this->config['debug']) { + echo "Got BNET_INVALID_CMD\n"; + } break; case self::BNET_CMD_FAILED: + if ($this->config['debug']) { + echo "Got BNET_CMD_FAILED\n"; + } break; case self::BNET_CMD_OK: + if ($this->config['debug']) { + echo "Got BNET_CMD_OK\n"; + } break; case self::BNET_CMD_BEGIN: + if ($this->config['debug']) { + echo "Got BNET_CMD_BEGIN\n"; + } break; case self::BNET_MSGS_PENDING: + if ($this->config['debug']) { + echo "Got BNET_MSGS_PENDING\n"; + } break; case self::BNET_MAIN_PROMPT: - if($this->config['debug']) { + if ($this->config['debug']) { echo "Got BNET_MAIN_PROMPT\n"; } - return $msg; + break; case self::BNET_SELECT_INPUT: + if ($this->config['debug']) { + echo "Got BNET_SELECT_INPUT\n"; + } break; case self::BNET_WARNING_MSG: + if ($this->config['debug']) { + echo "Got BNET_WARNINGS_MSG\n"; + } break; case self::BNET_ERROR_MSG: + if ($this->config['debug']) { + echo "Got BNET_ERROR_MSG\n"; + } break; case self::BNET_INFO_MSG: + if ($this->config['debug']) { + echo "Got BNET_INFO_MSG\n"; + } break; case self::BNET_RUN_CMD: + if ($this->config['debug']) { + echo "Got BNET_RUN_CMD\n"; + } break; case self::BNET_YESNO: + if ($this->config['debug']) { + echo "Got BNET_YESNO\n"; + } break; case self::BNET_START_RTREE: + if ($this->config['debug']) { + echo "Got BNET_START_RTREE\n"; + } break; case self::BNET_END_RTREE: + if ($this->config['debug']) { + echo "Got BNET_END_RTREE\n"; + } break; case self::BNET_SUB_PROMPT: - if($this->config['debug']) { + if ($this->config['debug']) { echo "Got BNET_SUB_PROMPT\n"; } - return $msg; + break; case self::BNET_TEXT_INPUT: + if ($this->config['debug']) { + echo "Got BNET_TEXT_INPUT\n"; + } break; default: throw new \Exception("Received unknown signal " . $len . "\n"); @@ -471,11 +543,15 @@ private function connect($username, $password) */ public function disconnect() { - fclose($this->socket); - if($this->config['debug']) { - echo "Connection to " . $this->config['host'] . " on port " . $this->config['port'] . " closed\n"; + if ($this->socket != null) { + fclose($this->socket); + if ($this->config['debug']) { + echo "Connection to " . $this->config['host'] . " on port " . $this->config['port'] . " closed\n"; + } + return true; } - return true; + + return false; } /** diff --git a/vendor/Bareos/library/Bareos/BSock/BareosBSockAbstractServiceFactory.php b/vendor/Bareos/library/Bareos/BSock/BareosBSockAbstractServiceFactory.php new file mode 100644 index 00000000..94e0f55b --- /dev/null +++ b/vendor/Bareos/library/Bareos/BSock/BareosBSockAbstractServiceFactory.php @@ -0,0 +1,89 @@ +. + * + */ + +namespace Bareos\BSock; + +use Zend\ServiceManager\AbstractFactoryInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class BSockAbstractServiceFactory implements AbstractFactoryInterface +{ + + protected $config; + + /** + */ + public function canCreateServiceWithName(ServiceLocatorInterface $service, $name $requestedName) + { + $config = $this->getConfig($service); + + if (empty($config)) { + return false; + } + + return ( + isset($config[$requestedName]) + && is_array($config[$requestedName]) + && !empty($config[$requestedName]) + ); + + } + + /** + */ + public function createServiceWithName(ServiceLocatorInterface $service, $name, $requestedName) + { + $config = $this->getConfig($service); + return new BSock($config[$requestedName]); + } + + /** + */ + protected function getConfig() + { + if ($this->config !== null) { + return $this->config; + } + + if (!$service->has('Config')) { + $this->config = array(); + return $this->config; + } + + $config = $service->get('Config'); + if (!isset($config['directors']) || !is_array($config['directors'])) { + $this->config = array(); + return $this->config; + } + + // todo + + $this->config = $config['directors'][$_SESSION['bareos']['director']]; + + return $this->config; + + } + +} diff --git a/vendor/Bareos/library/Bareos/BSock/BareosBSockInterface.php b/vendor/Bareos/library/Bareos/BSock/BareosBSockInterface.php new file mode 100644 index 00000000..002cf9fd --- /dev/null +++ b/vendor/Bareos/library/Bareos/BSock/BareosBSockInterface.php @@ -0,0 +1,76 @@ +. + * + */ + +namespace Bareos\BSock; + +interface BareosBSockInterface +{ + /** + * Initialize connection + * + * @return boolean + */ + public function init(); + + /** + * Authenticate + * + * @param $console + * @param $password + * @return boolean + */ + public function auth($console, $password); + + /** + * Set user credentials + * + * @param $username + * @param password + */ + public function set_user_credentials($username=null, $password=null); + + /** + * Set configuration + * + * @param $config + */ + public function set_config($config); + + /** + * Disconnect + * + * @return boolean + */ + public function disconnect(); + + /** + * Send command + * + * @param $cmd + * @return string + */ + public function send_command($cmd); + +} diff --git a/vendor/Bareos/library/Bareos/BSock/BareosBSockServiceFactory.php b/vendor/Bareos/library/Bareos/BSock/BareosBSockServiceFactory.php new file mode 100644 index 00000000..d5b82215 --- /dev/null +++ b/vendor/Bareos/library/Bareos/BSock/BareosBSockServiceFactory.php @@ -0,0 +1,50 @@ +. + * + */ + +namespace Bareos\BSock; + +use Zend\ServiceManager\FactoryInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class BareosBSockServiceFactory implements FactoryInterface +{ + protected $bsock; + + /** + */ + public function createService(ServiceLocatorInterface $serviceLocator) + { + $config = $serviceLocator->get('Config'); + $this->bsock = new BareosBSock($config['directors']); + + if (isset($_SESSION['bareos']['director'])) { + $this->bsock->set_config($config['directors'][$_SESSION['bareos']['director']]); + $this->bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']); + $this->bsock->init(); + } + + return $this->bsock; + } +}