Merge branch 'ent-3013-ipam-modo-configuracion-de-vlan' into 'develop'
fixed errors See merge request artica/pandorafms!2116 Former-commit-id: 355989ad28b743537f790433024bd88bd02ef53d
This commit is contained in:
commit
ffcdca7e8b
|
@ -1215,30 +1215,29 @@ function mysql_get_fields($table) {
|
|||
/**
|
||||
* Process a file with an oracle schema sentences.
|
||||
* Based on the function which installs the pandoradb.sql schema.
|
||||
*
|
||||
*
|
||||
* @param string $path File path.
|
||||
* @param bool $handle_error Whether to handle the mysqli_query/mysql_query errors or throw an exception.
|
||||
*
|
||||
*
|
||||
* @return bool Return the final status of the operation.
|
||||
*/
|
||||
function mysql_db_process_file ($path, $handle_error = true) {
|
||||
global $config;
|
||||
|
||||
|
||||
if (file_exists($path)) {
|
||||
$file_content = file($path);
|
||||
$query = "";
|
||||
|
||||
|
||||
// Begin the transaction
|
||||
mysql_db_process_sql_begin();
|
||||
|
||||
|
||||
foreach ($file_content as $sql_line) {
|
||||
if (trim($sql_line) != "" && strpos($sql_line, "--") === false) {
|
||||
|
||||
$query .= $sql_line;
|
||||
|
||||
|
||||
if (preg_match("/;[\040]*\$/", $sql_line)) {
|
||||
if ($config["mysqli"]) {
|
||||
$query_result = mysqli_query($config['dbconnection'], $query);
|
||||
$query_result = mysqli_query($config['dbconnection'], $query);
|
||||
}
|
||||
else {
|
||||
$query_result = mysql_query($query);
|
||||
|
@ -1246,9 +1245,14 @@ function mysql_db_process_file ($path, $handle_error = true) {
|
|||
if (!$result = $query_result) {
|
||||
// Error. Rollback the transaction
|
||||
mysql_db_process_sql_rollback();
|
||||
|
||||
$error_message = mysql_error();
|
||||
|
||||
|
||||
if($config["mysqli"]){
|
||||
$error_message = mysqli_error($config['dbconnection']);
|
||||
}
|
||||
else{
|
||||
$error_message = mysql_error();
|
||||
}
|
||||
|
||||
// Handle the error
|
||||
if ($handle_error) {
|
||||
$backtrace = debug_backtrace();
|
||||
|
@ -1258,7 +1262,7 @@ function mysql_db_process_file ($path, $handle_error = true) {
|
|||
set_error_handler('db_sql_error_handler');
|
||||
trigger_error($error);
|
||||
restore_error_handler();
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
// Throw an exception with the error message
|
||||
|
@ -1270,10 +1274,9 @@ function mysql_db_process_file ($path, $handle_error = true) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// No errors. Commit the transaction
|
||||
mysql_db_process_sql_commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3435,4 +3435,85 @@ function pandora_xhprof_display_result($key = "", $method = "link") {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* From a network with a mask remove the smallest ip and the highest
|
||||
*
|
||||
* @param string address to identify the network.
|
||||
* @param string mask to identify the mask network
|
||||
* @return array or false with smallest ip and highest ip
|
||||
*/
|
||||
function range_ips_for_network($address, $mask) {
|
||||
if(!isset($address) || !isset($mask)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//convert ip addresses to long form
|
||||
$address_long = ip2long($address);
|
||||
$mask_long = ip2long($mask);
|
||||
|
||||
//caculate first usable address
|
||||
$ip_host_first = ((~$mask_long) & $address_long);
|
||||
$ip_first = ($address_long ^ $ip_host_first) + 1;
|
||||
|
||||
//caculate last usable address
|
||||
$ip_broadcast_invert = ~$mask_long;
|
||||
$ip_last = ($address_long | $ip_broadcast_invert) - 1;
|
||||
|
||||
$range = array(
|
||||
'first' => long2ip($ip_first),
|
||||
'last' => long2ip($ip_last)
|
||||
);
|
||||
|
||||
return $range;
|
||||
}
|
||||
|
||||
/**
|
||||
* from two ips find out if there is such an ip
|
||||
*
|
||||
* @param string ip ip wont validate
|
||||
* @param string ip_lower
|
||||
* @param string ip_upper
|
||||
* @return bool true or false if the ip is between the two ips
|
||||
*/
|
||||
function is_in_network ($ip, $ip_lower, $ip_upper) {
|
||||
if(!isset($ip) || !isset($ip_lower) || !isset($ip_upper)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$ip = (float)sprintf("%u",ip2long($ip));
|
||||
$ip_lower = (float)sprintf("%u",ip2long($ip_lower));
|
||||
$ip_upper = (float)sprintf("%u",ip2long($ip_upper));
|
||||
|
||||
if ($ip >= $ip_lower && $ip <= $ip_upper){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function ip_belongs_to_network($ip, $network, $mask) {
|
||||
if ($ip == $network) {
|
||||
return true;
|
||||
}
|
||||
$ranges = range_ips_for_network($network, $mask);
|
||||
return is_in_network($ip, $ranges['first'], $ranges['last']);
|
||||
}
|
||||
/**
|
||||
* convert the mask to cird format
|
||||
*
|
||||
* @param string mask
|
||||
* @return string true or false if the ip is between the two ips
|
||||
*/
|
||||
function mask2cidr($mask){
|
||||
if(!isset($mask))
|
||||
return 0;
|
||||
|
||||
$long = ip2long($mask);
|
||||
$base = ip2long('255.255.255.255');
|
||||
return 32-log(($long ^ $base)+1,2);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -32,7 +32,6 @@ include_once($config['homedir'] . "/include/functions_servers.php");
|
|||
include_once($config['homedir'] . "/include/functions_planned_downtimes.php");
|
||||
include_once($config['homedir'] . "/include/functions_db.php");
|
||||
include_once($config['homedir'] . "/include/functions_event_responses.php");
|
||||
include_once($config['homedir'] . "/include/functions_policies.php");
|
||||
enterprise_include_once ('include/functions_local_components.php');
|
||||
enterprise_include_once ('include/functions_events.php');
|
||||
enterprise_include_once ('include/functions_agents.php');
|
||||
|
|
|
@ -249,6 +249,10 @@ function config_update_config () {
|
|||
$error_update[] = __('Activate Log Collector');
|
||||
if (!config_update_value ('enable_update_manager', get_parameter('enable_update_manager')))
|
||||
$error_update[] = __('Enable Update Manager');
|
||||
if (!config_update_value ('ipam_ocuppied_critical_treshold', get_parameter('ipam_ocuppied_critical_treshold')))
|
||||
$error_update[] = __('Ipam Ocuppied Manager Critical');
|
||||
if (!config_update_value ('ipam_ocuppied_warning_treshold', get_parameter('ipam_ocuppied_warning_treshold')))
|
||||
$error_update[] = __('Ipam Ocuppied Manager Warning');
|
||||
|
||||
$inventory_changes_blacklist = get_parameter('inventory_changes_blacklist', array());
|
||||
if (!config_update_value ('inventory_changes_blacklist', implode(',',$inventory_changes_blacklist)))
|
||||
|
@ -1085,6 +1089,14 @@ function config_process_config () {
|
|||
config_update_value ('enable_update_manager', 1);
|
||||
}
|
||||
|
||||
if (!isset ($config["ipam_ocuppied_critical_treshold"])) {
|
||||
config_update_value ('ipam_ocuppied_critical_treshold', 90);
|
||||
}
|
||||
|
||||
if (!isset ($config["ipam_ocuppied_warning_treshold"])) {
|
||||
config_update_value ('ipam_ocuppied_warning_treshold', 80);
|
||||
}
|
||||
|
||||
if (!isset ($config["reset_pass_option"])) {
|
||||
config_update_value ('reset_pass_option', 0);
|
||||
}
|
||||
|
|
|
@ -1025,7 +1025,8 @@ function html_print_input_text_extended ($name, $value, $id, $alt, $size, $maxle
|
|||
"title", "xml:lang", "onfocus", "onblur", "onselect",
|
||||
"onchange", "onclick", "ondblclick", "onmousedown",
|
||||
"onmouseup", "onmouseover", "onmousemove", "onmouseout",
|
||||
"onkeypress", "onkeydown", "onkeyup", "required");
|
||||
"onkeypress", "onkeydown", "onkeyup", "required",
|
||||
"autocomplete");
|
||||
|
||||
$output = '<input '.($password ? 'type="password" autocomplete="off" ' : 'type="text" ');
|
||||
|
||||
|
@ -1196,22 +1197,27 @@ function html_print_input_password ($name, $value, $alt = '',
|
|||
*
|
||||
* @return string HTML code if return parameter is true.
|
||||
*/
|
||||
function html_print_input_text ($name, $value, $alt = '', $size = 50, $maxlength = 255, $return = false, $disabled = false, $required = false, $function = "", $class = "", $onChange ="") {
|
||||
function html_print_input_text ($name, $value, $alt = '', $size = 50, $maxlength = 255, $return = false, $disabled = false, $required = false, $function = "", $class = "", $onChange ="", $autocomplete="") {
|
||||
if ($maxlength == 0)
|
||||
$maxlength = 255;
|
||||
|
||||
|
||||
if ($size == 0)
|
||||
$size = 10;
|
||||
|
||||
|
||||
$attr = array();
|
||||
if ($required)
|
||||
if ($required){
|
||||
$attr['required'] = 'required';
|
||||
if ($class != '')
|
||||
}
|
||||
if ($class != ''){
|
||||
$attr['class'] = $class;
|
||||
}
|
||||
if ($onChange != '') {
|
||||
$attr['onchange'] = $onChange;
|
||||
}
|
||||
|
||||
if($autocomplete !== ''){
|
||||
$attr['autocomplete'] = $autocomplete;
|
||||
}
|
||||
|
||||
return html_print_input_text_extended ($name, $value, 'text-'.$name, $alt, $size, $maxlength, $disabled, '', $attr, $return, false, $function);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,12 +67,21 @@ function os_get_name($id_os) {
|
|||
}
|
||||
|
||||
|
||||
function os_get_os() {
|
||||
function os_get_os($hash = false) {
|
||||
$result = array();
|
||||
$op_systems = db_get_all_rows_in_table('tconfig_os');
|
||||
if (empty($op_systems))
|
||||
$op_systems = array();
|
||||
|
||||
return $op_systems;
|
||||
|
||||
if ($hash) {
|
||||
foreach ($op_systems as $key => $value) {
|
||||
$result[$value['id_os']] = $value['name'];
|
||||
}
|
||||
} else {
|
||||
$result = $op_systems;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function os_get_icon($id_os) {
|
||||
|
|
|
@ -1584,8 +1584,8 @@ $config['css']['dialog'] = "include/javascript/introjs.css";
|
|||
//End load JQuery
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
include_once($config["homedir"] . '/include/graphs/functions_flot.php');
|
||||
$output .= include_javascript_dependencies_flot_graph(true);
|
||||
include_once (__DIR__ . '/graphs/functions_flot.php');
|
||||
$output .= include_javascript_dependencies_flot_graph (true);
|
||||
|
||||
$output .= '<!--[if gte IE 6]>
|
||||
<link rel="stylesheet" href="include/styles/ie.css" type="text/css"/>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -594,6 +594,9 @@ sub process_xml_data ($$$$$) {
|
|||
|
||||
# Process snmptrapd modules
|
||||
enterprise_hook('process_snmptrap_data', [$pa_config, $data, $server_id, $dbh]);
|
||||
|
||||
# Process disovery modules
|
||||
enterprise_hook('process_discovery_data', [$pa_config, $data, $server_id, $dbh]);
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
|
|
|
@ -18,7 +18,7 @@ use warnings;
|
|||
use LWP::UserAgent;
|
||||
use HTTP::Cookies;
|
||||
use HTTP::Request::Common;
|
||||
|
||||
use Socket qw(inet_ntoa inet_aton);
|
||||
use File::Copy;
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
use Time::HiRes qw(time);
|
||||
|
@ -40,6 +40,8 @@ our %EXPORT_TAGS = ( 'all' => [ qw() ] );
|
|||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
our @EXPORT = qw(
|
||||
__ip_to_long
|
||||
__long_to_ip
|
||||
api_available
|
||||
api_call
|
||||
api_create_custom_field
|
||||
|
@ -47,6 +49,7 @@ our @EXPORT = qw(
|
|||
api_create_group
|
||||
call_url
|
||||
check_lib_version
|
||||
csv_to_obj
|
||||
decrypt
|
||||
empty
|
||||
encrypt
|
||||
|
@ -67,6 +70,7 @@ our @EXPORT = qw(
|
|||
join_by_field
|
||||
load_perl_modules
|
||||
logger
|
||||
mask_to_decimal
|
||||
merge_hashes
|
||||
parse_arguments
|
||||
parse_configuration
|
||||
|
@ -74,6 +78,7 @@ our @EXPORT = qw(
|
|||
process_performance
|
||||
post_url
|
||||
print_agent
|
||||
print_discovery_module
|
||||
print_error
|
||||
print_execution_result
|
||||
print_message
|
||||
|
@ -125,6 +130,47 @@ sub check_lib_version {
|
|||
return 1;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Returns IP address(v4) in longint format
|
||||
###############################################################################
|
||||
sub __ip_to_long {
|
||||
my $ip_str = shift;
|
||||
return unpack "N", inet_aton($ip_str);
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Returns IP address(v4) in longint format
|
||||
###############################################################################
|
||||
sub __long_to_ip {
|
||||
my $ip_long = shift;
|
||||
return inet_ntoa pack("N", ($ip_long));
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Convert CSV string to hash
|
||||
################################################################################
|
||||
sub csv_to_obj {
|
||||
my ($csv) = @_;
|
||||
my @ahr;
|
||||
my @lines = split /\n/, $csv;
|
||||
|
||||
return [] unless $#lines >= 0;
|
||||
|
||||
# scan headers
|
||||
my @hr_headers = split /,/, shift @lines;
|
||||
|
||||
# Clean \n\r
|
||||
@hr_headers = map { $_ =~ s/\"//g; trim($_); } @hr_headers;
|
||||
|
||||
foreach my $line (@lines) {
|
||||
my $i = 0;
|
||||
my %hr = map { $_ =~ s/\"//g; $hr_headers[$i++] => trim($_) } split /,/, $line;
|
||||
|
||||
push @ahr, \%hr;
|
||||
}
|
||||
return \@ahr;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Get current time (milis)
|
||||
################################################################################
|
||||
|
@ -134,6 +180,25 @@ sub getCurrentUTimeMilis {
|
|||
return floor(time*1000);
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Mask to decimal
|
||||
################################################################################
|
||||
sub mask_to_decimal {
|
||||
my $mask = shift;
|
||||
my ($a,$b,$c,$d) = $mask =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
|
||||
|
||||
$a = sprintf "%08b", $a;
|
||||
$b = sprintf "%08b", $b;
|
||||
$c = sprintf "%08b", $c;
|
||||
$d = sprintf "%08b", $d;
|
||||
|
||||
my $str = $a . $b . $c . $d;
|
||||
|
||||
$str =~ s/0.*$//;
|
||||
|
||||
return length($str);
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Mix hashses
|
||||
################################################################################
|
||||
|
@ -442,8 +507,18 @@ sub print_agent {
|
|||
|
||||
$xml .= ">";
|
||||
|
||||
foreach my $module (@{$modules_def}) {
|
||||
$xml .= print_module($config, $module,1);
|
||||
if (ref($modules_def) eq "ARRAY") {
|
||||
foreach my $module (@{$modules_def}) {
|
||||
if (ref($module) eq "HASH" && (defined $module->{'name'})) {
|
||||
$xml .= print_module($config, $module,1);
|
||||
} elsif (ref($module) eq "HASH" && (defined $module->{'discovery'})) {
|
||||
$xml .= print_discovery_module($config, $module,1);
|
||||
}
|
||||
}
|
||||
} elsif (ref($modules_def) eq "HASH" && (defined $modules_def->{'name'})) {
|
||||
$xml .= print_module($config, $modules_def,1);
|
||||
} elsif (ref($modules_def) eq "HASH" && (defined $modules_def->{'discovery'})) {
|
||||
$xml .= print_discovery_module($config, $modules_def,1);
|
||||
}
|
||||
|
||||
# print tail
|
||||
|
@ -457,6 +532,28 @@ sub print_agent {
|
|||
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# print_module
|
||||
################################################################################
|
||||
sub print_discovery_module {
|
||||
my ($conf, $global_data, $not_print_flag) = @_;
|
||||
|
||||
return undef if (ref($global_data) ne "HASH" || !defined($global_data->{'discovery'}));
|
||||
return "" if empty($global_data);
|
||||
|
||||
my $data = $global_data->{'discovery'};
|
||||
|
||||
my $xml_module = "<discovery><![CDATA[";
|
||||
$xml_module .= encode_base64(encode_json($data));
|
||||
$xml_module .= "]]></discovery>\n";
|
||||
|
||||
if (empty ($not_print_flag)) {
|
||||
print $xml_module;
|
||||
}
|
||||
|
||||
return $xml_module;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# print_module
|
||||
################################################################################
|
||||
|
@ -660,7 +757,7 @@ sub transfer_xml {
|
|||
my $file_path;
|
||||
|
||||
if (! (empty ($name))) {
|
||||
$file_name = $name . "_" . time() . ".data";
|
||||
$file_name = $name . "." . sprintf("%d",time()) . ".data";
|
||||
}
|
||||
else {
|
||||
# Inherit file name
|
||||
|
@ -672,7 +769,7 @@ sub transfer_xml {
|
|||
$file_name = trim(`hostname`);
|
||||
}
|
||||
|
||||
$file_name .= "_" . time() . ".data";
|
||||
$file_name .= "." . sprintf("%d",time()) . ".data";
|
||||
}
|
||||
|
||||
logger($conf, "transfer_xml", "Failed to generate file name.") if empty($file_name);
|
||||
|
@ -680,6 +777,8 @@ sub transfer_xml {
|
|||
$conf->{temp} = $conf->{tmp} if (empty($conf->{temp}) && defined($conf->{tmp}));
|
||||
$conf->{temp} = $conf->{temporal} if (empty($conf->{temp}) && defined($conf->{temporal}));
|
||||
$conf->{temp} = $conf->{__system}->{tmp} if (empty($conf->{temp}) && defined($conf->{__system})) && (ref($conf->{__system}) eq "HASH");
|
||||
$conf->{temp} = $ENV{'TMP'} if empty($conf->{temp}) && $^O =~ /win/i;
|
||||
$conf->{temp} = '/tmp' if empty($conf->{temp}) && $^O =~ /lin/i;
|
||||
|
||||
$file_path = $conf->{temp} . "/" . $file_name;
|
||||
|
||||
|
@ -687,7 +786,7 @@ sub transfer_xml {
|
|||
|
||||
if ( -e $file_path ) {
|
||||
sleep (1);
|
||||
$file_name = $name . "_" . time() . ".data";
|
||||
$file_name = $name . "." . sprintf("%d",time()) . ".data";
|
||||
$file_path = $conf->{temp} . "/" . $file_name;
|
||||
}
|
||||
|
||||
|
@ -2252,6 +2351,8 @@ sub decrypt {
|
|||
sub get_unix_time {
|
||||
my ($str_time,$separator_dates,$separator_hours) = @_;
|
||||
|
||||
return 0 if empty($str_time);
|
||||
|
||||
if (empty($separator_dates)) {
|
||||
$separator_dates = "\/";
|
||||
}
|
||||
|
@ -2260,10 +2361,15 @@ sub get_unix_time {
|
|||
$separator_hours = ":";
|
||||
}
|
||||
|
||||
|
||||
use Time::Local;
|
||||
my ($mday,$mon,$year,$hour,$min,$sec) = split(/[\s$separator_dates$separator_hours]+/, $str_time);
|
||||
my $time = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
|
||||
my $time;
|
||||
eval {
|
||||
use Time::Local;
|
||||
my ($mday,$mon,$year,$hour,$min,$sec) = split(/[\s$separator_dates$separator_hours]+/, $str_time);
|
||||
$time = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
|
||||
};
|
||||
if ($@) {
|
||||
return 0;
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,8 @@ our @EXPORT = qw(
|
|||
start_server_thread
|
||||
stop_server_threads
|
||||
generate_agent_name_hash
|
||||
long_to_ip
|
||||
ip_to_long
|
||||
);
|
||||
|
||||
# ID of the different servers
|
||||
|
@ -1956,6 +1958,22 @@ sub rightrotate {
|
|||
return (0xFFFFFFFF & ($x << (32 - $c))) | ($x >> $c);
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Returns IP address(v4) in longint format
|
||||
###############################################################################
|
||||
sub ip_to_long {
|
||||
my $ip_str = shift;
|
||||
return unpack "N", inet_aton($ip_str);
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Returns IP address(v4) in longint format
|
||||
###############################################################################
|
||||
sub long_to_ip {
|
||||
my $ip_long = shift;
|
||||
return inet_ntoa pack("N", ($ip_long));
|
||||
}
|
||||
|
||||
# End of function declaration
|
||||
# End of defined Code
|
||||
|
||||
|
|
Loading…
Reference in New Issue