From patchwork Thu Feb 18 14:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 3895 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 ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4DhHDp6C4Kz3wps for ; Thu, 18 Feb 2021 14:30:34 +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 "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4DhHDn3tvlz27r; Thu, 18 Feb 2021 14:30:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4DhHDn1n90z2xqV; Thu, 18 Feb 2021 14:30:33 +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 ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4DhHDm1Ypnz2xXd for ; Thu, 18 Feb 2021 14:30:32 +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 4DhHDl34cgz11 for ; Thu, 18 Feb 2021 14:30:31 +0000 (UTC) Received: (qmail 28635 invoked from network); 18 Feb 2021 14:30:25 -0000 Received: from localhost (HELO localhost) (127.0.0.1) by arche.uberspace.de with SMTP; 18 Feb 2021 14:30:25 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH v2 1/6] zoneconf.cgi: Change NIC display order, improve code Date: Thu, 18 Feb 2021 15:30:11 +0100 Message-Id: <20210218143016.972-1-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 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=1613658631; a=rsa-sha256; cv=none; b=Qt3orUYbNSOtlBamOISAc9UsTSKgmEQbubWSwp0XAoBRmmCX3Ln+NGD4wz7OeSWG951Kpj WM6Vce2gV3bMyrA/R6Yn/Sz6P7xm1Ba6oQJRSDGOGvplIdNa0CuIEyCxsc3yenyHSE9PJU 56VklUfhE/FLvDj2erQOFUodOVSUQaXwEEJfhszrgQiYuYCAR9qkD5TfG74AYHM6e4zY9H RB6fm1A0iu8LTEpp9FEhgMH8jYts7aX3dIoO3EOdy0ftybQXruRK4RE89VOXjZSFI+1JM6 7RWWSzB95I++Z8rb+LUdHuyrcbcZNP5GcCNk+15wr26l2UNwj1g7tBBHCJAbsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1613658631; 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=amnPoMeUrLsvqi7o+uF/fNADN0wtx0B/tV5rVi9zfxMgHp5bT6HRYT3YhejNowKmNL1JmO CkU9XmFIWWLH4B0wrZJeGl8DmBxCyv0uOK/UF50kyZvhFl+nFkMbCu2I8EEQkH3Z2Gr7IC o1AfGOLt8anpnF8gOjQDFRhNqLRfvV8z68lNQWk/F1bo5HxqO5v9gLhpn/W9mpk6/8D5Iz wFtvxch0Z72X+k3OD2DhazlwPRhhhF7VFUPpso9eJq04TYJAokXBM8Njcyqoc+CKc74nWL a/ADyzrLO/GGtC3ZIcfoFSE4Ndk+eIKdW0D9Z0IET8ie5Gnle/n+2nmZ+95PMA== 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-Spamd-Result: default: False [2.71 / 11.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; 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(-1.98)[asn: 205766(-0.28), country: DE(-0.01), ip: 185.26.156.147(-0.70)]; MID_CONTAINS_FROM(1.00)[]; MIME_HTML_ONLY(0.20)[]; 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(-0.31)[75.19%] X-Rspamd-Queue-Id: 4DhHDl34cgz11 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)