From patchwork Thu Jul 28 11:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5775 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 4LtpCh40vtz40Wb for ; Thu, 28 Jul 2022 11:22:40 +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 4LtpCY1sMZz5SH; Thu, 28 Jul 2022 11:22:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4LtpCY1cnnz2ygN; Thu, 28 Jul 2022 11:22: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 4LtpCX0fHLz307D for ; Thu, 28 Jul 2022 11:22:32 +0000 (UTC) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) (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 4LtpCV4hcmzy6 for ; Thu, 28 Jul 2022 11:22:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 3379C40E71 for ; Thu, 28 Jul 2022 13:22:30 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mC5nCgkR6lml for ; Thu, 28 Jul 2022 13:22:29 +0200 (CEST) Received: from chojin.sicho.home (amaterasu.sicho.home [192.168.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (no client certificate requested) (Authenticated sender) by hachiman (MailScanner Milter) with SMTP id 62122560BC; Thu, 28 Jul 2022 13:21:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1659007341; bh=/E9KwcDHIBWBdwnWmzdNoH7E4zY6rBeUZmU3bcqArYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M0Cr6VqMWcXmFxcQB2wLguMHIqA/zdeoAU4DB0vkGUnO8O51Oob1AOR67jRflnVFr Bjn1gnVKFaUnS92PcOOanwDPnLRQz9+FohmxqLTSGBNoLLMonfkqi7PP74D90yVHKn 36+FCkg5uw467ciLgGNxmd24OtOUKCO9rngb/CcA98hpj0zsgIJjAGjaUTSrgq/BMB wawHsk5aCpxNFfbW9VODCnTrH3hCGRfHVSZPOQMfbK8+smLilIgFBuhbNYmNjOFqCf 80MtCrYwTt7aNn7LssBmJUbn2o+z1Khsxt6jJ0hfYH2WCRUz63ji/293KZfJPVFTnL oXnVcttnEvisQ== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v2 10/10] pakfire: Replace getmetadata duplicate code Date: Thu, 28 Jul 2022 13:21:36 +0200 Message-Id: <20220728112136.30218-11-robin.roevens@disroot.org> In-Reply-To: <20220728112136.30218-1-robin.roevens@disroot.org> References: <20220728112136.30218-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: 62122560BC.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1659612114.81852@mVrn0HMcLIwF4JDzfJqWtg ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1659007350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TrqKt7IjUBir9JfrCSVqHTaotH89uEoY7JW57+hNUwE=; b=hmxbsn/bisrizPFQ98zjC+4nZq80jDTLieQPNH3iaUu3Q8aQB7aYG4Aim3Kt8yhFyu3YDs Ww7K2j14l2rdPT7UNpwk9DnoSi29T9c2rEBC45lEO8TtOltSW1Wknl8zrg3RUqhUTZuYWy 7W/0eU71m3eaVUGUoDPh7NMmMHBKTK7C4jCse9hv7eYtrtKzhlTDhme50hKTj03pHAfsy1 SuIe5be94hp+7956WBiBdRahBmqaOqB2NGapi9d0kIf9eN9Q8aux+jj52N4VGAmveftVHg HSvSJWyuJpb6KK5XXbedg59PKCOk9nH+q/DTyI+QUv66mq/qkeZfgYXpc379rA== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=M0Cr6VqM; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1659007350; a=rsa-sha256; cv=none; b=XyjQ+rPNTs3TGW/E9ySiCm0TpcotwcPw3EBB56Dbf9kXNelsis90uLtwyzp8I8HqdIMI18 g99UWR/dTJuppvB1HQAf6Yg4A9HCk8oe1h6nRqkSXlvO5u8EhHLm9opDqr8lwbsjqRHvDd X5oyG6oEDRI/cl5UwuFpls6gJxSrf08Gusk/Yz7r2Q8lrCwSZfhKxjPts+K2qmfRTAcUL6 bpRsiWkUwd8bFA5i2GZaQoKqROEG+DVvEpxhB17+93NG1M1/op4V1T2ViJi8al6KPeN26J WNnp6y1xb4ff+THBDbk8ErsPO8fJbtHpYvxxlclu6/aOzsdhb89NzuFV6BLiFA== X-Rspamd-Queue-Id: 4LtpCV4hcmzy6 Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=M0Cr6VqM; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-7.57 / 11.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; SPF_REPUTATION_HAM(-0.82)[-0.81818758120783]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[disroot.org:s=mail]; MIME_HTML_ONLY(0.20)[]; R_SPF_ALLOW(-0.20)[+a:c]; IP_REPUTATION_HAM(-0.04)[asn: 50673(-0.03), country: NL(-0.01), ip: 178.21.23.139(0.00)]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; RCVD_COUNT_THREE(0.00)[4]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; DKIM_TRACE(0.00)[disroot.org:+]; MIME_TRACE(0.00)[0:~]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[] 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" - Use getmetadata function in services.cgi to determine installed addon services to display. Removing code duplication and intel that should only be known by pakfire itself. - Removed hardcoded exclusions: - squid should show up correctly using the new metadata info - mdadm is part of core and will never show up here - alsa, unknown if this problem still exists, but if it is, this should be handled somewhere else. Signed-off-by: Robin Roevens --- html/cgi-bin/services.cgi | 74 ++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index a1dcfd57e..29926ecc3 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; +require "/opt/pakfire/lib/functions.pl"; my %color = (); my %mainsettings = (); @@ -160,51 +161,44 @@ END my $lines=0; # Used to count the outputlines to make different bgcolor - # Generate list of installed addon pak's - opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!"; - my @pak = sort readdir DIR; - closedir(DIR); - - foreach (@pak){ - chomp($_); - next unless (m/^meta-/); - s/^meta-//; - - # Check which of the paks are services - if (-e "/etc/init.d/$_") { - # blacklist some packages - # - # alsa has trouble with the volume saving and was not really stopped - # mdadm should not stopped with webif because this could crash the system - # - if ( $_ eq 'squid' ) { - next; - } - if ( ($_ ne "alsa") && ($_ ne "mdadm") ) { - $lines++; - if ($lines % 2){ - print ""; - $col="bgcolor='$color{'color22'}'"; - }else{ - print ""; - $col="bgcolor='$color{'color20'}'"; - } + my @paks; + my @addon_services; + + # Generate list of installed addon pak services + my %paklist = &Pakfire::dblist("installed"); - print "$_ "; - my $status = isautorun($_,$col); - print "$status "; - print "$Lang::tr{"; - print "$Lang::tr{ "; - my $status = &isrunningaddon($_,$col); - $status =~ s/\\[[0-1]\;[0-9]+m//g; - - chomp($status); - print "$status"; - print ""; + foreach my $pak (keys %paklist) { + my %metadata = &Pakfire::getmetadata($pak, "installed"); + + if ("$metadata{'Services'}") { + foreach my $service (split(/ /, "$metadata{'Services'}")) { + push(@addon_services, $service); } } } + foreach (@addon_services) { + $lines++; + if ($lines % 2){ + print ""; + $col="bgcolor='$color{'color22'}'"; + }else{ + print ""; + $col="bgcolor='$color{'color20'}'"; + } + print "$_ "; + my $status = isautorun($_,$col); + print "$status "; + print "$Lang::tr{"; + print "$Lang::tr{ "; + my $status = isrunningaddon($_,$col); + $status =~ s/\\[[0-1]\;[0-9]+m//g; + + chomp($status); + print "$status"; + print ""; + } + print "\n"; &Header::closebox();