From patchwork Sun May 8 12:09:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 5592 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 4Kx35x3jkJz3x1v for ; Sun, 8 May 2022 12:10:13 +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 4Kx35t4vGSz1Qw; Sun, 8 May 2022 12:10:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Kx35t49q8z301d; Sun, 8 May 2022 12:10:10 +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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Kx35s2vFkz2x9j for ; Sun, 8 May 2022 12:10:09 +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 4Kx35l6GCgznj for ; Sun, 8 May 2022 12:10:03 +0000 (UTC) Received: (qmail 30295 invoked by uid 990); 8 May 2022 12:10:02 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 1/7] pakfire.cgi: Separate command processing and HTML generation Date: Sun, 8 May 2022 14:09:46 +0200 Message-Id: <20220508120952.52-1-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 X-Rspamd-Bar: - X-Rspamd-Report: R_MISSING_CHARSET(0.5) MIME_GOOD(-0.1) MID_CONTAINS_FROM(1) BAYES_HAM(-3) X-Rspamd-Score: -1.6 Received: from unknown (HELO unkown) (::1) by arche.uberspace.de (Haraka/2.8.28) with ESMTPSA; Sun, 08 May 2022 14:10:01 +0200 ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1652011804; a=rsa-sha256; cv=none; b=Tb1YFRJCdAnZiqiBa2QPNg+ONeCebnvRlyrnIAXB3AA9GD+RF1MFa/3Y1AeQ3IbG1z3yxk JTNpaMvYyXrr9ds7u18l4nswy5/em4BPeuXp0uJ4FmMkufgILVFoCXFKqEzoy2aCdXsjhX qjLgN5gneuswggcgcm/jZNugz0/QqzDnPF1XT8OKjQy3rUcT3Ecy6zVrqF909uN/bz3M5R xw2fcjTmo8o17Lg2xueya50XmqP9BoviX5WNA7FmfudOPweXPLKgC6d57eieWF/gzpw9B/ 2ACvscXN8ulzqDdLeo6VHQvP3nxwD/f/+RmjfGH44IJJvHNI049DmV7qWDT1hg== 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; dmarc=pass (policy=quarantine) header.from=leo-andres.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1652011804; 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=ZNRvAcAA9VQELXUF1ZtqEj5k7I5PVAxqJPxC5GX1MB4=; b=G38LYLkXxObkWv5DwOTnc28KFfkP2rtGG5nKXVkjMZoXThSScaGgGXlMADOeOMxQdUDqjS wlR1iQLU2Kvp5SQMmSvcaA+WoMhvQBdEJohxQKqeFxGgTKLEH0Xf/iQmj9Tgf/TpsnpCbx MI+b4s/R7QftStx2T+WSWqrsvqZ3vjHa6J8vwRzMPzyHdr6Dw1hnyl8JH75rVW1B6q0cej mPrrMxmVpTEWT4sSatdStJu5MtKR21hzVckBglOk6aHEiwB5RP0QAeMtlV7Ru/4w+SnbU8 126r0jps3k2j7+Yr5GZqxzQfoXxUPzGC/ORf7EVyFtaw+kLDk/2LsRvN6oA2Iw== X-Rspamd-Queue-Id: 4Kx35l6GCgznj X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-2.45 / 11.00]; BAYES_HAM(-1.87)[94.26%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-1.00)[-1.000]; SPF_REPUTATION_HAM(-0.77)[-0.77342682734463]; DMARC_POLICY_ALLOW(-0.50)[leo-andres.de,quarantine]; R_MISSING_CHARSET(0.50)[]; MX_INVALID(0.50)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; IP_REPUTATION_HAM(-0.01)[asn: 205766(0.00), country: DE(-0.01), ip: 185.26.156.147(0.00)]; RCPT_COUNT_ONE(0.00)[1]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; ARC_NA(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[185.26.156.147:from]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] 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=pass (policy=quarantine) header.from=leo-andres.de 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" Move most of the command execution away from the HTML output. This makes it easier to modify or extend individual commands. Also load Pakfire settings earlier to ensure that they are available during command execution. Signed-off-by: Leo-Andres Hofmann Acked-by: Peter Müller --- html/cgi-bin/pakfire.cgi | 61 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 65c67fb90..b908ec6a0 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -39,11 +39,12 @@ my %mainsettings = (); # Load general settings &General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); # Get CGI request data $cgiparams{'ACTION'} = ''; -$cgiparams{'VALID'} = ''; +$cgiparams{'FORCE'} = ''; $cgiparams{'INSPAKS'} = ''; $cgiparams{'DELPAKS'} = ''; @@ -94,6 +95,35 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { exit; } +### Process Pakfire install/update commands ### +if(($cgiparams{'ACTION'} ne '') && (! &_is_pakfire_busy())) { + if(($cgiparams{'ACTION'} eq 'install') && ($cgiparams{'FORCE'} eq 'on')) { + my @pkgs = split(/\|/, $cgiparams{'INSPAKS'}); + &General::system_background("/usr/local/bin/pakfire", "install", "--non-interactive", "--no-colors", @pkgs); + } elsif(($cgiparams{'ACTION'} eq 'remove') && ($cgiparams{'FORCE'} eq 'on')) { + my @pkgs = split(/\|/, $cgiparams{'DELPAKS'}); + &General::system_background("/usr/local/bin/pakfire", "remove", "--non-interactive", "--no-colors", @pkgs); + } elsif($cgiparams{'ACTION'} eq 'update') { + &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); + } elsif($cgiparams{'ACTION'} eq 'upgrade') { + &General::system_background("/usr/local/bin/pakfire", "upgrade", "-y", "--no-colors"); + } elsif($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { + $pakfiresettings{"TREE"} = $cgiparams{"TREE"}; + + # Check for valid input + if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) { + $errormessage .= $Lang::tr{'pakfire invalid tree'}; + } + + unless ($errormessage) { + &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresettings); + + # Update lists + &General::system_background("/usr/local/bin/pakfire", "update", "--force", "--no-colors"); + } + } +} + ### Start pakfire page ### &Header::showhttpheaders(); @@ -185,9 +215,6 @@ END # Process Pakfire commands if (($cgiparams{'ACTION'} eq 'install') && (! &_is_pakfire_busy())) { my @pkgs = split(/\|/, $cgiparams{'INSPAKS'}); - if ("$cgiparams{'FORCE'}" eq "on") { - &General::system_background("/usr/local/bin/pakfire", "install", "--non-interactive", "--no-colors", @pkgs); - } else { &Header::openbox("100%", "center", $Lang::tr{'request'}); my @output = &General::system_output("/usr/local/bin/pakfire", "resolvedeps", "--no-colors", @pkgs); print <