Skip to content

Commit

Permalink
base64 encode possible fields for DHCP that may possibly include bina…
Browse files Browse the repository at this point in the history
…ry data (#489)

* base64 encode uid and client hostname for dhcp lease info

* cleanup vendor_class_identifier as well and note the changes
  • Loading branch information
VVelox authored Sep 22, 2023
1 parent 3af4778 commit 00a68dc
Showing 1 changed file with 57 additions and 18 deletions.
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;

0 comments on commit 00a68dc

Please sign in to comment.