From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 54BD890675 for ; Thu, 9 Mar 2023 09:00:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3AC676FC7 for ; Thu, 9 Mar 2023 09:00:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 9 Mar 2023 09:00:28 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3B1F2416E8 for ; Thu, 9 Mar 2023 09:00:28 +0100 (CET) From: Stefan Sterz To: pmg-devel@lists.proxmox.com Date: Thu, 9 Mar 2023 09:00:15 +0100 Message-Id: <20230309080015.28615-1-s.sterz@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308161840.2396113-1-s.sterz@proxmox.com> References: <20230308161840.2396113-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.077 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] [PATCH pmg-api v1] proxy: add support for switching themes X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Mar 2023 08:00:29 -0000 parse the theme cookie so users can switch between themes in the ui this requires a bump of the pmg-gui, which in turn needs a bump for the widget toolkit, so the parameters passed to the template are handled appropriately. Signed-off-by: Stefan Sterz --- src/PMG/Service/pmgproxy.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/PMG/Service/pmgproxy.pm b/src/PMG/Service/pmgproxy.pm index 5334e6f..9b5ba52 100755 --- a/src/PMG/Service/pmgproxy.pm +++ b/src/PMG/Service/pmgproxy.pm @@ -83,7 +83,8 @@ sub init { add_dirs($dirs, '/pmg-docs/' => '/usr/share/pmg-docs/'); add_dirs($dirs, '/pmg-docs/api-viewer/extjs/' => $extjs_dir); add_dirs($dirs, '/pwt/css/' => "$widgettoolkit_dir/css/"); - add_dirs($dirs, '/pwt/images/' => "$widgettoolkit_dir/images/"); + add_dirs($dirs, '/pwt/images/' => "$widgettoolkit_dir/images/"); + add_dirs($dirs, '/pwt/themes/' => "$widgettoolkit_dir/themes/"); $self->{server_config} = { title => 'Proxmox Mail Gateway API', @@ -198,12 +199,23 @@ sub get_index { $mobile = $args->{mobile} ? 1 : 0; } + my $theme; + if (my $cookie = $r->header('Cookie')) { if (my $newlang = ($cookie =~ /(?:^|\s)PMGLangCookie=([^;]*)/)[0]) { if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) { $lang = $newlang; } } + + if (my $newtheme = ($cookie =~ /(?:^|\s)PMGThemeCookie=([^;]*)/)[0]) { + # theme names need to be kebab case, with each segment a maximum of 10 characters long + # and at most 6 segments + if ($newtheme =~ m/^[a-z]{1,10}(-[a-z]{1,10}){0,5}$/) { + $theme = $newtheme; + } + } + my $ticket = PVE::APIServer::Formatter::extract_auth_value($cookie, $server->{cookie_name}); if ($ticket =~ m/^PMGQUAR:/) { @@ -257,6 +269,8 @@ sub get_index { version => $version, wtversion => $wtversion, quarantinelink => $quarantinelink, + theme => $theme, + auto => $theme == "auto", }; my $template_name; -- 2.30.2