From d72f9fdac0c0aaa20e146ef089577548d9f03d83 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Dec 2020 17:38:40 +0100 Subject: [PATCH 001/238] SAML login in mobile console --- pandora_console/mobile/include/user.class.php | 59 ++++++++++++++++++- pandora_console/mobile/operation/home.php | 7 +++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/pandora_console/mobile/include/user.class.php b/pandora_console/mobile/include/user.class.php index 61267f2023..eb1af4c10d 100644 --- a/pandora_console/mobile/include/user.class.php +++ b/pandora_console/mobile/include/user.class.php @@ -86,6 +86,36 @@ class User { $system = System::getInstance(); + if ((bool) $system->getRequest('saml', false) === true) { + if ($system->getConfig('auth', 'mysql') !== 'saml') { + // Ignore. + return false; + } else { + \enterprise_include_once('include/auth/saml.php'); + $saml_user_id = enterprise_hook('saml_process_user_login'); + if (!$saml_user_id) { + $this->logged = false; + } else { + $this->logged = true; + $this->user = $saml_user_id; + $this->loginTime = time(); + $this->errorLogin = false; + } + + $this->saveLogin(); + return $this->logged; + } + } else if ($system->getConfig('auth', 'mysql') === 'saml') { + // Maybe back from SAML login. + $saml_session = $system->getSession('samlid', null); + if ($saml_session !== null) { + $this->user = $system->getSession('id_usuario', null); + $this->loginTime = time(); + $this->errorLogin = false; + $this->logged = true; + } + } + if (($user == null) && ($password == null)) { $user = $system->getRequest('user', null); $password = $system->getRequest('password', null); @@ -205,6 +235,12 @@ class User public function logout() { + $system = System::getInstance(); + if ($system->getConfig('auth', 'mysql') === 'saml') { + \enterprise_include_once('include/auth/saml.php'); + \enterprise_hook('saml_logout'); + } + $this->user = null; $this->logged = false; $this->loginTime = false; @@ -213,7 +249,6 @@ class User $this->needDoubleAuth = false; $this->errorDoubleAuth = false; - $system = System::getInstance(); $system->setSession('user', null); $system->sessionDestroy(); } @@ -286,7 +321,29 @@ class User 'name' => 'login_btn', ]; $ui->formAddSubmitButton($options); + $ui->endForm(); + + if ($system->getConfig('auth', 'mysql') === 'saml') { + // Add SAML login button. + $ui->beginForm(''); + $ui->formAddHtml( + html_print_input_hidden('action', 'login', true) + ); + $ui->formAddHtml( + html_print_input_hidden('saml', '1', true) + ); + $ui->formAddSubmitButton( + [ + 'value' => __('Login with SAML'), + 'icon' => 'arrow-r', + 'icon_pos' => 'right', + 'name' => 'login_button_saml', + ] + ); + $ui->endForm(''); + } + $ui->contentAddHtml(''); $ui->endContent(); $ui->showPage(); diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index b172d16021..d49f42eb0b 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -59,6 +59,12 @@ class Home 'menu_item' => true, 'icon' => 'groups', ]; + $items['console'] = [ + 'name' => __('Visual consoles'), + 'filename' => 'vconsole.php', + 'menu_item' => true, + 'icon' => 'consoles', + ]; if (!$system->getConfig('metaconsole')) { $items['alerts'] = [ @@ -74,6 +80,7 @@ class Home 'menu_item' => true, 'icon' => 'agents', ]; + $items['modules'] = [ 'name' => __('Modules'), 'filename' => 'modules.php', From 03569f79b6a41b6af643c971a09ce183168bd19d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Dec 2020 18:06:12 +0100 Subject: [PATCH 002/238] Avoid users with success login in SAML access console if not in console --- pandora_console/mobile/include/user.class.php | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/pandora_console/mobile/include/user.class.php b/pandora_console/mobile/include/user.class.php index eb1af4c10d..749233df99 100644 --- a/pandora_console/mobile/include/user.class.php +++ b/pandora_console/mobile/include/user.class.php @@ -86,34 +86,41 @@ class User { $system = System::getInstance(); - if ((bool) $system->getRequest('saml', false) === true) { - if ($system->getConfig('auth', 'mysql') !== 'saml') { - // Ignore. - return false; - } else { + if ($system->getConfig('auth', 'mysql') === 'saml') { + if ((bool) $system->getRequest('saml', false) === true) { \enterprise_include_once('include/auth/saml.php'); $saml_user_id = enterprise_hook('saml_process_user_login'); if (!$saml_user_id) { $this->logged = false; + $this->errorLogin = $system->getConfig('auth_error'); + \enterprise_hook('saml_logout', [true]); } else { $this->logged = true; $this->user = $saml_user_id; $this->loginTime = time(); $this->errorLogin = false; } - - $this->saveLogin(); - return $this->logged; } - } else if ($system->getConfig('auth', 'mysql') === 'saml') { + // Maybe back from SAML login. $saml_session = $system->getSession('samlid', null); if ($saml_session !== null) { $this->user = $system->getSession('id_usuario', null); - $this->loginTime = time(); - $this->errorLogin = false; - $this->logged = true; + if ($this->user !== null) { + $this->loginTime = time(); + $this->errorLogin = false; + $this->logged = true; + } else { + // SAML Session OK but not in DB. + $this->logged = false; + $this->errorLogin = __( + 'User cannot log in into this console, please contact administrator' + ); + } } + + $this->saveLogin(); + return $this->logged; } if (($user == null) && ($password == null)) { @@ -265,7 +272,12 @@ class User if ($this->errorLogin) { $options['type'] = 'onStart'; $options['title_text'] = __('Login Failed'); - $options['content_text'] = __('User not found in database or incorrect password.'); + if ($this->errorLogin !== false) { + $options['content_text'] = $this->errorLogin; + } else { + $options['content_text'] = __('User not found in database or incorrect password.'); + } + $ui->addDialog($options); } From 5b176d9370e2921714591c111ada5b9fa49f41c3 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Dec 2020 18:30:21 +0100 Subject: [PATCH 003/238] minor fixes --- pandora_console/mobile/include/user.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/mobile/include/user.class.php b/pandora_console/mobile/include/user.class.php index 749233df99..3a46ebac1d 100644 --- a/pandora_console/mobile/include/user.class.php +++ b/pandora_console/mobile/include/user.class.php @@ -100,6 +100,9 @@ class User $this->loginTime = time(); $this->errorLogin = false; } + + $this->saveLogin(); + return $this->logged; } // Maybe back from SAML login. @@ -117,10 +120,10 @@ class User 'User cannot log in into this console, please contact administrator' ); } - } - $this->saveLogin(); - return $this->logged; + $this->saveLogin(); + return $this->logged; + } } if (($user == null) && ($password == null)) { From b7e64f14776a62616617ea290033e652dfae7217 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 18 Dec 2020 13:23:35 +0100 Subject: [PATCH 004/238] Visual console list mobile view --- .../images/visual_console.menu.png | Bin 0 -> 8400 bytes pandora_console/mobile/include/style/main.css | 6 + .../mobile/include/system.class.php | 2 +- pandora_console/mobile/index.php | 12 ++ pandora_console/mobile/operation/home.php | 16 +- .../mobile/operation/visualmaps.php | 187 +++++++++++------- 6 files changed, 150 insertions(+), 73 deletions(-) create mode 100644 pandora_console/images/visual_console.menu.png diff --git a/pandora_console/images/visual_console.menu.png b/pandora_console/images/visual_console.menu.png new file mode 100644 index 0000000000000000000000000000000000000000..818beae6f2355799893dd2be8baaca5fa5239824 GIT binary patch literal 8400 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
'.__('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 71b6db82ac..6cb2b4a56c 100644 --- a/pandora_console/mobile/index.php +++ b/pandora_console/mobile/index.php @@ -349,6 +349,18 @@ switch ($action) { $agent = new Agent(); $agent->show(); break; + + case 'visualmap': + $id = $system->getRequest('id', null); + if ($id !== null) { + $vc = new Visualmap(); + $vc->show(); + } else { + // Show a list ov VC. + $vc_list = new Visualmaps(); + $vc_list->show(); + } + break; } break; } diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index d49f42eb0b..1fd8a79a47 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -59,12 +59,16 @@ class Home 'menu_item' => true, 'icon' => 'groups', ]; - $items['console'] = [ - 'name' => __('Visual consoles'), - 'filename' => 'vconsole.php', - 'menu_item' => true, - 'icon' => 'consoles', - ]; + + if ((bool) $system->getConfig('legacy_vc', false) === false) { + // Show Visual consoles only if new system is enabled. + $items['visualmap'] = [ + 'name' => __('Visual consoles'), + 'filename' => 'visualmaps.php', + 'menu_item' => true, + 'icon' => 'visual_console', + ]; + } if (!$system->getConfig('metaconsole')) { $items['alerts'] = [ diff --git a/pandora_console/mobile/operation/visualmaps.php b/pandora_console/mobile/operation/visualmaps.php index 632f0ff1a9..1159e14409 100644 --- a/pandora_console/mobile/operation/visualmaps.php +++ b/pandora_console/mobile/operation/visualmaps.php @@ -1,56 +1,107 @@ checkACL($this->acl)) { - $this->correct_acl = true; + $this->allowed = true; } else { - $this->correct_acl = false; + $this->allowed = false; } } + /** + * Prepare filters for current view. + * + * @return void + */ private function getFilters() { $system = System::getInstance(); $user = User::getInstance(); - $this->default_filters['group'] = true; - $this->default_filters['type'] = true; + $this->defaultFilters['group'] = true; + $this->defaultFilters['type'] = true; $this->group = (int) $system->getRequest('group', __('Group')); if (!$user->isInGroup($this->acl, $this->group)) { @@ -61,7 +112,7 @@ class Visualmaps $this->group = 0; } else { $this->default = false; - $this->default_filters['group'] = false; + $this->defaultFilters['group'] = false; } $this->type = $system->getRequest('type', __('Type')); @@ -69,14 +120,19 @@ class Visualmaps $this->type = '0'; } else { $this->default = false; - $this->default_filters['type'] = false; + $this->defaultFilters['type'] = false; } } + /** + * Run view. + * + * @return void + */ public function show() { - if (!$this->correct_acl) { + if (!$this->allowed) { $this->show_fail_acl(); } else { $this->getFilters(); @@ -85,12 +141,19 @@ class Visualmaps } + /** + * Show a message about failed ACL access. + * + * @return void + */ 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')) { + + // Redirect to main page. + if (class_exists('HomeEnterprise') === true) { $home = new HomeEnterprise(); } else { $home = new Home(); @@ -100,6 +163,11 @@ class Visualmaps } + /** + * Show visual console list header. + * + * @return void + */ private function show_visualmaps() { $ui = Ui::getInstance(); @@ -124,57 +192,44 @@ class Visualmaps } + /** + * Show list of visual consoles. + * + * @return void + */ private function listVisualmapsHtml() { $system = System::getInstance(); $ui = Ui::getInstance(); - // Create filter - $where = []; - // Order by type field - $where['order'] = 'type'; + $visualmaps = visual_map_get_user_layouts(); - if ($this->group != '0') { - $where['id_group'] = $this->group; - } - - if ($this->type != '0') { - $where['type'] = $this->type; - } - - // Only display maps of "All" group if user is administrator - // or has "RR" privileges, otherwise show only maps of user group - $id_user = $system->getConfig('id_user'); - $own_info = get_user_info($id_user); - if ($own_info['is_admin'] || $system->checkACL($this->acl)) { - $maps = visual_map_get_user_layouts(); - } else { - $maps = visual_map_get_user_layouts($id_user, false, false, false); - } - - if (empty($maps)) { - $maps = []; - } - - $list = []; - foreach ($maps as $map) { - $row = []; - $row[__('Name')] = ''.io_safe_output($map['name']).''; - // $row[__('Type')] = $map['type']; - $row[__('Group')] = ui_print_group_icon($map['id_group'], true, 'groups_small', '', false); - $list[] = $row; - } - - if (count($maps) == 0) { + if (empty($visualmaps) === true) { $ui->contentAddHtml('

'.__('No maps defined').'

'); } else { $table = new Table(); + // Without header jquery.mobile crashes. + $table->addHeader(['']); $table->id = 'list_visualmaps'; - $table->importFromHash($list); - $ui->contentAddHtml($table->getHTML()); - } + foreach ($visualmaps as $map) { + $link = ''.io_safe_output($map['name']).''; - $ui->contentAddLinkListener('list_visualmaps'); + $row = $link; + $row .= ui_print_group_icon( + $map['id_group'], + true, + 'groups_small', + '', + false + ); + $table->addRow([ $map['id'].' flex-center' => $row]); + } + + $ui->contentAddHtml($table->getHTML()); + $ui->contentAddLinkListener('list_visualmaps'); + } } From bc3616e6c5e28fe0db33f878457da90cba8283bd Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 18 Dec 2020 13:40:00 +0100 Subject: [PATCH 005/238] visual console mobile wip --- pandora_console/mobile/index.php | 17 ++++++++--------- pandora_console/mobile/operation/home.php | 2 +- pandora_server/util/recon_scripts/ipmi-recon.pl | 0 3 files changed, 9 insertions(+), 10 deletions(-) mode change 100644 => 100755 pandora_server/util/recon_scripts/ipmi-recon.pl diff --git a/pandora_console/mobile/index.php b/pandora_console/mobile/index.php index 6cb2b4a56c..bfeb6fe538 100644 --- a/pandora_console/mobile/index.php +++ b/pandora_console/mobile/index.php @@ -350,16 +350,15 @@ switch ($action) { $agent->show(); break; + case 'visualmaps': + // Show a list ov VC. + $vc_list = new Visualmaps(); + $vc_list->show(); + break; + case 'visualmap': - $id = $system->getRequest('id', null); - if ($id !== null) { - $vc = new Visualmap(); - $vc->show(); - } else { - // Show a list ov VC. - $vc_list = new Visualmaps(); - $vc_list->show(); - } + $vc = new Visualmap(); + $vc->show(); break; } break; diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index 1fd8a79a47..59b16683a7 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -62,7 +62,7 @@ class Home if ((bool) $system->getConfig('legacy_vc', false) === false) { // Show Visual consoles only if new system is enabled. - $items['visualmap'] = [ + $items['visualmaps'] = [ 'name' => __('Visual consoles'), 'filename' => 'visualmaps.php', 'menu_item' => true, diff --git a/pandora_server/util/recon_scripts/ipmi-recon.pl b/pandora_server/util/recon_scripts/ipmi-recon.pl old mode 100644 new mode 100755 From f72dabb04c948e9dca1b93b4d98e3000b76ca9f2 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 21 Dec 2020 14:23:50 +0100 Subject: [PATCH 006/238] New VC in mobile view (RC1) --- pandora_console/include/styles/dashboards.css | 11 + pandora_console/mobile/include/ui.class.php | 121 +++++ .../mobile/operation/visualmap.php | 416 ++++++++++++++---- 3 files changed, 471 insertions(+), 77 deletions(-) diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index bbbf993112..02263d7463 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -530,3 +530,14 @@ div#main_pure { #select_multiple_modules_filtered > div > div > * { flex: auto; } + +/* Mobile trick */ +.ui-mobile-viewport.ui-overlay-c > #main_page > .ui-content { + overflow: visible; + overflow-x: visible; + margin: 0 !important; + padding: 0 !important; +} +.ui-mobile-viewport.ui-overlay-c > #main_page > .ui-content div.label > p { + margin: 0; +} diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php index 1992268990..f87319b66b 100755 --- a/pandora_console/mobile/include/ui.class.php +++ b/pandora_console/mobile/include/ui.class.php @@ -1,4 +1,5 @@ \n"; echo " \n"; + $loaded = []; + foreach ($this->cssList as $filename) { + if (in_array($filename, $loaded) === true) { + continue; + } + + array_push($loaded, $filename); + + $url_css = ui_get_full_url($filename, false, false, false); + echo ''."\n\t"; + } + + $js_loaded = []; + foreach ($this->jsList as $filename) { + if (in_array($filename, $js_loaded) === true) { + continue; + } + + array_push($js_loaded, $filename); + + $url_css = ui_get_full_url($filename, false, false, false); + echo ''."\n\t"; + } + echo " \n"; echo " \n"; echo include_javascript_dependencies_flot_graph(false, false); @@ -857,6 +896,88 @@ class Ui } + /** + * Add CSS file to be loaded. + * + * @param string $name Css file name, as in ui_require_css. + * @param string $path Path where search for css file. + * + * @return boolean True if success, False if not. + */ + public function require_css( + string $name, + string $path='include/styles/' + ):bool { + $filename = $path.$name.'.css'; + $system = System::getInstance(); + + if (file_exists($filename) === false + && file_exists($system->getConfig('homedir').'/'.$filename) === false + && file_exists($system->getConfig('homedir').'/'.ENTERPRISE_DIR.'/'.$filename) === false + ) { + return false; + } + + if (in_array($filename, $this->cssList) === false) { + $this->cssList[] = $filename; + } + + return true; + } + + + /** + * Add JS file to be loaded. + * + * @param string $name JAvascript file name, as in + * \ui_require_javascript_file. + * @param string $path Path where search for Javascript file. + * + * @return boolean True if success, False if not. + */ + public function require_javascript( + string $name, + string $path='include/javascript/' + ):bool { + $filename = $path.$name.'.js'; + $system = System::getInstance(); + + if (file_exists($filename) === false + && file_exists($system->getConfig('homedir').'/'.$filename) === false + && file_exists($system->getConfig('homedir').'/'.ENTERPRISE_DIR.'/'.$filename) === false + ) { + return false; + } + + if (in_array($filename, $this->jsList) === false) { + $this->jsList[] = $filename; + } + + return true; + } + + + /** + * Forces reload to retrieve with and height. + * + * @return void + */ + public function retrieveViewPort() + { + ?> + + + checkACL($this->acl)) { - $this->correct_acl = true; + $this->validAcl = true; } else { - $this->correct_acl = false; + $this->validAcl = false; } } + /** + * Retrieve filters. + * + * @return void + */ private function getFilters() { $system = System::getInstance(); $this->id = (int) $system->getRequest('id', 0); + $this->width = (int) $system->getRequest('width', 0); + $this->height = (int) $system->getRequest('height', 0); + + if ($this->width < $this->height) { + $w = $this->width; + $this->width = $this->height; + $this->height = $w; + $this->rotate = true; + } } + /** + * Renders the view. + * + * @return void + */ public function show() { $this->getFilters(); + if (empty($this->width) === true + && empty($this->height) === true + ) { + // Reload forcing user to send width and height. + $ui = Ui::getInstance(); + $ui->retrieveViewPort(); + } + $this->visualmap = db_get_row( 'tlayout', 'id', @@ -65,7 +164,7 @@ class Visualmap } $this->checkVisualmapACL($this->visualmap['id_group']); - if (!$this->correct_acl) { + if (!$this->validAcl) { $this->show_fail_acl(); } @@ -73,12 +172,25 @@ class Visualmap } - private function show_fail_acl() + /** + * Shows an error if ACL fails. + * + * @param string $msg Optional message. + * + * @return void + */ + private function show_fail_acl(string $msg='') { $error['type'] = 'onStart'; - $error['title_text'] = __('You don\'t have access to this page'); - $error['content_text'] = System::getDefaultACLFailText(); - if (class_exists('HomeEnterprise')) { + if (empty($msg) === false) { + $error['title_text'] = __('Error'); + $error['content_text'] = $msg; + } else { + $error['title_text'] = __('You don\'t have access to this page'); + $error['content_text'] = System::getDefaultACLFailText(); + } + + if (class_exists('HomeEnterprise') === true) { $home = new HomeEnterprise(); } else { $home = new Home(); @@ -88,11 +200,18 @@ class Visualmap } - public function ajax($parameter2=false) + /** + * Ajax call manager. + * + * @param string $parameter2 Not sure why is doing this stuff. + * + * @return void + */ + public function ajax(string $parameter2='') { $system = System::getInstance(); $this->checkVisualmapACL($this->visualmap['id_group']); - if (!$this->correct_acl) { + if ((bool) $this->validAcl === false) { $this->show_fail_acl(); } else { switch ($parameter2) { @@ -100,18 +219,55 @@ class Visualmap $map_id = $system->getRequest('map_id', '0'); $width = $system->getRequest('width', '400'); $height = $system->getRequest('height', '400'); - visual_map_print_visual_map($map_id, false, true, $width, $height); + visual_map_print_visual_map( + $map_id, + false, + true, + $width, + $height + ); + exit; + + default: exit; } } } + /** + * Generates HTML code to view target Visual console. + * + * @return void + */ private function show_visualmap() { $ui = Ui::getInstance(); $system = System::getInstance(); + include_once $system->getConfig('homedir').'/vendor/autoload.php'; + + // Query parameters. + $visualConsoleId = (int) $system->getRequest('id'); + + // Refresh interval in seconds. + $refr = (int) get_parameter('refr', $system->getConfig('vc_refr')); + + // Check groups can access user. + $aclUserGroups = []; + if (!users_can_manage_group_all('AR')) { + $aclUserGroups = array_keys(users_get_groups(false, 'AR')); + } + + // Load Visual Console. + $visualConsole = null; + try { + $visualConsole = VisualConsole::fromDB(['id' => $visualConsoleId]); + } catch (Throwable $e) { + $this->show_fail_acl($e->getMessage()); + exit; + } + $ui->createPage(); $ui->createDefaultHeader( sprintf( @@ -127,61 +283,167 @@ class Visualmap ] ) ); + + $ui->require_css('visual_maps'); + $ui->require_css('register'); + $ui->require_css('dashboards'); + $ui->require_javascript('pandora_visual_console'); + $ui->require_javascript('pandora_dashboards'); + $ui->require_javascript('jquery.cookie'); + $ui->require_css('modal'); + $ui->require_css('form'); + $ui->showFooter(false); $ui->beginContent(); - - ob_start(); - $rendered_map = '
'; - $rendered_map .= html_print_image('images/spinner.gif', true); - $rendered_map .= '
'; - ob_clean(); - - $ui->contentAddHtml($rendered_map); $ui->contentAddHtml( - "" + include_javascript_d3(true) ); + + $size = [ + 'width' => $this->width, + 'height' => $this->height, + ]; + + $visualConsoleData = $visualConsole->toArray(); + $ratio_visualconsole = ($visualConsoleData['height'] / $visualConsoleData['width']); + $ratio_t = ($size['width'] / $visualConsoleData['width']); + $radio_h = ($size['height'] / $visualConsoleData['height']); + + $visualConsoleData['width'] = $size['width']; + $visualConsoleData['height'] = ($size['width'] * $ratio_visualconsole); + + if ($visualConsoleData['height'] > $size['height']) { + $ratio_t = $radio_h; + + $visualConsoleData['height'] = $size['height']; + $visualConsoleData['width'] = ($size['height'] / $ratio_visualconsole); + } + + $uniq = uniqid(); + + $output = '
'; + // Style. + $style = 'width:'.$visualConsoleData['width'].'px;'; + $style .= 'height:'.$visualConsoleData['height'].'px;'; + $style .= 'background-size: cover;'; + + // Class. + $class = 'visual-console-container-dashboard c-'.$uniq; + // Id. + $id = 'visual-console-container-'.$uniq; + $output .= '
'; + $output .= '
'; + $output .= '
'; + + // Check groups can access user. + $aclUserGroups = []; + if (users_can_manage_group_all('AR') === true) { + $aclUserGroups = array_keys( + users_get_groups(false, 'AR') + ); + } + + $ignored_params['refr'] = ''; + \ui_require_javascript_file( + 'tiny_mce', + 'include/javascript/tiny_mce/' + ); + \ui_require_javascript_file( + 'pandora_visual_console', + 'include/javascript/', + true + ); + \include_javascript_d3(); + \visual_map_load_client_resources(); + + // Load Visual Console Items. + $visualConsoleItems = VisualConsole::getItemsFromDB( + $visualConsoleId, + $aclUserGroups, + $ratio_t + ); + + // Horrible trick! due to the use of tinyMCE + // it is necessary to modify specific classes of each + // of the visual consoles. + $output .= ''; + + $visualConsoleItems = array_reduce( + $visualConsoleItems, + function ($carry, $item) use ($ratio_t) { + $carry[] = $item->toArray(); + return $carry; + }, + [] + ); + + $settings = \json_encode( + [ + 'props' => $visualConsoleData, + 'items' => $visualConsoleItems, + 'baseUrl' => ui_get_full_url('/', false, false, false), + 'ratio' => $ratio_t, + 'size' => $size, + 'cellId' => $uniq, + ] + ); + + $output .= ''; + + $ui->contentAddHtml($output); + + // Load Visual Console Items. + $visualConsoleItems = VisualConsole::getItemsFromDB( + $visualConsoleId, + $aclUserGroups + ); + + $javascript = ob_get_clean(); + $ui->contentAddHtml($javascript); + $ui->endContent(); $ui->showPage(); } From 025288d9fe5282b1fe35fc7ab2b058c62541e931 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 21 Dec 2020 18:10:46 +0100 Subject: [PATCH 007/238] Fixes on VC navigation (mobile) --- pandora_console/include/functions.php | 6 +++++- pandora_console/mobile/include/user.class.php | 17 +++++++++++++++-- pandora_console/mobile/operation/visualmap.php | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index f79c56b764..c63b928049 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2249,12 +2249,16 @@ function check_login($output=true) return true; } } else { + include_once $config['homedir'].'/mobile/include/db.class.php'; + include_once $config['homedir'].'/mobile/include/system.class.php'; include_once $config['homedir'].'/mobile/include/user.class.php'; if (isset($_SESSION['user'])) { - $user = $_SESSION['user']; + $user = User::getInstance(); $id_user = $user->getIdUser(); if (is_user($id_user)) { + $_SESSION['id_usuario'] = $id_user; + $config['id_user'] = $id_user; return true; } } diff --git a/pandora_console/mobile/include/user.class.php b/pandora_console/mobile/include/user.class.php index 3a46ebac1d..e6ef007206 100644 --- a/pandora_console/mobile/include/user.class.php +++ b/pandora_console/mobile/include/user.class.php @@ -38,8 +38,15 @@ class User $system = System::getInstance(); $user = $system->getSession('user', null); + if (is_object($user) === false) { + $user = json_decode($user, true); + } + if (!empty($user)) { - self::$instance = $user; + self::$instance = new self(); + foreach ($user as $k => $v) { + self::$instance->{$k} = $v; + } } else { self::$instance = new self(); } @@ -49,6 +56,12 @@ class User } + public function jsonSerialize() + { + return get_object_vars($this); + } + + public function saveLogin() { if ($this->logged) { @@ -59,7 +72,7 @@ class User $config['id_user'] = $this->user; $system->setSessionBase('id_usuario', $this->user); - $system->setSession('user', $this); + $system->setSession('user', json_encode($this->jsonSerialize())); config_user_set_custom_config(); } diff --git a/pandora_console/mobile/operation/visualmap.php b/pandora_console/mobile/operation/visualmap.php index 1667e8caf0..1313fc0f24 100644 --- a/pandora_console/mobile/operation/visualmap.php +++ b/pandora_console/mobile/operation/visualmap.php @@ -153,6 +153,8 @@ class Visualmap $ui->retrieveViewPort(); } + $this->height -= 39; + $this->visualmap = db_get_row( 'tlayout', 'id', From ac8af7ee527df8ec08260ec3fae63e52411b7be6 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Dec 2020 14:40:04 +0100 Subject: [PATCH 008/238] Use mobile navitagion in VC items while using mobile view --- .../rest-api/models/VisualConsole/Item.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index 13ddc6590f..31d17b55c5 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -1058,6 +1058,16 @@ class Item extends CachedModel { global $config; + $mobile_navigation = false; + + if (isset($_SERVER['PHP_SELF']) === true + && (strstr($_SERVER['PHP_SELF'], 'mobile/') !== false + || strstr($_SERVER['HTTP_REFERER'], 'mobile/') !== false) + ) { + $mobile_navigation = true; + } + + error_log(obhd($_SERVER['PHP_SELF'])); // Load side libraries. include_once $config['homedir'].'/include/functions_ui.php'; if (\is_metaconsole()) { @@ -1070,6 +1080,7 @@ class Item extends CachedModel $linkedAgent = static::extractLinkedAgent($data); $baseUrl = \ui_get_full_url('index.php'); + $mobileUrl = \ui_get_full_url('mobile/index.php'); // TODO: There's a feature to get the link from the label. if (static::$useLinkedVisualConsole === true @@ -1117,6 +1128,15 @@ class Item extends CachedModel * We are in a regular console. */ + if ($mobile_navigation === true) { + return $mobileUrl.'?'.http_build_query( + [ + 'page' => 'visualmap', + 'id' => $vcId, + ] + ); + } + return $baseUrl.'?'.http_build_query( [ 'sec' => 'network', @@ -1190,6 +1210,15 @@ class Item extends CachedModel ]; } + if ($mobile_navigation === true) { + return $mobileUrl.'?'.http_build_query( + [ + 'page' => 'module_graph', + 'id' => $moduleId, + ] + ); + } + return $baseUrl.'?'.http_build_query($queryParams); } else if (\is_metaconsole() && \can_user_access_node()) { /* @@ -1265,6 +1294,15 @@ class Item extends CachedModel * We are in a regular console. */ + if ($mobile_navigation === true) { + return $mobileUrl.'?'.http_build_query( + [ + 'page' => 'agent', + 'id' => $agentId, + ] + ); + } + return $baseUrl.'?'.http_build_query( [ 'sec' => 'estado', From 79ac7f43f7964f1777af94325c1ea6289a3426da Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Dec 2020 17:01:49 +0100 Subject: [PATCH 009/238] Style fixes (minor) event details --- pandora_console/mobile/include/style/main.css | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css index 347dce6732..2b29f6025a 100755 --- a/pandora_console/mobile/include/style/main.css +++ b/pandora_console/mobile/include/style/main.css @@ -349,6 +349,22 @@ tr.events { font-size: 12px !important; } +table.event_details { + height: 14px; + color: #424242; +} + +table.event_details tr th { + text-align: left; +} + +table.event_details td:not(:first-child) { + display: flex; + flex-direction: row; + align-items: center; + justify-items: start; +} + table#list_events th { font-size: 12px !important; font-weight: bolder !important; From c429ec59d5a5c36b59709efca640d8f77bc65bde Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Dec 2020 17:04:29 +0100 Subject: [PATCH 010/238] module status ball css fix --- pandora_console/mobile/include/style/main.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css index 2b29f6025a..60dd6f625d 100755 --- a/pandora_console/mobile/include/style/main.css +++ b/pandora_console/mobile/include/style/main.css @@ -1363,6 +1363,12 @@ span.nobold * { display: block !important; } +.status_rounded_rectangles.forced_title { + width: 1em; + height: 1em; + border-radius: 50%; +} + #list_Modules *, #list_agent_Modules *, #list_agents *, From 6ada7d46c85ba0210d1b51acbc9ebde37cfe85e5 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Dec 2020 17:09:21 +0100 Subject: [PATCH 011/238] event select list margin issue css --- pandora_console/mobile/include/style/main.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css index 60dd6f625d..81d6ce7af1 100755 --- a/pandora_console/mobile/include/style/main.css +++ b/pandora_console/mobile/include/style/main.css @@ -1369,6 +1369,11 @@ span.nobold * { border-radius: 50%; } +.ui-content .ui-listview, +.ui-panel-inner > .ui-listview { + margin: 0 !important; +} + #list_Modules *, #list_agent_Modules *, #list_agents *, From c55bdb6e6d4add120779c85dac2d55ffccfba722 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Dec 2020 17:16:38 +0100 Subject: [PATCH 012/238] Changed global to agent search because is only searching for agents... --- pandora_console/mobile/operation/home.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index 59b16683a7..c2afb324ed 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -165,7 +165,7 @@ class Home $options = [ 'name' => 'free_search', 'value' => $this->global_search, - 'placeholder' => __('Global search'), + 'placeholder' => __('Agent search'), ]; $ui->formAddInputSearch($options); $ui->endForm(); From 4fe9bdb9a53c60605adcb39aaf7bd0afbd33f6c6 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Wed, 30 Dec 2020 18:39:56 +0100 Subject: [PATCH 013/238] Fixed session close on api --- pandora_console/include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 944c3a710c..eccad7ad70 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -311,7 +311,7 @@ if ($correctLogin) { } // Logout. -if (session_status() === PHP_SESSION_ACTIVE) { +if (session_status() !== PHP_SESSION_DISABLED) { $_SESSION = []; // Could give a warning if no session file is created. Ignore. @session_destroy(); From 3f61d97e0fea22caff4a8b2d22934e024cbeb054 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 12 Jan 2021 13:39:03 +0100 Subject: [PATCH 014/238] Event text to Event name in alert_actions Monitoring event --- pandora_console/extras/mr/46.sql | 5 +++++ .../extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 1 + pandora_console/pandoradb_data.sql | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 pandora_console/extras/mr/46.sql diff --git a/pandora_console/extras/mr/46.sql b/pandora_console/extras/mr/46.sql new file mode 100644 index 0000000000..9e22fc0886 --- /dev/null +++ b/pandora_console/extras/mr/46.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +UPDATE `talert_commands` SET `fields_descriptions` = '[\"Event name\",\"Event type\",\"Source\",\"Agent name or _agent_\",\"Event severity\",\"ID extra\",\"Tags separated by commas\",\"Comments\",\"\",\"\"]' WHERE `name` = "Monitoring Event"; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index bae705f725..bd1eeee8a5 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2494,6 +2494,7 @@ CREATE TABLE `tnotification_source_group_user` ( -- Add alert command 'Generate notification' -- ---------------------------------------------------------------------- INSERT INTO `talert_commands` (`name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES ('Generate Notification','Internal type','This command allows you to send an internal notification to any user or group.',1,'[\"Destination user\",\"Destination group\",\"Title\",\"Message\",\"Link\",\"Criticity\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]'); +UPDATE `talert_commands` SET `fields_descriptions` = '[\"Event name\",\"Event type\",\"Source\",\"Agent name or _agent_\",\"Event severity\",\"ID extra\",\"Tags separated by commas\",\"Comments\",\"\",\"\"]' WHERE `name` = "Monitoring Event"; -- ---------------------------------------------------------------------- -- Update message references and pre-configure notifications diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index f58b5d2170..d36fa742c1 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -14,7 +14,7 @@ INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (1,'eMail','Internal type','This alert send an email using internal Server SMTP capabilities (defined in each server, using: _field1_ as destination email address, and _field2_ as subject for message. _field3_ as text of message. _field4_ as content type (plain/text or html/text).',1,'[\"Destination address\",\"Subject\",\"Text\",\"Content Type\",\"\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"_html_editor_\",\"_content_type_\",\"\",\"\",\"\",\"\",\"\",\"\"]'); INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (2,'Internal Audit','Internal type','This alert save alert in internal audit system. Fields are static and only _field1_ is used.',1,'[\"Description\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]'); -INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (3,'Monitoring Event','Internal type','This alert create an special event into event manager.',1,'[\"Event text\",\"Event type\",\"Source\",\"Agent name or _agent_\",\"Event severity\",\"ID extra\",\"Tags separated by commas\",\"Comments\",\"\",\"\"]','[\"\",\"alert_ceased,Alert ceased;alert_fired,Alert fired;alert_manual_validation,Alert manual validation;alert_recovered,Alert recovered;configuration_change,Configuration change ;error,Error;critical,Monitor Critical;normal,Monitor Normal;going_unknown,Monitor\",\"\",\"\",\"4,Critical;1,Informational;0,Maintenance;6,Major;5,Minor;2,Normal;3,Warning\",\"\",\"\",\"\",\"\",\"\"]'); +INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (3,'Monitoring Event','Internal type','This alert create an special event into event manager.',1,'[\"Event name\",\"Event type\",\"Source\",\"Agent name or _agent_\",\"Event severity\",\"ID extra\",\"Tags separated by commas\",\"Comments\",\"\",\"\"]','[\"\",\"alert_ceased,Alert ceased;alert_fired,Alert fired;alert_manual_validation,Alert manual validation;alert_recovered,Alert recovered;configuration_change,Configuration change ;error,Error;critical,Monitor Critical;normal,Monitor Normal;going_unknown,Monitor\",\"\",\"\",\"4,Critical;1,Informational;0,Maintenance;6,Major;5,Minor;2,Normal;3,Warning\",\"\",\"\",\"\",\"\",\"\"]'); INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (4,'Alertlog','echo _timestamp_ pandora _agent_ _data_ _field1_ _field2_ >> /var/log/pandora/pandora_alert.log','This is a default alert to write alerts in a standard ASCII plaintext log file in /var/log/pandora/pandora_alert.log ',0,'[\"Log Info 1\",\"Log Info 2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]'); INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (5,'SNMP Trap','/usr/bin/snmptrap -v 1 -c _field1_ _field2_ _field3_ _field4_','Send a SNMPTRAP to 192.168.0.4. Please review config and adapt to your needs, this is only a sample, not functional itself.',0,'[\"Community\",\"Destination address\",\"OID\",\"Source address\",\"\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]'); INSERT INTO `talert_commands` (`id`, `name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES (6,'Syslog','logger -p daemon.alert Pandora Alert _agent_ _data_ _field1_ _field2_','Uses field1 and field2 to generate Syslog alert in facility daemon with "alert" level.',0,'[\"Log Info 1\",\"Log Info 2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]'); From d9f360016b8ab211fc5dbb0b01abafe5231c94c5 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 26 Jan 2021 09:06:49 +0100 Subject: [PATCH 015/238] user_list optimization --- pandora_console/godmode/users/user_list.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 5178cce690..a297811c8d 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -412,17 +412,21 @@ if (!defined('METACONSOLE')) { $table->valign[6] = 'top'; } -$group_um = users_get_groups_UM($config['id_user']); - $info1 = []; $user_is_admin = users_is_admin(); -// Is admin or has group permissions all. -if ($user_is_admin || isset($group_um[0])) { + +if ($user_is_admin) { $info1 = get_users($order); } else { - foreach ($group_um as $group => $value) { - $info1 = array_merge($info1, users_get_users_by_group($group, $value)); + $group_um = users_get_groups_UM($config['id_user']); + // 0 is the group 'all'. + if (isset($group_um[0])) { + $info1 = get_users($order); + } else { + foreach ($group_um as $group => $value) { + $info1 = array_merge($info1, users_get_users_by_group($group, $value)); + } } } From 26a788b2e9ebb391087116c773dde49a46080372 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 26 Jan 2021 12:35:08 +0100 Subject: [PATCH 016/238] Added control for max agents in groups --- pandora_console/extras/mr/46.sql | 5 ++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 6 ++ .../godmode/agentes/configurar_agente.php | 5 ++ .../godmode/groups/configure_group.php | 50 +++++++++--- pandora_console/godmode/groups/group_list.php | 4 + pandora_console/include/functions_agents.php | 77 +++++++++++++++---- pandora_console/include/functions_api.php | 8 ++ pandora_console/pandoradb.sql | 1 + 8 files changed, 129 insertions(+), 27 deletions(-) create mode 100644 pandora_console/extras/mr/46.sql diff --git a/pandora_console/extras/mr/46.sql b/pandora_console/extras/mr/46.sql new file mode 100644 index 0000000000..c5fb00cd7e --- /dev/null +++ b/pandora_console/extras/mr/46.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE tgrupo ADD COLUMN max_agents int(10) NOT NULL DEFAULT 0; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 8c204943db..88d0e9ecc3 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2828,6 +2828,12 @@ UPDATE twidget SET description='Show a visual console' WHERE class_name='MapsMad UPDATE twidget SET description='Clock' WHERE class_name='ClockWidget'; UPDATE twidget SET description='Group status' WHERE class_name='SystemGroupStatusWidget'; +-- +-- Modifies tgrupo table. +-- + +ALTER TABLE tgrupo ADD COLUMN max_agents int(10) NOT NULL DEFAULT 0; + -- ---------------------------------------------------------------------- -- Table `tnode_relations` -- ---------------------------------------------------------------------- diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 72fc0ef125..e53b908691 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -229,6 +229,9 @@ if ($create_agent) { if ($alias == '') { $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; + } else if (group_allow_more_agents($grupo) === false) { + $agent_creation_error = __('Agent cannot be created due to the maximum agent limit for this group'); + $agent_created_ok = 0; } else { if ($alias_as_name) { $sql = 'SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'; @@ -947,6 +950,8 @@ if ($update_agent) { if ($grupo <= 0) { ui_print_error_message(__('The group id %d is incorrect.', $grupo)); + } else if (group_allow_more_agents($grupo) === false) { + ui_print_error_message(__('Agent cannot be updated due to the maximum agent limit for this group')); } else if ($exists_ip) { ui_print_error_message(__('Duplicate main IP address')); } else { diff --git a/pandora_console/godmode/groups/configure_group.php b/pandora_console/godmode/groups/configure_group.php index 019a981578..c4ce2361c5 100644 --- a/pandora_console/godmode/groups/configure_group.php +++ b/pandora_console/godmode/groups/configure_group.php @@ -1,16 +1,32 @@ '; @@ -223,6 +241,10 @@ if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK && !defined('METACONSOLE')) { $table->data[9][1] = skins_print_select($config['id_user'], 'skin', $skin, '', __('None'), 0, true); } +$table->data[$i][0] = __('Max agents allowed').' '.ui_print_help_tip(__('Set the maximum of agents allowed for this group. 0 is unlimited.'), true); +$table->data[$i][1] = html_print_input_text('max_agents', $max_agents, '', 10, 255, true); +$i++; + if (defined('METACONSOLE')) { $sec = 'advanced'; } else { @@ -240,6 +262,7 @@ if (isset($config['metaconsole_node_id']) && $config['metaconsole_node_id'] > 0) echo '
'; html_print_table($table); echo '
'; + html_print_button(__('Back'), 'button_back', false, '', 'class="sub cancel"'); if ($id_group) { html_print_input_hidden('update_group', 1); html_print_input_hidden('id_group', $id_group); @@ -330,5 +353,8 @@ function parent_changed () { $(document).ready (function () { $('#icon').change (icon_changed); $('#id_parent').change (parent_changed); + $('#button-button_back').on('click', function(){ + window.location = ''; + }); }); diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index ad6eb27adf..4bb170f2a4 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -367,6 +367,7 @@ if (($create_group) && (check_acl($config['id_user'], 0, 'PM'))) { $description = (string) get_parameter('description'); $contact = (string) get_parameter('contact'); $other = (string) get_parameter('other'); + $max_agents = (int) get_parameter('max_agents', 0); $check = db_get_value('nombre', 'tgrupo', 'nombre', $name); $propagate = (bool) get_parameter('propagate'); @@ -391,6 +392,7 @@ if (($create_group) && (check_acl($config['id_user'], 0, 'PM'))) { 'propagate' => $propagate, 'other' => $other, 'password' => io_safe_input($group_pass), + 'max_agents' => $max_agents, ]; $result = db_process_sql_insert('tgrupo', $values); @@ -424,6 +426,7 @@ if ($update_group) { $description = (string) get_parameter('description'); $contact = (string) get_parameter('contact'); $other = (string) get_parameter('other'); + $max_agents = (int) get_parameter('max_agents', 0); $aviable_name = true; if (preg_match('/script/i', $name)) { @@ -457,6 +460,7 @@ if ($update_group) { 'propagate' => $propagate, 'other' => $other, 'password' => io_safe_input($group_pass), + 'max_agents' => $max_agents, ]; $result = db_process_sql_update( diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 8be043fb98..7d605c7746 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1,22 +1,32 @@ $id_group] + ); + // Notice this issue. + db_pandora_audit( + 'Agent management', + sprintf( + 'Agent cannot be created due to the maximum agent limit for group "%s"', + $groupName + ) + ); + return false; + } + $id_agent = db_process_sql_insert('tagente', $values); if ($id_agent === false) { return false; @@ -3800,3 +3829,21 @@ function agents_get_last_status_change($id_agent) return $row['last_status_change']; } + + +/** + * Checks if group allow more agents due itself limitation. + * + * @param integer $id_group Id of the group + * @return boolean True if allow more agents. + */ +function group_allow_more_agents(int $id_group):bool +{ + $groupMaxAgents = (int) db_get_value('max_agents', 'tgrupo', sprintf('id_grupo = %d', $id_group)); + $groupCountAgents = (int) db_get_num_rows(sprintf('SELECT nombre FROM tagente WHERE id_grupo = "%s"', $id_group)); + + // If `max_agents` is not defined or the count of agents in the group is below of max agents allowed. + $output = ($groupMaxAgents === 0 || $groupCountAgents < $groupMaxAgents); + + return $output; +} diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 1afd3f8431..5b1a5e7af3 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1359,6 +1359,12 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) return; } + // Check if group allow more agents or have limit stablished. + if (group_allow_more_agents($idGroup) === false) { + returnError('Agent cannot be updated due to the maximum agent limit for this group'); + return; + } + // Check selected parent if ($idParent != 0) { $parentCheck = agents_check_access_agent($idParent); @@ -1561,6 +1567,8 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) returnError('agent_name_exist', 'The name of agent yet exist in DB.'); } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { returnError('id_grupo_not_exist', 'The group don`t exist.'); + } else if (group_allow_more_agents($grupo) === false) { + returnError('Agent cannot be created due to the maximum agent limit for this group'); } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { returnError('id_os_not_exist', 'The OS don`t exist.'); } else if ($server_name === false) { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 090e87fd2e..cef80ffcdf 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -722,6 +722,7 @@ CREATE TABLE IF NOT EXISTS `tgrupo` ( `contact` text, `other` text, `password` varchar(45) default '', + `max_agents` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id_grupo`), KEY `parent_index` (`parent`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 9454ed2ff3114c38cf9e5f52376a6fb59ffff656 Mon Sep 17 00:00:00 2001 From: marcos Date: Mon, 1 Feb 2021 12:11:39 +0100 Subject: [PATCH 017/238] unsort template items --- pandora_console/include/functions_reporting.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0d4b19efc0..face94f8e9 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -189,6 +189,14 @@ function reporting_make_reporting_data( $metaconsole_on = is_metaconsole(); $index_content = 0; + + usort( + $contents, + function ($a, $b) { + return ($a['order'] <=> $b['order']); + } + ); + foreach ($contents as $content) { $content['name'] = io_safe_input($content['name']); $content['description'] = io_safe_input($content['description']); From 6a9587bff875e5e0771b71726b7e124873341551 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 1 Feb 2021 13:54:57 +0100 Subject: [PATCH 018/238] #4536 autocomplete = off by default --- pandora_console/include/functions_html.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index df1efd0703..538f0a23de 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2095,7 +2095,7 @@ function html_print_input_text_extended( 'list', ]; - $output = ' $attr_value) { // Check valid attribute. if (in_array($attribute, $valid_attrs) === false) { @@ -2581,6 +2581,10 @@ function html_print_input_number(array $settings):string $settings['maxlength'] = 255; } + if (isset($settings['autocomplete']) === false) { + $settings['autocomplete'] = 'off'; + } + foreach ($settings as $attribute => $attr_value) { // Check valid attribute. if (in_array($attribute, $valid_attrs) === false) { @@ -4357,7 +4361,7 @@ function html_print_input($data, $wrapper='div', $input_only=false) ((isset($data['function']) === true) ? $data['function'] : ''), ((isset($data['class']) === true) ? $data['class'] : ''), ((isset($data['onChange']) === true) ? $data['onChange'] : ''), - ((isset($data['autocomplete']) === true) ? $data['autocomplete'] : ''), + ((isset($data['autocomplete']) === true) ? $data['autocomplete'] : 'off'), ((isset($data['autofocus']) === true) ? $data['autofocus'] : false), ((isset($data['onKeyDown']) === true) ? $data['onKeyDown'] : ''), ((isset($data['form']) === true) ? $data['form'] : ''), From 0ddc1929fac6b07eb06f982af0cb7ba467dec990 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 2 Feb 2021 11:25:26 +0100 Subject: [PATCH 019/238] multiple fixes --- pandora_console/godmode/tag/tag.php | 3 +++ pandora_console/godmode/users/user_list.php | 28 +++++++++++---------- pandora_console/include/ajax/events.php | 16 ++++++++---- pandora_console/include/functions.php | 6 ++++- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/pandora_console/godmode/tag/tag.php b/pandora_console/godmode/tag/tag.php index a80c2b76bb..d5711cbab7 100644 --- a/pandora_console/godmode/tag/tag.php +++ b/pandora_console/godmode/tag/tag.php @@ -66,6 +66,7 @@ if (is_ajax()) { function ($counter, $server) use ($id_tag) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_local_modules_count($id_tag); + metaconsole_restore_db(); } return $counter; @@ -83,6 +84,7 @@ if (is_ajax()) { function ($counter, $server) use ($id_tag) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_policy_modules_count($id_tag); + metaconsole_restore_db(); } return $counter; @@ -261,6 +263,7 @@ if (!empty($result)) { function ($counter, $server) use ($tag_id) { if (metaconsole_connect($server) === NOERR) { $counter += tags_get_modules_count($tag_id); + metaconsole_restore_db(); } return $counter; diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 5178cce690..488361b1d0 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -232,21 +232,21 @@ if (isset($_GET['user_del'])) { if (defined('METACONSOLE') && isset($_GET['delete_all'])) { $servers = metaconsole_get_servers(); foreach ($servers as $server) { - // Connect to the remote console - metaconsole_connect($server); + // Connect to the remote console. + if (metaconsole_connect($server) === NOERR) { + // Delete the user + $result = delete_user($id_user); + if ($result) { + db_pandora_audit( + 'User management', + __('Deleted user %s from metaconsole', io_safe_input($id_user)) + ); + } - // Delete the user - $result = delete_user($id_user); - if ($result) { - db_pandora_audit( - 'User management', - __('Deleted user %s from metaconsole', io_safe_input($id_user)) - ); + // Restore the db connection. + metaconsole_restore_db(); } - // Restore the db connection - metaconsole_restore_db(); - // Log to the metaconsole too if ($result) { db_pandora_audit( @@ -613,7 +613,9 @@ foreach ($info as $user_id => $user_info) { $data[6] .= ''.html_print_image('images/config.png', true, ['title' => __('Edit')]).''; if ($config['admin_can_delete_user'] && $user_info['id_user'] != $config['id_user'] && !isset($user_info['not_delete'])) { $data[6] .= "".html_print_image('images/cross.png', true, ['title' => __('Delete'), 'onclick' => "if (! confirm ('".__('Deleting User').' '.$user_info['id_user'].'. '.__('Are you sure?')."')) return false"]).''; - if (defined('METACONSOLE')) { + if ((bool) is_metaconsole() === true + && (bool) can_user_access_node() === true + ) { $data[6] .= "".html_print_image('images/cross_double.png', true, ['title' => __('Delete from all consoles'), 'onclick' => "if (! confirm ('".__('Deleting User %s from all consoles', $user_info['id_user']).'. '.__('Are you sure?')."')) return false"]).''; } } else { diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index b47a750e85..5e14d73ae8 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1436,15 +1436,21 @@ if ($get_extended_event) { $related = events_page_related($event, $server); } + $connected = true; if ($meta) { - metaconsole_connect($server); + if (metaconsole_connect($server) === NOERR) { + $connected = true; + } else { + $connected = false; + } } - $custom_fields = events_page_custom_fields($event); + if ($connected === true) { + $custom_fields = events_page_custom_fields($event); + $custom_data = events_page_custom_data($event); + } - $custom_data = events_page_custom_data($event); - - if ($meta) { + if ($meta && $connected === true) { metaconsole_restore_db(); } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 2509a67a66..0b07c16ebc 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2850,7 +2850,11 @@ function can_user_access_node() { global $config; - $userinfo = get_user_info($config['id_user']); + static $userinfo; + + if ($userinfo === null) { + $userinfo = get_user_info($config['id_user']); + } if (is_metaconsole()) { return $userinfo['is_admin'] == 1 ? 1 : $userinfo['metaconsole_access_node']; From 28445e3decc55f7a899dca18c99b8113673c7f98 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 2 Feb 2021 15:45:47 +0100 Subject: [PATCH 020/238] API get license, get license_remaining --- pandora_console/include/api.php | 1 + pandora_console/include/functions_api.php | 96 +++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 944c3a710c..5182a87d25 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -36,6 +36,7 @@ define('DEBUG', 0); define('VERBOSE', 0); // TESTING THE UPDATE MANAGER. +enterprise_include_once('load_enterprise.php'); enterprise_include_once('include/functions_enterprise_api.php'); $ipOrigin = $_SERVER['REMOTE_ADDR']; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d30da4cc4c..843ae291cb 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -375,6 +375,102 @@ function api_get_test_event_replication_db() // -------------------------DEFINED OPERATIONS FUNCTIONS----------------- + + +/** + * Example: http://localhost/pandora_console/include/api.php?op=get&op2=license&user=admin&apipass=1234&pass=pandora&return_type=json + * Retrieve license information. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license($trash1, $trash2, $trash3, $returnType='json') +{ + global $config; + check_login(); + + if (! check_acl($config['id_user'], 0, 'PM')) { + returnError('forbidden', $returnType); + return; + } + + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + // Not an enterprise environment? + if (license_free()) { + $license = 'PANDORA_FREE'; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => ['license_mode' => $license], + ] + ); + return; + } + + returnData( + $returnType, + [ + 'type' => 'array', + 'data' => $license, + ] + ); + +} + + +/** + * Retrieve license status agents or modules left. + * + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param null $trash1 Not used. + * @param string $returnType Return type (string, json...). + * + * @return void + */ +function api_get_license_remaining( + $trash1, + $trash2, + $trash3, + $returnType='json' +) { + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + if ($license === ENTERPRISE_NOT_HOOK) { + if (license_free()) { + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => PHP_INT_MAX, + ] + ); + } else { + returnError('get-license', 'Failed to verify license.'); + } + + return; + } + + returnData( + $returnType, + [ + 'type' => 'integer', + 'data' => ($license['limit'] - $license['count_enabled']), + ] + ); +} + + function api_get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) { $returnAllGroup = true; From f47eefdeec202d67665d578185521718457f97bf Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 2 Feb 2021 15:55:01 +0100 Subject: [PATCH 021/238] Minor fix --- pandora_console/include/functions_api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 843ae291cb..9d616da4b7 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -428,6 +428,7 @@ function api_get_license($trash1, $trash2, $trash3, $returnType='json') /** + * Example: http://localhost/pandora_console/include/api.php?op=get&op2=license_remaining&user=admin&apipass=1234&pass=pandora&return_type=json * Retrieve license status agents or modules left. * * @param null $trash1 Not used. From 7017c6136eb0dd9bd8fa72c3372a3b668c3f763d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 10 Feb 2021 10:21:39 +0100 Subject: [PATCH 022/238] Avoid events while ceasing alerts --- pandora_server/lib/PandoraFMS/Core.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 24b89ce1f1..aa63bba6d8 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -679,7 +679,12 @@ sub pandora_process_alert ($$$$$$$$;$$) { $alert->{'critical_instructions'} = $critical_instructions; $alert->{'warning_instructions'} = $warning_instructions; $alert->{'unknown_instructions'} = $unknown_instructions; - + + # Generate event only if not quieted by module or agent. + return if ((ref($module) eq 'HASH' && $module->{'quiet'} != "0") + || (ref($agent) eq 'HASH' && $agent->{'quiet'} != "0") + || (ref($alert) eq 'HASH' && $alert->{'disable_event'} != "0")); + # Generate an event if ($table eq 'tevent_alert') { pandora_event ($pa_config, "Alert ceased (" . From b44d9980347c80bc178ef6a9960f304f74681515 Mon Sep 17 00:00:00 2001 From: marcos Date: Wed, 10 Feb 2021 16:27:29 +0100 Subject: [PATCH 023/238] add deafult header --- pandora_console/general/first_task/cluster_builder.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandora_console/general/first_task/cluster_builder.php b/pandora_console/general/first_task/cluster_builder.php index f2bee5e687..019dae1e94 100644 --- a/pandora_console/general/first_task/cluster_builder.php +++ b/pandora_console/general/first_task/cluster_builder.php @@ -24,6 +24,14 @@ if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'], return; } +\ui_print_page_header( + __('Monitoring').' » '.__('Clusters'), + 'images/chart.png', + false, + '', + false +); + ui_require_css_file('first_task'); ?> Date: Mon, 15 Feb 2021 12:55:35 +0100 Subject: [PATCH 024/238] Fixed module library download links --- .../include/javascript/module_library.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/module_library.js b/pandora_console/include/javascript/module_library.js index 4d5be47f8c..c4f2f89eea 100644 --- a/pandora_console/include/javascript/module_library.js +++ b/pandora_console/include/javascript/module_library.js @@ -409,7 +409,7 @@ function print_excerpt(id_div, response) { category_names(elem.categories) + "

" + updated + - elem.content.rendered + + format_download_link(elem.content.rendered) + '