public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager 1/1] httpserver: add rewrite uri for /nodes/(qemu/lxc)/<vmid>
Date: Wed, 31 May 2023 13:19:52 +0200	[thread overview]
Message-ID: <20230531111952.568734-3-aderumier@odiso.com> (raw)
In-Reply-To: <20230531111952.568734-1-aderumier@odiso.com>

If nodename is not defined, we search the nodename
and rewrite uri to /nodes/<nodename>/(qemu|lxc)/<vmid

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 PVE/HTTPServer.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
index dabdf7f3..b43611e1 100755
--- a/PVE/HTTPServer.pm
+++ b/PVE/HTTPServer.pm
@@ -46,6 +46,21 @@ sub verify_spice_connect_url {
     return ($vmid, $node, $port);
 }
 
+sub rewrite_uri {
+    my ($self, $uri) = @_;
+
+    my $base_uri = $self->{base_uri};
+    if($uri =~ m/^(\Q$base_uri\E\/+([a-z][a-z0-9]+)\/nodes\/)((qemu|lxc)\/(\d+)(.*))/) {
+	PVE::Cluster::cfs_update();
+	my $vmid = $5;
+	my $vmlist = PVE::Cluster::get_vmlist();
+	my $nodename = $vmlist->{ids}->{$vmid}->{node};
+	return $uri if !$nodename;
+	$uri = "$1$nodename/$3";
+    }
+    return $uri;
+}
+
 sub generate_csrf_prevention_token {
     my ($username) = @_;
     return PVE::AccessControl::assemble_csrf_prevention_token($username);
-- 
2.30.2




  parent reply	other threads:[~2023-05-31 11:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 11:19 [pve-devel] [PATCH-SERIES pve-http-server/pve-manager] fix#4689: rewrite_uri: autofind nodename for qemu/lxc Alexandre Derumier
2023-05-31 11:19 ` [pve-devel] [PATCH pve-http-server 1/1] anyevent: add rewrite_uri Alexandre Derumier
2023-05-31 11:19 ` Alexandre Derumier [this message]
2023-05-31 11:49 ` [pve-devel] [PATCH-SERIES pve-http-server/pve-manager] fix#4689: rewrite_uri: autofind nodename for qemu/lxc Wolfgang Bumiller
2023-05-31 14:12   ` DERUMIER, Alexandre
2023-05-31 13:19 ` Dominik Csapak
2023-05-31 14:05   ` DERUMIER, Alexandre

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=20230531111952.568734-3-aderumier@odiso.com \
    --to=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal