From b1be01218acf051c37eea2643b87abda829a0431 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 23 Jan 2019 12:49:10 +0100 Subject: [PATCH] server/rest.rs: fake login cookie --- src/server/rest.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/server/rest.rs b/src/server/rest.rs index c2b175c2..97e80e10 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -1,3 +1,4 @@ +use crate::tools; use crate::api::schema::*; use crate::api::router::*; use crate::api::config::*; @@ -218,15 +219,15 @@ fn handle_async_api_request( fn get_index() -> BoxFut { - let nodename = "unknown"; - let username = ""; + let nodename = tools::nodename(); + let username = "fakelogin"; // todo: implement real auth let token = "abc"; let setup = json!({ "Setup": { "auth_cookie_name": "PBSAuthCookie" }, "NodeName": nodename, "UserName": username, - "CSRFPreventionToken": token + "CSRFPreventionToken": token, }); let index = format!(r###" @@ -264,7 +265,15 @@ fn get_index() -> BoxFut { "###, setup.to_string()); - Box::new(future::ok(Response::new(index.into()))) + let resp = Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "text/html") + // emulate succssful login, so that Proxmox:Utils.authOk() returns true + .header(header::SET_COOKIE, "PBSAuthCookie=\"XXX\"") // fixme: remove + .body(index.into()) + .unwrap(); + + Box::new(future::ok(resp)) } fn extension_to_content_type(filename: &Path) -> (&'static str, bool) {