Merge branch 'dev'

fix download error

static file lost
pull/206/head
ibuler 2016-04-20 15:17:04 +08:00
commit 58bb3cc84f
7 changed files with 33 additions and 12 deletions

View File

@ -29,7 +29,7 @@ from django.contrib.sessions.models import Session
from jumpserver.api import ServerError, User, Asset, PermRole, AssetGroup, get_object, mkdir, get_asset_info
from jumpserver.api import logger, Log, TtyLog, get_role_key, CRYPTOR, bash, get_tmp_dir
from jperm.perm_api import gen_resource, get_group_asset_perm, get_group_user_perm, user_have_perm, PermRole
from jumpserver.settings import LOG_DIR
from jumpserver.settings import LOG_DIR, NAV_SORT_BY
from jperm.ansible_api import MyRunner
# from jlog.log_api import escapeString
from jlog.models import ExecLog, FileLog
@ -437,11 +437,21 @@ class Nav(object):
def __init__(self, user):
self.user = user
self.user_perm = get_group_user_perm(self.user)
self.perm_assets = sorted(self.user_perm.get('asset', []).keys(),
key=lambda x: [int(num) for num in x.ip.split('.') if num.isdigit()])
if NAV_SORT_BY == 'ip':
self.perm_assets = sorted(self.user_perm.get('asset', []).keys(),
key=lambda x: [int(num) for num in x.ip.split('.') if num.isdigit()])
elif NAV_SORT_BY == 'hostname':
self.perm_assets = self.natural_sort_hostname(self.user_perm.get('asset', []).keys())
else:
self.perm_assets = tuple(self.user_perm.get('asset', []))
self.search_result = self.perm_assets
self.perm_asset_groups = self.user_perm.get('asset_group', [])
def natural_sort_hostname(self, list):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda x: [ convert(c) for c in re.split('([0-9]+)', x.hostname) ]
return sorted(list, key = alphanum_key)
@staticmethod
def print_nav():
"""
@ -490,8 +500,9 @@ class Nav(object):
except (ValueError, TypeError):
# 匹配 ip, hostname, 备注
str_r = str_r.lower()
self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip).lower()
or str_r in str(asset.hostname).lower()
self.search_result = [asset for asset in self.perm_assets if str_r == str(asset.ip).lower()] or \
[asset for asset in self.perm_assets if str_r in str(asset.ip).lower() \
or str_r in str(asset.hostname).lower() \
or str_r in str(asset.comment).lower()]
else:
# 如果没有输入就展现所有

View File

@ -26,7 +26,7 @@ class PermSudo(models.Model):
class PermRole(models.Model):
name = models.CharField(max_length=100, unique=True)
comment = models.CharField(max_length=100, null=True, blank=True, default='')
password = models.CharField(max_length=128)
password = models.CharField(max_length=512)
key_path = models.CharField(max_length=100)
date_added = models.DateTimeField(auto_now=True)
sudo = models.ManyToManyField(PermSudo, related_name='perm_role')

View File

@ -290,6 +290,8 @@ def perm_role_add(request):
if name == "root":
raise ServerError(u'禁止使用root用户作为系统用户这样非常危险')
default = get_object(Setting, name='default')
if len(password) > 64:
raise ServerError(u'密码长度不能超过64位!')
if password:
encrypt_pass = CRYPTOR.encrypt(password)
@ -446,6 +448,8 @@ def perm_role_edit(request):
role_sudo_names = request.POST.getlist("sudo_name")
role_sudos = [PermSudo.objects.get(id=sudo_id) for sudo_id in role_sudo_names]
key_content = request.POST.get("role_key", "")
if len(role_password) > 64:
raise ServerError(u'密码长度不能超过64位!')
try:
if not role:

View File

@ -20,3 +20,6 @@ email_host_user =
email_host_password =
email_use_tls = True
email_use_ssl = False
[connect]
nav_sort_by = ip

View File

@ -49,6 +49,12 @@ LOG_LEVEL = config.get('base', 'log')
IP = config.get('base', 'ip')
PORT = config.get('base', 'port')
# ======== Connect ==========
try:
NAV_SORT_BY = config.get('connect', 'nav_sort_by')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
NAV_SORT_BY = 'ip'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

View File

@ -326,11 +326,10 @@ def download(request):
FileLog(user=request.user.username, host=' '.join([asset.hostname for asset in asset_select]),
filename=file_path, type='download', remote_ip=remote_ip, result=runner.results).save()
logger.debug(runner.results)
# os.chdir('/tmp')
tmp_dir_name = os.path.basename(upload_dir)
tar_file = '%s.tar.gz' % upload_dir
bash('tar czf %s %s' % (tar_file, tmp_dir_name))
f = open(tar_file)
tar_file = '%s.tar.gz' % tmp_dir_name
bash('cd /tmp && tar czf %s %s' % (tar_file, tmp_dir_name))
f = open('/tmp/%s' % tar_file)
data = f.read()
f.close()
response = HttpResponse(data, content_type='application/octet-stream')

View File

@ -66,12 +66,10 @@ function openTerminal(options) {
} else {
rowHeight = 35
}
;
if (colWidth) {
} else {
colWidth = 100
}
;
var term = new Terminal({
rows: rowHeight,