# # SMArT # # Handle /settings/ requests # # Copyright 2001 Wilmer van der Gaast (lintux@lintux.cx) # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # 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 settings_nav_bar() { return <<'EOF_NAV';
EOF_NAV } sub delete_confirm_attr( $ ) { my $what = html_escape( $_[0] ); return ' onclick="return confirm(\'Delete ' . $what . '?\')"'; } $settings_nav_bar = settings_nav_bar(); sub kernel_network_interfaces() { my %interfaces = (); if( opendir( my $dh, '/sys/class/net' ) ) { foreach my $ifname ( readdir( $dh ) ) { next if $ifname =~ /^\./; next if $ifname =~ /[^-_\.A-Za-z0-9]/; $interfaces{$ifname} = 1; } closedir( $dh ); } return %interfaces; } sub ipx_enabled_interfaces() { my %ipx_interfaces = (); # Modern Linux IPX procfs format: # Network Node_Address Primary Device Frame_Type # AC100B98 000000000001 Yes Internal None # 00000022 508140F6AC45 No enp46s0u1u3u3 802.2 if( open( my $fh, '<', '/proc/net/ipx/interface' ) ) { while( my $line = <$fh> ) { chomp( $line ); $line =~ s/^\s+//; $line =~ s/\s+$//; next if $line eq ''; next if $line =~ /^Network\s+Node_Address\s+Primary\s+Device\s+Frame_Type/i; my @fields = split( /\s+/, $line ); # Device is the fourth column. Do not scan all tokens, otherwise # Network/Node/Frame_Type values can accidentally be treated as names. next if scalar( @fields ) < 5; my $dev = $fields[3]; next if ! defined( $dev ); next if $dev eq ''; next if lc( $dev ) eq 'internal'; next if $dev =~ /[^-_\.A-Za-z0-9]/; # Only show real Linux network interfaces. next if ! -e '/sys/class/net/' . $dev; $ipx_interfaces{$dev} = 1; } close( $fh ); } # Fallback for older distributions/tools, if present. This parser is kept # deliberately conservative and still verifies /sys/class/net/