From 70d78195736bcf21cde2f3bdef6d2f366b4fe1dd Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Wed, 20 Nov 2024 12:13:53 +0200 Subject: [PATCH] feat: add basic settings --- lnbits/core/templates/admin/_tab_audit.html | 105 ++++++++++++++++++++ lnbits/core/templates/admin/index.html | 8 +- lnbits/middleware.py | 7 +- lnbits/settings.py | 2 +- lnbits/static/js/admin.js | 30 ++++++ 5 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 lnbits/core/templates/admin/_tab_audit.html diff --git a/lnbits/core/templates/admin/_tab_audit.html b/lnbits/core/templates/admin/_tab_audit.html new file mode 100644 index 000000000..a712a190e --- /dev/null +++ b/lnbits/core/templates/admin/_tab_audit.html @@ -0,0 +1,105 @@ + + +
Audit
+ +
+
+ + + + + + Enable audit + Record HTTP requests according with the specified + filters + + +
+
+ + + + + + Record IP Address + If disabled audit entries will not record the IP + address + + +
+
+ +
+
+

Include Paths

+ + + +
+ + +
+
+
+
+

Exclude Paths

+ + + +
+ + +
+
+ +
+
+
+
+
diff --git a/lnbits/core/templates/admin/index.html b/lnbits/core/templates/admin/index.html index fb44ea3ab..054ab8196 100644 --- a/lnbits/core/templates/admin/index.html +++ b/lnbits/core/templates/admin/index.html @@ -101,6 +101,12 @@ :label="$t('notifications')" @update="val => tab = val.name" > + diff --git a/lnbits/middleware.py b/lnbits/middleware.py index 33385e232..edf1addb7 100644 --- a/lnbits/middleware.py +++ b/lnbits/middleware.py @@ -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), diff --git a/lnbits/settings.py b/lnbits/settings.py index 37158226d..b2d0adc7e 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -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/.*"]) diff --git a/lnbits/static/js/admin.js b/lnbits/static/js/admin.js index 267704c78..b2d50433f 100644 --- a/lnbits/static/js/admin.js +++ b/lnbits/static/js/admin.js @@ -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