mirror of https://github.com/jumpserver/jumpserver
TTY nav sort by ip / hostname / none (#198)
* TTY nav sort by ip / hostname / none * add newline at end of filepull/207/head
parent
35cc966132
commit
288a42663a
16
connect.py
16
connect.py
|
@ -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():
|
||||
"""
|
||||
|
|
|
@ -20,3 +20,6 @@ email_host_user =
|
|||
email_host_password =
|
||||
email_use_tls = True
|
||||
email_use_ssl = False
|
||||
|
||||
[connect]
|
||||
nav_sort_by = ip
|
||||
|
|
|
@ -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/
|
||||
|
||||
|
|
Loading…
Reference in New Issue