widgetId = $widgetId; $this->cellId = $cellId; $this->dashboardId = $dashboardId; $this->fields = $this->get(); $this->className = $this->fields['class_name']; $cellClass = new Cell($this->cellId, $this->dashboardId); $this->dataCell = $cellClass->get(); $this->values = $this->decoders($this->getOptionsWidget()); if (isset($this->values['node']) === true) { $this->nodeId = $this->values['node']; } } return $this; } /** * Retrieve a cell definition. * * @return array cell data. */ public function get() { $sql = sprintf( 'SELECT * FROM twidget WHERE id = %d', $this->widgetId ); $data = \db_get_row_sql($sql); if ($data === false) { return []; } return $data; } /** * Get options Cell widget configuration. * * @return array */ public function getOptionsWidget():array { $result = []; if (empty($this->dataCell['options']) === false) { $result = \json_decode($this->dataCell['options'], true); // Hack retrocompatibility. if ($result === null) { $result = \unserialize($this->dataCell['options']); } } return $result; } /** * Get options Cell widget configuration. * * @return array */ public function getPositionWidget():array { global $config; $result = []; if (empty($this->dataCell['position']) === false) { $result = \json_decode($this->dataCell['position'], true); // Hack retrocompatibility. if ($result === null) { $result = \unserialize($this->dataCell['position']); } } return $result; } /** * Insert widgets. * * @return void */ public function install() { $id = db_get_value( 'id', 'twidget', 'unique_name', $this->getName() ); if ($id !== false) { return; } $values = [ 'unique_name' => $this->getName(), 'description' => $this->getDescription(), 'options' => '', 'page' => $this->page, 'class_name' => $this->className, ]; $res = db_process_sql_insert('twidget', $values); return $res; } /** * Get all dashboard user can you see. * * @param integer $offset Offset query. * @param integer $limit Limit query. * @param string|null $search Search word. * * @return array Return info all dasboards. */ static public function getWidgets( int $offset=-1, int $limit=-1, ?string $search='' ):array { global $config; $sql_limit = ''; if ($offset !== -1 && $limit !== -1) { $sql_limit = ' LIMIT '.$offset.','.$limit; } $sql_search = ''; if (empty($search) === false) { $sql_search = 'AND description LIKE "%'.addslashes($search).'%" '; } // User admin view all dashboards. $sql_widget = \sprintf( 'SELECT * FROM twidget WHERE 1=1 %s ORDER BY `description` %s', $sql_search, $sql_limit ); $widgets = \db_get_all_rows_sql($sql_widget); if ($widgets === false) { $widgets = []; } return $widgets; } /** * Install Widgets. * * @param integer $cellId Cell ID. * * @return void */ public static function dashboardInstallWidgets(int $cellId) { global $config; $dir = $config['homedir'].'/include/lib/Dashboard/Widgets/'; $handle = opendir($dir); if ($handle === false) { return; } $ignores = [ '.', '..', ]; while (false !== ($file = readdir($handle))) { if (in_array($file, $ignores) === true) { continue; } $filepath = realpath($dir.'/'.$file); if (is_readable($filepath) === false || is_dir($filepath) === true || preg_match('/.*\.php$/', $filepath) === false ) { continue; } $name = preg_replace('/.php/', '', $file); $className = 'PandoraFMS\Dashboard'; $not_installed = false; switch ($name) { case 'agent_module': $className .= '\AgentModuleWidget'; break; case 'alerts_fired': $className .= '\AlertsFiredWidget'; break; case 'clock': $className .= '\ClockWidget'; break; case 'custom_graph': $className .= '\CustomGraphWidget'; break; case 'events_list': $className .= '\EventsListWidget'; break; case 'example': $className .= '\WelcomeWidget'; break; case 'graph_module_histogram': $className .= '\GraphModuleHistogramWidget'; break; case 'groups_status': $className .= '\GroupsStatusWidget'; break; case 'maps_made_by_user': $className .= '\MapsMadeByUser'; break; case 'maps_status': $className .= '\MapsStatusWidget'; break; case 'module_icon': $className .= '\ModuleIconWidget'; break; case 'module_status': $className .= '\ModuleStatusWidget'; break; case 'module_table_value': $className .= '\ModuleTableValueWidget'; break; case 'module_value': $className .= '\ModuleValueWidget'; break; case 'monitor_health': $className .= '\MonitorHealthWidget'; break; case 'network_map': if (\enterprise_installed() === false) { $not_installed = true; } $className .= '\NetworkMapWidget'; break; case 'post': $className .= '\PostWidget'; break; case 'reports': $className .= '\ReportsWidget'; break; case 'service_map': if (\enterprise_installed() === false) { $not_installed = true; } $className .= '\ServiceMapWidget'; break; case 'service_view': if (\enterprise_installed() === false) { $not_installed = true; } $className .= '\ServiceViewWidget'; break; case 'single_graph': $className .= '\SingleGraphWidget'; break; case 'sla_percent': $className .= '\SLAPercentWidget'; break; case 'system_group_status': $className .= '\SystemGroupStatusWidget'; break; case 'tactical': $className .= '\TacticalWidget'; break; case 'top_n_events_by_module': $className .= '\TopNEventByModuleWidget'; break; case 'top_n_events_by_group': $className .= '\TopNEventByGroupWidget'; break; case 'top_n': $className .= '\TopNWidget'; break; case 'tree_view': $className .= '\TreeViewWidget'; break; case 'url': $className .= '\UrlWidget'; break; case 'wux_transaction_stats': if (\enterprise_installed() === false) { $not_installed = true; } $className .= '\WuxStatsWidget'; break; case 'wux_transaction': if (\enterprise_installed() === false) { $not_installed = true; } $className .= '\WuxWidget'; break; case 'os_quick_report': $className .= '\OsQuickReportWidget'; break; case 'GroupedMeterGraphs': case 'ColorModuleTabs': case 'BlockHistogram': case 'DataMatrix': $className .= '\\'.$name; break; default: $className = false; break; } if ($not_installed === false && $className !== false) { include_once $filepath; $instance = new $className($cellId, 0, 0); if (method_exists($instance, 'install') === true) { $instance->install(); } } } closedir($handle); } /** * Draw html. * * @return string Html data. */ public function printHtml() { global $config; $output = ''; if ((bool) \is_metaconsole() === true) { \enterprise_include_once('include/functions_metaconsole.php'); if ($this->nodeId > 0) { if (\metaconsole_connect(null, $this->nodeId) !== NOERR) { $output .= '