|
|
@@ -1,3 +1,5 @@
|
|
|
+use std::collections::HashMap;
|
|
|
+
|
|
|
use actix_session::Session;
|
|
|
use actix_web::{http::{header, StatusCode}, web, HttpResponse, Responder};
|
|
|
use ldap::LdapWrapper;
|
|
|
@@ -25,6 +27,9 @@ async fn get_template(template_name: String, session: Session) -> String {
|
|
|
.unwrap_or(None);
|
|
|
let user_is_ssh: Option<bool> = session.get("user_is_ssh")
|
|
|
.unwrap_or(None);
|
|
|
+ let ssh_keys: Option<HashMap<String, String>> = session.get("ssh_keys")
|
|
|
+ .unwrap_or(None);
|
|
|
+
|
|
|
|
|
|
let tera = Tera::new("templates/*.html")
|
|
|
.expect("Failed to parse template files");
|
|
|
@@ -45,6 +50,10 @@ async fn get_template(template_name: String, session: Session) -> String {
|
|
|
Some(user_is_ssh) => ctx.insert("user_is_ssh", &user_is_ssh),
|
|
|
None => (),
|
|
|
}
|
|
|
+ match ssh_keys {
|
|
|
+ Some(ssh_keys) => ctx.insert("ssh_keys", &ssh_keys),
|
|
|
+ None => (),
|
|
|
+ }
|
|
|
|
|
|
tera.render(&template_name, &ctx)
|
|
|
.expect(format!("Faile to render template {}", template_name).as_str())
|
|
|
@@ -161,6 +170,49 @@ pub async fn change_password(ldap_wrapper: web::Data<LdapWrapper>, form: web::Fo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+pub async fn form_ssh(ldap_wrapper: web::Data<LdapWrapper>, session: Session) -> impl Responder {
|
|
|
+ if !validate_session(&session) {
|
|
|
+ return HttpResponse::Ok()
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
+ .append_header((header::LOCATION, "/"))
|
|
|
+ .finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ let is_ssh: bool = session.get("user_is_ssh").unwrap_or(None).unwrap();
|
|
|
+ if !is_ssh {
|
|
|
+ return HttpResponse::Ok()
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
+ .append_header((header::LOCATION, "/"))
|
|
|
+ .finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ let uid = session.get("user_id").unwrap().unwrap();
|
|
|
+
|
|
|
+ match ldap_wrapper.get_ssh_keys(uid).await {
|
|
|
+ Ok(ssh_keys) => {
|
|
|
+ session.insert("ssh_keys", ssh_keys).unwrap();
|
|
|
+ },
|
|
|
+ Err(e) => {
|
|
|
+ session.insert("error_message", e.to_string()).unwrap();
|
|
|
+ },
|
|
|
+ }
|
|
|
+ let body = get_template("sshhomepage.html".to_string(), session).await;
|
|
|
+ HttpResponse::Ok().content_type("text/html")
|
|
|
+ .body(body)
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn add_ssh_key(session: Session) -> impl Responder {
|
|
|
+ let body = get_template("sshhomepage.html".to_string(), session).await;
|
|
|
+ HttpResponse::Ok().content_type("text/html")
|
|
|
+ .body(body)
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn del_ssh_key(session: Session) -> impl Responder {
|
|
|
+ let body = get_template("sshhomepage.html".to_string(), session).await;
|
|
|
+ HttpResponse::Ok().content_type("text/html")
|
|
|
+ .body(body)
|
|
|
+}
|
|
|
+
|
|
|
pub async fn signout(session: Session) -> impl Responder {
|
|
|
session.purge();
|
|
|
HttpResponse::Ok()
|