2021-01-19 17:55:21 +01:00
|
|
|
<main class="container-xl">
|
2019-02-05 22:17:02 +01:00
|
|
|
<div id="config-block" class="align-items-center p-3 mb-3 bg-secondary rounded shadow">
|
2019-02-02 16:47:27 +01:00
|
|
|
<div>
|
2019-02-05 22:17:02 +01:00
|
|
|
<h6 class="text-white mb-3">Configuration</h6>
|
2019-03-07 20:22:02 +01:00
|
|
|
<div class="small text-white mb-3">
|
2019-03-07 21:08:33 +01:00
|
|
|
NOTE: The settings here override the environment variables. Once saved, it's recommended to stop setting
|
|
|
|
them to avoid confusion. This does not apply to the read-only section, which can only be set through the
|
|
|
|
environment.
|
2019-03-07 20:22:02 +01:00
|
|
|
</div>
|
2020-02-26 11:02:22 +01:00
|
|
|
|
2019-08-31 17:57:47 +02:00
|
|
|
<form class="form accordion" id="config-form" onsubmit="saveConfig(); return false;">
|
2019-02-03 00:22:18 +01:00
|
|
|
{{#each config}}
|
2019-02-05 22:17:02 +01:00
|
|
|
{{#if groupdoc}}
|
|
|
|
<div class="card bg-light mb-3">
|
2019-02-06 17:32:13 +01:00
|
|
|
<div class="card-header"><button type="button" class="btn btn-link collapsed" data-toggle="collapse"
|
2019-02-05 22:17:02 +01:00
|
|
|
data-target="#g_{{group}}">{{groupdoc}}</button></div>
|
|
|
|
<div id="g_{{group}}" class="card-body collapse" data-parent="#config-form">
|
|
|
|
{{#each elements}}
|
|
|
|
{{#if editable}}
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="form-group row align-items-center" title="[{{name}}] {{doc.description}}">
|
2019-02-08 20:49:04 +01:00
|
|
|
{{#case type "text" "number" "password"}}
|
2019-02-05 22:17:02 +01:00
|
|
|
<label for="input_{{name}}" class="col-sm-3 col-form-label">{{doc.name}}</label>
|
2019-02-08 20:49:04 +01:00
|
|
|
<div class="col-sm-8 input-group">
|
|
|
|
<input class="form-control conf-{{type}}" id="input_{{name}}" type="{{type}}"
|
|
|
|
name="{{name}}" value="{{value}}" {{#if default}} placeholder="Default: {{default}}"
|
|
|
|
{{/if}}>
|
|
|
|
|
|
|
|
{{#case type "password"}}
|
|
|
|
<div class="input-group-append">
|
|
|
|
<button class="btn btn-outline-secondary" type="button"
|
2019-08-31 17:47:52 +02:00
|
|
|
onclick="toggleVis('input_{{name}}');">Show/hide</button>
|
2019-02-08 20:49:04 +01:00
|
|
|
</div>
|
|
|
|
{{/case}}
|
2019-02-05 22:17:02 +01:00
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
{{#case type "checkbox"}}
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="col-sm-3 col-form-label">{{doc.name}}</div>
|
2019-02-05 22:17:02 +01:00
|
|
|
<div class="col-sm-8">
|
|
|
|
<div class="form-check">
|
2019-02-06 00:38:57 +01:00
|
|
|
<input class="form-check-input conf-{{type}}" type="checkbox" id="input_{{name}}"
|
|
|
|
name="{{name}}" {{#if value}} checked {{/if}}>
|
2019-02-03 00:22:18 +01:00
|
|
|
|
2019-02-05 22:17:02 +01:00
|
|
|
<label class="form-check-label" for="input_{{name}}"> Default: {{default}} </label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
2019-02-03 00:22:18 +01:00
|
|
|
</div>
|
2019-02-05 22:17:02 +01:00
|
|
|
{{/if}}
|
|
|
|
{{/each}}
|
2020-03-04 13:25:38 +01:00
|
|
|
{{#case group "smtp"}}
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="form-group row align-items-center pt-3 border-top" title="Send a test email to given email address">
|
2020-03-04 13:25:38 +01:00
|
|
|
<label for="smtp-test-email" class="col-sm-3 col-form-label">Test SMTP</label>
|
|
|
|
<div class="col-sm-8 input-group">
|
|
|
|
<input class="form-control" id="smtp-test-email" type="email" placeholder="Enter test email">
|
|
|
|
<div class="input-group-append">
|
|
|
|
<button type="button" class="btn btn-outline-primary" onclick="smtpTest(); return false;">Send test email</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
2019-02-03 00:22:18 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
|
|
|
{{/each}}
|
2019-02-18 19:25:33 +01:00
|
|
|
|
|
|
|
<div class="card bg-light mb-3">
|
|
|
|
<div class="card-header"><button type="button" class="btn btn-link collapsed" data-toggle="collapse"
|
|
|
|
data-target="#g_readonly">Read-Only Config</button></div>
|
|
|
|
<div id="g_readonly" class="card-body collapse" data-parent="#config-form">
|
2019-03-07 20:22:02 +01:00
|
|
|
<div class="small mb-3">
|
2019-02-18 19:25:33 +01:00
|
|
|
NOTE: These options can't be modified in the editor because they would require the server
|
|
|
|
to be restarted. To modify them, you need to set the correct environment variables when
|
|
|
|
launching the server. You can check the variable names in the tooltips of each option.
|
2019-03-07 20:22:02 +01:00
|
|
|
</div>
|
2019-02-18 19:25:33 +01:00
|
|
|
|
|
|
|
{{#each config}}
|
|
|
|
{{#each elements}}
|
|
|
|
{{#unless editable}}
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="form-group row align-items-center" title="[{{name}}] {{doc.description}}">
|
2019-02-18 19:25:33 +01:00
|
|
|
{{#case type "text" "number" "password"}}
|
|
|
|
<label for="input_{{name}}" class="col-sm-3 col-form-label">{{doc.name}}</label>
|
|
|
|
<div class="col-sm-8 input-group">
|
|
|
|
<input readonly class="form-control" id="input_{{name}}" type="{{type}}"
|
|
|
|
value="{{value}}" {{#if default}} placeholder="Default: {{default}}" {{/if}}>
|
|
|
|
|
|
|
|
{{#case type "password"}}
|
|
|
|
<div class="input-group-append">
|
|
|
|
<button class="btn btn-outline-secondary" type="button"
|
2019-08-31 17:47:52 +02:00
|
|
|
onclick="toggleVis('input_{{name}}');">Show/hide</button>
|
2019-02-18 19:25:33 +01:00
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
{{#case type "checkbox"}}
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="col-sm-3 col-form-label">{{doc.name}}</div>
|
2019-02-18 19:25:33 +01:00
|
|
|
<div class="col-sm-8">
|
2020-11-18 12:00:25 +01:00
|
|
|
<div class="form-check align-middle">
|
2019-02-18 19:25:33 +01:00
|
|
|
<input disabled class="form-check-input" type="checkbox" id="input_{{name}}"
|
|
|
|
{{#if value}} checked {{/if}}>
|
|
|
|
|
|
|
|
<label class="form-check-label" for="input_{{name}}"> Default: {{default}} </label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
</div>
|
|
|
|
{{/unless}}
|
|
|
|
{{/each}}
|
|
|
|
{{/each}}
|
2019-05-03 15:46:29 +02:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-02 00:08:52 +02:00
|
|
|
|
|
|
|
{{#if can_backup}}
|
2019-05-03 15:46:29 +02:00
|
|
|
<div class="card bg-light mb-3">
|
|
|
|
<div class="card-header"><button type="button" class="btn btn-link collapsed" data-toggle="collapse"
|
2019-06-02 00:08:52 +02:00
|
|
|
data-target="#g_database">Backup Database</button></div>
|
2019-05-03 15:46:29 +02:00
|
|
|
<div id="g_database" class="card-body collapse" data-parent="#config-form">
|
|
|
|
<div class="small mb-3">
|
2021-04-10 07:30:39 +02:00
|
|
|
WARNING: This function only creates a backup copy of the SQLite database.
|
|
|
|
This does not include any configuration or file attachment data that may
|
|
|
|
also be needed to fully restore a bitwarden_rs instance. For details on
|
|
|
|
how to perform complete backups, refer to the wiki page on
|
|
|
|
<a href="https://github.com/dani-garcia/bitwarden_rs/wiki/Backing-up-your-vault">backups</a>.
|
2019-05-03 15:46:29 +02:00
|
|
|
</div>
|
|
|
|
<button type="button" class="btn btn-primary" onclick="backupDatabase();">Backup Database</button>
|
2019-02-18 19:25:33 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-06-02 00:08:52 +02:00
|
|
|
{{/if}}
|
2019-02-18 19:25:33 +01:00
|
|
|
|
2019-02-02 16:47:27 +01:00
|
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
2019-02-17 15:22:27 +01:00
|
|
|
<button type="button" class="btn btn-danger float-right" onclick="deleteConf();">Reset defaults</button>
|
2019-02-02 16:47:27 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-19 22:12:52 +01:00
|
|
|
</main>
|
2019-01-19 21:36:34 +01:00
|
|
|
|
2019-02-03 00:22:18 +01:00
|
|
|
<style>
|
|
|
|
#config-block ::placeholder {
|
|
|
|
/* Most modern browsers support this now. */
|
|
|
|
color: orangered;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-01-19 22:12:52 +01:00
|
|
|
<script>
|
2020-02-26 11:02:22 +01:00
|
|
|
function smtpTest() {
|
2020-11-18 12:00:25 +01:00
|
|
|
if (formHasChanges(config_form)) {
|
|
|
|
alert("Config has been changed but not yet saved.\nPlease save the changes first before sending a test email.");
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-04 13:25:38 +01:00
|
|
|
test_email = document.getElementById("smtp-test-email");
|
|
|
|
data = JSON.stringify({ "email": test_email.value });
|
2020-02-26 16:58:57 +01:00
|
|
|
_post("{{urlpath}}/admin/test/smtp/",
|
2020-02-26 11:02:22 +01:00
|
|
|
"SMTP Test email sent correctly",
|
2020-03-04 13:25:38 +01:00
|
|
|
"Error sending SMTP test email", data, false);
|
2020-02-26 11:02:22 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-06 00:38:57 +01:00
|
|
|
function getFormData() {
|
|
|
|
let data = {};
|
2019-02-03 00:22:18 +01:00
|
|
|
|
2019-08-31 17:47:52 +02:00
|
|
|
document.querySelectorAll(".conf-checkbox").forEach(function (e, i) {
|
|
|
|
data[e.name] = e.checked;
|
2019-02-03 00:22:18 +01:00
|
|
|
});
|
|
|
|
|
2019-08-31 17:47:52 +02:00
|
|
|
document.querySelectorAll(".conf-number").forEach(function (e, i) {
|
|
|
|
data[e.name] = e.value ? +e.value : null;
|
2019-02-06 00:38:57 +01:00
|
|
|
});
|
|
|
|
|
2019-08-31 17:47:52 +02:00
|
|
|
document.querySelectorAll(".conf-text, .conf-password").forEach(function (e, i) {
|
2019-02-06 00:38:57 +01:00
|
|
|
data[e.name] = e.value || null;
|
|
|
|
});
|
|
|
|
return data;
|
2019-02-03 00:22:18 +01:00
|
|
|
}
|
2019-02-02 16:47:27 +01:00
|
|
|
function saveConfig() {
|
2019-02-06 00:38:57 +01:00
|
|
|
data = JSON.stringify(getFormData());
|
2020-02-22 17:49:33 +01:00
|
|
|
_post("{{urlpath}}/admin/config/", "Config saved correctly",
|
2019-02-02 16:47:27 +01:00
|
|
|
"Error saving config", data);
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-17 15:22:27 +01:00
|
|
|
function deleteConf() {
|
2019-02-06 17:32:13 +01:00
|
|
|
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") {
|
2020-02-22 17:49:33 +01:00
|
|
|
_post("{{urlpath}}/admin/config/delete",
|
2019-02-06 17:32:13 +01:00
|
|
|
"Config deleted correctly",
|
|
|
|
"Error deleting config");
|
|
|
|
} else {
|
|
|
|
alert("Wrong input, please try again")
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-03 15:46:29 +02:00
|
|
|
function backupDatabase() {
|
2020-02-22 17:49:33 +01:00
|
|
|
_post("{{urlpath}}/admin/config/backup_db",
|
2019-05-03 15:46:29 +02:00
|
|
|
"Backup created successfully",
|
2020-03-04 13:25:38 +01:00
|
|
|
"Error creating backup", null, false);
|
2019-05-03 15:46:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-06 00:38:57 +01:00
|
|
|
function masterCheck(check_id, inputs_query) {
|
2019-08-31 17:47:52 +02:00
|
|
|
function onChanged(checkbox, inputs_query) {
|
|
|
|
return function _fn() {
|
|
|
|
document.querySelectorAll(inputs_query).forEach(function (e, i) { e.disabled = !checkbox.checked; });
|
|
|
|
checkbox.disabled = false;
|
|
|
|
};
|
2019-02-06 00:38:57 +01:00
|
|
|
};
|
|
|
|
|
2019-08-31 17:47:52 +02:00
|
|
|
const checkbox = document.getElementById(check_id);
|
|
|
|
const onChange = onChanged(checkbox, inputs_query);
|
|
|
|
onChange(); // Trigger the event initially
|
|
|
|
checkbox.addEventListener("change", onChange);
|
2019-02-06 00:38:57 +01:00
|
|
|
}
|
2020-02-26 11:02:22 +01:00
|
|
|
// These are formatted because otherwise the
|
2019-08-31 17:47:52 +02:00
|
|
|
// VSCode formatter breaks But they still work
|
|
|
|
// {{#each config}} {{#if grouptoggle}}
|
|
|
|
masterCheck("input_{{grouptoggle}}", "#g_{{group}} input");
|
|
|
|
// {{/if}} {{/each}}
|
2020-11-18 12:00:25 +01:00
|
|
|
|
|
|
|
// Two functions to help check if there were changes to the form fields
|
|
|
|
// Useful for example during the smtp test to prevent people from clicking save before testing there new settings
|
|
|
|
function initChangeDetection(form) {
|
|
|
|
const ignore_fields = ["smtp-test-email"];
|
|
|
|
Array.from(form).forEach((el) => {
|
|
|
|
if (! ignore_fields.includes(el.id)) {
|
|
|
|
el.dataset.origValue = el.value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function formHasChanges(form) {
|
|
|
|
return Array.from(form).some(el => 'origValue' in el.dataset && ( el.dataset.origValue !== el.value));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trigger Form Change Detection
|
|
|
|
const config_form = document.getElementById('config-form');
|
|
|
|
initChangeDetection(config_form);
|
|
|
|
|
|
|
|
// Colorize some settings which are high risk
|
|
|
|
const risk_items = document.getElementsByClassName('col-form-label');
|
|
|
|
function colorRiskSettings(risk_el) {
|
|
|
|
Array.from(risk_el).forEach((el) => {
|
|
|
|
if (el.innerText.toLowerCase().includes('risks') ) {
|
|
|
|
el.parentElement.className += ' alert-danger'
|
|
|
|
console.log(el)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
colorRiskSettings(risk_items);
|
|
|
|
|
2020-02-19 06:27:00 +01:00
|
|
|
</script>
|