--- 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/23 10:54:38 1.8
@@ -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-23 10:14:00.000000000 +0000
@@ -140,12 +140,12 @@
my $c = shift;
my $title = $c->l("dhcpd_SCANNING_NETWORK_TITLE");
@@ -31,9 +31,12 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
return ;
}
-@@ -352,17 +352,17 @@
+@@ -350,19 +350,19 @@
+ # delete it
+ # If deletion not ok return message
# else return "ok"
- my $ret = delete_lease($c);
+- my $ret = delete_lease($c);
++ my $ret = delete_one_lease($c);
if ($ret == 'ok') {
- dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
+ $dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
@@ -68,7 +71,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
return "ok";
}
-@@ -391,6 +391,118 @@
+@@ -391,6 +391,171 @@
return @leases;
}
@@ -93,8 +96,10 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+ ###Pull CGI object from parameters array
+ my $c = shift;
+
++#my $fred = 1/0;
++
+ ###Pull entry to delete
-+ my $ip = $c->param('host');
++ my $ip = $c->param('ip');
+ my $name = $c->param('name');
+ my $name_in_file = '/var/lib/dhcpd/dhcpd.leases' ;
+ my $name_tmp_file = '/var/lib/dhcpd/dhcpd.leases.tmp' ;
@@ -144,7 +149,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 +157,57 @@ 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`;
++ #return $ping_result;
++ if($ping_result =~ m/1 packets transmitted, 1 received/) {
++ # Fetch the ARP table and find the line with the IP address
++ my $mac_result = `nmap -PR -sn $ip`;
++ #return "*$arp_result *$ip*";
++ # If found, return the MAC address
++ #if ($arp_result =~ m/.*at ((?:[0-9a-f]{2}\:){5}[0-9a-f]{2})/) {
++ if ($mac_result =~ /MAC Address: (..:..:..:..:..:..) /) {
++ return $1;
++ } else { return "mac not in nmap result";}
++ } 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 +222,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 +243,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 +701,4 @@
1;
@@ -381,7 +437,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+1;
diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_leases.html.ep smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_leases.html.ep
--- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_leases.html.ep 2023-12-19 09:44:56.681590497 +0000
-+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_leases.html.ep 2024-01-20 11:29:00.000000000 +0000
++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_leases.html.ep 2024-01-23 10:12:00.000000000 +0000
@@ -1,17 +1,17 @@
@@ -429,21 +485,27 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
% foreach my $ip (@$leases) {
|
%= t td => (class => 'sme-border') => $ip->{ip}
-@@ -66,9 +68,12 @@
+@@ -65,9 +67,7 @@
+ %= t td => (class => 'sme-border') => $ip->{end}
%= t td => (class => 'sme-border') => $ip->{mac}
- <%=l 'dhcpd_REMOVE'%>
+- <%=l 'dhcpd_REMOVE'%>
- |
-+ |
-+
%}
-
-@@ -110,4 +115,4 @@
+@@ -102,7 +102,7 @@
+ function Remove_lease_confirm(event,msg,current){
+ const getIP = /.*ip\=(.*)/;
+ var IP = current.href.match(getIP)[1];
+- if (prompt(msg+" IP: "+IP))
++ if (confirm(msg+" IP: "+IP))
+ { return true;}
+ else {event.preventDefault();return false;}
+ }
+@@ -110,4 +110,4 @@
%end
@@ -452,8 +514,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 @@
+
+
+ %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd3', onclick=>"showSpinnerNetwork1()", id=>"scanNetwork1"
@@ -474,6 +536,10 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+ |
+ %=l 'dhcpd_IP'
+ |
++
++ %=l 'dhcpd_MAC_ADDRESS'
++ |
++
+
+
+
@@ -481,6 +547,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}
+
+ %}
+