From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter =?utf-8?q?M=C3=BCller?= <peter.mueller@ipfire.org> To: development@lists.ipfire.org Subject: Re: [PATCH 1/7] pakfire.cgi: Separate command processing and HTML generation Date: Sun, 08 May 2022 13:11:20 +0000 Message-ID: <61786b3c-d543-8f0d-cc54-c783a32e7a21@ipfire.org> In-Reply-To: <20220508120952.52-1-hofmann@leo-andres.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2291137852792255060==" List-Id: <development.lists.ipfire.org> --===============2291137852792255060== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Acked-by: Peter M=C3=BCller <peter.muelle(a)ipfire.org> > Move most of the command execution away from the HTML output. > This makes it easier to modify or extend individual commands. >=20 > Also load Pakfire settings earlier to ensure that they are > available during command execution. >=20 > Signed-off-by: Leo-Andres Hofmann <hofmann(a)leo-andres.de> > --- > html/cgi-bin/pakfire.cgi | 61 +++++++++++++++++++++------------------- > 1 file changed, 32 insertions(+), 29 deletions(-) >=20 > 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 =3D (); > =20 > # Load general settings > &General::readhash("${General::swroot}/main/settings", \%mainsettings); > +&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresetting= s); > &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt"= , \%color); > =20 > # Get CGI request data > $cgiparams{'ACTION'} =3D ''; > -$cgiparams{'VALID'} =3D ''; > +$cgiparams{'FORCE'} =3D ''; > =20 > $cgiparams{'INSPAKS'} =3D ''; > $cgiparams{'DELPAKS'} =3D ''; > @@ -94,6 +95,35 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { > exit; > } > =20 > +### Process Pakfire install/update commands ### > +if(($cgiparams{'ACTION'} ne '') && (! &_is_pakfire_busy())) { > + if(($cgiparams{'ACTION'} eq 'install') && ($cgiparams{'FORCE'} eq 'on')) { > + my @pkgs =3D 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 =3D split(/\|/, $cgiparams{'DELPAKS'}); > + &General::system_background("/usr/local/bin/pakfire", "remove", "--non-i= nteractive", "--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"} =3D $cgiparams{"TREE"}; > + > + # Check for valid input > + if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) { > + $errormessage .=3D $Lang::tr{'pakfire invalid tree'}; > + } > + > + unless ($errormessage) { > + &General::writehash("${General::swroot}/pakfire/settings", \%pakfireset= tings); > + > + # Update lists > + &General::system_background("/usr/local/bin/pakfire", "update", "--forc= e", "--no-colors"); > + } > + } > +} > + > ### Start pakfire page ### > &Header::showhttpheaders(); > =20 > @@ -185,9 +215,6 @@ END > # Process Pakfire commands > if (($cgiparams{'ACTION'} eq 'install') && (! &_is_pakfire_busy())) { > my @pkgs =3D 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 =3D &General::system_output("/usr/local/bin/pakfire", "resolv= edeps", "--no-colors", @pkgs); > print <<END; > @@ -222,12 +249,9 @@ END > &Header::closebigbox(); > &Header::closepage(); > exit; > - } > + > } elsif (($cgiparams{'ACTION'} eq 'remove') && (! &_is_pakfire_busy())) { > my @pkgs =3D split(/\|/, $cgiparams{'DELPAKS'}); > - if ("$cgiparams{'FORCE'}" eq "on") { > - &General::system_background("/usr/local/bin/pakfire", "remove", "--non-i= nteractive", "--no-colors", @pkgs); > - } else { > &Header::openbox("100%", "center", $Lang::tr{'request'}); > my @output =3D &General::system_output("/usr/local/bin/pakfire", "resolv= edeps", "--no-colors", @pkgs); > print <<END; > @@ -262,30 +286,9 @@ END > &Header::closebigbox(); > &Header::closepage(); > exit; > - } > - > -} elsif (($cgiparams{'ACTION'} eq 'update') && (! &_is_pakfire_busy())) { > - &General::system_background("/usr/local/bin/pakfire", "update", "--force"= , "--no-colors"); > -} elsif (($cgiparams{'ACTION'} eq 'upgrade') && (! &_is_pakfire_busy())) { > - &General::system_background("/usr/local/bin/pakfire", "upgrade", "-y", "-= -no-colors"); > -} elsif ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}") { > - $pakfiresettings{"TREE"} =3D $cgiparams{"TREE"}; > - > - # Check for valid input > - if ($pakfiresettings{"TREE"} !~ m/^(stable|testing|unstable)$/) { > - $errormessage .=3D $Lang::tr{'pakfire invalid tree'}; > - } > - > - unless ($errormessage) { > - &General::writehash("${General::swroot}/pakfire/settings", \%pakfiresett= ings); > =20 > - # Update lists > - &General::system_background("/usr/local/bin/pakfire", "update", "--force= ", "--no-colors"); > - } > } > =20 > -&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresetting= s); > - > my %selected=3D(); > my %checked=3D(); > =20 --===============2291137852792255060==--