]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
pakfire.cgi: Separate command processing and HTML generation
authorLeo-Andres Hofmann <hofmann@leo-andres.de>
Sun, 8 May 2022 12:09:46 +0000 (14:09 +0200)
committerPeter Müller <peter.mueller@ipfire.org>
Sun, 8 May 2022 13:13:20 +0000 (13:13 +0000)
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 <hofmann@leo-andres.de>
Acked-by: Peter Müller <peter.muelle@ipfire.org>
html/cgi-bin/pakfire.cgi

index 65c67fb90c1fe0f47da3556bd7f0846460466359..b908ec6a0408b79a493083bddea1acddd2ec2dec 100644 (file)
@@ -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 <<END;
@@ -222,12 +249,9 @@ END
                &Header::closebigbox();
                &Header::closepage();
                exit;
-       }
+
 } elsif (($cgiparams{'ACTION'} eq 'remove') && (! &_is_pakfire_busy())) {
        my @pkgs = split(/\|/, $cgiparams{'DELPAKS'});
-       if ("$cgiparams{'FORCE'}" eq "on") {
-               &General::system_background("/usr/local/bin/pakfire", "remove", "--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 <<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"} = $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");
-       }
 }
 
-&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
-
 my %selected=();
 my %checked=();