Package: django-admin-shellx
Django Admin ShellA Django Web Shell using Xterm.js and Django Channels.Note: This package depends on websockets therefore you'll need to use an ASGI application to use it. If you are not using Django channels then read through the officialChannels' documentation on installing Channels, also see theChannels' documentation on running ASGI applications.FeaturesFully responsive terminal using Xterm.js.Accessible through the admin.Authentication with Django auth, configurable to allow only superusers.The commands written are tied to a user.Saves command in a new model and create favorite commands.Filterable command history.LogEntry of all commands ran.Custom admin site to add Terminal links to the admin.InstallationInstall the package using pip:pipinstalldjango-admin-shellxAdddjango_admin_shellx,channelsordaphneanddjango_admin_shellx_custom_adminto yourINSTALLED_APPS:INSTALLED_APPS=['daphne',# If you are using daphne, import it first# ...'django_admin_shellx',# ...]Add your ASGI application to your settings:ASGI_APPLICATION="config.asgi.application"# OptionalCHANNEL_LAYERS={"default":{"BACKEND":"channels_redis.core.RedisChannelLayer","CONFIG":{"hosts":[env("REDIS_URL")],},},}Since the package uses websockets you'll need to add the url patterns to your ASGI application:...fromdjango_admin_shellx.urlsimportwebsocket_urlpatterns# pylint: disable=unused-import,wrong-import-positionimportdjango_admin_shellx.urlsapplication=ProtocolTypeRouter({"http":django_asgi_app,"websocket":AllowedHostsOriginValidator(AuthMiddlewareStack(URLRouter(websocket_urlpatterns))),})If you do not have an ASGI application, you'll need to create one. You can use thechannelspackage to do so:# settings/asgi.pyimportosfromchannels.authimportAuthMiddlewareStackfromchannels.routingimportProtocolTypeRouter,URLRouterfromchannels.security.websocketimportAllowedHostsOriginValidatorfromdjango.core.asgiimportget_asgi_applicationfromdjango_admin_shellx.urlsimportwebsocket_urlpatternsos.environ.setdefault("DJANGO_SETTINGS_MODULE","tests.settings")# Initialize Django ASGI application early to ensure the AppRegistry# is populated before importing code that may import ORM models.django_asgi_app=get_asgi_application()# pylint: disable=unused-import,wrong-import-positionimportdjango_admin_shellx.urlsapplication=ProtocolTypeRouter({"http":django_asgi_app,"websocket":AllowedHostsOriginValidator(AuthMiddlewareStack(URLRouter(websocket_urlpatterns))),})Note: Daphne replacesrunserverto run as a ASGI application. If you are using Daphne, you'll need to import it first in your ASGI application.Lastly, we'll need to use a custom admin site to add terminal links to the admin, add the following to yourINSTALLED_APPS:installed_apps=[...'django_admin_shellx_custom_admin.apps.DjangoAdminShellXCustomAdminConfig',]The above is optional and only adds aviewbutton to the admin that links to the terminal. Otherwise, there will not be a link since it's not a model and can not be added to the admin. The terminal will either be accessible through the path/admin/django_admin_shellx/terminalcommand/terminal/and if you use the custom admin site, it will be accessible through a link in the admin.UsageHead over to the admin and click on theTerminallink. You'll be presented with a terminal that you can use to run commands. The default commands are./manage.py shell_plus,./manage.py shelland/bin/bash. You can change the default commands by setting theDJANGO_ADMIN_SHELLX_COMMANDsetting.Each command is saved in the database and can be accessed through the admin. You can also add new commands through the admin and favorite existing commands. Each command ran is also saved as aLogEntry.ASGI NotesAs mentioned previously, read through the officialChannels' documentation on installing Channels, also see theChannels' documentation on running ASGI applications. I'll add small snippets to help you get started.In the guide abovedaphneis used as the ASGI application and this will replace the commandrunserverto run as a ASGI application. In production, you'll need to rundaphneinstead ofgunicornto use the websockets. An example is shown below:daphneconfig.asgi:application-b127.0.0.1-p80Alternatively, you can run your ASGI application on a separate port and run your WSGI application as per default.daphneconfig.asgi:application-b127.0.0.1-p8001gunicorn-b127.0.0.1:80config.wsgiYou can also replacedaphnewithchannelsif you want to for example userunserver_pluswhich does not work withdaphne. Then, you'll need to run both an ASGI and WSGI application locally../manage.pyrunserver-p8000daphneconfig.asgi:application-b127.0.0.1-p8001SettingsNameDescriptionTypeDefaultRequiredDJANGO_ADMIN_SHELLX_SUPERUSER_ONLYAllow only SuperUsers to access the admin shellx.booleanTruenoDJANGO_ADMIN_SHELLX_COMMANDThe default commands to use when opening the terminal.list[list[str]][["./manage.py", "shell_plus"], ["./manage.py", "shell"], ["/bin/bash"]]noDJANGO_ADMIN_SHELLX_WS_PORTThe port to use for the websocket.intNoneno