Skip to content

Commit

Permalink
webui: remove getData action from dashboard controller
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Apr 17, 2023
1 parent d68f27c commit 3d83c57
Showing 1 changed file with 0 additions and 190 deletions.
Expand Up @@ -27,25 +27,11 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Json\Json;
use Exception;

class DashboardController extends AbstractActionController
{
/**
* Variables
*/
protected $directorModel = null;
protected $jobModel = null;
protected $dashboardModel = null;
protected $bsock = null;
protected $acl_alert = false;

/**
* Index Action
*
* @return object
*/
public function indexAction()
{
$this->RequestURIPlugin()->setRequestURI();
Expand Down Expand Up @@ -81,180 +67,4 @@ public function indexAction()

return new ViewModel();
}

/**
* Get Data Action
*
* @return object
*/
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 == "jobslaststatus") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJobsLastStatus($this->bsock);
$this->bsock->disconnect();
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "jobspast24h") {
$days = 1;
$hours = null;
$waiting = null;
$running = null;
$successful = null;
$warning = null;
$failed = null;
$result = null;

try {
$this->bsock = $this->getServiceLocator()->get('director');

// waiting
$jobs_F = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'F', $days, $hours);
$jobs_S = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'S', $days, $hours);
$jobs_s = $this->getJobModel()->getJobsByStatus($this->bsock, null, 's', $days, $hours);
$jobs_m = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'm', $days, $hours);
$jobs_M = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'M', $days, $hours);
$jobs_j = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'j', $days, $hours);
$jobs_c = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'c', $days, $hours);
$jobs_C = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'C', $days, $hours);
$jobs_d = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'd', $days, $hours);
$jobs_t = $this->getJobModel()->getJobsByStatus($this->bsock, null, 't', $days, $hours);
$jobs_p = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'p', $days, $hours);
$jobs_q = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'q', $days, $hours);
$waiting = count($jobs_F) + count($jobs_S) +
count($jobs_s) + count($jobs_m) +
count($jobs_M) + count($jobs_j) +
count($jobs_c) + count($jobs_C) +
count($jobs_d) + count($jobs_t) +
count($jobs_p) + count($jobs_q);

// running
$jobs_R = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'R', $days, $hours);
$jobs_l = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'l', $days, $hours);
$running = count($jobs_R) + count($jobs_l);

// successful
$jobs_T = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'T', $days, $hours);
$successful = count($jobs_T);

// warning
$jobs_A = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'A', $days, $hours);
$jobs_W = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'W', $days, $hours);
$warning = count($jobs_A) + count($jobs_W);

// failed
$jobs_E = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'E', $days, $hours);
$jobs_e = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'e', $days, $hours);
$jobs_f = $this->getJobModel()->getJobsByStatus($this->bsock, null, 'f', $days, $hours);
$failed = count($jobs_E) + count($jobs_e) + count($jobs_f);

// json result
$result['waiting'] = $waiting;
$result['running'] = $running;
$result['successful'] = $successful;
$result['warning'] = $warning;
$result['failed'] = $failed;
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "runningjobs") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getRunningJobsStatistics($this->bsock);
$this->bsock->disconnect();
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "jobtotals") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getJobModel()->getJobTotals($this->bsock);
$this->bsock->disconnect();
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "dirdmsg") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getDirectorModel()->getDirectorMessages($this->bsock, 50, null, false);
$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;
}

/**
* Get Director Model
*
* @return object
*/
public function getDirectorModel()
{
if (!$this->directorModel) {
$sm = $this->getServiceLocator();
$this->directorModel = $sm->get('Director\Model\DirectorModel');
}
return $this->directorModel;
}

/**
* Get Job Model
*
* @return object
*/
public function getJobModel()
{
if (!$this->jobModel) {
$sm = $this->getServiceLocator();
$this->jobModel = $sm->get('Job\Model\JobModel');
}
return $this->jobModel;
}

/**
* Get Dashboard Model
*
* @return object
*/
public function getDashboardModel()
{
if (!$this->dashboardModel) {
$sm = $this->getServiceLocator();
$this->dashboardModel = $sm->get('Dashboard\Model\DashboardModel');
}
return $this->dashboardModel;
}
}

0 comments on commit 3d83c57

Please sign in to comment.