mirror of https://github.com/jumpserver/jumpserver
Merge branch 'exec_cmd' into dev
commit
a7db713b1e
|
@ -412,9 +412,9 @@ def perm_role_push(request):
|
|||
push_resource = []
|
||||
for asset in calc_assets:
|
||||
if asset.use_default_auth:
|
||||
username = Setting.default_user
|
||||
password = Setting.default_password
|
||||
port = Setting.default_port
|
||||
username = Setting.field1
|
||||
port = Setting.field2
|
||||
password = Setting.field3
|
||||
else:
|
||||
username = asset.username
|
||||
password = asset.password
|
||||
|
|
|
@ -52,15 +52,15 @@ def get_asset_info(asset):
|
|||
info = {'hostname': asset.hostname, 'ip': asset.ip}
|
||||
if asset.use_default_auth:
|
||||
if default:
|
||||
info['port'] = default.default_port
|
||||
info['username'] = default.default_user
|
||||
info['port'] = int(default.field2)
|
||||
info['username'] = default.field1
|
||||
try:
|
||||
info['password'] = CRYPTOR.decrypt(default.default_password)
|
||||
info['password'] = CRYPTOR.decrypt(default.field3)
|
||||
except ServerError:
|
||||
pass
|
||||
info['ssh_key'] = default.default_pri_key_path
|
||||
info['ssh_key'] = default.field4
|
||||
else:
|
||||
info['port'] = asset.port
|
||||
info['port'] = int(asset.port)
|
||||
info['username'] = asset.username
|
||||
info['password'] = CRYPTOR.decrypt(asset.password)
|
||||
|
||||
|
|
|
@ -5,10 +5,14 @@ from django.db import models
|
|||
|
||||
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(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)
|
||||
field1 = models.CharField(max_length=100, null=True, blank=True)
|
||||
field2 = models.CharField(max_length=100, null=True, blank=True)
|
||||
field3 = models.CharField(max_length=100, null=True, blank=True)
|
||||
field4 = models.CharField(max_length=100, null=True, blank=True)
|
||||
field5 = models.CharField(max_length=100, null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = u'setting'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
|
|
@ -265,7 +265,7 @@ def setting(request):
|
|||
password = request.POST.get('password', '')
|
||||
private_key = request.POST.get('key', '')
|
||||
|
||||
if '' in [username, port] and ('' in password or '' in private_key):
|
||||
if '' in [username, port]:
|
||||
return HttpResponse('所填内容不能为空, 且密码和私钥填一个')
|
||||
else:
|
||||
private_key_path = os.path.join(BASE_DIR, 'keys/role_keys', 'default', 'default_private_key.pem')
|
||||
|
@ -275,19 +275,19 @@ def setting(request):
|
|||
os.chmod(private_key_path, 0600)
|
||||
|
||||
if setting_default:
|
||||
if password != setting_default.default_password:
|
||||
if 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)
|
||||
Setting.objects.filter(name='default').update(field1=username, field2=port,
|
||||
field3=password_encode,
|
||||
field4=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()
|
||||
setting_r = Setting(name='default', field1=username, field2=port,
|
||||
field3=password_encode,
|
||||
field4=private_key_path).save()
|
||||
|
||||
msg = "设置成功"
|
||||
return my_render('setting.html', locals(), request)
|
||||
|
|
|
@ -48,28 +48,30 @@
|
|||
<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_default.default_user }}" class="form-control">
|
||||
<input id="username" name="username" placeholder="Username" type="text" value="{{ setting_default.field1 }}" 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_default.default_port }}" class="form-control">
|
||||
<input id="port" name="port" placeholder="Port" type="text" value="{{ setting_default.field2 }}" 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">
|
||||
<input id="password" name="password" placeholder="Password" type="password" value="{{ setting_default.default_password }}" class="form-control">
|
||||
<input id="password" name="password" placeholder="Password" type="password" class="form-control">
|
||||
<span class="help-block m-b-none">如果不修改密码,请留空</span>
|
||||
</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>
|
||||
<textarea class="form-control" name="key" placeholder="请复制粘贴私钥" rows="10" style="font-size: 9px;"></textarea>
|
||||
<span class="help-block m-b-none">如果不修改密钥,请留空</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
|
Loading…
Reference in New Issue