From f8ec917bc502630f8c40a4a6ce26344151eb932b Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 16 Aug 2023 13:01:17 +0300 Subject: [PATCH 1/4] Revert "Fix to priorities `ip` command usage" This reverts commit 3b36dfa8ad90b077407209f852af59eb29f54a99. --- net/linux-lib.pl | 122 +++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/net/linux-lib.pl b/net/linux-lib.pl index b17de5d45..709c847fa 100755 --- a/net/linux-lib.pl +++ b/net/linux-lib.pl @@ -269,42 +269,7 @@ if (!&has_command("ifconfig") && &has_command("ip")) { } my $cmd; -if (&has_command("ip")) { - # If the IP is changing, first remove it then re-add - my $readd = 0; - if ($old && $old->{'address'}) { - if ($old->{'address'} ne $a->{'address'} || - $old->{'netmask'} ne $a->{'netmask'}) { - my $rcmd = "ip addr del ".quotemeta($old->{'address'}). - "/".&mask_to_prefix($old->{'netmask'}). - " dev ".quotemeta($a->{'name'}); - &system_logged("$rcmd >/dev/null 2>&1"); - $readd = 1; - } - } - else { - $readd = 1; - } - - # Build ip command to add the new IP - if ($readd) { - $cmd .= "ip addr add ".quotemeta($a->{'address'}); - if ($a->{'netmask'}) { - $cmd .= "/".&mask_to_prefix($a->{'netmask'}); - } - if ($a->{'broadcast'}) { - $cmd .= " broadcast ".quotemeta($a->{'broadcast'}); - } - if($a->{'vlan'} == 1) { - $cmd .= " dev ".quotemeta($a->{'physical'}).".". - quotemeta($a->{'vlanid'}); - } - else { - $cmd .= " dev ".quotemeta($a->{'name'}); - } - } - } -elsif (&use_ifup_command($a)) { +if (&use_ifup_command($a)) { # Use Debian / Redhat ifup command if($a->{'vlan'} == 1) { # Name and fullname for VLAN tagged interfaces are "auto" so @@ -360,6 +325,41 @@ elsif (&has_command("ifconfig")) { $cmd .= " down"; } } +elsif (&has_command("ip")) { + # If the IP is changing, first remove it then re-add + my $readd = 0; + if ($old && $old->{'address'}) { + if ($old->{'address'} ne $a->{'address'} || + $old->{'netmask'} ne $a->{'netmask'}) { + my $rcmd = "ip addr del ".quotemeta($old->{'address'}). + "/".&mask_to_prefix($old->{'netmask'}). + " dev ".quotemeta($a->{'name'}); + &system_logged("$rcmd >/dev/null 2>&1"); + $readd = 1; + } + } + else { + $readd = 1; + } + + # Build ip command to add the new IP + if ($readd) { + $cmd .= "ip addr add ".quotemeta($a->{'address'}); + if ($a->{'netmask'}) { + $cmd .= "/".&mask_to_prefix($a->{'netmask'}); + } + if ($a->{'broadcast'}) { + $cmd .= " broadcast ".quotemeta($a->{'broadcast'}); + } + if($a->{'vlan'} == 1) { + $cmd .= " dev ".quotemeta($a->{'physical'}).".". + quotemeta($a->{'vlanid'}); + } + else { + $cmd .= " dev ".quotemeta($a->{'name'}); + } + } + } else { &error("Both the ifconfig and ip commands are missing"); } @@ -439,31 +439,7 @@ elsif ($a->{'virtual'} eq '' && &has_command("ip")) { sub deactivate_interface { my ($a) = @_; -if (&has_command("ip")) { - # Use new ip command to remove all IPs - my @del; - if ($a->{'address'}) { - push(@del, $a->{'address'}."/". - &mask_to_prefix($a->{'netmask'})); - } - for(my $i=0; $i<@{$a->{'address6'}}; $i++) { - push(@del, $a->{'address6'}->[$i]."/". - $a->{'netmask6'}->[$i]); - } - foreach my $d (@del) { - my $cmd = "ip addr del ".quotemeta($d)." dev ". - quotemeta($a->{'name'}); - my $out = &backquote_logged("$cmd 2>&1"); - &error("Failed to remove old address : $out") if ($?); - } - - if ($a->{'virtual'} eq '') { - my $cmd = "ip link set dev ".quotemeta($a->{'name'})." down"; - my $out = &backquote_logged("$cmd 2>&1"); - &error("
".&html_escape($out)."
") if ($?); - } - } -elsif (&has_command("ifconfig")) { +if (&has_command("ifconfig")) { # Use old ifconfig command my $name = $a->{'name'}. ($a->{'virtual'} ne "" ? ":$a->{'virtual'}" : ""); @@ -509,6 +485,30 @@ elsif (&has_command("ifconfig")) { } } } +elsif (&has_command("ip")) { + # Use new ip command to remove all IPs + my @del; + if ($a->{'address'}) { + push(@del, $a->{'address'}."/". + &mask_to_prefix($a->{'netmask'})); + } + for(my $i=0; $i<@{$a->{'address6'}}; $i++) { + push(@del, $a->{'address6'}->[$i]."/". + $a->{'netmask6'}->[$i]); + } + foreach my $d (@del) { + my $cmd = "ip addr del ".quotemeta($d)." dev ". + quotemeta($a->{'name'}); + my $out = &backquote_logged("$cmd 2>&1"); + &error("Failed to remove old address : $out") if ($?); + } + + if ($a->{'virtual'} eq '') { + my $cmd = "ip link set dev ".quotemeta($a->{'name'})." down"; + my $out = &backquote_logged("$cmd 2>&1"); + &error("
".&html_escape($out)."
") if ($?); + } + } else { &error("Both the ifconfig and ip commands are missing"); } From 185e7db58d179438b620dbcfa78b3d3bd1b9e067 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 16 Aug 2023 13:03:51 +0300 Subject: [PATCH 2/4] Revert "Revert "Fix to priorities `ip` command usage"" This reverts commit f8ec917bc502630f8c40a4a6ce26344151eb932b. --- net/linux-lib.pl | 122 +++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/net/linux-lib.pl b/net/linux-lib.pl index 709c847fa..b17de5d45 100755 --- a/net/linux-lib.pl +++ b/net/linux-lib.pl @@ -269,7 +269,42 @@ if (!&has_command("ifconfig") && &has_command("ip")) { } my $cmd; -if (&use_ifup_command($a)) { +if (&has_command("ip")) { + # If the IP is changing, first remove it then re-add + my $readd = 0; + if ($old && $old->{'address'}) { + if ($old->{'address'} ne $a->{'address'} || + $old->{'netmask'} ne $a->{'netmask'}) { + my $rcmd = "ip addr del ".quotemeta($old->{'address'}). + "/".&mask_to_prefix($old->{'netmask'}). + " dev ".quotemeta($a->{'name'}); + &system_logged("$rcmd >/dev/null 2>&1"); + $readd = 1; + } + } + else { + $readd = 1; + } + + # Build ip command to add the new IP + if ($readd) { + $cmd .= "ip addr add ".quotemeta($a->{'address'}); + if ($a->{'netmask'}) { + $cmd .= "/".&mask_to_prefix($a->{'netmask'}); + } + if ($a->{'broadcast'}) { + $cmd .= " broadcast ".quotemeta($a->{'broadcast'}); + } + if($a->{'vlan'} == 1) { + $cmd .= " dev ".quotemeta($a->{'physical'}).".". + quotemeta($a->{'vlanid'}); + } + else { + $cmd .= " dev ".quotemeta($a->{'name'}); + } + } + } +elsif (&use_ifup_command($a)) { # Use Debian / Redhat ifup command if($a->{'vlan'} == 1) { # Name and fullname for VLAN tagged interfaces are "auto" so @@ -325,41 +360,6 @@ elsif (&has_command("ifconfig")) { $cmd .= " down"; } } -elsif (&has_command("ip")) { - # If the IP is changing, first remove it then re-add - my $readd = 0; - if ($old && $old->{'address'}) { - if ($old->{'address'} ne $a->{'address'} || - $old->{'netmask'} ne $a->{'netmask'}) { - my $rcmd = "ip addr del ".quotemeta($old->{'address'}). - "/".&mask_to_prefix($old->{'netmask'}). - " dev ".quotemeta($a->{'name'}); - &system_logged("$rcmd >/dev/null 2>&1"); - $readd = 1; - } - } - else { - $readd = 1; - } - - # Build ip command to add the new IP - if ($readd) { - $cmd .= "ip addr add ".quotemeta($a->{'address'}); - if ($a->{'netmask'}) { - $cmd .= "/".&mask_to_prefix($a->{'netmask'}); - } - if ($a->{'broadcast'}) { - $cmd .= " broadcast ".quotemeta($a->{'broadcast'}); - } - if($a->{'vlan'} == 1) { - $cmd .= " dev ".quotemeta($a->{'physical'}).".". - quotemeta($a->{'vlanid'}); - } - else { - $cmd .= " dev ".quotemeta($a->{'name'}); - } - } - } else { &error("Both the ifconfig and ip commands are missing"); } @@ -439,7 +439,31 @@ elsif ($a->{'virtual'} eq '' && &has_command("ip")) { sub deactivate_interface { my ($a) = @_; -if (&has_command("ifconfig")) { +if (&has_command("ip")) { + # Use new ip command to remove all IPs + my @del; + if ($a->{'address'}) { + push(@del, $a->{'address'}."/". + &mask_to_prefix($a->{'netmask'})); + } + for(my $i=0; $i<@{$a->{'address6'}}; $i++) { + push(@del, $a->{'address6'}->[$i]."/". + $a->{'netmask6'}->[$i]); + } + foreach my $d (@del) { + my $cmd = "ip addr del ".quotemeta($d)." dev ". + quotemeta($a->{'name'}); + my $out = &backquote_logged("$cmd 2>&1"); + &error("Failed to remove old address : $out") if ($?); + } + + if ($a->{'virtual'} eq '') { + my $cmd = "ip link set dev ".quotemeta($a->{'name'})." down"; + my $out = &backquote_logged("$cmd 2>&1"); + &error("
".&html_escape($out)."
") if ($?); + } + } +elsif (&has_command("ifconfig")) { # Use old ifconfig command my $name = $a->{'name'}. ($a->{'virtual'} ne "" ? ":$a->{'virtual'}" : ""); @@ -485,30 +509,6 @@ if (&has_command("ifconfig")) { } } } -elsif (&has_command("ip")) { - # Use new ip command to remove all IPs - my @del; - if ($a->{'address'}) { - push(@del, $a->{'address'}."/". - &mask_to_prefix($a->{'netmask'})); - } - for(my $i=0; $i<@{$a->{'address6'}}; $i++) { - push(@del, $a->{'address6'}->[$i]."/". - $a->{'netmask6'}->[$i]); - } - foreach my $d (@del) { - my $cmd = "ip addr del ".quotemeta($d)." dev ". - quotemeta($a->{'name'}); - my $out = &backquote_logged("$cmd 2>&1"); - &error("Failed to remove old address : $out") if ($?); - } - - if ($a->{'virtual'} eq '') { - my $cmd = "ip link set dev ".quotemeta($a->{'name'})." down"; - my $out = &backquote_logged("$cmd 2>&1"); - &error("
".&html_escape($out)."
") if ($?); - } - } else { &error("Both the ifconfig and ip commands are missing"); } From 5156a472be6b5d587fc509ad11f0ec684ac224e6 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 16 Aug 2023 13:48:54 +0300 Subject: [PATCH 3/4] Fix a bug in regex to correctly grep wack [build] https://sourceforge.net/p/webadmin/discussion/55377/thread/78e5aa05f3 --- net/linux-lib.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/linux-lib.pl b/net/linux-lib.pl index b17de5d45..f3d0d9910 100755 --- a/net/linux-lib.pl +++ b/net/linux-lib.pl @@ -57,7 +57,7 @@ if (&has_command("ip")) { $ifc{'address'} = $1; $ifc{'netmask'} = &prefix_to_mask("$3"); } - elsif ($l =~ /\sinet\s+([0-9\.]+)\/\d+\s+(?:metric\s+\d+\s+|)brd\s+(\S+)\s+scope\s+global(?:\s+secondary|)\s(dynamic)\s+.*?(\Q$iface_name\E)/) { + elsif ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)\s+(?:metric\s+\d+\s+|)brd\s+(\S+)\s+scope\s+global(?:\s+secondary|)\s(dynamic)\s+.*?(\Q$iface_name\E)/) { # Line like : # inet 193.9.101.120/24 brd 193.9.101.255 scope global secondary dynamic br0 # inet 10.211.55.81/24 metric 100 brd 10.211.55.255 scope global secondary dynamic enp0s5 From dd1b4bc77b826ee9c254fca01c87cefeef4fc4ee Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 16 Aug 2023 15:12:18 +0300 Subject: [PATCH 4/4] Fix to also set `UCF_FORCE_CONFFOLD` variable https://github.com/virtualmin/virtualmin-gpl/issues/612 --- software/apt-lib.pl | 2 ++ software/debian-lib.pl | 1 + 2 files changed, 3 insertions(+) diff --git a/software/apt-lib.pl b/software/apt-lib.pl index 3785e308c..49827265b 100755 --- a/software/apt-lib.pl +++ b/software/apt-lib.pl @@ -20,6 +20,7 @@ local $force = !$_[2]; local (@rv, @newpacks); # Build the command to run +$ENV{'UCF_FORCE_CONFFOLD'} = 'YES'; $ENV{'DEBIAN_FRONTEND'} = 'noninteractive'; local $uicmd = "$apt_get_command -y ".($force ? " -f" : "")." install $update"; $update = join(" ", map { quotemeta($_) } split(/\s+/, $update)); @@ -75,6 +76,7 @@ return @rv; sub update_system_operations { my ($packages) = @_; +$ENV{'UCF_FORCE_CONFFOLD'} = 'YES'; $ENV{'DEBIAN_FRONTEND'} = 'noninteractive'; my $cmd = "apt-get -s install ". join(" ", map { quotemeta($_) } split(/\s+/, $packages)). diff --git a/software/debian-lib.pl b/software/debian-lib.pl index e2635c238..60c98ae5e 100755 --- a/software/debian-lib.pl +++ b/software/debian-lib.pl @@ -202,6 +202,7 @@ local $args = ($in->{'depends'} ? " --force-depends" : ""). ($in->{'overwrite'} ? " --force-overwrite" : ""). ($in->{'downgrade'} ? " --force-downgrade" : ""); local $qm = quotemeta($_[0]); +$ENV{'UCF_FORCE_CONFFOLD'} = 'YES'; $ENV{'DEBIAN_FRONTEND'} = 'noninteractive'; local $out = &backquote_logged("dpkg --install $args $qm 2>&1