From patchwork Tue Dec 22 20:06:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 3745 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4D0nRy4pN4z3wgG for ; Tue, 22 Dec 2020 20:07:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4D0nRt1BSqz35l; Tue, 22 Dec 2020 20:07:06 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4D0nRs5f8kz304H; Tue, 22 Dec 2020 20:07:05 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4D0nRs1FgLz2xff for ; Tue, 22 Dec 2020 20:07:05 +0000 (UTC) Received: from arche.uberspace.de (arche.uberspace.de [185.26.156.147]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4D0nRq5bZSz5s for ; Tue, 22 Dec 2020 20:07:03 +0000 (UTC) Received: (qmail 17517 invoked from network); 22 Dec 2020 20:07:02 -0000 Received: from localhost (HELO localhost) (127.0.0.1) by arche.uberspace.de with SMTP; 22 Dec 2020 20:07:02 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 1/4] zoneconf.cgi: Change NIC display order, improve code Date: Tue, 22 Dec 2020 21:06:43 +0100 Message-Id: <20201222200646.1609-1-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1608667624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xSn2RSepe1SXE705yeN/+ziu1UMuvTGjr8Hx3TU7Irg=; b=hgKwmFrnQNqrLhYxGF5/dMhtLteCIz9RmOEclfxiOCIoBB6kR8P7Bf1H9qebi8XpIH9gJN wPj6sUqxflRdbtNtsBmkolkKb7TvnEXGbNHaXkluvboZZwuXIdOJTrts5HOWXAxHB4ogJr oGcq3bfE02GoVQRDrSHh16Q+wbkMMpPT18/NNGDtg5odC4RxB8ENZE7pJiymPi38rTTsD4 hobfU/nefFg/3r8BoNnEiQtKCN1Vtl3rUvvPX151RJ8WQDum/DHr7CHCRUgp8PNchz2+Nl KRrqjjvhS4ASz9aHip908B6O5kQ6bnuwnoF5vjBy7Lzqw3KBBfyO71OWrWfVrA== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1608667624; a=rsa-sha256; cv=none; b=uU6PqdOKOvdIEVFDBVVaJQPDuFIA0DKbVz/vbj6LJeKfso1MQ0Sep0bfIbGFxuaTgIygwa L8qYQWObbZ8HHEQp+YdwbxHBv07OhXie2BcppFnP95RGhsAWrfgzpxQ4aTDTd+YtX4bQwQ CGtbn1baoHdMQZovoVaLEP/AFvyo/skikg3WXJ7Az24OMAsn+xntNQFFixLH6Fn/+7PuV0 SzQRSaVtSBcd1B2g6di8lzVCMe3Ovy7tcmvUT2NLruWcNFV5s9FMbq73MRGOkcTgp9qG4M uyQtXeqfRWU0q2gY+8+s5SXq5RkqwvBnIYd7cU6meMiCodhw7kvAnNmLoZagFQ== X-Spamd-Result: default: False [1.69 / 11.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; IP_REPUTATION_HAM(-0.01)[asn: 205766(0.00), country: DE(-0.00), ip: 185.26.156.147(0.00)]; MID_CONTAINS_FROM(1.00)[]; R_SPF_ALLOW(-0.20)[+mx]; DMARC_NA(0.00)[leo-andres.de]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[99.99%] X-Rspamd-Queue-Id: 4D0nRq5bZSz5s Authentication-Results: mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de; dmarc=none X-Rspamd-Server: mail01.haj.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Refactor duplicate perl code and add comments Signed-off-by: Leo-Andres Hofmann --- html/cgi-bin/zoneconf.cgi | 53 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/html/cgi-bin/zoneconf.cgi b/html/cgi-bin/zoneconf.cgi index 0914ceb78..bf46ab0c7 100644 --- a/html/cgi-bin/zoneconf.cgi +++ b/html/cgi-bin/zoneconf.cgi @@ -26,6 +26,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; +###--- HTML HEAD ---### my $extraHead = < table#zoneconf { @@ -105,7 +106,9 @@ my $extraHead = < END ; +###--- END HTML HEAD ---### +### Read configuration ### my %ethsettings = (); my %vlansettings = (); my %cgiparams = (); @@ -119,7 +122,7 @@ my $restart_notice = ""; &Header::showhttpheaders(); # Define all zones we will check for NIC assignment -my @zones = ("green", "red", "orange", "blue"); +my @zones = ("red", "green", "orange", "blue"); # Get all physical NICs present opendir(my $dh, "/sys/class/net/"); @@ -153,6 +156,21 @@ foreach (@nics) { } } +### Functions ### + +# Check if a zone is in IP mode or in PPP, PPPoE, VDSL, ... mode +sub is_zonetype_ip { + my $zone_type = shift; + return ($zone_type eq "STATIC" || $zone_type eq "DHCP"); +} + +# Check if a zone is activated (device assigned) +sub is_zone_activated { + my $zone = uc shift; + return ($ethsettings{"${zone}_DEV"} ne ""); +} + +### START PAGE ### &Header::openpage($Lang::tr{"zoneconf title"}, 1, $extraHead); &Header::openbigbox('100%', 'center'); @@ -195,6 +213,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) { } } + # skip NIC/VLAN assignment and additional zone options for RED in PPP mode next; } @@ -278,6 +297,7 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) { } } + # validation failed, show error message and exit if ($VALIDATE_error) { &Header::openbox('100%', 'left', $Lang::tr{"error"}); @@ -290,16 +310,17 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{"save"}) { exit 0; } + # new settings are valid, write configuration files &General::writehash("${General::swroot}/ethernet/settings",\%ethsettings); &General::writehash("${General::swroot}/ethernet/vlans",\%vlansettings); $restart_notice = $Lang::tr{'zoneconf notice reboot'}; } -&Header::openbox('100%', 'left', $Lang::tr{"zoneconf nic assignment"}); - ### START OF TABLE ### +&Header::openbox('100%', 'left', $Lang::tr{"zoneconf nic assignment"}); + print < @@ -311,19 +332,16 @@ END # Fill the table header with all activated zones foreach (@zones) { my $uc = uc $_; - my $dev_name = $ethsettings{"${uc}_DEV"}; - if ($dev_name eq "") { # If the zone is not activated, don't show it - next; - } + # If the zone is not activated, don't show it + next unless is_zone_activated($_); - # If the zone is in PPP mode, don't show a mode dropdown + # If the red zone is in PPP mode, don't show a mode dropdown if ($uc eq "RED") { my $red_type = $ethsettings{"RED_TYPE"}; - my $red_restricted = ($uc eq "RED" && ! ($red_type eq "STATIC" || $red_type eq "DHCP")); - if ($red_restricted) { - print "\t\t\n"; + unless (is_zonetype_ip($red_type)) { + print "\t\t\n"; next; # We're done here } @@ -354,6 +372,7 @@ END print "\t\n"; +# NIC assignment matrix foreach (@nics) { my $mac = $_->[0]; my $nic = $_->[1]; @@ -365,19 +384,14 @@ foreach (@nics) { # Iterate through all zones and check if the current NIC is assigned to it foreach (@zones) { my $uc = uc $_; - my $dev_name = $ethsettings{"${uc}_DEV"}; my $highlight = ""; - if ($dev_name eq "") { # Again, skip the zone if it is not activated - next; - } + # If the zone is not activated, don't show it + next unless is_zone_activated($_); if ($uc eq "RED") { - my $red_type = $ethsettings{"RED_TYPE"}; - my $red_restricted = ($uc eq "RED" && ! ($red_type eq "STATIC" || $red_type eq "DHCP")); - # VLANs/Bridging is not possible if the RED interface is set to PPP, PPPoE, VDSL, ... - if ($red_restricted) { + unless (is_zonetype_ip($ethsettings{"RED_TYPE"})) { my $checked = ""; if ($mac eq $ethsettings{"${uc}_MACADDR"}) { @@ -449,6 +463,7 @@ END print "\t\n"; } +# footer and submit button print <
$uc ($red_type)$uc ($red_type)