add drop down menu for interfaces

This commit is contained in:
Mario Fetka
2026-05-21 16:59:55 +02:00
parent 97ac40f7a1
commit 6aec044c52
2 changed files with 65 additions and 1 deletions

View File

@@ -22,6 +22,61 @@
#
#
sub html_escape( $ )
{
my $s = $_[0];
$s = '' unless defined $s;
$s =~ s/&/&/g;
$s =~ s/</&lt;/g;
$s =~ s/>/&gt;/g;
$s =~ s/"/&quot;/g;
return $s;
}
sub network_interface_options( $ )
{
my $current = $_[0];
my @interfaces = ();
my %seen = ();
my $html = '';
$current = '' unless defined $current;
if( opendir( my $dh, '/sys/class/net' ) )
{
foreach my $ifname ( sort readdir( $dh ) )
{
next if $ifname =~ /^\./;
next if $ifname =~ /[^-_\.A-Za-z0-9]/;
next if $seen{$ifname};
push( @interfaces, $ifname );
$seen{$ifname} = 1;
}
closedir( $dh );
}
# Keep special/manual values usable even if they are not real kernel interfaces.
foreach my $ifname ( '*', 'auto', $current )
{
next if !defined( $ifname ) || $ifname eq '';
next if $seen{$ifname};
push( @interfaces, $ifname );
$seen{$ifname} = 1;
}
foreach my $ifname ( @interfaces )
{
my $selected = ( $ifname eq $current ) ? ' SELECTED' : '';
my $label = $ifname;
$label = '* (all interfaces)' if $ifname eq '*';
$label = 'auto' if $ifname eq 'auto';
$html .= '\t\t\t\t<OPTION VALUE="' . html_escape( $ifname ) . '"' . $selected . '>' . html_escape( $label ) . '</OPTION>\n';
}
return $html;
}
sub handle_request()
{
if( $c[1] eq 'general' )
@@ -1385,6 +1440,7 @@ EOF
{
$c = getconfigline( '4 ' . $c[2] );
@c = split( ' ', $c );
$interface_options = network_interface_options( $c[1] );
$c[2] =~ s/\.//g;
eval( '$frametype_' . $c[2] . ' = " SELECTED";' );
@@ -1453,7 +1509,10 @@ TT { color:#5b4b38; }
<B>Network interface:</B>
</TD>
<TD ALIGN=RIGHT>
<INPUT NAME="interface" TYPE=TEXT SIZE=20 VALUE="$c[1]"><BR>
<SELECT NAME="interface">
$interface_options </SELECT><BR>
<SMALL>Manual override:</SMALL><BR>
<INPUT NAME="interface_manual" TYPE=TEXT SIZE=20 VALUE=""><BR>
</TD>
</TR>
<TR BGCOLOR="#fbf7f1">