Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
139bd96639 | ||
|
|
f6114fc33a | ||
|
|
399e01c6a8 | ||
|
|
abe1e2fb27 | ||
|
|
43900dd6da | ||
|
|
06c553219a | ||
|
|
fc73d83bd9 | ||
|
|
4cb743d952 | ||
|
|
3b6e87b060 | ||
|
|
09e44f18e5 |
+1
-1
@@ -43,4 +43,4 @@ ENV LNBITS_HOST="0.0.0.0"
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["sh", "-c", "uv --offline run lnbits --port $LNBITS_PORT --host $LNBITS_HOST --forwarded-allow-ips='*'"]
|
||||
CMD ["sh", "-c", "uv --offline run --no-sync lnbits --port $LNBITS_PORT --host $LNBITS_HOST --forwarded-allow-ips='*'"]
|
||||
|
||||
@@ -41,6 +41,7 @@ class SimpleStatus(BaseModel):
|
||||
class SimpleItem(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
expires_at: int | None = None
|
||||
|
||||
|
||||
class DbVersion(BaseModel):
|
||||
|
||||
@@ -17,7 +17,7 @@ from lnbits.db import Connection, Filters
|
||||
from lnbits.decorators import check_user_extension_access
|
||||
from lnbits.exceptions import InvoiceError, PaymentError, UnsupportedError
|
||||
from lnbits.fiat import get_fiat_provider
|
||||
from lnbits.helpers import check_callback_url
|
||||
from lnbits.helpers import check_callback_url, daystart_timestamp
|
||||
from lnbits.settings import settings
|
||||
from lnbits.task_manager import task_manager
|
||||
from lnbits.utils.crypto import fake_privkey, random_secret_and_hash, verify_preimage
|
||||
@@ -557,10 +557,9 @@ async def check_wallet_daily_withdraw_limit(
|
||||
raise ValueError("It is not allowed to spend funds from this server.")
|
||||
|
||||
payments = await get_payments(
|
||||
since=int(time.time()) - 60 * 60 * 24,
|
||||
since=daystart_timestamp(),
|
||||
outgoing=True,
|
||||
wallet_id=wallet_id,
|
||||
limit=1,
|
||||
conn=conn,
|
||||
)
|
||||
if len(payments) == 0:
|
||||
|
||||
@@ -295,7 +295,10 @@ async def api_create_user_api_token(
|
||||
account.username, api_token_id, data.expiration_time_minutes
|
||||
)
|
||||
|
||||
acl.token_id_list.append(SimpleItem(id=api_token_id, name=data.token_name))
|
||||
expires_at = int(time()) + data.expiration_time_minutes * 60
|
||||
acl.token_id_list.append(
|
||||
SimpleItem(id=api_token_id, name=data.token_name, expires_at=expires_at)
|
||||
)
|
||||
await update_user_access_control_list(acls)
|
||||
return ApiTokenResponse(id=api_token_id, api_token=api_token)
|
||||
|
||||
|
||||
@@ -158,10 +158,6 @@ async def api_update_user(
|
||||
async def api_users_delete_user(
|
||||
user_id: str, account: Account = Depends(check_admin)
|
||||
) -> SimpleStatus:
|
||||
wallets = await get_wallets(user_id, deleted=False)
|
||||
for wallet in wallets:
|
||||
await delete_wallet_by_id(wallet.id)
|
||||
|
||||
if user_id == settings.super_user:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
@@ -173,6 +169,11 @@ async def api_users_delete_user(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Only super_user can delete admin user.",
|
||||
)
|
||||
|
||||
wallets = await get_wallets(user_id, deleted=False)
|
||||
for wallet in wallets:
|
||||
await delete_wallet_by_id(wallet.id)
|
||||
|
||||
await delete_account(user_id)
|
||||
return SimpleStatus(success=True, message="User deleted.")
|
||||
|
||||
|
||||
@@ -372,3 +372,13 @@ def sha256s(value: str) -> str:
|
||||
Returns the hex as a string.
|
||||
"""
|
||||
return hashlib.sha256(value.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
def daystart_timestamp(dt: datetime | None = None) -> int:
|
||||
"""
|
||||
Returns the timestamp of the start of the day for the given
|
||||
datetime (or now in UTC if not provided).
|
||||
"""
|
||||
dt = dt or datetime.now(timezone.utc)
|
||||
day_start = dt.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
return int(day_start.timestamp())
|
||||
|
||||
@@ -27,6 +27,8 @@ from lnbits.settings import set_cli_settings, settings
|
||||
@click.option(
|
||||
"--reload", is_flag=True, default=False, help="Enable auto-reload for development"
|
||||
)
|
||||
@click.option("--ws-max-queue", default=128, help="Websocket max queue size")
|
||||
@click.option("--ws-ping-timeout", default=60.0, help="Websocket ping timeout")
|
||||
def main(
|
||||
port: int,
|
||||
host: str,
|
||||
@@ -34,6 +36,8 @@ def main(
|
||||
ssl_keyfile: str,
|
||||
ssl_certfile: str,
|
||||
reload: bool,
|
||||
ws_max_queue: int,
|
||||
ws_ping_timeout: float,
|
||||
):
|
||||
"""Launched with `uv run lnbits` at root level"""
|
||||
|
||||
@@ -58,6 +62,8 @@ def main(
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
ssl_certfile=ssl_certfile,
|
||||
reload=reload or False,
|
||||
ws_ping_timeout=ws_ping_timeout,
|
||||
ws_max_queue=ws_max_queue,
|
||||
)
|
||||
|
||||
server = uvicorn.Server(config=config)
|
||||
|
||||
@@ -496,6 +496,11 @@ class NotificationsSettings(LNbitsSettings):
|
||||
and self.lnbits_telegram_notifications_access_token is not None
|
||||
)
|
||||
|
||||
def is_email_notifications_configured(self) -> bool:
|
||||
return self.lnbits_email_notifications_enabled and bool(
|
||||
self.lnbits_email_notifications_email
|
||||
)
|
||||
|
||||
|
||||
class FakeWalletFundingSource(LNbitsSettings):
|
||||
fake_wallet_secret: str = Field(default="ToTheMoon1")
|
||||
@@ -1295,6 +1300,7 @@ class PublicSettings(BaseModel):
|
||||
extensions_reviews_url: str = Field(alias="extensionsReviewsUrl")
|
||||
ext_builder: bool = Field(alias="extBuilder")
|
||||
nostr_configured: bool = Field(alias="nostrConfigured")
|
||||
email_configured: bool = Field(alias="emailConfigured")
|
||||
telegram_configured: bool = Field(alias="telegramConfigured")
|
||||
wallet_featured_button_label: str | None = Field(alias="walletFeaturedButtonLabel")
|
||||
wallet_featured_button_url: str | None = Field(alias="walletFeaturedButtonUrl")
|
||||
@@ -1359,6 +1365,7 @@ class PublicSettings(BaseModel):
|
||||
extensionsReviewsUrl=settings.lnbits_extensions_reviews_url,
|
||||
extBuilder=settings.lnbits_extensions_builder_activate_non_admins,
|
||||
nostrConfigured=settings.is_nostr_notifications_configured(),
|
||||
emailConfigured=settings.is_email_notifications_configured(),
|
||||
telegramConfigured=settings.is_telegram_notifications_configured(),
|
||||
walletFeaturedButtonLabel=settings.lnbits_wallet_featured_button_label,
|
||||
walletFeaturedButtonUrl=settings.lnbits_wallet_featured_button_url,
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -482,6 +482,8 @@ window.localisation.en = {
|
||||
access_control_list_admin_warning:
|
||||
'This is an admin account. The generated tokens will have admin privileges.',
|
||||
new_api_acl: 'New Access Control List',
|
||||
acl_token_active: 'Active',
|
||||
acl_token_expired: 'Expired',
|
||||
api_token_id: 'Token Id',
|
||||
toggle_gradient: 'Toggle Gradient',
|
||||
gradient_background: 'Gradient Background',
|
||||
|
||||
@@ -217,6 +217,35 @@ window.PageAccount = {
|
||||
computed: {
|
||||
isUserTouched() {
|
||||
return !_.isEqual(this.g.user, this.untouchedUser)
|
||||
},
|
||||
selectedApiToken() {
|
||||
return this.selectedApiAcl.token_id_list.find(
|
||||
token => token.id === this.apiAcl.selectedTokenId
|
||||
)
|
||||
},
|
||||
expiryAt() {
|
||||
if (this.selectedApiToken.expires_at) {
|
||||
return `${this.$t('expiry')}: ${LNbits.utils.formatTimestamp(this.selectedApiToken.expires_at)}`
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
},
|
||||
tokenStatus() {
|
||||
if (this.selectedApiToken.expires_at) {
|
||||
const now = new Date()
|
||||
const expiresAt = new Date(this.selectedApiToken.expires_at * 1000)
|
||||
let status = ''
|
||||
let badgeColor = 'positive'
|
||||
if (expiresAt < now) {
|
||||
status = this.$t('acl_token_expired')
|
||||
badgeColor = 'negative'
|
||||
} else {
|
||||
status = this.$t('acl_token_active')
|
||||
}
|
||||
return {status, badgeColor}
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -889,6 +889,17 @@
|
||||
></q-btn>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="selectedApiToken && selectedApiToken.expires_at"
|
||||
class="row items-center q-mb-md q-gutter-sm"
|
||||
>
|
||||
<span v-text="expiryAt"></span>
|
||||
<span v-text="$t('status') + ':'"></span>
|
||||
<q-badge
|
||||
:color="tokenStatus.badgeColor"
|
||||
:label="tokenStatus.status"
|
||||
></q-badge>
|
||||
</div>
|
||||
<div v-if="apiAcl.apiToken" class="row q-mb-md">
|
||||
<div class="col-12">
|
||||
<q-badge>
|
||||
|
||||
@@ -1745,10 +1745,14 @@ async def test_api_create_user_api_token_success(
|
||||
), "Expiration time should be 60 minutes from now."
|
||||
|
||||
token_id = payload["api_token_id"]
|
||||
assert any(
|
||||
token_id in [token.id for token in acl.token_id_list]
|
||||
stored_token = next(
|
||||
token
|
||||
for acl in acls.access_control_list
|
||||
), "API token should be part of at least one ACL."
|
||||
for token in acl.token_id_list
|
||||
if token.id == token_id
|
||||
)
|
||||
assert stored_token.expires_at is not None
|
||||
assert abs(stored_token.expires_at - expiration_time) <= 1
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
@@ -1433,7 +1433,7 @@ def test_check_revolut_signature_multiple_v1_headers():
|
||||
check_revolut_signature(payload, sig_header, timestamp, secret)
|
||||
|
||||
|
||||
def test_check_revolut_signature_docs_vector():
|
||||
def test_check_revolut_signature_docs_vector(mocker: MockerFixture):
|
||||
payload = (
|
||||
b'{"data":{"id":"645a7696-22f3-aa47-9c74-cbae0449cc46",'
|
||||
b'"new_state":"completed","old_state":"pending",'
|
||||
@@ -1445,9 +1445,14 @@ def test_check_revolut_signature_docs_vector():
|
||||
secret = "wsk_r59a4HfWVAKycbCaNO1RvgCJec02gRd8"
|
||||
sig = "v1=bca326fb378d0da7f7c490ad584a8106bab9723d8d9cdd0d50b4c5b3be3837c0"
|
||||
|
||||
check_revolut_signature(
|
||||
payload, sig, timestamp, secret, tolerance_seconds=100000000
|
||||
# This is a fixed vector straight from Revolut's docs, so its timestamp is
|
||||
# necessarily in the past. Freeze time to it instead of growing
|
||||
# tolerance_seconds indefinitely as real time marches on.
|
||||
mocker.patch(
|
||||
"lnbits.core.services.fiat_providers.time.time",
|
||||
return_value=int(timestamp) / 1000,
|
||||
)
|
||||
check_revolut_signature(payload, sig, timestamp, secret)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
@@ -27,6 +27,7 @@ from lnbits.core.services.payments import (
|
||||
check_pending_payments,
|
||||
check_time_limit_between_transactions,
|
||||
check_transaction_status,
|
||||
check_wallet_daily_withdraw_limit,
|
||||
check_wallet_limits,
|
||||
create_payment_request,
|
||||
get_payments_daily_stats,
|
||||
@@ -248,6 +249,23 @@ async def test_check_wallet_limits_and_time_limit(
|
||||
settings.lnbits_wallet_limit_secs_between_trans = original_limit
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_check_wallet_daily_limit_counts_all_daily_payments(settings: Settings):
|
||||
wallet = await _create_wallet()
|
||||
await _create_payment(wallet, amount_msat=-2_000, status=PaymentState.SUCCESS)
|
||||
await _create_payment(wallet, amount_msat=-3_000, status=PaymentState.SUCCESS)
|
||||
|
||||
original_limit = settings.lnbits_wallet_limit_daily_max_withdraw
|
||||
try:
|
||||
settings.lnbits_wallet_limit_daily_max_withdraw = 5
|
||||
with pytest.raises(
|
||||
ValueError, match="Daily withdrawal limit of 5 sats reached."
|
||||
):
|
||||
await check_wallet_daily_withdraw_limit(wallet.id, 1_000)
|
||||
finally:
|
||||
settings.lnbits_wallet_limit_daily_max_withdraw = original_limit
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_calculate_fiat_amounts_handles_conversion_and_errors(
|
||||
mocker: MockerFixture,
|
||||
|
||||
Reference in New Issue
Block a user