Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Module.php « Application « module - github.com/bareos/bareos-webui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c3bc745800349818496f100ce0bdec73cc5642a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?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;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Session\SessionManager;
use Zend\Session\Container;
use Bareos\BSock\BareosBsock;

class Module
{

   public function onBootstrap(MvcEvent $e)
   {
      $eventManager = $e->getApplication()->getEventManager();
      $moduleRouteListener = new ModuleRouteListener();
      $moduleRouteListener->attach($eventManager);
      $this->initSession($e);

      $translator = $e->getApplication()->getServiceManager()->get('MVCTranslator');
      $translator->setLocale( ( isset( $_SESSION['bareos']['locale'] ) ? $_SESSION['bareos']['locale'] : 'en_EN' ) )->setFallbackLocale('en_EN');

      $viewModel = $e->getApplication()->getMVCEvent()->getViewModel();
      $viewModel->dirdUpdate = $_SESSION['bareos']['dird-update-available'];

   }

   public function getConfig()
   {
      return include __DIR__ . '/config/module.config.php';
   }

   public function getAutoloaderConfig()
   {
      return array(
            'Zend\Loader\ClassMapAutoloader' => array(
            'application' => __DIR__ . '/autoload_classmap.php',
         ),
         'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
               'Bareos' => __DIR__ .'/../../vendor/Bareos/library/Bareos',
            ),
         ),
      );
   }

   public function initSession($e)
   {
      $session = $e->getApplication()->getServiceManager()->get('Zend\Session\SessionManager');

      if($session->isValid()) {
         // do nothing
      }
      else {
         $session->expireSessionCookie();
         $session->destroy();
         $session->start();
      }

      $container = new Container('bareos');

      if(!isset($container->init)) {

         $serviceManager = $e->getApplication()->getServiceManager();
         $request = $serviceManager->get('Request');

         $session->regenerateId(true);
         $container->init      = 1;
         $container->remoteAddr      = $request->getServer()->get('REMOTE_ADDR');
         $container->httpUserAgent   = $request->getServer()->get('HTTP_USER_AGENT');
         $container->username       = "";
         $container->authenticated   = false;

         $config = $serviceManager->get('Config');

         if(!isset($config['session'])) {
            return;
         }

         $sessionConfig = $config['session'];

         if(isset($sessionConfig['validators'])) {
            $chain = $session->getValidatorChain();
            foreach($sessionConfig['validators'] as $validator) {
               switch ($validator) {
                  case 'Zend\Session\Validator\HttpUserAgent':
                     $validator = new $validator($container->httpUserAgent);
                     break;
                  case 'Zend\Session\Validator\RemoteAddr':
                     $validator = new $validator($container->remoteAddr);
                     break;
                  default:
                     $validator = new $validator();
               }
               $chain->attach('session.validate', array($validator, 'isValid'));
            }
         }

      }

   }

   public function getServiceConfig()
   {
      return array(
         'factories' => array(
            'Zend\Session\SessionManager' => function ($sm) {

               $config = $sm->get('config');

               if (isset($config['session'])) {

                  $session = $config['session'];

                  $sessionConfig = null;

                  if(isset($session['config'])) {
                     $class = isset($session['config']['class'])  ? $session['config']['class'] : 'Zend\Session\Config\SessionConfig';
                     $options = isset($session['config']['options']) ? $session['config']['options'] : array();
                     $sessionConfig = new $class();
                     $sessionConfig->setOptions($options);
                  }

                  $sessionStorage = null;

                  if (isset($session['storage'])) {
                     $class = $session['storage'];
                     $sessionStorage = new $class();
                  }

                  $sessionSaveHandler = null;

                  if (isset($session['save_handler'])) {
                     // class should be fetched from service manager since it will require constructor arguments
                     $sessionSaveHandler = $sm->get($session['save_handler']);
                  }

                  $sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);

                  } else {
                     $sessionManager = new SessionManager();
                  }

                  Container::setDefaultManager($sessionManager);

                  return $sessionManager;

            },

         ),

      );

   }

}