Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base64 encode possible fields for DHCP that may possibly include binary data #489

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 57 additions & 18 deletions snmp/dhcp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ client hostname, and state are unique.
- .found_leases.[].starts :: Unix time of of when the lease starts.
- .found_leases.[].state :: State of the lease.
- .found_leases.[].uid :: UID passed during the request.
- .found_leases.[].vendor_class_identifier :: Vendor class identifier passed during the request.

The following are Base64 encoded as they may include binary that breaks either SNMP or
the PHP JSON decoder.

- .found_leases.[].vendor_class_identifier
- .found_leases.[].uid :: UID passed during the request.
- .found_leases.[].vendor_class_identifier

=cut

Expand Down Expand Up @@ -100,7 +108,7 @@ if ( !defined( $opts{l} ) ) {
$Getopt::Std::STANDARD_HELP_VERSION = 1;

sub main::VERSION_MESSAGE {
print "LibreNMS ISC-DHCPD extend 0.0.1\n";
print "LibreNMS ISC-DHCPD extend 0.0.2\n";
}

sub main::HELP_MESSAGE {
Expand Down Expand Up @@ -197,33 +205,65 @@ if ( !$opts{d} ) {
. $lease->{hardware_address} } = $lease;
}
foreach my $lease_key ( keys( %{$found_leases} ) ) {
my $uid = $found_leases->{$lease_key}{uid};
if ( $uid ne '' ) {
$uid = encode_base64($uid);
chomp($uid);
}
my $client_hostname = $found_leases->{$lease_key}{client_hostname};
if ( $client_hostname ne '' ) {
$client_hostname = encode_base64($client_hostname);
chomp($client_hostname);
}
my $vendor_class_identifier = $found_leases->{$lease_key}{vendor_class_identifier};
if ( $vendor_class_identifier ne '' ) {
$vendor_class_identifier = encode_base64($vendor_class_identifier);
chomp($vendor_class_identifier);
}
push(
@{ $to_return->{data}{found_leases} },
{
uid => $found_leases->{$lease_key}{uid},
cltt => $found_leases->{$lease_key}{cltt},
state => $found_leases->{$lease_key}{state},
ip => $found_leases->{$lease_key}{ip_address},
hw_address => $found_leases->{$lease_key}{hardware_address},
starts => $found_leases->{$lease_key}{starts},
ends => $found_leases->{$lease_key}{ends},
client_hostname => $found_leases->{$lease_key}{client_hostname},
uid => $uid,
cltt => $found_leases->{$lease_key}{cltt},
state => $found_leases->{$lease_key}{state},
ip => $found_leases->{$lease_key}{ip_address},
hw_address => $found_leases->{$lease_key}{hardware_address},
starts => $found_leases->{$lease_key}{starts},
ends => $found_leases->{$lease_key}{ends},
client_hostname => $client_hostname,
vendor_class_identifier => $vendor_class_identifier,
}
);
} ## end foreach my $lease_key ( keys( %{$found_leases} ...))
} else {
foreach my $lease ( @{$leases} ) {
my $uid = $lease->{uid};
if ( $uid ne '' ) {
$uid = encode_base64($uid);
chomp($uid);
}
my $client_hostname = $lease->{client_hostname};
if ( $client_hostname ne '' ) {
$client_hostname = encode_base64($client_hostname);
chomp($client_hostname);
}
my $vendor_class_identifier = $lease->{vendor_class_identifier};
if ( $vendor_class_identifier ne '' ) {
$vendor_class_identifier = encode_base64($vendor_class_identifier);
chomp($vendor_class_identifier);
}
push(
@{ $to_return->{data}{found_leases} },
{
uid => $lease->{uid},
cltt => $lease->{cltt},
state => $lease->{state},
ip => $lease->{ip_address},
hw_address => $lease->{hardware_address},
starts => $lease->{starts},
ends => $lease->{ends},
client_hostname => $lease->{client_hostname},
uid => $uid,
cltt => $lease->{cltt},
state => $lease->{state},
ip => $lease->{ip_address},
hw_address => $lease->{hardware_address},
starts => $lease->{starts},
ends => $lease->{ends},
client_hostname => $client_hostname,
vendor_class_identifier => $vendor_class_identifier,
}
);
} ## end foreach my $lease ( @{$leases} )
Expand Down Expand Up @@ -316,4 +356,3 @@ if ( $opts{Z} ) {
print $toReturn;

exit;

Loading