diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 1d11aad151..54325f28e0 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -813,6 +813,7 @@ define('AUDIT_LOG_SERVICE_MANAGEMENT', 'Service management'); define('AUDIT_LOG_INCIDENT_MANAGEMENT', 'Incident management'); define('AUDIT_LOG_UMC', 'Warp Manager'); define('AUDIT_LOG_NMS_VIOLATION', 'NMS Violation'); +define('AUDIT_LOG_ENTERPRISE_VIOLATION', 'Enterprise Violation'); // MIMEs. define( diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css index e2d6c868ab..c373aa8d22 100755 --- a/pandora_console/mobile/include/style/main.css +++ b/pandora_console/mobile/include/style/main.css @@ -892,14 +892,16 @@ table.event_details td.cell_event_name { font-size: 12px !important; } - table#list_servers tr { + table#list_servers tr, + table[id^="service-table-"] tr { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; } - table#list_servers b.ui-table-cell-label { + table#list_servers b.ui-table-cell-label, + table[id^="service-table-"] b.ui-table-cell-label { display: none; } @@ -912,9 +914,20 @@ table.event_details td.cell_event_name { table#list_servers tr td.cell_2 { width: 80%; } + + table[id^="service-table-"] tr td.cell_0 { + width: 10%; + } + table[id^="service-table-"] tr td.cell_1 { + width: 80%; + } + table[id^="service-table-"] tr td.cell_2 { + width: 10%; + } } -table#list_servers tr td.cell_0 { +table#list_servers tr td.cell_0, +table[id^="service-table-"] td.cell_0 { border-top: 0px; } @@ -1286,12 +1299,26 @@ table.tactical_bars { background-size: 18px 18px !important; } +.ui-icon-server-status { + background-image: url(../../../images/server-status.menu.png) !important; + background-color: #333 !important; + background-size: 18px 18px !important; +} + +.ui-icon-services { + background-image: url(../../../images/services.menu.png) !important; + background-color: #333 !important; + background-size: 18px 18px !important; +} + .ui-icon-tactical_view, .ui-icon-events, .ui-icon-groups, .ui-icon-alerts, .ui-icon-agents, .ui-icon-modules, +.ui-icon-server-status, +.ui-icon-services, .ui-icon-network_maps, .ui-icon-visual_console, .ui-icon-dashboard { @@ -1323,6 +1350,8 @@ table.tactical_bars { .ui-icon-alerts, .ui-icon-agents, .ui-icon-modules, + .ui-icon-server-status, + .ui-icon-services, .ui-icon-network_maps, .ui-icon-visual_console, .ui-icon-dashboard { @@ -1339,6 +1368,8 @@ table.tactical_bars { .ui-icon-alerts, .ui-icon-agents, .ui-icon-modules, + .ui-icon-server-status, + .ui-icon-services, .ui-icon-network_maps, .ui-icon-visual_console, .ui-icon-dashboard { @@ -1776,3 +1807,35 @@ span.agents-counter { float: right; margin-right: 15px; } + +span.agents-counter span { + padding-left: 1px; + padding-right: 1px; +} + +div.border-collapsible + > h4.ui-collapsible-heading + + div.ui-collapsible-content { + border-width: 1px !important; + border-top: 0px !important; + border-left: 1px solid #ddd; + border-right: 1px solid #ddd; + border-bottom: 1px solid #ddd; +} + +table[id^="service-table-"] { + width: 100%; +} + +table[id^="service-table-"] > tbody > tr:nth-child(even) { + background-color: #ebebeb; +} + +table[id^="service-table-"] a strong { + color: #000 !important; +} + +.mt15px { + margin-top: 15px; + margin-bottom: 15px; +} diff --git a/pandora_console/mobile/include/system.class.php b/pandora_console/mobile/include/system.class.php index b8a21d60b1..253885659f 100644 --- a/pandora_console/mobile/include/system.class.php +++ b/pandora_console/mobile/include/system.class.php @@ -151,10 +151,35 @@ class System } + public function checkEnterprise($page='') + { + if ((int) $this->getConfig('enterprise_installed', false) === 1) { + return true; + } else { + if (empty($this->getRequest('page', false)) === false && $page === '') { + $page = $this->getRequest('page', false); + } + + db_pandora_audit( + AUDIT_LOG_ENTERPRISE_VIOLATION, + 'Trying to access to Mobile Page: '.$page + ); + + return false; + } + } + + public static function getDefaultACLFailText() { return __('Access to this page is restricted to authorized users only, please contact your system administrator if you should need help.').'

'.__('Please remember that any attempts to access this page will be recorded on the %s System Database.', get_product_name()); } + public static function getDefaultLicenseFailText() + { + return __('Invalid license, please contact your system administrator if you should need help.').'

'.__('Please remember that any attempts to access this page will be recorded on the %s System Database.', get_product_name()); + } + + } diff --git a/pandora_console/mobile/index.php b/pandora_console/mobile/index.php index dfad2dbebd..401f96ae11 100644 --- a/pandora_console/mobile/index.php +++ b/pandora_console/mobile/index.php @@ -44,6 +44,7 @@ require_once 'operation/agent.php'; require_once 'operation/visualmaps.php'; require_once 'operation/visualmap.php'; require_once 'operation/server_status.php'; +require_once 'operation/services.php'; $enterpriseHook = enterprise_include('mobile/include/enterprise.class.php'); $enterpriseHook = enterprise_include('mobile/operation/home.php'); @@ -183,6 +184,11 @@ switch ($action) { $server_status->ajax($parameter2); break; + case 'services': + $services = new Services(); + $services->ajax($parameter2); + break; + default: if (class_exists('Enterprise')) { $enterprise->enterpriseAjax($parameter1, $parameter2); @@ -418,6 +424,11 @@ switch ($action) { $server_status = new ServerStatus(); $server_status->show(); break; + + case 'services': + $services = new Services(); + $services->show(); + break; } break; } diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index c0743941bd..06797a1d1b 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -40,7 +40,7 @@ class Home $items = []; - // In home + // In home. $items['tactical'] = [ 'name' => __('Tactical view'), 'filename' => 'tactical.php', @@ -95,9 +95,18 @@ class Home 'name' => __('Server status'), 'filename' => 'server_status.php', 'menu_item' => true, - 'icon' => 'ui-icon- ui-widget-icon-floatbeginning', + 'icon' => 'ui-icon-server-status ui-widget-icon-floatbeginning', ]; + if ((int) $system->getConfig('enterprise_installed', false) === 1) { + $items['services'] = [ + 'name' => __('Services'), + 'filename' => 'services.php', + 'menu_item' => true, + 'icon' => 'ui-icon-services ui-widget-icon-floatbeginning', + ]; + } + // Not in home. $items['agent'] = [ 'name' => __('Agent'), diff --git a/pandora_console/mobile/operation/services.php b/pandora_console/mobile/operation/services.php new file mode 100644 index 0000000000..b0fae9d354 --- /dev/null +++ b/pandora_console/mobile/operation/services.php @@ -0,0 +1,536 @@ +checkACL($this->acl)) { + $this->correct_acl = true; + + $this->services = enterprise_hook('services_get_services'); + } else { + $this->correct_acl = false; + } + + if ($system->checkEnterprise() === false) { + $this->show_fail_enterprise(); + } + } + + + public function show() + { + if (!$this->correct_acl) { + $this->show_fail_acl(); + } else { + $this->show_services(); + } + } + + + private function show_fail_acl() + { + $error['type'] = 'onStart'; + $error['title_text'] = __('You don\'t have access to this page'); + $error['content_text'] = System::getDefaultACLFailText(); + if (class_exists('HomeEnterprise')) { + $home = new HomeEnterprise(); + } else { + $home = new Home(); + } + + $home->show($error); + } + + + private function show_fail_enterprise() + { + $error['type'] = 'onStart'; + $error['title_text'] = __('You don\'t have access to this page'); + $error['content_text'] = System::getDefaultLicenseFailText(); + if (class_exists('HomeEnterprise')) { + $home = new HomeEnterprise(); + } else { + $home = new Home(); + } + + $home->show($error); + } + + + public function ajax($parameter2=false) + { + $system = System::getInstance(); + + if (!$this->correct_acl) { + return; + } else { + switch ($parameter2) { + case 'get_services': + $this->serviceId = $system->getRequest('service_id', 0); + $rows = $this->getListServices(); + + $this->rows = $rows; + $table = $this->getTable(); + + echo $table; + break; + } + } + } + + + private function show_services() + { + $ui = Ui::getInstance(); + + $ui->createPage(); + $ui->createDefaultHeader( + __('Services'), + $ui->createHeaderButton( + [ + 'icon' => 'ui-icon-back', + 'pos' => 'left', + 'text' => __('Back'), + 'href' => 'index.php?page=home', + 'class' => 'header-button-left', + ] + ) + ); + $ui->showFooter(false); + $ui->beginContent(); + + $ui->contentAddHtml('
'); + $count = 0; + $url_agent = 'index.php?page=agents&group=%s&status=%s'; + $url_modules = 'index.php?page=modules&group=%s&status=%s'; + + foreach ($this->services as $service) { + switch ($service['status']) { + case SERVICE_STATUS_NORMAL: + $color = COL_NORMAL; + break; + + case SERVICE_STATUS_CRITICAL: + $color = COL_CRITICAL; + break; + + case SERVICE_STATUS_WARNING: + $color = COL_WARNING; + break; + + case SERVICE_STATUS_UNKNOWN: + default: + $color = COL_UNKNOWN; + break; + } + + $group_icon = ui_print_group_icon($service['id_group'], true, '../images/groups_small_white', '', false); + + $ui->contentAddHtml( + ' + + ' + ); + $ui->contentAddHtml('
'); + $ui->contentAddHtml('

'.$group_icon.' '.$service['description'].'

'); + + $spinner = ' +
+ + + + +
+ '; + + $ui->contentAddHtml($spinner); + $ui->contentAddHtml('
'); + + $count++; + } + + $ui->contentAddHtml('
'); + $this->addJavascriptAddBottom(); + + $ui->endContent(); + $ui->showPage(); + } + + + public function getListServices() + { + $ui = Ui::getInstance(); + $this->idTable = 'service-table-'.$this->serviceId; + $rows = []; + + $elements_list = new Service($this->serviceId); + $elements = $elements_list->getElements(true); + + if (empty($elements) === false) { + foreach ($elements as $item) { + $name = ''; + // Icon. + switch ($item->type()) { + case SERVICE_ELEMENT_AGENT: + $element_icon = html_print_image( + 'images/agents@svg.svg', + true, + [ + 'title' => __('Agent'), + 'class' => 'main_menu_icon', + ] + ); + + if ($item->exists() !== true) { + $name .= ''.__('Nonexistent. This element should be deleted').''; + } else { + $url = ui_get_full_url( + 'index.php?sec=eventos&sec2=operation/events/events&event_view_hr=8&severity=4&id_agent='.$item->agent()->id_agente() + ); + $name = ''; + if (((bool) $item->agent()->disabled()) === true) { + $disabled_element = true; + if (is_metaconsole() === true) { + $name .= ''; + } else { + $name .= ''; + } + } + + $name .= ''; + if (is_metaconsole() + && ((int) $item->id_server_meta()) !== 0 + ) { + $name .= $item->nodeName().' » '; + } + + $name .= $item->agent()->alias(); + $name .= ''; + $name .= ''; + + if (((bool) $item->agent()->disabled()) === true) { + $name .= ui_print_help_tip( + __('This element does not affect service weigth because is disabled.'), + true + ).''; + } + } + break; + + case SERVICE_ELEMENT_SERVICE: + $element_icon = html_print_image( + 'images/item-service.svg', + true, + [ + 'title' => __('Service'), + 'class' => 'main_menu_icon', + ] + ); + if ($item->exists() !== true) { + $name .= ''.__('Nonexistent. This element should be deleted').''; + } else { + if (is_metaconsole() + && (((int) $item->id_server_meta()) !== 0 ) + ) { + $server = db_get_row( + 'tmetaconsole_setup', + 'id', + $item->id_server_meta() + ); + + $url = ui_meta_get_url_console_child( + $server, + 'estado', + 'enterprise/operation/services/services', + [ + 'tab' => 'service', + 'action' => 'view', + 'id_service' => $item->id_service_child(), + ] + ); + } else { + $url = ui_get_full_url( + 'index.php?sec=network&sec2=enterprise/operation/services/services&tab=service&action=view&id_service='.$item->id_service_child() + ); + } + + $name = ''; + if (((bool) $item->service()->disabled()) === true) { + $disabled_element = true; + if (is_metaconsole() === true) { + $name .= ''; + } else { + $name .= ''; + } + } + + $name .= ''; + if (is_metaconsole() + && ((int) $item->id_server_meta()) !== 0 + ) { + $name .= $item->nodeName().' » '; + } + + $name .= $item->service()->name(); + $name .= ''; + $name .= ''; + + if (((bool) $item->service()->disabled()) === true) { + $name .= ui_print_help_tip( + __('This element does not affect service weigth because is disabled.'), + true + ).''; + } + } + break; + + case SERVICE_ELEMENT_MODULE: + $element_icon = html_print_image( + 'images/modules@svg.svg', + true, + [ + 'title' => __('Module'), + 'class' => 'main_menu_icon', + ] + ); + + if ($item->exists() !== true) { + $name .= ''.__('Nonexistent. This element should be deleted').''; + } else { + $url = ui_get_full_url( + 'index.php?sec=eventos&sec2=operation/events/events&event_view_hr=8&severity=4&id_agent='.$item->module()->id_agente().'&id_agent_module='.$item->id_agente_modulo() + ); + $name = ''; + $name .= ''; + + if (((bool) $item->module()->disabled()) === true) { + $disabled_element = true; + if (is_metaconsole()) { + $name .= ''; + } else { + $name .= ''; + } + } + + if (is_metaconsole() + && ((int) $item->id_server_meta()) !== 0 + ) { + $name .= $item->nodeName().' » '; + } + + $name .= $item->module()->agent()->alias(); + $name .= ' » '.$item->module()->nombre(); + + if (((bool) $item->module()->disabled()) === true) { + $name .= ui_print_help_tip( + __('This element does not affect service weigth because is disabled.'), + true + ).''; + } + + $name .= ''; + $name .= ''; + } + break; + + case SERVICE_ELEMENT_DYNAMIC: + $element_icon = html_print_image( + 'images/modules-group@svg.svg', + true, + [ + 'title' => __('Dynamic element'), + 'class' => 'main_menu_icon', + ] + ); + + try { + if (empty($item->getMatches(true)) === true) { + ui_print_warning_message( + __( + 'Dynamic element (%d) \'%s\' does not match any target', + $item->id(), + $item->description() + ) + ); + } + } catch (Exception $e) { + ui_print_warning_message( + __( + 'Dynamic element (%d) \'%s\' causes an error: %s', + $item->id(), + $item->description(), + $e->getMessage() + ) + ); + } + + if ($item->rules()->dynamic_type === 'agent') { + $name = ''.__( + 'agents like "%s"', + $item->rules()->agent_name + ).''; + } else if ($item->rules()->dynamic_type === 'module') { + $name = ''.__( + 'modules like "%s"', + $item->rules()->module_name + ).''; + } + break; + + default: + $element_icon = ''; + break; + } + + // Status. + switch ($item->lastStatus(true)) { + case SERVICE_STATUS_NORMAL: + case AGENT_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL: + $status_element = STATUS_MODULE_OK; + $title_element = __('NORMAL'); + break; + + case SERVICE_STATUS_CRITICAL: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_STATUS_CRITICAL: + $status_element = STATUS_MODULE_CRITICAL; + $title_element = __('CRITICAL'); + break; + + case SERVICE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_STATUS_WARNING: + $status_element = STATUS_MODULE_WARNING; + $title_element = __('WARNING'); + break; + + case SERVICE_STATUS_ALERT: + case AGENT_MODULE_STATUS_NOT_INIT: + case AGENT_STATUS_NOT_INIT: + $status_element = STATUS_MODULE_NO_DATA; + $title_element = __('NOT INITIALIZED'); + break; + + case AGENT_MODULE_STATUS_UNKNOWN: + case SERVICE_STATUS_UNKNOWN: + case AGENT_STATUS_UNKNOWN: + default: + $status_element = STATUS_MODULE_UNKNOWN; + $title_element = __('UNKNOWN'); + break; + } + + $row = []; + $row[0] = $element_icon; + $row[1] = $name; + $row[2] = ui_print_status_image($status_element, $title_element, true); + + array_push($rows, $row); + } + } + + return $rows; + } + + + public function getTable() + { + $html = ''; + + $html = "serviceId."' data-mode='reflow' class='ui-responsive table-stroke'>"; + + // $html .= ''; + // $html .= ''; + // $html .= ''; + // $html .= ''; + // $html .= ''; + // $html .= ''; + // $html .= ''; + $html .= ''; + foreach ($this->rows as $key => $row) { + $html .= ""; + + foreach ($row as $key_cell => $cell) { + $html .= "'; + } + + $html .= ''; + } + + $html .= ''; + $html .= '
'.__('Type').''.__('Name').''.__('Status').'
".$cell.'
'; + + return $html; + } + + + private function addJavascriptAddBottom() + { + $ui = Ui::getInstance(); + + $ui->contentAddHtml( + "" + ); + } + + +}