add drop down menu for interfaces
This commit is contained in:
61
settings.pl
61
settings.pl
@@ -22,6 +22,61 @@
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
sub html_escape( $ )
|
||||
{
|
||||
my $s = $_[0];
|
||||
$s = '' unless defined $s;
|
||||
$s =~ s/&/&/g;
|
||||
$s =~ s/</</g;
|
||||
$s =~ s/>/>/g;
|
||||
$s =~ s/"/"/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">
|
||||
|
||||
Reference in New Issue
Block a user