From patchwork Thu Jan 9 19:04:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adolf Belka X-Patchwork-Id: 8389 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R11" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4YTZ3d4PkLz3x36 for ; Thu, 9 Jan 2025 19:05:01 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "E5" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4YTZ3Y5N2lz2J6; Thu, 9 Jan 2025 19:04:57 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4YTZ3Y2x0mz343j; Thu, 9 Jan 2025 19:04:57 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "R11" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4YTZ3V61PVz32bL for ; Thu, 9 Jan 2025 19:04:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4YTZ3V0cPdzTl; Thu, 9 Jan 2025 19:04:54 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1736449494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UXwlEqLlF2BUKIyg/y9rs2/j+gQHT0A9K+zRWY1h0Yg=; b=3f0Yw03P4U7aM+jbKYEZfZrNTl9nc+9KA+b/yq0wvb9iApMPEv60G+8XUl97vnp6D6jZgr bNlNgbmpXJdND4DA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1736449494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UXwlEqLlF2BUKIyg/y9rs2/j+gQHT0A9K+zRWY1h0Yg=; b=DK25Kft7GaEoDWED/0qPEEsyxnlIbr9GKC9edX1MSMARXwc4PGxKdaOVUDlbEmM8LkSSA5 5xacUdr6zz19qaQtEEldvgLsVruFpj0J8tA/oz78aCbUJWIstlFcaKetBwZDj5CqfxEXnl 6Djx86w7dl6OO7xf4q8QxnRT19fV30vZTFIHujGmpyIO9hfDz0NSMIBM3eWk2wYncB4xYw 674Y/gPAFMictaDyWJBJoGpjW24T1zG9OaRScC6N3di9ThzU5q/m1wuYN4vAnwDrr7dDYF sm4bq13a9+vOIcpMayywYpjSG0QGgE5AubULg2a2hn/cTnvaWj+vsbkFaWQ+iA== From: Adolf Belka To: development@lists.ipfire.org Subject: [PATCH v2 1/4] logo.cgi: Fix for bug13795 - captive portal not displaying uploaded logo Date: Thu, 9 Jan 2025 20:04:35 +0100 Message-ID: <20250109190441.18122-1-adolf.belka@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: MY737TMWWUZ7CAUN7OMDBF2P5ICTJWPR X-Message-ID-Hash: MY737TMWWUZ7CAUN7OMDBF2P5ICTJWPR X-MailFrom: adolf.belka@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: - 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 Signed-off-by: Adolf Belka --- 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@ipfire.org # +# Copyright (C) 2016-2024 IPFire Team # # # -# 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);