From 6d0bab6c1f830e4ad2bc279ce840d6311fa70a9f Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 28 Dec 2021 17:15:50 +0800 Subject: [PATCH 01/20] =?UTF-8?q?#=20=E6=96=B0=E5=A2=9E=20pkey=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=8C=82=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docker-compose/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/docker-compose/docker-compose.yml b/src/docker-compose/docker-compose.yml index 8395105e6a..c2083980b1 100644 --- a/src/docker-compose/docker-compose.yml +++ b/src/docker-compose/docker-compose.yml @@ -53,6 +53,7 @@ services: - "./archery/downloads:/opt/archery/downloads" - "./archery/sql/migrations:/opt/archery/sql/migrations" - "./archery/logs:/opt/archery/logs" + - "./archery/keys:/opt/archery/keys" entrypoint: "dockerize -wait tcp://mysql:3306 -wait tcp://redis:6379 -timeout 60s /opt/archery/src/docker/startup.sh" environment: NGINX_PORT: 9123 From 31e00e6e129e1a5f21d436099a206c49ea8cce42 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 28 Dec 2021 17:19:15 +0800 Subject: [PATCH 02/20] =?UTF-8?q?#=20=E4=BF=AE=E6=94=B9=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=BC=95=E5=AF=BC=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=A1=AB=E5=86=99=20pkey=20=E6=96=87=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index 0389a52599..0d8a4abe81 100755 --- a/sql/models.py +++ b/sql/models.py @@ -99,7 +99,7 @@ class Tunnel(models.Model): port = models.IntegerField('端口', default=0) user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) - pkey_path = fields.EncryptedCharField(verbose_name='密钥地址', max_length=300, default='', blank=True, null=True) + pkey_path = fields.EncryptedCharField(verbose_name='密钥名称', max_length=300, default='', blank=True, null=True) pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) From cce914c2889ddc938dbe21cf298497e3801ede4f Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 28 Dec 2021 17:23:09 +0800 Subject: [PATCH 03/20] =?UTF-8?q?#=20=E6=96=B0=E5=A2=9E=20ssh=20tunnel=20k?= =?UTF-8?q?eys=20=E9=BB=98=E8=AE=A4=E5=AD=98=E6=94=BE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archery/settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/archery/settings.py b/archery/settings.py index 69387e605e..524e5b3677 100644 --- a/archery/settings.py +++ b/archery/settings.py @@ -257,3 +257,8 @@ # }, } } + +# 存放用于 ssh tunnel 秘钥的文件夹 +SSH_TUNNEL_KEY_PATH = os.path.join(BASE_DIR, 'keys') +if not os.path.exists(SSH_TUNNEL_KEY_PATH): + os.makedirs(SSH_TUNNEL_KEY_PATH) \ No newline at end of file From 0902cfbf127f16091862c7cce806559fc75bca7e Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 28 Dec 2021 17:27:08 +0800 Subject: [PATCH 04/20] =?UTF-8?q?#=20=E5=B0=86=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E7=9A=84=20pkey=20=E5=90=8D=E5=AD=97=E4=B8=8E=20pkey=20?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/utils/ssh_tunnel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/utils/ssh_tunnel.py b/sql/utils/ssh_tunnel.py index fe58923ed0..008441ddc3 100644 --- a/sql/utils/ssh_tunnel.py +++ b/sql/utils/ssh_tunnel.py @@ -5,8 +5,10 @@ @file: ssh_tunnel.py @time: 2020/05/09 """ +import os from sshtunnel import SSHTunnelForwarder from paramiko import RSAKey +from django.conf import settings class SSHConnection(object): """ @@ -21,6 +23,7 @@ def __init__(self, host, port, tun_host, tun_port, tun_user, tun_password, pkey_ self.tun_password = tun_password if pkey_path: + pkey_path = os.path.join(settings.SSH_TUNNEL_KEY_PATH, pkey_path) self.private_key = RSAKey.from_private_key_file(pkey_path, password=pkey_password) self.server = SSHTunnelForwarder( ssh_address_or_host=(self.tun_host, self.tun_port), From 5b71dd737633df3d0f299db0e9ce9163f2edf641 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 29 Dec 2021 09:06:42 +0800 Subject: [PATCH 05/20] =?UTF-8?q?#=20=E5=90=8E=E5=8F=B0=20django=20q=20?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=94=B9=E4=B8=BA=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sql/models.py b/sql/models.py index 0d8a4abe81..3b0825f498 100755 --- a/sql/models.py +++ b/sql/models.py @@ -5,6 +5,9 @@ from django.utils.translation import gettext as _ from mirage.crypto import Crypto +from django_q.apps import DjangoQConfig +from django_q.models import Success, Failure, OrmQ + class ResourceGroup(models.Model): """ @@ -853,3 +856,22 @@ class Meta: index_together = ('hostname_max', 'ts_min') verbose_name = u'慢日志明细' verbose_name_plural = u'慢日志明细' + + +class MyDjangoQConfig(DjangoQConfig): + verbose_name = u"调度器" + + +class MySuccess(Success): + verbose_name = u'成功任务' + verbose_name_plural = verbose_name + + +class MyFailure(Failure): + verbose_name = u'失败任务' + verbose_name_plural = verbose_name + + +class MyOrmQ(OrmQ): + verbose_name = u'任务队列' + verbose_name_plural = verbose_name \ No newline at end of file From 88821c4684ed40633da16aa270b0c4532c1b266a Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 30 Dec 2021 18:06:23 +0800 Subject: [PATCH 06/20] =?UTF-8?q?#=20=E5=AF=B9=E5=BA=94=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20pkey=20=E6=96=87=E6=9C=AC=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/admin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/admin.py b/sql/admin.py index 33355722b8..2a7b82a659 100755 --- a/sql/admin.py +++ b/sql/admin.py @@ -10,6 +10,7 @@ QueryPrivileges, InstanceAccount, InstanceDatabase, ArchiveConfig, \ WorkflowAudit, WorkflowLog, ParamTemplate, ParamHistory, InstanceTag, \ Tunnel +from sql.form import TunnelForm # 用户管理 @@ -87,13 +88,14 @@ class TunnelAdmin(admin.ModelAdmin): search_fields = ('id', 'tunnel_name') fieldsets = ( None, - {'fields': ('tunnel_name', 'host', 'port', 'user', 'password', 'pkey_path', 'pkey_password',), }), + {'fields': ('tunnel_name', 'host', 'port', 'user', 'password', 'pkey_path', 'pkey_password', 'pkey'), }), ordering = ('id',) # 添加页显示内容 add_fieldsets = ( ('隧道信息', {'fields': ('tunnel_name', 'host', 'port')}), - ('连接信息', {'fields': ('user', 'password', 'pkey_path', 'pkey_password')}), + ('连接信息', {'fields': ('user', 'password', 'pkey_path', 'pkey_password', 'pkey')}), ) + form = TunnelForm def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name in ['password', 'pkey_password']: From beb211206c452c0ce1510f56b7c05cd0d8ff4dbe Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 30 Dec 2021 18:12:18 +0800 Subject: [PATCH 07/20] =?UTF-8?q?#=20=E9=80=9A=E8=BF=87=20form=20=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E7=A7=98=E9=92=A5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/form.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sql/form.py diff --git a/sql/form.py b/sql/form.py new file mode 100644 index 0000000000..10a34d7fcc --- /dev/null +++ b/sql/form.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- +""" +--------------------------------------------------------- +@project: issacmarkArchery +@file: form +@date: 2021/12/30 17:43 +@author: mayp +--------------------------------------------------------- +""" +from django.forms import ModelForm, Textarea +from sql.models import Tunnel + + +class TunnelForm(ModelForm): + class Meta: + model = Tunnel + fields = "__all__" + widgets = { + 'PKey': Textarea(attrs={'cols': 40, 'rows': 8}), + } + + def clean(self): + cleaned_data = super().clean() + pkey_path = cleaned_data.get('pkey_path').read() + if pkey_path: + cleaned_data['pkey'] = str(pkey_path, 'utf-8').replace(r'\r', '').replace(r'\n', '') \ No newline at end of file From 32e24228bee05e6c88d77b2bccf759d7645d248b Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 08:56:55 +0800 Subject: [PATCH 08/20] =?UTF-8?q?#=20=E6=96=B0=E5=A2=9E=20pkey=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=AD=98=E5=82=A8=E5=AF=86=E9=92=A5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sql/models.py b/sql/models.py index 0389a52599..c2723f16df 100755 --- a/sql/models.py +++ b/sql/models.py @@ -2,9 +2,12 @@ from django.db import models from django.contrib.auth.models import AbstractUser from mirage import fields - from django.utils.translation import gettext as _ from mirage.crypto import Crypto +from django.conf import settings + +pkey_root = settings.PKEY_ROOT + class ResourceGroup(models.Model): """ @@ -99,7 +102,8 @@ class Tunnel(models.Model): port = models.IntegerField('端口', default=0) user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) - pkey_path = fields.EncryptedCharField(verbose_name='密钥地址', max_length=300, default='', blank=True, null=True) + pkey = models.TextField(verbose_name="密钥", blank=True, null=True) + pkey_path = models.FileField(verbose_name='密钥路径', blank=True, null=True, upload_to=pkey_root) pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) @@ -107,6 +111,12 @@ class Tunnel(models.Model): def __str__(self): return self.tunnel_name + def short_pkey(self): + if len(str(self.pkey)) > 30: + return '{}...'.format(str(self.pkey)[0:29]) + else: + return str(self.pkey) + class Meta: managed = True db_table = 'ssh_tunnel' @@ -852,4 +862,4 @@ class Meta: unique_together = ('checksum', 'ts_min', 'ts_max') index_together = ('hostname_max', 'ts_min') verbose_name = u'慢日志明细' - verbose_name_plural = u'慢日志明细' + verbose_name_plural = u'慢日志明细' \ No newline at end of file From a34d3e188d93c905c78f73b120be0b8de533d65b Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 09:56:42 +0800 Subject: [PATCH 09/20] =?UTF-8?q?#=20=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20pkey=20=E6=96=87=E4=BB=B6=E5=AF=B9=E8=B1=A1=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/utils/ssh_tunnel.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sql/utils/ssh_tunnel.py b/sql/utils/ssh_tunnel.py index 008441ddc3..e40c9861e7 100644 --- a/sql/utils/ssh_tunnel.py +++ b/sql/utils/ssh_tunnel.py @@ -5,16 +5,16 @@ @file: ssh_tunnel.py @time: 2020/05/09 """ -import os from sshtunnel import SSHTunnelForwarder from paramiko import RSAKey -from django.conf import settings +import io + class SSHConnection(object): """ ssh隧道连接类,用于映射ssh隧道端口到本地,连接结束时需要清理 """ - def __init__(self, host, port, tun_host, tun_port, tun_user, tun_password, pkey_path, pkey_password): + def __init__(self, host, port, tun_host, tun_port, tun_user, tun_password, pkey, pkey_password): self.host = host self.port = int(port) self.tun_host = tun_host @@ -22,9 +22,11 @@ def __init__(self, host, port, tun_host, tun_port, tun_user, tun_password, pkey_ self.tun_user = tun_user self.tun_password = tun_password - if pkey_path: - pkey_path = os.path.join(settings.SSH_TUNNEL_KEY_PATH, pkey_path) - self.private_key = RSAKey.from_private_key_file(pkey_path, password=pkey_password) + if pkey: + private_key_file_obj = io.StringIO() + private_key_file_obj.write(pkey) + private_key_file_obj.seek(0) + self.private_key = RSAKey.from_private_key(private_key_file_obj, password=pkey_password) self.server = SSHTunnelForwarder( ssh_address_or_host=(self.tun_host, self.tun_port), ssh_username=self.tun_user, From 166ac3b9521d68593fc426121b9029033de03112 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 10:02:15 +0800 Subject: [PATCH 10/20] =?UTF-8?q?#=20=E6=96=B0=E5=A2=9E=20pkey=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=AD=98=E5=82=A8=E5=AF=86=E9=92=A5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/sql/models.py b/sql/models.py index 3b0825f498..7452251120 100755 --- a/sql/models.py +++ b/sql/models.py @@ -5,9 +5,6 @@ from django.utils.translation import gettext as _ from mirage.crypto import Crypto -from django_q.apps import DjangoQConfig -from django_q.models import Success, Failure, OrmQ - class ResourceGroup(models.Model): """ @@ -102,7 +99,8 @@ class Tunnel(models.Model): port = models.IntegerField('端口', default=0) user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) - pkey_path = fields.EncryptedCharField(verbose_name='密钥名称', max_length=300, default='', blank=True, null=True) + pkey = models.TextField(verbose_name="密钥", blank=True, null=True) + pkey_path = fields.EncryptedCharField(verbose_name='密钥地址', max_length=300, default='', blank=True, null=True) pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) @@ -110,6 +108,12 @@ class Tunnel(models.Model): def __str__(self): return self.tunnel_name + def short_pkey(self): + if len(str(self.pkey)) > 20: + return '{}...'.format(str(self.pkey)[0:19]) + else: + return str(self.pkey) + class Meta: managed = True db_table = 'ssh_tunnel' @@ -856,22 +860,3 @@ class Meta: index_together = ('hostname_max', 'ts_min') verbose_name = u'慢日志明细' verbose_name_plural = u'慢日志明细' - - -class MyDjangoQConfig(DjangoQConfig): - verbose_name = u"调度器" - - -class MySuccess(Success): - verbose_name = u'成功任务' - verbose_name_plural = verbose_name - - -class MyFailure(Failure): - verbose_name = u'失败任务' - verbose_name_plural = verbose_name - - -class MyOrmQ(OrmQ): - verbose_name = u'任务队列' - verbose_name_plural = verbose_name \ No newline at end of file From a2cdf04830bb4c7d2c8e392ad8674d444f5fad40 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 10:07:37 +0800 Subject: [PATCH 11/20] # --- sql/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index 7452251120..bd3359fc24 100755 --- a/sql/models.py +++ b/sql/models.py @@ -5,6 +5,10 @@ from django.utils.translation import gettext as _ from mirage.crypto import Crypto +from django.conf import settings + +pkey_root = settings.PKEY_ROOT + class ResourceGroup(models.Model): """ @@ -100,7 +104,7 @@ class Tunnel(models.Model): user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) pkey = models.TextField(verbose_name="密钥", blank=True, null=True) - pkey_path = fields.EncryptedCharField(verbose_name='密钥地址', max_length=300, default='', blank=True, null=True) + PKey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to=pkey_root) pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) From a24f90c04dbcbc8a968668f273e5715c127dba55 Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 10:12:31 +0800 Subject: [PATCH 12/20] =?UTF-8?q?#=20=E6=94=B9=E4=B8=BA=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=20pkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/engines/__init__.py b/sql/engines/__init__.py index 21bf69033e..97cf8ee434 100644 --- a/sql/engines/__init__.py +++ b/sql/engines/__init__.py @@ -27,7 +27,7 @@ def __init__(self, instance=None): instance.tunnel.port, instance.tunnel.user, instance.tunnel.password, - instance.tunnel.pkey_path, + instance.tunnel.pkey, instance.tunnel.pkey_password, ) self.host,self.port = self.ssh.get_ssh() @@ -48,7 +48,7 @@ def remote_instance_conn(self, instance=None): instance.tunnel.port, instance.tunnel.user, instance.tunnel.password, - instance.tunnel.pkey_path, + instance.tunnel.pkey, instance.tunnel.pkey_password, ) self.remote_host, self.remote_port = self.remotessh.get_ssh() From 0ce4f40d4df666710047e01fb3496cfd1b6d30ca Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 31 Dec 2021 10:18:42 +0800 Subject: [PATCH 13/20] =?UTF-8?q?#=20=E6=96=B0=E5=A2=9E=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=20pkey=20=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archery/settings.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/archery/settings.py b/archery/settings.py index 524e5b3677..7780d26b49 100644 --- a/archery/settings.py +++ b/archery/settings.py @@ -258,7 +258,10 @@ } } -# 存放用于 ssh tunnel 秘钥的文件夹 -SSH_TUNNEL_KEY_PATH = os.path.join(BASE_DIR, 'keys') -if not os.path.exists(SSH_TUNNEL_KEY_PATH): - os.makedirs(SSH_TUNNEL_KEY_PATH) \ No newline at end of file +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +if not os.path.exists(MEDIA_ROOT): + os.mkdir(MEDIA_ROOT) + +PKEY_ROOT = os.path.join(MEDIA_ROOT, 'keys') +if not os.path.exists(PKEY_ROOT): + os.mkdir(PKEY_ROOT) \ No newline at end of file From aa420a7ae06532063945690cbe0e161da8ed91ba Mon Sep 17 00:00:00 2001 From: issacmark Date: Fri, 31 Dec 2021 10:35:14 +0800 Subject: [PATCH 14/20] Update models.py --- sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index bd3359fc24..6c53a3efa9 100755 --- a/sql/models.py +++ b/sql/models.py @@ -104,7 +104,7 @@ class Tunnel(models.Model): user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) pkey = models.TextField(verbose_name="密钥", blank=True, null=True) - PKey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to=pkey_root) + pkey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to=pkey_root) pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) From 2b59a0f74c26a992b3013fbb489c2c099d6350a0 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 4 Jan 2022 09:16:43 +0800 Subject: [PATCH 15/20] =?UTF-8?q?#=20=E8=AE=BE=E7=BD=AE=E4=B8=BA=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index bd3359fc24..7f49412bac 100755 --- a/sql/models.py +++ b/sql/models.py @@ -104,7 +104,7 @@ class Tunnel(models.Model): user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) pkey = models.TextField(verbose_name="密钥", blank=True, null=True) - PKey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to=pkey_root) + PKey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to='keys/') pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) From e88478c8223cd5bbf7129ed164710670147b6539 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 4 Jan 2022 09:44:04 +0800 Subject: [PATCH 16/20] # --- sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index bd3359fc24..980961738e 100755 --- a/sql/models.py +++ b/sql/models.py @@ -104,7 +104,7 @@ class Tunnel(models.Model): user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) pkey = models.TextField(verbose_name="密钥", blank=True, null=True) - PKey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to=pkey_root) + pkey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to='keys/') pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) update_time = models.DateTimeField('更新时间', auto_now=True) From 99e262dc2d2fc51b57a9a38cf24a9f2442fdf645 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 6 Jan 2022 09:49:29 +0800 Subject: [PATCH 17/20] # --- sql/models.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sql/models.py b/sql/models.py index 980961738e..be19ef0402 100755 --- a/sql/models.py +++ b/sql/models.py @@ -5,10 +5,6 @@ from django.utils.translation import gettext as _ from mirage.crypto import Crypto -from django.conf import settings - -pkey_root = settings.PKEY_ROOT - class ResourceGroup(models.Model): """ @@ -703,6 +699,7 @@ class Meta: ('menu_tools', '菜单 工具插件'), ('menu_archive', '菜单 数据归档'), ('menu_binlog2sql', '菜单 Binlog2SQL'), + ('menu_my2sql', '菜单 My2SQL'), ('menu_schemasync', '菜单 SchemaSync'), ('menu_system', '菜单 系统管理'), ('menu_document', '菜单 相关文档'), @@ -864,3 +861,28 @@ class Meta: index_together = ('hostname_max', 'ts_min') verbose_name = u'慢日志明细' verbose_name_plural = u'慢日志明细' + + +class AuditEntry(models.Model): + """ + 登录审计日志 + """ + user_id = models.IntegerField('用户ID') + user_name = models.CharField('用户名称', max_length=255, null=True) + action = models.CharField('动作', max_length=255) + ip = models.GenericIPAddressField('IP', null=True) + action_time = models.DateTimeField('操作时间', auto_now_add=True) + + class Meta: + managed = True + db_table = 'audit_log' + verbose_name = u'审计日志' + verbose_name_plural = u'审计日志' + + def __unicode__(self): + return '{0} - {1} - {2} - {3} - {4}'.format(self.user_id, self.user_name, self.ip + , self.action, self.action_time) + + def __str__(self): + return '{0} - {1} - {2} - {3} - {4}'.format(self.user_id, self.user_name, self.ip + , self.action, self.action_time) From fd128c01ae59d9356b8c598b8f1f6b0babfe5ba4 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 12 Jan 2022 09:34:07 +0800 Subject: [PATCH 18/20] =?UTF-8?q?#=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E5=A1=AB?= =?UTF-8?q?=E5=86=99=E4=BA=86=E7=A7=98=E9=92=A5=E8=B7=AF=E5=BE=84=EF=BC=8C?= =?UTF-8?q?=E7=A7=98=E9=92=A5=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/form.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sql/form.py b/sql/form.py index 10a34d7fcc..9b8280bb37 100644 --- a/sql/form.py +++ b/sql/form.py @@ -10,6 +10,7 @@ """ from django.forms import ModelForm, Textarea from sql.models import Tunnel +from django.core.exceptions import ValidationError class TunnelForm(ModelForm): @@ -22,6 +23,10 @@ class Meta: def clean(self): cleaned_data = super().clean() - pkey_path = cleaned_data.get('pkey_path').read() - if pkey_path: - cleaned_data['pkey'] = str(pkey_path, 'utf-8').replace(r'\r', '').replace(r'\n', '') \ No newline at end of file + if cleaned_data.get('pkey_path'): + try: + pkey_path = cleaned_data.get('pkey_path').read() + if pkey_path: + cleaned_data['pkey'] = str(pkey_path, 'utf-8').replace(r'\r', '').replace(r'\n', '') + except IOError: + raise ValidationError("秘钥文件不存在, 请勾选秘钥路径的清除选项再进行保存") From ca9f5195af734b4143731486e93d7beaa3c61c1d Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 12 Jan 2022 09:38:55 +0800 Subject: [PATCH 19/20] =?UTF-8?q?#=20pkey=20=E5=AD=97=E6=AE=B5=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20EncryptedTextField?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/models.py b/sql/models.py index be19ef0402..98f85731c6 100755 --- a/sql/models.py +++ b/sql/models.py @@ -99,7 +99,7 @@ class Tunnel(models.Model): port = models.IntegerField('端口', default=0) user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True) password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True) - pkey = models.TextField(verbose_name="密钥", blank=True, null=True) + pkey = fields.EncryptedTextField(verbose_name="密钥", blank=True, null=True) pkey_path = models.FileField(verbose_name="密钥地址", blank=True, null=True, upload_to='keys/') pkey_password = fields.EncryptedCharField(verbose_name='密钥密码', max_length=300, default='', blank=True, null=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) From 3b78bea6ee17cda60ada3b07dacb65b80cb23788 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 12 Jan 2022 09:49:51 +0800 Subject: [PATCH 20/20] =?UTF-8?q?#=20ssh=20=E9=9A=A7=E9=81=93=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/init_sql/v1.8.3.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/init_sql/v1.8.3.sql b/src/init_sql/v1.8.3.sql index 25779d6125..ac4496b75a 100644 --- a/src/init_sql/v1.8.3.sql +++ b/src/init_sql/v1.8.3.sql @@ -8,4 +8,7 @@ CREATE TABLE `audit_log` ( `action_time` datetime(6) NOT NULL COMMENT '操作时间', PRIMARY KEY (`id`), KEY `idx_username` (`user_name`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='登录审计日志表'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='登录审计日志表'; + +-- ssh 隧道功能修改 +ALTER TABLE `ssh_tunnel` ADD COLUMN pkey longtext NULL AFTER password DEFAULT CHARSET=utf8mb4 COMMENT='密钥信息'; \ No newline at end of file