Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend support for alternate base dir (subdir/subpath) hosting #868

Merged
merged 4 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn admin_path() -> String {
fn admin_login(flash: Option<FlashMessage>) -> ApiResult<Html<String>> {
// If there is an error, show it
let msg = flash.map(|msg| format!("{}: {}", msg.name(), msg.msg()));
let json = json!({"page_content": "admin/login", "version": VERSION, "error": msg});
let json = json!({"page_content": "admin/login", "version": VERSION, "error": msg, "urlpath": CONFIG.domain_path()});

// Return the page
let text = CONFIG.render_template(BASE_TEMPLATE, &json)?;
Expand Down Expand Up @@ -115,6 +115,7 @@ struct AdminTemplateData {
config: Value,
can_backup: bool,
logged_in: bool,
urlpath: String,
}

impl AdminTemplateData {
Expand All @@ -126,6 +127,7 @@ impl AdminTemplateData {
config: CONFIG.prepare_json(),
can_backup: *CAN_BACKUP,
logged_in: true,
urlpath: CONFIG.domain_path(),
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/static/templates/admin/base.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bitwarden_rs Admin Panel</title>

<link rel="stylesheet" href="bwrs_static/bootstrap.css" />
<script src="bwrs_static/bootstrap-native-v4.js"></script>
<script src="bwrs_static/md5.js"></script>
<script src="bwrs_static/identicon.js"></script>
<link rel="stylesheet" href="{{urlpath}}/bwrs_static/bootstrap.css" />
<script src="{{urlpath}}/bwrs_static/bootstrap-native-v4.js"></script>
<script src="{{urlpath}}/bwrs_static/md5.js"></script>
<script src="{{urlpath}}/bwrs_static/identicon.js"></script>
<style>
body {
padding-top: 70px;
Expand Down Expand Up @@ -38,10 +38,10 @@
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="admin">Admin Panel</a>
<a class="nav-link" href="{{urlpath}}/admin">Admin Panel</a>
</li>
<li class="nav-item">
<a class="nav-link" href=".">Vault</a>
<a class="nav-link" href="{{urlpath}}/">Vault</a>
</li>
</ul>
</div>
Expand All @@ -55,7 +55,7 @@

{{#if logged_in}}
<li class="nav-item">
<a class="nav-link" href="admin/logout">Log Out</a>
<a class="nav-link" href="{{urlpath}}/admin/logout">Log Out</a>
</li>
{{/if}}
</ul>
Expand Down
20 changes: 10 additions & 10 deletions src/static/templates/admin/page.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<main class="container">
<div id="users-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
<h6 class="border-bottom pb-2 mb-0">Registered Users {{urlpath}}</h6>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional for this {{urlpath}} to be here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, no that was me checking that the urlpath was set to the correct value, forgot to remove it!


<div id="users-list">
{{#each users}}
Expand All @@ -19,7 +19,7 @@
<span class="d-block">{{Email}}</span>
</div>
<div class="col">
<strong> Organizations:</strong>
<strong> Organizations: </strong>
<span class="d-block">
{{#each Organizations}}
<span class="badge badge-primary" data-orgtype="{{Type}}">{{Name}}</span>
Expand Down Expand Up @@ -225,7 +225,7 @@
var input_mail = prompt("To delete user '" + mail + "', please type the email below")
if (input_mail != null) {
if (input_mail == mail) {
_post("admin/users/" + id + "/delete",
_post("{{urlpath}}/admin/users/" + id + "/delete",
"User deleted correctly",
"Error deleting user");
} else {
Expand All @@ -235,19 +235,19 @@
return false;
}
function remove2fa(id) {
_post("admin/users/" + id + "/remove-2fa",
_post("{{urlpath}}/admin/users/" + id + "/remove-2fa",
"2FA removed correctly",
"Error removing 2FA");
return false;
}
function deauthUser(id) {
_post("admin/users/" + id + "/deauth",
_post("{{urlpath}}/admin/users/" + id + "/deauth",
"Sessions deauthorized correctly",
"Error deauthorizing sessions");
return false;
}
function updateRevisions() {
_post("admin/users/update_revision",
_post("{{urlpath}}/admin/users/update_revision",
"Success, clients will sync next time they connect",
"Error forcing clients to sync");
return false;
Expand All @@ -256,7 +256,7 @@
inv = document.getElementById("email-invite");
data = JSON.stringify({ "email": inv.value });
inv.value = "";
_post("admin/invite/", "User invited correctly",
_post("{{urlpath}}/admin/invite/", "User invited correctly",
"Error inviting user", data);
return false;
}
Expand All @@ -278,15 +278,15 @@
}
function saveConfig() {
data = JSON.stringify(getFormData());
_post("admin/config/", "Config saved correctly",
_post("{{urlpath}}/admin/config/", "Config saved correctly",
"Error saving config", data);
return false;
}
function deleteConf() {
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",
_post("{{urlpath}}/admin/config/delete",
"Config deleted correctly",
"Error deleting config");
} else {
Expand All @@ -296,7 +296,7 @@
return false;
}
function backupDatabase() {
_post("admin/config/backup_db",
_post("{{urlpath}}/admin/config/backup_db",
"Backup created successfully",
"Error creating backup");
return false;
Expand Down