From: Leo-Andres Hofmann Date: Sun, 8 May 2022 12:09:46 +0000 (+0200) Subject: pakfire.cgi: Separate command processing and HTML generation X-Git-Tag: v2.27-core170~180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd521e78b815e84c31683b3cc2ec085f6f97d939;p=ipfire-2.x.git pakfire.cgi: Separate command processing and HTML generation 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 --- diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 65c67fb90c..b908ec6a04 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 <