/[smecontribs]/rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch
ViewVC logotype

Diff of /rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

Revision 1.5 by brianr, Sat Jan 20 17:11:30 2024 UTC Revision 1.6 by brianr, Sun Jan 21 16:59:03 2024 UTC
# Line 1  Line 1 
1  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  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
2  --- 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.old/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm     2023-12-19 09:44:56.678590486 +0000
3  +++ 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
4  @@ -140,12 +140,12 @@  @@ -140,12 +140,12 @@
5          my $c = shift;          my $c = shift;
6       my $title = $c->l("dhcpd_SCANNING_NETWORK_TITLE");       my $title = $c->l("dhcpd_SCANNING_NETWORK_TITLE");
# Line 68  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 68  diff -urN smeserver-dhcpmanager-2.0.4.ol
68       return "ok";       return "ok";
69   }   }
70    
71  @@ -391,6 +391,118 @@  @@ -391,6 +391,167 @@
72       return @leases;       return @leases;
73   }   }
74    
# Line 144  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 144  diff -urN smeserver-dhcpmanager-2.0.4.ol
144  +      $binoct = dec2bin($_);  +      $binoct = dec2bin($_);
145  +      $binmask = $binmask . substr $binoct, -8;  +      $binmask = $binmask . substr $binoct, -8;
146  +    }  +    }
147  +  +
148  +    # let's count the 1s  +    # let's count the 1s
149  +    @bits = split (//,$binmask);  +    @bits = split (//,$binmask);
150  +    foreach (@bits) {  +    foreach (@bits) {
# Line 152  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 152  diff -urN smeserver-dhcpmanager-2.0.4.ol
152  +        $bitcount++;  +        $bitcount++;
153  +      }  +      }
154  +    }  +    }
 +  
155  +    my $cidr = $network . "/" . $bitcount;  +    my $cidr = $network . "/" . $bitcount;
156  +    return $cidr;  +    return $cidr;
157  +}  +}
158  +  +
159    +sub get_mac_address {
160    +       # From the leases file
161    +    my ($ip, $file) = @_;
162    +    open(my $fh, '<', $file) or die "Could not open file '$file' $!";
163    +    my $mac_address = undef;
164    +    my $lease_block;
165    +    while(my $line = <$fh>) {
166    +        if($line =~ /lease $ip {/ .. $line =~ /}/) {
167    +            $lease_block .= $line;
168    +            if($line =~ /}/) {
169    +                if($lease_block =~ /hardware ethernet (\S+);/) {
170    +                    $mac_address = $1;
171    +                    last;
172    +                } else {
173    +                    $lease_block = '';
174    +                }
175    +            }
176    +        }
177    +    }
178    +    close $fh;
179    +    return $mac_address;
180    +}
181    +
182    +sub  trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
183    +
184    +sub get_mac_address_by_ping {
185    +    my ($ip) = trim(@_);
186    +    # Ping the IP to ensure it's in the ARP table
187    +    my $ping_result = `ping -c 1 -W 1 $ip`;
188    +    if($ping_result =~ /1 packets transmitted, 1 received/) {
189    +        # Fetch the ARP table and find the line with the IP address
190    +        my $arp_result = `arp -an | grep "\($ip)"`;
191    +        # If found, return the MAC address
192    +        return $arp_result;
193    +        if ($arp_result =~ /.*at ((?:[0-9a-f]{2}\:){5}[0-9a-f]{2})/) {
194    +            return $1;
195    +        } else { return "not in arp table"}
196    +    } else { return "no ping"}
197    +    return undef;
198    +}
199    +
200    +
201    +
202  +sub Scan_Local_Network ($) {            +sub Scan_Local_Network ($) {          
203  +      +  
204  +        my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration');  +        my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration');
205  +        my $mask = $nmap_sme->get_value('LocalNetmask');  +        my $mask = $nmap_sme->get_value('LocalNetmask');
206  +        my $network = $nmap_sme->get_prop('InternalInterface','Network');  +        my $network = $nmap_sme->get_prop('InternalInterface','Network');
# Line 173  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 215  diff -urN smeserver-dhcpmanager-2.0.4.ol
215  +                               /bin/sed -e 's/Nmap//g'|/bin/sed -e 's/|/  /g'`;  +                               /bin/sed -e 's/Nmap//g'|/bin/sed -e 's/|/  /g'`;
216  +        +      
217  +    my @extracted_output;  +    my @extracted_output;
218    +    my $leasefile = "/var/lib/dhcpd/dhcpd.leases";
219  +    foreach my $line (@nmap_output) {  +    foreach my $line (@nmap_output) {
220  +        if ($line =~ m/Scan report for ([\w\.-]+) \(([\d\.\:]+)\)/) {  +        if ($line =~ m/Scan report for ([\w\.-]+) \(([\d\.\:]+)\)/) {
221  +            my %pair = ('Network' => $1, 'ip' => $2);  # $1 => PC Name, $2 => IP Address  +                       my $ip = $2;
222  +            push @extracted_output, \%pair;  +                       my $mac = get_mac_address($ip,$leasefile);
223  +        }  +                       if (!$mac){
224    +                               $mac = get_mac_address_by_ping($ip);
225    +                       }
226    +                       if (!$mac) {$mac = "unknown";}
227    +                       my %pair = ('Network' => $1, 'ip' => $ip, 'mac' => $mac);  # $1 => PC Name, $2 => IP Address
228    +                       push @extracted_output, \%pair;
229    +       }
230  +    }  +    }
231  +    return \@extracted_output;  +    return \@extracted_output;
232  +}  +}
# Line 187  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 236  diff -urN smeserver-dhcpmanager-2.0.4.ol
236   #=========================================================================   #=========================================================================
237   # Procedure qui charge le dhcpd.conf   # Procedure qui charge le dhcpd.conf
238   # retourne un tableau contenant les informations   # retourne un tableau contenant les informations
239  @@ -536,4 +648,4 @@  @@ -536,4 +697,4 @@
240    
241   1;   1;
242    
# Line 452  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 501  diff -urN smeserver-dhcpmanager-2.0.4.ol
501  +</div>  +</div>
502  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  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
503  --- 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.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scan.html.ep       1970-01-01 01:00:00.000000000 +0100
504  +++ 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  +++ 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
505  @@ -0,0 +1,58 @@  @@ -0,0 +1,63 @@
506  +<div id='dhcpd-scan'>  +<div id='dhcpd-scan'>
507  +       <table><tr><td>  +       <table><tr><td>
508  +       %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd3', onclick=>"showSpinnerNetwork1()", id=>"scanNetwork1"  +       %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd3', onclick=>"showSpinnerNetwork1()", id=>"scanNetwork1"
# Line 474  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 523  diff -urN smeserver-dhcpmanager-2.0.4.ol
523  +                       <th class='sme-border'>  +                       <th class='sme-border'>
524  +                               %=l 'dhcpd_IP'  +                               %=l 'dhcpd_IP'
525  +                       </th>  +                       </th>
526    +                       <th class='sme-border'>
527    +                               %=l 'dhcpd_MAC_ADDRESS'
528    +                       </th>
529    +
530  +               </tr>  +               </tr>
531  +               </thead>  +               </thead>
532  +               <tbody>  +               <tbody>
# Line 481  diff -urN smeserver-dhcpmanager-2.0.4.ol Line 534  diff -urN smeserver-dhcpmanager-2.0.4.ol
534  +        <tr>  +        <tr>
535  +                       %= t td => (class => 'sme-border') => $ip->{Network}  +                       %= t td => (class => 'sme-border') => $ip->{Network}
536  +                       %= t td => (class => 'sme-border') => $ip->{ip}  +                       %= t td => (class => 'sme-border') => $ip->{ip}
537    +                       %= t td => (class => 'sme-border') => $ip->{mac}
538  +               </tr>  +               </tr>
539  +               %}  +               %}
540  +               </tbody>  +               </tbody>


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed