overall fixes

This commit is contained in:
dni ⚡ 2022-10-03 22:14:07 +02:00
parent 2479fc15f5
commit 11c0b655d9
9 changed files with 47 additions and 226 deletions

View File

@ -1,2 +1,3 @@
from .app import create_app
app = create_app()

View File

@ -16,7 +16,6 @@ from fastapi.staticfiles import StaticFiles
from loguru import logger
from lnbits.core.tasks import register_task_listeners
from lnbits.settings import WALLET, check_admin_settings, settings
from .commands import migrate_databases
@ -60,14 +59,13 @@ def create_app() -> FastAPI:
name="core_static",
)
origins = ["*"]
app.add_middleware(
CORSMiddleware, allow_origins=origins, allow_methods=["*"], allow_headers=["*"]
CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]
)
# TODO: why those 2?
g().config = settings
g().base_url = f"http://{settings.host}:{settings.port}"
# g().base_url = f"http://{settings.host}:{settings.port}"
app.add_middleware(GZipMiddleware, minimum_size=1000)
@ -86,7 +84,6 @@ async def check_funding_source() -> None:
# def signal_handler(signal, frame):
# logger.debug(f"SIGINT received, terminating LNbits.")
# sys.exit(1)
# signal.signal(signal.SIGINT, signal_handler)
while True:
try:

View File

@ -26,17 +26,8 @@
filled
v-model="data.settings.lnbits_backend_wallet_class"
hint="Select the active funding wallet"
:options="data.settings.lnbits_funding_sources"
:options="data.settings.lnbits_allowed_funding_sources"
></q-select>
<br />
<div>
<q-btn
class="q-mt-md float-right"
label="Restart Server"
color="primary"
@click="restartServer"
></q-btn>
</div>
</div>
<div class="col-12">
<p>Fee reserve</p>
@ -72,7 +63,7 @@
dense
type="text"
filled
v-model="wallet.data.id"
v-model="wallet.id"
label="Wallet ID"
hint="Use the wallet ID to topup any wallet"
></q-input>
@ -83,7 +74,7 @@
dense
type="number"
filled
v-model="wallet.data.amount"
v-model="wallet.amount"
label="Topup amount"
></q-input>
</div>
@ -100,59 +91,21 @@
</div>
</div>
<p>Funding Sources</p>
{% raw %}
<q-list v-for="fund in data.settings.funding" :key="fund.id">
<q-expansion-item
expand-separator
icon="payments"
:label="fund.backend_wallet"
>
<q-list v-for="fund in data.settings.lnbits_allowed_funding_sources">
<q-expansion-item expand-separator icon="payments" :label="fund">
<q-card>
<q-card-section>
<q-input
v-if="fund.endpoint"
filled
type="text"
v-model="fund.endpoint"
label="Endpoint"
v-model="data.settings.lnbits_backend_wallet_class"
label="Wallet class"
class="q-pr-md"
></q-input>
<q-input
v-if="fund.port"
filled
type="text"
v-model="fund.port"
label="Port"
class="q-pr-md"
></q-input>
<q-input
v-if="fund.admin_key"
filled
type="text"
v-model="fund.admin_key"
label="Admin Key"
class="q-pr-md"
></q-input>
<q-input
v-if="fund.cert"
filled
type="text"
v-model="fund.cert"
label="Location of your ssl cert"
class="q-pr-md"
></q-input>
<q-btn
class="q-mt-md"
label="Save"
flat
color="primary"
@click="updateFunding(fund.backend_wallet)"
></q-btn>
</q-card-section>
</q-card>
</q-expansion-item>
</q-list>
{% endraw %}
</div>
</q-card-section>
</q-tab-panel>

View File

@ -70,9 +70,5 @@
</div>
</div>
</div>
<div class="row q-mt-lg">
<q-btn unelevated color="primary" type="submit">Save</q-btn>
</div>
</q-card-section>
</q-tab-panel>

View File

@ -66,7 +66,7 @@
v-model="data.settings.lnbits_theme"
multiple
hint="Choose themes available for users"
:options="themes"
:options="data.settings.lnbits_theme_options"
label="Themes"
></q-select>
<br />
@ -114,9 +114,5 @@
</div>
</div>
</div>
<div class="row q-mt-lg">
<q-btn unelevated color="primary" type="submit">Save</q-btn>
</div>
</q-card-section>
</q-tab-panel>

View File

@ -68,10 +68,9 @@
<p>Admin Extensions</p>
<q-select
filled
v-model="data.settings.admin_extensions"
v-model="data.settings.lnbits_admin_extensions"
multiple
hint="Extensions only user with admin privileges can use"
:options="options"
label="Admin extensions"
></q-select>
<br />
@ -83,14 +82,10 @@
v-model="data.settings.lnbits_disabled_extensions"
multiple
hint="Disable extensions *amilk disabled by default as resource heavy"
:options="options"
label="Disable extensions"
></q-select>
<br />
</div>
</div>
<div class="row q-mt-lg">
<q-btn unelevated color="primary" type="submit">Save</q-btn>
</div>
</q-card-section>
</q-tab-panel>

View File

@ -1,5 +1,12 @@
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
%} {% block page %}
<div class="row q-col-gutter-md justify-center">
<div class="col q-gutter-y-md">
<q-btn label="Save" flat @click="updateSettings"></q-btn>
<q-btn label="Restart server" flat @click="restartServer"></q-btn>
<q-btn label="Reset to defaults" flat @click="restartServer"></q-btn>
</div>
</div>
<div class="row q-col-gutter-md justify-center">
<div class="col q-gutter-y-md">
<q-card>
@ -29,7 +36,7 @@
</q-tabs>
</div>
</div>
<q-form @submit="UpdateLNbits">
<q-form>
<q-tab-panels v-model="tab" animated>
{% include "admin/_tab_funding.html" %} {% include
"admin/_tab_users.html" %} {% include "admin/_tab_server.html" %} {%
@ -42,68 +49,20 @@
{% endblock %} {% block scripts %} {{ window_vars(user) }}
<script>
const queryString = window.location.search
const urlParams = new URLSearchParams(queryString)
const usr = urlParams.get('usr')
new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {
wallet: {data: {}},
settings: {},
data: {},
wallet: {},
cancel: {},
tab: 'funding',
data: {
funding_sources: [
'CLightningWallet',
'LndRestWallet',
'LndWallet',
'LntxbotWallet',
'LNPayWallet',
'LnbitsWallet',
'OpenNodeWallet'
],
},
themes: [
'classic',
'bitcoin',
'flamingo',
'mint',
'autumn',
'monochrome',
'salvador'
],
options: [
'bleskomat',
'captcha',
'events',
'example',
'livestream',
'lndhub',
'lnurlp',
'offlineshop',
'paywall',
'splitpayments',
'subdomains',
'tpos',
'usermanager',
'watchonly',
'withdraw',
'copilot',
'hivemind',
'jukebox',
'lnticket',
'ngrok',
'amilk'
]
tab: 'funding'
}
},
created: function () {
var self = this
if (usr != null) {
self.cancel.on = true
}
this.data.settings = JSON.parse('{{ settings | tojson|safe }}')
this.data.settings = JSON.parse('{{ settings|tojson|safe }}')
this.data.balance = {{ balance|safe }}
console.log(this.data.settings, this.data.balance)
},
@ -144,7 +103,7 @@
}
},
removeAdSpace(ad) {
let spaces = this.data.admin.ad_space
let spaces = this.data.settings.lnbits_ad_space
this.data.admin.ad_space = spaces.filter(s => s !== ad)
},
restartServer() {
@ -168,111 +127,38 @@
topupWallet() {
LNbits.api
.request(
'GET',
'/admin/api/v1/admin/' +
this.wallet.data.id +
'/' +
this.wallet.data.amount,
this.g.user.wallets[0].adminkey
'POST',
'/admin/api/v1/admin/topup/',
this.g.user.wallets[0].adminkey,
this.wallet.id,
this.wallet.amount,
)
.then(response => {
this.$q.notify({
type: 'positive',
message:
'Success! Added ' +
this.wallet.data.amount +
this.wallet.amount +
' to ' +
this.wallet.data.id,
this.wallet.id,
icon: null
})
this.wallet.data = {}
this.wallet = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
createWallet: function () {
LNbits.href.createWallet(this.walletName)
},
addSource: function (source) {
var self = this
self.data.admin.edited.push(source)
console.log(self.data.admin.edited)
},
updateFunding(fund) {
let data = this.data.admin.funding.find(v => v.backend_wallet == fund)
updateSettings() {
let data = {}
LNbits.api
.request(
'POST',
'/admin/api/v1/admin/funding',
this.g.user.wallets[0].adminkey,
data
)
.then(response => {
//let wallet = response.data.backend_wallet
//this.data.admin.funding[wallet] = response.data
//this.data.admin.funding[wallet].endpoint = response.data.endpoint
//console.log(this.data.admin.funding)
//console.log(this.data.admin)
this.$q.notify({
type: 'positive',
message: `Success! ${response.data.backend_wallet} changed!`,
icon: null
})
})
},
UpdateLNbits() {
let {
admin_users,
allowed_users,
admin_ext,
disabled_ext,
funding_source,
force_https,
reserve_fee_min,
reserve_fee_pct,
service_fee,
hide_api,
site_title,
site_tagline,
site_description,
default_wallet_name,
denomination,
theme,
custom_logo,
ad_space
} = this.data.admin
let data = {
admin_users: admin_users.toString(),
allowed_users: allowed_users.toString(),
admin_ext: admin_ext.toString(),
disabled_ext: disabled_ext.toString(),
funding_source,
force_https,
reserve_fee_min,
reserve_fee_pct,
service_fee,
hide_api,
site_title,
site_tagline,
site_description,
default_wallet_name,
denomination,
theme: theme.toString(),
custom_logo: custom_logo.toString(),
ad_space: ad_space.toString()
}
LNbits.api
.request(
'POST',
'PUT',
'/admin/api/v1/admin/',
this.g.user.wallets[0].adminkey,
data
)
.then(response => {
//console.log(response.data)
this.$q.notify({
type: 'positive',
message: 'Success! Settings changed!',
@ -281,15 +167,7 @@
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
processing: function () {
this.$q.notify({
timeout: 0,
message: 'Processing...',
icon: null
})
});
}
}
})

View File

@ -1,5 +1,7 @@
import asyncio
import uvloop
uvloop.install()
import contextlib

View File

@ -20,7 +20,7 @@ def list_parse_fallback(v):
return []
read_only_variables = ["host", "port", "lnbits_commit"]
read_only_variables = ["host", "port", "lnbits_commit", "lnbits_path"]
class Settings(BaseSettings):
@ -31,7 +31,7 @@ class Settings(BaseSettings):
debug: Optional[bool]
host: Optional[str]
port: Optional[int]
lnbits_path: Optional[str] = path.dirname(path.realpath(__file__))
lnbits_path: str = Field(default=".")
lnbits_commit: str = Field(default="unknown")
# users
@ -54,7 +54,7 @@ class Settings(BaseSettings):
# ops
lnbits_data_folder: str = Field(default="./data")
lnbits_database_url: str = Field(default=None)
lnbits_force_https: bool = Field(default=True)
lnbits_force_https: bool = Field(default=False)
lnbits_reserve_fee_min: int = Field(default=4000)
lnbits_reserve_fee_percent: float = Field(default=1.0)
lnbits_service_fee: float = Field(default=0)
@ -65,6 +65,8 @@ class Settings(BaseSettings):
lnbits_backend_wallet_class: str = Field(default="VoidWallet")
lnbits_allowed_funding_sources: List[str] = Field(
default=[
"VoidWallet",
"FakeWallet",
"CLightningWallet",
"LndRestWallet",
"LndWallet",
@ -129,6 +131,7 @@ class Settings(BaseSettings):
settings = Settings()
settings.lnbits_path = str(path.dirname(path.realpath(__file__)))
settings.lnbits_commit = (
subprocess.check_output(
["git", "-C", settings.lnbits_path, "rev-parse", "HEAD"],