diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php
index 28daa277e7..cb48c0ea6e 100644
--- a/pandora_console/include/functions_servers.php
+++ b/pandora_console/include/functions_servers.php
@@ -522,7 +522,7 @@ function servers_get_rate($avg_interval, $num_modules)
*
* @return mixed False in case the server doesn't exist or an array with info.
*/
-function servers_get_info($id_server=-1)
+function servers_get_info($id_server=-1, $sql_limit=-1)
{
global $config;
@@ -538,6 +538,14 @@ function servers_get_info($id_server=-1)
SELECT *
FROM tserver '.$select_id.'
ORDER BY server_type';
+
+ if ($sql_limit !== -1) {
+ $sql = '
+ SELECT *
+ FROM tserver '.$select_id.'
+ ORDER BY server_type'.$sql_limit;
+ }
+
$result = db_get_all_rows_sql($sql);
$time = get_system_time();
diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css
index 410b39c581..23321ed8cb 100755
--- a/pandora_console/mobile/include/style/main.css
+++ b/pandora_console/mobile/include/style/main.css
@@ -571,7 +571,8 @@ table.event_details td.cell_event_name {
#list_Modules td:hover,
#list_agent_Modules td:hover,
#list_visualmaps td:hover,
-#last_agent_events td:hover {
+#last_agent_events td:hover,
+#list_servers_status td:hover {
cursor: pointer;
}
@@ -866,6 +867,31 @@ table.event_details td.cell_event_name {
#list_Modules .module_name {
font-size: 12px !important;
}
+
+ table#list_servers tr {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: nowrap;
+ align-items: center;
+ }
+
+ table#list_servers b.ui-table-cell-label {
+ display: none;
+ }
+
+ table#list_servers tr td.cell_0 {
+ width: 10%;
+ }
+ table#list_servers tr td.cell_1 {
+ width: 10%;
+ }
+ table#list_servers tr td.cell_2 {
+ width: 80%;
+ }
+}
+
+table#list_servers tr td.cell_0 {
+ border-top: 0px;
}
#list_Modules .cell_5 a {
@@ -1648,3 +1674,61 @@ body.login-background
> span.ui-button-icon-space {
width: 5px;
}
+
+/* ==== Spinner ==== */
+.spinner {
+ width: 100px;
+ height: 100px;
+ border-radius: 100%;
+ background: linear-gradient(#82b92e, #c1ccdc);
+ animation: animate 1.2s linear infinite;
+ margin: auto;
+ margin-bottom: 40px;
+}
+.spinner span {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ border-radius: 100%;
+ background: linear-gradient(#82b92e, #c1ccdc);
+}
+.spinner span:nth-child(1) {
+ filter: blur(4px);
+}
+.spinner span:nth-child(2) {
+ filter: blur(8px);
+}
+.spinner span:nth-child(3) {
+ filter: blur(12px);
+}
+.spinner span:nth-child(4) {
+ filter: blur(16px);
+}
+.spinner:after {
+ content: "";
+ position: absolute;
+ top: 10px;
+ left: 10px;
+ right: 10px;
+ bottom: 10px;
+ /* background: transparent; */
+ background: #f1f1f1;
+ border: solid #fff 10px;
+ border-radius: 50%;
+}
+
+@keyframes animate {
+ 0% {
+ transform: rotate(0deg);
+ }
+ 100% {
+ transform: rotate(360deg);
+ }
+}
+
+.status_small_squares,
+.status_balls {
+ width: 12px;
+ height: 12px;
+ display: inline-block;
+}
diff --git a/pandora_console/mobile/include/user.class.php b/pandora_console/mobile/include/user.class.php
index 31d559bd87..00a7e605d1 100644
--- a/pandora_console/mobile/include/user.class.php
+++ b/pandora_console/mobile/include/user.class.php
@@ -408,6 +408,13 @@ class User
$(".ui-overlay-a").addClass("login-background");
$(".ui-overlay-a").removeClass("ui-overlay-a");
$(".ui-page-theme-a").css({"background-color":"transparent !important"});
+
+ $("#text-login_btn").click(function (e) {
+ $("#user-container").hide();
+ $("#password-container").hide();
+ $("#text-login_btn").hide();
+ $("#spinner-login").show();
+ });
});
'
@@ -448,6 +455,17 @@ class User
'required' => 'required',
];
$ui->formAddInputPassword($options);
+
+ $spinner = '
+
+
+
+
+
+
+ ';
+ $ui->formAddHtml($spinner);
+
$options = [
'value' => __('Login'),
'icon' => 'arrow-r',
diff --git a/pandora_console/mobile/index.php b/pandora_console/mobile/index.php
index dc79e07c04..dfad2dbebd 100644
--- a/pandora_console/mobile/index.php
+++ b/pandora_console/mobile/index.php
@@ -43,6 +43,7 @@ require_once 'operation/module_graph.php';
require_once 'operation/agent.php';
require_once 'operation/visualmaps.php';
require_once 'operation/visualmap.php';
+require_once 'operation/server_status.php';
$enterpriseHook = enterprise_include('mobile/include/enterprise.class.php');
$enterpriseHook = enterprise_include('mobile/operation/home.php');
@@ -177,6 +178,11 @@ switch ($action) {
$tactical->ajax($parameter2);
break;
+ case 'server_status':
+ $server_status = new ServerStatus();
+ $server_status->ajax($parameter2);
+ break;
+
default:
if (class_exists('Enterprise')) {
$enterprise->enterpriseAjax($parameter1, $parameter2);
@@ -407,6 +413,11 @@ switch ($action) {
$vc = new Visualmap();
$vc->show();
break;
+
+ case 'server_status':
+ $server_status = new ServerStatus();
+ $server_status->show();
+ break;
}
break;
}
diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php
index f6ea3e60f1..c0743941bd 100644
--- a/pandora_console/mobile/operation/home.php
+++ b/pandora_console/mobile/operation/home.php
@@ -91,6 +91,13 @@ class Home
'icon' => 'ui-icon-modules ui-widget-icon-floatbeginning',
];
+ $items['server_status'] = [
+ 'name' => __('Server status'),
+ 'filename' => 'server_status.php',
+ 'menu_item' => true,
+ 'icon' => 'ui-icon- ui-widget-icon-floatbeginning',
+ ];
+
// Not in home.
$items['agent'] = [
'name' => __('Agent'),
diff --git a/pandora_console/mobile/operation/server_status.php b/pandora_console/mobile/operation/server_status.php
new file mode 100644
index 0000000000..eeae698929
--- /dev/null
+++ b/pandora_console/mobile/operation/server_status.php
@@ -0,0 +1,534 @@
+checkACL($this->acl)) {
+ $this->correct_acl = true;
+ } else {
+ $this->correct_acl = false;
+ }
+
+ if ($system->getConfig('metaconsole') === 0) {
+ $this->all_servers = true;
+ }
+ }
+
+
+ public function ajax($parameter2=false)
+ {
+ $system = System::getInstance();
+
+ if (!$this->correct_acl) {
+ return;
+ } else {
+ switch ($parameter2) {
+ case 'get_server_status':
+ $this->getFilters();
+ $page = $system->getRequest('page', 0);
+ $server_status = [];
+ $end = 1;
+
+ $listServers = $this->getListServers($page, true);
+
+ if (!empty($listServers['servers'])) {
+ $end = 0;
+ $servers = $listServers['servers'];
+ }
+
+ hd(json_encode(['end' => $end, 'servers' => $servers]), true);
+ echo json_encode(['end' => $end, 'servers' => $servers]);
+ break;
+ }
+ }
+ }
+
+
+ public function setFilters($filters)
+ {
+ if (isset($filters['id_agent'])) {
+ $this->id_agent = $filters['id_agent'];
+ }
+
+ if (isset($filters['all_servers'])) {
+ $this->all_servers = $filters['all_servers'];
+ }
+
+ if (isset($filters['status'])) {
+ $this->status = (int) $filters['status'];
+ }
+
+ if (isset($filters['name'])) {
+ $this->name = $filters['name'];
+ }
+ }
+
+
+ public function disabledColumns($columns=null)
+ {
+ if (!empty($columns)) {
+ foreach ($columns as $column) {
+ $this->columns[$column] = 0;
+ }
+ }
+ }
+
+
+ private function getFilters()
+ {
+ $system = System::getInstance();
+ $user = User::getInstance();
+
+ $this->default_filters['module_group'] = true;
+ $this->default_filters['group'] = true;
+ $this->default_filters['status'] = true;
+ $this->default_filters['free_search'] = true;
+ $this->default_filters['tag'] = true;
+
+ $this->free_search = $system->getRequest('free_search', '');
+ if ($this->free_search != '') {
+ $this->default = false;
+ $this->default_filters['free_search'] = false;
+ }
+
+ $this->status = $system->getRequest('status', __('Status'));
+ if (($this->status === __('Status')) || ((int) $this->status === AGENT_MODULE_STATUS_ALL)) {
+ $this->status = AGENT_MODULE_STATUS_ALL;
+ } else {
+ $this->default = false;
+ $this->default_filters['status'] = false;
+ }
+
+ $this->group = (int) $system->getRequest('group', __('Group'));
+ if (!$user->isInGroup($this->acl, $this->group)) {
+ $this->group = 0;
+ }
+
+ if (($this->group === __('Group')) || ($this->group == 0)) {
+ $this->group = 0;
+ } else {
+ $this->default = false;
+ $this->default_filters['group'] = false;
+ }
+
+ $this->module_group = (int) $system->getRequest('module_group', __('Module group'));
+ if (($this->module_group === __('Module group')) || ($this->module_group === -1)
+ || ($this->module_group == 0)
+ ) {
+ $this->module_group = -1;
+ } else {
+ $this->default = false;
+ $this->module_group = (int) $this->module_group;
+ $this->default_filters['module_group'] = false;
+ }
+
+ $this->tag = (int) $system->getRequest('tag', __('Tag'));
+ if (($this->tag === __('Tag')) || ($this->tag == 0)) {
+ $this->tag = 0;
+ } else {
+ $this->default = false;
+ $this->default_filters['tag'] = false;
+ }
+ }
+
+
+ public function show()
+ {
+ if (!$this->correct_acl) {
+ $this->show_fail_acl();
+ } else {
+ $this->getFilters();
+ $this->show_servers();
+ }
+ }
+
+
+ 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_servers()
+ {
+ $ui = Ui::getInstance();
+
+ $ui->createPage();
+ $ui->createDefaultHeader(
+ __('Server status'),
+ $ui->createHeaderButton(
+ [
+ 'icon' => 'ui-icon-back',
+ 'pos' => 'left',
+ 'text' => __('Back'),
+ 'href' => 'index.php?page=home',
+ 'class' => 'header-button-left',
+ ]
+ )
+ );
+ $ui->showFooter(false);
+ $ui->beginContent();
+ $this->listServersHtml();
+ $ui->endContent();
+ $ui->showPage();
+ }
+
+
+ private function getListServers($page=0, $ajax=false)
+ {
+ global $config;
+ $system = System::getInstance();
+ $user = User::getInstance();
+
+ $total = 0;
+ $servers = [];
+ $servers_db = [];
+
+ if ($this->all_servers === true) {
+ $sql_limit = ' LIMIT '.(int) ($page * $system->getPageSize()).','.(int) $system->getPageSize();
+ }
+
+ if ($system->getConfig('metaconsole')) {
+ $servers_info = servers_get_info();
+ $total = (int) count(servers_get_info());
+
+ foreach ($servers_info as $server_value) {
+ $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true);
+ if ($server_value['status'] == -1) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_CRASH,
+ __('Server has crashed.'),
+ true
+ );
+ } else if ($server_value['status'] == 0) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_DOWN,
+ __('Server is stopped.'),
+ true
+ );
+ }
+
+ // $row[__('Status')] = ''.$server_value['status'].'';
+ $row[__('Status')] = ''.$image_status.'';
+ $row[__('Image')] = ''.$server_value['img'].'';
+ $row[__('Name')] = ''.$server_value['name'].'';
+
+ $servers[$server_value['id_server'].'-'.$server_value['name']] = $row;
+ }
+
+ $meta_servers = metaconsole_get_servers();
+
+ if ($meta_servers === false) {
+ $meta_servers = [];
+ }
+
+ foreach ($meta_servers as $server) {
+ if (metaconsole_connect($server) != NOERR) {
+ continue;
+ }
+
+ $servers_info = servers_get_info();
+ $total += (int) count(servers_get_info());
+
+ foreach ($servers_info as $server_value) {
+ $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true);
+ if ($server_value['status'] == -1) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_CRASH,
+ __('Server has crashed.'),
+ true
+ );
+ } else if ($server_value['status'] == 0) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_DOWN,
+ __('Server is stopped.'),
+ true
+ );
+ }
+
+ // $row[__('Status')] = ''.$server_value['status'].'';
+ $row[__('Status')] = ''.$image_status.'';
+ $row[__('Image')] = ''.$server_value['img'].'';
+ $row[__('Name')] = ''.$server_value['name'].'';
+
+ $servers[$server_value['id_server']] = $row;
+ }
+
+ metaconsole_restore_db();
+ }
+ } else {
+ $servers_info = servers_get_info(-1, $sql_limit);
+ $total = count(servers_get_info());
+
+ foreach ($servers_info as $server_value) {
+ echo '';
+ $image_status = ui_print_status_image(STATUS_SERVER_OK, '', true);
+ if ($server_value['status'] == -1) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_CRASH,
+ __('Server has crashed.'),
+ true
+ );
+ } else if ($server_value['status'] == 0) {
+ $image_status = ui_print_status_image(
+ STATUS_SERVER_DOWN,
+ __('Server is stopped.'),
+ true
+ );
+ }
+
+ // $row[__('Status')] = ''.$server_value['status'].'';
+ $row[__('Status')] = ''.$image_status.'';
+ $row[__('Image')] = ''.$server_value['img'].'';
+ $row[__('Name')] = ''.$server_value['name'].'';
+
+ $servers[$server_value['id_server']] = $row;
+ }
+ }
+
+ return [
+ 'servers' => $servers,
+ 'total' => $total,
+ ];
+ }
+
+
+ public function listServersHtml($page=0, $return=false)
+ {
+ $system = System::getInstance();
+ $ui = Ui::getInstance();
+
+ $listServers = $this->getListServers($page);
+ if ($listServers['total'] == 0) {
+ $html = ''.__('No servers').'
';
+ if (!$return) {
+ $ui->contentAddHtml($html);
+ } else {
+ return $html;
+ }
+ } else {
+ if (!$return) {
+ $table = new Table();
+ $table->id = 'list_servers';
+ $table->importFromHash($listServers['servers']);
+
+ $ui->contentAddHtml($table->getHTML());
+ } else {
+ $table = new Table();
+ $table->id = 'list_servers_status';
+
+ $table->importFromHash($listServers['servers']);
+
+ $html = $table->getHTML();
+
+ return $html;
+ }
+
+ if ($this->all_servers === true) {
+ if ($system->getPageSize() < $listServers['total']) {
+ $ui->contentAddHtml(
+ ''.html_print_image('images/spinner.gif', true, false, false, false, false, true).' '.__('Loading...').'
'
+ );
+
+ $this->addJavascriptAddBottom();
+ }
+ }
+ }
+
+ $ui->contentAddLinkListener('list_servers');
+ }
+
+
+ private function addJavascriptAddBottom()
+ {
+ $ui = Ui::getInstance();
+
+ $ui->contentAddHtml(
+ "'
+ );
+ }
+
+
+ private function filterServersGetString()
+ {
+ if ($this->default) {
+ return __('(Default)');
+ } else {
+ $filters_to_serialize = [];
+
+ if (!$this->default_filters['group']) {
+ $filters_to_serialize[] = sprintf(
+ __('Group: %s'),
+ groups_get_name($this->group, true)
+ );
+ }
+
+ if (!$this->default_filters['module_group']) {
+ $module_group = db_get_value(
+ 'name',
+ 'tmodule_group',
+ 'id_mg',
+ $this->module_group
+ );
+ $module_group = io_safe_output($module_group);
+
+ $filters_to_serialize[] = sprintf(
+ __('Module group: %s'),
+ $module_group
+ );
+ }
+
+ if (!$this->default_filters['status']) {
+ $filters_to_serialize[] = sprintf(
+ __('Status: %s'),
+ $this->list_status[$this->status]
+ );
+ }
+
+ if (!$this->default_filters['free_search']) {
+ $filters_to_serialize[] = sprintf(
+ __('Free Search: %s'),
+ $this->free_search
+ );
+ }
+
+ if (!$this->default_filters['tag']) {
+ $tag_name = tags_get_name($this->tag);
+ $filters_to_serialize[] = sprintf(
+ __('Tag: %s'),
+ $tag_name
+ );
+ }
+
+ $string = '('.implode(' - ', $filters_to_serialize).')';
+
+ return $string;
+ }
+ }
+
+
+}