2018-02-10 00:00:55 +00:00
|
|
|
mod accounts;
|
|
|
|
mod ciphers;
|
|
|
|
mod folders;
|
2018-02-17 21:30:19 +00:00
|
|
|
mod organizations;
|
2018-07-12 19:46:50 +00:00
|
|
|
pub(crate) mod two_factor;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
use self::accounts::*;
|
|
|
|
use self::ciphers::*;
|
|
|
|
use self::folders::*;
|
2018-02-17 21:30:19 +00:00
|
|
|
use self::organizations::*;
|
2018-02-10 00:00:55 +00:00
|
|
|
use self::two_factor::*;
|
|
|
|
|
|
|
|
pub fn routes() -> Vec<Route> {
|
|
|
|
routes![
|
|
|
|
register,
|
|
|
|
profile,
|
2018-08-15 15:10:40 +00:00
|
|
|
put_profile,
|
2018-06-16 22:06:59 +00:00
|
|
|
post_profile,
|
2018-04-24 20:01:55 +00:00
|
|
|
get_public_keys,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_keys,
|
|
|
|
post_password,
|
2018-09-19 15:30:14 +00:00
|
|
|
post_kdf,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_sstamp,
|
2018-06-16 22:06:59 +00:00
|
|
|
post_email_token,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_email,
|
|
|
|
delete_account,
|
2018-09-18 10:13:45 +00:00
|
|
|
post_delete_account,
|
2018-02-10 00:00:55 +00:00
|
|
|
revision_date,
|
2018-08-10 13:21:42 +00:00
|
|
|
password_hint,
|
2018-08-24 17:02:34 +00:00
|
|
|
prelogin,
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
sync,
|
2018-10-18 22:54:40 +00:00
|
|
|
sync_no_query,
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
get_ciphers,
|
|
|
|
get_cipher,
|
2018-05-04 17:25:50 +00:00
|
|
|
get_cipher_admin,
|
2018-05-17 22:03:08 +00:00
|
|
|
get_cipher_details,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_ciphers,
|
2018-08-15 13:27:37 +00:00
|
|
|
put_cipher_admin,
|
2018-04-27 11:49:34 +00:00
|
|
|
post_ciphers_admin,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_ciphers_import,
|
|
|
|
post_attachment,
|
2018-07-14 06:09:20 +00:00
|
|
|
post_attachment_admin,
|
|
|
|
post_attachment_share,
|
2018-02-14 23:40:34 +00:00
|
|
|
delete_attachment_post,
|
2018-07-14 06:09:20 +00:00
|
|
|
delete_attachment_post_admin,
|
2018-02-10 00:00:55 +00:00
|
|
|
delete_attachment,
|
2018-08-28 22:48:53 +00:00
|
|
|
delete_attachment_admin,
|
2018-05-04 17:25:50 +00:00
|
|
|
post_cipher_admin,
|
2018-05-14 15:13:59 +00:00
|
|
|
post_cipher_share,
|
2018-08-01 18:37:14 +00:00
|
|
|
put_cipher_share,
|
2018-08-13 11:35:41 +00:00
|
|
|
put_cipher_share_seleted,
|
2018-02-10 00:00:55 +00:00
|
|
|
post_cipher,
|
|
|
|
put_cipher,
|
2018-02-15 23:32:26 +00:00
|
|
|
delete_cipher_post,
|
2018-07-01 11:43:11 +00:00
|
|
|
delete_cipher_post_admin,
|
2018-03-05 23:02:36 +00:00
|
|
|
delete_cipher,
|
2018-08-28 22:48:53 +00:00
|
|
|
delete_cipher_admin,
|
2018-03-05 23:02:36 +00:00
|
|
|
delete_cipher_selected,
|
2018-08-03 14:01:01 +00:00
|
|
|
delete_cipher_selected_post,
|
2018-02-10 00:00:55 +00:00
|
|
|
delete_all,
|
2018-04-19 14:32:11 +00:00
|
|
|
move_cipher_selected,
|
2018-08-01 05:51:05 +00:00
|
|
|
move_cipher_selected_put,
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
get_folders,
|
|
|
|
get_folder,
|
|
|
|
post_folders,
|
|
|
|
post_folder,
|
|
|
|
put_folder,
|
|
|
|
delete_folder_post,
|
|
|
|
delete_folder,
|
|
|
|
|
|
|
|
get_twofactor,
|
|
|
|
get_recover,
|
2018-02-15 18:05:57 +00:00
|
|
|
recover,
|
2018-07-12 19:46:50 +00:00
|
|
|
disable_twofactor,
|
2018-08-10 17:49:07 +00:00
|
|
|
disable_twofactor_put,
|
2018-02-10 00:00:55 +00:00
|
|
|
generate_authenticator,
|
|
|
|
activate_authenticator,
|
2018-08-10 17:49:07 +00:00
|
|
|
activate_authenticator_put,
|
2018-07-12 19:46:50 +00:00
|
|
|
generate_u2f,
|
|
|
|
activate_u2f,
|
2018-08-13 13:26:01 +00:00
|
|
|
activate_u2f_put,
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-04-20 16:35:11 +00:00
|
|
|
get_organization,
|
2018-04-24 20:01:55 +00:00
|
|
|
create_organization,
|
2018-04-24 22:34:40 +00:00
|
|
|
delete_organization,
|
2018-08-13 15:45:30 +00:00
|
|
|
post_delete_organization,
|
2018-07-11 14:30:03 +00:00
|
|
|
leave_organization,
|
2018-02-17 21:30:19 +00:00
|
|
|
get_user_collections,
|
2018-04-24 20:01:55 +00:00
|
|
|
get_org_collections,
|
2018-04-20 16:35:11 +00:00
|
|
|
get_org_collection_detail,
|
2018-04-24 22:34:40 +00:00
|
|
|
get_collection_users,
|
2018-08-21 12:25:52 +00:00
|
|
|
put_organization,
|
2018-04-20 16:35:11 +00:00
|
|
|
post_organization,
|
|
|
|
post_organization_collections,
|
2018-08-13 15:45:30 +00:00
|
|
|
delete_organization_collection_user,
|
2018-05-29 15:01:38 +00:00
|
|
|
post_organization_collection_delete_user,
|
2018-04-20 16:35:11 +00:00
|
|
|
post_organization_collection_update,
|
2018-08-13 15:45:30 +00:00
|
|
|
put_organization_collection_update,
|
|
|
|
delete_organization_collection,
|
2018-05-16 22:05:50 +00:00
|
|
|
post_organization_collection_delete,
|
2018-05-17 22:03:08 +00:00
|
|
|
post_collections_update,
|
2018-05-09 10:55:05 +00:00
|
|
|
post_collections_admin,
|
2018-08-13 15:00:10 +00:00
|
|
|
put_collections_admin,
|
2018-04-24 20:01:55 +00:00
|
|
|
get_org_details,
|
|
|
|
get_org_users,
|
|
|
|
send_invite,
|
|
|
|
confirm_invite,
|
2018-04-24 22:34:40 +00:00
|
|
|
get_user,
|
|
|
|
edit_user,
|
2018-08-13 15:45:30 +00:00
|
|
|
put_organization_user,
|
2018-04-24 20:01:55 +00:00
|
|
|
delete_user,
|
2018-08-13 15:45:30 +00:00
|
|
|
post_delete_user,
|
2018-10-05 09:38:02 +00:00
|
|
|
post_reinvite_user,
|
2018-09-13 13:16:24 +00:00
|
|
|
post_org_import,
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
clear_device_token,
|
|
|
|
put_device_token,
|
|
|
|
|
|
|
|
get_eq_domains,
|
2018-04-20 16:35:11 +00:00
|
|
|
post_eq_domains,
|
2018-10-22 22:32:43 +00:00
|
|
|
put_eq_domains,
|
2018-04-20 16:35:11 +00:00
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Move this somewhere else
|
|
|
|
///
|
|
|
|
|
|
|
|
use rocket::Route;
|
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
use rocket_contrib::{Json, Value};
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
use db::DbConn;
|
2018-06-01 13:08:03 +00:00
|
|
|
use db::models::*;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-05-31 22:18:50 +00:00
|
|
|
use api::{JsonResult, EmptyResult, JsonUpcase};
|
2018-02-10 00:00:55 +00:00
|
|
|
use auth::Headers;
|
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
#[put("/devices/identifier/<uuid>/clear-token", data = "<data>")]
|
|
|
|
fn clear_device_token(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> EmptyResult {
|
2018-07-04 12:27:47 +00:00
|
|
|
let _data: Value = data.into_inner();
|
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
let device = match Device::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(device) => device,
|
|
|
|
None => err!("Device not found")
|
|
|
|
};
|
|
|
|
|
|
|
|
if device.user_uuid != headers.user.uuid {
|
|
|
|
err!("Device not owned by user")
|
|
|
|
}
|
|
|
|
|
2018-10-12 14:20:10 +00:00
|
|
|
match device.delete(&conn) {
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err(_) => err!("Failed deleting device")
|
|
|
|
}
|
2018-02-17 19:47:13 +00:00
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
#[put("/devices/identifier/<uuid>/token", data = "<data>")]
|
|
|
|
fn put_device_token(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-07-04 12:27:47 +00:00
|
|
|
let _data: Value = data.into_inner();
|
|
|
|
|
2018-06-01 13:08:03 +00:00
|
|
|
let device = match Device::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(device) => device,
|
|
|
|
None => err!("Device not found")
|
|
|
|
};
|
|
|
|
|
|
|
|
if device.user_uuid != headers.user.uuid {
|
|
|
|
err!("Device not owned by user")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: What does this do?
|
|
|
|
|
2018-02-17 19:47:13 +00:00
|
|
|
err!("Not implemented")
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-17 22:21:04 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct GlobalDomain {
|
|
|
|
Type: i32,
|
|
|
|
Domains: Vec<String>,
|
|
|
|
Excluded: bool,
|
|
|
|
}
|
|
|
|
|
2018-06-11 13:44:37 +00:00
|
|
|
const GLOBAL_DOMAINS: &str = include_str!("global_domains.json");
|
2018-02-17 22:21:04 +00:00
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
#[get("/settings/domains")]
|
2018-02-20 13:09:00 +00:00
|
|
|
fn get_eq_domains(headers: Headers) -> JsonResult {
|
2018-02-17 22:21:04 +00:00
|
|
|
let user = headers.user;
|
|
|
|
use serde_json::from_str;
|
|
|
|
|
|
|
|
let equivalent_domains: Vec<Vec<String>> = from_str(&user.equivalent_domains).unwrap();
|
|
|
|
let excluded_globals: Vec<i32> = from_str(&user.excluded_globals).unwrap();
|
|
|
|
|
|
|
|
let mut globals: Vec<GlobalDomain> = from_str(GLOBAL_DOMAINS).unwrap();
|
|
|
|
|
|
|
|
for global in &mut globals {
|
|
|
|
global.Excluded = excluded_globals.contains(&global.Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Json(json!({
|
|
|
|
"EquivalentDomains": equivalent_domains,
|
2018-02-20 13:09:00 +00:00
|
|
|
"GlobalEquivalentDomains": globals,
|
|
|
|
"Object": "domains",
|
2018-02-17 22:21:04 +00:00
|
|
|
})))
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct EquivDomainData {
|
|
|
|
ExcludedGlobalEquivalentDomains: Option<Vec<i32>>,
|
|
|
|
EquivalentDomains: Option<Vec<Vec<String>>>,
|
|
|
|
}
|
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
#[post("/settings/domains", data = "<data>")]
|
2018-10-22 22:32:43 +00:00
|
|
|
fn post_eq_domains(data: JsonUpcase<EquivDomainData>, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-05-31 22:18:50 +00:00
|
|
|
let data: EquivDomainData = data.into_inner().data;
|
2018-02-14 23:40:34 +00:00
|
|
|
|
2018-06-11 13:44:37 +00:00
|
|
|
let excluded_globals = data.ExcludedGlobalEquivalentDomains.unwrap_or_default();
|
|
|
|
let equivalent_domains = data.EquivalentDomains.unwrap_or_default();
|
2018-02-14 23:40:34 +00:00
|
|
|
|
2018-02-17 22:21:04 +00:00
|
|
|
let mut user = headers.user;
|
|
|
|
use serde_json::to_string;
|
2018-02-14 23:40:34 +00:00
|
|
|
|
2018-02-17 22:21:04 +00:00
|
|
|
user.excluded_globals = to_string(&excluded_globals).unwrap_or("[]".to_string());
|
|
|
|
user.equivalent_domains = to_string(&equivalent_domains).unwrap_or("[]".to_string());
|
|
|
|
|
2018-10-14 17:32:43 +00:00
|
|
|
match user.save(&conn) {
|
2018-10-22 22:32:43 +00:00
|
|
|
Ok(()) => Ok(Json(json!({}))),
|
2018-10-14 17:32:43 +00:00
|
|
|
Err(_) => err!("Failed to save user")
|
|
|
|
}
|
2018-02-17 22:21:04 +00:00
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
2018-10-22 22:32:43 +00:00
|
|
|
|
|
|
|
#[put("/settings/domains", data = "<data>")]
|
|
|
|
fn put_eq_domains(data: JsonUpcase<EquivDomainData>, headers: Headers, conn: DbConn) -> JsonResult {
|
|
|
|
post_eq_domains(data, headers, conn)
|
|
|
|
}
|