From patchwork Wed Mar 9 22:56:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5326 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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KDSJS0nQMz3xj2 for ; Wed, 9 Mar 2022 22:57:28 +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 4KDSJM4nQ2z5SC; Wed, 9 Mar 2022 22:57:23 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KDSJM1QNvz30H6; Wed, 9 Mar 2022 22:57:23 +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 4KDSJL1R2fz2yj9 for ; Wed, 9 Mar 2022 22:57:22 +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 4KDSJK1xvbz2BK for ; Wed, 9 Mar 2022 22:57:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 058C74008F for ; Wed, 9 Mar 2022 23:57:21 +0100 (CET) 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 m-EA4LcIV8Kf for ; Wed, 9 Mar 2022 23:57:19 +0100 (CET) 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 A23301B989; Wed, 9 Mar 2022 23:57:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1646866639; bh=dkNj0oL3BwCHrAf5lWEKm52Fl3AIIXLOShXSXZsBs4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cbagWLI5kBA4FeRztNW9qoGbmk+KuKd0D5f8H7MyJXXdN8AH3/rgJMyTnGbh365tL LNqZLPFv4SEQ38dIN2D2+vlfrCpzXzhPIcoppzHL8juN54E32ZCLNl80OXdnBwp7pm DiT1e/mhC7dwTNVJ78u2doAfuYQNYlgmah9Ydx8kQkU6GBjLNoWVCZjel0wi8G22Ul nUTy4qWQ88R4nctb+zOgcV3hyMVk5tmJbExNaqqtpecZjX7SkTw2qzTeUaLH800x4v bdN+RpaeZrtBYvL20sGylM9zowg3Sni+ibNSJcoDeHFJwQUkiRFhosVIpk8OhNXWLd FlUDqRubFJCIg== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH 7/9] pakfire: Refactor status function separating UI and logic Date: Wed, 9 Mar 2022 23:56:53 +0100 Message-Id: <20220309225655.4472-8-robin.roevens@disroot.org> In-Reply-To: <20220309225655.4472-1-robin.roevens@disroot.org> References: <20220309225655.4472-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: A23301B989.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1647471431.4742@zVFbVD4kPcwtRUTDQ4IPiw ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1646866641; a=rsa-sha256; cv=none; b=V0i6kTmpGWIzc322f2bbXrvqv86FWkoH3sPKYRLu8bBqaEF7z2kH37jICFZMSFEfU52lXQ XE5wcOuhYCcEiQ+PT2glvZ9NDUMI1LUWZVxLMKH7Z+DqW+1tL9UFSrs3mxyGTE1+8rw2I8 1dvIDqLwqCjzgiml8hxPKuUDtjf5W3i7HZ0DPEBWdgAGJZ91tIfOYHhSv9DIqniN5bqqiC I2TBNURStSJzY1QLGOMOK0t0HcfPZXbw8rnUGZAOV8yU004hPBbMWs/vhYbh5azdn8VKih 2LwwnE6dFRaIY/vX6E2xTItD3yngfkM89cf5Zr6h5CfPRrrB5Y1jrzryeDosvQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=cbagWLI5; 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1646866641; 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=E7uZYk1F5h5M9+LQ0N7LdIkvvHymdUGpxZu6yF19zH8=; b=EM5vOAVJKet7S6HbZ98C1fqoAKVfNFs091Y2A2Y1BcMzWNxpYol2coynX86BaZCmCP8rC8 UrHcQ5Cd+I7pX+u3hdkNqYymmqQWC847JCBRN08HgG9Iivgsot5W3WzxLSByVoqASjDRM1 mkwcUxpGjaFKMmT0Dvyd8OReeJ8CsyamPth/CtQgFuRFFb+q0MK9JxvMddQ6NAVoahjtVj AZs2UE32OQaUqnODdbljNV4FCotGYrM5IyyPgMLSERqbTYwIVj7Y5wpdCU1vU0+n+bK9sc fw/pcZX8fFCqmSyfrOY4ScWgbVtLSD4X8DhQ8pF7F3UlfMTw5nbBL8a0jlhvdg== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=cbagWLI5; 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 [-4.43 / 11.00]; BAYES_HAM(-3.00)[99.99%]; IP_REPUTATION_HAM(-1.15)[asn: 50673(-0.33), country: NL(-0.01), ip: 178.21.23.139(-0.82)]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-0.90)[-0.896]; SPF_REPUTATION_HAM(-0.68)[-0.6773174338785]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; R_MISSING_CHARSET(0.50)[]; MIME_HTML_ONLY(0.20)[]; R_SPF_ALLOW(-0.20)[+a:c]; R_DKIM_ALLOW(-0.20)[disroot.org:s=mail]; MX_GOOD(-0.01)[]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:~]; ARC_NA(0.00)[]; DKIM_TRACE(0.00)[disroot.org:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1] X-Rspamd-Queue-Id: 4KDSJK1xvbz2BK 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" - removed UI related code from status function and refactor it to returning hash representing pakfire status. - Add UI part to pakfire script - Use pakfire status function in pakfire.cgi, removing duplicate code Signed-off-by: Robin Roevens --- html/cgi-bin/pakfire.cgi | 39 ++++++++++++++++------------------- src/pakfire/lib/functions.pl | 40 ++++++++++++++++++------------------ src/pakfire/pakfire | 13 +++++++++++- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 30a23128b..d62b6058f 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -37,6 +37,9 @@ my %color = (); my %pakfiresettings = (); my %mainsettings = (); +# Get Pakfire status +my %pakfire_status = &Pakfire::status(); + # Load general settings &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); @@ -66,7 +69,7 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { my %status = ( 'running' => &_is_pakfire_busy() || "0", 'running_since' => &General::age("$Pakfire::lockfile") || "0s", - 'reboot' => (-e "/var/run/need_reboot") || "0", + 'reboot' => ("$pakfire_status{'RebootRequired'}" eq "yes") || "0", 'failure' => $failure || "0" ); @@ -333,32 +336,26 @@ END exit; } -my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; -chomp($core_release); -my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); -my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); -my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); -my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db"); - &Header::openbox("100%", "center", "Pakfire"); print < END -if ( -e "/var/run/need_reboot") { +if ("$pakfire_status{'RebootRequired'}" eq "yes") { print "\t\t$Lang::tr{'needreboot'}!\n"; } + print <$Lang::tr{'pakfire system state'}: $Lang::tr{'available updates'}: - $Lang::tr{'pakfire core update level'}: $core_release + $Lang::tr{'pakfire core update level'}: $pakfire_status{'Release'}
- $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}
- $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}
- $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}
- $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} + $Lang::tr{'pakfire last update'} $pakfire_status{'LastUpdate'} $Lang::tr{'pakfire ago'}
+ $Lang::tr{'pakfire last serverlist update'} $pakfire_status{'LastServerListUpdate'} $Lang::tr{'pakfire ago'}
+ $Lang::tr{'pakfire last core list update'} $pakfire_status{'LastCoreListUpdate'} $Lang::tr{'pakfire ago'}
+ $Lang::tr{'pakfire last package update'} $pakfire_status{'LastPakListUpdate'} $Lang::tr{'pakfire ago'}
@@ -370,17 +367,17 @@ print < END - my %coredb = &Pakfire::coredbinfo(); - if (defined $coredb{'AvailableRelease'}) { - print "\n"; + if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") { + print "\n"; } - my %upgradelist = &Pakfire::dblist("upgrade"); - foreach my $pak (sort keys %upgradelist) { - print "\n"; + if ($pakfire_status{'PakUpdatesAvailable'} > 0) { + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "\n"; + } } - print < diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index b35aed6a3..028a0277e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -897,26 +897,26 @@ sub reboot_required { } sub status { - # General info - my $return = "Core-Version: $Conf::version\n"; - $return .= "Core-Update-Level: $Conf::core_mine\n"; - $return .= "Last update: " . &General::age("/opt/pakfire/db/core/mine") . " ago\n"; - $return .= "Last core-list update: " . &General::age("/opt/pakfire/db/lists/core-list.db") . " ago\n"; - $return .= "Last server-list update: " . &General::age("/opt/pakfire/db/lists/server-list.db") . " ago\n"; - $return .= "Last packages-list update: " . &General::age("/opt/pakfire/db/lists/packages_list.db") . " ago\n"; - - # Get availability of core updates - $return .= "Core-Update available: " . &Pakfire::coreupdate_available() . "\n"; - - # Get availability of package updates - $return .= "Package-Updates available: " . &Pakfire::updates_available() . "\n"; - - # Test if reboot is required - $return .= "Reboot required: " . &Pakfire::reboot_required() . "\n"; - - # Return status text - print "$return"; - exit 1; + ### This subroutine returns pakfire status information in a hash. + # Usage is without arguments + + # Add core version info + my %status = &Pakfire::coredbinfo(); + + # Add last update info + $status{'LastUpdate'} = &General::age("/opt/pakfire/db/core/mine"); + $status{'LastCoreListUpdate'} = &General::age("/opt/pakfire/db/lists/core-list.db"); + $status{'LastServerListUpdate'} = &General::age("/opt/pakfire/db/lists/server-list.db"); + $status{'LastPakListUpdate'} = &General::age("/opt/pakfire/db/lists/packages_list.db"); + + # Add number of available package updates + $status{'CoreUpdateAvailable'} = (defined $status{'AvailableRelease'}) ? "yes" : "no"; + $status{'PakUpdatesAvailable'} = &Pakfire::updates_available(); + + # Add if reboot is required + $status{'RebootRequired'} = &Pakfire::reboot_required(); + + return %status; } sub get_arch() { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index b529db77a..0ed8aacd4 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -406,7 +406,18 @@ system("rm -f /etc/fcron.daily/pakfire-upgrade"); } } elsif ("$ARGV[0]" eq "status") { - &Pakfire::status; + my %status = &Pakfire::status; + + print "Core-Version: $status{'CoreVersion'}\n"; + print "Core-Update-Level: $status{'Release'}\n"; + print "Last update: $status{'LastUpdate'} ago\n"; + print "Last core-list update: $status{'LastCoreListUpdate'} ago\n"; + print "Last server-list update: $status{'LastServerListUpdate'} ago\n"; + print "Last packages-list update: $status{'LastPakListUpdate'} ago\n"; + print "Core-Update available: $status{'CoreUpdateAvailable'}"; + print " ($status{'AvailableRelease'})" if ("$status{'CoreUpdateAvailable'}" eq "yes"); + print "\nPackage-Updates available: $status{'PakUpdatesAvailable'}\n"; + print "Reboot required: $status{'RebootRequired'}\n"; } else { &Pakfire::usage; }