Skip to content

Commit

Permalink
webui: update analytics controller
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Mar 10, 2022
1 parent daf9329 commit 5853baf
Showing 1 changed file with 99 additions and 1 deletion.
Expand Up @@ -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();
}

}
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;
}

}

0 comments on commit 5853baf

Please sign in to comment.