Merge branch 'ent-5312-SNMP-browser-enchancements' into 'develop'
Ent 5312 snmp browser enchancements See merge request artica/pandorafms!3049
This commit is contained in:
commit
72e09fdebf
|
@ -494,6 +494,25 @@ if ($id_agent_module) {
|
|||
|
||||
$module_macros = [];
|
||||
}
|
||||
|
||||
$create_network_from_snmp_browser = get_parameter('create_network_from_snmp_browser', 0);
|
||||
|
||||
if ($create_network_from_snmp_browser) {
|
||||
$moduletype = get_parameter('id_component_type', 2);
|
||||
$id_module_type = get_parameter('type', 1);
|
||||
$name = get_parameter('name', '');
|
||||
$description = get_parameter('description');
|
||||
$ip_target = get_parameter('target_ip');
|
||||
$snmp_community = get_parameter('community');
|
||||
$snmp_version = get_parameter('snmp_version');
|
||||
$snmp3_auth_user = get_parameter('snmp3_auth_user');
|
||||
$snmp3_auth_pass = get_parameter('snmp3_auth_pass');
|
||||
$snmp3_auth_method = get_parameter('snmp3_auth_method');
|
||||
$snmp3_privacy_method = get_parameter('snmp3_privacy_method');
|
||||
$snmp3_privacy_pass = get_parameter('snmp3_privacy_pass');
|
||||
$snmp3_security_level = get_parameter('snmp3_security_level');
|
||||
$snmp_oid = get_parameter('snmp_oid');
|
||||
}
|
||||
}
|
||||
|
||||
$is_function_policies = enterprise_include_once(
|
||||
|
|
|
@ -183,7 +183,7 @@ if ($id_module_type >= 15 && $id_module_type <= 18) {
|
|||
$data[3] = html_print_select(
|
||||
$snmp_versions,
|
||||
'snmp_version',
|
||||
$tcp_send,
|
||||
$snmp_version,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
|
@ -496,7 +496,7 @@ if ($id_module_type !== 34
|
|||
$table_simple->rowstyle['row-cmd-row-2'] = 'display: none;';
|
||||
}
|
||||
|
||||
snmp_browser_print_container(false, '100%', '60%', 'none');
|
||||
snmp_browser_print_container(false, '100%', '60%', 'display:none');
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -15,10 +15,13 @@ require_once $config['homedir'].'/include/functions_config.php';
|
|||
require_once $config['homedir'].'/include/functions_snmp_browser.php';
|
||||
require_once $config['homedir'].'/include/functions_network_components.php';
|
||||
|
||||
|
||||
global $config;
|
||||
|
||||
if (is_ajax()) {
|
||||
ob_clean();
|
||||
|
||||
$method = (string) get_parameter('method', '');
|
||||
$action = (string) get_parameter('action', '');
|
||||
$target_ip = (string) get_parameter('target_ip', '');
|
||||
$community = (string) get_parameter('community', '');
|
||||
|
@ -29,110 +32,200 @@ if (is_ajax()) {
|
|||
$snmp3_auth_pass = io_safe_output(get_parameter('snmp3_browser_auth_pass'));
|
||||
$snmp3_privacy_method = get_parameter('snmp3_browser_privacy_method');
|
||||
$snmp3_privacy_pass = io_safe_output(get_parameter('snmp3_browser_privacy_pass'));
|
||||
|
||||
$module_target = get_parameter('module_target', '');
|
||||
$targets_oids = get_parameter('oids', '');
|
||||
|
||||
$return_id = get_parameter('return_id', false);
|
||||
$custom_action = get_parameter('custom_action', '');
|
||||
|
||||
if (!is_array($targets_oids)) {
|
||||
$targets_oids = explode(',', $targets_oids);
|
||||
}
|
||||
|
||||
if ($custom_action != '') {
|
||||
$custom_action = urldecode(base64_decode($custom_action));
|
||||
}
|
||||
|
||||
if ($action == 'create_modules_snmp') {
|
||||
$fail_modules = [];
|
||||
foreach ($targets_oids as $key => $target_oid) {
|
||||
$oid = snmp_browser_get_oid(
|
||||
// SNMP browser.
|
||||
if ($action == 'snmptree') {
|
||||
$starting_oid = (string) get_parameter('starting_oid', '.');
|
||||
|
||||
|
||||
$snmp_tree = snmp_browser_get_tree(
|
||||
$target_ip,
|
||||
$community,
|
||||
htmlspecialchars_decode($target_oid),
|
||||
$starting_oid,
|
||||
$snmp_version,
|
||||
$snmp3_auth_user,
|
||||
$snmp3_security_level,
|
||||
$snmp3_auth_method,
|
||||
$snmp3_auth_pass,
|
||||
$snmp3_privacy_method,
|
||||
$snmp3_privacy_pass
|
||||
$snmp3_privacy_pass,
|
||||
$server_to_exec
|
||||
);
|
||||
if (! is_array($snmp_tree)) {
|
||||
echo $snmp_tree;
|
||||
} else {
|
||||
snmp_browser_print_tree(
|
||||
$snmp_tree,
|
||||
// Id.
|
||||
0,
|
||||
// Depth.
|
||||
0,
|
||||
// Last.
|
||||
0,
|
||||
// Last_array.
|
||||
[],
|
||||
// Sufix.
|
||||
false,
|
||||
// Checked.
|
||||
[],
|
||||
// Return.
|
||||
false,
|
||||
// Descriptive_ids.
|
||||
false,
|
||||
// Previous_id.
|
||||
''
|
||||
);
|
||||
|
||||
// Div for error/succes dialog.
|
||||
$output .= '<div id="snmp_result_msg" style="display:none"></div>';
|
||||
|
||||
$name_check = db_get_value(
|
||||
'name',
|
||||
'tnetwork_component',
|
||||
'name',
|
||||
$oid['oid']
|
||||
);
|
||||
// Dialog error.
|
||||
$output .= '<div id="dialog_error" style="display:none" title="'.__('SNMP modules').'">';
|
||||
$output .= '<div>';
|
||||
$output .= "<div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div>";
|
||||
$output .= "<div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3>";
|
||||
$output .= "<p style='font-family:Verdana; font-size:12pt;margin-bottom: 0px'>".__('Error creating the following modules:').'</p>';
|
||||
$output .= "<p id='error_text' style='font-family:Verdana; font-size:12pt;'></p>";
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
if (empty($oid['description'])) {
|
||||
$description = '';
|
||||
} else {
|
||||
$description = io_safe_input($oid['description']);
|
||||
}
|
||||
// Dialog success.
|
||||
$output .= '<div id="dialog_success" style="display: none" title="'.__('SNMP modules').'">';
|
||||
$output .= '<div>';
|
||||
$output .= "<div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_exito_mr.png'></div>";
|
||||
$output .= "<div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>SUCCESS</strong></h3>";
|
||||
$output .= "<p style='font-family:Verdana; font-size:12pt;'>".__('Modules successfully created').'</p>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
if (!$name_check) {
|
||||
$id = network_components_create_network_component(
|
||||
$oid['oid'],
|
||||
17,
|
||||
1,
|
||||
[
|
||||
'description' => $description,
|
||||
'module_interval' => 300,
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'tcp_send' => $snmp_version,
|
||||
'tcp_rcv' => '',
|
||||
'tcp_port' => 0,
|
||||
'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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
array_push($fail_modules, $name_check);
|
||||
}
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode($fail_modules);
|
||||
return;
|
||||
if ($action == 'snmpget') {
|
||||
// SNMP get.
|
||||
$target_oid = htmlspecialchars_decode(get_parameter('oid', ''));
|
||||
$custom_action = get_parameter('custom_action', '');
|
||||
if ($custom_action != '') {
|
||||
$custom_action = urldecode(base64_decode($custom_action));
|
||||
}
|
||||
|
||||
$oid = snmp_browser_get_oid(
|
||||
$target_ip,
|
||||
$community,
|
||||
$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
|
||||
);
|
||||
|
||||
snmp_browser_print_oid(
|
||||
$oid,
|
||||
$custom_action,
|
||||
false,
|
||||
$community,
|
||||
$snmp_version
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($method == 'snmp_browser_create_modules') {
|
||||
// Get target ids from form.
|
||||
$id_items = get_parameter('id_item2', null);
|
||||
if (!is_null($id_items)) {
|
||||
$id_target = explode(',', $id_items[0]);
|
||||
}
|
||||
|
||||
$snmp_extradata = get_parameter('snmp_extradata', '');
|
||||
|
||||
if (!is_array($snmp_extradata)) {
|
||||
// Decode SNMP values.
|
||||
$snmp_extradata = json_decode(io_safe_output($snmp_extradata), true);
|
||||
}
|
||||
|
||||
|
||||
foreach ($snmp_extradata as $snmp_conf) {
|
||||
$snmp_conf_values[$snmp_conf['name']] = $snmp_conf['value'];
|
||||
}
|
||||
|
||||
$fail_modules = snmp_browser_create_modules_snmp($module_target, $snmp_conf_values, $id_target);
|
||||
|
||||
// Return fail modules for error/success message.
|
||||
echo json_encode($fail_modules);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($method == 'snmp_browser_print_create_module_massive') {
|
||||
// Get SNMP conf vaues from modal onshow extradata.
|
||||
$snmp_extradata = get_parameter('extradata', '');
|
||||
|
||||
$return = snmp_browser_print_create_module_massive($module_target, $snmp_extradata, true);
|
||||
echo $return;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($method == 'snmp_browser_print_create_policy') {
|
||||
$return = snmp_browser_print_create_policy();
|
||||
echo $return;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($method == 'snmp_browser_create_policy') {
|
||||
enterprise_include_once('include/functions_policies.php');
|
||||
|
||||
$policy_name = get_parameter('name', '');
|
||||
$policy_id_group = get_parameter('id_group', 0);
|
||||
$policy_description = get_parameter('description', '');
|
||||
$values = [
|
||||
'id_group' => $policy_id_group,
|
||||
'description' => $policy_description,
|
||||
|
||||
];
|
||||
|
||||
// Check if policy exist.
|
||||
$policy_exists = policies_get_id($policy_name);
|
||||
if ($policy_exists != false) {
|
||||
$id_policy = 0;
|
||||
} else {
|
||||
$id_policy = (boolean) policies_create_policy($policy_name, $values);
|
||||
}
|
||||
|
||||
|
||||
$return = [
|
||||
'error' => (int) $id_policy,
|
||||
'title' => [
|
||||
__('Failed'),
|
||||
__('Success'),
|
||||
],
|
||||
'text' => [
|
||||
ui_print_error_message(__('Failed to create policy'), '', true),
|
||||
ui_print_success_message(__('Policy created succesfully'), '', true),
|
||||
],
|
||||
];
|
||||
|
||||
echo json_encode($return);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,28 +253,49 @@ function snmp_browser_get_tree(
|
|||
$snmp3_auth_method='',
|
||||
$snmp3_auth_pass='',
|
||||
$snmp3_privacy_method='',
|
||||
$snmp3_privacy_pass='',
|
||||
$server_to_exec=0
|
||||
$snmp3_privacy_pass=''
|
||||
) {
|
||||
global $config;
|
||||
|
||||
$output = get_snmpwalk(
|
||||
$target_ip,
|
||||
$version,
|
||||
$community,
|
||||
$snmp3_auth_user,
|
||||
$snmp3_security_level,
|
||||
$snmp3_auth_method,
|
||||
$snmp3_auth_pass,
|
||||
$snmp3_privacy_method,
|
||||
$snmp3_privacy_pass,
|
||||
0,
|
||||
$starting_oid,
|
||||
'',
|
||||
$server_to_exec,
|
||||
'',
|
||||
''
|
||||
);
|
||||
switch ($version) {
|
||||
case '1':
|
||||
$snmp_version = SNMP::VERSION_1;
|
||||
break;
|
||||
|
||||
case '2':
|
||||
$snmp_version = SNMP::VERSION_2c;
|
||||
break;
|
||||
|
||||
case '2c':
|
||||
$snmp_version = SNMP::VERSION_2C;
|
||||
break;
|
||||
|
||||
case '3':
|
||||
$snmp_version = SNMP::VERSION_3;
|
||||
$community = $snmp3_auth_user;
|
||||
break;
|
||||
|
||||
default:
|
||||
$snmp_version = SNMP::VERSION_2c;
|
||||
}
|
||||
|
||||
$snmp_session = new SNMP($snmp_version, $target_ip, $community);
|
||||
$snmp_session->oid_output_format = SNMP_OID_OUTPUT_MODULE;
|
||||
|
||||
// Set security if SNMP Version is 3.
|
||||
if ($snmp_version == SNMP::VERSION_3) {
|
||||
$snmp_session->setSecurity($snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass, $snmp3_privacy_method, $snmp3_privacy_pass);
|
||||
}
|
||||
|
||||
snmp_read_mib($config['homedir'].'/attachment/mibs');
|
||||
$output = $snmp_session->walk($starting_oid);
|
||||
if ($output == false) {
|
||||
$output = $snmp_session->getError();
|
||||
$snmp_session->close();
|
||||
return $output;
|
||||
}
|
||||
|
||||
$snmp_session->close();
|
||||
|
||||
// Build the tree.
|
||||
$oid_tree = ['__LEAVES__' => []];
|
||||
|
@ -556,8 +577,7 @@ function snmp_browser_print_oid(
|
|||
$output .= html_print_table($table, true);
|
||||
|
||||
$url = 'index.php?'.'sec=gmodules&'.'sec2=godmode/modules/manage_network_components';
|
||||
|
||||
$output .= '<form style="text-align: center; margin: 10px" method="post" action="'.$url.'">';
|
||||
$output .= '<form id="snmp_create_module" style="text-align: center; margin: 10px" method="post" action="'.$url.'">';
|
||||
$output .= html_print_input_hidden('create_network_from_snmp_browser', 1, true);
|
||||
$output .= html_print_input_hidden('id_component_type', 2, true);
|
||||
$output .= html_print_input_hidden('type', 17, true);
|
||||
|
@ -570,19 +590,35 @@ function snmp_browser_print_oid(
|
|||
$description = '';
|
||||
if (!empty($oid['description'])) {
|
||||
$description = $oid['description'];
|
||||
// Remove extra whitespaces.
|
||||
$description = preg_replace('/\s+/', ' ', $description);
|
||||
}
|
||||
|
||||
$output .= html_print_input_hidden('description', $description, true);
|
||||
$output .= html_print_input_hidden('snmp_oid', $oid['numeric_oid'], true);
|
||||
$output .= html_print_input_hidden('snmp_community', $community, true);
|
||||
$output .= html_print_input_hidden('snmp_version', $snmp_version, true);
|
||||
|
||||
// Create module buttons.
|
||||
$output .= html_print_submit_button(
|
||||
__('Create network component'),
|
||||
'',
|
||||
'create_network_component',
|
||||
false,
|
||||
'class="sub add"',
|
||||
true
|
||||
);
|
||||
|
||||
// Hidden by default.
|
||||
$output .= html_print_button(
|
||||
__('Create agent module'),
|
||||
'create_module_agent_single',
|
||||
false,
|
||||
'show_add_module()',
|
||||
'class="sub add" style="display:none"',
|
||||
true
|
||||
);
|
||||
|
||||
// Select agent modal.
|
||||
$output .= snmp_browser_print_create_modules(true);
|
||||
|
||||
$output .= '</form>';
|
||||
|
||||
if ($return) {
|
||||
|
@ -603,7 +639,7 @@ function snmp_browser_print_oid(
|
|||
*
|
||||
* @return string The container div.
|
||||
*/
|
||||
function snmp_browser_print_container($return=false, $width='100%', $height='60%', $display='')
|
||||
function snmp_browser_print_container($return=false, $width='100%', $height='60%', $display='', $show_massive_buttons=false)
|
||||
{
|
||||
// Target selection
|
||||
$table = new stdClass();
|
||||
|
@ -746,12 +782,13 @@ function snmp_browser_print_container($return=false, $width='100%', $height='60%
|
|||
$table2->data[0][2] .= ' '.'<a href="javascript:">'.html_print_image('images/collapse.png', true, ['title' => __('Collapse the tree'), 'style' => 'vertical-align: middle;', 'onclick' => 'collapseAll();']).'</a>';
|
||||
$table2->cellstyle[0][2] = 'text-align:center;';
|
||||
|
||||
// This extra div that can be handled by jquery's dialog
|
||||
// This extra div that can be handled by jquery's dialog.
|
||||
$output = '<div id="snmp_browser_container" style="display:'.$display.'">';
|
||||
$output .= '<div style="text-align: left; width: '.$width.'; height: '.$height.';">';
|
||||
$output .= '<div style="width: 100%">';
|
||||
$output .= html_print_table($table, true);
|
||||
$output .= '</div>';
|
||||
|
||||
if (!isset($snmp_version)) {
|
||||
$snmp_version = null;
|
||||
}
|
||||
|
@ -779,12 +816,45 @@ function snmp_browser_print_container($return=false, $width='100%', $height='60%
|
|||
|
||||
$output .= '<div id="search_results" style="display: none; padding: 5px; background-color: #EAEAEA; border: 1px solid #E2E2E2; border-radius: 4px;"></div>';
|
||||
$output .= '<div id="spinner" style="position: absolute; top:0; left:0px; display:none; padding: 5px;">'.html_print_image('images/spinner.gif', true).'</div>';
|
||||
$output .= '<div id="snmp_browser" style="height: 100%; min-height:100px; overflow: auto; background-color: #F4F5F4; border: 1px solid #E2E2E2; border-radius: 4px; padding: 5px;"></div>';
|
||||
$output .= '<div class="databox" id="snmp_data" style="margin: 5px;"></div>';
|
||||
$output .= '<div id="snmp_browser">';
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="databox" id="snmp_data" style="margin: 5px; display: none"></div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
if ($show_massive_buttons) {
|
||||
$output .= '<div id="snmp_create_buttons" style="display:none">';
|
||||
|
||||
$output .= html_print_submit_button(
|
||||
__('Create agent modules'),
|
||||
'create_modules_agent',
|
||||
false,
|
||||
['class' => 'sub add'],
|
||||
true
|
||||
);
|
||||
|
||||
if (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 .= '</div>';
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
}
|
||||
|
@ -793,141 +863,500 @@ function snmp_browser_print_container($return=false, $width='100%', $height='60%
|
|||
}
|
||||
|
||||
|
||||
?>
|
||||
/**
|
||||
* 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.
|
||||
* @return array $fail_modules
|
||||
*/
|
||||
function snmp_browser_create_modules_snmp(string $module_target, array $snmp_values, ?array $id_target)
|
||||
{
|
||||
if (is_array($snmp_values)) {
|
||||
$snmp_version = $snmp_values['snmp_browser_version'];
|
||||
$community = $snmp_values['community'];
|
||||
$target_ip = $snmp_values['target_ip'];
|
||||
$snmp3_auth_user = $snmp_values['snmp3_browser_auth_user'];
|
||||
$snmp3_security_level = $snmp_values['snmp3_browser_security_level'];
|
||||
$snmp3_auth_method = $snmp_values['snmp3_browser_auth_method'];
|
||||
$snmp3_auth_pass = $snmp_values['snmp3_browser_auth_pass'];
|
||||
$snmp3_privacy_method = $snmp_values['snmp3_privacy_method'];
|
||||
$snmp3_privacy_pass = $snmp_values['snmp3_browser_privacy_pass'];
|
||||
$targets_oids = $snmp_values['oids'];
|
||||
}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('input[name*=create_network_component]').click(function () {
|
||||
var id_check = $('#ul_0').find('input').map(function(){
|
||||
if(this.id.indexOf('checkbox-create_')!=-1){
|
||||
if($(this).is(':checked')){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
} }).get();
|
||||
$('input[name*=create_network_component]').removeClass("sub add");
|
||||
$('input[name*=create_network_component]').addClass("sub spinn");
|
||||
|
||||
var target_ip = $('#text-target_ip').val();
|
||||
var community = $('#text-community').val();
|
||||
var snmp_version = $('#snmp_browser_version').val();
|
||||
var snmp3_auth_user = $('#text-snmp3_browser_auth_user').val();
|
||||
var snmp3_security_level = $('#snmp3_browser_security_level').val();
|
||||
var snmp3_auth_method = $('#snmp3_browser_auth_method').val();
|
||||
var snmp3_auth_pass = $('#password-snmp3_browser_auth_pass').val();
|
||||
var snmp3_privacy_method = $('#snmp3_browser_privacy_method').val();
|
||||
var snmp3_privacy_pass = $('#password-snmp3_browser_privacy_pass').val();
|
||||
|
||||
var custom_action = $('#hidden-custom_action').val();
|
||||
if (custom_action == undefined) {
|
||||
custom_action = '';
|
||||
$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
|
||||
);
|
||||
|
||||
if (empty($oid['description'])) {
|
||||
$description = '';
|
||||
} else {
|
||||
// Delete extra spaces.
|
||||
$description = io_safe_input(preg_replace('/\s+/', ' ', $oid['description']));
|
||||
}
|
||||
|
||||
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'],
|
||||
17,
|
||||
1,
|
||||
[
|
||||
'description' => $description,
|
||||
'module_interval' => 300,
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'tcp_send' => $snmp_version,
|
||||
'tcp_rcv' => '',
|
||||
'tcp_port' => 0,
|
||||
'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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
var oids = [];
|
||||
id_check.forEach(function(product, index) {
|
||||
var oid = $("#"+product).siblings('a').attr('href');
|
||||
if(oid.indexOf('javascript: snmpGet("')!=-1) {
|
||||
oid = oid.replace('javascript: snmpGet("',"");
|
||||
oid = oid.replace('");',"");
|
||||
oids.push(oid);
|
||||
} else if ($module_target == 'agent') {
|
||||
$values = [
|
||||
'id_tipo_modulo' => 17,
|
||||
'descripcion' => $description,
|
||||
'module_interval' => 300,
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'tcp_send' => $snmp_version,
|
||||
'tcp_rcv' => '',
|
||||
'tcp_port' => 0,
|
||||
'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,
|
||||
];
|
||||
foreach ($id_target as $agent) {
|
||||
$ids[] = modules_create_agent_module($agent, $oid['oid'], $values);
|
||||
}
|
||||
|
||||
});
|
||||
// Prepare the AJAX call
|
||||
var params = {};
|
||||
params["target_ip"] = target_ip;
|
||||
params["community"] = community;
|
||||
params["oids"] = oids;
|
||||
params["snmp_browser_version"] = snmp_version;
|
||||
params["snmp3_browser_auth_user"] = snmp3_auth_user;
|
||||
params["snmp3_browser_security_level"] = snmp3_security_level;
|
||||
params["snmp3_browser_auth_method"] = snmp3_auth_method;
|
||||
params["snmp3_browser_auth_pass"] = snmp3_auth_pass;
|
||||
params["snmp3_browser_privacy_method"] = snmp3_privacy_method;
|
||||
params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass;
|
||||
params["action"] = "create_modules_snmp";
|
||||
params["custom_action"] = custom_action;
|
||||
params["page"] = "include/ajax/snmp_browser.ajax";
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "ajax.php",
|
||||
data: params,
|
||||
dataType: "html",
|
||||
success: function(data) {
|
||||
|
||||
var dato = data.replace(/[^]+(?=\[)/,"");
|
||||
$('input[name*=create_network_component]').removeClass("sub spinn");
|
||||
$('input[name*=create_network_component]').addClass("sub add");
|
||||
|
||||
dato = JSON.parse(dato);
|
||||
|
||||
if(dato.length !== 0){
|
||||
$('#error_text').text("");
|
||||
|
||||
dato.forEach( function(valor, indice, array) {
|
||||
$('#error_text').append('<br/>'+ valor );
|
||||
});
|
||||
$("#dialog_error")
|
||||
.dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 300,
|
||||
width: 500,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#dialog_success")
|
||||
.dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 250,
|
||||
width: 500,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} else if ($module_target == 'policy') {
|
||||
// Policies only in enterprise version.
|
||||
if (enterprise_installed()) {
|
||||
$values = [
|
||||
'id_tipo_modulo' => 17,
|
||||
'description' => $description,
|
||||
'module_interval' => 300,
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'tcp_send' => $snmp_version,
|
||||
'tcp_rcv' => '',
|
||||
'tcp_port' => 0,
|
||||
'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' => $target_ip,
|
||||
'configuration_data' => '',
|
||||
];
|
||||
|
||||
enterprise_include_once('include/functions_policies.php');
|
||||
foreach ($id_target as $policy) {
|
||||
$ids[] = policies_create_module($oid['oid'], $policy, 2, $values);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('input[id^=checkbox-create]').change(function () {
|
||||
if ($(this).is(':checked') ) {
|
||||
$('input[name*=create_network_component]').show();
|
||||
var id_input = $(this).attr("id");
|
||||
id_input = id_input.match("checkbox-create_([0-9]+)");
|
||||
var checks = $('#ul_'+id_input[1]).find('input').map(function(){
|
||||
if(this.id.indexOf('checkbox-create_')!=-1){
|
||||
return this.id;
|
||||
} }).get();
|
||||
|
||||
checks.forEach(function(product, index) {
|
||||
$("#"+product).prop('checked', "true");
|
||||
});
|
||||
|
||||
} else {
|
||||
var id_input = $(this).attr("id");
|
||||
|
||||
id_input = id_input.match("checkbox-create_([0-9]+)");
|
||||
var checks = $('#ul_'+id_input[1]).find('input').map(function(){
|
||||
if(this.id.indexOf('checkbox-create_')!=-1){
|
||||
return this.id;
|
||||
} }).get();
|
||||
|
||||
checks.forEach(function(product, index) {
|
||||
$("#"+product).prop('checked', false);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
}
|
||||
|
||||
if (is_array($ids)) {
|
||||
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)
|
||||
{
|
||||
// String for labels.
|
||||
switch ($target) {
|
||||
case 'agent':
|
||||
$target_item = 'Agents';
|
||||
break;
|
||||
|
||||
case 'policy':
|
||||
$target_item = 'Policies';
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= "<form target='_blank' id='create_module_massive' action='#' method='post'>";
|
||||
|
||||
$strict_user = db_get_value(
|
||||
'strict_acl',
|
||||
'tusuario',
|
||||
'id_user',
|
||||
$config['id_user']
|
||||
);
|
||||
|
||||
$keys_field = 'id_grupo';
|
||||
|
||||
$table = new stdClass();
|
||||
$table->width = '100%';
|
||||
$table->data = [];
|
||||
|
||||
$table->data[0][0] = __('Filter group')."<div id='loading_group' class='loading_div' style='display:none; float:left;'><img src='images/spinner.gif'></div>";
|
||||
|
||||
$table->data[0][1] = html_print_select_groups(
|
||||
false,
|
||||
'RR',
|
||||
users_can_manage_group_all('RR'),
|
||||
'group',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
'',
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
$keys_field,
|
||||
$strict_user
|
||||
);
|
||||
|
||||
$table->data[1][0] = __('Search')."<div id='loading_filter' class='loading_div' style='display:none; float:left;'><img src='images/spinner.gif'></div>";
|
||||
$table->data[1][1] = html_print_input_text(
|
||||
'filter',
|
||||
'',
|
||||
'',
|
||||
20,
|
||||
150,
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[2][0] = __($target_item.' available').html_print_input_image('select_all_left', 'images/tick.png', 1, '', true, ['title' => __('Select all')]);
|
||||
$table->data[2][1] = '';
|
||||
$table->data[2][2] = __($target_item.' to apply').html_print_input_image('select_all_right', 'images/tick.png', 1, '', true, ['title' => __('Select all')]);
|
||||
|
||||
$table->data[3][0] = html_print_select(
|
||||
[],
|
||||
'id_item[]',
|
||||
0,
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width: 100%;',
|
||||
[]
|
||||
);
|
||||
|
||||
if ($target == 'policy') {
|
||||
if (enterprise_installed()) {
|
||||
$table->data[4][0] = html_print_button(
|
||||
__('Create new policy'),
|
||||
'snmp_browser_create_policy',
|
||||
false,
|
||||
'',
|
||||
'class="sub add" style="margin-left:0px"',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
$table->data[4][1] = html_print_div(
|
||||
[
|
||||
'style' => 'display:none',
|
||||
'id' => 'policy_modal',
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
$table->cellstyle[3][1] = 'text-align: center';
|
||||
$table->data[3][1] = html_print_image(
|
||||
'images/darrowright.png',
|
||||
true,
|
||||
[
|
||||
'id' => 'right',
|
||||
'title' => __('Add'),
|
||||
]
|
||||
).'<br /><br /><br /><br />'.html_print_image(
|
||||
'images/darrowleft.png',
|
||||
true,
|
||||
[
|
||||
'id' => 'left',
|
||||
'title' => __('Undo'),
|
||||
]
|
||||
);
|
||||
$table->data[3][2] = html_print_select(
|
||||
[],
|
||||
'id_item2[]',
|
||||
0,
|
||||
false,
|
||||
'',
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width: 100%;',
|
||||
[]
|
||||
);
|
||||
|
||||
$output .= html_print_table($table, true);
|
||||
|
||||
// SNMP extradata.
|
||||
$output .= html_print_input_hidden('snmp_extradata', $snmp_conf, true);
|
||||
|
||||
$output .= '</form>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
$script = 'add_module_massive_controller("'.$target.'")';
|
||||
|
||||
// Add script to output.
|
||||
$output .= '<script>'.$script.'</script>';
|
||||
|
||||
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 = "<div id='dialog_create_module' style='display: none;' title='Select agent'>";
|
||||
|
||||
$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 .= '</div>';
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
echo $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function snmp_browser_print_create_policy()
|
||||
{
|
||||
$table = new stdClass();
|
||||
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox filters';
|
||||
$table->style = [];
|
||||
$table->style[0] = 'font-weight: bold; vertical-align: top';
|
||||
$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] = html_print_select_groups(
|
||||
false,
|
||||
'AW',
|
||||
false,
|
||||
'id_group',
|
||||
$id_group,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
true
|
||||
);
|
||||
$table->data[1][1] .= ' <span id="group_preview">';
|
||||
$table->data[1][1] .= ui_print_group_icon($id_group, true, 'groups_small', '', false);
|
||||
$table->data[1][1] .= '</span>';
|
||||
|
||||
$table->data[2][0] = __('Description');
|
||||
$table->data[2][1] = html_print_textarea('description', 3, 30, $description, '', true);
|
||||
|
||||
$output = '<form method="post" id="snmp_browser_add_policy_form">';
|
||||
$output .= html_print_table($table, true);
|
||||
$output .= '</form>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ function snmpBrowse() {
|
|||
params["snmp3_browser_privacy_method"] = snmp3_privacy_method;
|
||||
params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass;
|
||||
params["action"] = "snmptree";
|
||||
params["page"] = "operation/snmpconsole/snmp_browser";
|
||||
params["page"] = "include/ajax/snmp_browser.ajax";
|
||||
|
||||
// Browse!
|
||||
jQuery.ajax({
|
||||
|
@ -57,6 +57,63 @@ function snmpBrowse() {
|
|||
|
||||
// Load the SNMP tree
|
||||
$("#snmp_browser").html(data);
|
||||
|
||||
// Manage click and select events.
|
||||
snmp_browser_events_manage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function snmp_browser_events_manage() {
|
||||
// Hide create buttons.
|
||||
$("#snmp_create_buttons").hide();
|
||||
|
||||
$("input[id^=checkbox-create]").change(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
$("#snmp_create_buttons").show();
|
||||
var id_input = $(this).attr("id");
|
||||
id_input = id_input.match("checkbox-create_([0-9]+)");
|
||||
var checks = $("#ul_" + id_input[1])
|
||||
.find("input")
|
||||
.map(function() {
|
||||
if (this.id.indexOf("checkbox-create_") != -1) {
|
||||
return this.id;
|
||||
}
|
||||
})
|
||||
.get();
|
||||
|
||||
checks.forEach(function(product, index) {
|
||||
$("#" + product).prop("checked", "true");
|
||||
});
|
||||
} else {
|
||||
var id_input = $(this).attr("id");
|
||||
|
||||
id_input = id_input.match("checkbox-create_([0-9]+)");
|
||||
var checks = $("#ul_" + id_input[1])
|
||||
.find("input")
|
||||
.map(function() {
|
||||
if (this.id.indexOf("checkbox-create_") != -1) {
|
||||
return this.id;
|
||||
}
|
||||
})
|
||||
.get();
|
||||
|
||||
checks.forEach(function(product, index) {
|
||||
$("#" + product).prop("checked", false);
|
||||
});
|
||||
}
|
||||
|
||||
// Hide buttons if no ckbox is checked.
|
||||
var checked = false;
|
||||
$("input[id^=checkbox-create]").each(function() {
|
||||
checked = $(this).is(":checked");
|
||||
if (checked == true) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (checked == false) {
|
||||
$("#snmp_create_buttons").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -187,7 +244,7 @@ function snmpGet(oid) {
|
|||
"server_to_exec=" + server_to_exec,
|
||||
"action=" + "snmpget",
|
||||
"custom_action=" + custom_action,
|
||||
"page=operation/snmpconsole/snmp_browser"
|
||||
"page=include/ajax/snmp_browser.ajax"
|
||||
];
|
||||
|
||||
// SNMP get!
|
||||
|
@ -224,7 +281,7 @@ function hideOIDData() {
|
|||
// Search the SNMP tree for a matching string
|
||||
function searchText() {
|
||||
var text = $("#text-search_text").val();
|
||||
var regexp = new RegExp(text);
|
||||
var regexp = new RegExp(text, "i");
|
||||
var search_matches_translation = $(
|
||||
"#hidden-search_matches_translation"
|
||||
).val();
|
||||
|
@ -348,6 +405,7 @@ function searchNextMatch() {
|
|||
var id = $(".match:eq(" + search_index + ")").attr("id");
|
||||
|
||||
// Scroll
|
||||
var body = $("html, body");
|
||||
$("#snmp_browser").animate(
|
||||
{
|
||||
scrollTop:
|
||||
|
@ -355,7 +413,16 @@ function searchNextMatch() {
|
|||
$("#" + id).offset().top -
|
||||
$("#snmp_browser").offset().top
|
||||
},
|
||||
1000
|
||||
1000,
|
||||
function() {
|
||||
// Blink.
|
||||
$("#" + id)
|
||||
.fadeOut(100)
|
||||
.fadeIn(100)
|
||||
.fadeOut(100)
|
||||
.fadeIn(100)
|
||||
.focus();
|
||||
}
|
||||
);
|
||||
|
||||
// Save the search index
|
||||
|
@ -384,7 +451,16 @@ function searchPrevMatch() {
|
|||
$("#" + id).offset().top -
|
||||
$("#snmp_browser").offset().top
|
||||
},
|
||||
1000
|
||||
1000,
|
||||
function() {
|
||||
// Blink.
|
||||
$("#" + id)
|
||||
.fadeOut(100)
|
||||
.fadeIn(100)
|
||||
.fadeOut(100)
|
||||
.fadeIn(100)
|
||||
.focus();
|
||||
}
|
||||
);
|
||||
|
||||
// Save the search index
|
||||
|
@ -464,3 +540,99 @@ function setOID() {
|
|||
// Close the SNMP browser
|
||||
$(".ui-dialog-titlebar-close").trigger("click");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create module on selected module_target (agent, networlk component or policy).
|
||||
*
|
||||
* @param string module_target Target to create module.
|
||||
* @param return_values Return snmp values.
|
||||
*/
|
||||
function snmp_browser_create_modules(module_target, return_post = true) {
|
||||
var id_check = $("#ul_0")
|
||||
.find("input")
|
||||
.map(function() {
|
||||
if (this.id.indexOf("checkbox-create_") != -1) {
|
||||
if ($(this).is(":checked")) {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
})
|
||||
.get();
|
||||
|
||||
var target_ip = $("#text-target_ip").val();
|
||||
var community = $("#text-community").val();
|
||||
var snmp_version = $("#snmp_browser_version").val();
|
||||
var snmp3_auth_user = $("#text-snmp3_browser_auth_user").val();
|
||||
var snmp3_security_level = $("#snmp3_browser_security_level").val();
|
||||
var snmp3_auth_method = $("#snmp3_browser_auth_method").val();
|
||||
var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val();
|
||||
var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val();
|
||||
var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val();
|
||||
|
||||
var custom_action = $("#hidden-custom_action").val();
|
||||
if (custom_action == undefined) {
|
||||
custom_action = "";
|
||||
}
|
||||
|
||||
var oids = [];
|
||||
id_check.forEach(function(product, index) {
|
||||
var oid = $("#" + product)
|
||||
.siblings("a")
|
||||
.attr("href");
|
||||
if (oid.indexOf('javascript: snmpGet("') != -1) {
|
||||
oid = oid.replace('javascript: snmpGet("', "");
|
||||
oid = oid.replace('");', "");
|
||||
oids.push(oid);
|
||||
}
|
||||
});
|
||||
|
||||
var snmp_conf = {};
|
||||
|
||||
snmp_conf["target_ip"] = target_ip;
|
||||
snmp_conf["community"] = community;
|
||||
snmp_conf["oids"] = oids;
|
||||
snmp_conf["snmp_browser_version"] = snmp_version;
|
||||
snmp_conf["snmp3_browser_auth_user"] = snmp3_auth_user;
|
||||
snmp_conf["snmp3_browser_security_level"] = snmp3_security_level;
|
||||
snmp_conf["snmp3_browser_auth_method"] = snmp3_auth_method;
|
||||
snmp_conf["snmp3_browser_auth_pass"] = snmp3_auth_pass;
|
||||
snmp_conf["snmp3_browser_privacy_method"] = snmp3_privacy_method;
|
||||
snmp_conf["snmp3_browser_privacy_pass"] = snmp3_privacy_pass;
|
||||
snmp_conf["module_target"] = module_target;
|
||||
snmp_conf["custom_action"] = custom_action;
|
||||
|
||||
var snmp_data = [];
|
||||
|
||||
for (var snmp_data_name in snmp_conf) {
|
||||
snmp_data.push({
|
||||
name: snmp_data_name,
|
||||
value: snmp_conf[snmp_data_name]
|
||||
});
|
||||
}
|
||||
|
||||
if (return_post) {
|
||||
return snmp_data;
|
||||
} else {
|
||||
var params = {};
|
||||
|
||||
params["method"] = "snmp_browser_create_modules";
|
||||
params["module_target"] = module_target;
|
||||
params["page"] = "include/ajax/snmp_browser.ajax";
|
||||
params["snmp_extradata"] = snmp_data;
|
||||
|
||||
$("input[name=create_modules_" + module_target + "]").removeClass(
|
||||
"sub add"
|
||||
);
|
||||
$("input[name=create_modules_" + module_target + "]").addClass("sub spinn");
|
||||
|
||||
$.ajax({
|
||||
method: "post",
|
||||
url: "ajax.php",
|
||||
data: params,
|
||||
dataType: "html",
|
||||
success: function(data) {
|
||||
snmp_show_result_message(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -730,6 +730,7 @@ input.sub {
|
|||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
padding-left: 15px;
|
||||
margin-left: 10px;
|
||||
border: 1px solid #888;
|
||||
font-family: "lato", "Open Sans", sans-serif;
|
||||
cursor: pointer;
|
||||
|
@ -4300,6 +4301,33 @@ form ul.form_flex li ul li {
|
|||
border: 0px;
|
||||
}
|
||||
|
||||
#snmp_browser {
|
||||
text-align: left;
|
||||
font-family: "lato-lighter", "Open Sans", sans-serif;
|
||||
letter-spacing: 0.03pt;
|
||||
font-size: 8pt;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
min-height: 100px;
|
||||
max-height: 500px;
|
||||
overflow: auto;
|
||||
background-color: #f4f5f4;
|
||||
border: 1px solid #e2e2e2;
|
||||
border-radius: 4px;
|
||||
padding: 5px;
|
||||
}
|
||||
#snmp_create_buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
#snmp_create_buttons > .sub {
|
||||
display: flex;
|
||||
margin-left: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* library for graphs */
|
||||
.yAxis.y1Axis > .tickLabel {
|
||||
white-space: nowrap;
|
||||
|
|
|
@ -30,140 +30,14 @@
|
|||
global $config;
|
||||
require_once $config['homedir'].'/include/functions_snmp_browser.php';
|
||||
ui_require_javascript_file('pandora_snmp_browser');
|
||||
|
||||
// AJAX call.
|
||||
if (is_ajax()) {
|
||||
// Read the action to perform.
|
||||
$action = (string) get_parameter('action', '');
|
||||
$target_ip = (string) get_parameter('target_ip', '');
|
||||
$community = (string) get_parameter('community', '');
|
||||
$snmp_version = (string) get_parameter('snmp_browser_version', '');
|
||||
$server_to_exec = (int) get_parameter('server_to_exec', 0);
|
||||
$snmp3_auth_user = io_safe_output(get_parameter('snmp3_browser_auth_user'));
|
||||
$snmp3_security_level = get_parameter('snmp3_browser_security_level');
|
||||
$snmp3_auth_method = get_parameter('snmp3_browser_auth_method');
|
||||
$snmp3_auth_pass = io_safe_output(get_parameter('snmp3_browser_auth_pass'));
|
||||
$snmp3_privacy_method = get_parameter('snmp3_browser_privacy_method');
|
||||
$snmp3_privacy_pass = io_safe_output(
|
||||
get_parameter('snmp3_browser_privacy_pass')
|
||||
);
|
||||
|
||||
// SNMP browser.
|
||||
if ($action == 'snmptree') {
|
||||
$starting_oid = (string) get_parameter('starting_oid', '.');
|
||||
|
||||
$snmp_tree = snmp_browser_get_tree(
|
||||
$target_ip,
|
||||
$community,
|
||||
$starting_oid,
|
||||
$snmp_version,
|
||||
$snmp3_auth_user,
|
||||
$snmp3_security_level,
|
||||
$snmp3_auth_method,
|
||||
$snmp3_auth_pass,
|
||||
$snmp3_privacy_method,
|
||||
$snmp3_privacy_pass,
|
||||
$server_to_exec
|
||||
);
|
||||
if (! is_array($snmp_tree)) {
|
||||
echo $snmp_tree;
|
||||
} else {
|
||||
snmp_browser_print_tree(
|
||||
$snmp_tree,
|
||||
// Id.
|
||||
0,
|
||||
// Depth.
|
||||
0,
|
||||
// Last.
|
||||
0,
|
||||
// Last_array.
|
||||
[],
|
||||
// Sufix.
|
||||
false,
|
||||
// Checked.
|
||||
[],
|
||||
// Return.
|
||||
false,
|
||||
// Descriptive_ids.
|
||||
false,
|
||||
// Previous_id.
|
||||
''
|
||||
);
|
||||
echo html_print_submit_button(
|
||||
__('Create network components'),
|
||||
'create_network_component',
|
||||
false,
|
||||
[
|
||||
'style' => 'display: none; position: absolute; bottom: 0px; right: 35px;',
|
||||
'class' => 'sub add',
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
echo '<div id="dialog_error" style="display: none" title="Network components">';
|
||||
echo '<div>';
|
||||
echo "<div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_error_mr.png'></div>";
|
||||
echo "<div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>ERROR</strong></h3>";
|
||||
echo "<p style='font-family:Verdana; font-size:12pt;margin-bottom: 0px'>".__('Error creating the following modules:').'</p>';
|
||||
echo "<p id='error_text' style='font-family:Verdana; font-size:12pt;'></p>";
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
|
||||
echo '<div id="dialog_success" style="display: none" title="Network components">';
|
||||
echo '<div>';
|
||||
echo "<div style='width:25%; float:left'><img style='padding-left:20px; padding-top:20px;' src='images/icono_exito_mr.png'></div>";
|
||||
echo "<div style='width:75%; float:left;'><h3><strong style='font-family:Verdana; font-size:13pt;'>SUCCESS</strong></h3>";
|
||||
echo "<p style='font-family:Verdana; font-size:12pt;'>".__('Modules successfully created').'</p>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
return;
|
||||
} else if ($action == 'snmpget') {
|
||||
// SNMP get.
|
||||
$target_oid = htmlspecialchars_decode(get_parameter('oid', ''));
|
||||
$custom_action = get_parameter('custom_action', '');
|
||||
if ($custom_action != '') {
|
||||
$custom_action = urldecode(base64_decode($custom_action));
|
||||
}
|
||||
|
||||
$oid = snmp_browser_get_oid(
|
||||
$target_ip,
|
||||
$community,
|
||||
$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
|
||||
);
|
||||
|
||||
snmp_browser_print_oid(
|
||||
$oid,
|
||||
$custom_action,
|
||||
false,
|
||||
$community,
|
||||
$snmp_version
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
ui_require_jquery_file('pandora.controls');
|
||||
|
||||
// Check login and ACLs.
|
||||
check_login();
|
||||
if (! check_acl($config['id_user'], 0, 'AR')) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access SNMP Console'
|
||||
);
|
||||
if (!check_acl($config['id_user'], 0, 'AR')) {
|
||||
db_pandora_audit('ACL Violation', 'Trying to access SNMP Console');
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
exit();
|
||||
}
|
||||
|
||||
// Header.
|
||||
|
@ -174,7 +48,9 @@ if ($config['pure']) {
|
|||
$link['text'] .= html_print_image(
|
||||
'images/normal_screen.png',
|
||||
true,
|
||||
['title' => __('Normal screen')]
|
||||
[
|
||||
'title' => __('Normal screen'),
|
||||
]
|
||||
);
|
||||
$link['text'] .= '</a>';
|
||||
} else {
|
||||
|
@ -183,7 +59,9 @@ if ($config['pure']) {
|
|||
$link['text'] .= html_print_image(
|
||||
'images/full_screen.png',
|
||||
true,
|
||||
['title' => __('Full screen')]
|
||||
[
|
||||
'title' => __('Full screen'),
|
||||
]
|
||||
);
|
||||
$link['text'] .= '</a>';
|
||||
}
|
||||
|
@ -198,4 +76,556 @@ ui_print_page_header(
|
|||
);
|
||||
|
||||
// SNMP tree container.
|
||||
snmp_browser_print_container();
|
||||
snmp_browser_print_container(false, '100%', '60%', '', true);
|
||||
|
||||
// Div for modal
|
||||
echo '<div id="modal" style="display:none"></div>';
|
||||
// Div for loading modal.
|
||||
echo '<div id="loading_modal" style="display:none"></div>';
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
// Show button for add module to agent on oid detail.
|
||||
$(document).on('DOMSubtreeModified', "#snmp_create_module", function() {
|
||||
$('#button-create_module_agent_single').show();
|
||||
|
||||
});
|
||||
|
||||
$(document).on("click", 'div#snmp_create_buttons > input', function (event) {
|
||||
var source_button = this.name;
|
||||
var target = "";
|
||||
|
||||
switch (source_button) {
|
||||
case "create_modules_agent":
|
||||
target = "agent";
|
||||
break;
|
||||
|
||||
case "create_modules_policy":
|
||||
target = "policy";
|
||||
break;
|
||||
|
||||
case "create_modules_network_component":
|
||||
target = "network_component";
|
||||
break;
|
||||
|
||||
default:
|
||||
target = "network_component";
|
||||
break;
|
||||
}
|
||||
|
||||
if (target === "network_component") {
|
||||
waiting_modal();
|
||||
snmp_browser_create_modules("network_component", false);
|
||||
} else {
|
||||
snmp_browser_show_add_module_massive(target);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* Show select to add massive snmp modules.
|
||||
*
|
||||
* @param {string} target The target where module will be created (agent/policy).
|
||||
*/
|
||||
function snmp_browser_show_add_module_massive(module_target = 'agent') {
|
||||
|
||||
|
||||
var module_target = module_target;
|
||||
|
||||
var title = '<?php echo __('Add modules'); ?>';
|
||||
var snmp_extradata = snmp_browser_create_modules(module_target);
|
||||
// Load dinamically modal form.
|
||||
load_modal({
|
||||
target: $('#modal'),
|
||||
form: 'snmp_browser_add_module_form',
|
||||
extradata: [
|
||||
{
|
||||
name: 'module_target',
|
||||
value: module_target,
|
||||
},
|
||||
],
|
||||
ajax_callback: snmp_show_result_message,
|
||||
cleanup: cleanupDOM,
|
||||
onsubmitClose: true,
|
||||
form: 'create_module_massive',
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
modal: {
|
||||
title: title,
|
||||
cancel: '<?php echo __('Cancel'); ?>',
|
||||
ok: '<?php echo __('Add modules'); ?>',
|
||||
},
|
||||
onload: function (data) {
|
||||
// Add policy button handler.
|
||||
if (module_target == 'policy') {
|
||||
$('#button-snmp_browser_create_policy').click(function () {
|
||||
snmp_browser_show_add_policy();
|
||||
});
|
||||
}
|
||||
},
|
||||
onshow: {
|
||||
extradata: snmp_extradata,
|
||||
page: 'include/ajax/snmp_browser.ajax',
|
||||
method: 'snmp_browser_print_create_module_massive',
|
||||
},
|
||||
onsubmit: {
|
||||
preaction: modal_preaction,
|
||||
page: 'include/ajax/snmp_browser.ajax',
|
||||
method: 'snmp_browser_create_modules',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all items in select box.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function modal_preaction() {
|
||||
|
||||
// Select all in select box.
|
||||
$("input[name='select_all_right']").click();
|
||||
|
||||
// Load adding modules modal.
|
||||
waiting_modal();
|
||||
|
||||
}
|
||||
|
||||
function waiting_modal(stop = false) {
|
||||
|
||||
|
||||
var waiting_modal =
|
||||
'<div id="loading_in_progress_dialog" style="text-align: center;">' +
|
||||
'<?php echo __('Adding modules in progress'); ?> <br /><br />' +
|
||||
'<?php echo html_print_image('images/spinner.gif', true); ?> </div>';
|
||||
|
||||
$('#loading_modal').html(waiting_modal);
|
||||
|
||||
$('#loading_modal')
|
||||
.dialog({
|
||||
title: '<?php echo __('Action in progress'); ?>',
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
close: false,
|
||||
height: 100,
|
||||
width: 200,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
||||
if(stop) {
|
||||
$('#loading_modal').dialog("close");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show error/success message.
|
||||
*
|
||||
* @param mixed data Fail modules.
|
||||
*/
|
||||
function snmp_show_result_message(data) {
|
||||
|
||||
// Stop waiting modal.
|
||||
waiting_modal(stop);
|
||||
|
||||
var dato = data.replace(/[^]+(?=\[)/, "");
|
||||
|
||||
dato = JSON.parse(dato);
|
||||
if (dato.length !== 0) {
|
||||
$("#error_text").text("");
|
||||
|
||||
dato.forEach(function (valor, indice, array) {
|
||||
$("#error_text").append("<br/>" + valor);
|
||||
});
|
||||
$("#dialog_error").dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 300,
|
||||
width: 500,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#dialog_success").dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 250,
|
||||
width: 500,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* When invoking modals from JS, some DOM id could be repeated.
|
||||
* This method cleans DOM to avoid duplicated IDs.
|
||||
*/
|
||||
function cleanupDOM() {
|
||||
$("#modal").empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls internal add module massive dialog behaviour.
|
||||
*
|
||||
* @param string $target
|
||||
* @return void
|
||||
*/
|
||||
function add_module_massive_controller(target = 'agent')
|
||||
{
|
||||
// Load items from groups.
|
||||
filter_by_group($("#group").val(), '', target);
|
||||
|
||||
// Change group listener.
|
||||
$("select[name='group']").change(function(){
|
||||
filter_by_group($(this).val(), '', target);
|
||||
});
|
||||
|
||||
// Item filter search listener
|
||||
$("#text-filter").keyup (function () {
|
||||
|
||||
$('#loading_filter').show();
|
||||
refresh_item($(this).val(), items_out_keys, items_out, $("#id_item"));
|
||||
});
|
||||
|
||||
// Select all Items.
|
||||
$("input[name='select_all_left']").click(function () {
|
||||
$('#id_item option').map(function() {
|
||||
$(this).prop('selected', true);
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
$("input[name='select_all_right']").click(function () {
|
||||
$('#id_item2 option').map(function() {
|
||||
$(this).prop('selected', true);
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Select items.
|
||||
$("#right").click (function () {
|
||||
jQuery.each($("select[name='id_item[]'] option:selected"), function (key, value) {
|
||||
|
||||
item_name = $(value).html();
|
||||
if (item_name != <?php echo "'".__('None')."'"; ?>){
|
||||
id_item = $(value).attr('value');
|
||||
|
||||
//Remove the none value
|
||||
$("#id_item2").find("option[value='']").remove();
|
||||
|
||||
$("select[name='id_item2[]']").append($("<option>").val(id_item).html('<i>' + item_name + '</i>'));
|
||||
$("#id_item").find("option[value='" + id_item + "']").remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#left").click(function() {
|
||||
jQuery.each($("select[name='id_item2[]'] option:selected"), function (key, value) {
|
||||
item_name = $(value).html();
|
||||
if (item_name != <?php echo "'".__('None')."'"; ?>){
|
||||
id_item = $(value).attr('value');
|
||||
$("select[name='id_item[]']").append($("<option>").val(id_item).html('<i>' + item_name + '</i>'));
|
||||
$("#id_item2").find("option[value='" + id_item + "']").remove();
|
||||
}
|
||||
|
||||
//If empty the selectbox
|
||||
if ($("#id_item2 option").length == 0) {
|
||||
$("select[name='id_item2[]']")
|
||||
.append($("<option>").val("")
|
||||
.html("<?php echo __('None'); ?>"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agents by group dinamically..
|
||||
*
|
||||
* @param {number} id_group
|
||||
* @param {string} id_select
|
||||
* @param {string} module_target
|
||||
*/
|
||||
function filter_by_group(id_group, id_select, module_target) {
|
||||
$('#loading_group').show();
|
||||
|
||||
|
||||
var params = {};
|
||||
|
||||
$('#id_item' + id_select).empty ();
|
||||
search = $("#text-filter" + id_select).val();
|
||||
|
||||
params["id_group"] = id_group;
|
||||
params["search"]= search;
|
||||
|
||||
switch (module_target) {
|
||||
case 'agent':
|
||||
page = "godmode/groups/group_list";
|
||||
method = 'get_group_agents';
|
||||
break;
|
||||
case 'policy':
|
||||
page = "enterprise/include/ajax/policy.ajax";
|
||||
method = 'get_policies_by_group';
|
||||
break;
|
||||
|
||||
default:
|
||||
page = '';
|
||||
method = '';
|
||||
break;
|
||||
}
|
||||
|
||||
params['page'] = page;
|
||||
if(method != '') {
|
||||
params[method] = 1;
|
||||
}
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
dataType: "json",
|
||||
success: function (data, status) {
|
||||
|
||||
var group_items = new Array();
|
||||
var group_items_keys = new Array();
|
||||
|
||||
jQuery.each (data, function (id, value) {
|
||||
|
||||
group_items.push(value);
|
||||
group_items_keys.push(id);
|
||||
});
|
||||
|
||||
if(id_select == '') {
|
||||
items_out_keys = group_items_keys;
|
||||
items_out = group_items;
|
||||
}
|
||||
else {
|
||||
items_in_keys = group_items_keys;
|
||||
items_in = group_agents;
|
||||
}
|
||||
|
||||
refresh_item($("#text-filter"+id_select).attr('value'), items_out_keys, items_out, $("#id_item"+id_select));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function refresh_item(start_search, keys, values, select) {
|
||||
var n = 0;
|
||||
var i = 0;
|
||||
select.empty();
|
||||
|
||||
$('#id_item2 option').each(function(){
|
||||
|
||||
var out_agent = $(this).val();
|
||||
|
||||
if (out_agent) {
|
||||
|
||||
keys.forEach(function(it) {
|
||||
|
||||
var it_data = it;
|
||||
|
||||
if (it_data == out_agent) {
|
||||
|
||||
var index = keys.indexOf(it);
|
||||
|
||||
// Remove from array!
|
||||
values.splice(index, 1);
|
||||
keys.splice(index, 1);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
values.forEach(function(item) {
|
||||
var re = new RegExp(start_search,"gi");
|
||||
match = item.match(re);
|
||||
|
||||
if (match != null) {
|
||||
select.append ($("<option></option>").attr("value", keys[n]).html(values[n]));
|
||||
i++;
|
||||
}
|
||||
n++;
|
||||
});
|
||||
if (i == 0) {
|
||||
$(select).empty ();
|
||||
$(select).append ($("<option></option>").attr ("value", 0).html (' <?php echo __('None'); ?> '));
|
||||
}
|
||||
|
||||
$('.loading_div').hide();
|
||||
}
|
||||
|
||||
function snmp_browser_show_add_policy() {
|
||||
|
||||
var title = '<?php __('Create new policy'); ?>';
|
||||
|
||||
load_modal({
|
||||
target: $('#policy_modal'),
|
||||
form: 'snmp_browser_add_policy_form',
|
||||
ajax_callback: snmp_browser_add_policy_callback,
|
||||
idMsgCallback: 'snmp_result_msg',
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
modal: {
|
||||
title: title,
|
||||
cancel: '<?php echo __('Cancel'); ?>',
|
||||
ok: '<?php echo __('Create policy'); ?>',
|
||||
},
|
||||
onshow: {
|
||||
page: 'include/ajax/snmp_browser.ajax',
|
||||
method: 'snmp_browser_print_create_policy',
|
||||
width: 550,
|
||||
|
||||
},
|
||||
onsubmit: {
|
||||
page: 'include/ajax/snmp_browser.ajax',
|
||||
method: 'snmp_browser_create_policy',
|
||||
},
|
||||
onload: function () {
|
||||
$('#id_group').pandoraSelectGroupIcon();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function snmp_browser_add_policy_callback(data, idMsg) {
|
||||
|
||||
data = JSON.parse(data);
|
||||
|
||||
//Show message
|
||||
var title = data.title[data.error];
|
||||
var text = data.text[data.error];
|
||||
var failed = !data.error;
|
||||
|
||||
$("#" + idMsg).empty();
|
||||
$("#" + idMsg).html(text);
|
||||
$("#" + idMsg).dialog({
|
||||
width: 450,
|
||||
position: {
|
||||
my: "center",
|
||||
at: "center",
|
||||
of: window,
|
||||
collision: "fit"
|
||||
},
|
||||
title: title,
|
||||
buttons: [
|
||||
{
|
||||
class:
|
||||
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
||||
text: "OK",
|
||||
click: function(e) {
|
||||
if (!failed) {
|
||||
filter_by_group($("#group").val(), '', 'policy');
|
||||
}
|
||||
|
||||
$(this).dialog("close");
|
||||
$('#policy_modal').dialog("close");
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows dialog to select agent to add module.
|
||||
*
|
||||
*/
|
||||
function show_add_module() {
|
||||
|
||||
var id_agent = 0;
|
||||
var id_module = 0;
|
||||
|
||||
$("#dialog_create_module").dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
width: '300',
|
||||
height:'auto',
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
},
|
||||
buttons:
|
||||
[
|
||||
{
|
||||
class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel",
|
||||
text: '<?php echo __('Cancel'); ?>',
|
||||
click: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
||||
text: '<?php echo __('Create module'); ?>',
|
||||
click: function(e) {
|
||||
|
||||
confirmDialog({
|
||||
title: '<?php echo __('Are you sure?'); ?>',
|
||||
message: '<?php echo __('Are you sure you want add module?'); ?> ',
|
||||
ok: '<?php echo __('OK'); ?>',
|
||||
cancel: '<?php echo __('Cancel'); ?>',
|
||||
onAccept: function() {
|
||||
|
||||
// Get id agent and add it to form.
|
||||
id_agent = $('#hidden-id_agent').val();
|
||||
|
||||
// Get SNMP target.
|
||||
var snmp_target = {
|
||||
|
||||
target_ip : $('#text-target_ip').val(),
|
||||
community : $('#text-community').val(),
|
||||
snmp_version : $('#snmp_browser_version').val(),
|
||||
snmp3_auth_user : $('#text-snmp3_browser_auth_user').val(),
|
||||
snmp3_security_level : $('#snmp3_browser_security_level').val(),
|
||||
snmp3_auth_method : $('#snmp3_browser_auth_method').val(),
|
||||
snmp3_auth_pass : $('#password-snmp3_browser_auth_pass').val(),
|
||||
snmp3_privacy_method : $('#snmp3_browser_privacy_method').val(),
|
||||
snmp3_privacy_pass : $('#password-snmp3_browser_privacy_pass').val(),
|
||||
|
||||
};
|
||||
|
||||
// Append values to form.
|
||||
var input = "";
|
||||
|
||||
$.each( snmp_target, function( key, val ) {
|
||||
input = $("<input>")
|
||||
.attr("type", "hidden")
|
||||
.attr("name", key).val(val);
|
||||
|
||||
$("#snmp_create_module").append(input);
|
||||
});
|
||||
|
||||
//Submit form to agent module url.
|
||||
$("#snmp_create_module").attr(
|
||||
"action",
|
||||
"index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente="+id_agent+"&tab=module&edit_module=1");
|
||||
|
||||
$('#snmp_create_module').submit();
|
||||
|
||||
|
||||
//Close dialog.
|
||||
$('#dialog_create_module').dialog("close");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue