From 90b9ace749a3f4fcaabacf15e4c69de9988c96f3 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 4 Dec 2020 13:41:06 +0100 Subject: [PATCH 01/97] added number limitation for operation of adding agents to policy in metaconsole --- pandora_console/include/constants.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 66b784d712..a186e656cf 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -476,6 +476,8 @@ define('MODULE_LINKED', 1); define('MODULE_PENDING_UNLINK', 10); define('MODULE_PENDING_LINK', 11); +define('POLICY_ADD_MAX_AGENTS', 200); + // EVENTS. define('EVENTS_GOING_UNKNOWN', 'going_unknown'); define('EVENTS_UNKNOWN', 'unknown'); From fd6aef1b37e41d2b3e7c1ce80b18b933ad1c0579 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 9 Dec 2020 18:15:01 +0100 Subject: [PATCH 02/97] Added control for id_agent_module --- pandora_console/operation/events/events.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index f24aa98699..5efe5a538d 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -140,8 +140,11 @@ $text_module = get_parameter( $filter['module_search'] ); $id_agent_module = get_parameter( - 'filter[id_agent_module]', - $filter['id_agent_module'] + 'id_agent_module', + get_parameter( + 'filter[id_agent_module]', + $filter['id_agent_module'] + ) ); $pagination = get_parameter( 'filter[pagination]', From d0b119c05f712da25d50ca9b4b0aa4ebdd1c1e22 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Thu, 10 Dec 2020 10:49:13 +0100 Subject: [PATCH 03/97] Module library user pass let empty user/pass --- pandora_console/include/functions_config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 4d3665db4d..fe148bfc1e 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1619,12 +1619,12 @@ function config_update_config() case 'module_library': $module_library_user = get_parameter('module_library_user'); - if ($module_library_user == '' || !config_update_value('module_library_user', $module_library_user)) { + if (!config_update_value('module_library_user', $module_library_user)) { $error_update[] = __('User'); } $module_library_password = get_parameter('module_library_password'); - if ($module_library_password == '' || !config_update_value('module_library_password', $module_library_password)) { + if (!config_update_value('module_library_password', $module_library_password)) { $error_update[] = __('Password'); } break; From c4eb3dd088cd1d03c6b3cc486bc6d52cdcd8ebe6 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Mon, 14 Dec 2020 10:52:12 +0100 Subject: [PATCH 04/97] Added log on deleting tgraph_source data in pandora_db --- pandora_server/util/pandora_db.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index fc72c2f4ff..07498b6e2d 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -404,8 +404,10 @@ sub pandora_purgedb ($$) { } # Delete old tgraph_source data + log_message ('PURGE', 'Deleting old tgraph_source data.'); db_do ($dbh,"DELETE FROM tgraph_source WHERE id_graph NOT IN (SELECT id_graph FROM tgraph)"); + # Delete network traffic old data. log_message ('PURGE', 'Deleting old network matrix data.'); if ($conf->{'_delete_old_network_matrix'} > 0) { From 010dc65dd4f1b89f1f982035f0c7b0bca2825ce1 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 16 Dec 2020 14:09:54 +0100 Subject: [PATCH 05/97] WIP: Backup upload --- pandora_console/godmode/menu.php | 3 + pandora_console/godmode/setup/setup.php | 15 ++ .../godmode/setup/setup_net_tools.php | 36 +++++ .../include/class/NetTools.class.php | 147 ++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 pandora_console/godmode/setup/setup_net_tools.php create mode 100644 pandora_console/include/class/NetTools.class.php diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index ddea5fcafd..b71e44ea54 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -351,6 +351,9 @@ if (check_acl($config['id_user'], 0, 'PM')) { $sub2['godmode/setup/setup&section=websocket_engine']['text'] = __('Websocket Engine'); $sub2['godmode/setup/setup&section=websocket_engine']['refr'] = 0; + $sub2['godmode/setup/setup&section=nettools']['text'] = __('Network Tools'); + $sub2['godmode/setup/setup&section=nettools']['refr'] = 0; + if ($config['activate_gis']) { $sub2['godmode/setup/setup&section=gis']['text'] = __('Map conections GIS'); } diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 9e4fb13a9c..7bfa1709f4 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -145,6 +145,11 @@ $buttons['websocket_engine'] = [ 'text' => ''.html_print_image('images/websocket_small.png', true, ['title' => __('Websocket engine')]).'', ]; +$buttons['nettools'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/nettool.png', true, ['title' => __('Websocket engine')]).'', +]; + if ($config['activate_gis']) { $buttons['gis'] = [ 'active' => false, @@ -220,6 +225,12 @@ switch ($section) { $help_header = 'quickshell_settings'; break; + case 'nettools': + $buttons['nettools']['active'] = true; + $subpage = ' » '.__('Network Tools'); + $help_header = 'Network_Tools'; + break; + case 'enterprise': $buttons['enterprise']['active'] = true; $subpage = ' » '.__('Enterprise'); @@ -292,6 +303,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_websocket_engine.php'; break; + case 'nettools': + include_once $config['homedir'].'/godmode/setup/setup_net_tools.php'; + break; + default: enterprise_hook('setup_enterprise_select_tab', [$section]); break; diff --git a/pandora_console/godmode/setup/setup_net_tools.php b/pandora_console/godmode/setup/setup_net_tools.php new file mode 100644 index 0000000000..9f5c88fb8a --- /dev/null +++ b/pandora_console/godmode/setup/setup_net_tools.php @@ -0,0 +1,36 @@ +width = '100%'; + + $table->data = []; + + $table->data[0][0] = __('Traceroute path'); + $table->data[0][1] = html_print_input_text('traceroute_path', $traceroute_path, '', 40, 255, true); + + $table->data[1][0] = __('Ping path'); + $table->data[1][1] = html_print_input_text('ping_path', $ping_path, '', 40, 255, true); + + $table->data[2][0] = __('Nmap path'); + $table->data[2][1] = html_print_input_text('nmap_path', $nmap_path, '', 40, 255, true); + + $table->data[3][0] = __('Dig path'); + $table->data[3][1] = html_print_input_text('dig_path', $dig_path, '', 40, 255, true); + + $table->data[4][0] = __('Snmpget path'); + $table->data[4][1] = html_print_input_text('snmpget_path', $snmpget_path, '', 40, 255, true); + + echo '
'; + echo '
'; + echo ''.__('Options').''; + html_print_input_hidden('update_traceroute', 1); + html_print_table($table); + echo '
'; + + echo '
'; + html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); + echo '
'; + echo '
'; + } + + +} From 6da8f33e2010a1317ab2a25d6bfab3bcf63b844f Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 16 Dec 2020 14:26:32 +0100 Subject: [PATCH 06/97] WIP --- .../godmode/setup/setup_net_tools.php | 3 +- .../include/class/NetTools.class.php | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pandora_console/godmode/setup/setup_net_tools.php b/pandora_console/godmode/setup/setup_net_tools.php index 9f5c88fb8a..0f1b246626 100644 --- a/pandora_console/godmode/setup/setup_net_tools.php +++ b/pandora_console/godmode/setup/setup_net_tools.php @@ -32,5 +32,4 @@ global $config; require_once $config['homedir'].'/include/functions.php'; // Require needed class. -// require_once $config['homedir'].'/include/class/NetTools.class.php'; -hd('MIS HUEVOS EN VINAGRETA'); +require_once $config['homedir'].'/include/class/NetTools.class.php'; diff --git a/pandora_console/include/class/NetTools.class.php b/pandora_console/include/class/NetTools.class.php index 1bed9fc0bf..aeac561c7b 100644 --- a/pandora_console/include/class/NetTools.class.php +++ b/pandora_console/include/class/NetTools.class.php @@ -44,7 +44,7 @@ class NetTools extends HTML */ public function __construct() { - + echo 'Estoy funcionando'; } @@ -130,17 +130,24 @@ class NetTools extends HTML $table->data[4][0] = __('Snmpget path'); $table->data[4][1] = html_print_input_text('snmpget_path', $snmpget_path, '', 40, 255, true); - echo '
'; - echo '
'; - echo ''.__('Options').''; - html_print_input_hidden('update_traceroute', 1); - html_print_table($table); - echo '
'; + $form = ''; + $form .= '
'; + $form .= ''.__('Options').''; + $form .= html_print_input_hidden('update_traceroute', 1, true); + $form .= html_print_table($table); + $form .= '
'; + $form .= html_print_div( + [ + 'id' => '', + 'class' => 'action-buttons', + 'style' => 'width: 100%', + 'content' => html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'), + ] + ); - echo '
'; - html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); - echo '
'; - echo '
'; + $form .= ''; + + echo $form; } From 959fbd4764fed0fabb406312d5982284056b38cb Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 17 Dec 2020 13:04:21 +0100 Subject: [PATCH 07/97] WIP: Backup upload --- .../godmode/setup/setup_net_tools.php | 13 + .../include/class/NetTools.class.php | 557 ++++++++++++++++-- .../operation/agentes/net_tools.php | 48 ++ .../operation/agentes/ver_agente.php | 17 +- 4 files changed, 585 insertions(+), 50 deletions(-) create mode 100644 pandora_console/operation/agentes/net_tools.php diff --git a/pandora_console/godmode/setup/setup_net_tools.php b/pandora_console/godmode/setup/setup_net_tools.php index 0f1b246626..4dafb6e39c 100644 --- a/pandora_console/godmode/setup/setup_net_tools.php +++ b/pandora_console/godmode/setup/setup_net_tools.php @@ -33,3 +33,16 @@ require_once $config['homedir'].'/include/functions.php'; // Require needed class. require_once $config['homedir'].'/include/class/NetTools.class.php'; + +// Control call flow for debug window. +try { + // User access and validation is being processed on class constructor. + $obj = new NetTools('setup'); +} catch (Exception $e) { + echo '[NetTools]'.$e->getMessage(); + + // Stop this execution, but continue 'globally'. + return; +} + +$obj->run(); diff --git a/pandora_console/include/class/NetTools.class.php b/pandora_console/include/class/NetTools.class.php index aeac561c7b..1e3e3343dd 100644 --- a/pandora_console/include/class/NetTools.class.php +++ b/pandora_console/include/class/NetTools.class.php @@ -40,56 +40,98 @@ class NetTools extends HTML /** - * Class constructor + * Undocumented function + * + * @param string $origin Origin of the request. */ - public function __construct() + public function __construct(string $origin) { - echo 'Estoy funcionando'; + global $config; + + // Check if the user can access here. + check_login(); + // Setting the origin. + $this->origin = $origin; + + if ($this->origin === 'agent') { + if (check_acl($config['id_user'], 0, 'AR') === false) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access Agent Management' + ); + include 'general/noaccess.php'; + return; + } + + // Capture needed parameter for agent form. + $this->operation = get_parameter('operation', 0); + $this->community = get_parameter('community', 'public'); + $this->ip = get_parameter('select_ips'); + $this->snmp_version = get_parameter('select_version'); + + // Show form. + $this->id_agente = get_parameter('id_agente', 0); + + // Capture needed parameters for agent executions. + } else if ($this->origin === 'setup') { + if (check_acl($config['id_user'], 0, 'PM') === false) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access Profile Management' + ); + include 'general/noaccess.php'; + return; + } + + // Capture needed parameters for setup form. + $this->updatePaths = (bool) get_parameter('update_paths', 0); + // Capture paths. + $this->pathTraceroute = (string) get_parameter('traceroute_path'); + $this->pathPing = (string) get_parameter('ping_path'); + $this->pathNmap = (string) get_parameter('nmap_path'); + $this->pathDig = (string) get_parameter('dig_path'); + $this->pathSnmpget = (string) get_parameter('snmpget_path'); + } + + return $this; + } /** - * Add option. + * Undocumented function * * @return void */ - function godmode_net_tools() + public function run() { - global $config; - - check_login(); - - if (! check_acl($config['id_user'], 0, 'PM')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access Profile Management' - ); - include 'general/noaccess.php'; - return; + if ($this->origin === 'agent') { + // Print tool form. + $this->agentNetToolsForm(); + } else if ($this->origin === 'setup') { + // Print setup form. + $this->setupNetToolsForm(); } - ui_print_page_header( - __('Config Network Tools'), - '', - false, - 'network_tools_tab' - ); + // Anyway, load JS. + $this->loadJS(); + } - $update_traceroute = (bool) get_parameter('update_traceroute', 0); - $traceroute_path = (string) get_parameter('traceroute_path', ''); - $ping_path = (string) get_parameter('ping_path', ''); - $nmap_path = (string) get_parameter('nmap_path', ''); - $dig_path = (string) get_parameter('dig_path', ''); - $snmpget_path = (string) get_parameter('snmpget_path', ''); - - if ($update_traceroute) { + /** + * Print the form for setup the network tools. + * + * @return void + */ + private function setupNetToolsForm() + { + if ($this->updatePaths === true) { $network_tools_config = []; - $network_tools_config['traceroute_path'] = $traceroute_path; - $network_tools_config['ping_path'] = $ping_path; - $network_tools_config['nmap_path'] = $nmap_path; - $network_tools_config['dig_path'] = $dig_path; - $network_tools_config['snmpget_path'] = $snmpget_path; + $network_tools_config['traceroute_path'] = $this->pathTraceroute; + $network_tools_config['ping_path'] = $this->pathPing; + $network_tools_config['nmap_path'] = $this->pathNmap; + $network_tools_config['dig_path'] = $this->pathDig; + $network_tools_config['snmpget_path'] = $this->pathSnmpget; $result = config_update_value('network_tools_config', json_encode($network_tools_config)); @@ -102,47 +144,50 @@ class NetTools extends HTML if (isset($config['network_tools_config'])) { $network_tools_config_output = io_safe_output($config['network_tools_config']); $network_tools_config = json_decode($network_tools_config_output, true); - $traceroute_path = $network_tools_config['traceroute_path']; - $ping_path = $network_tools_config['ping_path']; - $nmap_path = $network_tools_config['nmap_path']; - $dig_path = $network_tools_config['dig_path']; - $snmpget_path = $network_tools_config['snmpget_path']; + // Setting paths. + $this->pathTraceroute = $network_tools_config['traceroute_path']; + $this->pathPing = $network_tools_config['ping_path']; + $this->pathNmap = $network_tools_config['nmap_path']; + $this->pathDig = $network_tools_config['dig_path']; + $this->pathSnmpget = $network_tools_config['snmpget_path']; } } + // Make the table for show the form. $table = new stdClass(); $table->width = '100%'; $table->data = []; $table->data[0][0] = __('Traceroute path'); - $table->data[0][1] = html_print_input_text('traceroute_path', $traceroute_path, '', 40, 255, true); + $table->data[0][1] = html_print_input_text('traceroute_path', $this->pathTraceroute, '', 40, 255, true); $table->data[1][0] = __('Ping path'); - $table->data[1][1] = html_print_input_text('ping_path', $ping_path, '', 40, 255, true); + $table->data[1][1] = html_print_input_text('ping_path', $this->pathPing, '', 40, 255, true); $table->data[2][0] = __('Nmap path'); - $table->data[2][1] = html_print_input_text('nmap_path', $nmap_path, '', 40, 255, true); + $table->data[2][1] = html_print_input_text('nmap_path', $this->pathNmap, '', 40, 255, true); $table->data[3][0] = __('Dig path'); - $table->data[3][1] = html_print_input_text('dig_path', $dig_path, '', 40, 255, true); + $table->data[3][1] = html_print_input_text('dig_path', $this->pathDig, '', 40, 255, true); $table->data[4][0] = __('Snmpget path'); - $table->data[4][1] = html_print_input_text('snmpget_path', $snmpget_path, '', 40, 255, true); + $table->data[4][1] = html_print_input_text('snmpget_path', $this->pathSnmpget, '', 40, 255, true); $form = '
'; $form .= '
'; $form .= ''.__('Options').''; - $form .= html_print_input_hidden('update_traceroute', 1, true); - $form .= html_print_table($table); + $form .= html_print_input_hidden('update_paths', 1, true); + $form .= html_print_table($table, true); $form .= '
'; $form .= html_print_div( [ 'id' => '', 'class' => 'action-buttons', 'style' => 'width: 100%', - 'content' => html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'), - ] + 'content' => html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"', true), + ], + true ); $form .= '
'; @@ -151,4 +196,418 @@ class NetTools extends HTML } + /** + * Print the form for use the network tools. + * + * @return void + */ + private function agentNetToolsForm() + { + $principal_ip = db_get_sql( + sprintf( + 'SELECT direccion FROM tagente WHERE id_agente = %d', + $this->id_agente + ) + ); + + $list_address = db_get_all_rows_sql( + sprintf( + 'SELECT id_a FROM taddress_agent WHERE id_agent = %d', + $this->id_agente + ) + ); + foreach ($list_address as $address) { + $ids[] = join(',', $address); + } + + $ips = db_get_all_rows_sql( + sprintf( + 'SELECT ip FROM taddress WHERE id_a IN (%s)', + join(',', $ids) + ) + ); + + // Must be an a IP at least for work. + if (empty($ips) === true) { + html_print_div( + [ + 'class' => 'error', + 'style' => 'margin-top:5px', + 'content' => __('The agent hasn\'t got IP'), + ] + ); + return; + } + + // Make the data for show in table. + $ipsSelect = array_reduce( + $ips, + function ($carry, $item) { + $carry[$item['ip']] = $item['ip']; + return $carry; + } + ); + + // Form table. + $table = new StdClass(); + $table->class = 'databox filters w100p'; + $table->id = 'netToolTable'; + + $table->data = []; + + $table->data[0][0] = __('Operation'); + + $table->data[0][1] = html_print_select( + [ + 1 => __('Traceroute'), + 2 => __('Ping host & Latency'), + 3 => __('SNMP Interface status'), + 4 => __('Basic TCP Port Scan'), + 5 => __('DiG/Whois Lookup'), + ], + 'operation', + $this->operation, + 'mostrarColumns(this.value)', + __('Please select'), + 0, + true + ); + + $table->data[0][2] = __('IP Adress'); + $table->data[0][3] = html_print_select( + $ipsSelect, + 'select_ips', + $principal_ip, + '', + '', + 0, + true + ); + + $table->cellclass[0][4] = 'snmpcolumn'; + $table->data[0][4] = __('SNMP Version'); + $table->data[0][4] .= ' '; + $table->data[0][4] .= html_print_select( + [ + '1' => 'v1', + '2c' => 'v2c', + ], + 'select_version', + $this->snmp_version, + '', + '', + 0, + true + ); + + $table->cellclass[0][5] = 'snmpcolumn'; + $table->data[0][5] = __('SNMP Community'); + $table->data[0][5] .= ' '; + $table->data[0][5] .= html_print_input_text( + 'community', + $this->community, + '', + 50, + 255, + true + ); + + $table->data[0][6] = ""; + + // Output string. + $output = ''; + $output .= "
"; + $output .= html_print_table($table, true); + $output .= '
'; + + html_print_div( + [ + 'class' => '', + 'style' => 'width: 100%', + 'content' => $output, + ] + ); + + if ($this->operation === true) { + // Execute form. + $executionResult = $this->netToolsExecution($this->operation, $this->ip, $this->community, $this->snmp_version); + echo $executionResult; + } + + echo ''; + + } + + + /** + * Searchs for command. + * + * @param string $command Command. + * + * @return string Path. + */ + private function whereIsTheCommand($command) + { + global $config; + + if (isset($config['network_tools_config'])) { + $network_tools_config = json_decode($config['network_tools_config'], true); + $traceroute_path = $network_tools_config['traceroute_path']; + $ping_path = $network_tools_config['ping_path']; + $nmap_path = $network_tools_config['nmap_path']; + $dig_path = $network_tools_config['dig_path']; + $snmpget_path = $network_tools_config['snmpget_path']; + + switch ($command) { + case 'traceroute': + if (!empty($traceroute_path)) { + return $traceroute_path; + } + break; + + case 'ping': + if (!empty($ping_path)) { + return $ping_path; + } + break; + + case 'nmap': + if (!empty($nmap_path)) { + return $nmap_path; + } + break; + + case 'dig': + if (!empty($dig_path)) { + return $dig_path; + } + break; + + case 'snmpget': + if (!empty($snmpget_path)) { + return $snmpget_path; + } + break; + + default: + return null; + } + } + + ob_start(); + system('whereis '.$command); + $output = ob_get_clean(); + $result = explode(':', $output); + $result = trim($result[1]); + + if (empty($result)) { + return null; + } + + $result = explode(' ', $result); + $fullpath = trim($result[0]); + + if (! file_exists($fullpath)) { + return null; + } + + return $fullpath; + } + + + /** + * Execute net tools action. + * + * @param integer $operation Operation. + * @param string $ip Ip. + * @param string $community Community. + * @param string $snmp_version SNMP version. + * + * @return string String formed result of execution. + */ + public function netToolsExecution(int $operation, string $ip, string $community, string $snmp_version) + { + $output = ''; + + if (!validate_address($ip)) { + $output .= ui_print_error_message( + __('The ip or dns name entered cannot be resolved'), + '', + true + ); + } else { + switch ($operation) { + case 1: + $traceroute = $this->whereIsTheCommand('traceroute'); + if (empty($traceroute)) { + ui_print_error_message(__('Traceroute executable does not exist.')); + } else { + echo '

'.__('Traceroute to ').$ip.'

'; + echo '
';
+                        echo system($traceroute.' '.$ip);
+                        echo '
'; + } + break; + + case 2: + $ping = $this->whereIsTheCommand('ping'); + if (empty($ping)) { + ui_print_error_message(__('Ping executable does not exist.')); + } else { + echo '

'.__('Ping to %s', $ip).'

'; + echo '
';
+                        echo system($ping.' -c 5 '.$ip);
+                        echo '
'; + } + break; + + case 4: + $nmap = $this->whereIsTheCommand('nmap'); + if (empty($nmap)) { + ui_print_error_message(__('Nmap executable does not exist.')); + } else { + echo '

'.__('Basic TCP Scan on ').$ip.'

'; + echo '
';
+                        echo system($nmap.' -F '.$ip);
+                        echo '
'; + } + break; + + case 5: + echo '

'.__('Domain and IP information for ').$ip.'

'; + + $dig = $this->whereIsTheCommand('dig'); + if (empty($dig)) { + ui_print_error_message(__('Dig executable does not exist.')); + } else { + echo '
';
+                        echo system('dig '.$ip);
+                        echo '
'; + } + + $whois = $this->whereIsTheCommand('whois'); + if (empty($whois)) { + ui_print_error_message(__('Whois executable does not exist.')); + } else { + echo '
';
+                        echo system('whois '.$ip);
+                        echo '
'; + } + break; + + case 3: + $snmp_obj = [ + 'ip_target' => $ip, + 'snmp_version' => $snmp_version, + 'snmp_community' => $community, + 'format' => '-Oqn', + ]; + + $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.3.0'; + $result = get_h_snmpwalk($snmp_obj); + echo '

'.__('SNMP information for ').$ip.'

'; + echo '

'.__('Uptime').'

'; + echo '
';
+                    if (empty($result)) {
+                        ui_print_error_message(__('Target unreachable.'));
+                        break;
+                    } else {
+                        echo array_pop($result);
+                    }
+
+                    echo '
'; + echo '

'.__('Device info').'

'; + echo '
';
+                    $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.1.0';
+                    $result = get_h_snmpwalk($snmp_obj);
+                    if (empty($result)) {
+                        ui_print_error_message(__('Target unreachable.'));
+                        break;
+                    } else {
+                        echo array_pop($result);
+                    }
+
+                    echo '
'; + + echo '

Interface Information

'; + + $table = new StdClass(); + $table->class = 'databox'; + $table->head = []; + $table->head[] = __('Interface'); + $table->head[] = __('Status'); + + $i = 0; + + $base_oid = '.1.3.6.1.2.1.2.2.1'; + $idx_oids = '.1'; + $names_oids = '.2'; + $status_oids = '.8'; + + $snmp_obj['base_oid'] = $base_oid.$idx_oids; + $idx = get_h_snmpwalk($snmp_obj); + + $snmp_obj['base_oid'] = $base_oid.$names_oids; + $names = get_h_snmpwalk($snmp_obj); + + $snmp_obj['base_oid'] = $base_oid.$status_oids; + $statuses = get_h_snmpwalk($snmp_obj); + + foreach ($idx as $k => $v) { + $index = str_replace($base_oid.$idx_oids, '', $k); + $name = $names[$base_oid.$names_oids.$index]; + + $status = $statuses[$base_oid.$status_oids.$index]; + + $table->data[$i][0] = $name; + $table->data[$i++][1] = $status; + } + + html_print_table($table); + break; + + default: + // Ignore. + break; + } + } + + return $output; + + } + + + /** + * Load the JS and attach + * + * @return string Formed script string. + */ + private function loadJS() + { + $str = ''; + ob_start(); + ?> + + getMessage(); + + // Stop this execution, but continue 'globally'. + return; +} + +$obj->run(); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index df5146711c..72b4ee4389 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -1351,6 +1351,13 @@ if ($is_sap) { $saptab = ''; } +// Network Tools tab. +$nettools['text'] = ''.html_print_image('images/nettool.png', true, ['title' => __('Network Tools')]).''; +if ($tab == 'nettools') { + $nettools['active'] = true; +} else { + $nettools['active'] = false; +} $onheader = [ 'manage' => $managetab, @@ -1366,7 +1373,7 @@ $onheader = [ 'wux_console' => $wux_console_tab, 'url_route_analyzer' => $url_route_analyzer_tab, 'sap_view' => $saptab, - + 'nettools' => $nettools, ]; // Added after it exists @@ -1536,6 +1543,10 @@ switch ($tab) { $tab_name = 'SAP View'; break; + case 'nettools': + $tab_name = 'Net Tools'; + break; + default: $tab_name = ''; $help_header = ''; @@ -1656,6 +1667,10 @@ switch ($tab) { include 'general/sap_view.php'; break; + case 'nettools': + include 'net_tools.php'; + break; + case 'extension': $found = false; foreach ($config['extensions'] as $extension) { From 7d5f4f8f65471067158ecee39de787f4f3f14c9c Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 17 Dec 2020 16:51:05 +0100 Subject: [PATCH 08/97] WIP: Backup upload --- pandora_console/godmode/setup/setup.php | 2 +- .../include/class/NetTools.class.php | 330 ++++++++++-------- pandora_console/include/constants.php | 7 + 3 files changed, 189 insertions(+), 150 deletions(-) diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 7bfa1709f4..7fae0afa3b 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -147,7 +147,7 @@ $buttons['websocket_engine'] = [ $buttons['nettools'] = [ 'active' => false, - 'text' => ''.html_print_image('images/nettool.png', true, ['title' => __('Websocket engine')]).'', + 'text' => ''.html_print_image('images/nettool.png', true, ['title' => __('Network Tools')]).'', ]; if ($config['activate_gis']) { diff --git a/pandora_console/include/class/NetTools.class.php b/pandora_console/include/class/NetTools.class.php index 1e3e3343dd..779ddca25e 100644 --- a/pandora_console/include/class/NetTools.class.php +++ b/pandora_console/include/class/NetTools.class.php @@ -40,7 +40,7 @@ class NetTools extends HTML /** - * Undocumented function + * Constructor. * * @param string $origin Origin of the request. */ @@ -64,15 +64,11 @@ class NetTools extends HTML } // Capture needed parameter for agent form. - $this->operation = get_parameter('operation', 0); - $this->community = get_parameter('community', 'public'); - $this->ip = get_parameter('select_ips'); - $this->snmp_version = get_parameter('select_version'); - - // Show form. - $this->id_agente = get_parameter('id_agente', 0); - - // Capture needed parameters for agent executions. + $this->id_agente = (int) get_parameter('id_agente', 0); + $this->operation = (int) get_parameter('operation', 0); + $this->community = (string) get_parameter('community', 'public'); + $this->ip = (string) get_parameter('select_ips'); + $this->snmp_version = (string) get_parameter('select_version'); } else if ($this->origin === 'setup') { if (check_acl($config['id_user'], 0, 'PM') === false) { db_pandora_audit( @@ -99,7 +95,7 @@ class NetTools extends HTML /** - * Undocumented function + * Run action. * * @return void */ @@ -133,7 +129,10 @@ class NetTools extends HTML $network_tools_config['dig_path'] = $this->pathDig; $network_tools_config['snmpget_path'] = $this->pathSnmpget; - $result = config_update_value('network_tools_config', json_encode($network_tools_config)); + $result = config_update_value( + 'network_tools_config', + json_encode($network_tools_config) + ); ui_print_result_message( $result, @@ -259,11 +258,11 @@ class NetTools extends HTML $table->data[0][1] = html_print_select( [ - 1 => __('Traceroute'), - 2 => __('Ping host & Latency'), - 3 => __('SNMP Interface status'), - 4 => __('Basic TCP Port Scan'), - 5 => __('DiG/Whois Lookup'), + COMMAND_TRACEROUTE => __('Traceroute'), + COMMAND_PING => __('Ping host & Latency'), + COMMAND_SNMP => __('SNMP Interface status'), + COMMAND_NMAP => __('Basic TCP Port Scan'), + COMMAND_DIGWHOIS => __('DiG/Whois Lookup'), ], 'operation', $this->operation, @@ -316,7 +315,7 @@ class NetTools extends HTML // Output string. $output = ''; - $output .= "
"; + $output .= ''; $output .= html_print_table($table, true); $output .= '
'; @@ -328,14 +327,10 @@ class NetTools extends HTML ] ); - if ($this->operation === true) { + if ($this->operation !== 0) { // Execute form. - $executionResult = $this->netToolsExecution($this->operation, $this->ip, $this->community, $this->snmp_version); - echo $executionResult; + echo $this->netToolsExecution($this->operation, $this->ip, $this->community, $this->snmp_version); } - - echo ''; - } @@ -346,45 +341,45 @@ class NetTools extends HTML * * @return string Path. */ - private function whereIsTheCommand($command) + private function whereIsTheCommand(string $command) { global $config; if (isset($config['network_tools_config'])) { - $network_tools_config = json_decode($config['network_tools_config'], true); + $network_tools_config = json_decode(io_safe_output($config['network_tools_config']), true); $traceroute_path = $network_tools_config['traceroute_path']; - $ping_path = $network_tools_config['ping_path']; - $nmap_path = $network_tools_config['nmap_path']; - $dig_path = $network_tools_config['dig_path']; - $snmpget_path = $network_tools_config['snmpget_path']; + $ping_path = $network_tools_config['ping_path']; + $nmap_path = $network_tools_config['nmap_path']; + $dig_path = $network_tools_config['dig_path']; + $snmpget_path = $network_tools_config['snmpget_path']; switch ($command) { case 'traceroute': - if (!empty($traceroute_path)) { + if (empty($traceroute_path) === false) { return $traceroute_path; } break; case 'ping': - if (!empty($ping_path)) { + if (empty($ping_path) === false) { return $ping_path; } break; case 'nmap': - if (!empty($nmap_path)) { + if (empty($nmap_path) === false) { return $nmap_path; } break; case 'dig': - if (!empty($dig_path)) { + if (empty($dig_path) === false) { return $dig_path; } break; case 'snmpget': - if (!empty($snmpget_path)) { + if (empty($snmpget_path) === false) { return $snmpget_path; } break; @@ -415,6 +410,44 @@ class NetTools extends HTML } + /** + * Create the output for show. + * + * @param string $command Command for execute. + * @param string $caption Description of the execution. + * + * @return void + */ + private function performExecution(string $command='', string $caption='') + { + $output = ''; + + try { + // If caption is not added, don't show anything. + if (empty($caption) === false) { + $output .= sprintf('

%s

', $caption); + } + + $output .= '
';
+
+            // Only perform an execution if command is passed. Avoid errors.
+            if (empty($command) === false) {
+                ob_start();
+                system($command);
+                $output .= ob_get_clean();
+            } else {
+                $output .= __('No command for perform');
+            }
+
+            $output .= '
'; + } catch (\Throwable $th) { + $output = __('Something went wrong while perform the execution. Please check the configuration.'); + } + + echo $output; + } + + /** * Execute net tools action. * @@ -429,146 +462,145 @@ class NetTools extends HTML { $output = ''; - if (!validate_address($ip)) { + if (validate_address($ip) === false) { $output .= ui_print_error_message( __('The ip or dns name entered cannot be resolved'), '', true ); } else { - switch ($operation) { - case 1: - $traceroute = $this->whereIsTheCommand('traceroute'); - if (empty($traceroute)) { - ui_print_error_message(__('Traceroute executable does not exist.')); - } else { - echo '

'.__('Traceroute to ').$ip.'

'; - echo '
';
-                        echo system($traceroute.' '.$ip);
-                        echo '
'; - } - break; + if ($operation === COMMAND_SNMP) { + $snmp_obj = [ + 'ip_target' => $ip, + 'snmp_version' => $snmp_version, + 'snmp_community' => $community, + 'format' => '-Oqn', + ]; - case 2: - $ping = $this->whereIsTheCommand('ping'); - if (empty($ping)) { - ui_print_error_message(__('Ping executable does not exist.')); - } else { - echo '

'.__('Ping to %s', $ip).'

'; - echo '
';
-                        echo system($ping.' -c 5 '.$ip);
-                        echo '
'; - } - break; + echo '

'.__('SNMP information for ').$ip.'

'; - case 4: - $nmap = $this->whereIsTheCommand('nmap'); - if (empty($nmap)) { - ui_print_error_message(__('Nmap executable does not exist.')); - } else { - echo '

'.__('Basic TCP Scan on ').$ip.'

'; - echo '
';
-                        echo system($nmap.' -F '.$ip);
-                        echo '
'; - } - break; - - case 5: - echo '

'.__('Domain and IP information for ').$ip.'

'; - - $dig = $this->whereIsTheCommand('dig'); - if (empty($dig)) { - ui_print_error_message(__('Dig executable does not exist.')); - } else { - echo '
';
-                        echo system('dig '.$ip);
-                        echo '
'; - } - - $whois = $this->whereIsTheCommand('whois'); - if (empty($whois)) { - ui_print_error_message(__('Whois executable does not exist.')); - } else { - echo '
';
-                        echo system('whois '.$ip);
-                        echo '
'; - } - break; - - case 3: - $snmp_obj = [ - 'ip_target' => $ip, - 'snmp_version' => $snmp_version, - 'snmp_community' => $community, - 'format' => '-Oqn', - ]; - - $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.3.0'; - $result = get_h_snmpwalk($snmp_obj); - echo '

'.__('SNMP information for ').$ip.'

'; + $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.3.0'; + $result = get_h_snmpwalk($snmp_obj); + if (empty($result) === true) { + ui_print_error_message(__('Target unreachable.')); + return null; + } else { echo '

'.__('Uptime').'

'; echo '
';
-                    if (empty($result)) {
-                        ui_print_error_message(__('Target unreachable.'));
-                        break;
-                    } else {
-                        echo array_pop($result);
-                    }
-
+                    echo array_pop($result);
                     echo '
'; + } + + $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.1.0'; + $result = get_h_snmpwalk($snmp_obj); + if (empty($result) === true) { + ui_print_error_message(__('Target unreachable.')); + return null; + } else { echo '

'.__('Device info').'

'; echo '
';
-                    $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.1.0';
-                    $result = get_h_snmpwalk($snmp_obj);
-                    if (empty($result)) {
-                        ui_print_error_message(__('Target unreachable.'));
-                        break;
-                    } else {
-                        echo array_pop($result);
-                    }
-
+                    echo array_pop($result);
                     echo '
'; + } - echo '

Interface Information

'; + echo '

Interface Information

'; - $table = new StdClass(); - $table->class = 'databox'; - $table->head = []; - $table->head[] = __('Interface'); - $table->head[] = __('Status'); + $table = new StdClass(); + $table->class = 'databox'; + $table->head = []; + $table->head[] = __('Interface'); + $table->head[] = __('Status'); - $i = 0; + $i = 0; - $base_oid = '.1.3.6.1.2.1.2.2.1'; - $idx_oids = '.1'; - $names_oids = '.2'; - $status_oids = '.8'; + $base_oid = '.1.3.6.1.2.1.2.2.1'; + $idx_oids = '.1'; + $names_oids = '.2'; + $status_oids = '.8'; - $snmp_obj['base_oid'] = $base_oid.$idx_oids; - $idx = get_h_snmpwalk($snmp_obj); + $snmp_obj['base_oid'] = $base_oid.$idx_oids; + $idx = get_h_snmpwalk($snmp_obj); - $snmp_obj['base_oid'] = $base_oid.$names_oids; - $names = get_h_snmpwalk($snmp_obj); + $snmp_obj['base_oid'] = $base_oid.$names_oids; + $names = get_h_snmpwalk($snmp_obj); - $snmp_obj['base_oid'] = $base_oid.$status_oids; - $statuses = get_h_snmpwalk($snmp_obj); + $snmp_obj['base_oid'] = $base_oid.$status_oids; + $statuses = get_h_snmpwalk($snmp_obj); - foreach ($idx as $k => $v) { - $index = str_replace($base_oid.$idx_oids, '', $k); - $name = $names[$base_oid.$names_oids.$index]; + foreach ($idx as $k => $v) { + $index = str_replace($base_oid.$idx_oids, '', $k); + $name = $names[$base_oid.$names_oids.$index]; - $status = $statuses[$base_oid.$status_oids.$index]; + $status = $statuses[$base_oid.$status_oids.$index]; - $table->data[$i][0] = $name; - $table->data[$i++][1] = $status; - } + $table->data[$i][0] = $name; + $table->data[$i++][1] = $status; + } - html_print_table($table); - break; + html_print_table($table); + } else if ($operation === COMMAND_DIGWHOIS) { + echo '

'.__('Domain and IP information for ').$ip.'

'; - default: - // Ignore. - break; + // Dig execution. + $dig = $this->whereIsTheCommand('dig'); + if (empty($dig) === true) { + ui_print_error_message(__('Dig executable does not exist.')); + } else { + $this->performExecution($dig); + } + + // Whois execution. + $whois = $this->whereIsTheCommand('whois'); + if (empty($whois) === true) { + ui_print_error_message(__('Whois executable does not exist.')); + } else { + $this->performExecution($whois); + } + + return; + } else { + switch ($operation) { + case COMMAND_TRACEROUTE: + $command = $this->whereIsTheCommand('traceroute'); + if (empty($command) === true) { + ui_print_error_message(__('Traceroute executable does not exist.')); + return; + } else { + $stringCommand = __('Traceroute to %s', $ip); + $executeCommand = sprintf('%s %s', $command, $ip); + } + break; + + case COMMAND_PING: + $command = $this->whereIsTheCommand('ping'); + if (empty($command) === true) { + ui_print_error_message(__('Ping executable does not exist.')); + return; + } else { + $stringCommand = __('Ping to %s', $ip); + $executeCommand = sprintf('%s -c 5 %s', $command, $ip); + } + break; + + case COMMAND_NMAP: + $command = $this->whereIsTheCommand('nmap'); + if (empty($command) === true) { + ui_print_error_message(__('Nmap executable does not exist.')); + return; + } else { + $stringCommand = __('Basic TCP Scan on %s', $ip); + $executeCommand = sprintf('%s -F %s', $command, $ip); + } + break; + + default: + // Nothing to do. + $stringCommand = ''; + $executeCommand = ''; + break; + } + + $this->performExecution($executeCommand, $stringCommand); } } diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 54f4c286f2..d8dfa770f2 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -747,3 +747,10 @@ define('MODULE_TYPE_REMOTE_CMD_PROC', 35); define('MODULE_TYPE_REMOTE_CMD_STRING', 36); define('MODULE_TYPE_REMOTE_CMD_INC', 37); define('MODULE_TYPE_KEEP_ALIVE', 100); + +// Commands for network tools. +define('COMMAND_TRACEROUTE', 1); +define('COMMAND_PING', 2); +define('COMMAND_SNMP', 3); +define('COMMAND_NMAP', 4); +define('COMMAND_DIGWHOIS', 5); From daa6e47768da779b257246719c0fe6183b631cc0 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 17 Dec 2020 19:33:10 +0100 Subject: [PATCH 09/97] Changes ended --- pandora_console/include/class/NetTools.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/class/NetTools.class.php b/pandora_console/include/class/NetTools.class.php index 779ddca25e..e519019158 100644 --- a/pandora_console/include/class/NetTools.class.php +++ b/pandora_console/include/class/NetTools.class.php @@ -121,6 +121,8 @@ class NetTools extends HTML */ private function setupNetToolsForm() { + global $config; + if ($this->updatePaths === true) { $network_tools_config = []; $network_tools_config['traceroute_path'] = $this->pathTraceroute; @@ -140,7 +142,7 @@ class NetTools extends HTML __('Set the paths.') ); } else { - if (isset($config['network_tools_config'])) { + if (isset($config['network_tools_config']) === true) { $network_tools_config_output = io_safe_output($config['network_tools_config']); $network_tools_config = json_decode($network_tools_config_output, true); // Setting paths. @@ -345,7 +347,7 @@ class NetTools extends HTML { global $config; - if (isset($config['network_tools_config'])) { + if (isset($config['network_tools_config']) === true) { $network_tools_config = json_decode(io_safe_output($config['network_tools_config']), true); $traceroute_path = $network_tools_config['traceroute_path']; $ping_path = $network_tools_config['ping_path']; @@ -395,14 +397,14 @@ class NetTools extends HTML $result = explode(':', $output); $result = trim($result[1]); - if (empty($result)) { + if (empty($result) === true) { return null; } $result = explode(' ', $result); $fullpath = trim($result[0]); - if (! file_exists($fullpath)) { + if (file_exists($fullpath) === false) { return null; } From 5f0d686034a7be45d5250910bbce7e8c243cfded Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 18 Dec 2020 12:31:44 +0100 Subject: [PATCH 10/97] Changed Network Tools for External Tools --- pandora_console/extensions/net_tools.php | 506 ------------------ ...net_tools.php => setup_external_tools.php} | 8 +- ...ools.class.php => ExternalTools.class.php} | 99 +++- pandora_console/include/constants.php | 2 +- pandora_console/include/styles/pandora.css | 7 + .../{net_tools.php => external_tools.php} | 10 +- .../operation/agentes/ver_agente.php | 20 +- 7 files changed, 113 insertions(+), 539 deletions(-) delete mode 100644 pandora_console/extensions/net_tools.php rename pandora_console/godmode/setup/{setup_net_tools.php => setup_external_tools.php} (89%) rename pandora_console/include/class/{NetTools.class.php => ExternalTools.class.php} (87%) rename pandora_console/operation/agentes/{net_tools.php => external_tools.php} (86%) diff --git a/pandora_console/extensions/net_tools.php b/pandora_console/extensions/net_tools.php deleted file mode 100644 index b23c5b1fe0..0000000000 --- a/pandora_console/extensions/net_tools.php +++ /dev/null @@ -1,506 +0,0 @@ -'.__('Traceroute to ').$ip.''; - echo '
';
-                    echo system($traceroute.' '.$ip);
-                    echo '
'; - } - break; - - case 2: - $ping = whereis_the_command('ping'); - if (empty($ping)) { - ui_print_error_message(__('Ping executable does not exist.')); - } else { - echo '

'.__('Ping to %s', $ip).'

'; - echo '
';
-                    echo system($ping.' -c 5 '.$ip);
-                    echo '
'; - } - break; - - case 4: - $nmap = whereis_the_command('nmap'); - if (empty($nmap)) { - ui_print_error_message(__('Nmap executable does not exist.')); - } else { - echo '

'.__('Basic TCP Scan on ').$ip.'

'; - echo '
';
-                    echo system($nmap.' -F '.$ip);
-                    echo '
'; - } - break; - - case 5: - echo '

'.__('Domain and IP information for ').$ip.'

'; - - $dig = whereis_the_command('dig'); - if (empty($dig)) { - ui_print_error_message(__('Dig executable does not exist.')); - } else { - echo '
';
-                    echo system('dig '.$ip);
-                    echo '
'; - } - - $whois = whereis_the_command('whois'); - if (empty($whois)) { - ui_print_error_message(__('Whois executable does not exist.')); - } else { - echo '
';
-                    echo system('whois '.$ip);
-                    echo '
'; - } - break; - - case 3: - $snmp_obj = [ - 'ip_target' => $ip, - 'snmp_version' => $snmp_version, - 'snmp_community' => $community, - 'format' => '-Oqn', - ]; - - $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.3.0'; - $result = get_h_snmpwalk($snmp_obj); - echo '

'.__('SNMP information for ').$ip.'

'; - echo '

'.__('Uptime').'

'; - echo '
';
-                if (empty($result)) {
-                    ui_print_error_message(__('Target unreachable.'));
-                    break;
-                } else {
-                    echo array_pop($result);
-                }
-
-                echo '
'; - echo '

'.__('Device info').'

'; - echo '
';
-                $snmp_obj['base_oid'] = '.1.3.6.1.2.1.1.1.0';
-                $result = get_h_snmpwalk($snmp_obj);
-                if (empty($result)) {
-                    ui_print_error_message(__('Target unreachable.'));
-                    break;
-                } else {
-                    echo array_pop($result);
-                }
-
-                echo '
'; - - echo '

Interface Information

'; - - $table = new StdClass(); - $table->class = 'databox'; - $table->head = []; - $table->head[] = __('Interface'); - $table->head[] = __('Status'); - - $i = 0; - - $base_oid = '.1.3.6.1.2.1.2.2.1'; - $idx_oids = '.1'; - $names_oids = '.2'; - $status_oids = '.8'; - - $snmp_obj['base_oid'] = $base_oid.$idx_oids; - $idx = get_h_snmpwalk($snmp_obj); - - $snmp_obj['base_oid'] = $base_oid.$names_oids; - $names = get_h_snmpwalk($snmp_obj); - - $snmp_obj['base_oid'] = $base_oid.$status_oids; - $statuses = get_h_snmpwalk($snmp_obj); - - foreach ($idx as $k => $v) { - $index = str_replace($base_oid.$idx_oids, '', $k); - $name = $names[$base_oid.$names_oids.$index]; - - $status = $statuses[$base_oid.$status_oids.$index]; - - $table->data[$i][0] = $name; - $table->data[$i++][1] = $status; - } - - html_print_table($table); - break; - - default: - // Ignore. - break; - } - } - -} - - -/** - * Main function. - * - * @return void - */ -function main_net_tools() -{ - $operation = get_parameter('operation', 0); - $community = get_parameter('community', 'public'); - $ip = get_parameter('select_ips'); - $snmp_version = get_parameter('select_version'); - - // Show form. - $id_agente = get_parameter('id_agente', 0); - $principal_ip = db_get_sql( - sprintf( - 'SELECT direccion FROM tagente WHERE id_agente = %d', - $id_agente - ) - ); - - $list_address = db_get_all_rows_sql( - sprintf( - 'SELECT id_a FROM taddress_agent WHERE id_agent = %d', - $id_agente - ) - ); - foreach ($list_address as $address) { - $ids[] = join(',', $address); - } - - $ips = db_get_all_rows_sql( - sprintf( - 'SELECT ip FROM taddress WHERE id_a IN (%s)', - join(',', $ids) - ) - ); - - if ($ips == '') { - echo "
".__('The agent hasn\'t got IP').'
'; - return; - } - - // Javascript. - ?> - - '; - echo "
"; - echo ""; - echo ''; - echo ''; - echo "'; - echo '
'; - echo __('Operation'); - echo ''; - - html_print_select( - [ - 1 => __('Traceroute'), - 2 => __('Ping host & Latency'), - 3 => __('SNMP Interface status'), - 4 => __('Basic TCP Port Scan'), - 5 => __('DiG/Whois Lookup'), - ], - 'operation', - $operation, - 'mostrarColumns(this.value)', - __('Please select') - ); - - echo ''; - echo __('IP address'); - echo ''; - - $ips_for_select = array_reduce( - $ips, - function ($carry, $item) { - $carry[$item['ip']] = $item['ip']; - return $carry; - } - ); - - html_print_select( - $ips_for_select, - 'select_ips', - $principal_ip - ); - echo '"; - echo __('SNMP Version'); - html_print_select( - [ - '1' => 'v1', - '2c' => 'v2c', - ], - 'select_version', - $snmp_version - ); - echo ''; - echo __('SNMP Community').' '; - html_print_input_text('community', $community); - echo ''; - echo ""; - echo '
'; - echo '
'; - - if ($operation) { - // Execute form. - net_tools_execute($operation, $ip, $community, $snmp_version); - } - - echo ''; -} - - -/** - * Add option. - * - * @return void - */ -function godmode_net_tools() -{ - global $config; - - check_login(); - - if (! check_acl($config['id_user'], 0, 'PM')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access Profile Management' - ); - include 'general/noaccess.php'; - return; - } - - ui_print_page_header( - __('Config Network Tools'), - '', - false, - 'network_tools_tab' - ); - - $update_traceroute = (bool) get_parameter('update_traceroute', 0); - - $traceroute_path = (string) get_parameter('traceroute_path', ''); - $ping_path = (string) get_parameter('ping_path', ''); - $nmap_path = (string) get_parameter('nmap_path', ''); - $dig_path = (string) get_parameter('dig_path', ''); - $snmpget_path = (string) get_parameter('snmpget_path', ''); - - if ($update_traceroute) { - $network_tools_config = []; - $network_tools_config['traceroute_path'] = $traceroute_path; - $network_tools_config['ping_path'] = $ping_path; - $network_tools_config['nmap_path'] = $nmap_path; - $network_tools_config['dig_path'] = $dig_path; - $network_tools_config['snmpget_path'] = $snmpget_path; - - $result = config_update_value('network_tools_config', json_encode($network_tools_config)); - - ui_print_result_message( - $result, - __('Set the paths.'), - __('Set the paths.') - ); - } else { - if (isset($config['network_tools_config'])) { - $network_tools_config_output = io_safe_output($config['network_tools_config']); - $network_tools_config = json_decode($network_tools_config_output, true); - $traceroute_path = $network_tools_config['traceroute_path']; - $ping_path = $network_tools_config['ping_path']; - $nmap_path = $network_tools_config['nmap_path']; - $dig_path = $network_tools_config['dig_path']; - $snmpget_path = $network_tools_config['snmpget_path']; - } - } - - $table = null; - $table->width = '100%'; - - $table->data = []; - - $table->data[0][0] = __('Traceroute path'); - $table->data[0][1] = html_print_input_text('traceroute_path', $traceroute_path, '', 40, 255, true); - - $table->data[1][0] = __('Ping path'); - $table->data[1][1] = html_print_input_text('ping_path', $ping_path, '', 40, 255, true); - - $table->data[2][0] = __('Nmap path'); - $table->data[2][1] = html_print_input_text('nmap_path', $nmap_path, '', 40, 255, true); - - $table->data[3][0] = __('Dig path'); - $table->data[3][1] = html_print_input_text('dig_path', $dig_path, '', 40, 255, true); - - $table->data[4][0] = __('Snmpget path'); - $table->data[4][1] = html_print_input_text('snmpget_path', $snmpget_path, '', 40, 255, true); - - echo '
'; - echo '
'; - echo ''.__('Options').''; - html_print_input_hidden('update_traceroute', 1); - html_print_table($table); - echo '
'; - - echo '
'; - html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); - echo '
'; - echo '
'; -} - - -extensions_add_godmode_menu_option(__('Config Network Tools'), 'PM'); -extensions_add_godmode_function('godmode_net_tools'); diff --git a/pandora_console/godmode/setup/setup_net_tools.php b/pandora_console/godmode/setup/setup_external_tools.php similarity index 89% rename from pandora_console/godmode/setup/setup_net_tools.php rename to pandora_console/godmode/setup/setup_external_tools.php index 4dafb6e39c..30bdd6b188 100644 --- a/pandora_console/godmode/setup/setup_net_tools.php +++ b/pandora_console/godmode/setup/setup_external_tools.php @@ -1,6 +1,6 @@ getMessage(); + echo '[ExternalTools]'.$e->getMessage(); // Stop this execution, but continue 'globally'. return; diff --git a/pandora_console/include/class/NetTools.class.php b/pandora_console/include/class/ExternalTools.class.php similarity index 87% rename from pandora_console/include/class/NetTools.class.php rename to pandora_console/include/class/ExternalTools.class.php index e519019158..97b644a11f 100644 --- a/pandora_console/include/class/NetTools.class.php +++ b/pandora_console/include/class/ExternalTools.class.php @@ -1,6 +1,6 @@ updatePaths = (bool) get_parameter('update_paths', 0); + // Capture paths. $this->pathTraceroute = (string) get_parameter('traceroute_path'); $this->pathPing = (string) get_parameter('ping_path'); @@ -103,10 +104,10 @@ class NetTools extends HTML { if ($this->origin === 'agent') { // Print tool form. - $this->agentNetToolsForm(); + $this->agentExternalToolsForm(); } else if ($this->origin === 'setup') { // Print setup form. - $this->setupNetToolsForm(); + $this->setupExternalToolsForm(); } // Anyway, load JS. @@ -115,11 +116,11 @@ class NetTools extends HTML /** - * Print the form for setup the network tools. + * Print the form for setup the external tools. * * @return void */ - private function setupNetToolsForm() + private function setupExternalToolsForm() { global $config; @@ -151,6 +152,7 @@ class NetTools extends HTML $this->pathNmap = $network_tools_config['nmap_path']; $this->pathDig = $network_tools_config['dig_path']; $this->pathSnmpget = $network_tools_config['snmpget_path']; + $this->pathCustomComm = ($network_tools_config['custom_command'] ?? ['a' => 'a']); } } @@ -175,6 +177,70 @@ class NetTools extends HTML $table->data[4][0] = __('Snmpget path'); $table->data[4][1] = html_print_input_text('snmpget_path', $this->pathSnmpget, '', 40, 255, true); + $table->data[5][0] = html_print_div( + [ + 'class' => 'title_custom_commands bolder float-left', + 'content' => __('Custom commands') + ], + true + ); + + $table->data[5][0] .= html_print_div( + [ + 'id' => 'add_button_custom_command', + 'content' => html_print_image( + 'images/add.png', + true, + ['title' => __('Add new custom command') ] + ) + ], + true + ); + + $table->data[6][0] = __('Command'); + $table->data[6][1] = __('Parameters'); + + $i = 0; + $iRow = 6; + foreach ($this->pathCustomComm as $command) { + $i++; + $iRow++; + + // Fill the fields. + $customCommand = ($command['custom_command'] ?? ''); + $customParams = ($command['custom_params'] ?? ''); + // Attach the fields. + $table->rowid[$iRow] = 'custom_row_'.$i; + $table->data[$iRow][0] = html_print_input_text( + 'command_custom_'.$i, + $customCommand, + '', + 40, + 255, + true + ); + $table->data[$iRow][1] = html_print_input_text( + 'params_custom_'.$i, + $customParams, + '', + 40, + 255, + true + ); + $table->data[$iRow][2] = html_print_div( + [ + 'id' => 'delete_custom_'.$i, + 'class' => '', + 'content' => html_print_image( + 'images/delete.png', + true, + ['title' => __('Delete this custom command') ] + ) + ], + true + ); + } + $form = '
'; $form .= '
'; $form .= ''.__('Options').''; @@ -198,11 +264,11 @@ class NetTools extends HTML /** - * Print the form for use the network tools. + * Print the form for use the external tools. * * @return void */ - private function agentNetToolsForm() + private function agentExternalToolsForm() { $principal_ip = db_get_sql( sprintf( @@ -252,7 +318,7 @@ class NetTools extends HTML // Form table. $table = new StdClass(); $table->class = 'databox filters w100p'; - $table->id = 'netToolTable'; + $table->id = 'externalToolTable'; $table->data = []; @@ -331,7 +397,7 @@ class NetTools extends HTML if ($this->operation !== 0) { // Execute form. - echo $this->netToolsExecution($this->operation, $this->ip, $this->community, $this->snmp_version); + echo $this->externalToolsExecution($this->operation, $this->ip, $this->community, $this->snmp_version); } } @@ -451,7 +517,7 @@ class NetTools extends HTML /** - * Execute net tools action. + * Execute external tools action. * * @param integer $operation Operation. * @param string $ip Ip. @@ -460,7 +526,7 @@ class NetTools extends HTML * * @return string String formed result of execution. */ - public function netToolsExecution(int $operation, string $ip, string $community, string $snmp_version) + public function externalToolsExecution(int $operation, string $ip, string $community, string $snmp_version) { $output = ''; @@ -623,6 +689,13 @@ class NetTools extends HTML ?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d3005d5639..fcf9adce0d 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -6273,3 +6273,55 @@ function ui_print_reveal_password(string $name, bool $return=false) echo $output; } + + +/** + * Generate a spinner box for waiting times + * + * @param string $text Text for show in spinner. English Loading for default. + * @param boolean $return If true, return the string with the formed element. + * + * @return string + */ +function ui_print_spinner(string $text='Loading', bool $return=false) +{ + $output = ''; + + $output .= '
'; + + $output .= html_print_div( + [ + 'id' => 'loading_spinner', + 'class' => 'white_box invisible', + 'content' => ''.$text.'...'.html_print_image( + 'images/spinner.gif', + true, + [ + 'border' => '0', + 'width' => '25px', + 'heigth' => '25px', + ] + ), + ], + true + ); + + $output .= '
'; + + $output .= ' + + '; + + if ($return === true) { + return $output; + } else { + echo $output; + } +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 9a1ce23dca..c2cb379ea4 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -792,6 +792,7 @@ p.center { cursor: help; } +/* Legacy spinner */ #loading { position: fixed; width: 200px; @@ -802,6 +803,18 @@ p.center { padding: 20px; } +/* New standard spinner */ +#loading_spinner { + position: fixed; + margin-left: 30%; + text-align: center; + top: 50%; + background-color: #fff; + border: 2px solid #82b92e; + box-shadow: 2px 2px 2px #9dbba1; + padding: 20px; +} + .tactical_set legend { text-align: left; color: #3f3f3f; From e727f7c276a63d515f1fc89c040b4e732056d17b Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 12 Feb 2021 11:28:13 +0100 Subject: [PATCH 31/97] Added modals and fixed some bugs --- .../massive/massive_add_action_alerts.php | 67 ++++++------- .../godmode/massive/massive_add_alerts.php | 14 ++- .../godmode/massive/massive_add_profiles.php | 48 +++++---- .../godmode/massive/massive_copy_modules.php | 60 +++++++----- .../massive/massive_delete_action_alerts.php | 45 ++++++--- .../godmode/massive/massive_delete_agents.php | 64 ++++++------ .../godmode/massive/massive_delete_alerts.php | 49 ++++++---- .../massive/massive_delete_modules.php | 71 +++++++------- .../massive/massive_delete_profiles.php | 48 +++++---- .../godmode/massive/massive_edit_agents.php | 85 +++++++++------- .../godmode/massive/massive_edit_modules.php | 93 +++++++++--------- .../godmode/massive/massive_edit_plugins.php | 44 ++++++--- .../massive/massive_enable_disable_alerts.php | 39 +++++--- .../godmode/massive/massive_operations.php | 84 ++++++++++------ .../massive/massive_standby_alerts.php | 43 +++++--- .../include/functions_massive_operations.php | 97 +++++++++++++++++++ pandora_console/include/functions_ui.php | 3 +- .../include/javascript/massive_operations.js | 93 ++++++++++++++++++ pandora_console/include/styles/pandora.css | 1 + 19 files changed, 690 insertions(+), 358 deletions(-) create mode 100644 pandora_console/include/functions_massive_operations.php create mode 100644 pandora_console/include/javascript/massive_operations.js diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 7bfbbee09f..f9a02c8545 100755 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -1,17 +1,32 @@ data[1][0] .= ''; $table->data[1][1] = html_print_select([], 'id_agents[]', 0, false, __('Any'), '', true, true); $table->data[2][0] = __('Alert templates'); -$table->data[2][0] .= ''; $table->data[2][1] = html_print_select([], 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0); $table->data[2][2] = __('When select agents'); $table->data[2][2] .= '
'; @@ -251,10 +263,8 @@ $agents_with_templates_json = json_encode($agents_with_templates_json); echo ""; -echo '
'; -html_print_input_hidden('add', 1); -html_print_submit_button(__('Add'), 'go', false, 'class="sub add"'); -echo '
'; +attachActionButton('add', 'create', $table->width); + echo ''; echo ''; @@ -265,23 +275,8 @@ ui_require_jquery_file('pandora.controls'); ?> - - "+value+""; }); $("#id_alert_templates").append (options); - $("#template_loading").hide (); + hideSpinner(); $select_template.enable (); }, "json" diff --git a/pandora_console/include/functions_massive_operations.php b/pandora_console/include/functions_massive_operations.php new file mode 100644 index 0000000000..389d87ddcc --- /dev/null +++ b/pandora_console/include/functions_massive_operations.php @@ -0,0 +1,97 @@ + 'action-buttons', + 'style' => sprintf('width: %s', $tableWidth), + 'content' => html_print_input_hidden( + $action, + 1 + ).html_print_button( + __($caption), + 'go', + false, + '', + sprintf('class="sub %s"', $class), + true + ), + ], + $return + ); +} diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index fcf9adce0d..8cb234db8e 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -6277,8 +6277,9 @@ function ui_print_reveal_password(string $name, bool $return=false) /** * Generate a spinner box for waiting times + * TIP: It's made for Massive Operations, but it migth used in entire project. * - * @param string $text Text for show in spinner. English Loading for default. + * @param string $text Text for show in spinner. English term Loading for default. * @param boolean $return If true, return the string with the formed element. * * @return string diff --git a/pandora_console/include/javascript/massive_operations.js b/pandora_console/include/javascript/massive_operations.js new file mode 100644 index 0000000000..dd1c8acd13 --- /dev/null +++ b/pandora_console/include/javascript/massive_operations.js @@ -0,0 +1,93 @@ +/** global $ */ +function massiveOperationValidation(contents, totalCount, limit, thisForm) { + var output = false; + + // If the amount of changes exceed the limit, the operation stops. + if (totalCount > limit) { + // Set the content. + $("#massive_modal") + .empty() + .html(contents.html); + // Set the title. + $("#massive_modal").prop("title", contents.title); + // Build the dialog for show the mesage. + $("#massive_modal").dialog({ + resizable: true, + draggable: true, + modal: true, + width: 800, + buttons: [ + { + text: "OK", + click: function() { + hideSpinner(); + $(this).dialog("close"); + return false; + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + } + }); + + return false; + } else { + confirmDialog({ + title: contents.title, + message: contents.question, + ok: contents.ok, + cancel: contents.cancel, + onAccept: function() { + showSpinner(); + output = true; + $("#" + thisForm).submit(); + }, + onDeny: function() { + hideSpinner(); + return false; + } + }); + } + + return output; +} + +/* +function showMassiveOperationMessage(message) { + $("#massive_modal") + .empty() + .html(message); + + $("#massive_modal").prop("title", "Massive operations"); + + $("#massive_modal").dialog({ + resizable: true, + draggable: true, + modal: true, + width: 800, + buttons: [ + { + text: "OK", + click: function() { + $(this).dialog("close"); + hideSpinner(); + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + } + }); +} +*/ diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index c2cb379ea4..79e5572823 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -813,6 +813,7 @@ p.center { border: 2px solid #82b92e; box-shadow: 2px 2px 2px #9dbba1; padding: 20px; + z-index: 100; } .tactical_set legend { From 64ae9641911ce55923b36ada623f1242c069440a Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 19 Feb 2021 14:30:09 +0100 Subject: [PATCH 32/97] Fixed forced 2FA --- pandora_console/general/register.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 9f90e7ad39..9147a0e016 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -234,8 +234,8 @@ if (!$double_auth_enabled && $config['2FA_all_users'] != '' } }); - $("div#doble_auth_window").dialog({ + $("div#doble_auth_window").dialog({ resizable: true, draggable: true, modal: true, @@ -247,12 +247,6 @@ if (!$double_auth_enabled && $config['2FA_all_users'] != '' width: 500, height: 400, close: function (event, ui) { - - // Abort the ajax request if (typeof request != 'undefined'){ request.abort(); From 793ca4ace7f762958be7637af8fc8542bcbc85e1 Mon Sep 17 00:00:00 2001 From: "rafael.ameijeiras" Date: Tue, 23 Feb 2021 15:05:08 +0100 Subject: [PATCH 33/97] change agent docker image to centos7 --- pandora_agents/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_agents/Dockerfile b/pandora_agents/Dockerfile index 0ee2515a75..79257b955c 100644 --- a/pandora_agents/Dockerfile +++ b/pandora_agents/Dockerfile @@ -1,15 +1,15 @@ -FROM centos:centos8 -MAINTAINER Pandora FMS Team +FROM centos:7 +LABEL maintainer="Pandora FMS Team " # Add Pandora FMS agent installer ADD unix /opt/pandora/pandora_agent/unix RUN export LC_ALL=C -RUN dnf install -y dnf-plugins-core; dnf config-manager --set-enabled PowerTools +RUN yum -y update # Install dependencies -RUN dnf -y install \ +RUN yum -y install \ epel-release \ unzip \ perl \ @@ -17,7 +17,7 @@ RUN dnf -y install \ sed \ perl-YAML-Tiny \ "perl(Sys::Syslog)" \ - && dnf clean all + && yum clean all # Install Pandora FMS agent From 901d12fec02b31f6c5f28e825daa28aadf409f48 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 25 Feb 2021 13:18:04 +0100 Subject: [PATCH 34/97] Integration with Integria --- pandora_console/extras/mr/45.sql | 5 + .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 + .../godmode/agentes/agent_incidents.php | 44 +- .../godmode/agentes/configurar_agente.php | 19 - .../godmode/alerts/alert_commands.php | 72 ++- .../godmode/alerts/alert_list.builder.php | 9 +- .../godmode/alerts/configure_alert_action.php | 248 +++++++- .../godmode/setup/setup_integria.php | 227 ++++++-- pandora_console/include/functions_alerts.php | 27 +- pandora_console/include/functions_config.php | 8 +- pandora_console/include/functions_graph.php | 204 ++----- .../include/functions_integriaims.php | 23 +- .../operation/agentes/ver_agente.php | 11 +- .../configure_integriaims_incident.php | 20 +- .../dashboard_detail_integriaims_incident.php | 2 +- .../operation/incidents/incident.php | 503 ----------------- .../operation/incidents/incident_detail.php | 532 ------------------ .../incidents/incident_statistics.php | 8 +- .../incidents/list_integriaims_incidents.php | 2 +- pandora_console/operation/menu.php | 5 +- pandora_server/lib/PandoraFMS/Core.pm | 172 ++++-- pandora_server/util/pandora_db.pl | 33 ++ pandora_server/util/pandora_manage.pl | 21 - .../util/recon_scripts/wmi-recon.pl | 8 - 24 files changed, 837 insertions(+), 1368 deletions(-) create mode 100644 pandora_console/extras/mr/45.sql delete mode 100755 pandora_console/operation/incidents/incident.php delete mode 100755 pandora_console/operation/incidents/incident_detail.php diff --git a/pandora_console/extras/mr/45.sql b/pandora_console/extras/mr/45.sql new file mode 100644 index 0000000000..c02109bd16 --- /dev/null +++ b/pandora_console/extras/mr/45.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `talert_actions` ADD COLUMN `create_wu_integria` TINYINT(1) default NULL; + +COMMIT; 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..4a279450f3 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 @@ -1378,6 +1378,8 @@ ALTER TABLE `talert_actions` MODIFY COLUMN `field11` text NOT NULL, MODIFY COLUMN `field14` text NOT NULL, MODIFY COLUMN `field15` text NOT NULL; +ALTER TABLE `talert_actions` ADD COLUMN `create_wu_integria` TINYINT(1) default NULL; + -- --------------------------------------------------------------------- -- Table `talert_commands` -- --------------------------------------------------------------------- diff --git a/pandora_console/godmode/agentes/agent_incidents.php b/pandora_console/godmode/agentes/agent_incidents.php index c144cdfdcd..c669af992e 100644 --- a/pandora_console/godmode/agentes/agent_incidents.php +++ b/pandora_console/godmode/agentes/agent_incidents.php @@ -18,6 +18,11 @@ require_once 'include/functions_incidents.php'; check_login(); +if (!$config['integria_enabled']) { + ui_print_error_message(__('In order to access ticket management system, integration with Integria IMS must be enabled and properly configured')); + return; +} + $group = $id_grupo; if (! check_acl($config['id_user'], $group, 'AW', $id_agente)) { @@ -38,24 +43,21 @@ $groups = users_get_groups($config['id_user'], 'IR'); $filter = ' AND id_agent = '.$id_agent; $url = 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agent; -// Select incidencts where the user has access to ($groups from -// get_user_groups), array_keys for the id, implode to pass to SQL -switch ($config['dbtype']) { - case 'mysql': - $sql = 'SELECT * FROM tincidencia WHERE - id_grupo IN ('.implode(',', array_keys($groups)).')'.$filter.' - ORDER BY actualizacion DESC LIMIT '.$offset.','.$config['block_size']; - break; +$params = [ + '', + '-10', + '1', + '-1', + '0', + '', + '', + '', + agents_get_name($id_agent), +]; - case 'oracle': - $sql = 'SELECT * FROM tincidencia WHERE - id_grupo IN ('.implode(',', array_keys($groups)).')'.$filter.' - AND rownum <= '.$offset.','.$config['block_size'].' - ORDER BY actualizacion DESC'; - break; -} +$result = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents', $params, false, 'json', ','); -$result = db_get_all_rows_sql($sql); +$result = json_decode($result, true); $count_sql = 'SELECT count(*) FROM tincidencia WHERE id_grupo IN ('.implode(',', array_keys($groups)).')'.$filter.' @@ -91,8 +93,6 @@ $table->head[2] = __('Incident'); $table->head[3] = __('Priority'); $table->head[4] = __('Group'); $table->head[5] = __('Updated'); -$table->head[6] = __('Source'); -$table->head[7] = __('Owner'); $table->size[0] = 43; $table->size[7] = 50; @@ -115,7 +115,7 @@ foreach ($result as $row) { $data = []; - $data[0] = ''.$row['id_incidencia'].''; + $data[0] = ''.$row['id_incidencia'].''; $attach = incidents_get_attach($row['id_incidencia']); if (!empty($attach)) { @@ -123,12 +123,10 @@ foreach ($result as $row) { } $data[1] = incidents_print_status_img($row['estado'], true); - $data[2] = ''.substr(io_safe_output($row['titulo']), 0, 45).''; + $data[2] = ''.substr(io_safe_output($row['titulo']), 0, 45).''; $data[3] = incidents_print_priority_img($row['prioridad'], true); - $data[4] = ui_print_group_icon($row['id_grupo'], true); + $data[4] = $row['id_grupo']; $data[5] = ui_print_timestamp($row['actualizacion'], true); - $data[6] = $row['origen']; - $data[7] = ui_print_username($row['id_usuario'], true); array_push($table->data, $data); } diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 72fc0ef125..1f765c7d86 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -486,20 +486,6 @@ if ($id_agente) { $agent_wizard['active'] = false; } - - $total_incidents = agents_get_count_incidents($id_agente); - - // Incident tab. - if ($total_incidents > 0) { - $incidenttab['text'] = ''.html_print_image('images/book_edit.png', true, ['title' => __('Incidents')]).''; - - if ($tab == 'incident') { - $incidenttab['active'] = true; - } else { - $incidenttab['active'] = false; - } - } - if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { if ($has_remote_conf) { $agent_name = agents_get_name($id_agente); @@ -550,11 +536,6 @@ if ($id_agente) { ]; } - - // Only if the agent has incidents associated show incidents tab. - if ($total_incidents) { - $onheader['incident'] = $incidenttab; - } } else { $onheader = [ 'view' => $viewtab, diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 53272f6273..2175c8f7b2 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -56,7 +56,7 @@ if (is_ajax()) { $command = alerts_get_alert_command($id); - // If is setted a description, we change the carriage return by
tags + // If a description is set, change the carriage return by
tags. if (isset($command['description'])) { $command['description'] = str_replace( [ @@ -265,6 +265,76 @@ if (is_ajax()) { $editor_type_chkbx .= ''; $rfield = $editor_type_chkbx; // Select type. + } else if (preg_match('/^_integria_type_custom_field_$/i', $field_value)) { + $ffield = ''; + $rfield = ''; + + $ffield .= '
'.html_print_switch( + [ + 'name' => 'field'.$i.'_value[]', + 'value' => '', + ] + ).'
'; + $rfield .= '
'.html_print_switch( + [ + 'name' => 'field'.$i.'_recovery_value[]', + 'value' => '', + ] + ).'
'; + + $ffield .= html_print_select( + '', + 'field'.$i.'_value[]', + '', + '', + __('None'), + '', + true, + false, + false, + 'fields', + $is_central_policies_on_node + ); + + $rfield .= html_print_select( + '', + 'field'.$i.'_recovery_value[]', + '', + '', + __('None'), + '', + true, + false, + false, + 'fields', + $is_central_policies_on_node + ); + + $ffield .= html_print_input_text('field'.$i.'_value[]', '', '', 10, 10, true, false, false, '', 'datepicker'); + $rfield .= html_print_input_text('field'.$i.'_recovery_value[]', '', '', 10, 10, true, false, false, '', 'datepicker'); + + $ffield .= html_print_textarea( + 'field'.$i.'_value[]', + 1, + 1, + '', + 'style="min-height:40px; '.$style.'" class="fields"', + true, + '', + $is_central_policies_on_node + ); + + + $rfield .= html_print_textarea( + 'field'.$i.'_recovery_value[]', + 1, + 1, + '', + 'style="min-height:40px; '.$style.'" class="fields_recovery', + true, + '', + $is_central_policies_on_node + ); } else { $fields_value_select = []; $fv = explode(';', $field_value); diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index 4fa89805ce..e1c07778c3 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -97,7 +97,14 @@ $table->data[1][0] = __('Actions'); $groups_user = users_get_groups($config['id_user']); if (!empty($groups_user)) { $groups = implode(',', array_keys($groups_user)); - $sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)"; + + if ($config['integria_enabled'] == 0) { + $integria_command = 'Integria IMS Ticket'; + $sql = sprintf('SELECT taa.id, taa.name FROM talert_actions taa INNER JOIN talert_commands tac ON taa.id_alert_command = tac.id WHERE tac.name <> "%s" AND taa.id_group IN (%s)', $integria_command, $groups); + } else { + $sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)"; + } + $actions = db_get_all_rows_sql($sql); } diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 67a2837955..f3dfc35250 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -16,6 +16,7 @@ global $config; require_once $config['homedir'].'/include/functions_alerts.php'; require_once $config['homedir'].'/include/functions_users.php'; +require_once $config['homedir'].'/include/functions_integriaims.php'; enterprise_include_once('meta/include/functions_alerts_meta.php'); check_login(); @@ -36,6 +37,19 @@ $id = (int) get_parameter('id'); $al_action = alerts_get_alert_action($id); $pure = get_parameter('pure', 0); +if (is_ajax()) { + $get_integria_ticket_custom_types = (bool) get_parameter('get_integria_ticket_custom_types'); + + if ($get_integria_ticket_custom_types) { + $ticket_type_id = get_parameter('ticket_type_id'); + + $api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_fields', $ticket_type_id, false, 'json'); + + echo $api_call; + return; + } +} + if (defined('METACONSOLE')) { $sec = 'advanced'; } else { @@ -101,6 +115,7 @@ if ($id) { $group = $action['id_group']; $action_threshold = $action['action_threshold']; + $create_wu_integria = $action['create_wu_integria']; } // Hidden div with help hint to fill with javascript. @@ -185,10 +200,18 @@ $table->data[1][1] = '
'.html_print_select_groups( ).'
'; $table->colspan[1][1] = 2; +$create_ticket_command_id = db_get_value('id', 'talert_commands', 'name', io_safe_input('Integria IMS Ticket')); + +$sql_exclude_command_id = ''; + +if ($config['integria_enabled'] == 0 && $create_ticket_command_id !== false) { + $sql_exclude_command_id = ' AND id <> '.$create_ticket_command_id; +} + $table->data[2][0] = __('Command'); $commands_sql = db_get_all_rows_filter( 'talert_commands', - ['id_group' => array_keys(users_get_groups(false, 'LW'))], + 'id_group IN ('.implode(',', array_keys(users_get_groups(false, 'LW'))).')'.$sql_exclude_command_id, [ 'id', 'name', @@ -266,6 +289,12 @@ $table->data[5][2] = html_print_textarea( true ); +$table->data[6][0] = __('Create workunit on recovery').ui_print_help_tip( + __('If closed status is set on recovery, a workunit will be added to the ticket in Integria IMS rather that closing the ticket.'), + true +); +$table->data[6][1] = html_print_checkbox_switch_extended('create_wu_integria', 1, $create_wu_integria, false, '', '', true); + for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $table->data['field'.$i][0] = html_print_image( 'images/spinner.gif', @@ -356,6 +385,182 @@ $(document).ready (function () { render_command_description(command_description); } + function ajax_get_integria_custom_fields(ticket_type_id, values, recovery_values) { + var values = values || []; + var recovery_values = recovery_values || []; + + if (ticket_type_id === null || ticket_type_id === '' || (Array.isArray(values) && values.length === 0 && Array.isArray(recovery_values) && recovery_values.length === 0)) { + $('[name=field8_value\\[\\]').val(''); + $('[name=field9_value\\[\\]').val(''); + $('[name=field10_value\\[\\]').val(''); + $('[name=field8_recovery_value\\[\\]').val(''); + $('[name=field9_recovery_value\\[\\]').val(''); + $('[name=field10_recovery_value\\[\\]').val(''); + } + + // On ticket type change, hide all table rows and inputs corresponding to custom fields, regardless of what its type is. + $('[name=field8_value\\[\\]').hide(); + $('[name=field9_value\\[\\]').hide(); + $('[name=field10_value\\[\\]').hide(); + $('[name=field8_recovery_value\\[\\]').hide(); + $('[name=field9_recovery_value\\[\\]').hide(); + $('[name=field10_recovery_value\\[\\]').hide(); + $('#table_macros-field8').hide(); + $('#table_macros-field9').hide(); + $('#table_macros-field10').hide(); + $('[name=field8_value_container').hide(); + $('[name=field9_value_container').hide(); + $('[name=field10_value_container').hide(); + $('[name=field8_recovery_value_container').hide(); + $('[name=field9_recovery_value_container').hide(); + $('[name=field10_recovery_value_container').hide(); + + jQuery.post( + "ajax.php", + { + page: "godmode/alerts/configure_alert_action", + get_integria_ticket_custom_types: 1, + ticket_type_id: ticket_type_id + }, + function(data) { + var max_macro_fields = ; + + data.forEach(function(custom_field, key) { + var custom_field_key = key+8; // Custom fields start from field 8. + + if (custom_field_key > max_macro_fields) { + return; + } + + // Display field row for current input. + var custom_field_row = $('#table_macros-field'+custom_field_key); + custom_field_row.show(); + + // Replace label text of field row for current input. + var label_html = $('#table_macros-field'+custom_field_key+' td').first().html(); + var label_name = label_html.split('
')[0]; + var new_html_content = custom_field_row.html().replace(label_name, custom_field.label); + custom_field_row.html(new_html_content); + + switch (custom_field.type) { + case 'checkbox': + var checkbox_selector = $('input:not(.datepicker)[name=field'+custom_field_key+'_value\\[\\]]'); + var checkbox_recovery_selector = $('input:not(.datepicker)[name=field'+custom_field_key+'_recovery_value\\[\\]]'); + + checkbox_selector.on('change', function() { + if (checkbox_selector.prop('checked')) { + checkbox_selector.attr('value', "1"); + } else { + checkbox_selector.attr('value', "0"); + } + }); + + checkbox_recovery_selector.on('change', function() { + if (checkbox_recovery_selector.prop('checked')) { + checkbox_recovery_selector.attr('value', "1"); + } else { + checkbox_recovery_selector.attr('value', "0"); + } + }); + + if (typeof values[key] !== "undefined") { + if (values[key] == 1) { + checkbox_selector.prop('checked', true); + checkbox_selector.attr('value', "1"); + } else { + checkbox_selector.prop('checked', false); + checkbox_selector.attr('value', "0"); + } + } + + if (typeof recovery_values[key] !== "undefined") { + if (recovery_values[key] == 1) { + checkbox_recovery_selector.prop('checked', true); + checkbox_recovery_selector.attr('value', "1"); + } else { + checkbox_recovery_selector.prop('checked', false); + checkbox_recovery_selector.attr('value', "0"); + } + } + + $('[name=field'+custom_field_key+'_value_container]').show(); + $('[name=field'+custom_field_key+'_recovery_value_container]').show(); + $('input:not(.datepicker)[name=field'+custom_field_key+'_value\\[\\]]').show(); + $('input:not(.datepicker)[name=field'+custom_field_key+'_recovery_value\\[\\]]').show(); + break; + case 'combo': + var combo_input = $('select[name=field'+custom_field_key+'_value\\[\\]]'); + var combo_input_recovery = $('select[name=field'+custom_field_key+'_recovery_value\\[\\]]'); + + combo_input.find('option').remove(); + combo_input_recovery.find('option').remove(); + + var combo_values_array = custom_field.combo_value.split(','); + + combo_values_array.forEach(function(value) { + combo_input.append($('
'; - echo "
"; - html_print_input_hidden('api_execute', 1); - html_print_submit_button(__('Call'), 'submit', false, 'class="sub next"'); + echo "
"; echo '
'; echo ''; @@ -212,7 +210,7 @@ function extension_api_checker() html_print_table($table3); echo ''; - echo "
"; + echo "
"; html_print_input_hidden('api_execute', 1); html_print_submit_button(__('Call'), 'submit', false, 'class="sub next"'); echo '
'; diff --git a/pandora_console/extensions/db_status.php b/pandora_console/extensions/db_status.php index 09bf7b9672..d55294f3a6 100755 --- a/pandora_console/extensions/db_status.php +++ b/pandora_console/extensions/db_status.php @@ -67,7 +67,7 @@ function extension_db_status() html_print_table($table); echo ''; - echo "
"; + echo "
"; html_print_input_hidden('db_status_execute', 1); html_print_submit_button(__('Execute Test'), 'submit', false, 'class="sub next"'); echo '
'; diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index 416c208a04..7d32b730e5 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -119,7 +119,7 @@ function dbmgr_extension_main() echo "
"; html_print_textarea('sql', 5, 50, html_entity_decode($sql, ENT_QUOTES)); echo '
'; - echo '
'; + echo '
'; echo '
'; html_print_submit_button(__('Execute SQL'), '', false, 'class="sub next"'); echo '
'; @@ -156,7 +156,7 @@ function dbmgr_extension_main() return; } - echo "
"; + echo "
"; $table = new stdClass(); $table->width = '100%'; $table->class = 'info_table'; diff --git a/pandora_console/extensions/disabled/matrix_events.php b/pandora_console/extensions/disabled/matrix_events.php index b89f58a96c..2f8d815684 100644 --- a/pandora_console/extensions/disabled/matrix_events.php +++ b/pandora_console/extensions/disabled/matrix_events.php @@ -25,12 +25,19 @@ function load_matrix_console() if (! $pure) { $title_menu = __('Matrix events'); - $fullscreen['text'] = ''.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).''; + $fullscreen['text'] = ''.html_print_image( + 'images/full_screen.png', + true, + [ + 'title' => __('Full screen mode'), + 'class' => 'invert_filter', + ] + ).''; $onheader = ['fullscreen' => $fullscreen]; ui_print_page_header($title_menu, 'images/op_monitoring.png', false, '', false, $onheader); } - echo ''; + echo ''; ?> '; } else { @@ -256,7 +257,7 @@ if ($config['menu_type'] == 'classic') { $ignored_params['refr'] = ''; $values = get_refresh_time_array(); - $autorefresh_additional = '