LoxiLB UI: select virtual ip from red0 interface

since we added loxilb ip management to add ip on
red0 interface, we can select the virtual ip from
red0 interface.

Signed-off-by: Vincent Li <vincent.mc.li@gmail.com>
This commit is contained in:
Vincent Li
2024-06-19 18:20:57 +00:00
parent 780f556e9c
commit 61d054216d
2 changed files with 36 additions and 2 deletions

View File

@@ -1306,6 +1306,22 @@ sub grab_address_from_file($) {
return;
}
sub get_ipaddresses_from_interface($) {
my ($interface) = @_;
my @ip_addresses;
my $output = `ip addr show $interface 2>/dev/null`;
# Check if the command was successful
if ($? == 0) {
# Extract IP addresses using regex
while ($output =~ /inet (\d+\.\d+\.\d+\.\d+)/g) {
push @ip_addresses, $1;
}
}
return @ip_addresses;
}
# Function to get all configured and enabled nameservers.
sub get_nameservers () {
my %settings;

View File

@@ -288,6 +288,7 @@ my @PROTOCOLS = ("tcp", "udp");
my @ALGO = ("rr", "hash", "priority", "persist", "lc");
my @MODE = ("default", "onearm", "fullnat", "dsr");
my @MONITOR = ("on", "off");
my @VIP = &General::get_ipaddresses_from_interface("red0");
#Edited line number (KEY1) passed until cleared by 'save' or 'remove' or 'new sort order'
print <<END;
@@ -297,9 +298,26 @@ print <<END;
<tr>
<td class='base'>$Lang::tr{'loxilb lb name'}:&nbsp;</td>
<td><input type='text' name='NAME' value='$settings{'NAME'}' size='25'/></td>
</tr><tr>
</tr>
<tr>
<td class='base'>$Lang::tr{'loxilb lb extip'}:&nbsp;</td>
<td><input type='text' name='EXTIP' value='$settings{'EXTIP'}' size='25'/></td>
<td>
<select name='EXTIP' id='extip' style="width: 95px;">
END
foreach (@VIP) {
print "<option value=\"$_\"";
if ($_ eq $settings{'EXTIP'}) {
print " selected=\"selected\"";
}
print ">$_</option>";
}
print <<END;
</select>
</td>
<td class='base'>$Lang::tr{'enabled'}</td>
<td><input type='checkbox' name='EN' $checked{'EN'}{'on'} /></td>
</tr>