From 459d0668a8bef290c49a81c6eb07223b1278102e Mon Sep 17 00:00:00 2001 From: liuzheng Date: Mon, 26 Feb 2018 15:06:00 +0800 Subject: [PATCH] feat: replay setting page and api --- apps/common/api.py | 3 +- apps/common/forms.py | 10 +- .../templates/common/terminal_setting.html | 128 +++++++++++------- apps/common/views.py | 3 + apps/jumpserver/settings.py | 18 ++- 5 files changed, 98 insertions(+), 64 deletions(-) diff --git a/apps/common/api.py b/apps/common/api.py index eb108e94e..e93844988 100644 --- a/apps/common/api.py +++ b/apps/common/api.py @@ -9,7 +9,7 @@ from django.core.mail import get_connection, send_mail from django.utils.translation import ugettext_lazy as _ from django.conf import settings -from .permissions import IsSuperUser +from .permissions import IsSuperUser, IsAppUser from .serializers import MailTestSerializer, LDAPTestSerializer @@ -102,4 +102,3 @@ class DjangoSettingsAPI(APIView): if i.isupper(): configs[i] = str(getattr(settings, i)) return Response(configs) - diff --git a/apps/common/forms.py b/apps/common/forms.py index 882a7ab7a..0d0f057cf 100644 --- a/apps/common/forms.py +++ b/apps/common/forms.py @@ -127,7 +127,8 @@ class LDAPSettingForm(BaseForm): "name": "sn", "email": "mail" }), - help_text=_("User attr map present how to map LDAP user attr to jumpserver, username,name,email is jumpserver attr") + help_text=_( + "User attr map present how to map LDAP user attr to jumpserver, username,name,email is jumpserver attr") ) # AUTH_LDAP_GROUP_SEARCH_OU = CONFIG.AUTH_LDAP_GROUP_SEARCH_OU # AUTH_LDAP_GROUP_SEARCH_FILTER = CONFIG.AUTH_LDAP_GROUP_SEARCH_FILTER @@ -160,3 +161,10 @@ class TerminalSettingForm(BaseForm): "You can set other storage and some terminal using" ) ) + TERMINAL_REPLAY_STORAGE = DictField( + label=_("Replay storage"), help_text=_( + "Set replay storage setting, `default` is the using as default," + "You can set other storage and some terminal using" + ) + ) + diff --git a/apps/common/templates/common/terminal_setting.html b/apps/common/templates/common/terminal_setting.html index c15ff4bc7..881dd6343 100644 --- a/apps/common/templates/common/terminal_setting.html +++ b/apps/common/templates/common/terminal_setting.html @@ -12,27 +12,31 @@
-
-
+
+ {% if form.non_field_errors %} -
- {{ form.non_field_errors }} -
+
+ {{ form.non_field_errors }} +
{% endif %} {% csrf_token %}

{% trans "Basic setting" %}

@@ -41,13 +45,14 @@ {% bootstrap_field field layout="horizontal" %} {% else %}
- +
{{ field }}
- {{ field.help_text }} + {{ field.help_text }}
@@ -56,12 +61,12 @@

{% trans "Command storage" %}

- +
- - - - + + + + {% for name, setting in command_storage.items %} @@ -72,19 +77,38 @@ {% endfor %}
{% trans 'Name' %}{% trans 'Type' %}
{% trans 'Name' %}{% trans 'Type' %}
-{# #} -{#
#} -{#

{% trans "Replay storage" %}

#} - + {# #} + {#
#} + {#

{% trans "Replay storage" %}

#} +
+

{% trans "Replay storage" %}

+ + + + + + + + + + {% for name, setting in replay_storage.items %} + + + + + + {% endfor %} + +
{% trans 'Name' %}{% trans 'Type' %}{% trans 'Setting' %}
{{ name }}{{ setting.TYPE }}{{ setting }}
- +
- -
+
@@ -92,38 +116,40 @@ + {% endblock %} {% block custom_foot_js %} - + APIUpdateAttr({ + url: the_url, + body: JSON.stringify(data), + method: "POST", + flash_message: false, + success: success, + error: error + }); + }) + .on('click', '', function () { + + }) + {% endblock %} diff --git a/apps/common/views.py b/apps/common/views.py index dc0d74f92..99b924423 100644 --- a/apps/common/views.py +++ b/apps/common/views.py @@ -97,10 +97,12 @@ class TerminalSettingView(AdminUserRequiredMixin, TemplateView): def get_context_data(self, **kwargs): command_storage = settings.TERMINAL_COMMAND_STORAGE + replay_storage = settings.TERMINAL_REPLAY_STORAGE context = { 'app': _('Settings'), 'action': _('Terminal setting'), 'form': self.form_class(), + 'replay_storage': replay_storage, 'command_storage': command_storage, } kwargs.update(context) @@ -117,3 +119,4 @@ class TerminalSettingView(AdminUserRequiredMixin, TemplateView): context = self.get_context_data() context.update({"form": form}) return render(request, self.template_name, context) + diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 77dd8e114..8151147d2 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -17,7 +17,6 @@ import ldap from django_auth_ldap.config import LDAPSearch from django.urls import reverse_lazy - # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_DIR = os.path.dirname(BASE_DIR) @@ -39,11 +38,9 @@ SECRET_KEY = CONFIG.SECRET_KEY # SECURITY WARNING: don't run with debug turned on in production! DEBUG = CONFIG.DEBUG or False - # Absolute url for some case, for example email link SITE_URL = CONFIG.SITE_URL or 'http://localhost' - # LOG LEVEL LOG_LEVEL = 'DEBUG' if DEBUG else CONFIG.LOG_LEVEL or 'WARNING' @@ -114,7 +111,7 @@ LOGIN_URL = reverse_lazy('users:login') SESSION_COOKIE_DOMAIN = CONFIG.SESSION_COOKIE_DOMAIN or None CSRF_COOKIE_DOMAIN = CONFIG.CSRF_COOKIE_DOMAIN or None -SESSION_COOKIE_AGE = CONFIG.SESSION_COOKIE_AGE or 3600*24 +SESSION_COOKIE_AGE = CONFIG.SESSION_COOKIE_AGE or 3600 * 24 MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' # Database @@ -250,7 +247,6 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(PROJECT_DIR, "data", "static") STATIC_DIR = os.path.join(BASE_DIR, "static") - STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) @@ -265,7 +261,7 @@ MEDIA_ROOT = os.path.join(PROJECT_DIR, 'data', 'media').replace('\\', '/') + '/' # BOOTSTRAP_COLUMN_COUNT = 11 # Init data or generate fake data source for development -FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'),] +FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'), ] # Email config EMAIL_HOST = CONFIG.EMAIL_HOST @@ -308,7 +304,6 @@ AUTHENTICATION_BACKENDS = [ # Custom User Auth model AUTH_USER_MODEL = 'users.User' - # Auth LDAP settings AUTH_LDAP = CONFIG.AUTH_LDAP AUTH_LDAP_SERVER_URI = CONFIG.AUTH_LDAP_SERVER_URI @@ -319,7 +314,7 @@ AUTH_LDAP_SEARCH_FILTER = CONFIG.AUTH_LDAP_SEARCH_FILTER AUTH_LDAP_START_TLS = CONFIG.AUTH_LDAP_START_TLS AUTH_LDAP_USER_ATTR_MAP = CONFIG.AUTH_LDAP_USER_ATTR_MAP AUTH_LDAP_USER_SEARCH = LDAPSearch( - AUTH_LDAP_SEARCH_OU, ldap.SCOPE_SUBTREE, AUTH_LDAP_SEARCH_FILTER, + AUTH_LDAP_SEARCH_OU, ldap.SCOPE_SUBTREE, AUTH_LDAP_SEARCH_FILTER, ) AUTH_LDAP_GROUP_SEARCH_OU = CONFIG.AUTH_LDAP_GROUP_SEARCH_OU AUTH_LDAP_GROUP_SEARCH_FILTER = CONFIG.AUTH_LDAP_GROUP_SEARCH_FILTER @@ -332,7 +327,6 @@ AUTH_LDAP_BACKEND = 'django_auth_ldap.backend.LDAPBackend' if AUTH_LDAP: AUTHENTICATION_BACKENDS.insert(0, AUTH_LDAP_BACKEND) - # Celery using redis as broker CELERY_BROKER_URL = 'redis://:%(password)s@%(host)s:%(port)s/3' % { 'password': CONFIG.REDIS_PASSWORD if CONFIG.REDIS_PASSWORD else '', @@ -354,7 +348,6 @@ CELERY_REDIRECT_STDOUTS = True CELERY_REDIRECT_STDOUTS_LEVEL = "INFO" CELERY_WORKER_HIJACK_ROOT_LOGGER = False - # Cache use redis CACHES = { 'default': { @@ -387,6 +380,11 @@ TERMINAL_COMMAND_STORAGE = { # }, } +TERMINAL_REPLAY_STORAGE = { + "default": { + "TYPE": "server", + }, +} # Django bootstrap3 setting, more see http://django-bootstrap3.readthedocs.io/en/latest/settings.html BOOTSTRAP3 = {