jumpserver/apps/settings/views.py

179 lines
6.0 KiB
Python
Raw Normal View History

2018-07-23 04:55:13 +00:00
from django.views.generic import TemplateView
from django.shortcuts import render, redirect
2018-01-11 12:10:27 +00:00
from django.contrib import messages
from django.utils.translation import ugettext as _
2016-09-03 11:05:50 +00:00
from common.permissions import PermissionsMixin, IsSuperUser
from .utils import LDAPSyncUtil
2018-01-20 14:22:09 +00:00
from .forms import EmailSettingForm, LDAPSettingForm, BasicSettingForm, \
TerminalSettingForm, SecuritySettingForm, EmailContentSettingForm
2018-01-11 12:10:27 +00:00
class BasicSettingView(PermissionsMixin, TemplateView):
2018-01-12 07:43:26 +00:00
form_class = BasicSettingForm
template_name = "settings/basic_setting.html"
permission_classes = [IsSuperUser]
2018-01-12 07:43:26 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Settings'),
'action': _('Basic setting'),
'form': self.form_class(),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
2018-01-15 05:54:19 +00:00
messages.success(request, msg)
2018-01-12 07:43:26 +00:00
return redirect('settings:basic-setting')
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)
class EmailSettingView(PermissionsMixin, TemplateView):
2018-01-11 12:10:27 +00:00
form_class = EmailSettingForm
template_name = "settings/email_setting.html"
permission_classes = [IsSuperUser]
2018-01-11 12:10:27 +00:00
2018-01-12 07:43:26 +00:00
def get_context_data(self, **kwargs):
2018-01-11 12:10:27 +00:00
context = {
2018-01-12 07:43:26 +00:00
'app': _('Settings'),
'action': _('Email setting'),
'form': self.form_class(),
2018-01-11 12:10:27 +00:00
}
2018-01-12 07:43:26 +00:00
kwargs.update(context)
return super().get_context_data(**kwargs)
2018-01-11 12:10:27 +00:00
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
2018-01-15 05:54:19 +00:00
messages.success(request, msg)
2018-01-12 07:43:26 +00:00
return redirect('settings:email-setting')
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)
2018-01-11 12:10:27 +00:00
class LDAPSettingView(PermissionsMixin, TemplateView):
2018-01-12 07:43:26 +00:00
form_class = LDAPSettingForm
template_name = "settings/ldap_setting.html"
permission_classes = [IsSuperUser]
2018-01-12 07:43:26 +00:00
def get_context_data(self, **kwargs):
2018-01-11 12:10:27 +00:00
context = {
2018-01-12 07:43:26 +00:00
'app': _('Settings'),
'action': _('LDAP setting'),
'form': self.form_class(),
2018-01-11 12:10:27 +00:00
}
2018-01-12 07:43:26 +00:00
kwargs.update(context)
return super().get_context_data(**kwargs)
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
2018-01-15 05:54:19 +00:00
messages.success(request, msg)
LDAPSyncUtil().clear_cache()
2018-01-12 07:43:26 +00:00
return redirect('settings:ldap-setting')
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)
2018-01-17 09:17:18 +00:00
class TerminalSettingView(PermissionsMixin, TemplateView):
2018-01-20 14:22:09 +00:00
form_class = TerminalSettingForm
template_name = "settings/terminal_setting.html"
permission_classes = [IsSuperUser]
2018-01-17 09:17:18 +00:00
def get_context_data(self, **kwargs):
Config (#3502) * [Update] 修改config * [Update] 移动存储设置到到terminal中 * [Update] 修改permission 查看 * [Update] pre merge * [Update] 录像存储 * [Update] 命令存储 * [Update] 添加存储测试可连接性 * [Update] 修改 meta 值的 key 为大写 * [Update] 修改 Terminal 相关 Storage 配置 * [Update] 删除之前获取录像/命令存储的代码 * [Update] 修改导入失败 * [Update] 迁移文件添加default存储 * [Update] 删除之前代码,添加help_text信息 * [Update] 删除之前代码 * [Update] 删除之前代码 * [Update] 抽象命令/录像存储 APIView * [Update] 抽象命令/录像存储 APIView 1 * [Update] 抽象命令/录像存储 DictField * [Update] 抽象命令/录像存储列表页面 * [Update] 修复CustomDictField的bug * [Update] RemoteApp 页面添加 hidden * [Update] 用户页面添加用户关联授权 * [Update] 修改存储测试可连接性 target * [Update] 修改配置 * [Update] 修改存储前端 Form 渲染逻辑 * [Update] 修改存储细节 * [Update] 统一存储类型到 const 文件 * [Update] 修改迁移文件及Model,创建默认存储 * [Update] 修改迁移文件及Model初始化默认数据 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 限制删除默认存储配置,只允许创建扩展的存储类型 * [Update] 修改ip字段长度 * [Update] 修改ip字段长度 * [Update] 修改一些css * [Update] 修改关联 * [Update] 添加操作日志定时清理 * [Update] 修改记录syslog的instance encoder * [Update] 忽略登录产生的操作日志 * [Update] 限制更新存储时不覆盖原有AK SK 等字段 * [Update] 修改迁移文件添加comment字段 * [Update] 修改迁移文件 * [Update] 添加 comment 字段 * [Update] 修改默认存储no -> null * [Update] 修改细节 * [Update] 更新翻译(存储配置 * [Update] 修改定时任务注册,修改系统用户资产、节点关系api * [Update] 添加监控磁盘任务 * [Update] 修改session * [Update] 拆分serializer * [Update] 还原setting原来的manager
2019-12-05 07:09:25 +00:00
from terminal.models import CommandStorage, ReplayStorage
command_storage = CommandStorage.objects.all()
replay_storage = ReplayStorage.objects.all()
2018-01-17 09:17:18 +00:00
context = {
'app': _('Settings'),
2018-01-20 14:22:09 +00:00
'action': _('Terminal setting'),
2018-01-17 09:17:18 +00:00
'form': self.form_class(),
2018-02-26 07:06:00 +00:00
'replay_storage': replay_storage,
'command_storage': command_storage
2018-01-17 09:17:18 +00:00
}
kwargs.update(context)
return super().get_context_data(**kwargs)
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
2018-01-17 09:17:18 +00:00
messages.success(request, msg)
2018-01-20 14:22:09 +00:00
return redirect('settings:terminal-setting')
2018-01-17 09:17:18 +00:00
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)
2018-02-26 07:06:00 +00:00
2018-04-01 15:45:37 +00:00
class SecuritySettingView(PermissionsMixin, TemplateView):
form_class = SecuritySettingForm
template_name = "settings/security_setting.html"
permission_classes = [IsSuperUser]
def get_context_data(self, **kwargs):
context = {
'app': _('Settings'),
'action': _('Security setting'),
'form': self.form_class(),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
messages.success(request, msg)
return redirect('settings:security-setting')
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)
class EmailContentSettingView(PermissionsMixin, TemplateView):
template_name = "settings/email_content_setting.html"
form_class = EmailContentSettingForm
permission_classes = [IsSuperUser]
def get_context_data(self, **kwargs):
context = {
'app': _('Settings'),
'action': _('Email content setting'),
'form': self.form_class(),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
def post(self, request):
form = self.form_class(request.POST)
if form.is_valid():
form.save()
msg = _("Update setting successfully")
messages.success(request, msg)
return redirect('settings:email-content-setting')
else:
context = self.get_context_data()
context.update({"form": form})
return render(request, self.template_name, context)