mirror of https://github.com/jumpserver/jumpserver
添加资产的默认设置
parent
7849ff2b92
commit
5692e9dc86
|
@ -7,6 +7,7 @@ class Setting(models.Model):
|
|||
name = models.CharField(max_length=100)
|
||||
default_user = models.CharField(max_length=100, null=True, blank=True)
|
||||
default_port = models.IntegerField(max_length=10, null=True, blank=True)
|
||||
default_password = models.CharField(max_length=100, null=True, blank=True)
|
||||
default_pri_key_path = models.CharField(max_length=100, null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -245,27 +245,39 @@ def Logout(request):
|
|||
|
||||
def setting(request):
|
||||
header_title, path1 = '项目设置', '设置'
|
||||
setting_r = get_object(Setting, name='default')
|
||||
setting_default = get_object(Setting, name='default')
|
||||
|
||||
if request.method == "POST":
|
||||
username = request.POST.get('username', '')
|
||||
port = request.POST.get('port', '')
|
||||
private_key = request.POST.get('key', '')
|
||||
setting_raw = request.POST.get('setting', '')
|
||||
if setting_raw == 'default':
|
||||
username = request.POST.get('username', '')
|
||||
port = request.POST.get('port', '')
|
||||
password = request.POST.get('password', '')
|
||||
private_key = request.POST.get('key', '')
|
||||
|
||||
if '' in [username, port, private_key]:
|
||||
return HttpResponse('所填内容不能为空')
|
||||
else:
|
||||
settings = get_object(Setting, id=1)
|
||||
private_key_path = os.path.join(BASE_DIR, 'keys', 'default', 'default_private_key.pem')
|
||||
with open(private_key_path, 'w') as f:
|
||||
f.write(private_key)
|
||||
os.chmod(private_key_path, 0600)
|
||||
if settings:
|
||||
Setting.objects.filter(name='default').update(default_user=username, default_port=port,
|
||||
default_pri_key_path=private_key_path)
|
||||
if '' in [username, port] and ('' in password or '' in private_key):
|
||||
return HttpResponse('所填内容不能为空, 且密码和私钥填一个')
|
||||
else:
|
||||
setting_r = Setting(name='default', default_user=username, default_port=port,
|
||||
default_pri_key_path=private_key_path).save()
|
||||
private_key_path = os.path.join(BASE_DIR, 'keys', 'default', 'default_private_key.pem')
|
||||
if private_key:
|
||||
with open(private_key_path, 'w') as f:
|
||||
f.write(private_key)
|
||||
os.chmod(private_key_path, 0600)
|
||||
|
||||
if setting_default:
|
||||
if password != setting_default.default_password:
|
||||
password_encode = CRYPTOR.encrypt(password)
|
||||
else:
|
||||
password_encode = password
|
||||
Setting.objects.filter(name='default').update(default_user=username, default_port=port,
|
||||
default_password=password_encode,
|
||||
default_pri_key_path=private_key_path)
|
||||
|
||||
else:
|
||||
password_encode = CRYPTOR.encrypt(password)
|
||||
setting_r = Setting(name='default', default_user=username, default_port=port,
|
||||
default_password=password_encode,
|
||||
default_pri_key_path=private_key_path).save()
|
||||
|
||||
msg = "设置成功"
|
||||
return my_render('setting.html', locals(), request)
|
||||
|
|
|
@ -46,20 +46,28 @@
|
|||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-2 control-label">默认用户名<span class="red-fonts">*</span></label>
|
||||
<input name="setting" value="default" style="display: none">
|
||||
<div class="col-sm-8">
|
||||
<input id="username" name="username" placeholder="Username" type="text" value="{{ setting_r.default_user }}" class="form-control">
|
||||
<input id="username" name="username" placeholder="Username" type="text" value="{{ setting_default.default_user }}" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="port" class="col-sm-2 control-label">默认ssh端口<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input id="port" name="port" placeholder="Port" type="text" value="{{ setting_r.default_port }}" class="form-control">
|
||||
<input id="port" name="port" placeholder="Port" type="text" value="{{ setting_default.default_port }}" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="key" class="col-sm-2 control-label">默认密钥<span class="red-fonts">*</span></label>
|
||||
<label for="key" class="col-sm-2 control-label">默认密码</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="password" name="password" placeholder="Password" type="password" value="{{ setting_default.default_password }}" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="key" class="col-sm-2 control-label">默认密钥</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea class="form-control" name="key" placeholder="请复制粘贴私钥(原来的因为安全原因不被显示)" rows="10" style="font-size: 9px;"></textarea>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue