Added remote command execute to agent wizard
This commit is contained in:
parent
6b4dfe9885
commit
bab1f14a31
|
@ -34,6 +34,7 @@ $ip_target = (string) get_parameter ('ip_target', $ipAgent);
|
|||
$use_agent = get_parameter ('use_agent');
|
||||
$snmp_community = (string) get_parameter ('snmp_community', 'public');
|
||||
$snmp_version = get_parameter('snmp_version', '1');
|
||||
$server_to_exec = get_parameter('server_to_exec', 0);
|
||||
$snmp3_auth_user = get_parameter('snmp3_auth_user');
|
||||
$snmp3_security_level = get_parameter('snmp3_security_level');
|
||||
$snmp3_auth_method = get_parameter('snmp3_auth_method');
|
||||
|
@ -87,7 +88,8 @@ if ($snmpwalk) {
|
|||
// OID Used is for DISKS
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.25.2.3.1.3", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.25.2.3.1.3", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
if (empty($snmpis)) {
|
||||
$fail = true;
|
||||
|
@ -120,7 +122,8 @@ if ($snmpwalk) {
|
|||
// OID Used is for PROCESSES
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.25.4.2.1.2", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.25.4.2.1.2", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
if ($snmpis === false) {
|
||||
$snmpis = array();
|
||||
|
@ -158,7 +161,8 @@ if ($snmpwalk) {
|
|||
// OID Used is for SENSOR TEMPERATURES
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.4.1.2021.13.16.2.1", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.4.1.2021.13.16.2.1", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
if ($snmpis === false) {
|
||||
$snmpis = array();
|
||||
|
@ -196,7 +200,8 @@ if ($snmpwalk) {
|
|||
// OID Used is for DEVICES
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.4.1.2021.13.15.1.1", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.4.1.2021.13.15.1.1", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
if ($snmpis === false) {
|
||||
$snmpis = array();
|
||||
|
@ -706,6 +711,19 @@ $table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, tr
|
|||
$table->data[1][0] = '<b>' . __('Use agent ip') . '</b>';
|
||||
$table->data[1][1] = html_print_checkbox ('use_agent', 1, $use_agent, true);
|
||||
|
||||
$servers_to_exec = array();
|
||||
$servers_to_exec[0] = __('Local console');
|
||||
if (enterprise_installed()) {
|
||||
enterprise_include_once ('include/functions_satellite.php');
|
||||
|
||||
$rows = get_proxy_servers();
|
||||
foreach ($rows as $row) {
|
||||
$servers_to_exec[$row['id_server']] = $row['name'];
|
||||
}
|
||||
}
|
||||
$table->data[1][2] = '<b>' . __('Server to execute command') . '</b>';
|
||||
$table->data[1][3] = html_print_select ($servers_to_exec, 'server_to_exec', $server_to_exec, '', '', '', true);
|
||||
|
||||
$snmp_versions['1'] = 'v. 1';
|
||||
$snmp_versions['2'] = 'v. 2';
|
||||
$snmp_versions['2c'] = 'v. 2c';
|
||||
|
|
|
@ -30,6 +30,7 @@ check_login ();
|
|||
$ip_target = (string) get_parameter ('ip_target', $ipAgent);
|
||||
$use_agent = get_parameter ('use_agent');
|
||||
$snmp_community = (string) get_parameter ('snmp_community', 'public');
|
||||
$server_to_exec = get_parameter('server_to_exec', 0);
|
||||
$snmp_version = get_parameter('snmp_version', '1');
|
||||
$snmp3_auth_user = get_parameter('snmp3_auth_user');
|
||||
$snmp3_security_level = get_parameter('snmp3_security_level');
|
||||
|
@ -53,16 +54,19 @@ if ($snmpwalk) {
|
|||
// OID Used is for SNMP MIB-2 Interfaces
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.2", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.2", $tcp_port,
|
||||
$server_to_exec);
|
||||
// ifXTable is also used
|
||||
$ifxitems = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.31.1.1", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.31.1.1", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
// Get the interfaces IPV4/IPV6
|
||||
$snmp_int_ip = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.4.34.1.3", $tcp_port);
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.4.34.1.3", $tcp_port,
|
||||
$server_to_exec);
|
||||
|
||||
// Build a [<interface id>] => [<interface ip>] array
|
||||
if (!empty($snmp_int_ip)) {
|
||||
|
@ -345,6 +349,19 @@ $table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, tr
|
|||
$table->data[1][0] = '<b>' . __('Use agent ip') . '</b>';
|
||||
$table->data[1][1] = html_print_checkbox ('use_agent', 1, $use_agent, true);
|
||||
|
||||
$servers_to_exec = array();
|
||||
$servers_to_exec[0] = __('Local console');
|
||||
if (enterprise_installed()) {
|
||||
enterprise_include_once ('include/functions_satellite.php');
|
||||
|
||||
$rows = get_proxy_servers();
|
||||
foreach ($rows as $row) {
|
||||
$servers_to_exec[$row['id_server']] = $row['name'];
|
||||
}
|
||||
}
|
||||
$table->data[1][2] = '<b>' . __('Server to execute command') . '</b>';
|
||||
$table->data[1][3] = html_print_select ($servers_to_exec, 'server_to_exec', $server_to_exec, '', '', '', true);
|
||||
|
||||
$snmp_versions['1'] = 'v. 1';
|
||||
$snmp_versions['2'] = 'v. 2';
|
||||
$snmp_versions['2c'] = 'v. 2c';
|
||||
|
|
|
@ -29,6 +29,7 @@ $ip_target = (string) get_parameter ('ip_target', $ipAgent); // Host
|
|||
$plugin_user = (string) get_parameter ('plugin_user', 'Administrator'); // Username
|
||||
$plugin_pass = io_safe_output(get_parameter('plugin_pass', '')); // Password
|
||||
$tcp_send = (string) get_parameter ('tcp_send'); // Namespace
|
||||
$server_to_exec = get_parameter('server_to_exec', true);
|
||||
|
||||
//See if id_agente is set (either POST or GET, otherwise -1
|
||||
$id_agent = $idAgent;
|
||||
|
@ -53,7 +54,18 @@ if ($wmiexplore) {
|
|||
$wmi_processes = $wmi_command . ' "select Name from Win32_Process"';
|
||||
$processes_name_field = 1;
|
||||
|
||||
exec($wmi_processes, $output);
|
||||
if (enterprise_installed()) {
|
||||
if ($server_to_exec != 0) {
|
||||
$server_data = db_get_row('tserver','id_server', $server_to_exec);
|
||||
exec("ssh root@" . $server_data['ip_address'] . " '" . $wmi_processes . "'", $output, $rc);
|
||||
}
|
||||
else {
|
||||
exec($wmi_processes, $output);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exec($wmi_processes, $output);
|
||||
}
|
||||
|
||||
$fail = false;
|
||||
if (preg_match('/^Failed/', $output[0])) {
|
||||
|
@ -79,7 +91,18 @@ if ($wmiexplore) {
|
|||
$services_name_field = 0;
|
||||
$services_check_field = 1;
|
||||
|
||||
exec($wmi_services, $output);
|
||||
if (enterprise_installed()) {
|
||||
if ($server_to_exec != 0) {
|
||||
$server_data = db_get_row('tserver','id_server', $server_to_exec);
|
||||
exec("ssh root@" . $server_data['ip_address'] . " '" . $wmi_services . "'", $output, $rc);
|
||||
}
|
||||
else {
|
||||
exec($wmi_services, $output);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exec($wmi_services, $output);
|
||||
}
|
||||
|
||||
foreach ($output as $index => $row) {
|
||||
// First and second rows are Class and column names, ignore it
|
||||
|
@ -98,7 +121,18 @@ if ($wmiexplore) {
|
|||
$wmi_disks = $wmi_command . ' "Select DeviceID from Win32_LogicalDisk"';
|
||||
$disks_name_field = 0;
|
||||
|
||||
exec($wmi_disks, $output);
|
||||
if (enterprise_installed()) {
|
||||
if ($server_to_exec != 0) {
|
||||
$server_data = db_get_row('tserver','id_server', $server_to_exec);
|
||||
exec("ssh root@" . $server_data['ip_address'] . " '" . $wmi_disks . "'", $output, $rc);
|
||||
}
|
||||
else {
|
||||
exec($wmi_disks, $output);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exec($wmi_disks, $output);
|
||||
}
|
||||
|
||||
foreach ($output as $index => $row) {
|
||||
// First and second rows are Class and column names, ignore it
|
||||
|
@ -267,6 +301,19 @@ $table->data[1][3] = html_print_input_password ('plugin_pass', $plugin_pass, '',
|
|||
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
|
||||
html_print_input_hidden('wmiexplore', 1);
|
||||
|
||||
$servers_to_exec = array();
|
||||
$servers_to_exec[0] = __('Local console');
|
||||
if (enterprise_installed()) {
|
||||
enterprise_include_once ('include/functions_satellite.php');
|
||||
|
||||
$rows = get_proxy_servers();
|
||||
foreach ($rows as $row) {
|
||||
$servers_to_exec[$row['id_server']] = $row['name'];
|
||||
}
|
||||
}
|
||||
$table->data[2][0] = '<b>' . __('Server to execute command') . '</b>';
|
||||
$table->data[2][1] = html_print_select ($servers_to_exec, 'server_to_exec', $server_to_exec, '', '', '', true);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
|
|
|
@ -139,7 +139,7 @@ if ($perform_event_response) {
|
|||
$return_val = array();
|
||||
$return_val['correct'] = false;
|
||||
|
||||
$exec_val = system("ssh root@" . $server_data['ip_address'] . " '" . $command . " 2>&1'", $ret_val);
|
||||
$exec_val = system("ssh root@" . $server_data['ip_address'] . " \"" . $command . " 2>&1\"", $ret_val);
|
||||
|
||||
if ($ret_val != 0) {
|
||||
$return_val['message'] = "Conection error";
|
||||
|
|
|
@ -1506,7 +1506,7 @@ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '',
|
|||
$snmp3_auth_user = '', $snmp3_security_level = '',
|
||||
$snmp3_auth_method = '', $snmp3_auth_pass = '',
|
||||
$snmp3_privacy_method = '', $snmp3_privacy_pass = '',
|
||||
$quick_print = 0, $base_oid = "", $snmp_port = '') {
|
||||
$quick_print = 0, $base_oid = "", $snmp_port = '', $server_to_exec = 0) {
|
||||
|
||||
global $config;
|
||||
|
||||
|
@ -1598,7 +1598,18 @@ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '',
|
|||
break;
|
||||
}
|
||||
|
||||
exec($command_str, $output, $rc);
|
||||
if (enterprise_installed()) {
|
||||
if ($server_to_exec != 0) {
|
||||
$server_data = db_get_row('tserver','id_server', $server_to_exec);
|
||||
exec("ssh root@" . $server_data['ip_address'] . " \"" . $command_str . "\"", $output, $rc);
|
||||
}
|
||||
else {
|
||||
exec($command_str, $output, $rc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exec($command_str, $output, $rc);
|
||||
}
|
||||
|
||||
// Parse the output of snmpwalk
|
||||
$snmpwalk = array();
|
||||
|
|
Loading…
Reference in New Issue