diff --git a/app/Controller/DashboardsController.php b/app/Controller/DashboardsController.php index f89ac93ee..427e70bdb 100644 --- a/app/Controller/DashboardsController.php +++ b/app/Controller/DashboardsController.php @@ -139,16 +139,25 @@ class DashboardsController extends AppController $org_scope = $this->_isSiteAdmin() ? 0 : $this->Auth->user('org_id'); $lookup_hash = hash('sha256', $value['widget'] . $value['config']); $data = $redis->get('misp:dashboard:' . $org_scope . ':' . $lookup_hash); - if (empty($data)) { - $cacheLifetime = isset($dashboardWidget->cacheLifetime) ? $dashboardWidget->cacheLifetime : 300; + if (!isset($dashboardWidget->cacheLifetime)) { + $dashboardWidget->cacheLifetime = false; + } + if (empty($dashboardWidget->cacheLifetime) || empty($data)) { $data = $dashboardWidget->handler($this->Auth->user(), json_decode($value['config'], true)); - $redis->set('misp:dashboard:' . $org_scope . ':' . $lookup_hash, json_encode(array('data' => $data))); - $redis->expire('misp:dashboard:' . $org_scope . ':' . $lookup_hash, $cacheLifetime); + if (!empty($dashboardWidget->cacheLifetime)) { + $redis->set('misp:dashboard:' . $org_scope . ':' . $lookup_hash, json_encode(array('data' => $data))); + $redis->expire('misp:dashboard:' . $org_scope . ':' . $lookup_hash, $dashboardWidget->cacheLifetime); + } } else { $data = json_decode($data, true)['data']; } + $config = array( + 'render' => $dashboardWidget->render, + 'autoRefreshDelay' => empty($dashboardWidget->autoRefreshDelay) ? false : $dashboardWidget->autoRefreshDelay + ); $this->set('data', $data); - $this->render('/Dashboards/Widgets/' . $dashboardWidget->render); + $this->set('config', $config); + $this->render('widget_loader'); } else { throw new MethodNotAllowedException(__('This endpoint can only be reached via POST requests.')); } diff --git a/app/Lib/Dashboard/MispAdminResourceWidget.php b/app/Lib/Dashboard/MispAdminResourceWidget.php index a3d499560..b4eb4f89b 100644 --- a/app/Lib/Dashboard/MispAdminResourceWidget.php +++ b/app/Lib/Dashboard/MispAdminResourceWidget.php @@ -8,7 +8,8 @@ class MispAdminResourceWidget public $height = 2; public $params = array(); public $description = 'Basic widget showing some server statistics in regards to MISP.'; - public $cacheLifetime = 5; + public $cacheLifetime = false; + public $autoRefreshDelay = 3; public function handler($user, $options = array()) diff --git a/app/Lib/Dashboard/MispAdminWorkerWidget.php b/app/Lib/Dashboard/MispAdminWorkerWidget.php index 588474293..4bc0f40f6 100644 --- a/app/Lib/Dashboard/MispAdminWorkerWidget.php +++ b/app/Lib/Dashboard/MispAdminWorkerWidget.php @@ -8,7 +8,8 @@ class MispAdminWorkerWidget public $height = 2; public $params = array(); public $description = 'Basic widget showing some server statistics in regards to MISP.'; - public $cacheLifetime = 5; + public $cacheLifetime = false; + public $autoRefreshDelay = 5; public function handler($user, $options = array()) @@ -23,11 +24,13 @@ class MispAdminWorkerWidget } $total = 0; $alive = 0; - foreach ($queue['workers'] as $worker) { - if ($worker['alive']) { - $alive += 1; + if (!empty($queue['workers'])) { + foreach ($queue['workers'] as $worker) { + if ($worker['alive']) { + $alive += 1; + } + $total += 1; } - $total += 1; } $colour = 'green'; if ($alive == 0) { diff --git a/app/Model/Dashboard.php b/app/Model/Dashboard.php index f24444c25..72ce655a5 100644 --- a/app/Model/Dashboard.php +++ b/app/Model/Dashboard.php @@ -80,7 +80,8 @@ class Dashboard extends AppModel 'description' => empty($widgetClass->description) ? $widgetClass->title : $widgetClass->description, 'height' => empty($widgetClass->height) ? 1 : $widgetClass->height, 'width' => empty($widgetClass->width) ? 1 : $widgetClass->width, - 'placeholder' => empty($widgetClass->placeholder) ? '' : $widgetClass->placeholder + 'placeholder' => empty($widgetClass->placeholder) ? '' : $widgetClass->placeholder, + 'autoRefreshDelay' => empty($widgetClass->autoRefreshDelay) ? false : $widgetClass->autoRefreshDelay, ); return $widget; } diff --git a/app/View/Dashboards/widget_loader.ctp b/app/View/Dashboards/widget_loader.ctp new file mode 100644 index 000000000..514ef54db --- /dev/null +++ b/app/View/Dashboards/widget_loader.ctp @@ -0,0 +1,21 @@ + +
%s | %s |