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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 41A3595BE for ; Wed, 8 Mar 2023 17:40:44 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1146B95E4 for ; Wed, 8 Mar 2023 17:40:14 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 8 Mar 2023 17:40:13 +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 CAB3846301 for ; Wed, 8 Mar 2023 17:40:12 +0100 (CET) From: Stefan Sterz To: pve-devel@lists.proxmox.com Date: Wed, 8 Mar 2023 17:40:07 +0100 Message-Id: <20230308164010.2463409-2-s.sterz@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308164010.2463409-1-s.sterz@proxmox.com> References: <20230308161840.2396113-1-s.sterz@proxmox.com> <20230308164010.2463409-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.094 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [pveproxy.pm] Subject: [pve-devel] [PATCH manager v1 2/4] pveproxy/template: add support for switching themes X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Mar 2023 16:40:44 -0000 load the dark theme only if requested through a cookie, also adds support for the "auto" theme that uses the dark theme based on a media query. this requires a bump of the widget toolkit so the dark-theme css file is available. Signed-off-by: Stefan Sterz --- PVE/Service/pveproxy.pm | 13 +++++++++++++ www/index.html.tpl | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm index f73fdd6f..3fd76128 100755 --- a/PVE/Service/pveproxy.pm +++ b/PVE/Service/pveproxy.pm @@ -88,6 +88,7 @@ sub init { add_dirs($dirs, '/xtermjs/' => "$basedirs->{xtermjs}/"); add_dirs($dirs, '/pwt/images/' => "$basedirs->{widgettoolkit}/images/"); add_dirs($dirs, '/pwt/css/' => "$basedirs->{widgettoolkit}/css/"); + add_dirs($dirs, '/pwt/themes/' => "$basedirs->{widgettoolkit}/themes/"); $self->{server_config} = { title => 'Proxmox VE API', @@ -191,6 +192,7 @@ sub get_index { my $lang; my $username; my $token = 'null'; + my $theme = ""; if (my $cookie = $r->header('Cookie')) { if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) { @@ -198,6 +200,15 @@ sub get_index { $lang = $newlang; } } + + if (my $newtheme = ($cookie =~ /(?:^|\s)PVEThemeCookie=([^;]*)/)[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 (($username = PVE::AccessControl::verify_ticket($ticket, 1))) { $token = PVE::AccessControl::assemble_csrf_prevention_token($username); @@ -252,6 +263,8 @@ sub get_index { debug => $debug, version => "$version", wtversion => $wtversion, + theme => $theme, + auto => $theme == "auto", }; # by default, load the normal index diff --git a/www/index.html.tpl b/www/index.html.tpl index 0c819977..be31dd40 100644 --- a/www/index.html.tpl +++ b/www/index.html.tpl @@ -12,6 +12,14 @@ + [%- IF theme %] + [%- IF theme == 'auto' %] + + [%- ELSE %] + + [%- END -%] + [%- END -%] + [% IF langfile %] [%- ELSE %] -- 2.30.2