mirror of https://github.com/MISP/MISP
chg: [dashboard] Allow for the use of subdirectories in /app/Lib/Dashboard/Custom to be able to git clone repos
parent
6d3801d43b
commit
52e8924e6f
|
@ -139,7 +139,7 @@ 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)) {
|
||||
if (1 || empty($data)) {
|
||||
$cacheLifetime = isset($dashboardWidget->cacheLifetime) ? $dashboardWidget->cacheLifetime : 300;
|
||||
$data = $dashboardWidget->handler($this->Auth->user(), json_decode($value['config'], true));
|
||||
$redis->set('misp:dashboard:' . $org_scope . ':' . $lookup_hash, json_encode(array('data' => $data)));
|
||||
|
|
|
@ -6,12 +6,26 @@ class Dashboard extends AppModel
|
|||
|
||||
public function loadWidget($user, $name)
|
||||
{
|
||||
$name = str_replace('/', '', $name);
|
||||
if (file_exists(APP . 'Lib/Dashboard/' . $name . '.php')) {
|
||||
App::uses($name, 'Dashboard');
|
||||
} else if (file_exists(APP . 'Lib/Dashboard/Custom/' . $name . '.php')) {
|
||||
App::uses($name, 'Dashboard/Custom');
|
||||
} else {
|
||||
throw new NotFoundException(__('Invalid widget or widget not found.'));
|
||||
$customdir = new Folder(APP . 'Lib/Dashboard/Custom');
|
||||
$subDirectories = $customdir->read();
|
||||
$found = false;
|
||||
foreach ($subDirectories[0] as $subDir) {
|
||||
$currentDir = new Folder(APP . 'Lib/Dashboard/' . $subDir);
|
||||
if (file_exists(APP . 'Lib/Dashboard/Custom/' . $subDir . '/' . $name . '.php')) {
|
||||
App::uses($name, 'Dashboard/Custom/' . $subDir);
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
throw new NotFoundException(__('Invalid widget or widget not found.'));
|
||||
}
|
||||
}
|
||||
$widget = new $name();
|
||||
if (method_exists($widget, 'checkPermissions')) {
|
||||
|
@ -24,31 +38,34 @@ class Dashboard extends AppModel
|
|||
|
||||
public function loadAllWidgets($user)
|
||||
{
|
||||
$dir = new Folder(APP . 'Lib/Dashboard');
|
||||
$paths = array(
|
||||
'/',
|
||||
'/Custom'
|
||||
);
|
||||
$customdir = new Folder(APP . 'Lib/Dashboard/Custom');
|
||||
$widgetFiles = $dir->find('.*Widget\.php');
|
||||
$customWidgetFiles = $customdir->find('.*Widget\.php');
|
||||
$widgets = array();
|
||||
foreach ($widgetFiles as $widgetFile) {
|
||||
$className = substr($widgetFile, 0, strlen($widgetFile) -4);
|
||||
$temp = $this->__extractMeta($user, $className, false);
|
||||
if ($temp !== false) {
|
||||
$widgets[$className] = $temp;
|
||||
}
|
||||
$subDirectories = $customdir->read();
|
||||
foreach ($subDirectories[0] as $subDir) {
|
||||
$paths[] = '/Custom/' . $subDir;
|
||||
}
|
||||
foreach ($customWidgetFiles as $widgetFile) {
|
||||
$className = substr($widgetFile, 0, strlen($widgetFile) -4);
|
||||
$temp = $this->__extractMeta($user, $className, true);
|
||||
if ($temp !== false) {
|
||||
$widgets[$className] = $temp;
|
||||
$widgetMeta = array();
|
||||
$widgets = array();
|
||||
foreach ($paths as $path) {
|
||||
$currentDir = new Folder(APP . 'Lib/Dashboard' . $path);
|
||||
$widgetFiles = $currentDir->find('.*Widget\.php');
|
||||
foreach ($widgetFiles as $widgetFile) {
|
||||
$className = substr($widgetFile, 0, strlen($widgetFile) -4);
|
||||
$temp = $this->__extractMeta($user, $className, $path);
|
||||
if ($temp !== false) {
|
||||
$widgets[$className] = $temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
private function __extractMeta($user, $className, $custom)
|
||||
private function __extractMeta($user, $className, $path)
|
||||
{
|
||||
App::uses($className, 'Dashboard' . ($custom ? '/Custom' : ''));
|
||||
App::uses($className, 'Dashboard' . ($path === '/' ? '' : $path));
|
||||
$widgetClass = new $className();
|
||||
if (method_exists($widgetClass, 'checkPermissions')) {
|
||||
if (!$widgetClass->checkPermissions($user)) {
|
||||
|
|
Loading…
Reference in New Issue