From 38e8e8734d79d1ed8609476db51b9f8b40afd9df Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 24 Jul 2023 17:49:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0=20DEBUG=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/conf.py | 3 +-- apps/jumpserver/settings/base.py | 37 +++++++++++++++++++++-------- requirements/requirements_xpack.txt | 8 +++---- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/apps/jumpserver/conf.py b/apps/jumpserver/conf.py index 711edf657..1de30cd86 100644 --- a/apps/jumpserver/conf.py +++ b/apps/jumpserver/conf.py @@ -514,10 +514,9 @@ class Config(dict): 'TIME_ZONE': 'Asia/Shanghai', 'FORCE_SCRIPT_NAME': '', 'SESSION_COOKIE_SECURE': False, - 'ALLOWED_HOSTS': '', + 'TRUST_SITES': '', 'CSRF_COOKIE_SECURE': False, 'REFERER_CHECK_ENABLED': False, - 'CSRF_TRUSTED_ORIGINS': '', 'SESSION_ENGINE': 'cache', 'SESSION_SAVE_EVERY_REQUEST': True, 'SESSION_EXPIRE_AT_BROWSER_CLOSE_FORCE': False, diff --git a/apps/jumpserver/settings/base.py b/apps/jumpserver/settings/base.py index 551e4ae8a..fc3ba19ad 100644 --- a/apps/jumpserver/settings/base.py +++ b/apps/jumpserver/settings/base.py @@ -67,21 +67,38 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # LOG LEVEL LOG_LEVEL = CONFIG.LOG_LEVEL +DOMAINS = CONFIG.DOMAINS or CONFIG.SITE_URL +ALLOWED_DOMAINS = DOMAINS.split(',') if DOMAINS else ['localhost:8080'] +ALLOWED_DOMAINS = [host.strip() for host in ALLOWED_DOMAINS] +ALLOWED_DOMAINS = [host.replace('http://', '').replace('https://', '') for host in ALLOWED_DOMAINS if host] +ALLOWED_DOMAINS = [host.split('/')[0] for host in ALLOWED_DOMAINS if host] -ALLOWED_HOSTS = CONFIG.ALLOWED_HOSTS.split(',') if CONFIG.ALLOWED_HOSTS else ['localhost', '127.0.0.1'] +DEBUG_HOSTS = ['127.0.0.1', 'localhost'] +DEBUG_PORT = ['8080', '80', '443', '4200', '9528'] +if DEBUG: + for host in DEBUG_HOSTS: + for port in DEBUG_PORT: + ALLOWED_DOMAINS.append('{}:{}'.format(host, port)) + +ALLOWED_HOSTS = list(set(['.' + host.split(':')[0] for host in ALLOWED_DOMAINS])) + +print("ALLOWED_HOSTS: ", ALLOWED_HOSTS) # https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS CSRF_TRUSTED_ORIGINS = [] -for origin in ALLOWED_HOSTS: - # 避免错误 先判断一下吧 - if origin.startswith('http'): - CSRF_TRUSTED_ORIGINS.append(origin) - continue - if origin.startswith('.'): - origin = '*.' - for schema in ['https', 'http']: - CSRF_TRUSTED_ORIGINS.append('{}://{}'.format(schema, origin)) +for host in ALLOWED_DOMAINS: + host = host.strip('.') + if host.startswith('http'): + CSRF_TRUSTED_ORIGINS.append(host) + continue + for schema in ['https', 'http']: + # CSRF_TRUSTED_ORIGINS.append('{}://{}'.format(schema, host)) + CSRF_TRUSTED_ORIGINS.append('{}://*.{}'.format(schema, host)) + +print("CSRF_TRUSTED_ORIGINS: ") +for origin in CSRF_TRUSTED_ORIGINS: + print(' - ' + origin) # Max post update field num DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000 diff --git a/requirements/requirements_xpack.txt b/requirements/requirements_xpack.txt index 0c62395e7..f7644fb05 100644 --- a/requirements/requirements_xpack.txt +++ b/requirements/requirements_xpack.txt @@ -7,16 +7,14 @@ azure-mgmt-network==23.1.0 google-cloud-compute==1.13.0 grpcio==1.56.2 alibabacloud_dysmsapi20170525==2.0.24 -python-novaclient==11.0.1 +python-novaclient==18.3.0 python-keystoneclient==5.1.0 bce-python-sdk==0.8.87 tencentcloud-sdk-python==3.0.941 aliyun-python-sdk-core-v3==2.13.33 aliyun-python-sdk-ecs==4.24.64 -huaweicloud-sdk-python==1.0.28 -# python-keystoneclient need keystoneauth1>=3.4.0 -# huaweicloud-sdk-python need keystoneauth1<=3.4.0 -keystoneauth1==3.4.0 +#huaweicloud-sdk-python==1.0.28 +keystoneauth1==5.2.1 # DB requirements oracledb==1.3.2 psycopg2-binary==2.9.6