-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
新增选择本地文件上传密钥,上传后将密钥信息保存到数据库,连接时从数据库读取 #1303
Changes from 20 commits
6d0bab6
31e00e6
cce914c
0902cfb
5b71dd7
88821c4
beb2112
32e2422
c33d6c1
a34d3e1
166ac3b
a2cdf04
a24f90c
0ce4f40
aa420a7
a4d66a8
2b59a0f
d9f2ddf
e88478c
5e31b8c
99e262d
7eee255
fd128c0
ca9f519
3b78bea
6793607
fe7fe9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', '') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
""" | ||
|
@@ -99,14 +103,21 @@ 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='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) | ||
|
||
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' | ||
|
@@ -853,28 +864,3 @@ class Meta: | |
index_together = ('hostname_max', 'ts_min') | ||
verbose_name = u'慢日志明细' | ||
verbose_name_plural = u'慢日志明细' | ||
|
||
|
||
class AuditEntry(models.Model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这块应该是其他pr合并到主干的,注意冲突处理 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原来的方式:将密钥上传至 archery 部署的服务器目录,如果是docker部署的还需要传到容器卷挂载的目录下,如 downloads logs这种目录里,然后在后台天上这个目录的绝对路径,当部署多实例的时候就无法使用了,而且使用起来也不是特别便捷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前使用这个功能的用户应该都是把密钥上传到了部署 archery 服务的服务器上,升级时需要把密钥下载到本地,更新版本后编辑对应条目,重新选择文件上传即可。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
辛苦增加到1.8.3的sql文件中 |
||
""" | ||
登录审计日志 | ||
""" | ||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否也采取加密存储的形式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
密钥长度太长了,所以用了这个
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加密组件也支持text,可以调整下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯 改成 EncryptedTextField 了