mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2024-11-14 06:52:41 +01:00
Add reset user config button
This commit is contained in:
parent
89840790e7
commit
ef63342e20
@ -27,6 +27,7 @@ pub fn routes() -> Vec<Route> {
|
|||||||
delete_user,
|
delete_user,
|
||||||
deauth_user,
|
deauth_user,
|
||||||
post_config,
|
post_config,
|
||||||
|
delete_config,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +174,11 @@ fn post_config(data: Json<ConfigBuilder>, _token: AdminToken) -> EmptyResult {
|
|||||||
CONFIG.update_config(data)
|
CONFIG.update_config(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/config/delete")]
|
||||||
|
fn delete_config(_token: AdminToken) -> EmptyResult {
|
||||||
|
CONFIG.delete_user_config()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AdminToken {}
|
pub struct AdminToken {}
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for AdminToken {
|
impl<'a, 'r> FromRequest<'a, 'r> for AdminToken {
|
||||||
|
@ -13,17 +13,14 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! make_config {
|
macro_rules! make_config {
|
||||||
(
|
($(
|
||||||
$(
|
|
||||||
$(#[doc = $groupdoc:literal])?
|
$(#[doc = $groupdoc:literal])?
|
||||||
$group:ident $(: $group_enabled:ident)? {
|
$group:ident $(: $group_enabled:ident)? {
|
||||||
$(
|
$(
|
||||||
$(#[doc = $doc:literal])+
|
$(#[doc = $doc:literal])+
|
||||||
$name:ident : $ty:ty, $editable:literal, $none_action:ident $(, $default:expr)?;
|
$name:ident : $ty:ty, $editable:literal, $none_action:ident $(, $default:expr)?;
|
||||||
)+
|
)+},
|
||||||
},)+
|
)+) => {
|
||||||
|
|
||||||
) => {
|
|
||||||
pub struct Config { inner: RwLock<Inner> }
|
pub struct Config { inner: RwLock<Inner> }
|
||||||
|
|
||||||
struct Inner {
|
struct Inner {
|
||||||
@ -355,6 +352,28 @@ impl Config {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_user_config(&self) -> Result<(), Error> {
|
||||||
|
crate::util::delete_file(&CONFIG_FILE)?;
|
||||||
|
|
||||||
|
// Empty user config
|
||||||
|
let usr = ConfigBuilder::default();
|
||||||
|
|
||||||
|
// Config now is env + defaults
|
||||||
|
let config = {
|
||||||
|
let env = &self.inner.read().unwrap()._env;
|
||||||
|
env.build()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save configs
|
||||||
|
{
|
||||||
|
let mut writer = self.inner.write().unwrap();
|
||||||
|
writer.config = config;
|
||||||
|
writer._usr = usr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn private_rsa_key(&self) -> String {
|
pub fn private_rsa_key(&self) -> String {
|
||||||
format!("{}.der", CONFIG.rsa_key_filename())
|
format!("{}.der", CONFIG.rsa_key_filename())
|
||||||
}
|
}
|
||||||
@ -366,14 +385,11 @@ impl Config {
|
|||||||
}
|
}
|
||||||
pub fn mail_enabled(&self) -> bool {
|
pub fn mail_enabled(&self) -> bool {
|
||||||
let inner = &self.inner.read().unwrap().config;
|
let inner = &self.inner.read().unwrap().config;
|
||||||
inner._enable_smtp
|
inner._enable_smtp && inner.smtp_host.is_some()
|
||||||
&& inner.smtp_host.is_some()
|
|
||||||
}
|
}
|
||||||
pub fn yubico_enabled(&self) -> bool {
|
pub fn yubico_enabled(&self) -> bool {
|
||||||
let inner = &self.inner.read().unwrap().config;
|
let inner = &self.inner.read().unwrap().config;
|
||||||
inner._enable_yubico
|
inner._enable_yubico && inner.yubico_client_id.is_some() && inner.yubico_secret_key.is_some()
|
||||||
&& inner.yubico_client_id.is_some()
|
|
||||||
&& inner.yubico_secret_key.is_some()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_template<T: serde::ser::Serialize>(
|
pub fn render_template<T: serde::ser::Serialize>(
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
{{#each config}}
|
{{#each config}}
|
||||||
{{#if groupdoc}}
|
{{#if groupdoc}}
|
||||||
<div class="card bg-light mb-3">
|
<div class="card bg-light mb-3">
|
||||||
<div class="card-header"><button class="btn btn-link collapsed" type="button" data-toggle="collapse"
|
<div class="card-header"><button type="button" class="btn btn-link collapsed" data-toggle="collapse"
|
||||||
data-target="#g_{{group}}">{{groupdoc}}</button></div>
|
data-target="#g_{{group}}">{{groupdoc}}</button></div>
|
||||||
<div id="g_{{group}}" class="card-body collapse" data-parent="#config-form">
|
<div id="g_{{group}}" class="card-body collapse" data-parent="#config-form">
|
||||||
{{#each elements}}
|
{{#each elements}}
|
||||||
@ -95,6 +95,7 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
<button type="submit" class="btn btn-primary">Save</button>
|
<button type="submit" class="btn btn-primary">Save</button>
|
||||||
|
<button type="button" class="btn btn-danger float-right" onclick="deleteConfig();">Reset defaults</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -176,6 +177,19 @@
|
|||||||
"Error saving config", data);
|
"Error saving config", data);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
function deleteConfig() {
|
||||||
|
var input = prompt("This will remove all user configurations, and restore the defaults and the " +
|
||||||
|
"values set by the environment. This operation could be dangerous. Type 'DELETE' to proceed:");
|
||||||
|
if (input === "DELETE") {
|
||||||
|
_post("/admin/config/delete",
|
||||||
|
"Config deleted correctly",
|
||||||
|
"Error deleting config");
|
||||||
|
} else {
|
||||||
|
alert("Wrong input, please try again")
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
function masterCheck(check_id, inputs_query) {
|
function masterCheck(check_id, inputs_query) {
|
||||||
function toggleEnabled(check_id, inputs_query, enabled) {
|
function toggleEnabled(check_id, inputs_query, enabled) {
|
||||||
$(inputs_query).prop("disabled", !enabled)
|
$(inputs_query).prop("disabled", !enabled)
|
||||||
|
Loading…
Reference in New Issue
Block a user