';
}
$table->colspan[2][0] = 3;
$table->data[2] .= ui_toggle(
html_print_table(
$table3,
true
),
__('SNMP v3 settings'),
'',
'',
true,
true
);
$table->data[2] .= '
';
if ($toggle == true) {
$print_create_agent_module = 1;
} else {
$print_create_agent_module = 0;
}
$searchForm = '
';
if ($toggle == true) {
ui_toggle(
$searchForm,
'',
'filter_form',
'',
false,
false,
'',
'white-box-content',
'box-flat white_table_graph fixed_filter_bar'
);
}
// Search tools.
$table2 = new stdClass();
$table2->width = '100%';
$table2->class = 'databox filters';
$table2->size = [];
$table2->data = [];
$table2->data[0][0] = html_print_input_text(
'search_text',
'',
'',
25,
0,
true
);
$table2->data[0][0] .= '
';
$table2->cellstyle[0][1] = 'text-align:center;';
$table2->data[0][2] = ' ';
$table2->data[0][2] .= '
';
$output .= ui_toggle(
html_print_table($table2, true),
__('Search options'),
'',
'',
true,
true
);
$output .= '
';
if ($toggle === false) {
// This extra div that can be handled by jquery's dialog.
$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_browser_privacy_method']) === true) {
$snmp3_privacy_method = $snmp_values['snmp3_browser_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' => $snmp3_auth_user,
'plugin_pass' => $snmp3_auth_pass,
'plugin_parameter' => $snmp3_auth_method,
'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' => $snmp3_privacy_method,
'custom_string_2' => $snmp3_privacy_pass,
'custom_string_3' => $snmp3_security_level,
'post_process' => 0,
'unit' => '',
'wizard_level' => 'nowizard',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'percentage_warning' => 0,
'percentage_critical' => 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' => $snmp3_auth_user,
'plugin_pass' => $snmp3_auth_pass,
'plugin_parameter' => $snmp3_auth_method,
'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' => $snmp3_privacy_method,
'custom_string_2' => $snmp3_privacy_pass,
'custom_string_3' => $snmp3_security_level,
'post_process' => 0,
'unit' => '',
'wizard_level' => 'nowizard',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'percentage_warning' => 0,
'percentage_critical' => 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' => $snmp3_auth_user,
'plugin_pass' => $snmp3_auth_pass,
'plugin_parameter' => $snmp3_auth_method,
'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' => $snmp3_privacy_method,
'custom_string_2' => $snmp3_privacy_pass,
'custom_string_3' => $snmp3_security_level,
'post_process' => 0,
'unit' => '',
'macros' => '',
'critical_instructions' => '',
'warning_instructions' => '',
'unknown_instructions' => '',
'critical_inverse' => 0,
'warning_inverse' => 0,
'percentage_warning' => 0,
'percentage_critical' => 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 $target Target.
* @param string $snmp_conf Conf.
* @param boolean $return Type return.
*
* @return string Output html.
*/
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;
default:
// Not possible.
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 = 'filter-table-adv databox';
$table->style = [];
$table->data = [];
$table->size[0] = '100%';
$table->size[1] = '100%';
$table->size[2] = '100%';
$table->data[0][0] = html_print_label_input_block(
__('Name'),
html_print_input_text(
'name',
$name,
'',
'60%',
150,
true
)
);
$table->data[1][0] = html_print_label_input_block(
__('Group'),
'
'
);
$table->data[2][0] = html_print_label_input_block(
__('Description'),
html_print_textarea('description', 3, 30, $description, '', true)
);
$output = '