From patchwork Thu Jul 28 11:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5774 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 4LtpCg0nqDz40Wd for ; Thu, 28 Jul 2022 11:22:39 +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 4LtpCX5S3Vz5Rh; Thu, 28 Jul 2022 11:22:32 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4LtpCX11DCz30H2; Thu, 28 Jul 2022 11:22:32 +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 4LtpCV6x0xz2xc4 for ; Thu, 28 Jul 2022 11:22:30 +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 4LtpCV0vGLz1Ll for ; Thu, 28 Jul 2022 11:22:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id AD16840DC8 for ; Thu, 28 Jul 2022 13:22:29 +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 lPcS_n_1SBvj for ; Thu, 28 Jul 2022 13:22:28 +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 50CF3560B6; 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=1659007340; bh=BHAm4keprzphaBB7qCurpaqUJHtWWKIjFE8kSZuLlcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=g4L+phxTgW+nGetvp52sJvBehLttw5eIgYkzYnrxFAlcMKL7TJh65FWlfBHMpALZ5 tN8iXv29ULpHvByM2Rol9kpY9AGqzMAo102USHJJCD6TbElql/cIyjkO8QpstpYM9H yLKJwLHq8cIrFNctKUd7ByQGpHvsjxJUGRBI7OY6QdtkK5ikkSunepLKLguAA0ogHF OSuzE8Xx8FwlYZonxXCrUm6SXD0yBffHRMsILpRmyyqlEMl2gzh81yiQHJEArjdSyn qgXi9gkOzDcDZztnenEjrwTv7Hcj248Byn+4e27NH6+KIXCiDablRTaijd3DkiWsUz hJ0CtAep0qy5g== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v2 08/10] pakfire: Replace status duplicate code Date: Thu, 28 Jul 2022 13:21:34 +0200 Message-Id: <20220728112136.30218-9-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: 50CF3560B6.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1659612114.93447@83swRzxhHiEduxGW6MHkFA 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=/1mD7Di0XkcJyUROMMV2pLJOoTEolmgUe9UZt/WsclA=; b=u27OtalK1IvBCYwF9qg4DDr+OeemAh1rzbaKbaiUplWSrtGv/o0gYrRuaAlNpdb9menjSU Amg27c807RNwQir1RvR/+fWy2yh2QKBEsHgARzfFYtOs3WxpLj38Wgv1bTW+rnGaDTzZUb yQASX2O3guw0ERqUXrtCMul3J4nRDwxJHez9lXgV4Xtn+aTZ4OAfKBDkuW/SZeK8ZxqkZO gtvjvC8lQJYBeuZWZe2+qU1vK5fzOYj4zyzWvJwp8Odn8c/lyoOixV4Jgc23Ipv8wyORXL brvJu5WBo7ZvglUacrWfOaNBt5NGF1ac1ZNLbHjbdRHYXc77YPZtzVWiYGtUhA== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=g4L+phxT; 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=n/yvJdaWMdnLAXGJlDHsM7hp33vGUY330jos9guyiwXTXts4lU9Zl/iMk4SengLTRAB2hE zrd8ZtKbZi0SMBT/uLENI5jjukRm9CU4j4zzu4Wj+7Wdp0qOiio+O5+0SXyhLRBO/sGsP0 2pnodBI2VgYQ17ZzTX9ywPppe/PBBwNdCP1VdvGNvaFVosGwM6QteCVOW2L/ATanVDgQGh 5m5oHQ9yGhAHPv/OAysLL7T+dolFr5FP49y+Yuj7epl8XCE1opo64fgExxT9XKeN6NC1C4 ShNRSs8VOY0f2aHgSo8ulenIyGxuFGgNrrwnmtzcT0xXPoPyBzYjWECvxX3DVg== X-Rspamd-Queue-Id: 4LtpCV0vGLz1Ll Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=g4L+phxT; 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.81818751467824]; 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" - Make use of renewed status function in pakfire.cgi removing duplicate code Signed-off-by: Robin Roevens --- html/cgi-bin/pakfire.cgi | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index cb1272c63..42c603c61 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -43,6 +43,9 @@ my $PM_DEFAULT = 'default'; # Default user interface with command processing my $PM_LOGREAD = 'logread'; # Log messages viewer (ignores all commands) my $pagemode = $PM_DEFAULT; +# Get Pakfire status +my %pakfire_status = &Pakfire::status(); + # Load general settings &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings); @@ -84,7 +87,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" ); @@ -366,32 +369,26 @@ $selected{"TREE"}{"testing"} = ""; $selected{"TREE"}{"unstable"} = ""; $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected"; -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'}
@@ -403,14 +400,15 @@ 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 <