1<?php
2
3/**
4 *
5 * bareos-webui - Bareos Web-Frontend
6 *
7 * @link      https://github.com/bareos/bareos for the canonical source repository
8 * @copyright Copyright (c) 2014-2015 Bareos GmbH & Co. KG
9 * @license   GNU Affero General Public License (http://www.gnu.org/licenses/)
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26namespace Bareos\BSock;
27
28use Zend\ServiceManager\FactoryInterface;
29use Zend\ServiceManager\ServiceLocatorInterface;
30
31class BareosBSockServiceFactory implements FactoryInterface
32{
33   protected $bsock;
34
35   /**
36    */
37   public function createService(ServiceLocatorInterface $serviceLocator)
38   {
39      $config = $serviceLocator->get('Config');
40      $this->bsock = new BareosBSock($config['directors']);
41
42      if (isset($_SESSION['bareos']['director'])) {
43         $this->bsock->set_config($config['directors'][$_SESSION['bareos']['director']]);
44         $this->bsock->set_user_credentials($_SESSION['bareos']['username'], $_SESSION['bareos']['password']);
45         $this->bsock->connect_and_authenticate();
46      }
47
48      return $this->bsock;
49   }
50}
51