|
|
@@ -20,10 +20,15 @@ pub struct FormChangePasswd {
|
|
|
}
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
-pub struct FormSSHKey {
|
|
|
+pub struct FormAddSSHKey {
|
|
|
new_ssh_key: String,
|
|
|
}
|
|
|
|
|
|
+#[derive(Deserialize)]
|
|
|
+pub struct FormDelSSHKey {
|
|
|
+ key_to_delete: String,
|
|
|
+}
|
|
|
+
|
|
|
async fn get_template(template_name: String, session: Session) -> String {
|
|
|
let error_message: Option<String> = session.get("error_message")
|
|
|
.unwrap_or(None);
|
|
|
@@ -206,7 +211,7 @@ pub async fn form_ssh(ldap_wrapper: web::Data<LdapWrapper>, session: Session) ->
|
|
|
.body(body)
|
|
|
}
|
|
|
|
|
|
-pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<FormSSHKey>,session: Session) -> impl Responder {
|
|
|
+pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<FormAddSSHKey>,session: Session) -> impl Responder {
|
|
|
if !validate_session(&session) {
|
|
|
return HttpResponse::Ok()
|
|
|
.status(StatusCode::FOUND)
|
|
|
@@ -224,7 +229,7 @@ pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<F
|
|
|
|
|
|
let uid = session.get("user_id").unwrap().unwrap();
|
|
|
|
|
|
- match ldap_wrapper.add_ssh_key(uid, form.new_ssh_key.clone()).await {
|
|
|
+ match ldap_wrapper.manage_ssh_key(uid, form.new_ssh_key.clone(), ldap::ManageSSHOps::ADD).await {
|
|
|
Ok(_) => return HttpResponse::Ok()
|
|
|
.status(StatusCode::FOUND)
|
|
|
.append_header((header::LOCATION, "/ssh"))
|
|
|
@@ -239,10 +244,37 @@ pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<F
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-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 del_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<FormDelSSHKey>,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.manage_ssh_key(uid, form.key_to_delete.clone(), ldap::ManageSSHOps::DEL).await {
|
|
|
+ Ok(_) => return HttpResponse::Ok()
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
+ .append_header((header::LOCATION, "/ssh"))
|
|
|
+ .finish(),
|
|
|
+ Err(e) => {
|
|
|
+ session.insert("error_message", e.to_string()).unwrap();
|
|
|
+ return HttpResponse::Ok()
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
+ .append_header((header::LOCATION, "/ssh"))
|
|
|
+ .finish()
|
|
|
+ },
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
pub async fn signout(session: Session) -> impl Responder {
|