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 ?>