diff --git a/.gitignore b/.gitignore index a314fc974..5b3ab4252 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,6 @@ tests/data/*.sqlite3 *.pyc *.env .env -.super_user .pre-commit-config.yaml data diff --git a/lnbits/commands.py b/lnbits/commands.py index a8471fe17..f8f396dc6 100644 --- a/lnbits/commands.py +++ b/lnbits/commands.py @@ -1,4 +1,5 @@ import asyncio +from pathlib import Path import click from loguru import logger @@ -20,11 +21,22 @@ def command_group(): """ +def get_super_user() -> str: + """Get the superuser""" + with open(Path(settings.lnbits_data_folder) / ".super_user", "r") as file: + return file.readline() + + @click.command("superuser") def superuser(): """Prints the superuser""" - with open(".super_user", "r") as file: - print(f"http://{settings.host}:{settings.port}/wallet?usr={file.readline()}") + click.echo(get_super_user()) + + +@click.command("superuser-url") +def superuser_url(): + """Prints the superuser""" + click.echo(f"http://{settings.host}:{settings.port}/wallet?usr={get_super_user()}") @click.command("delete-settings") @@ -101,6 +113,7 @@ async def load_disabled_extension_list() -> None: def main(): """main function""" command_group.add_command(superuser) + command_group.add_command(superuser_url) command_group.add_command(delete_settings) command_group.add_command(database_migrate) command_group.add_command(database_versions) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index a0cebe3fc..7d5082106 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -1,6 +1,7 @@ import asyncio import json from io import BytesIO +from pathlib import Path from typing import Dict, List, Optional, Tuple, TypedDict from urllib.parse import parse_qs, urlparse @@ -528,11 +529,8 @@ async def check_admin_settings(): update_cached_settings(settings_db.dict()) - admin_url = f'{settings.lnbits_baseurl}wallet?usr=' - logger.success(f"✔️ Access super user account at: {admin_url}") - - # saving it to .super_user file - with open(".super_user", "w") as file: + # saving superuser to {data_dir}/.super_user file + with open(Path(settings.lnbits_data_folder) / ".super_user", "w") as file: file.write(settings.super_user) # callback for saas @@ -543,6 +541,11 @@ async def check_admin_settings(): ): send_admin_user_to_saas() + logger.success( + "✔️ Admin UI is enabled. run `poetry run lnbits-cli superuser` " + "to get the superuser." + ) + def update_cached_settings(sets_dict: dict): for key, value in sets_dict.items():