diff --git a/webui/module/Analytics/src/Analytics/Controller/AnalyticsController.php b/webui/module/Analytics/src/Analytics/Controller/AnalyticsController.php index 4333516fdb9..bf18a8f118f 100644 --- a/webui/module/Analytics/src/Analytics/Controller/AnalyticsController.php +++ b/webui/module/Analytics/src/Analytics/Controller/AnalyticsController.php @@ -32,9 +32,107 @@ class AnalyticsController extends AbstractActionController { + protected $analyticsModel = null; + public function indexAction() { + $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'] + ) + ) + ); + } + + $module_config = $this->getServiceLocator()->get('ModuleManager')->getModule('Application')->getConfig(); + $invalid_commands = $this->CommandACLPlugin()->getInvalidCommands( + $module_config['console_commands']['Analytics']['mandatory'] + ); + + if(count($invalid_commands) > 0) { + $this->acl_alert = true; + return new ViewModel( + array( + 'acl_alert' => $this->acl_alert, + 'invalid_commands' => implode(",", $invalid_commands) + ) + ); + } + return new ViewModel(); } -} \ No newline at end of file + public function getDataAction() + { + $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'] + ) + ) + ); + } + + $result = null; + + $data = $this->params()->fromQuery('data'); + + if($data == "jobtotals") { + try { + $this->bsock = $this->getServiceLocator()->get('director'); + $result = $this->getAnalyticsModel()->getJobTotals($this->bsock); + $this->bsock->disconnect(); + } + catch(Exception $e) { + echo $e->getMessage(); + } + } + elseif($data == "overall-jobtotals") { + try { + $this->bsock = $this->getServiceLocator()->get('director'); + $result = $this->getAnalyticsModel()->getOverallJobTotals($this->bsock); + $this->bsock->disconnect(); + } + catch(Exception $e) { + echo $e->getMessage(); + } + } + + $response = $this->getResponse(); + $response->getHeaders()->addHeaderLine('Content-Type', 'application/json'); + + if(isset($result)) { + $response->setContent(JSON::encode($result)); + } + + return $response; + + } + + public function getAnalyticsModel() + { + if(!$this->analyticsModel) { + $sm = $this->getServiceLocator(); + $this->analyticsModel = $sm->get('Analytics\Model\AnalyticsModel'); + } + return $this->analyticsModel; + } + +}