Merge branch 'dev' of github.com:jumpserver/jumpserver into dev

pull/223/head
ibuler 2016-04-28 15:54:33 +08:00
commit 2fd68845ce
8 changed files with 91 additions and 71 deletions

View File

@ -67,7 +67,7 @@ class Asset(models.Model):
port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号") port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号")
group = models.ManyToManyField(AssetGroup, blank=True, verbose_name=u"所属主机组") group = models.ManyToManyField(AssetGroup, blank=True, verbose_name=u"所属主机组")
username = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"管理用户名") username = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"管理用户名")
password = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"密码") password = models.CharField(max_length=256, blank=True, null=True, verbose_name=u"密码")
use_default_auth = models.BooleanField(default=True, verbose_name=u"使用默认管理账号") use_default_auth = models.BooleanField(default=True, verbose_name=u"使用默认管理账号")
idc = models.ForeignKey(IDC, blank=True, null=True, on_delete=models.SET_NULL, verbose_name=u'机房') idc = models.ForeignKey(IDC, blank=True, null=True, on_delete=models.SET_NULL, verbose_name=u'机房')
mac = models.CharField(max_length=20, blank=True, null=True, verbose_name=u"MAC地址") mac = models.CharField(max_length=20, blank=True, null=True, verbose_name=u"MAC地址")

View File

@ -135,13 +135,16 @@ def asset_add(request):
af_post = AssetForm(request.POST) af_post = AssetForm(request.POST)
ip = request.POST.get('ip', '') ip = request.POST.get('ip', '')
hostname = request.POST.get('hostname', '') hostname = request.POST.get('hostname', '')
is_active = True if request.POST.get('is_active') == '1' else False is_active = True if request.POST.get('is_active') == '1' else False
use_default_auth = request.POST.get('use_default_auth', '') use_default_auth = request.POST.get('use_default_auth', '')
try: try:
if Asset.objects.filter(hostname=unicode(hostname)): if Asset.objects.filter(hostname=unicode(hostname)):
error = u'该主机名 %s 已存在!' % hostname error = u'该主机名 %s 已存在!' % hostname
raise ServerError(error) raise ServerError(error)
if len(hostname) > 54:
error = u"主机名长度不能超过53位!"
raise ServerError(error)
except ServerError: except ServerError:
pass pass
else: else:
@ -219,8 +222,9 @@ def asset_edit(request):
if asset_test and asset_id != unicode(asset_test.id): if asset_test and asset_id != unicode(asset_test.id):
emg = u'该主机名 %s 已存在!' % hostname emg = u'该主机名 %s 已存在!' % hostname
raise ServerError(emg) raise ServerError(emg)
except ServerError: if len(hostname) > 54:
pass emg = u'主机名长度不能超过54位!'
raise ServerError(emg)
else: else:
if af_post.is_valid(): if af_post.is_valid():
af_save = af_post.save(commit=False) af_save = af_post.save(commit=False)
@ -245,7 +249,10 @@ def asset_edit(request):
smg = u'主机 %s 修改成功' % ip smg = u'主机 %s 修改成功' % ip
else: else:
emg = u'主机 %s 修改失败' % ip emg = u'主机 %s 修改失败' % ip
return my_render('jasset/error.html', locals(), request) raise ServerError(emg)
except ServerError as e:
error = e.message
return my_render('jasset/asset_edit.html', locals(), request)
return HttpResponseRedirect(reverse('asset_detail')+'?id=%s' % asset_id) return HttpResponseRedirect(reverse('asset_detail')+'?id=%s' % asset_id)
return my_render('jasset/asset_edit.html', locals(), request) return my_render('jasset/asset_edit.html', locals(), request)

View File

@ -240,6 +240,7 @@ class TermLogRecorder(object):
TermLogRecorder.loglist[str(id)] = [self] TermLogRecorder.loglist[str(id)] = [self]
def write(self, msg): def write(self, msg):
"""
if self.recoder and (not self._in_vim): if self.recoder and (not self._in_vim):
if self.commands.__len__() == 0: if self.commands.__len__() == 0:
self._stream.feed(msg) self._stream.feed(msg)
@ -256,6 +257,7 @@ class TermLogRecorder(object):
self._screen.reset() self._screen.reset()
else: else:
self._command() self._command()
"""
try: try:
self.write_message(msg) self.write_message(msg)
except: except:

View File

@ -7,7 +7,7 @@ class Setting(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
field1 = 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) field2 = models.CharField(max_length=100, null=True, blank=True)
field3 = models.CharField(max_length=100, null=True, blank=True) field3 = models.CharField(max_length=256, null=True, blank=True)
field4 = 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) field5 = models.CharField(max_length=100, null=True, blank=True)

View File

@ -220,6 +220,7 @@ def setting(request):
setting_default = get_object(Setting, name='default') setting_default = get_object(Setting, name='default')
if request.method == "POST": if request.method == "POST":
try:
setting_raw = request.POST.get('setting', '') setting_raw = request.POST.get('setting', '')
if setting_raw == 'default': if setting_raw == 'default':
username = request.POST.get('username', '') username = request.POST.get('username', '')
@ -227,8 +228,11 @@ def setting(request):
password = request.POST.get('password', '') password = request.POST.get('password', '')
private_key = request.POST.get('key', '') private_key = request.POST.get('key', '')
if len(password) > 30:
raise ServerError(u'秘密长度不能超过30位!')
if '' in [username, port]: if '' in [username, port]:
return HttpResponse('所填内容不能为空, 且密码和私钥填一个') return ServerError(u'所填内容不能为空, 且密码和私钥填一个')
else: else:
private_key_dir = os.path.join(BASE_DIR, 'keys', 'default') private_key_dir = os.path.join(BASE_DIR, 'keys', 'default')
private_key_path = os.path.join(private_key_dir, 'admin_user.pem') private_key_path = os.path.join(private_key_dir, 'admin_user.pem')
@ -253,8 +257,9 @@ def setting(request):
setting_r = Setting(name='default', field1=username, field2=port, setting_r = Setting(name='default', field1=username, field2=port,
field3=password_encode, field3=password_encode,
field4=private_key_path).save() field4=private_key_path).save()
msg = "设置成功" msg = "设置成功"
except ServerError as e:
error = e.message
return my_render('setting.html', locals(), request) return my_render('setting.html', locals(), request)

View File

@ -164,7 +164,7 @@
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },
"hostname": { "hostname": {
rule: "required", rule: "required;length[0~53]",
tip: "填写主机名", tip: "填写主机名",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
@ -182,7 +182,7 @@
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },
"password": { "password": {
rule: "required(use_default_auth)", rule: "required(use_default_auth);length[0~64]",
tip: "输入密码", tip: "输入密码",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}

View File

@ -206,7 +206,7 @@
}, },
fields: { fields: {
"hostname": { "hostname": {
rule: "required", rule: "required;length[0~53]",
tip: "填写主机名", tip: "填写主机名",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
@ -218,17 +218,17 @@
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },
"username": { "username": {
rule: "required(use_default_auth)", rule: "required(use_default_auth);",
tip: "输入用户名", tip: "输入用户名",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },
{# "password": {#} "password": {
{# rule: "required(use_default_auth)",#} rule: "length[0~64]",
{# tip: "输入密码",#} tip: "输入密码",
{# ok: "",#} ok: "",
{# msg: {required: "必须填写!"}#} empty: true
{# }#} }
}, },
valid: function(form) { valid: function(form) {
form.submit(); form.submit();

View File

@ -128,6 +128,12 @@
tip: "输入端口号", tip: "输入端口号",
ok: "", ok: "",
msg: {required: "端口号必填"} msg: {required: "端口号必填"}
},
"password": {
rule: "length[0~30]",
tip: "输入密码",
ok: "",
empty: true
} }
{# "key": {#} {# "key": {#}
{# rule: "required(either)",#} {# rule: "required(either)",#}