id_name)) or filters filtered
* Used also in Cloud Wizard.
*
* @param string $tree SNMP tree returned by snmp_broser_get_tree.
* @param string $id Level ID. Do not set, used for recursion.
* @param string $depth Branch depth. Do not set, used for recursion.
* @param integer $last Last.
* @param array $last_array Last_array.
* @param string $sufix Sufix.
* @param array $checked Checked.
* @param boolean $descriptive_ids Descriptive_ids.
* @param string $previous_id Previous_id.
*
* @return string HTML code with complete tree.
*/
function snmp_browser_get_html_tree(
$tree,
$id=0,
$depth=0,
$last=0,
$last_array=[],
$sufix=false,
$checked=[],
$descriptive_ids=false,
$previous_id=''
) {
static $url = false;
$output = '';
// Get the base URL for images.
if ($url === false) {
$url = ui_get_full_url('operation/tree', false, false, false);
}
// Leaf.
if (empty($tree['__LEAVES__'])) {
return '';
}
$count = 0;
$total = (count(array_keys($tree['__LEAVES__'])) - 1);
$last_array[$depth] = $last;
$class = 'item_'.$depth;
if ($depth > 0) {
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
if (isset($snmp_version) === false) {
$snmp_version = null;
}
if ($snmp_version == 3) {
$output .= '
';
} else {
$output .= '
';
}
$output .= ui_toggle(
html_print_table($table3, true),
__('SNMP v3 options'),
'',
'',
true,
true
);
$output .= '
';
$output .= '
';
$output .= ui_toggle(
html_print_table($table2, true),
__('Search options'),
'',
'',
true,
true
);
$output .= '
';
// SNMP tree container.
$output .= '
';
$output .= html_print_input_hidden('search_count', 0, true);
$output .= html_print_input_hidden('search_index', -1, true);
// Save some variables for javascript functions.
$output .= html_print_input_hidden(
'ajax_url',
ui_get_full_url('ajax.php'),
true
);
$output .= html_print_input_hidden(
'search_matches_translation',
__('Search matches'),
true
);
$output .= '
';
$output .= '
'.html_print_image('images/spinner.gif', true).'
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
$output .= '
';
if ($show_massive_buttons) {
$output .= '
';
$output .= html_print_submit_button(
__('Create agent modules'),
'create_modules_agent',
false,
['class' => 'sub add'],
true
);
if (is_management_allowed() === true && enterprise_installed()) {
$output .= html_print_submit_button(
__('Create policy modules'),
'create_modules_policy',
false,
['class' => 'sub add'],
true
);
}
$output .= html_print_submit_button(
__('Create network components'),
'create_modules_network_component',
false,
['class' => 'sub add'],
true
);
$output .= '
';
}
if ($return) {
return $output;
}
echo $output;
}
/**
* Create selected oids as modules on selected target.
*
* @param string $module_target Target where modules will be created (network componen, agent or policy).
* @param array $targets_oids Modules oids.
* @param array $values SNMP conf values.
* @param array|null $id_target (Optional) Id target where modules will be created.
* @param string|null $server_to_exec Remote server to execute command.
*
* @return array Failed modules.
*/
function snmp_browser_create_modules_snmp(
string $module_target,
array $snmp_values,
?array $id_target,
?string $server_to_exec=null
) {
$target_ip = null;
$target_port = null;
$community = null;
$target_oid = null;
$snmp_version = null;
$snmp3_auth_user = null;
$snmp3_security_level = null;
$snmp3_auth_method = null;
$snmp3_auth_pass = null;
$snmp3_privacy_method = null;
$snmp3_privacy_pass = null;
if (is_array($snmp_values)) {
if (isset($snmp_values['snmp_browser_version']) === true) {
$snmp_version = $snmp_values['snmp_browser_version'];
}
if (isset($snmp_values['community']) === true) {
$community = $snmp_values['community'];
}
if (isset($snmp_values['target_ip']) === true) {
$target_ip = $snmp_values['target_ip'];
}
if (isset($snmp_values['target_port']) === true) {
$target_port = $snmp_values['target_port'];
}
if (isset($snmp_values['snmp3_browser_auth_user']) === true) {
$snmp3_auth_user = $snmp_values['snmp3_browser_auth_user'];
}
if (isset($snmp_values['snmp3_browser_security_level']) === true) {
$snmp3_security_level = $snmp_values['snmp3_browser_security_level'];
};
if (isset($snmp_values['snmp3_browser_auth_method']) === true) {
$snmp3_auth_method = $snmp_values['snmp3_browser_auth_method'];
}
if (isset($snmp_values['snmp3_browser_auth_pass']) === true) {
$snmp3_auth_pass = $snmp_values['snmp3_browser_auth_pass'];
}
if (isset($snmp_values['snmp3_privacy_method']) === true) {
$snmp3_privacy_method = $snmp_values['snmp3_privacy_method'];
};
if (isset($snmp_values['snmp3_browser_privacy_pass']) === true) {
$snmp3_privacy_pass = $snmp_values['snmp3_browser_privacy_pass'];
}
if (isset($snmp_values['oids']) === true) {
$targets_oids = $snmp_values['oids'];
}
}
$fail_modules = [];
foreach ($targets_oids as $key => $target_oid) {
$oid = snmp_browser_get_oid(
$target_ip,
$community,
htmlspecialchars_decode($target_oid),
$snmp_version,
$snmp3_auth_user,
$snmp3_security_level,
$snmp3_auth_method,
$snmp3_auth_pass,
$snmp3_privacy_method,
$snmp3_privacy_pass,
$server_to_exec,
$target_port
);
if (isset($oid['numeric_oid']) === false) {
$fail_modules[] = $target_oid;
continue;
}
if (empty($oid['description'])) {
$description = '';
} else {
// Delete extra spaces.
$description = io_safe_input(preg_replace('/\s+/', ' ', $oid['description']));
}
if (!empty($oid['type'])) {
$module_type = snmp_module_get_type($oid['type']);
} else {
$module_type = 17;
}
if ($module_target == 'network_component') {
$name_check = db_get_value(
'name',
'tnetwork_component',
'name',
$oid['oid']
);
if (!$name_check) {
$id = network_components_create_network_component(
$oid['oid'],
$module_type,
1,
[
'description' => $description,
'module_interval' => 300,
'max' => 0,
'min' => 0,
'tcp_send' => $snmp_version,
'tcp_rcv' => '',
'tcp_port' => $target_port,
'snmp_oid' => $oid['numeric_oid'],
'snmp_community' => $community,
'id_module_group' => 3,
'id_modulo' => 2,
'id_plugin' => 0,
'plugin_user' => '',
'plugin_pass' => '',
'plugin_parameter' => '',
'macros' => '',
'max_timeout' => 0,
'max_retries' => 0,
'history_data' => '',
'dynamic_interval' => 0,
'dynamic_max' => 0,
'dynamic_min' => 0,
'dynamic_two_tailed' => 0,
'min_warning' => 0,
'max_warning' => 0,
'str_warning' => '',
'min_critical' => 0,
'max_critical' => 0,
'str_critical' => '',
'min_ff_event' => 0,
'custom_string_1' => '',
'custom_string_2' => '',
'custom_string_3' => '',
'post_process' => 0,
'unit' => '',
'wizard_level' => 'nowizard',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'id_category' => 0,
'tags' => '',
'disabled_types_event' => '{"going_unknown":1}',
'min_ff_event_normal' => 0,
'min_ff_event_warning' => 0,
'min_ff_event_critical' => 0,
'ff_type' => 0,
'each_ff' => 0,
'history_data' => 1,
]
);
}
} else if ($module_target == 'agent') {
$values = [
'id_tipo_modulo' => $module_type,
'descripcion' => $description,
'module_interval' => 300,
'max' => 0,
'min' => 0,
'tcp_send' => $snmp_version,
'tcp_rcv' => '',
'tcp_port' => $target_port,
'snmp_oid' => $oid['numeric_oid'],
'snmp_community' => $community,
'id_module_group' => 3,
'id_modulo' => 2,
'id_plugin' => 0,
'plugin_user' => '',
'plugin_pass' => '',
'plugin_parameter' => '',
'macros' => '',
'max_timeout' => 0,
'max_retries' => 0,
'history_data' => '',
'dynamic_interval' => 0,
'dynamic_max' => 0,
'dynamic_min' => 0,
'dynamic_two_tailed' => 0,
'min_warning' => 0,
'max_warning' => 0,
'str_warning' => '',
'min_critical' => 0,
'max_critical' => 0,
'str_critical' => '',
'min_ff_event' => 0,
'custom_string_1' => '',
'custom_string_2' => '',
'custom_string_3' => '',
'post_process' => 0,
'unit' => '',
'wizard_level' => 'nowizard',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'id_category' => 0,
'disabled_types_event' => '{"going_unknown":1}',
'min_ff_event_normal' => 0,
'min_ff_event_warning' => 0,
'min_ff_event_critical' => 0,
'ff_type' => 0,
'each_ff' => 0,
'ip_target' => $target_ip,
'history_data' => 1,
];
foreach ($id_target as $agent) {
$ids[] = modules_create_agent_module($agent, $oid['oid'], $values);
}
} else if ($module_target == 'policy') {
// Policies only in enterprise version.
if (enterprise_installed()) {
$values = [
'id_tipo_modulo' => $module_type,
'description' => $description,
'module_interval' => 300,
'max' => 0,
'min' => 0,
'tcp_send' => $snmp_version,
'tcp_rcv' => '',
'tcp_port' => $target_port,
'snmp_oid' => $oid['numeric_oid'],
'snmp_community' => $community,
'id_module_group' => 3,
'id_plugin' => 0,
'plugin_user' => '',
'plugin_pass' => '',
'plugin_parameter' => '',
'macros' => '',
'max_timeout' => 0,
'max_retries' => 0,
'history_data' => 1,
'dynamic_interval' => 0,
'dynamic_max' => 0,
'dynamic_min' => 0,
'dynamic_two_tailed' => 0,
'min_warning' => 0,
'max_warning' => 0,
'str_warning' => '',
'min_critical' => 0,
'max_critical' => 0,
'str_critical' => '',
'min_ff_event' => 0,
'custom_string_1' => '',
'custom_string_2' => '',
'custom_string_3' => '',
'post_process' => 0,
'unit' => '',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'id_category' => 0,
'disabled_types_event' => '{"going_unknown":1}',
'min_ff_event_normal' => 0,
'min_ff_event_warning' => 0,
'min_ff_event_critical' => 0,
'ff_type' => 0,
'each_ff' => 0,
'ip_target' => '',
'configuration_data' => '',
'history_data' => 1,
];
enterprise_include_once('include/functions_policies.php');
foreach ($id_target as $policy) {
$ids[] = policies_create_module($oid['oid'], $policy, 2, $values);
}
}
}
if (isset($ids) === true && is_array($ids) === true) {
foreach ($ids as $id) {
// Id < 0 for error codes.
if (!$id || $id < 0) {
array_push($fail_modules, $oid['oid']);
}
}
} else {
if (empty($id)) {
array_push($fail_modules, $oid['oid']);
}
}
}
return $fail_modules;
}
/**
* Prints html for create module from snmp massive dialog
*
* @param string $url_form
* @param string $title
* @param boolean $return
* @return void
*/
function snmp_browser_print_create_module_massive($target='agent', $snmp_conf, $return=false)
{
global $config;
// String for labels.
switch ($target) {
case 'agent':
$target_item = 'Agents';
break;
case 'policy':
$target_item = 'Policies';
break;
}
$output = "
';
$output .= '
';
$script = 'add_module_massive_controller("'.$target.'")';
// Add script to output.
$output .= '';
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints form from create snmp module dialog
*
* @param boolean $return
* @return void
*/
function snmp_browser_print_create_modules($return=false)
{
$output = "";
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->style = [];
$table->style[0] = 'font-weight: bolder;';
$table->data[0][0] = __('Agent');
$params['return'] = true;
$params['show_helptip'] = true;
$params['input_name'] = 'id_agent';
$params['selectbox_id'] = 'id_agent_module';
$params['metaconsole_enabled'] = false;
$params['hidden_input_idagent_name'] = 'id_agent_module';
$params['print_hidden_input_idagent'] = true;
$table->data[1][1] = ui_print_agent_autocomplete_input($params);
$output .= html_print_table($table, true);
$output .= '
';
if ($return) {
return $output;
}
echo $output;
}
function snmp_browser_print_create_policy()
{
$table = new stdClass();
$name = get_parameter('name');
$id_group = get_parameter('id_group');
$description = get_parameter('description');
$table->width = '100%';
$table->class = 'databox filters bold_top';
$table->style = [];
$table->data = [];
$table->data[0][0] = __('Name');
$table->data[0][1] = html_print_input_text('name', $name, '', '60%', 150, true);
$table->data[1][0] = __('Group');
$table->data[1][1] = '