[3/7] pakfire.cgi: Show error and log messages earlier

Message ID 20220508120952.52-3-hofmann@leo-andres.de
State Accepted
Commit 4b5d1f3001e5f47399d3c1a6eabcd18c1a318996
Headers
Series [1/7] pakfire.cgi: Separate command processing and HTML generation |

Commit Message

Leo-Andres Hofmann May 8, 2022, 12:09 p.m. UTC
  The main page cannot be used while an installation is running.
Therefore it makes more sense to generate the log output first.

Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
---
 html/cgi-bin/pakfire.cgi | 79 ++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 39 deletions(-)
  

Comments

Peter Müller May 8, 2022, 1:12 p.m. UTC | #1
Acked-by: Peter Müller <peter.muelle@ipfire.org>

> The main page cannot be used while an installation is running.
> Therefore it makes more sense to generate the log output first.
> 
> Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
> ---
>  html/cgi-bin/pakfire.cgi | 79 ++++++++++++++++++++--------------------
>  1 file changed, 40 insertions(+), 39 deletions(-)
> 
> diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi
> index 535168547..daa82e34c 100644
> --- a/html/cgi-bin/pakfire.cgi
> +++ b/html/cgi-bin/pakfire.cgi
> @@ -212,7 +212,45 @@ END
>  &Header::openpage($Lang::tr{'pakfire configuration'}, 1, $extraHead);
>  &Header::openbigbox('100%', 'left', '', $errormessage);
>  
> -# Process Pakfire commands
> +# Show error message
> +if ($errormessage) {
> +	&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
> +	print "<font class='base'>$errormessage&nbsp;</font>\n";
> +	&Header::closebox();
> +}
> +
> +# Show log output while Pakfire is running
> +if(&_is_pakfire_busy()) {
> +	&Header::openbox("100%", "center", "Pakfire");
> +
> +	print <<END
> +<section id="pflog-header">
> +	<div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div>
> +	<div>
> +		<span id="pflog-status">$Lang::tr{'pakfire working'}</span><br>
> +		<span id="pflog-time"></span><br>
> +		<span id="pflog-action"></span>
> +	</div>
> +	<div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div>
> +</section>
> +
> +<!-- Pakfire log messages -->
> +<pre id="pflog-messages"></pre>
> +<script>
> +	// Start automatic log refresh
> +	pakfire.running = true;
> +</script>
> +
> +END
> +;
> +
> +	&Header::closebox();
> +	&Header::closebigbox();
> +	&Header::closepage();
> +	exit;
> +}
> +
> +# Show Pakfire install/remove dependencies and confirm form
>  if (($cgiparams{'ACTION'} eq 'install') && (! &_is_pakfire_busy())) {
>  	&Header::openbox("100%", "center", $Lang::tr{'request'});
>  
> @@ -290,6 +328,7 @@ END
>  	exit;
>  }
>  
> +# Show Pakfire main page
>  my %selected=();
>  my %checked=();
>  
> @@ -299,44 +338,6 @@ $selected{"TREE"}{"testing"} = "";
>  $selected{"TREE"}{"unstable"} = "";
>  $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected";
>  
> -# DPC move error message to top so it is seen!
> -if ($errormessage) {
> -	&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
> -	print "<font class='base'>$errormessage&nbsp;</font>\n";
> -	&Header::closebox();
> -}
> -
> -# Show log output while Pakfire is running
> -if(&_is_pakfire_busy()) {
> -	&Header::openbox("100%", "center", "Pakfire");
> -
> -	print <<END
> -<section id="pflog-header">
> -	<div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div>
> -	<div>
> -		<span id="pflog-status">$Lang::tr{'pakfire working'}</span><br>
> -		<span id="pflog-time"></span><br>
> -		<span id="pflog-action"></span>
> -	</div>
> -	<div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div>
> -</section>
> -
> -<!-- Pakfire log messages -->
> -<pre id="pflog-messages"></pre>
> -<script>
> -	// Start automatic log refresh
> -	pakfire.running = true;
> -</script>
> -
> -END
> -;
> -
> -	&Header::closebox();
> -	&Header::closebigbox();
> -	&Header::closepage();
> -	exit;
> -}
> -
>  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");
  

Patch

diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi
index 535168547..daa82e34c 100644
--- a/html/cgi-bin/pakfire.cgi
+++ b/html/cgi-bin/pakfire.cgi
@@ -212,7 +212,45 @@  END
 &Header::openpage($Lang::tr{'pakfire configuration'}, 1, $extraHead);
 &Header::openbigbox('100%', 'left', '', $errormessage);
 
-# Process Pakfire commands
+# Show error message
+if ($errormessage) {
+	&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+	print "<font class='base'>$errormessage&nbsp;</font>\n";
+	&Header::closebox();
+}
+
+# Show log output while Pakfire is running
+if(&_is_pakfire_busy()) {
+	&Header::openbox("100%", "center", "Pakfire");
+
+	print <<END
+<section id="pflog-header">
+	<div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div>
+	<div>
+		<span id="pflog-status">$Lang::tr{'pakfire working'}</span><br>
+		<span id="pflog-time"></span><br>
+		<span id="pflog-action"></span>
+	</div>
+	<div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div>
+</section>
+
+<!-- Pakfire log messages -->
+<pre id="pflog-messages"></pre>
+<script>
+	// Start automatic log refresh
+	pakfire.running = true;
+</script>
+
+END
+;
+
+	&Header::closebox();
+	&Header::closebigbox();
+	&Header::closepage();
+	exit;
+}
+
+# Show Pakfire install/remove dependencies and confirm form
 if (($cgiparams{'ACTION'} eq 'install') && (! &_is_pakfire_busy())) {
 	&Header::openbox("100%", "center", $Lang::tr{'request'});
 
@@ -290,6 +328,7 @@  END
 	exit;
 }
 
+# Show Pakfire main page
 my %selected=();
 my %checked=();
 
@@ -299,44 +338,6 @@  $selected{"TREE"}{"testing"} = "";
 $selected{"TREE"}{"unstable"} = "";
 $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected";
 
-# DPC move error message to top so it is seen!
-if ($errormessage) {
-	&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
-	print "<font class='base'>$errormessage&nbsp;</font>\n";
-	&Header::closebox();
-}
-
-# Show log output while Pakfire is running
-if(&_is_pakfire_busy()) {
-	&Header::openbox("100%", "center", "Pakfire");
-
-	print <<END
-<section id="pflog-header">
-	<div><img src="/images/indicator.gif" alt="$Lang::tr{'active'}" title="$Lang::tr{'pagerefresh'}"></div>
-	<div>
-		<span id="pflog-status">$Lang::tr{'pakfire working'}</span><br>
-		<span id="pflog-time"></span><br>
-		<span id="pflog-action"></span>
-	</div>
-	<div><a href="$ENV{'SCRIPT_NAME'}"><img src="/images/view-refresh.png" alt="$Lang::tr{'refresh'}" title="$Lang::tr{'refresh'}"></a></div>
-</section>
-
-<!-- Pakfire log messages -->
-<pre id="pflog-messages"></pre>
-<script>
-	// Start automatic log refresh
-	pakfire.running = true;
-</script>
-
-END
-;
-
-	&Header::closebox();
-	&Header::closebigbox();
-	&Header::closepage();
-	exit;
-}
-
 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");