From: Adolf Belka <adolf.belka@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH v2 1/4] logo.cgi: Fix for bug13795 - captive portal not displaying uploaded logo
Date: Thu, 09 Jan 2025 20:04:35 +0100 [thread overview]
Message-ID: <20250109190441.18122-1-adolf.belka@ipfire.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 3532 bytes --]
- This v2 version now includes the use of File-LibMagic to identify the specific
content type and apply that to the modified header command so that image/png or
image/jp[eg are used depending on the type of image provided.
- Something changed in some package in CU188 that means that the existing method of
printing the content type to the browser no longer worked.
- I tested it in some stand alone code and even if using text/txt for the content-type
print statement the File::Copy::copy then resulted in an Internal Server Error with
the same message as with the image file which was "malformed header from script
'logo.cgi': Bad header:".
- I tested it with text, html, image and application. In all cases the error message
about a bad header was provided.
- Did some searching and found an alternative way to explicitly print the header info
which is what I have used in this patch change.
- With this approach, in the stand alone code, I was able to get an image, html code or
text shown in the browser correctly and without any error message.
- I then used this new method in the logo.cgi code as submitted here and tested the
change in my vm testbed and the image was shown in the captive portal correctly.
- So this change fixes the problem with the logo not being shown but I have been unable
to identify what changed to stop the method that worked prior to CU188 from working
any more.
Fixes: Bug13795
Tested-by: Adolf Belka <adolf.belka(a)ipfire.org>
Signed-off-by: Adolf Belka <adolf.belka(a)ipfire.org>
---
html/cgi-bin/captive/logo.cgi | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/html/cgi-bin/captive/logo.cgi b/html/cgi-bin/captive/logo.cgi
index 8f292b171..0b09476aa 100644
--- a/html/cgi-bin/captive/logo.cgi
+++ b/html/cgi-bin/captive/logo.cgi
@@ -2,9 +2,9 @@
###############################################################################
# #
# IPFire.org - A linux based firewall #
-# Copyright (C) 2016 Alexander Marx alexander.marx(a)ipfire.org #
+# Copyright (C) 2016-2024 IPFire Team <info(a)ipfire.org> #
# #
-# This program is free software you can redistribute it and/or modify #
+# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
@@ -22,6 +22,7 @@
use strict;
use CGI;
use File::Copy;
+use File::LibMagic;
# enable only the following on debugging purpose
#use warnings;
@@ -29,7 +30,11 @@ use File::Copy;
require '/var/ipfire/general-functions.pl';
+my $q = new CGI;
+my $magic = File::LibMagic->new;
+
my $logo = "${General::swroot}/captive/logo.dat";
+my $file_info = $magic->info_from_filename($logo);
# Send 404 if logo was not uploaded and exit
if (!-e $logo) {
@@ -37,8 +42,8 @@ if (!-e $logo) {
exit(0);
}
-print "Content-Type: application/octet-stream\n\n";
-
# Send image data
+print $q->header(-type=>$file_info->{mime_type});
+binmode STDOUT;
File::Copy::copy $logo, \*STDOUT;
exit(0);
--
2.47.1
next reply other threads:[~2025-01-09 19:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 19:04 Adolf Belka [this message]
2025-01-09 19:04 ` [PATCH v2 2/4] captive.cgi: Update code to check for the image content type not just the extension Adolf Belka
2025-01-09 19:04 ` [PATCH v2 3/4] perl-File-LibMagic: New package implemented for content type extraction of a file Adolf Belka
2025-01-09 19:04 ` [PATCH v2 4/4] language files: Updated de, en, es, fr & tr language files Adolf Belka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250109190441.18122-1-adolf.belka@ipfire.org \
--to=adolf.belka@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox