[pbs-devel] [PATCH proxmox-backup 4/5] server/rest: add console to index

Dominik Csapak d.csapak at proxmox.com
Tue Jul 21 11:10:39 CEST 2020


register the console template and render it when the 'console' parameter
is given

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs | 1 +
 src/server/rest.rs              | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 1e93886..a303391 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -56,6 +56,7 @@ async fn run() -> Result<(), Error> {
     let mut indexpath = PathBuf::from(buildcfg::JS_DIR);
     indexpath.push("index.hbs");
     config.register_template("index", &indexpath)?;
+    config.register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")?;
 
     let rest_server = RestServer::new(config);
 
diff --git a/src/server/rest.rs b/src/server/rest.rs
index a7b0a23..09b6848 100644
--- a/src/server/rest.rs
+++ b/src/server/rest.rs
@@ -319,11 +319,14 @@ fn get_index(username: Option<String>, token: Option<String>, api: &Arc<ApiConfi
     let token = token.unwrap_or_else(|| String::from(""));
 
     let mut debug = false;
+    let mut template_file = "index";
 
     if let Some(query_str) = parts.uri.query() {
         for (k, v) in form_urlencoded::parse(query_str.as_bytes()).into_owned() {
             if k == "debug" && v != "0" && v != "false" {
                 debug = true;
+            } else if k == "console" {
+                template_file = "console";
             }
         }
     }
@@ -337,12 +340,12 @@ fn get_index(username: Option<String>, token: Option<String>, api: &Arc<ApiConfi
 
     let mut ct = "text/html";
 
-    let index = match api.render_template("index", &data) {
+    let index = match api.render_template(template_file, &data) {
         Ok(index) => index,
         Err(err) => {
             ct = "text/plain";
             format!("Error rendering template: {}", err)
-        },
+        }
     };
 
     Response::builder()
-- 
2.20.1






More information about the pbs-devel mailing list