diff --git a/CHANGELOG.md b/CHANGELOG.md index d5ed0e7..9131e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Added support for demodulating M17 digital voice signals using m17-cxx-demod - New reporting infrastructure, allowing WSPR and FST4W spots to be sent to wsprnet.org - Add some basic filtering capabilities to the map -- New command-line tool `openwebrx-admin` that facilitates the administration of users +- New arguments to the `openwebrx` command-line to facilitate the administration of users (try `openwebrx admin`) - Default bandwidth changes: - "WFM" changed to 150kHz - "Packet" (APRS) changed to 12.5kHz diff --git a/debian/changelog b/debian/changelog index 2b61b7c..2211957 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,8 @@ openwebrx (0.21.0) UNRELEASED; urgency=low * New reporting infrastructure, allowing WSPR and FST4W spots to be sent to wsprnet.org * Add some basic filtering capabilities to the map + * New arguments to the `openwebrx` command-line to facilitate the + administration of users (try `openwebrx admin`) * New command-line tool `openwebrx-admin` that facilitates the administration of users * Default bandwidth changes: diff --git a/debian/openwebrx.config b/debian/openwebrx.config index 9e9a6dc..500fb0a 100755 --- a/debian/openwebrx.config +++ b/debian/openwebrx.config @@ -1,7 +1,8 @@ #!/bin/sh -e . /usr/share/debconf/confmodule -if ! openwebrx-admin --silent hasuser admin; then +db_get openwebrx/admin_user_configured +if [ "${RET}" != true ]; then db_input high openwebrx/admin_user_password || true db_go fi diff --git a/debian/openwebrx.postinst b/debian/openwebrx.postinst index 8b98999..ba24ebb 100755 --- a/debian/openwebrx.postinst +++ b/debian/openwebrx.postinst @@ -26,10 +26,12 @@ case "$1" in db_get openwebrx/admin_user_password if [ ! -z "${RET}" ]; then # create initial openwebrx user - OWRX_PASSWORD="${RET}" openwebrx-admin --noninteractive adduser admin + OWRX_PASSWORD="${RET}" openwebrx admin --noninteractive adduser admin fi # remove password from debconf database db_unregister openwebrx/admin_user_password + # set a marker that admin is configured to avoid future questions + db_set openwebrx/admin_user_configured true ;; *) echo "postinst called with unknown argument '$1'" 1>&2 diff --git a/debian/openwebrx.templates b/debian/openwebrx.templates index 484e143..f69e47b 100644 --- a/debian/openwebrx.templates +++ b/debian/openwebrx.templates @@ -11,6 +11,6 @@ Description: OpenWebRX "admin" user password: empty for now. You can return to this prompt at a later time by running the command "sudo dpkg-reconfigure openwebrx". . - You can also use the "openwebrx-admin" command to create, delete or manage + You can also use the "openwebrx admin" command to create, delete or manage existing users. More information is available in by running the command - "openwebrx-admin --help". \ No newline at end of file + "openwebrx admin --help". \ No newline at end of file diff --git a/docker/scripts/run.sh b/docker/scripts/run.sh index 627a12e..cde6fdf 100755 --- a/docker/scripts/run.sh +++ b/docker/scripts/run.sh @@ -17,8 +17,8 @@ if [[ ! -f /etc/openwebrx/openwebrx.conf ]] ; then cp openwebrx.conf /etc/openwebrx/ fi if [[ ! -z "${OPENWEBRX_ADMIN_USER:-}" ]] && [[ ! -z "${OPENWEBRX_ADMIN_PASSWORD:-}" ]] ; then - if ! python3 openwebrx-admin.py --silent hasuser "${OPENWEBRX_ADMIN_USER}" ; then - OWRX_PASSWORD="${OPENWEBRX_ADMIN_PASSWORD}" python3 openwebrx-admin.py --noninteractive adduser "${OPENWEBRX_ADMIN_USER}" + if ! python3 openwebrx.py admin --silent hasuser "${OPENWEBRX_ADMIN_USER}" ; then + OWRX_PASSWORD="${OPENWEBRX_ADMIN_PASSWORD}" python3 openwebrx.py admin --noninteractive adduser "${OPENWEBRX_ADMIN_USER}" fi fi diff --git a/openwebrx-admin.py b/openwebrx-admin.py deleted file mode 100755 index c1f6caa..0000000 --- a/openwebrx-admin.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python3 - -from owrxadmin.__main__ import main - -if __name__ == "__main__": - main() diff --git a/owrx/__main__.py b/owrx/__main__.py index 26ac4c8..b7c00e8 100644 --- a/owrx/__main__.py +++ b/owrx/__main__.py @@ -10,7 +10,9 @@ from owrx.websocket import WebSocketConnection from owrx.reporting import ReportingEngine from owrx.version import openwebrx_version from owrx.audio.queue import DecoderQueue +from owrx.admin import add_admin_parser, run_admin_action import signal +import argparse import logging @@ -31,6 +33,26 @@ def handleSignal(sig, frame): def main(): + parser = argparse.ArgumentParser(description="OpenWebRX - Open Source SDR Web App for Everyone!") + parser.add_argument("-v", "--version", action="store_true", help="Show the software version") + + moduleparser = parser.add_subparsers(title="Modules", dest="module") + adminparser = moduleparser.add_parser("admin", help="OpenWebRX admin actions") + add_admin_parser(adminparser) + + args = parser.parse_args() + + if args.version: + print("OpenWebRX version {version}".format(version=openwebrx_version)) + elif args.module == "admin": + # override loglevel for admin commands, they shouldn't be that verbose + logging.basicConfig(level=logging.INFO, force=True) + run_admin_action(adminparser, args) + else: + start_receiver() + + +def start_receiver(): print( """ diff --git a/owrxadmin/__main__.py b/owrx/admin/__init__.py similarity index 71% rename from owrxadmin/__main__.py rename to owrx/admin/__init__.py index 36f7b6e..dc5410d 100644 --- a/owrxadmin/__main__.py +++ b/owrx/admin/__init__.py @@ -1,16 +1,10 @@ -from owrx.version import openwebrx_version -from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser, HasUser -import argparse +from owrx.admin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser, HasUser import sys import traceback -import logging - -logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") -def main(): - parser = argparse.ArgumentParser() - subparsers = parser.add_subparsers(title="Commands", dest="command") +def add_admin_parser(moduleparser): + subparsers = moduleparser.add_subparsers(title="Commands", dest="command") adduser_parser = subparsers.add_parser("adduser", help="Add a new user") adduser_parser.add_argument("user", help="Username to be added") @@ -40,17 +34,12 @@ def main(): hasuser_parser.add_argument("user", help="Username to be checked") hasuser_parser.set_defaults(cls=HasUser) - parser.add_argument("-v", "--version", action="store_true", help="Show the software version") - parser.add_argument( + moduleparser.add_argument( "--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)" ) - parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)") - args = parser.parse_args() - - if args.version: - print("OpenWebRX Admin CLI version {version}".format(version=openwebrx_version)) - sys.exit(0) + moduleparser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)") +def run_admin_action(parser, args): if hasattr(args, "cls"): command = args.cls() else: @@ -67,3 +56,4 @@ def main(): traceback.print_exc() sys.exit(1) sys.exit(0) + diff --git a/owrxadmin/commands.py b/owrx/admin/commands.py similarity index 100% rename from owrxadmin/commands.py rename to owrx/admin/commands.py diff --git a/setup.py b/setup.py index 8373ffd..4315a25 100644 --- a/setup.py +++ b/setup.py @@ -24,13 +24,13 @@ setup( "owrx.config", "owrx.reporting", "owrx.audio", + "owrx.admin", "csdr", "htdocs", - "owrxadmin", ] ), package_data={"htdocs": [f[len("htdocs/") :] for f in glob("htdocs/**/*", recursive=True)]}, - entry_points={"console_scripts": ["openwebrx=owrx.__main__:main", "openwebrx-admin=owrxadmin.__main__:main"]}, + entry_points={"console_scripts": ["openwebrx=owrx.__main__:main"]}, url="https://www.openwebrx.de/", author="Jakob Ketterl", author_email="jakob.ketterl@gmx.de",