From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 089371FF168
	for <inbox@lore.proxmox.com>; Tue, 10 Dec 2024 17:12:46 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id DE11734329;
	Tue, 10 Dec 2024 17:12:35 +0100 (CET)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 10 Dec 2024 17:11:55 +0100
Message-Id: <20241210161158.383142-2-g.goller@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20241210161158.383142-1-g.goller@proxmox.com>
References: <20241210161158.383142-1-g.goller@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.034 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 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 v3 1/4] show optional consent-banner
 before login
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Add ConsentBanner variable to html template and populate it from the
`datacenter.cfg` config file. Add Datacenter option to set the text and
trigger the popup on login. The max length of the input is 63*1024,
which is a bit less than the max body size for a api request (64*1024).

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 PVE/Service/pveproxy.pm            | 13 ++++++++++---
 www/index.html.tpl                 |  3 ++-
 www/manager6/dc/OptionView.js      |  8 ++++++++
 www/manager6/window/LoginWindow.js | 12 +++++++++++-
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm
index ac1085457f2e..b5bfd34ca3aa 100755
--- a/PVE/Service/pveproxy.pm
+++ b/PVE/Service/pveproxy.pm
@@ -218,10 +218,16 @@ sub get_index {
 	}
     }
 
-    if (!$lang) {
+    my $consent_text;
+    eval {
 	my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
-	$lang = $dc_conf->{language} // 'en';
-    }
+	$consent_text = $dc_conf->{'consent-text'};
+
+	if (!$lang) {
+	    $lang = $dc_conf->{language} // 'en';
+	}
+    };
+    warn "$@\n" if $@;
 
     my $mobile = (is_phone($r->header('User-Agent')) && (!defined($args->{mobile}) || $args->{mobile})) || $args->{mobile};
 
@@ -251,6 +257,7 @@ sub get_index {
 	version => "$version",
 	wtversion => $wtversion,
 	theme => $theme,
+	consenttext => $consent_text
     };
 
     # by default, load the normal index
diff --git a/www/index.html.tpl b/www/index.html.tpl
index 46dc877bcaf2..d53a867522dd 100644
--- a/www/index.html.tpl
+++ b/www/index.html.tpl
@@ -41,7 +41,8 @@
 	defaultLang: '[% lang %]',
 	NodeName: '[% nodename %]',
 	UserName: '[% username %]',
-	CSRFPreventionToken: '[% token %]'
+	CSRFPreventionToken: '[% token %]',
+	ConsentText: '[% consenttext %]'
     };
     </script>
     <script type="text/javascript" src="/proxmoxlib.js?ver=[% wtversion %]"></script>
diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index b200fd12dcc9..02e640d88f60 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -516,6 +516,14 @@ Ext.define('PVE.dc.OptionView', {
 	    },
 	};
 
+	me.add_textareafield_row('consent-text', gettext('Consent Text'), {
+	    deleteEmpty: true,
+	    fieldOpts: {
+		maxLength: 63 * 1024,
+	    },
+	    onlineHelp: 'consent_banner',
+	});
+
 	me.selModel = Ext.create('Ext.selection.RowModel', {});
 
 	Ext.apply(me, {
diff --git a/www/manager6/window/LoginWindow.js b/www/manager6/window/LoginWindow.js
index aaeca3550289..b4dff0c19ac1 100644
--- a/www/manager6/window/LoginWindow.js
+++ b/www/manager6/window/LoginWindow.js
@@ -18,9 +18,19 @@ Ext.define('PVE.window.LoginWindow', {
     },
 
     controller: {
-
 	xclass: 'Ext.app.ViewController',
 
+	init: async function() {
+	    if (Proxmox.ConsentText) {
+		Ext.create("Proxmox.window.ConsentModal", {
+		    autoShow: true,
+		    consent: Proxmox.Markdown.parse(
+			Proxmox.Utils.base64ToUtf8(Proxmox.ConsentText),
+		    ),
+		});
+	    }
+	},
+
 	onLogon: async function() {
 	    var me = this;
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel