From c06a15c3bbb6fba160543b7bda533455b36dbe9a Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 24 Feb 2023 22:19:30 +0000 Subject: [PATCH] add no token proxmox api proxy endpoint Signed-off-by: Arthur Lu --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c138ab2..8f19c27 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,12 @@ app.get("/api/auth", async (req, res) => { res.send({auth: result}); }); +app.get("/api/proxmox/*", async (req, res) => { // proxy endpoint for proxmox api with no token + path = req.url.replace("/api/proxmox", ""); + let result = await requestPVE(path, "GET", req.cookies); + res.send(result.data, result.status); +}); + app.post("/api/disk/detach", async (req, res) => { let vmpath = `/nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`; @@ -188,7 +194,7 @@ async function requestPVE (path, method, cookies, body = null, token = null) { if (token) { content.headers.Authorization = `PVEAPIToken=${token.user}@${token.realm}!${token.id}=${token.uuid}`; } - else { + else if (cookies) { content.headers.CSRFPreventionToken = cookies.CSRFPreventionToken; content.headers.Cookie = `PVEAuthCookie=${cookies.PVEAuthCookie}; CSRFPreventionToken=${cookies.CSRFPreventionToken}`; } @@ -202,7 +208,7 @@ async function requestPVE (path, method, cookies, body = null, token = null) { return response; } catch (error) { - return error; + return error.response; } }