--- rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch 2023/12/31 14:45:40 1.2
+++ rpms/smeserver-dhcpmanager/contribs10/smeserver-dhcpmanager-2.0.4-Yet-more-changes-for-SM2-panels.patch 2024/01/20 17:11:30 1.5
@@ -1,62 +1,7 @@
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 2023-12-31 13:44:00.000000000 +0000
-@@ -117,22 +117,41 @@
- $c->render( template => 'dhcpd' );
- }
-
--
--sub do_winpopup {
-- #
-- # call to win pop up
-- #
-+sub netmask2cidr {
- my $c = shift;
-- my $title = $c->l("dhcpd_GLOBAL_WINPOPUP");
-- my $modul = '';
-- my $trt = "WINPOPUP";
-- $dhcp_data{trt} = $trt;
-- $dhcp_data{"first"} = '';
-- #..... get winpopup details
-- $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data );
-- $c->render( template => 'dhcpd' );
-+ #my ($mask, $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');
-+ my @octet = split (/\./, $mask);
-+ my @bits;
-+ my $binmask;
-+ my $binoct;
-+ my $bitcount=0;
-+
-+ foreach (@octet) {
-+ $binoct = dec2bin($_);
-+ $binmask = $binmask . substr $binoct, -8;
-+ }
-+
-+ # let's count the 1s
-+ @bits = split (//,$binmask);
-+ foreach (@bits) {
-+ if ($_ eq "1") {
-+ $bitcount++;
-+ }
-+ }
-+
-+ my $cidr = $network . "/" . $bitcount;
-+ return $cidr;
- }
-
-+sub dec2bin {
-+ my $str = unpack("B32", pack("N", shift));
-+ return $str;
-+}
-+
-+
- sub do_scan {
- #
- # call to show scan results
-@@ -140,12 +159,13 @@
++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/Controller/Dhcpd.pm 2024-01-20 17:01:00.000000000 +0000
+@@ -140,12 +140,12 @@
my $c = shift;
my $title = $c->l("dhcpd_SCANNING_NETWORK_TITLE");
my $modul = '';
@@ -64,29 +9,21 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+ my $trt = "SCAN";
$dhcp_data{trt} = $trt;
$dhcp_data{"first"} = '';
- # ..... get scan results into dhcp_data
+- # ..... get scan results into dhcp_data
- dhcp_data{"scanresults"} = get_scan_results($c);
- $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data );
-+ $dhcp_data{"cidr"} = netmask2cidr($c);
-+ my @scanresults = get_scan_results($c);
-+ $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data, scanresults => @scanresults );
++ # ..... get scan results into stash for passing to html template
++ my $dhcp_scanresults = get_scan_results($c);
++ $c->stash( title => $title, modul => $modul, "dhcp_data" => \%dhcp_data, "scanresults" => $dhcp_scanresults);
$c->render( template => 'dhcpd' );
}
-@@ -314,7 +334,6 @@
- }
- }
-
--
- # - 4 expand templates
- # changed to new sme standard signal-event
- system ("/sbin/e-smith/signal-event","workgroup-update") == 0
-@@ -332,10 +351,10 @@
+@@ -332,10 +332,10 @@
my $c = shift;
my $ret = delete_all_leases($c);
if ($ret == 'ok') {
- dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
-+ $dhcp_data{"success"}="dhcpd_SUCCESSFULLY_REMOVED_ALL_LEASES";
++ $dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
do_leases($c);
}
- else {dhcp_data{"error"}=$ret;}
@@ -94,12 +31,12 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
return ;
}
-@@ -352,17 +371,39 @@
+@@ -352,17 +352,17 @@
# else return "ok"
my $ret = delete_lease($c);
if ($ret == 'ok') {
- dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
-+ $dhcp_data{"success"}="dhcpd_SUCCESSFULLY_DELETED_THE_CLIENT";
++ $dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
do_leases($c);
}
- else {dhcp_data{"error"}=$ret;}
@@ -109,40 +46,52 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
sub get_scan_results {
my $c = shift;
-- #...do it
+ #...do it
- return "results";
-+ my $cidr = netmask2cidr($c);
-+ my $res = execute_nmap($cidr);
-+ return $res;
-+}
-+
-+sub execute_nmap {
-+ my ($ip, $port) = @_;
-+ my @result;
-+ my $nmapcmd = qq(/usr/bin/nmap --script smb-os-discovery.nse -p U:137,T:139 $ip| \
-+ /bin/grep -Ev "MAC|NetBIOS|OS CPE"| /bin/grep -E "scan|done|Computer|OS"| \
-+ /bin/sed -e 's/Nmap scan/-- Scan/g'|/bin/sed -e 's/done/Done/g'| \
-+ /bin/sed -e 's/Nmap//g'|/bin/sed -e 's/|/ /g');
-+
-+ open my $nmap, '-|', "$nmapcmd" or die "Can't start nmap: $!";
-+
-+ while (my $line = <$nmap>) {
-+ chomp $line;
-+ my @fields = split /\s+/, $line;
-+ push @result, \@fields;
-+ }
-+
-+ close $nmap;
-+
-+ return \@result;
++ return Scan_Local_Network($c);
}
-@@ -374,13 +415,45 @@
+@@ -374,13 +374,13 @@
sub delete_one_lease {
my $c = shift;
- # ...do it
++ Perform_Del_Lease($c);
+ return "ok";
+ }
+
+ sub delete_all_leases {
+ my $c = shift;
+- # ...do it
++ Perform_del_all_Lease($c);
+ return "ok";
+ }
+
+@@ -391,6 +391,118 @@
+ return @leases;
+ }
+
++
++sub Perform_del_all_Lease ($){
++
++ system ('/bin/echo "" > /var/lib/dhcpd/dhcpd.leases') ==0
++ or die "Error while removing all leases: $!";
++
++ system ("/sbin/e-smith/signal-event","workgroup-update") == 0
++ or die "Error while saving settings: $!";
++
++ return 'ok';
++ exit;
++}
++
++#===============================================================================
++#SUBROUTINE: Perform delete lease
++#===============================================================================
++sub Perform_Del_Lease($){
++
++ ###Pull CGI object from parameters array
++ my $c = shift;
+
+ ###Pull entry to delete
+ my $ip = $c->param('host');
@@ -171,36 +120,74 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+ # changed to new sme standard signal-event
+ system ("/sbin/e-smith/signal-event","workgroup-update") == 0
+ or die "Error while saving settings: $!";
- return "ok";
- }
-
- sub delete_all_leases {
- my $c = shift;
-- # ...do it
-+ system ('/bin/echo "" > /var/lib/dhcpd/dhcpd.leases') ==0
-+ or die "Error while removing all leases: $!";
-+
-+ system ("/sbin/e-smith/signal-event","workgroup-update") == 0
-+ or die "Error while saving settings: $!";
-+
- return "ok";
- }
-
-@@ -498,13 +571,6 @@
- return @results;
- }
-
--sub winpopup{
-- my $c = shift;
-- # Message in $c->param("winpopupmsg")
-- # .... do it
-- return TRUE;
--}
--
- sub do_wol{
- my $c = shift;
- my $retVal = Perform_Wake_Up($c);
-@@ -536,4 +602,4 @@
++ ###Return action message
++ return $c->l('SUCCESSFULLY_DELETED_THE_CLIENT') . ' (' . $name . '/' . $ip .')';
++}
++
++#===============================================================================
++#SUBROUTINE: Scan The Local Network
++#===============================================================================
++sub dec2bin {
++ my $str = unpack("B32", pack("N", shift));
++ return $str;
++}
++
++sub netmask2cidr {
++ my ($mask, $network) = @_;
++ my @octet = split (/\./, $mask);
++ my @bits;
++ my $binmask;
++ my $binoct;
++ my $bitcount=0;
++
++ foreach (@octet) {
++ $binoct = dec2bin($_);
++ $binmask = $binmask . substr $binoct, -8;
++ }
++
++ # let's count the 1s
++ @bits = split (//,$binmask);
++ foreach (@bits) {
++ if ($_ eq "1") {
++ $bitcount++;
++ }
++ }
++
++ my $cidr = $network . "/" . $bitcount;
++ return $cidr;
++}
++
++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');
++
++#we start to calculate the method to find the cidr (we want to use network/cidr with nmap)
++ my $cidr = netmask2cidr($mask, $network);
++
++#ok go to use nmap with nmap -T4 -sP network/cidr
++ my @nmap_output= `/usr/bin/nmap --script smb-os-discovery.nse -p U:137,T:139 $cidr|
++ /bin/grep -Ev "MAC|NetBIOS|OS CPE"| /bin/grep -E "scan|done|Computer|OS"|
++ /bin/sed -e 's/Nmap scan/-- Scan/g'|/bin/sed -e 's/done/Done/g'|
++ /bin/sed -e 's/Nmap//g'|/bin/sed -e 's/|/ /g'`;
++
++ my @extracted_output;
++ 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;
++ }
++ }
++ return \@extracted_output;
++}
++
++
++
+ #=========================================================================
+ # Procedure qui charge le dhcpd.conf
+ # retourne un tableau contenant les informations
+@@ -536,4 +648,4 @@
1;
@@ -209,7 +196,7 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+
diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dhcpd/en.pm smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dhcpd/en.pm
--- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dhcpd/en.pm 1970-01-01 01:00:00.000000000 +0100
-+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dhcpd/en.pm 2023-12-30 11:30:00.000000000 +0000
++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Dhcpd/en.pm 2024-01-20 08:46:00.000000000 +0000
@@ -0,0 +1,109 @@
+package SrvMngr::I18N::Modules::Dhcpd::en;
+use strict;
@@ -322,81 +309,108 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
+1;
diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/dhcpd.html.ep smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/dhcpd.html.ep
--- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/dhcpd.html.ep 2023-12-19 09:44:56.680590493 +0000
-+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/dhcpd.html.ep 2023-12-31 13:55:00.000000000 +0000
-@@ -49,23 +49,30 @@
++++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/dhcpd.html.ep 2024-01-20 17:01:00.000000000 +0000
+@@ -49,24 +49,26 @@
% if ($dhcp_data->{trt} eq 'LEASES') {
%= include 'partials/_dhcpd_leases'
- %} elsif ($dhcp_data->{trt} eq 'WINPOPUP') {
- %= include 'partials/_dhcpd_winpopup'
%} elsif ($dhcp_data->{trt} eq 'SCAN') {
-- %= include 'partials/_dhcpd_scan'
-+ %= include 'partials/_dhcpd_scanresults'
+ %= include 'partials/_dhcpd_scan'
%} else { #PARAMS
% my $ip_regex = '^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$';
-
+-
- %= button_to $c->l('dhcpd_CONNECTED_IP') => '/dhcpd1', onclick=>"showSpinner()", id=>"scanLeases"
- |
+-
+-
+- |
- %= button_to $c->l('dhcpd_SCAN_YOUR_NETWORK') => '/dhcpd3'
- |
- %= button_to $c->l('dhcpd_GLOBAL_WINPOPUP') => '/dhcpd2'
-+ %= button_to $c->l('dhcpd_SCAN_YOUR_NETWORK') => '/dhcpd3', onclick=>"showNetworkSpinner()", id=>"scanNetwork"
-+
-+ Scanning
-+
-+
-+
-+ |
-+
-
+-
+-
++
++
++
++ %= button_to $c->l('dhcpd_CONNECTED_IP') => '/dhcpd1', onclick=>"showSpinnerLeases()", id=>"scanLeases"
++
++ Scanning
++
++
++ |
++ %= button_to $c->l('dhcpd_SCAN_YOUR_NETWORK') => '/dhcpd3', onclick=>"showSpinnerNetwork()", id=>"scanNetwork"
++
++ Scanning
++
++
++ |
++
-@@ -179,10 +186,15 @@
-
+
+@@ -180,10 +182,17 @@
%= javascript begin
-- document.getElementById("load").style.display="none";
+ document.getElementById("load").style.display="none";
- function showSpinner(){
-+ document.getElementById("loadLeases").style.display="none";
-+ document.getElementById("loadNetwork").style.display="none";
-+ function showLeasesSpinner(){
++ document.getElementById("loadingNetwork").style.display="none";
++
++ function showSpinnerLeases(){
document.getElementById("scanLeases").style.display="none";
-- document.getElementById("load").style.display="inline";
-+ document.getElementById("loadLeases").style.display="inline";
-+ }
-+ function showNetworkSpinner(){
-+ document.getElementById("scanNetwork").style.display="none";
-+ document.getElementById("loadNetwork").style.display="inline";
+ document.getElementById("load").style.display="inline";
}
++
++ function showSpinnerNetwork(){
++ document.getElementById("scanNetwork").style.display="none";
++ document.getElementById("loadingNetwork").style.display="inline";
++ }
%end
+ %= stylesheet begin
+@@ -205,7 +214,6 @@
+ border-color: darkgrey;
+ border-image: initial;
+ }
+-
+ %end
+-
+ %end
++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 2023-12-31 14:11:00.000000000 +0000
-@@ -1,8 +1,8 @@
++++ 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
+@@ -1,17 +1,17 @@
- %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd1', onclick=>"showSpinner()", id=>"scanLeases"
-
- Scanning
-+ %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd1', onclick=>"showLeaseSpinner()", id=>"scanLeases"
-+
-+ Scanning
-
-
-
+-
+-
+-
+- |
+- %= button_to $c->l('dhcpd_REMOVE_ALL_LEASES') => '/dhcpd4'
+- |
+-
++ %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd1', onclick=>"showSpinnerLeases()", id=>"scanLeases"
++
++ Scanning
++
++
++
++
++ %= button_to $c->l('dhcpd_REMOVE_ALL_LEASES') => '/dhcpd4'
++ |
++
+
+-
++
+ % my $btn = l('dhcpd_SAVE/RESTART');
+ %= form_for '/dhcpd10' => (method => 'POST') => begin
+
@@ -26,7 +26,7 @@
%= submit_button "$btn", class => 'action'
% end
@@ -429,77 +443,72 @@ diff -urN smeserver-dhcpmanager-2.0.4.ol
%}
-@@ -78,6 +83,7 @@
- %= button_to $c->l('dhcpd_CLICK_HERE_TO_MAIN_PANEL') => '/dhcpd'
-
- %= javascript begin
-+ document.getElementById("loadLease").style.display="none";
- function Wol_confirm(event,msg,current){
- const getMAC = /.*MAC\=(.*)\&name.*/;
- var MAC = current.href.match(getMAC)[1];
-@@ -110,4 +116,4 @@
+@@ -110,4 +115,4 @@
%end
-
\ No newline at end of file
+
-diff -urN smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scanresults.html.ep smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scanresults.html.ep
---- smeserver-dhcpmanager-2.0.4.old/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scanresults.html.ep 1970-01-01 01:00:00.000000000 +0100
-+++ smeserver-dhcpmanager-2.0.4/root/usr/share/smanager/themes/default/templates/partials/_dhcpd_scanresults.html.ep 2023-12-31 13:59:00.000000000 +0000
-@@ -0,0 +1,55 @@
-+
-+
-+
-+
-+
-+
-+%#= 1/0
-+ %= $c->l('dhcpd_NETWORK_VALUES_FOUND').$dhcp_data->{"cidr"};
-+ %= form_for '/dhcpd10' => (method => 'POST') => begin
-+
-+
+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 @@
++
++
++ %= button_to $c->l('dhcpd_REFRESH') => '/dhcpd3', onclick=>"showSpinnerNetwork1()", id=>"scanNetwork1"
++
++ Scanning
++
++
++
++ |
++
++
++
++
+
-+
++ |
+ %=l 'dhcpd_NETWORK_NAME'
+ |
+
+ %=l 'dhcpd_IP'
+ |
-+
-+ %=l 'dhcpd_MAC_ADDRESS'
-+ |
-+
-+ %=l 'dhcpd_STATUS_CLICK_FOR_WOL'
-+ |
+
+
+
-+ % foreach my $line (@$scanresults) {
-+ % my @thisline = @$line;
-+
-+
-+ %= "$thisline[4]";
-+ |
-+
-+ %= "$thisline[5]";
-+ |
-+
-+ |
-+
-+ |
-+
-+ %}
++ % foreach my $ip (@$scanresults) {
++
++ %= t td => (class => 'sme-border') => $ip->{Network}
++ %= t td => (class => 'sme-border') => $ip->{ip}
++
++ %}
++
+
-+ % end
++ %= hidden_field "hiddenmsg"=>"", id=>"hiddenmsg"
++
+ %= button_to $c->l('dhcpd_CLICK_HERE_TO_MAIN_PANEL') => '/dhcpd'
++
++ %= javascript begin
++ function Wol_confirm(event,msg,current){
++ const getMAC = /.*MAC\=(.*)\&name.*/;
++ var MAC = current.href.match(getMAC)[1];
++ if (confirm(msg+": MAC: "+MAC))
++ { return true;}
++ else {event.preventDefault();return false;}
++ }
++
++
++ %end
++
++
+
-+
++%= javascript begin
++ document.getElementById("loadingNetwork1").style.display="none";
++
++ function showSpinnerNetwork1(){
++ document.getElementById("scanNetwork1").style.display="none";
++ document.getElementById("loadingNetwork1").style.display="inline";
++ }
+
++%end
|
|