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
28d1588e
Unverified
Commit
28d1588e
authored
6 years ago
by
Daniel García
Browse files
Options
Downloads
Patches
Plain Diff
Show version in admin panel
parent
f3b1a5ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
build.rs
+21
-3
21 additions, 3 deletions
build.rs
src/api/admin.rs
+6
-3
6 additions, 3 deletions
src/api/admin.rs
src/static/templates/admin/base.hbs
+11
-8
11 additions, 8 deletions
src/static/templates/admin/base.hbs
with
38 additions
and
14 deletions
build.rs
+
21
−
3
View file @
28d1588e
...
@@ -6,6 +6,10 @@ fn main() {
...
@@ -6,6 +6,10 @@ fn main() {
fn
run
(
args
:
&
[
&
str
])
->
Result
<
String
,
std
::
io
::
Error
>
{
fn
run
(
args
:
&
[
&
str
])
->
Result
<
String
,
std
::
io
::
Error
>
{
let
out
=
Command
::
new
(
args
[
0
])
.args
(
&
args
[
1
..
])
.output
()
?
;
let
out
=
Command
::
new
(
args
[
0
])
.args
(
&
args
[
1
..
])
.output
()
?
;
if
!
out
.status
.success
()
{
use
std
::
io
::{
Error
,
ErrorKind
};
return
Err
(
Error
::
new
(
ErrorKind
::
Other
,
"Command not successful"
));
}
Ok
(
String
::
from_utf8
(
out
.stdout
)
.unwrap
()
.trim
()
.to_string
())
Ok
(
String
::
from_utf8
(
out
.stdout
)
.unwrap
()
.trim
()
.to_string
())
}
}
...
@@ -13,8 +17,10 @@ fn run(args: &[&str]) -> Result<String, std::io::Error> {
...
@@ -13,8 +17,10 @@ fn run(args: &[&str]) -> Result<String, std::io::Error> {
fn
read_git_info
()
->
Result
<
(),
std
::
io
::
Error
>
{
fn
read_git_info
()
->
Result
<
(),
std
::
io
::
Error
>
{
// The exact tag for the current commit, can be empty when
// The exact tag for the current commit, can be empty when
// the current commit doesn't have an associated tag
// the current commit doesn't have an associated tag
let
exact_tag
=
run
(
&
[
"git"
,
"describe"
,
"--abbrev=0"
,
"--tags"
,
"--exact-match"
])
?
;
let
exact_tag
=
run
(
&
[
"git"
,
"describe"
,
"--abbrev=0"
,
"--tags"
,
"--exact-match"
])
.ok
();
println!
(
"cargo:rustc-env=GIT_EXACT_TAG={}"
,
exact_tag
);
if
let
Some
(
ref
exact
)
=
exact_tag
{
println!
(
"cargo:rustc-env=GIT_EXACT_TAG={}"
,
exact
);
}
// The last available tag, equal to exact_tag when
// The last available tag, equal to exact_tag when
// the current commit is tagged
// the current commit is tagged
...
@@ -27,13 +33,25 @@ fn read_git_info() -> Result<(), std::io::Error> {
...
@@ -27,13 +33,25 @@ fn read_git_info() -> Result<(), std::io::Error> {
// The current git commit hash
// The current git commit hash
let
rev
=
run
(
&
[
"git"
,
"rev-parse"
,
"HEAD"
])
?
;
let
rev
=
run
(
&
[
"git"
,
"rev-parse"
,
"HEAD"
])
?
;
let
rev_short
=
rev
.get
(
..
12
)
.unwrap_or_default
();
let
rev_short
=
rev
.get
(
..
8
)
.unwrap_or_default
();
println!
(
"cargo:rustc-env=GIT_REV={}"
,
rev_short
);
println!
(
"cargo:rustc-env=GIT_REV={}"
,
rev_short
);
// Combined version
let
version
=
if
let
Some
(
exact
)
=
exact_tag
{
exact
}
else
if
&
branch
!=
"master"
{
format!
(
"{}-{} ({})"
,
last_tag
,
rev_short
,
branch
)
}
else
{
format!
(
"{}-{}"
,
last_tag
,
rev_short
)
};
println!
(
"cargo:rustc-env=GIT_VERSION={}"
,
version
);
// To access these values, use:
// To access these values, use:
// env!("GIT_EXACT_TAG")
// env!("GIT_EXACT_TAG")
// env!("GIT_LAST_TAG")
// env!("GIT_LAST_TAG")
// env!("GIT_BRANCH")
// env!("GIT_BRANCH")
// env!("GIT_REV")
// env!("GIT_REV")
// env!("GIT_VERSION")
Ok
(())
Ok
(())
}
}
This diff is collapsed.
Click to expand it.
src/api/admin.rs
+
6
−
3
View file @
28d1588e
...
@@ -40,12 +40,13 @@ const COOKIE_NAME: &str = "BWRS_ADMIN";
...
@@ -40,12 +40,13 @@ const COOKIE_NAME: &str = "BWRS_ADMIN";
const
ADMIN_PATH
:
&
str
=
"/admin"
;
const
ADMIN_PATH
:
&
str
=
"/admin"
;
const
BASE_TEMPLATE
:
&
str
=
"admin/base"
;
const
BASE_TEMPLATE
:
&
str
=
"admin/base"
;
const
VERSION
:
Option
<&
str
>
=
option_env!
(
"GIT_VERSION"
);
#[get(
"/"
,
rank
=
2
)]
#[get(
"/"
,
rank
=
2
)]
fn
admin_login
(
flash
:
Option
<
FlashMessage
>
)
->
ApiResult
<
Html
<
String
>>
{
fn
admin_login
(
flash
:
Option
<
FlashMessage
>
)
->
ApiResult
<
Html
<
String
>>
{
// If there is an error, show it
// If there is an error, show it
let
msg
=
flash
.map
(|
msg
|
format!
(
"{}: {}"
,
msg
.name
(),
msg
.msg
()));
let
msg
=
flash
.map
(|
msg
|
format!
(
"{}: {}"
,
msg
.name
(),
msg
.msg
()));
let
json
=
json!
({
"page_content"
:
"admin/login"
,
"error"
:
msg
});
let
json
=
json!
({
"page_content"
:
"admin/login"
,
"version"
:
VERSION
,
"error"
:
msg
});
// Return the page
// Return the page
let
text
=
CONFIG
.render_template
(
BASE_TEMPLATE
,
&
json
)
?
;
let
text
=
CONFIG
.render_template
(
BASE_TEMPLATE
,
&
json
)
?
;
...
@@ -94,16 +95,18 @@ fn _validate_token(token: &str) -> bool {
...
@@ -94,16 +95,18 @@ fn _validate_token(token: &str) -> bool {
#[derive(Serialize)]
#[derive(Serialize)]
struct
AdminTemplateData
{
struct
AdminTemplateData
{
users
:
Vec
<
Value
>
,
page_content
:
String
,
page_content
:
String
,
version
:
Option
<&
'static
str
>
,
users
:
Vec
<
Value
>
,
config
:
Value
,
config
:
Value
,
}
}
impl
AdminTemplateData
{
impl
AdminTemplateData
{
fn
new
(
users
:
Vec
<
Value
>
)
->
Self
{
fn
new
(
users
:
Vec
<
Value
>
)
->
Self
{
Self
{
Self
{
users
,
page_content
:
String
::
from
(
"admin/page"
),
page_content
:
String
::
from
(
"admin/page"
),
version
:
VERSION
,
users
,
config
:
CONFIG
.prepare_json
(),
config
:
CONFIG
.prepare_json
(),
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/static/templates/admin/base.hbs
+
11
−
8
View file @
28d1588e
...
@@ -8,14 +8,14 @@
...
@@ -8,14 +8,14 @@
<link
rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css"
<link
rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css"
integrity=
"sha256-azvvU9xKluwHFJ0Cpgtf0CYzK7zgtOznnzxV4924X1w="
crossorigin=
"anonymous"
/>
integrity=
"sha256-azvvU9xKluwHFJ0Cpgtf0CYzK7zgtOznnzxV4924X1w="
crossorigin=
"anonymous"
/>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
integrity=
"sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
crossorigin=
"anonymous"
></script>
integrity=
"sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.js"
integrity=
"sha256-tCQ/BldMlN2vWe5gAiNoNb5svoOgVUhlUgv7UjONKKQ="
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.js"
crossorigin=
"anonymous"
></script>
integrity=
"sha256-tCQ/BldMlN2vWe5gAiNoNb5svoOgVUhlUgv7UjONKKQ="
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/identicon.js/2.3.3/identicon.min.js"
integrity=
"sha256-nYoL3nK/HA1e1pJvLwNPnpKuKG9q89VFX862r5aohmA="
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/identicon.js/2.3.3/identicon.min.js"
crossorigin=
"anonymous"
></script>
integrity=
"sha256-nYoL3nK/HA1e1pJvLwNPnpKuKG9q89VFX862r5aohmA="
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/js/bootstrap.bundle.min.js"
integrity=
"sha256-MSYVjWgrr6UL/9eQfQvOyt6/gsxb6dpwI1zqM5DbLCs="
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/js/bootstrap.bundle.min.js"
crossorigin=
"anonymous"
></script>
integrity=
"sha256-MSYVjWgrr6UL/9eQfQvOyt6/gsxb6dpwI1zqM5DbLCs="
crossorigin=
"anonymous"
></script>
<style>
<style>
body
{
body
{
padding-top
:
70px
;
padding-top
:
70px
;
...
@@ -41,6 +41,9 @@
...
@@ -41,6 +41,9 @@
</li>
</li>
</ul>
</ul>
</div>
</div>
{{#if
version
}}
<div
class=
"navbar-text"
>
Version:
{{
version
}}
</div>
{{/if}}
</nav>
</nav>
{{>
(
page_content
)
}}
{{>
(
page_content
)
}}
...
...
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