mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-12-12 16:53:05 +01:00
Formatting
This commit is contained in:
parent
4cec502f7b
commit
a0ece3754b
13 changed files with 29 additions and 67 deletions
|
@ -1 +1,2 @@
|
|||
version = "Two"
|
||||
max_width = 120
|
||||
|
|
|
@ -110,7 +110,7 @@ struct AdminTemplateData {
|
|||
users: Vec<Value>,
|
||||
config: Value,
|
||||
can_backup: bool,
|
||||
logged_in: bool
|
||||
logged_in: bool,
|
||||
}
|
||||
|
||||
impl AdminTemplateData {
|
||||
|
@ -121,7 +121,7 @@ impl AdminTemplateData {
|
|||
users,
|
||||
config: CONFIG.prepare_json(),
|
||||
can_backup: *CAN_BACKUP,
|
||||
logged_in: true
|
||||
logged_in: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,11 +149,10 @@ fn hibp_breach(username: String) -> JsonResult {
|
|||
use reqwest::{header::USER_AGENT, Client};
|
||||
|
||||
if let Some(api_key) = crate::CONFIG.hibp_api_key() {
|
||||
let hibp_client = Client::builder()
|
||||
.use_sys_proxy()
|
||||
.build()?;
|
||||
let hibp_client = Client::builder().use_sys_proxy().build()?;
|
||||
|
||||
let res = hibp_client.get(&url)
|
||||
let res = hibp_client
|
||||
.get(&url)
|
||||
.header(USER_AGENT, user_agent)
|
||||
.header("hibp-api-key", api_key)
|
||||
.send()?;
|
||||
|
|
|
@ -16,11 +16,7 @@ use crate::error::MapResult;
|
|||
use crate::CONFIG;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
get_duo,
|
||||
activate_duo,
|
||||
activate_duo_put,
|
||||
]
|
||||
routes![get_duo, activate_duo, activate_duo_put,]
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -171,7 +167,7 @@ fn activate_duo(data: JsonUpcase<EnableDuoData>, headers: Headers, conn: DbConn)
|
|||
let type_ = TwoFactorType::Duo;
|
||||
let twofactor = TwoFactor::new(user.uuid.clone(), type_, data_str);
|
||||
twofactor.save(&conn)?;
|
||||
|
||||
|
||||
_generate_recover_code(&mut user, &conn);
|
||||
|
||||
Ok(Json(json!({
|
||||
|
|
|
@ -18,12 +18,7 @@ use chrono::{Duration, NaiveDateTime, Utc};
|
|||
use std::ops::Add;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
get_email,
|
||||
send_email_login,
|
||||
send_email,
|
||||
email,
|
||||
]
|
||||
routes![get_email, send_email_login, send_email, email,]
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
@ -16,11 +16,7 @@ use crate::error::{Error, MapResult};
|
|||
use crate::CONFIG;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
generate_yubikey,
|
||||
activate_yubikey,
|
||||
activate_yubikey_put,
|
||||
]
|
||||
routes![generate_yubikey, activate_yubikey, activate_yubikey_put,]
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
|
|
@ -391,7 +391,7 @@ fn download_icon(domain: &str) -> Result<Vec<u8>, Error> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
_ => warn!("data uri is invalid")
|
||||
_ => warn!("data uri is invalid"),
|
||||
};
|
||||
} else {
|
||||
match get_page_with_cookies(&icon.href, &cookie_str) {
|
||||
|
|
|
@ -7,12 +7,12 @@ use rocket::Route;
|
|||
use rocket_contrib::json::Json;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::util::Cached;
|
||||
use crate::error::Error;
|
||||
use crate::util::Cached;
|
||||
use crate::CONFIG;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
// If addding more routes here, consider also adding them to
|
||||
// If addding more routes here, consider also adding them to
|
||||
// crate::utils::LOGGED_ROUTES to make sure they appear in the log
|
||||
if CONFIG.web_vault_enabled() {
|
||||
routes![web_index, app_id, web_files, attachments, alive, static_files]
|
||||
|
@ -23,9 +23,7 @@ pub fn routes() -> Vec<Route> {
|
|||
|
||||
#[get("/")]
|
||||
fn web_index() -> Cached<Option<NamedFile>> {
|
||||
Cached::short(NamedFile::open(
|
||||
Path::new(&CONFIG.web_vault_folder()).join("index.html"),
|
||||
).ok())
|
||||
Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("index.html")).ok())
|
||||
}
|
||||
|
||||
#[get("/app-id.json")]
|
||||
|
@ -79,4 +77,4 @@ fn static_files(filename: String) -> Result<Content<&'static [u8]>, Error> {
|
|||
"identicon.js" => Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/identicon.js"))),
|
||||
_ => err!("Image not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,9 +156,7 @@ pub struct DeleteJWTClaims {
|
|||
pub sub: String,
|
||||
}
|
||||
|
||||
pub fn generate_delete_claims(
|
||||
uuid: String,
|
||||
) -> DeleteJWTClaims {
|
||||
pub fn generate_delete_claims(uuid: String) -> DeleteJWTClaims {
|
||||
let time_now = Utc::now().naive_utc();
|
||||
DeleteJWTClaims {
|
||||
nbf: time_now.timestamp(),
|
||||
|
@ -180,9 +178,7 @@ pub struct VerifyEmailJWTClaims {
|
|||
pub sub: String,
|
||||
}
|
||||
|
||||
pub fn generate_verify_email_claims(
|
||||
uuid: String,
|
||||
) -> DeleteJWTClaims {
|
||||
pub fn generate_verify_email_claims(uuid: String) -> DeleteJWTClaims {
|
||||
let time_now = Utc::now().naive_utc();
|
||||
DeleteJWTClaims {
|
||||
nbf: time_now.timestamp(),
|
||||
|
|
|
@ -378,7 +378,6 @@ make_config! {
|
|||
|
||||
fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
|
||||
let db_url = cfg.database_url.to_lowercase();
|
||||
|
||||
if cfg!(feature = "sqlite") && (db_url.starts_with("mysql:") || db_url.starts_with("postgresql:")) {
|
||||
err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite")
|
||||
}
|
||||
|
@ -447,12 +446,7 @@ impl Config {
|
|||
validate_config(&config)?;
|
||||
|
||||
Ok(Config {
|
||||
inner: RwLock::new(Inner {
|
||||
templates: load_templates(&config.templates_folder),
|
||||
config,
|
||||
_env,
|
||||
_usr,
|
||||
}),
|
||||
inner: RwLock::new(Inner { templates: load_templates(&config.templates_folder), config, _env, _usr }),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -500,9 +494,8 @@ impl Config {
|
|||
let e: Vec<&str> = email.rsplitn(2, '@').collect();
|
||||
if e.len() != 2 || e[0].is_empty() || e[1].is_empty() {
|
||||
warn!("Failed to parse email address '{}'", email);
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
self.signups_domains_whitelist().split(',').any(|d| d == e[0])
|
||||
}
|
||||
|
||||
|
@ -634,9 +627,7 @@ impl HelperDef for CaseHelper {
|
|||
rc: &mut RenderContext<'reg>,
|
||||
out: &mut dyn Output,
|
||||
) -> HelperResult {
|
||||
let param = h
|
||||
.param(0)
|
||||
.ok_or_else(|| RenderError::new("Param not found for helper \"case\""))?;
|
||||
let param = h.param(0).ok_or_else(|| RenderError::new("Param not found for helper \"case\""))?;
|
||||
let value = param.value().clone();
|
||||
|
||||
if h.params().iter().skip(1).any(|x| x.value() == &value) {
|
||||
|
@ -658,14 +649,10 @@ impl HelperDef for JsEscapeHelper {
|
|||
_: &mut RenderContext<'reg>,
|
||||
out: &mut dyn Output,
|
||||
) -> HelperResult {
|
||||
let param = h
|
||||
.param(0)
|
||||
.ok_or_else(|| RenderError::new("Param not found for helper \"js_escape\""))?;
|
||||
let param = h.param(0).ok_or_else(|| RenderError::new("Param not found for helper \"js_escape\""))?;
|
||||
|
||||
let value = param
|
||||
.value()
|
||||
.as_str()
|
||||
.ok_or_else(|| RenderError::new("Param for helper \"js_escape\" is not a String"))?;
|
||||
let value =
|
||||
param.value().as_str().ok_or_else(|| RenderError::new("Param for helper \"js_escape\" is not a String"))?;
|
||||
|
||||
let escaped_value = value.replace('\\', "").replace('\'', "\\x22").replace('\"', "\\x27");
|
||||
let quoted_value = format!(""{}"", escaped_value);
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// PBKDF2 derivation
|
||||
//
|
||||
|
||||
use crate::error::Error;
|
||||
use ring::{digest, hmac, pbkdf2};
|
||||
use std::num::NonZeroU32;
|
||||
use crate::error::Error;
|
||||
|
||||
static DIGEST_ALG: &digest::Algorithm = &digest::SHA256;
|
||||
const OUTPUT_LEN: usize = digest::SHA256_OUTPUT_LEN;
|
||||
|
|
|
@ -94,7 +94,7 @@ impl std::fmt::Debug for Error {
|
|||
} else {
|
||||
write!(f, "{}. {}", self.message, s)
|
||||
}
|
||||
},
|
||||
}
|
||||
ErrorKind::JsonError(_) => write!(f, "{}", self.message),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
|
|
14
src/mail.rs
14
src/mail.rs
|
@ -8,7 +8,7 @@ use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
|
|||
use quoted_printable::encode_to_str;
|
||||
|
||||
use crate::api::EmptyResult;
|
||||
use crate::auth::{encode_jwt, generate_invite_claims, generate_delete_claims, generate_verify_email_claims};
|
||||
use crate::auth::{encode_jwt, generate_delete_claims, generate_invite_claims, generate_verify_email_claims};
|
||||
use crate::error::Error;
|
||||
use crate::CONFIG;
|
||||
use chrono::NaiveDateTime;
|
||||
|
@ -96,9 +96,7 @@ pub fn send_password_hint(address: &str, hint: Option<String>) -> EmptyResult {
|
|||
}
|
||||
|
||||
pub fn send_delete_account(address: &str, uuid: &str) -> EmptyResult {
|
||||
let claims = generate_delete_claims(
|
||||
uuid.to_string(),
|
||||
);
|
||||
let claims = generate_delete_claims(uuid.to_string());
|
||||
let delete_token = encode_jwt(&claims);
|
||||
|
||||
let (subject, body_html, body_text) = get_text(
|
||||
|
@ -115,9 +113,7 @@ pub fn send_delete_account(address: &str, uuid: &str) -> EmptyResult {
|
|||
}
|
||||
|
||||
pub fn send_verify_email(address: &str, uuid: &str) -> EmptyResult {
|
||||
let claims = generate_verify_email_claims(
|
||||
uuid.to_string(),
|
||||
);
|
||||
let claims = generate_verify_email_claims(uuid.to_string());
|
||||
let verify_email_token = encode_jwt(&claims);
|
||||
|
||||
let (subject, body_html, body_text) = get_text(
|
||||
|
@ -145,9 +141,7 @@ pub fn send_welcome(address: &str) -> EmptyResult {
|
|||
}
|
||||
|
||||
pub fn send_welcome_must_verify(address: &str, uuid: &str) -> EmptyResult {
|
||||
let claims = generate_verify_email_claims(
|
||||
uuid.to_string(),
|
||||
);
|
||||
let claims = generate_verify_email_claims(uuid.to_string());
|
||||
let verify_email_token = encode_jwt(&claims);
|
||||
|
||||
let (subject, body_html, body_text) = get_text(
|
||||
|
|
Loading…
Reference in a new issue