From 2eb635cb15f3cebc34a1274f64800c5defcff033 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Fri, 22 Sep 2023 00:49:33 -0500 Subject: [PATCH 1/2] base64 encode uid and client hostname for dhcp lease info --- snmp/dhcp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/snmp/dhcp b/snmp/dhcp index 67ad5dc2f..bb09eabbf 100755 --- a/snmp/dhcp +++ b/snmp/dhcp @@ -100,7 +100,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 { @@ -197,33 +197,53 @@ 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); + } push( @{ $to_return->{data}{found_leases} }, { - uid => $found_leases->{$lease_key}{uid}, + 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 => $found_leases->{$lease_key}{client_hostname}, + client_hostname => $client_hostname, } ); } ## 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); + } push( @{ $to_return->{data}{found_leases} }, { - uid => $lease->{uid}, + 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 => $lease->{client_hostname}, + client_hostname => $client_hostname, } ); } ## end foreach my $lease ( @{$leases} ) @@ -316,4 +336,3 @@ if ( $opts{Z} ) { print $toReturn; exit; - From ae4c053402d3b6cdd6005a8b35d1e3bdd5428f29 Mon Sep 17 00:00:00 2001 From: "Zane C. Bowers-Hadley" Date: Fri, 22 Sep 2023 01:08:12 -0500 Subject: [PATCH 2/2] cleanup vendor_class_identifier as well and note the changes --- snmp/dhcp | 76 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/snmp/dhcp b/snmp/dhcp index bb09eabbf..97e4e8e6a 100755 --- a/snmp/dhcp +++ b/snmp/dhcp @@ -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 @@ -197,53 +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); + 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); + 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 => $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, + 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); + 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); + 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 => $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, + 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} )