geforkt von mirrored/vaultwarden
Added version check to diagnostics
- Added a version check based upon the github api information.
Dieser Commit ist enthalten in:
Ursprung
3c66deb5cc
Commit
b6fde857a7
2 geänderte Dateien mit 112 neuen und 26 gelöschten Zeilen
|
@ -319,6 +319,24 @@ pub struct WebVaultVersion {
|
||||||
version: String,
|
version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_github_api(url: &str) -> Result<Value, Error> {
|
||||||
|
use reqwest::{header::USER_AGENT, blocking::Client};
|
||||||
|
let github_api = Client::builder().build()?;
|
||||||
|
|
||||||
|
let res = github_api
|
||||||
|
.get(url)
|
||||||
|
.header(USER_AGENT, "Bitwarden_RS")
|
||||||
|
.send()?;
|
||||||
|
|
||||||
|
let res_status = res.status();
|
||||||
|
if res_status != 200 {
|
||||||
|
error!("Could not retrieve '{}', response code: {}", url, res_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
let value: Value = res.error_for_status()?.json()?;
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/diagnostics")]
|
#[get("/diagnostics")]
|
||||||
fn diagnostics(_token: AdminToken, _conn: DbConn) -> ApiResult<Html<String>> {
|
fn diagnostics(_token: AdminToken, _conn: DbConn) -> ApiResult<Html<String>> {
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
|
@ -335,6 +353,27 @@ fn diagnostics(_token: AdminToken, _conn: DbConn) -> ApiResult<Html<String>> {
|
||||||
_ => "Could not resolve domain name.".to_string(),
|
_ => "Could not resolve domain name.".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let bitwarden_rs_releases = get_github_api("https://api.github.com/repos/dani-garcia/bitwarden_rs/releases/latest");
|
||||||
|
let latest_release = match &bitwarden_rs_releases {
|
||||||
|
Ok(j) => j["tag_name"].as_str().unwrap(),
|
||||||
|
_ => "-",
|
||||||
|
};
|
||||||
|
|
||||||
|
let bitwarden_rs_commits = get_github_api("https://api.github.com/repos/dani-garcia/bitwarden_rs/commits/master");
|
||||||
|
let mut latest_commit = match &bitwarden_rs_commits {
|
||||||
|
Ok(j) => j["sha"].as_str().unwrap(),
|
||||||
|
_ => "-",
|
||||||
|
};
|
||||||
|
if latest_commit.len() >= 8 {
|
||||||
|
latest_commit = &latest_commit[..8];
|
||||||
|
}
|
||||||
|
|
||||||
|
let bw_web_builds_releases = get_github_api("https://api.github.com/repos/dani-garcia/bw_web_builds/releases/latest");
|
||||||
|
let latest_web_build = match &bw_web_builds_releases {
|
||||||
|
Ok(j) => j["tag_name"].as_str().unwrap(),
|
||||||
|
_ => "-",
|
||||||
|
};
|
||||||
|
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let server_time = dt.format("%Y-%m-%d %H:%M:%S").to_string();
|
let server_time = dt.format("%Y-%m-%d %H:%M:%S").to_string();
|
||||||
|
|
||||||
|
@ -342,6 +381,9 @@ fn diagnostics(_token: AdminToken, _conn: DbConn) -> ApiResult<Html<String>> {
|
||||||
"dns_resolved": dns_resolved,
|
"dns_resolved": dns_resolved,
|
||||||
"server_time": server_time,
|
"server_time": server_time,
|
||||||
"web_vault_version": web_vault_version.version,
|
"web_vault_version": web_vault_version.version,
|
||||||
|
"latest_release": latest_release,
|
||||||
|
"latest_commit": latest_commit,
|
||||||
|
"latest_web_build": latest_web_build.replace("v", ""),
|
||||||
});
|
});
|
||||||
|
|
||||||
let text = AdminTemplateData::diagnostics(diagnostics_json).render()?;
|
let text = AdminTemplateData::diagnostics(diagnostics_json).render()?;
|
||||||
|
|
|
@ -6,14 +6,30 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<dl class="row">
|
<dl class="row">
|
||||||
<dt class="col-sm-5">Server Installed</dt>
|
<dt class="col-sm-5">Server Installed
|
||||||
|
<span class="badge badge-success d-none" id="server-success" title="Latest version is installed.">Ok</span>
|
||||||
|
<span class="badge badge-warning d-none" id="server-warning" title="There seems to be an update available.">Update</span>
|
||||||
|
<span class="badge badge-danger d-none" id="server-failed" title="Unable to determine latest version.">Unknown</span>
|
||||||
|
</dt>
|
||||||
<dd class="col-sm-7">
|
<dd class="col-sm-7">
|
||||||
<span id="server-installed">{{version}}</span>
|
<span id="server-installed">{{version}}</span>
|
||||||
</dd>
|
</dd>
|
||||||
<dt class="col-sm-5">Web Installed</dt>
|
<dt class="col-sm-5">Server Latest</dt>
|
||||||
|
<dd class="col-sm-7">
|
||||||
|
<span id="server-latest">{{diagnostics.latest_release}}<span id="server-latest-commit" class="d-none">-{{diagnostics.latest_commit}}</span></span>
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-5">Web Installed
|
||||||
|
<span class="badge badge-success d-none" id="web-success" title="Latest version is installed.">Ok</span>
|
||||||
|
<span class="badge badge-warning d-none" id="web-warning" title="There seems to be an update available.">Update</span>
|
||||||
|
<span class="badge badge-danger d-none" id="web-failed" title="Unable to determine latest version.">Unknown</span>
|
||||||
|
</dt>
|
||||||
<dd class="col-sm-7">
|
<dd class="col-sm-7">
|
||||||
<span id="web-installed">{{diagnostics.web_vault_version}}</span>
|
<span id="web-installed">{{diagnostics.web_vault_version}}</span>
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt class="col-sm-5">Web Latest</dt>
|
||||||
|
<dd class="col-sm-7">
|
||||||
|
<span id="web-latest">{{diagnostics.latest_web_build}}</span>
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -45,6 +61,7 @@
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
(() => {
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
const year = d.getUTCFullYear();
|
const year = d.getUTCFullYear();
|
||||||
const month = String((d.getUTCMonth()+1)).padStart(2, '0');
|
const month = String((d.getUTCMonth()+1)).padStart(2, '0');
|
||||||
|
@ -70,4 +87,31 @@
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('dns-warning').classList.remove('d-none');
|
document.getElementById('dns-warning').classList.remove('d-none');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let serverInstalled = document.getElementById('server-installed').innerText;
|
||||||
|
let serverLatest = document.getElementById('server-latest').innerText;
|
||||||
|
if (serverInstalled.indexOf('-') > -1 && serverLatest !== '-') {
|
||||||
|
document.getElementById('server-latest-commit').classList.remove('d-none');
|
||||||
|
serverLatest += document.getElementById('server-latest-commit').innerText;
|
||||||
|
}
|
||||||
|
|
||||||
|
const webInstalled = document.getElementById('web-installed').innerText;
|
||||||
|
const webLatest = document.getElementById('web-latest').innerText;
|
||||||
|
|
||||||
|
checkVersions('server', serverInstalled, serverLatest);
|
||||||
|
checkVersions('web', webInstalled, webLatest);
|
||||||
|
|
||||||
|
function checkVersions(platform, installed, latest) {
|
||||||
|
if (installed === '-' || latest === '-') {
|
||||||
|
document.getElementById(platform + '-failed').classList.remove('d-none');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (installed !== latest) {
|
||||||
|
document.getElementById(platform + '-warning').classList.remove('d-none');
|
||||||
|
} else {
|
||||||
|
document.getElementById(platform + '-success').classList.remove('d-none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
Laden …
In neuem Issue referenzieren