lnbits-legend/lnbits/core/templates/admin/index.html

530 lines
14 KiB
HTML
Raw Normal View History

2022-03-07 05:03:32 +00:00
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
%} {% block page %}
2022-10-03 22:14:07 +02:00
<div class="row q-col-gutter-md justify-center">
<div class="col q-my-md">
<q-btn
label="Save"
color="primary"
@click="updateSettings"
:disabled="!checkChanges"
>
<q-tooltip v-if="checkChanges"> Save your changes </q-tooltip>
2022-10-12 19:04:46 +01:00
<q-badge
v-if="checkChanges"
color="red"
rounded
floating
style="padding: 6px; border-radius: 6px"
/>
2022-10-07 18:39:53 +01:00
</q-btn>
2022-12-14 16:09:27 +00:00
<q-btn
v-if="isSuperUser"
label="Restart server"
color="primary"
@click="restartServer"
>
<q-tooltip v-if="needsRestart">
Restart the server for changes to take effect
</q-tooltip>
<q-badge
v-if="needsRestart"
color="red"
rounded
floating
style="padding: 6px; border-radius: 6px"
/>
</q-btn>
2022-12-14 16:09:27 +00:00
<q-btn
v-if="isSuperUser"
label="Topup"
color="primary"
@click="topUpDialog.show = true"
>
<q-tooltip> Add funds to a wallet. </q-tooltip>
</q-btn>
2022-10-07 18:39:53 +01:00
<!-- <q-btn
2022-10-05 09:19:07 +02:00
label="Download Database Backup"
flat
@click="downloadBackup"
></q-btn> -->
<q-btn
flat
v-if="isSuperUser"
label="Reset to defaults"
color="primary"
@click="deleteSettings"
class="float-right"
>
<q-tooltip> Delete all settings and reset to defaults. </q-tooltip>
</q-btn>
2022-10-03 22:14:07 +02:00
</div>
</div>
2022-03-18 16:55:31 +00:00
<div class="row q-col-gutter-md justify-center">
<div class="col q-gutter-y-md">
<q-card>
<div class="q-pa-md">
<div class="q-gutter-y-md">
<q-tabs v-model="tab" active-color="primary" align="justify">
<q-tab
name="funding"
label="Funding"
@update="val => tab = val.name"
></q-tab>
<q-tab
name="users"
label="Users"
@update="val => tab = val.name"
></q-tab>
<q-tab
name="server"
label="Server"
@update="val => tab = val.name"
></q-tab>
<q-tab
name="theme"
label="Theme"
@update="val => tab = val.name"
></q-tab>
</q-tabs>
</div>
</div>
2022-10-05 09:19:07 +02:00
<q-form name="settings_form" id="settings_form">
2022-04-14 16:37:13 +01:00
<q-tab-panels v-model="tab" animated>
2022-10-03 16:36:14 +02:00
{% include "admin/_tab_funding.html" %} {% include
"admin/_tab_users.html" %} {% include "admin/_tab_server.html" %} {%
include "admin/_tab_theme.html" %}
2022-04-14 16:37:13 +01:00
</q-tab-panels>
</q-form>
2022-03-18 16:55:31 +00:00
</q-card>
</div>
2022-04-14 16:37:13 +01:00
</div>
2022-12-14 16:09:27 +00:00
<q-dialog v-if="isSuperUser" v-model="topUpDialog.show" position="top">
2022-10-07 18:39:53 +01:00
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-form class="q-gutter-md">
<p>TopUp a wallet</p>
<div class="row">
<div class="col-12">
<q-input
dense
type="text"
filled
v-model="wallet.id"
label="Wallet ID"
hint="Use the wallet ID to topup any wallet"
></q-input>
<br />
</div>
<div class="col-12">
<q-input
dense
type="number"
filled
v-model="wallet.amount"
label="Topup amount"
></q-input>
</div>
</div>
<div class="row q-mt-lg">
<q-btn label="Topup" color="primary" @click="topupWallet"></q-btn>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Cancel</q-btn>
</div>
</q-form>
</q-card>
</q-dialog>
2022-03-07 05:03:32 +00:00
{% endblock %} {% block scripts %} {{ window_vars(user) }}
<script>
new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {
2022-10-03 22:14:07 +02:00
settings: {},
lnbits_theme_options: [
2023-01-10 17:35:43 +01:00
'classic',
'bitcoin',
'flamingo',
'freedom',
'mint',
'autumn',
'monochrome',
'salvador'
],
2022-10-07 18:39:53 +01:00
formData: {},
formAddAdmin: '',
formAddUser: '',
isSuperUser: false,
2022-10-03 22:14:07 +02:00
wallet: {},
2022-03-07 05:03:32 +00:00
cancel: {},
2022-10-07 18:39:53 +01:00
topUpDialog: {
show: false
},
2022-10-12 19:04:46 +01:00
tab: 'funding',
needsRestart: false,
2022-10-12 19:04:46 +01:00
funding_sources: new Map([
['VoidWallet', null],
[
'FakeWallet',
{
fake_wallet_secret: {
value: null,
label: 'Secret'
}
}
],
[
'CLightningWallet',
{
corelightning_rpc: {
value: null,
label: 'Endpoint'
}
}
],
[
'LndRestWallet',
{
lnd_rest_endpoint: {
value: null,
label: 'Endpoint'
},
lnd_rest_cert: {
value: null,
label: 'Certificate'
},
lnd_rest_macaroon: {
value: null,
label: 'Macaroon'
},
lnd_rest_macaroon_encrypted: {
value: null,
label: 'Encrypted Macaroon'
},
lnd_cert: {
value: null,
label: 'Certificate'
},
2023-01-10 17:35:43 +01:00
lnd_rest_admin_macaroon: {
2022-10-12 19:04:46 +01:00
value: null,
label: 'Admin Macaroon'
},
2023-01-10 17:35:43 +01:00
lnd_rest_invoice_macaroon: {
2022-10-12 19:04:46 +01:00
value: null,
label: 'Invoice Macaroon'
}
}
],
[
'LndWallet',
{
lnd_grpc_endpoint: {
value: null,
label: 'Endpoint'
},
lnd_grpc_cert: {
value: null,
label: 'Certificate'
},
lnd_grpc_port: {
value: null,
label: 'Port'
},
lnd_grpc_admin_macaroon: {
value: null,
label: 'Admin Macaroon'
},
lnd_grpc_invoice_macaroon: {
value: null,
label: 'Invoice Macaroon'
},
lnd_grpc_macaroon_encrypted: {
value: null,
label: 'Encrypted Macaroon'
}
}
],
[
'LntxbotWallet',
{
lntxbot_api_endpoint: {
value: null,
label: 'Endpoint'
},
lntxbot_key: {
value: null,
label: 'Key'
}
}
],
[
'LNPayWallet',
{
lnpay_api_endpoint: {
value: null,
label: 'Endpoint'
},
lnpay_api_key: {
value: null,
label: 'API Key'
},
lnpay_wallet_key: {
value: null,
label: 'Wallet Key'
}
}
],
[
'EclairWallet',
{
eclair_url: {
value: null,
label: 'Endpoint'
},
eclair_pass: {
value: null,
label: 'Password'
}
}
],
[
'LNbitsWallet',
2022-10-12 19:04:46 +01:00
{
lnbits_endpoint: {
value: null,
label: 'Endpoint'
},
lnbits_key: {
value: null,
label: 'Admin Key'
}
}
],
[
'OpenNodeWallet',
{
opennode_api_endpoint: {
value: null,
label: 'Endpoint'
},
opennode_key: {
value: null,
label: 'Key'
}
}
],
[
'ClicheWallet',
{
cliche_endpoint: {
value: null,
label: 'Endpoint'
}
}
],
[
'SparkWallet',
{
spark_url: {
value: null,
label: 'Endpoint'
},
spark_token: {
value: null,
label: 'Token'
}
}
2022-12-01 10:01:16 +00:00
],
[
'LnTipsWallet',
{
lntips_api_endpoint: {
value: null,
label: 'Endpoint'
},
lntips_api_key: {
value: null,
label: 'API Key'
}
}
2022-10-12 19:04:46 +01:00
]
])
2022-03-07 05:03:32 +00:00
}
},
created: function () {
this.getSettings()
2022-10-07 18:39:53 +01:00
this.balance = +'{{ balance|safe }}'
2022-03-07 05:03:32 +00:00
},
computed: {
2022-10-12 19:04:46 +01:00
checkChanges() {
return !_.isEqual(this.settings, this.formData)
}
2022-10-07 19:44:03 +01:00
},
2022-03-07 05:03:32 +00:00
methods: {
2022-04-14 16:37:13 +01:00
addAdminUser() {
let addUser = this.formAddAdmin
let admin_users = this.formData.lnbits_admin_users
if (addUser && addUser.length && !admin_users.includes(addUser)) {
//admin_users = [...admin_users, addUser]
this.formData.lnbits_admin_users = [...admin_users, addUser]
this.formAddAdmin = ''
//console.log(this.checkChanges)
2022-03-18 16:55:31 +00:00
}
},
2022-04-14 16:37:13 +01:00
removeAdminUser(user) {
let admin_users = this.formData.lnbits_admin_users
this.formData.lnbits_admin_users = admin_users.filter(u => u !== user)
2022-03-18 16:55:31 +00:00
},
2022-04-14 16:37:13 +01:00
addAllowedUser() {
let addUser = this.formAddUser
let allowed_users = this.formData.lnbits_allowed_users
if (addUser && addUser.length && !allowed_users.includes(addUser)) {
this.formData.lnbits_allowed_users = [...allowed_users, addUser]
this.formAddUser = ''
2022-03-18 16:55:31 +00:00
}
},
2022-04-14 16:37:13 +01:00
removeAllowedUser(user) {
let allowed_users = this.formData.lnbits_allowed_users
this.formData.lnbits_allowed_users = allowed_users.filter(
2022-10-12 19:04:46 +01:00
u => u !== user
)
2022-03-18 16:55:31 +00:00
},
2022-09-27 16:37:08 +02:00
restartServer() {
LNbits.api
2022-10-07 18:39:53 +01:00
.request('GET', '/admin/api/v1/restart/?usr=' + this.g.user.id)
2022-09-27 16:37:08 +02:00
.then(response => {
this.$q.notify({
type: 'positive',
message: 'Success! Restarted Server',
icon: null
})
this.needsRestart = false
2022-09-27 16:37:08 +02:00
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
2022-03-22 10:29:18 +00:00
topupWallet() {
2022-03-07 05:03:32 +00:00
LNbits.api
.request(
2022-10-12 13:08:59 +02:00
'PUT',
2022-10-05 09:19:07 +02:00
'/admin/api/v1/topup/?usr=' + this.g.user.id,
2022-10-12 13:08:59 +02:00
this.g.user.wallets[0].adminkey,
this.wallet
2022-03-07 05:03:32 +00:00
)
2022-04-14 16:37:13 +01:00
.then(response => {
2022-03-22 10:29:18 +00:00
this.$q.notify({
2022-03-07 05:03:32 +00:00
type: 'positive',
message:
2022-04-14 16:37:13 +01:00
'Success! Added ' +
2022-10-03 22:14:07 +02:00
this.wallet.amount +
2022-04-14 16:37:13 +01:00
' to ' +
2022-10-03 22:14:07 +02:00
this.wallet.id,
2022-03-07 05:03:32 +00:00
icon: null
})
2022-10-03 22:14:07 +02:00
this.wallet = {}
2022-03-07 05:03:32 +00:00
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
updateFundingData() {
2022-10-12 19:04:46 +01:00
this.settings.lnbits_allowed_funding_sources.map(f => {
let opts = this.funding_sources.get(f)
if (!opts) return
2022-10-12 19:04:46 +01:00
Object.keys(opts).forEach(e => {
opts[e].value = this.settings[e]
})
})
},
getSettings() {
LNbits.api
.request(
'GET',
'/admin/api/v1/settings/?usr=' + this.g.user.id,
this.g.user.wallets[0].adminkey
)
.then(response => {
this.isSuperUser = response.data.super_user || false
this.settings = response.data
this.formData = _.clone(this.settings)
this.updateFundingData()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
2022-10-12 19:04:46 +01:00
},
2022-10-03 22:14:07 +02:00
updateSettings() {
let data = _.omit(this.formData, [
'super_user',
'lnbits_allowed_funding_sources'
])
2022-03-07 05:03:32 +00:00
LNbits.api
.request(
2022-10-03 22:14:07 +02:00
'PUT',
2022-10-05 09:19:07 +02:00
'/admin/api/v1/settings/?usr=' + this.g.user.id,
2022-03-22 10:29:18 +00:00
this.g.user.wallets[0].adminkey,
2022-03-12 14:18:09 +00:00
data
2022-03-07 05:03:32 +00:00
)
2022-03-22 10:29:18 +00:00
.then(response => {
this.needsRestart =
this.settings.lnbits_backend_wallet_class !==
this.formData.lnbits_backend_wallet_class
this.settings = this.formData
this.formData = _.clone(this.settings)
2022-10-12 19:04:46 +01:00
this.updateFundingData()
2022-03-22 10:29:18 +00:00
this.$q.notify({
2022-03-07 05:03:32 +00:00
type: 'positive',
2022-04-14 16:37:13 +01:00
message: 'Success! Settings changed!',
2022-03-07 05:03:32 +00:00
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
2022-10-07 18:39:53 +01:00
})
2022-10-05 09:19:07 +02:00
},
deleteSettings() {
LNbits.utils
.confirmDialog(
'Are you sure you want to restore settings to default?'
)
.onOk(() => {
LNbits.api
.request(
'DELETE',
'/admin/api/v1/settings/?usr=' + this.g.user.id
)
.then(response => {
this.$q.notify({
type: 'positive',
message:
'Success! Restored settings to defaults, restart required!',
icon: null
})
this.needsRestart = true
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
2022-10-07 18:39:53 +01:00
})
2022-10-05 09:19:07 +02:00
},
downloadBackup() {
LNbits.api
2022-10-07 18:39:53 +01:00
.request('GET', '/admin/api/v1/backup/?usr=' + this.g.user.id)
2022-10-05 09:19:07 +02:00
.then(response => {
this.$q.notify({
type: 'positive',
2022-10-07 18:39:53 +01:00
message:
'Success! Database backup request, download starts soon!',
2022-10-05 09:19:07 +02:00
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
2022-10-07 18:39:53 +01:00
})
2022-03-07 05:03:32 +00:00
}
2022-10-12 19:04:46 +01:00
}
2022-03-07 05:03:32 +00:00
})
</script>
{% endblock %}