Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vaultwarden
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Vaultwarden
Commits
a72809b2
Unverified
Commit
a72809b2
authored
6 years ago
by
Daniel García
Browse files
Options
Downloads
Patches
Plain Diff
Yubico and SMTP enable/disable master switches
parent
9976e473
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/config.rs
+44
-28
44 additions, 28 deletions
src/config.rs
src/static/templates/admin/page.hbs
+40
-19
40 additions, 19 deletions
src/static/templates/admin/page.hbs
with
84 additions
and
47 deletions
src/config.rs
+
44
−
28
View file @
a72809b2
...
@@ -16,7 +16,7 @@ macro_rules! make_config {
...
@@ -16,7 +16,7 @@ macro_rules! make_config {
(
(
$
(
$
(
$
(
#[doc
=
$
groupdoc:literal]
)
?
$
(
#[doc
=
$
groupdoc:literal]
)
?
$group: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
)
?
;
...
@@ -108,28 +108,6 @@ macro_rules! make_config {
...
@@ -108,28 +108,6 @@ macro_rules! make_config {
}
}
)
+
)
+
)
+
)
+
pub
fn
load
()
->
Result
<
Self
,
Error
>
{
// Loading from env and file
let
_env
=
ConfigBuilder
::
from_env
();
let
_usr
=
ConfigBuilder
::
from_file
(
&
CONFIG_FILE
)
.unwrap_or_default
();
// Create merged config, config file overwrites env
let
builder
=
_env
.merge
(
&
_usr
);
// Fill any missing with defaults
let
config
=
builder
.build
();
validate_config
(
&
config
)
?
;
Ok
(
Config
{
inner
:
RwLock
::
new
(
Inner
{
templates
:
load_templates
(
&
config
.templates_folder
),
config
,
_env
,
_usr
,
}),
})
}
pub
fn
prepare_json
(
&
self
)
->
serde_json
::
Value
{
pub
fn
prepare_json
(
&
self
)
->
serde_json
::
Value
{
let
(
def
,
cfg
)
=
{
let
(
def
,
cfg
)
=
{
let
inner
=
&
self
.inner
.read
()
.unwrap
();
let
inner
=
&
self
.inner
.read
()
.unwrap
();
...
@@ -155,6 +133,7 @@ macro_rules! make_config {
...
@@ -155,6 +133,7 @@ macro_rules! make_config {
json!
([
$
({
json!
([
$
({
"group"
:
stringify!
(
$group
),
"group"
:
stringify!
(
$group
),
"grouptoggle"
:
stringify!
(
$
(
$group_enabled
)
?
),
"groupdoc"
:
make_config!
{
@
show
$
(
$groupdoc
)
?
},
"groupdoc"
:
make_config!
{
@
show
$
(
$groupdoc
)
?
},
"elements"
:
[
"elements"
:
[
$
(
{
$
(
{
...
@@ -172,7 +151,7 @@ macro_rules! make_config {
...
@@ -172,7 +151,7 @@ macro_rules! make_config {
// Group or empty string
// Group or empty string
(
@
show
)
=>
{
""
};
(
@
show
)
=>
{
""
};
(
@
show
$
groupdoc
:literal
)
=>
{
$
groupdoc
};
(
@
show
$
lit
:literal
)
=>
{
$
lit
};
// Wrap the optionals in an Option type
// Wrap the optionals in an Option type
(
@
type
$ty:ty
,
option
)
=>
{
Option
<
$ty
>
};
(
@
type
$ty:ty
,
option
)
=>
{
Option
<
$ty
>
};
...
@@ -273,7 +252,9 @@ make_config! {
...
@@ -273,7 +252,9 @@ make_config! {
},
},
/// Yubikey settings
/// Yubikey settings
yubico
{
yubico
:
_enable_yubico
{
/// Enabled
_enable_yubico
:
bool
,
true
,
def
,
true
;
/// Client ID
/// Client ID
yubico_client_id
:
String
,
true
,
option
;
yubico_client_id
:
String
,
true
,
option
;
/// Secret Key
/// Secret Key
...
@@ -283,7 +264,9 @@ make_config! {
...
@@ -283,7 +264,9 @@ make_config! {
},
},
/// SMTP Email Settings
/// SMTP Email Settings
smtp
{
smtp
:
_enable_smtp
{
/// Enabled
_enable_smtp
:
bool
,
true
,
def
,
true
;
/// Host
/// Host
smtp_host
:
String
,
true
,
option
;
smtp_host
:
String
,
true
,
option
;
/// Enable SSL
/// Enable SSL
...
@@ -318,9 +301,34 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
...
@@ -318,9 +301,34 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
}
}
impl
Config
{
impl
Config
{
pub
fn
load
()
->
Result
<
Self
,
Error
>
{
// Loading from env and file
let
_env
=
ConfigBuilder
::
from_env
();
let
_usr
=
ConfigBuilder
::
from_file
(
&
CONFIG_FILE
)
.unwrap_or_default
();
// Create merged config, config file overwrites env
let
builder
=
_env
.merge
(
&
_usr
);
// Fill any missing with defaults
let
config
=
builder
.build
();
validate_config
(
&
config
)
?
;
Ok
(
Config
{
inner
:
RwLock
::
new
(
Inner
{
templates
:
load_templates
(
&
config
.templates_folder
),
config
,
_env
,
_usr
,
}),
})
}
pub
fn
update_config
(
&
self
,
other
:
ConfigBuilder
)
->
Result
<
(),
Error
>
{
pub
fn
update_config
(
&
self
,
other
:
ConfigBuilder
)
->
Result
<
(),
Error
>
{
// Remove default values
// Remove default values
let
builder
=
other
.remove
(
&
self
.inner
.read
()
.unwrap
()
._env
);
//let builder = other.remove(&self.inner.read().unwrap()._env);
// TODO: Remove values that are defaults, above only checks those set by env and not the defaults
let
builder
=
other
;
// Serialize now before we consume the builder
// Serialize now before we consume the builder
let
config_str
=
serde_json
::
to_string_pretty
(
&
builder
)
?
;
let
config_str
=
serde_json
::
to_string_pretty
(
&
builder
)
?
;
...
@@ -357,7 +365,15 @@ impl Config {
...
@@ -357,7 +365,15 @@ impl Config {
format!
(
"{}.pub.der"
,
CONFIG
.rsa_key_filename
())
format!
(
"{}.pub.der"
,
CONFIG
.rsa_key_filename
())
}
}
pub
fn
mail_enabled
(
&
self
)
->
bool
{
pub
fn
mail_enabled
(
&
self
)
->
bool
{
self
.inner
.read
()
.unwrap
()
.config.smtp_host
.is_some
()
let
inner
=
&
self
.inner
.read
()
.unwrap
()
.config
;
inner
._enable_smtp
&&
inner
.smtp_host
.is_some
()
}
pub
fn
yubico_enabled
(
&
self
)
->
bool
{
let
inner
=
&
self
.inner
.read
()
.unwrap
()
.config
;
inner
._enable_yubico
&&
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
>
(
...
...
This diff is collapsed.
Click to expand it.
src/static/templates/admin/page.hbs
+
40
−
19
View file @
a72809b2
...
@@ -70,18 +70,20 @@
...
@@ -70,18 +70,20 @@
{{#
case
type
"text"
"number"
}}
{{#
case
type
"text"
"number"
}}
<label
for=
"input_
{{
name
}}
"
class=
"col-sm-3 col-form-label"
>
{{
doc
.
name
}}
</label>
<label
for=
"input_
{{
name
}}
"
class=
"col-sm-3 col-form-label"
>
{{
doc
.
name
}}
</label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<input
class=
"form-control"
id=
"input_
{{
name
}}
"
type=
"
{{
type
}}
"
name=
"
{{
name
}}
"
value=
"
{{
value
}}
"
<input
class=
"form-control
conf-
{{
type
}}
"
id=
"input_
{{
name
}}
"
type=
"
{{
type
}}
"
name=
"
{{
name
}}
"
{{#if
default
}}
placeholder=
"Default:
{{
default
}}
"
{{/if}}
>
value=
"
{{
value
}}
"
{{#if
default
}}
placeholder=
"Default:
{{
default
}}
"
{{/if}}
>
</div>
</div>
{{/
case
}}
{{/
case
}}
{{#
case
type
"checkbox"
}}
{{#
case
type
"checkbox"
}}
<div
class=
"col-sm-3"
>
{{
doc
.
name
}}
</div>
<div
class=
"col-sm-3"
>
{{
doc
.
name
}}
</div>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<div
class=
"form-check"
>
<div
class=
"form-check"
>
<input
class=
"form-check-input"
type=
"checkbox"
id=
"input_
{{
name
}}
"
name=
"
{{
name
}}
"
<input
class=
"form-check-input
conf-
{{
type
}}
"
type=
"checkbox"
id=
"input_
{{
name
}}
"
{{#if
value
}}
checked
{{/if}}
>
name=
"
{{
name
}}
"
{{#if
value
}}
checked
{{/if}}
>
{{#if
default
}}
<label
class=
"form-check-label"
for=
"input_
{{
name
}}
"
>
Default:
{{
default
}}
</label>
<label
class=
"form-check-label"
for=
"input_
{{
name
}}
"
>
Default:
{{
default
}}
</label>
{{/if}}
</div>
</div>
</div>
</div>
{{/
case
}}
{{/
case
}}
...
@@ -152,30 +154,43 @@
...
@@ -152,30 +154,43 @@
"
Error inviting user
"
,
data
);
"
Error inviting user
"
,
data
);
return
false
;
return
false
;
}
}
function
getFormData
(
form
)
{
function
getFormData
()
{
var
form_array
=
form
.
serializeArray
();
let
data
=
{};
var
indexed_array
=
{};
$
.
each
(
form_array
,
function
(
i
,
v
)
{
$
(
"
.conf-checkbox
"
).
each
(
function
(
i
,
e
)
{
indexed_array
[
v
.
name
]
=
process_value
(
v
.
value
);
data
[
e
.
name
]
=
$
(
e
).
is
(
"
:checked
"
);
});
});
return
indexed_array
;
$
(
"
.conf-number
"
).
each
(
function
(
i
,
e
)
{
}
data
[
e
.
name
]
=
+
e
.
value
;
function
process_value
(
val
)
{
});
val
=
val
.
trim
();
if
(
val
===
""
)
{
return
null
;
}
$
(
"
.conf-text
"
).
each
(
function
(
i
,
e
)
{
if
(
!
isNaN
(
val
))
{
return
+
val
;
}
data
[
e
.
name
]
=
e
.
value
||
null
;
if
(
val
===
"
true
"
||
val
===
"
on
"
)
{
return
true
;
}
});
if
(
val
===
"
false
"
||
val
===
"
off
"
)
{
return
false
;
}
return
data
;
return
val
;
}
}
function
saveConfig
()
{
function
saveConfig
()
{
data
=
JSON
.
stringify
(
getFormData
(
$
(
"
#config-form
"
)
));
data
=
JSON
.
stringify
(
getFormData
());
_post
(
"
/admin/config/
"
,
"
Config saved correctly
"
,
_post
(
"
/admin/config/
"
,
"
Config saved correctly
"
,
"
Error saving config
"
,
data
);
"
Error saving config
"
,
data
);
return
false
;
return
false
;
}
}
function
masterCheck
(
check_id
,
inputs_query
)
{
function
toggleEnabled
(
check_id
,
inputs_query
,
enabled
)
{
$
(
inputs_query
).
prop
(
"
disabled
"
,
!
enabled
)
if
(
!
enabled
)
$
(
inputs_query
).
val
(
""
);
$
(
check_id
).
prop
(
"
disabled
"
,
false
);
};
function
onChanged
(
check_id
,
inputs_query
)
{
return
function
_fn
()
{
toggleEnabled
(
check_id
,
inputs_query
,
this
.
checked
);
};
};
toggleEnabled
(
check_id
,
inputs_query
,
$
(
check_id
).
is
(
"
:checked
"
));
$
(
check_id
).
change
(
onChanged
(
check_id
,
inputs_query
));
}
let
OrgTypes
=
{
let
OrgTypes
=
{
"
0
"
:
{
"
name
"
:
"
Owner
"
,
"
color
"
:
"
orange
"
},
"
0
"
:
{
"
name
"
:
"
Owner
"
,
"
color
"
:
"
orange
"
},
"
1
"
:
{
"
name
"
:
"
Admin
"
,
"
color
"
:
"
blueviolet
"
},
"
1
"
:
{
"
name
"
:
"
Admin
"
,
"
color
"
:
"
blueviolet
"
},
...
@@ -193,5 +208,11 @@
...
@@ -193,5 +208,11 @@
e
.
style
.
backgroundColor
=
orgtype
.
color
;
e
.
style
.
backgroundColor
=
orgtype
.
color
;
e
.
title
=
orgtype
.
name
;
e
.
title
=
orgtype
.
name
;
});
});
// These are formatted because otherwise the
// VSCode formatter breaks But they still work
//
{{#
each
config
}}
{{#if
grouptoggle
}}
masterCheck
(
"
#input_
{{
grouptoggle
}}
"
,
"
#g_
{{
group
}}
input
"
);
//
{{/if}}
{{/
each
}}
});
});
</script>
</script>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment