mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-31 16:08:42 +02:00
feat: add basic settings
This commit is contained in:
parent
91865d38e3
commit
70d7819573
105
lnbits/core/templates/admin/_tab_audit.html
Normal file
105
lnbits/core/templates/admin/_tab_audit.html
Normal file
@ -0,0 +1,105 @@
|
||||
<q-tab-panel name="audit">
|
||||
<q-card-section class="q-pa-none">
|
||||
<h6 class="q-my-none q-mb-sm">Audit</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-sm-12 q-pr-sm">
|
||||
<q-item tag="label" v-ripple>
|
||||
<q-item-section avatar>
|
||||
<q-toggle
|
||||
size="md"
|
||||
v-model="formData.lnbits_audit_enabled"
|
||||
checked-icon="check"
|
||||
color="green"
|
||||
unchecked-icon="clear"
|
||||
/>
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label>Enable audit</q-item-label>
|
||||
<q-item-label caption
|
||||
>Record HTTP requests according with the specified
|
||||
filters</q-item-label
|
||||
>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12 q-pr-sm">
|
||||
<q-item tag="label" v-ripple>
|
||||
<q-item-section avatar>
|
||||
<q-toggle
|
||||
size="md"
|
||||
v-model="formData.lnbits_audit_log_ip_address"
|
||||
checked-icon="check"
|
||||
color="green"
|
||||
unchecked-icon="clear"
|
||||
/>
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label>Record IP Address</q-item-label>
|
||||
<q-item-label caption
|
||||
>If disabled audit entries will not record the IP
|
||||
address</q-item-label
|
||||
>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</div>
|
||||
</div>
|
||||
<q-separator class="q-mb-lg q-mt-sm"></q-separator>
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-sm-12 q-pr-sm">
|
||||
<p>Include Paths</p>
|
||||
<q-input
|
||||
filled
|
||||
v-model="formAddIncludePath"
|
||||
@keydown.enter="addIncludePath"
|
||||
type="text"
|
||||
label="HTTP Path (regex)"
|
||||
hint="List of paths to be included (regex match). Empty list means all."
|
||||
>
|
||||
<q-btn @click="addIncludePath" dense flat icon="add"></q-btn>
|
||||
</q-input>
|
||||
<div>
|
||||
<q-chip
|
||||
v-for="path in formData.lnbits_audit_include_paths"
|
||||
:key="path"
|
||||
removable
|
||||
@remove="removeIncludePath(path)"
|
||||
color="primary"
|
||||
text-color="white"
|
||||
:label="path"
|
||||
>
|
||||
</q-chip>
|
||||
</div>
|
||||
<br />
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<p>Exclude Paths</p>
|
||||
<q-input
|
||||
filled
|
||||
v-model="formAddExcludePath"
|
||||
@keydown.enter="addExcludePath"
|
||||
type="text"
|
||||
label="HTTP Path (regex)"
|
||||
hint="List of paths to be excluded (regex match). Empty list means none."
|
||||
>
|
||||
<q-btn @click="addExcludePath" dense flat icon="add"></q-btn>
|
||||
</q-input>
|
||||
<div>
|
||||
<q-chip
|
||||
v-for="path in formData.lnbits_audit_exclude_paths"
|
||||
:key="path"
|
||||
removable
|
||||
@remove="removeExcludePath(path)"
|
||||
color="primary"
|
||||
text-color="white"
|
||||
:label="path"
|
||||
>
|
||||
</q-chip>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-tab-panel>
|
@ -101,6 +101,12 @@
|
||||
:label="$t('notifications')"
|
||||
@update="val => tab = val.name"
|
||||
></q-tab>
|
||||
<q-tab
|
||||
name="audit"
|
||||
icon="playlist_add_check_circle"
|
||||
:label="$t('audit')"
|
||||
@update="val => tab = val.name"
|
||||
></q-tab>
|
||||
<q-tab
|
||||
name="site_customisation"
|
||||
icon="language"
|
||||
@ -125,7 +131,7 @@
|
||||
{% include "admin/_tab_extensions.html" %} {% include
|
||||
"admin/_tab_notifications.html" %} {% include
|
||||
"admin/_tab_security.html" %} {% include "admin/_tab_theme.html"
|
||||
%}
|
||||
%}{% include "admin/_tab_audit.html"%}
|
||||
</q-tab-panels>
|
||||
</q-form>
|
||||
</template>
|
||||
|
@ -153,8 +153,13 @@ class AuditMiddleware(BaseHTTPMiddleware):
|
||||
response_code = str(response.status_code) if response else None
|
||||
if not settings.is_http_request_auditable(http_method, path, response_code):
|
||||
return None
|
||||
ip_address = (
|
||||
request.client.host
|
||||
if settings.lnbits_audit_log_ip_address and request.client
|
||||
else None
|
||||
)
|
||||
data = AuditEntry(
|
||||
ip_address=request.client.host if request.client else None,
|
||||
ip_address=ip_address,
|
||||
user_id=request.scope.get("user_id", None),
|
||||
path=path,
|
||||
route_path=getattr(request.scope.get("route", {}), "path", None),
|
||||
|
@ -516,7 +516,7 @@ class AuditSettings(LNbitsSettings):
|
||||
# number of days to keep the audit entry
|
||||
lnbits_audit_retention_days: int = Field(default=7)
|
||||
|
||||
lnbits_audit_log_ip: bool = Field(default=False)
|
||||
lnbits_audit_log_ip_address: bool = Field(default=False)
|
||||
|
||||
# List of paths to be included (regex match). Empty list means all.
|
||||
lnbits_audit_include_paths: list[str] = Field(default=[".*api/v1/.*"])
|
||||
|
@ -42,6 +42,8 @@ window.app = Vue.createApp({
|
||||
formAllowedIPs: '',
|
||||
formBlockedIPs: '',
|
||||
nostrAcceptedUrl: '',
|
||||
formAddIncludePath: '',
|
||||
formAddExcludePath: '',
|
||||
isSuperUser: false,
|
||||
wallet: {},
|
||||
cancel: {},
|
||||
@ -103,6 +105,34 @@ window.app = Vue.createApp({
|
||||
let allowed_users = this.formData.lnbits_allowed_users
|
||||
this.formData.lnbits_allowed_users = allowed_users.filter(u => u !== user)
|
||||
},
|
||||
addIncludePath() {
|
||||
if (!this.formAddIncludePath) {
|
||||
return
|
||||
}
|
||||
const paths = this.formData.lnbits_audit_include_paths
|
||||
if (!paths.includes(this.formAddIncludePath)) {
|
||||
paths.push(this.formAddIncludePath)
|
||||
}
|
||||
this.formAddIncludePath = ''
|
||||
},
|
||||
removeIncludePath(path) {
|
||||
this.formData.lnbits_audit_include_paths =
|
||||
this.formData.lnbits_audit_include_paths.filter(p => p !== path)
|
||||
},
|
||||
addExcludePath() {
|
||||
if (!this.formAddExcludePath) {
|
||||
return
|
||||
}
|
||||
const paths = this.formData.lnbits_audit_exclude_paths
|
||||
if (!paths.includes(this.formAddExcludePath)) {
|
||||
paths.push(this.formAddExcludePath)
|
||||
}
|
||||
this.formAddExcludePath = ''
|
||||
},
|
||||
removeExcludePath(path) {
|
||||
this.formData.lnbits_audit_exclude_paths =
|
||||
this.formData.lnbits_audit_exclude_paths.filter(p => p !== path)
|
||||
},
|
||||
addExtensionsManifest() {
|
||||
const addManifest = this.formAddExtensionsManifest.trim()
|
||||
const manifests = this.formData.lnbits_extensions_manifests
|
||||
|
Loading…
x
Reference in New Issue
Block a user