diff --git a/config/asgi.py b/config/asgi.py index 5fd82ade5660b563438daefc34dbbd18d8d03e68..631349c0159d2429799831ade8dc8e1152b7a652 100644 --- a/config/asgi.py +++ b/config/asgi.py @@ -8,9 +8,16 @@ https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/ """ import os - +from channels.auth import AuthMiddlewareStack +from config.urls import websocket_urlpatterns +from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') -application = get_asgi_application() +application = ProtocolTypeRouter({ + "http": get_asgi_application(), + 'websocket': AuthMiddlewareStack( + URLRouter(websocket_urlpatterns) + ), +}) diff --git a/config/settings.py b/config/settings.py index 527712371ae02c250a59e6b710a1110854187610..3a3ea47b1485e450214ab79d5db1a9ab922e5832 100644 --- a/config/settings.py +++ b/config/settings.py @@ -15,6 +15,10 @@ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +SSHKEY_PATH = os.path.join(BASE_DIR, '.ssh') + +if not os.path.isdir(SSHKEY_PATH): + os.makedirs(SSHKEY_PATH) # Quick-start development settings - unsuitable for production @@ -32,6 +36,7 @@ ALLOWED_HOSTS = [ "*" ] # Application definition INSTALLED_APPS = [ + 'daphne', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -39,6 +44,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'webssh.apps.WebsshConfig', + 'channels', ] MIDDLEWARE = [ @@ -72,6 +78,8 @@ TEMPLATES = [ }, ] +ASGI_APPLICATION = 'config.asgi.application' + WSGI_APPLICATION = 'config.wsgi.application' @@ -131,10 +139,9 @@ STATICFILES_DIRS = [ BASE_DIR / "webssh/static", ] -# 设置媒体路由 +# Media files (mp4, avi) MEDIA_URL = 'media/' -# 设置media目录的完整路径 MEDIA_ROOT = BASE_DIR / 'media' # Default primary key field type diff --git a/config/urls.py b/config/urls.py index 45675714bd16ceddda71f1c49c74ceafd916776f..df1f364294da75c59c66e9b232c2e1aa464f4faf 100644 --- a/config/urls.py +++ b/config/urls.py @@ -14,12 +14,18 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +import webssh.views from django.contrib import admin from django.urls import path, re_path, include from django.views.generic import RedirectView -import webssh.views +from webssh.websocket import WebSSH urlpatterns = [ path('admin/', admin.site.urls), + path('index/', webssh.views.index), path('webssh/', include(('webssh.urls', 'webssh'), namespace='webssh')), ] + +websocket_urlpatterns = [ + path('ws/', WebSSH.as_asgi()), +] diff --git a/manage.py b/manage.py index 0336a527951de98541b0835567a612eb97879bbc..3fce01b3d602779d4cbed82ed4c34c8897537170 100755 --- a/manage.py +++ b/manage.py @@ -4,7 +4,6 @@ import os import sys from django.core.management.commands.runserver import Command as Runserver - def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') @@ -18,7 +17,6 @@ def main(): ) from exc execute_from_command_line(sys.argv) - if __name__ == '__main__': Runserver.default_addr = '192.168.3.50' Runserver.default_port = '8099' diff --git a/static/bootbox/5.4.0/bootbox.min.js b/static/bootbox/5.4.0/bootbox.min.js new file mode 100644 index 0000000000000000000000000000000000000000..8b8a0197259eade7da8f97f355f2d384976b2d49 --- /dev/null +++ b/static/bootbox/5.4.0/bootbox.min.js @@ -0,0 +1 @@ +!function(t,e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):t.bootbox=e(t.jQuery)}(this,function e(p,u){"use strict";var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable("toString"),l=(i=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"]).length,function(t){if("function"!=typeof t&&("object"!=typeof t||null===t))throw new TypeError("Object.keys called on non-object");var e,o,a=[];for(e in t)r.call(t,e)&&a.push(e);if(n)for(o=0;o