--- rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch 2024/01/20 17:11:30 1.5 +++ rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch 2024/01/21 16:59:03 1.6 @@ -1,6 +1,6 @@ diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm --- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm 2023-12-19 09:44:56.678590486 +0000 -+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm 2024-01-20 17:01:00.000000000 +0000 ++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm 2024-01-21 16:53:00.000000000 +0000 @@ -140,12 +140,12 @@ my $c = shift; my $title = $c->l("dhcpd_SCANNING_NETWORK_TITLE"); @@ -68,7 +68,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol return "ok"; } -@@ -391,6 +391,118 @@ +@@ -391,6 +391,167 @@ return @leases; } @@ -144,7 +144,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + $binoct = dec2bin($_); + $binmask = $binmask . substr $binoct, -8; + } -+ ++ + # let's count the 1s + @bits = split (//,$binmask); + foreach (@bits) { @@ -152,13 +152,55 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + $bitcount++; + } + } -+ + my $cidr = $network . "/" . $bitcount; + return $cidr; +} + ++sub get_mac_address { ++ # From the leases file ++ my ($ip, $file) = @_; ++ open(my $fh, '<', $file) or die "Could not open file '$file' $!"; ++ my $mac_address = undef; ++ my $lease_block; ++ while(my $line = <$fh>) { ++ if($line =~ /lease $ip {/ .. $line =~ /}/) { ++ $lease_block .= $line; ++ if($line =~ /}/) { ++ if($lease_block =~ /hardware ethernet (\S+);/) { ++ $mac_address = $1; ++ last; ++ } else { ++ $lease_block = ''; ++ } ++ } ++ } ++ } ++ close $fh; ++ return $mac_address; ++} ++ ++sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s }; ++ ++sub get_mac_address_by_ping { ++ my ($ip) = trim(@_); ++ # Ping the IP to ensure it's in the ARP table ++ my $ping_result = `ping -c 1 -W 1 $ip`; ++ if($ping_result =~ /1 packets transmitted, 1 received/) { ++ # Fetch the ARP table and find the line with the IP address ++ my $arp_result = `arp -an | grep "\($ip)"`; ++ # If found, return the MAC address ++ return $arp_result; ++ if ($arp_result =~ /.*at ((?:[0-9a-f]{2}\:){5}[0-9a-f]{2})/) { ++ return $1; ++ } else { return "not in arp table"} ++ } else { return "no ping"} ++ return undef; ++} ++ ++ ++ +sub Scan_Local_Network ($) { -+ ++ + my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); + my $mask = $nmap_sme->get_value('LocalNetmask'); + my $network = $nmap_sme->get_prop('InternalInterface','Network'); @@ -173,11 +215,18 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + /bin/sed -e 's/Nmap//g'|/bin/sed -e 's/|/ /g'`; + + my @extracted_output; ++ my $leasefile = "/var/lib/dhcpd/dhcpd.leases"; + foreach my $line (@nmap_output) { + if ($line =~ m/Scan report for ([\w\.-]+) \(([\d\.\:]+)\)/) { -+ my %pair = ('Network' => $1, 'ip' => $2); # $1 => PC Name, $2 => IP Address -+ push @extracted_output, \%pair; -+ } ++ my $ip = $2; ++ my $mac = get_mac_address($ip,$leasefile); ++ if (!$mac){ ++ $mac = get_mac_address_by_ping($ip); ++ } ++ if (!$mac) {$mac = "unknown";} ++ my %pair = ('Network' => $1, 'ip' => $ip, 'mac' => $mac); # $1 => PC Name, $2 => IP Address ++ push @extracted_output, \%pair; ++ } + } + return \@extracted_output; +} @@ -187,7 +236,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol #========================================================================= # Procedure qui charge le dhcpd.conf # retourne un tableau contenant les informations -@@ -536,4 +648,4 @@ +@@ -536,4 +697,4 @@ 1; @@ -452,8 +501,8 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep --- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep 1970-01-01 01:00:00.000000000 +0100 -+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep 2024-01-20 17:08:00.000000000 +0000 -@@ -0,0 +1,58 @@ ++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep 2024-01-20 17:30:00.000000000 +0000 +@@ -0,0 +1,63 @@ +
+ ++ ++ + + + @@ -481,6 +534,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + + %= t td => (class => 'sme-border') => $ip->{Network} + %= t td => (class => 'sme-border') => $ip->{ip} ++ %= t td => (class => 'sme-border') => $ip->{mac} + + %} +
+ %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd3', onclick=>"showSpinnerNetwork1()", id=>"scanNetwork1" @@ -474,6 +523,10 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol + + %=l 'dhcpd_IP' + ++ %=l 'dhcpd_MAC_ADDRESS' ++