diff --git a/.gitignore b/.gitignore index 488f8a776..b75f0c9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ django.db celerybeat-schedule.db data/static docs/_build/ +xpack diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index ff69c9621..49b2f7870 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -78,6 +78,12 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', ] + +XPACK_DIR = os.path.join(BASE_DIR, 'xpack') +XPACK_ENABLED = os.path.isdir(XPACK_DIR) +if XPACK_ENABLED: + INSTALLED_APPS.append('xpack.apps.XpackConfig') + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -94,10 +100,30 @@ MIDDLEWARE = [ ROOT_URLCONF = 'jumpserver.urls' + +def get_xpack_context_processor(): + if XPACK_ENABLED: + return ['xpack.context_processor.xpack_processor'] + return [] + + +def get_xpack_templates_dir(): + if XPACK_ENABLED: + dirs = [] + from xpack.utils import find_enabled_plugins + for i in find_enabled_plugins(): + template_dir = os.path.join(BASE_DIR, 'xpack', 'plugins', i, 'templates') + if os.path.isdir(template_dir): + dirs.append(template_dir) + return dirs + else: + return [] + + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates'), ], + 'DIRS': [os.path.join(BASE_DIR, 'templates'), *get_xpack_templates_dir()], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -111,6 +137,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.template.context_processors.media', 'orgs.context_processor.org_processor', + *get_xpack_context_processor(), ], }, }, diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index 06034865c..b0c30b575 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -1,6 +1,7 @@ # ~*~ coding: utf-8 ~*~ from __future__ import unicode_literals import re +import os from django.urls import path, include, re_path from django.conf import settings @@ -74,6 +75,10 @@ app_view_patterns = [ path('orgs/', include('orgs.urls.views_urls', namespace='orgs')), ] +XPACK_DIR = os.path.join(settings.BASE_DIR, 'xpack') +if os.path.isdir(XPACK_DIR): + app_view_patterns.append(path('xpack/', include('xpack.urls', namespace='xpack'))) + urlpatterns = [ path('', IndexView.as_view(), name='index'), diff --git a/apps/templates/_nav.html b/apps/templates/_nav.html index 772c9db78..be9633054 100644 --- a/apps/templates/_nav.html +++ b/apps/templates/_nav.html @@ -80,6 +80,18 @@ {#