diff --git a/jperm/views.py b/jperm/views.py index 1c9eaa15c..0128bfca2 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -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 diff --git a/jumpserver/api.py b/jumpserver/api.py index b44d5d4e5..fa53587f2 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -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) diff --git a/jumpserver/models.py b/jumpserver/models.py index e8cb7ea2b..e75921aa4 100644 --- a/jumpserver/models.py +++ b/jumpserver/models.py @@ -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 diff --git a/jumpserver/views.py b/jumpserver/views.py index 57ae3f5dd..87cdf0126 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -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) diff --git a/templates/setting.html b/templates/setting.html index 7fa097150..de6264d46 100644 --- a/templates/setting.html +++ b/templates/setting.html @@ -48,28 +48,30 @@