From 5eb2953810bb77f890dca35c10f3583873820062 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 14 Jan 2020 15:43:17 +0100 Subject: [PATCH] Added port option on server configuration to be used when connecting to execution server --- pandora_console/extras/mr/35.sql | 5 ++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 1 + .../agentes/agent_wizard.snmp_explorer.php | 2 +- .../agent_wizard.snmp_interfaces_explorer.php | 2 +- .../agentes/agent_wizard.wmi_explorer.php | 57 ++++++++++++++----- .../godmode/servers/modificar_server.php | 13 ++++- .../godmode/servers/servers.build_table.php | 4 ++ pandora_console/include/ajax/events.php | 6 +- pandora_console/include/functions.php | 7 ++- .../include/functions_snmp_browser.php | 19 +++++-- pandora_console/pandoradb.sql | 1 + 11 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 pandora_console/extras/mr/35.sql diff --git a/pandora_console/extras/mr/35.sql b/pandora_console/extras/mr/35.sql new file mode 100644 index 0000000000..cf6a4d940a --- /dev/null +++ b/pandora_console/extras/mr/35.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `tserver` ADD COLUMN `port` int(5) unsigned NOT NULL default 0; + +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 ca415cd52a..d4f773b1ff 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 @@ -1775,6 +1775,7 @@ ALTER TABLE tserver_export_data MODIFY `module_name` varchar(600) NOT NULL defau -- Table `tserver` -- --------------------------------------------------------------------- ALTER TABLE tserver ADD COLUMN exec_proxy tinyint(1) UNSIGNED NOT NULL default 0; +ALTER TABLE `tserver` ADD COLUMN `port` int(5) unsigned NOT NULL default 0; -- --------------------------------------------------------------------- -- Table `tevent_response` diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php index fbb03c6e02..1fd9136a2c 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_explorer.php @@ -750,7 +750,7 @@ if (enterprise_installed()) { } } -$table->data[1][2] = ''.__('Server to execute command').''; +$table->data[1][2] = ''.__('Server to execute command').''.ui_print_help_icon('agent_snmp_explorer_tab', true); $table->data[1][3] = html_print_select($servers_to_exec, 'server_to_exec', $server_to_exec, '', '', '', true); $snmp_versions['1'] = 'v. 1'; diff --git a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php index 3eb404340e..50ae676926 100644 --- a/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.snmp_interfaces_explorer.php @@ -492,7 +492,7 @@ if (enterprise_installed()) { } } -$table->data[1][2] = ''.__('Server to execute command').''; +$table->data[1][2] = ''.__('Server to execute command').''.ui_print_help_icon('agent_snmp_explorer_tab', true); $table->data[1][2] .= ''.ui_print_help_tip(__('In order to use remote executions you need to enable remote execution in satellite server'), true, 'images/tip_help.png', false, 'display:').''; $table->data[1][4] = html_print_select( $servers_to_exec, diff --git a/pandora_console/godmode/agentes/agent_wizard.wmi_explorer.php b/pandora_console/godmode/agentes/agent_wizard.wmi_explorer.php index 5d889178bb..c7eb716e80 100644 --- a/pandora_console/godmode/agentes/agent_wizard.wmi_explorer.php +++ b/pandora_console/godmode/agentes/agent_wizard.wmi_explorer.php @@ -64,12 +64,22 @@ if ($wmiexplore) { $processes_name_field = 1; if (enterprise_installed() && (int) $server_to_exec != 0) { $server_data = db_get_row('tserver', 'id_server', $server_to_exec); - exec( - 'ssh pandora_exec_proxy@'.$server_data['ip_address']." - '".$wmi_processes."'", - $output, - $rc - ); + + if (empty($server_data['port'])) { + exec( + 'ssh pandora_exec_proxy@'.$server_data['ip_address']." + '".$wmi_processes."'", + $output, + $rc + ); + } else { + exec( + 'ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address']." + '".$wmi_processes."'", + $output, + $rc + ); + } } else { exec($wmi_processes, $output); } @@ -110,12 +120,21 @@ if ($wmiexplore) { 'id_server', $server_to_exec ); + if (empty($server_data['port'])) { exec( 'ssh pandora_exec_proxy@'.$server_data['ip_address']." - '".$wmi_services."'", + '".$wmi_services."'", $output, $rc ); + } else { + exec( + 'ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address']." + '".$wmi_services."'", + $output, + $rc + ); + } } else { exec($wmi_services, $output); } @@ -145,12 +164,22 @@ if ($wmiexplore) { if (enterprise_installed() && (int) $server_to_exec != 0) { $server_data = db_get_row('tserver', 'id_server', $server_to_exec); - exec( - 'ssh pandora_exec_proxy@'.$server_data['ip_address']." - '".$wmi_disks."'", - $output, - $rc - ); + + if (empty($server_data['port'])) { + exec( + 'ssh pandora_exec_proxy@'.$server_data['ip_address']." + '".$wmi_disks."'", + $output, + $rc + ); + } else { + exec( + 'ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address']." + '".$wmi_disks."'", + $output, + $rc + ); + } } else { exec($wmi_disks, $output); } @@ -469,7 +498,7 @@ if (enterprise_installed()) { } } -$table->data[2][0] = ''.__('Server to execute command').''; +$table->data[2][0] = ''.__('Server to execute command').''.ui_print_help_icon('agent_snmp_explorer_tab', true); $table->data[2][1] = html_print_select( $servers_to_exec, 'server_to_exec', diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 66c14ee89f..8af5e47199 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -32,7 +32,7 @@ if (isset($_GET['server'])) { $id_server = get_parameter_get('server'); // Headers ui_print_page_header(__('Update Server'), 'images/gm_servers.png', false, 'servers', true); - $sql = sprintf('SELECT name, ip_address, description, server_type, exec_proxy FROM tserver WHERE id_server = %d', $id_server); + $sql = sprintf('SELECT name, ip_address, description, server_type, exec_proxy, port FROM tserver WHERE id_server = %d', $id_server); $row = db_get_row_sql($sql); echo '
'; html_print_input_hidden('server', $id_server); @@ -81,6 +81,13 @@ if (isset($_GET['server'])) { ''.html_print_image('images/dot_red.disabled.png', true).''.'
', ]; } + + $port_number = empty($row['port']) ? '' : $row['port']; + + $table->data[] = [ + __('Port'), + html_print_input_text('port', $port_number, '', 10, 0, true).ui_print_help_tip(__('Leave blank to use SSH default port (22)'), true), + ]; } } @@ -136,11 +143,15 @@ if (isset($_GET['server'])) { $description = get_parameter_post('description'); $id_server = get_parameter_post('server'); $exec_proxy = get_parameter_post('exec_proxy'); + $port = get_parameter_post('port'); + + $port_number = empty($port) ? 0 : $port; $values = [ 'ip_address' => $address, 'description' => $description, 'exec_proxy' => $exec_proxy, + 'port' => $port_number, ]; $result = db_process_sql_update('tserver', $values, ['id_server' => $id_server]); if ($result !== false) { diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 0006fc3e9b..668ef26f0c 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -101,6 +101,10 @@ foreach ($servers as $server) { $data[2] .= ui_print_help_tip(__('This is a master server'), true); } + if ($server['exec_proxy'] == 1) { + $data[2] .= html_print_image('images/star.png', true, ['title' => __('Exec server enabled')]); + } + // $data[2] .= ' v' .. ''; switch ($server['type']) { case 'snmp': diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 24fa8be341..70d1470366 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -954,7 +954,11 @@ if ($perform_event_response) { break; } - system('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1"', $ret_val); + if (empty($server_data['port'])) { + system('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1"', $ret_val); + } else { + system('ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1"', $ret_val); + } } } else { switch (PHP_OS) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 08a41a00f2..ba6350e49c 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1994,7 +1994,12 @@ function get_snmpwalk( if (enterprise_installed()) { if ($server_to_exec != 0) { $server_data = db_get_row('tserver', 'id_server', $server_to_exec); - exec('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_str.'"', $output, $rc); + + if (empty($server_data['port'])) { + exec('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_str.'"', $output, $rc); + } else { + exec('ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_str.'"', $output, $rc); + } } else { exec($command_str, $output, $rc); } diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index dc423481f2..bb69eec319 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -409,11 +409,20 @@ function snmp_browser_get_oid( if ($server_to_exec != 0) { $command_output = $snmptranslate_bin.' -m ALL -M +'.escapeshellarg($config['homedir'].'/attachment/mibs').' -Td '.escapeshellarg($oid); - exec( - 'ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_output.'"', - $translate_output, - $rc - ); + + if (empty($server_data['port'])) { + exec( + 'ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_output.'"', + $translate_output, + $rc + ); + } else { + exec( + 'ssh -p '.$server_data['port'].' pandora_exec_proxy@'.$server_data['ip_address'].' "'.$command_output.'"', + $translate_output, + $rc + ); + } } else { exec( $snmptranslate_bin.' -m ALL -M +'.escapeshellarg($config['homedir'].'/attachment/mibs').' -Td '.escapeshellarg($oid), diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index d1db588a10..f6cbd459d5 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1020,6 +1020,7 @@ CREATE TABLE IF NOT EXISTS `tserver` ( `server_keepalive` int(11) NOT NULL default 0, `stat_utimestamp` bigint(20) NOT NULL default '0', `exec_proxy` tinyint(1) UNSIGNED NOT NULL default 0, + `port` int(5) unsigned NOT NULL default 0, PRIMARY KEY (`id_server`), KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;