diff --git a/build.rs b/build.rs index 39c16095..7d0a7bce 100644 --- a/build.rs +++ b/build.rs @@ -15,11 +15,14 @@ fn main() { "You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite" ); - if let Ok(version) = env::var("BWRS_VERSION") { - println!("cargo:rustc-env=BWRS_VERSION={}", version); + // Support $BWRS_VERSION for legacy compatibility, but default to $VW_VERSION. + // If neither exist, read from git. + let maybe_vaultwarden_version = + env::var("VW_VERSION").or_else(|_| env::var("BWRS_VERSION")).or_else(|_| version_from_git_info()); + + if let Ok(version) = maybe_vaultwarden_version { + println!("cargo:rustc-env=VW_VERSION={}", version); println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version); - } else { - read_git_info().ok(); } } @@ -33,7 +36,13 @@ fn run(args: &[&str]) -> Result { } /// This method reads info from Git, namely tags, branch, and revision -fn read_git_info() -> Result<(), std::io::Error> { +/// To access these values, use: +/// - env!("GIT_EXACT_TAG") +/// - env!("GIT_LAST_TAG") +/// - env!("GIT_BRANCH") +/// - env!("GIT_REV") +/// - env!("VW_VERSION") +fn version_from_git_info() -> Result { // The exact tag for the current commit, can be empty when // the current commit doesn't have an associated tag let exact_tag = run(&["git", "describe", "--abbrev=0", "--tags", "--exact-match"]).ok(); @@ -56,23 +65,11 @@ fn read_git_info() -> Result<(), std::io::Error> { println!("cargo:rustc-env=GIT_REV={}", rev_short); // Combined version - let version = if let Some(exact) = exact_tag { - exact + if let Some(exact) = exact_tag { + Ok(exact) } else if &branch != "main" && &branch != "master" { - format!("{}-{} ({})", last_tag, rev_short, branch) + Ok(format!("{}-{} ({})", last_tag, rev_short, branch)) } else { - format!("{}-{}", last_tag, rev_short) - }; - - println!("cargo:rustc-env=BWRS_VERSION={}", version); - println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version); - - // To access these values, use: - // env!("GIT_EXACT_TAG") - // env!("GIT_LAST_TAG") - // env!("GIT_BRANCH") - // env!("GIT_REV") - // env!("BWRS_VERSION") - - Ok(()) + Ok(format!("{}-{}", last_tag, rev_short)) + } } diff --git a/src/api/admin.rs b/src/api/admin.rs index 60f6aad4..38d30c99 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -21,7 +21,7 @@ use crate::{ util::{ docker_base_image, format_naive_datetime_local, get_display_size, get_reqwest_client, is_running_in_docker, }, - CONFIG, + CONFIG, VERSION, }; pub fn routes() -> Vec { @@ -74,11 +74,10 @@ fn admin_disabled() -> &'static str { "The admin panel is disabled, please configure the 'ADMIN_TOKEN' variable to enable it" } -const COOKIE_NAME: &str = "BWRS_ADMIN"; +const COOKIE_NAME: &str = "VW_ADMIN"; const ADMIN_PATH: &str = "/admin"; const BASE_TEMPLATE: &str = "admin/base"; -const VERSION: Option<&str> = option_env!("BWRS_VERSION"); fn admin_path() -> String { format!("{}{}", CONFIG.domain_path(), ADMIN_PATH) @@ -486,7 +485,7 @@ fn diagnostics(_token: AdminToken, ip_header: IpHeader, conn: DbConn) -> ApiResu // Get current running versions let web_vault_version: WebVaultVersion = - match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "bwrs-version.json")) { + match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "vw-version.json")) { Ok(s) => serde_json::from_str(&s)?, _ => match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "version.json")) { Ok(s) => serde_json::from_str(&s)?, diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index f828dc44..77e8780d 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -170,7 +170,7 @@ fn hibp_breach(username: String) -> JsonResult { "BreachDate": "2019-08-18T00:00:00Z", "AddedDate": "2019-08-18T00:00:00Z", "Description": format!("Go to: https://haveibeenpwned.com/account/{account} for a manual check.

HaveIBeenPwned API key not set!
Go to https://haveibeenpwned.com/API/Key to purchase an API key from HaveIBeenPwned.

", account=username), - "LogoPath": "bwrs_static/hibp.png", + "LogoPath": "vw_static/hibp.png", "PwnCount": 0, "DataClasses": [ "Error - No API key set!" diff --git a/src/api/web.rs b/src/api/web.rs index 154dc2cf..9a5f74cc 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -77,7 +77,7 @@ fn alive(_conn: DbConn) -> Json { Json(format_date(&Utc::now().naive_utc())) } -#[get("/bwrs_static/")] +#[get("/vw_static/")] fn static_files(filename: String) -> Result, Error> { match filename.as_ref() { "mail-github.png" => Ok(Content(ContentType::PNG, include_bytes!("../static/images/mail-github.png"))), diff --git a/src/main.rs b/src/main.rs index dd9fa51e..d7bef292 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,16 +76,18 @@ const HELP: &str = "\ -v, --version Prints the app version "; +pub const VERSION: Option<&str> = option_env!("VW_VERSION"); + fn parse_args() { - const NO_VERSION: &str = "(Version info from Git not present)"; let mut pargs = pico_args::Arguments::from_env(); + let version = VERSION.unwrap_or("(Version info from Git not present)"); if pargs.contains(["-h", "--help"]) { - println!("vaultwarden {}", option_env!("BWRS_VERSION").unwrap_or(NO_VERSION)); + println!("vaultwarden {}", version); print!("{}", HELP); exit(0); } else if pargs.contains(["-v", "--version"]) { - println!("vaultwarden {}", option_env!("BWRS_VERSION").unwrap_or(NO_VERSION)); + println!("vaultwarden {}", version); exit(0); } } @@ -94,7 +96,7 @@ fn launch_info() { println!("/--------------------------------------------------------------------\\"); println!("| Starting Vaultwarden |"); - if let Some(version) = option_env!("BWRS_VERSION") { + if let Some(version) = VERSION { println!("|{:^68}|", format!("Version {}", version)); } diff --git a/src/static/templates/admin/base.hbs b/src/static/templates/admin/base.hbs index 9c876723..d385cdcd 100644 --- a/src/static/templates/admin/base.hbs +++ b/src/static/templates/admin/base.hbs @@ -4,9 +4,9 @@ - + Vaultwarden Admin Panel - + - + - + diff --git a/src/static/templates/admin/organizations.hbs b/src/static/templates/admin/organizations.hbs index 05509659..ac3c0f30 100644 --- a/src/static/templates/admin/organizations.hbs +++ b/src/static/templates/admin/organizations.hbs @@ -48,9 +48,9 @@ - - - + + + - + + +