Merge branch 'ent-6908-10801-cambio-funcionamiento-snmp-browser' into 'develop'

Ent 6908 10801 cambio funcionamiento snmp browser

See merge request artica/pandorafms!3826
This commit is contained in:
Daniel Rodriguez 2021-02-09 16:44:16 +01:00
commit 4ef97ae494
18 changed files with 511 additions and 431 deletions

View File

@ -80,9 +80,8 @@ if (isset($_GET['loginhash']) === true) {
} else {
include_once 'general/login_page.php';
db_pandora_audit('Logon Failed (loginhash', '', 'system');
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -149,7 +148,9 @@ if (__PAN_XHPROF__ === 1) {
}
if ($config['force_instant_logout'] === true) {
if (isset($config['force_instant_logout']) === true
&& $config['force_instant_logout'] === true
) {
// Force user logout.
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
@ -169,7 +170,6 @@ if ($config['force_instant_logout'] === true) {
}
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}

View File

@ -32,8 +32,6 @@ global $config;
require_once $config['homedir'].'/vendor/autoload.php';
require_once $config['homedir'].'/include/class/HTML.class.php';
use \HTML;
/**
* Global Wizard generic class. Needs to be inherited.
*

View File

@ -19,231 +19,255 @@ 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) io_safe_output((get_parameter('community', '')));
$snmp_version = (string) get_parameter('snmp_browser_version', '');
$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'));
$module_target = get_parameter('module_target', '');
$targets_oids = get_parameter('oids', '');
$return_id = get_parameter('return_id', false);
$custom_action = get_parameter('custom_action', '');
$server_to_exec = get_parameter('server_to_exec');
if (!is_array($targets_oids)) {
$targets_oids = explode(',', $targets_oids);
set_error_handler(
function ($code, $string, $file, $line) {
throw new ErrorException($string, null, $code, $file, $line);
}
);
if ($custom_action != '') {
$custom_action = urldecode(base64_decode($custom_action));
register_shutdown_function(
function () {
$error = error_get_last();
if (null !== $error) {
echo $error['message'];
}
}
);
// SNMP browser.
if ($action == 'snmptree') {
$starting_oid = (string) get_parameter('starting_oid', '.');
try {
if ((bool) is_ajax() === true) {
$method = (string) get_parameter('method', '');
$action = (string) get_parameter('action', '');
$target_ip = (string) get_parameter('target_ip', '');
$target_port = (string) get_parameter('target_port', '');
$community = (string) io_safe_output((get_parameter('community', '')));
$snmp_version = (string) get_parameter('snmp_browser_version', '');
$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'));
$module_target = get_parameter('module_target', '');
$targets_oids = get_parameter('oids', '');
$return_id = get_parameter('return_id', false);
$custom_action = get_parameter('custom_action', '');
$server_to_exec = get_parameter('server_to_exec');
$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,
'null',
$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>';
// 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>';
// 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>';
// Dialog no agent selected.
$output .= '<div id="dialog_no_agents_selected" 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'>".__('Module must be applied to an agent or a policy').'</p>';
$output .= "<p id='error_text' style='font-family:Verdana; font-size:12pt;'></p>";
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
echo $output;
if (!is_array($targets_oids)) {
$targets_oids = explode(',', $targets_oids);
}
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.
if ($action == 'snmptree') {
$starting_oid = (string) get_parameter('starting_oid', '.');
snmp_browser_print_oid(
$oid,
$custom_action,
false,
$community,
$snmp_version
);
return;
}
$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,
'null',
$server_to_exec,
$target_port
);
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.
''
);
if ($method == 'snmp_browser_create_modules') {
// Get target ids from form.
$id_items = get_parameter('id_item2', null);
if (empty($id_items) === false) {
$id_target = explode(',', $id_items[0]);
// Div for error/succes dialog.
$output = '<div id="snmp_result_msg" style="display:none"></div>';
// 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>';
// 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>';
// Dialog no agent selected.
$output .= '<div id="dialog_no_agents_selected" 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'>".__('Module must be applied to an agent or a policy').'</p>';
$output .= "<p id='error_text' style='font-family:Verdana; font-size:12pt;'></p>";
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
echo $output;
}
return;
}
if (empty($id_items[0]) && $module_target !== 'network_component') {
echo json_encode([0 => -1]);
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);
$id_target = null;
if (empty($id_items) === false) {
$id_target = explode(',', $id_items[0]);
}
if (empty($id_items[0]) && $module_target !== 'network_component') {
echo json_encode([0 => -1]);
exit;
}
$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,
$server_to_exec
);
// Return fail modules for error/success message.
echo json_encode($fail_modules);
exit;
}
$snmp_extradata = get_parameter('snmp_extradata', '');
if ($method == 'snmp_browser_print_create_module_massive') {
// Get SNMP conf vaues from modal onshow extradata.
$snmp_extradata = get_parameter('extradata', '');
if (!is_array($snmp_extradata)) {
// Decode SNMP values.
$snmp_extradata = json_decode(io_safe_output($snmp_extradata), true);
$return = snmp_browser_print_create_module_massive($module_target, $snmp_extradata, true);
echo $return;
exit;
}
foreach ($snmp_extradata as $snmp_conf) {
$snmp_conf_values[$snmp_conf['name']] = $snmp_conf['value'];
if ($method == 'snmp_browser_print_create_policy') {
$return = snmp_browser_print_create_policy();
echo $return;
exit;
}
$fail_modules = snmp_browser_create_modules_snmp($module_target, $snmp_conf_values, $id_target);
if ($method == 'snmp_browser_create_policy') {
enterprise_include_once('include/functions_policies.php');
// Return fail modules for error/success message.
echo json_encode($fail_modules);
exit;
}
$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,
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;
}
// 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);
}
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');
$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),
],
];
$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);
echo json_encode($return);
}
$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;
}
} catch (\Exception $e) {
echo $e->getMessage();
}

View File

@ -42,16 +42,7 @@ if (!is_dir($config['homedir'])) {
// Help to debug problems. Override global PHP configuration
global $develop_bypass;
if ($develop_bypass != 1) {
// error_reporting(E_ALL);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
} else {
error_reporting(E_ALL & ~E_NOTICE);
}
ini_set('display_errors', 0);
} else {
if ((int) $develop_bypass === 1) {
// Develop mode, show all notices and errors on Console (and log it)
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
error_reporting(E_ALL & ~E_DEPRECATED);
@ -304,7 +295,7 @@ switch ($config['dbtype']) {
// ======================================================================
// Menu display mode.
if ($_SESSION['menu_type']) {
if (isset($_SESSION['meny_type']) === true && $_SESSION['menu_type']) {
$config['menu_type'] = $_SESSION['menu_type'];
} else {
$config['menu_type'] = 'classic';

View File

@ -2001,6 +2001,10 @@ function get_snmpwalk(
) {
global $config;
if (empty($ip_target) === true) {
return [];
}
// Note: quick_print is ignored
// Fix for snmp port
if (!empty($snmp_port)) {
@ -4459,7 +4463,7 @@ function get_help_info($section_name)
{
global $config;
$user_language = get_user_language($id_user);
$user_language = get_user_language($config['id_user']);
$es = false;
$result = 'https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:';

View File

@ -536,6 +536,8 @@ function html_print_select_groups(
$include_groups[$nothing_value] = $nothing;
}
$json_exclusions = '';
$json_inclusions = '';
if (is_array($delete_groups) === true) {
$json_exclusions = json_encode($delete_groups);
}

View File

@ -675,6 +675,8 @@ function modules_create_agent_module(
$time = 0;
if (empty($values['interval']) === false) {
$time = (time() - (int) $values['interval']);
} else {
$values['interval'] = null;
}
$result = db_process_sql_insert(

View File

@ -12864,7 +12864,7 @@ function reporting_get_stats_servers()
);
$tdata[1] = '<span class="big_data" id="total_events">'.html_print_image('images/spinner.gif', true).'</span>';
if ($system_events > 50000 && !enterprise_installed()) {
if (isset($system_events) && $system_events > 50000 && !enterprise_installed()) {
$tdata[2] = "<div id='monitoreventsmodal' class='publienterprise' title='Community version' style='text-align:left'><img data-title='Enterprise version' class='img_help forced_title' data-use_title_for_force_title='1' src='images/alert_enterprise.png'></div>";
} else {
$tdata[3] = '&nbsp;';

View File

@ -265,94 +265,43 @@ function snmp_browser_get_tree(
$snmp3_privacy_method='',
$snmp3_privacy_pass='',
$snmp3_context_engine_id=null,
$server_to_exec=0
$server_to_exec=0,
$target_port=''
) {
global $config;
if ($server_to_exec != 0) {
$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,
'',
''
);
} else {
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;
break;
}
$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,
'',
$snmp3_context_engine_id
);
}
$mibs_dir = $config['homedir'].'/attachment/mibs';
$_dir = opendir($mibs_dir);
// Future. Recomemended: Use a global config limit of MIBs loaded.
while (($mib_file = readdir($_dir)) !== false) {
if ($mib_file == '..' || $mib_file == '.') {
continue;
}
$rs = snmp_read_mib($mibs_dir.'/'.$mib_file);
if ($rs !== true) {
error_log('Failed while reading MIB file: '.$mib_file);
}
}
closedir($_dir);
$output = $snmp_session->walk($starting_oid);
if ($output == false) {
$output = $snmp_session->getError();
$snmp_session->close();
return $output;
}
$snmp_session->close();
}
$output = get_snmpwalk(
// Ip_target.
$target_ip,
// Snmp_version.
$version,
// Snmp_community.
$community,
// Snmp3_auth_user.
$snmp3_auth_user,
// Snmp3_security_level.
$snmp3_security_level,
// Snmp3_auth_method.
$snmp3_auth_method,
// Snmp3_auth_pass.
$snmp3_auth_pass,
// Snmp3_privacy_method.
$snmp3_privacy_method,
// Snmp3_privacy_pass.
$snmp3_privacy_pass,
// Quick_print.
0,
// Base_oid.
$starting_oid,
// Snmp_port.
$target_port,
// Server_to_exec.
$server_to_exec,
// Extra_arguments.
'',
// Format.
''
);
// Build the tree if output comes filled.
if (empty($output) === false) {
@ -415,17 +364,18 @@ function snmp_browser_get_tree(
/**
* Retrieve data for the specified OID.
*
* @param string $target_ip IP of the SNMP agent.
* @param string $community SNMP community to use.
* @param string $target_oid SNMP OID to query.
* @param string $version Version SNMP.
* @param string $snmp3_auth_user User snmp3.
* @param string $snmp3_security_level Security level snmp3.
* @param string $snmp3_auth_method Method snmp3.
* @param string $snmp3_auth_pass Pass snmp3.
* @param string $snmp3_privacy_method Privicy method snmp3.
* @param string $snmp3_privacy_pass Pass Method snmp3.
* @param integer $server_to_exec Execute with other server.
* @param string $target_ip IP of the SNMP agent.
* @param string $community SNMP community to use.
* @param string $target_oid SNMP OID to query.
* @param string $version Version SNMP.
* @param string $snmp3_auth_user User snmp3.
* @param string $snmp3_security_level Security level snmp3.
* @param string $snmp3_auth_method Method snmp3.
* @param string $snmp3_auth_pass Pass snmp3.
* @param string $snmp3_privacy_method Privicy method snmp3.
* @param string $snmp3_privacy_pass Pass Method snmp3.
* @param integer $server_to_exec Execute with other server.
* @param integer|null $target_port Target port.
*
* @return mixed OID data.
*/
@ -440,7 +390,8 @@ function snmp_browser_get_oid(
$snmp3_auth_pass='',
$snmp3_privacy_method='',
$snmp3_privacy_pass='',
$server_to_exec=0
$server_to_exec=0,
$target_port=''
) {
global $config;
@ -453,24 +404,40 @@ function snmp_browser_get_oid(
}
$output = get_snmpwalk(
// Ip_target.
$target_ip,
// Snmp_version.
$version,
// Snmp_community.
$community,
// Snmp3_auth_user.
$snmp3_auth_user,
// Snmp3_security_level.
$snmp3_security_level,
// Snmp3_auth_method.
$snmp3_auth_method,
// Snmp3_auth_pass.
$snmp3_auth_pass,
// Snmp3_privacy_method.
$snmp3_privacy_method,
// Snmp3_privacy_pass.
$snmp3_privacy_pass,
// Quick_print.
0,
// Base_oid.
$target_oid,
'',
// Snmp_port.
$target_port,
// Server_to_exec.
$server_to_exec,
// Extra_arguments.
'',
// Format.
'-On'
);
$oid_data['oid'] = $target_oid;
foreach ($output as $oid => $value) {
$oid = trim($oid);
$oid_data['numeric_oid'] = $oid;
@ -494,7 +461,8 @@ function snmp_browser_get_oid(
$snmptranslate_bin = $config['snmptranslate'];
}
if ($server_to_exec != 0) {
if ($server_to_exec != 0 && enterprise_installed()) {
$server_data = db_get_row('tserver', 'id_server', $server_to_exec);
$command_output = $snmptranslate_bin.' -m ALL -M +'.escapeshellarg($config['homedir'].'/attachment/mibs').' -Td '.escapeshellarg($oid);
if (empty($server_data['port'])) {
@ -574,7 +542,8 @@ function snmp_browser_print_oid(
) {
$output = '';
// OID information table
// OID information table.
$table = new StdClass();
$table->width = '100%';
$table->size = [];
$table->data = [];
@ -725,15 +694,33 @@ function snmp_browser_print_container(
$table->size = [];
$table->data = [];
$table->data[0][0] = '<strong>'.__('Target IP').'</strong> &nbsp;&nbsp;';
$table->data[0][0] .= html_print_input_text(
'target_ip',
get_parameter('target_ip', ''),
'',
25,
0,
true
$table->size[0] = '30%';
$table->data[0][0] = '<div class="mw500px"><strong>'.__('Target IP').'</strong> &nbsp;&nbsp;';
$table->data[0][0] .= html_print_input(
[
'type' => 'text',
'name' => 'target_ip',
'value' => get_parameter('target_ip', ''),
'required' => true,
'size' => 25,
'maxlength' => 0,
'return' => true,
]
);
$table->data[0][0] .= '&nbsp;&nbsp<strong>'.__('Port').'</strong>&nbsp;&nbsp;';
$table->data[0][0] .= html_print_input(
[
'type' => 'number',
'name' => 'target_port',
'id' => 'target_port',
'value' => get_parameter('target_port', 161),
'required' => true,
'return' => true,
]
);
$table->data[0][0] .= '</div>';
$table->data[0][1] = '<strong>'.__('Community').'</strong> &nbsp;&nbsp;';
$table->data[0][1] .= html_print_input_text(
'community',
@ -746,7 +733,7 @@ function snmp_browser_print_container(
$table->data[0][2] = '<strong>'.__('Starting OID').'</strong> &nbsp;&nbsp;';
$table->data[0][2] .= html_print_input_text(
'starting_oid',
get_parameter('starting_oid', '.1.3.6.1.2'),
get_parameter('starting_oid', '.1.3.6.1.2.1.2.2'),
'',
25,
0,
@ -805,12 +792,17 @@ function snmp_browser_print_container(
true
);
$table->data[1][2] = html_print_button(
__('Browse'),
'browse',
false,
'snmpBrowse()',
'class="sub search" style="margin-top:0px;"',
$table->data[1][2] = html_print_input(
[
'type' => 'submit',
'label' => __('Browse'),
'name' => 'browse',
'disabled' => false,
'script' => 'snmpBrowse()',
'attributes' => 'class="sub search" style="margin-top:0px;"',
'return' => true,
],
'div',
true
);
@ -1013,8 +1005,9 @@ function snmp_browser_print_container(
$output = '<div id="snmp_browser_container" style="'.$display.'">';
$output .= '<div style="text-align: left; width: '.$width.'; height: '.$height.';">';
$output .= '<div style="width: 100%">';
$output .= '<form onsubmit="snmpBrowse(); return false;">';
$output .= html_print_table($table, true);
$output .= '</div>';
$output .= '</form></div>';
if (isset($snmp_version) === false) {
$snmp_version = null;
@ -1114,25 +1107,74 @@ function snmp_browser_print_container(
/**
* 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
* @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)
{
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)) {
$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'];
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 = [];
@ -1148,9 +1190,16 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
$snmp3_auth_method,
$snmp3_auth_pass,
$snmp3_privacy_method,
$snmp3_privacy_pass
$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 {
@ -1241,7 +1290,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
'min' => 0,
'tcp_send' => $snmp_version,
'tcp_rcv' => '',
'tcp_port' => 0,
'tcp_port' => $target_port,
'snmp_oid' => $oid['numeric_oid'],
'snmp_community' => $community,
'id_module_group' => 3,
@ -1301,7 +1350,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
'min' => 0,
'tcp_send' => $snmp_version,
'tcp_rcv' => '',
'tcp_port' => 0,
'tcp_port' => $target_port,
'snmp_oid' => $oid['numeric_oid'],
'snmp_community' => $community,
'id_module_group' => 3,
@ -1354,7 +1403,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
}
}
if (is_array($ids)) {
if (isset($ids) === true && is_array($ids) === true) {
foreach ($ids as $id) {
// Id < 0 for error codes.
if (!$id || $id < 0) {
@ -1382,6 +1431,8 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
*/
function snmp_browser_print_create_module_massive($target='agent', $snmp_conf, $return=false)
{
global $config;
// String for labels.
switch ($target) {
case 'agent':
@ -1393,7 +1444,7 @@ function snmp_browser_print_create_module_massive($target='agent', $snmp_conf, $
break;
}
$output .= "<form target='_blank' id='create_module_massive' action='#' method='post'>";
$output = "<form target='_blank' id='create_module_massive' action='#' method='post'>";
$strict_user = db_get_value(
'strict_acl',
@ -1582,6 +1633,10 @@ 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';
$table->style = [];
@ -1592,7 +1647,8 @@ function snmp_browser_print_create_policy()
$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(
$table->data[1][1] = '<div class="flex flex-row"><div class="w90p">';
$table->data[1][1] .= html_print_select_groups(
false,
'AW',
false,
@ -1602,10 +1658,10 @@ function snmp_browser_print_create_policy()
'',
'',
true
);
).'</div>';
$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[1][1] .= '</span></div>';
$table->data[2][0] = __('Description');
$table->data[2][1] = html_print_textarea('description', 3, 30, $description, '', true);

View File

@ -304,6 +304,7 @@ function users_get_groups(
$search=''
) {
static $group_cache = [];
$filter = '';
// Added users_group_cache to avoid unnecessary proccess on massive calls...
static $users_group_cache = [];

View File

@ -103,7 +103,7 @@ class gettext_reader {
* @param object Reader the StreamReader object
* @param boolean enable_cache Enable or disable caching of strings (default on)
*/
function gettext_reader($Reader, $enable_cache = true) {
function __construct($Reader, $enable_cache = true) {
$machine = php_uname("m");
$enabled64Bits = false;

View File

@ -1,3 +1,4 @@
/* globals $,jQuery */
// Load the SNMP tree via AJAX
function snmpBrowse() {
// Empty the SNMP tree
@ -15,6 +16,7 @@ function snmpBrowse() {
// Read the target IP and community
var target_ip = $("#text-target_ip").val();
var target_port = $("#target_port").val();
var community = $("#text-community").val();
var starting_oid = $("#text-starting_oid").val();
var snmp_version = $("#snmp_browser_version").val();
@ -25,13 +27,13 @@ function snmpBrowse() {
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 server_to_exec = $("#server_to_exec").val();
var ajax_url = $("#hidden-ajax_url").val();
// Prepare the AJAX call
var params = {};
params["target_ip"] = target_ip;
params["target_port"] = target_port;
params["community"] = community;
params["starting_oid"] = starting_oid;
params["snmp_browser_version"] = snmp_version;
@ -52,7 +54,6 @@ function snmpBrowse() {
type: "POST",
url: (action = ajax_url),
async: true,
timeout: 120000,
success: function(data) {
// Hide the spinner
$("#spinner").css("display", "none");
@ -62,6 +63,19 @@ function snmpBrowse() {
// Manage click and select events.
snmp_browser_events_manage();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#spinner").css("display", "none");
$("#snmp_browser").html(
"<p>Status: " +
textStatus +
"</p><p>" +
"Error: " +
errorThrown +
"</p><p>" +
XMLHttpRequest.responseText +
"</p>"
);
}
});
}
@ -499,6 +513,7 @@ function checkSNMPVersion() {
function snmpBrowserWindow() {
// Keep elements in the form and the SNMP browser synced
$("#text-target_ip").val($("#text-ip_target").val());
$("#target_port").val($("#text-tcp_port").val());
$("#text-community").val($("#text-snmp_community").val());
$("#snmp_browser_version").val($("#snmp_version").val());
$("#text-snmp3_browser_auth_user").val($("#text-snmp3_auth_user").val());
@ -525,7 +540,7 @@ function snmpBrowserWindow() {
opacity: 0.5,
background: "black"
},
width: 920,
width: 1000,
height: 500
});
}
@ -561,6 +576,7 @@ function snmp_browser_create_modules(module_target, return_post = true) {
.get();
var target_ip = $("#text-target_ip").val();
var target_port = $("#target_port").val();
var community = $("#text-community").val();
var snmp_version = $("#snmp_browser_version").val();
var snmp3_auth_user = $("#text-snmp3_browser_auth_user").val();
@ -590,6 +606,7 @@ function snmp_browser_create_modules(module_target, return_post = true) {
var snmp_conf = {};
snmp_conf["target_ip"] = target_ip;
snmp_conf["target_port"] = target_port;
snmp_conf["community"] = community;
snmp_conf["oids"] = oids;
snmp_conf["snmp_browser_version"] = snmp_version;

View File

@ -219,7 +219,9 @@ function enable_session_handlers()
{
global $config;
if ($config['_using_pandora_sessionhandlers'] !== true) {
if (isset($config['_using_pandora_sessionhandlers']) !== true
|| $config['_using_pandora_sessionhandlers'] !== true
) {
if (session_status() !== PHP_SESSION_NONE) {
// Close previous version.
session_write_close();

View File

@ -60,7 +60,7 @@ class StringReader {
var $_pos;
var $_str;
function StringReader($str='') {
function __construct($str='') {
$this->_str = $str;
$this->_pos = 0;
//BUGFIX-HR: 2008-07-21 we have to detect, if we need mb_str* functions instead of normal functions !
@ -128,7 +128,7 @@ class FileReader {
var $_fd;
var $_length;
function FileReader($filename) {
function __construct($filename) {
if (file_exists($filename)) {
$this->_length=filesize($filename);
@ -184,8 +184,8 @@ class FileReader {
// Preloads entire file in memory first, then creates a StringReader
// over it (it assumes knowledge of StringReader internals)
class CachedFileReader extends StringReader {
function CachedFileReader($filename) {
parent::StringReader(); //BUGFIX-HR: 2008-07-21 missing parent constructor call
function __construct($filename) {
parent::__construct(); //BUGFIX-HR: 2008-07-21 missing parent constructor call
if (file_exists($filename)) {
$length=filesize($filename);

View File

@ -380,9 +380,8 @@ if (! isset($config['id_user'])) {
'Invalid double auth login: '.$_SERVER['REMOTE_ADDR'],
$_SERVER['REMOTE_ADDR']
);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -401,9 +400,8 @@ if (! isset($config['id_user'])) {
if (!$saml_user_id) {
$login_failed = true;
include_once 'general/login_page.php';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -446,9 +444,8 @@ if (! isset($config['id_user'])) {
if ($blocked) {
include_once 'general/login_page.php';
db_pandora_audit('Password expired', 'Password expired: '.$nick, $nick);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -481,9 +478,8 @@ if (! isset($config['id_user'])) {
'Password expired: '.$nick,
$nick
);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -505,9 +501,8 @@ if (! isset($config['id_user'])) {
// Load the page to introduce the double auth code.
$login_screen = 'double_auth';
include_once 'general/login_page.php';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -603,7 +598,7 @@ if (! isset($config['id_user'])) {
}
if ($prepare_session) {
config_prepare_session();
config_prepare_session();
}
if (is_user_admin($config['id_user'])) {
@ -677,9 +672,8 @@ if (! isset($config['id_user'])) {
'Invalid login: '.$nick,
$nick
);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -690,9 +684,8 @@ if (! isset($config['id_user'])) {
'Invalid login: '.$nick,
$nick
);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -741,9 +734,8 @@ if (! isset($config['id_user'])) {
} else {
include_once 'general/login_page.php';
db_pandora_audit('Logon Failed (loginhash', '', 'system');
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -891,9 +883,8 @@ if (! isset($config['id_user'])) {
}
}
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -917,9 +908,8 @@ if (! isset($config['id_user'])) {
} else {
include_once 'general/login_page.php';
db_pandora_audit('Logon Failed (loginhash', '', 'system');
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -941,9 +931,8 @@ if (! isset($config['id_user'])) {
unset($_SESSION['id_usuario']);
unset($iduser);
include_once 'general/login_page.php';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -960,9 +949,8 @@ if (! isset($config['id_user'])) {
unset($_SESSION['id_usuario']);
unset($iduser);
include_once 'general/login_page.php';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -995,9 +983,8 @@ if (isset($_GET['bye'])) {
// Process logout.
include 'general/logoff.php';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
exit('</html>');
@ -1007,11 +994,11 @@ clear_pandora_error_for_header();
/*
* ----------------------------------------------------------------------
* EXTENSIONS
* ----------------------------------------------------------------------
*
* Load the basic configurations of extension and add extensions into menu.
* Load here, because if not, some extensions not load well, I don't why.
* EXTENSIONS
* ----------------------------------------------------------------------
*
* Load the basic configurations of extension and add extensions into menu.
* Load here, because if not, some extensions not load well, I don't why.
*/
$config['logged'] = false;
@ -1081,7 +1068,7 @@ if ($config['pure'] == 0) {
/*
* Session locking concurrency speedup!
* http://es2.php.net/manual/en/ref.session.php#64525
* http://es2.php.net/manual/en/ref.session.php#64525
*/
session_write_close();
@ -1298,9 +1285,8 @@ if ($config['pure'] == 0) {
require_once 'include/functions_clippy.php';
clippy_start($sec2);
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
db_print_database_debug();
@ -1317,8 +1303,8 @@ require 'include/php_to_js_values.php';
<script type="text/javascript" language="javascript">
// When there are less than 5 rows, all rows must be white
var theme = "<?php echo $config['style']; ?>";
// When there are less than 5 rows, all rows must be white
var theme = "<?php echo $config['style']; ?>";
if(theme === 'pandora'){
if($('table.info_table tr').length < 5){
$('table.info_table tbody > tr').css('background-color', '#fff');
@ -1345,11 +1331,11 @@ require 'include/php_to_js_values.php';
function topFunction() {
/*
* Safari.
* document.body.scrollTop = 0;
* For Chrome, Firefox, IE and Opera.
* document.documentElement.scrollTop = 0;
*/
* Safari.
* document.body.scrollTop = 0;
* For Chrome, Firefox, IE and Opera.
* document.documentElement.scrollTop = 0;
*/
$("HTML, BODY").animate({ scrollTop: 0 }, 500);
}

View File

@ -60,7 +60,6 @@ if ($config['force_instant_logout'] === true) {
}
}
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}

View File

@ -287,9 +287,8 @@ $(document).ready (function () {
<?php
echo '</body>';
while (@ob_end_flush()) {
// Dumping...
continue;
while (ob_get_length() > 0) {
ob_end_flush();
}
echo '</html>';

View File

@ -139,7 +139,6 @@ function snmp_browser_show_add_module_massive(module_target = 'agent') {
var snmp_extradata = snmp_browser_create_modules(module_target);
// Load dinamically modal form.
load_modal({
target: $('#modal'),
form: 'snmp_browser_add_module_form',
extradata: [
{