diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 14bf0c85a8..20cd0c4a80 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -130,15 +130,29 @@ if ($perform_event_response) { if ($event_response['server_to_exec'] != 0 && $event_response['type'] == 'command') { $commandExclusions = array ('vi', 'vim', 'nano'); + $server_data = db_get_row('tserver','id_server', $event_response['server_to_exec']); + if (in_array(strtolower($command),$commandExclusions)) { echo "Only stdin/stdout commands are supported"; } else { - enterprise_include_once ('include/functions_satellite.php'); - - $connection = connect_to_proxy_server('192.168.70.165'); + $return_val = array(); + $return_val['correct'] = false; - $exec_val = proxy_execute_command($connection, io_safe_output($command)); + $exec_val = system("ssh root@" . $server_data['ip_address'] . " '" . $command . " 2>&1'", $ret_val); + + if ($ret_val != 0) { + $return_val['message'] = "Conection error"; + } + else { + if ($exec_val == "root") { + $return_val['correct'] = true; + } + else { + $return_val['message'] = "User must be pandora_exec_proxy"; + } + } + ob_clean(); echo $exec_val; } diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index df434c8545..9da6d75881 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -173,37 +173,32 @@ function snmp_browser_get_tree ($target_ip, $community, $starting_oid = '.', $ve $error_redir_dir = '/dev/null'; break; } - + if ($server_to_exec != 0) { - $sql = sprintf("SELECT exec_proxy: FROM tserver WHERE id_server = %d", $server_to_exec); - $server = db_get_row_sql($sql); + $sql = sprintf("SELECT ip_address FROM tserver WHERE id_server = %d", $server_to_exec); + $server_data = db_get_row_sql($sql); - if ($server) { - if (enterprise_installed()) { - enterprise_include_once ('include/functions_satellite.php'); + if (enterprise_installed()) { + enterprise_include_once ('include/functions_satellite.php'); - $oid_tree = array('__LEAVES__' => array()); - if ($version == "3") { - switch ($snmp3_security_level) { - case "authPriv": - $command = $snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir; - break; - case "authNoPriv": - $command = $snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir; - break; - case "noAuthNoPriv": - $command = $snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -l ' . escapeshellarg($snmp3_security_level) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir; - break; - } + $oid_tree = array('__LEAVES__' => array()); + if ($version == "3") { + switch ($snmp3_security_level) { + case "authPriv": + $command = $snmpwalk_bin . " -m ALL -v 3 -u " . escapeshellarg($snmp3_auth_user) . " -A " . escapeshellarg($snmp3_auth_pass) . " -l " . escapeshellarg($snmp3_security_level) . " -a " . escapeshellarg($snmp3_auth_method) . " -x " . escapeshellarg($snmp3_privacy_method) . " -X " . escapeshellarg($snmp3_privacy_pass) . " " . escapeshellarg($target_ip) . " " . escapeshellarg($starting_oid) . " 2> " . $error_redir_dir; + break; + case "authNoPriv": + $command = $snmpwalk_bin . " -m ALL -v 3 -u " . escapeshellarg($snmp3_auth_user) . " -A " . escapeshellarg($snmp3_auth_pass) . " -l " . escapeshellarg($snmp3_security_level) . " -a " . escapeshellarg($snmp3_auth_method) . " " . escapeshellarg($target_ip) . " " . escapeshellarg($starting_oid) . " 2> " . $error_redir_dir; + break; + case "noAuthNoPriv": + $command = $snmpwalk_bin . " -m ALL -v 3 -u " . escapeshellarg($snmp3_auth_user) . " -l " . escapeshellarg($snmp3_security_level) . " " . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . " 2> " . $error_redir_dir; + break; } - else { - $command = $snmpwalk_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -Cc -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir; - } - - $connection = connect_to_proxy_server('192.168.70.165'); - - $output = proxy_execute_command($connection, io_safe_output($command)); } + else { + $command = $snmpwalk_bin . " -m ALL -M +" . escapeshellarg($config['homedir'] . "/attachment/mibs") . " -Cc -c " . escapeshellarg($community) . " -v " . escapeshellarg($version) . " " . escapeshellarg($target_ip) . " " . escapeshellarg($starting_oid) . " 2> " . $error_redir_dir; + } + exec("ssh root@" . $server_data['ip_address'] . " \"" . $command . "\"", $output, $rc); } else { $oid_tree = array('__LEAVES__' => array()); @@ -225,7 +220,26 @@ function snmp_browser_get_tree ($target_ip, $community, $starting_oid = '.', $ve } } } - + else { + $oid_tree = array('__LEAVES__' => array()); + if ($version == "3") { + switch ($snmp3_security_level) { + case "authPriv": + exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir, $output, $rc); + break; + case "authNoPriv": + exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir, $output, $rc); + break; + case "noAuthNoPriv": + exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -l ' . escapeshellarg($snmp3_security_level) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir, $output, $rc); + break; + } + } + else { + exec ($snmpwalk_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -Cc -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir, $output, $rc); + } + } +html_debug($output, true); foreach ($output as $line) { // Separate the OID from the value