mirror of https://github.com/zulip/zulip.git
settings: Split hostname from port more carefully.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
fa89d1b266
commit
7f46886696
|
@ -17,6 +17,7 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Any, Dict, List, Sequence, Set
|
from typing import Any, Dict, List, Sequence, Set
|
||||||
|
from urllib.parse import SplitResult
|
||||||
|
|
||||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||||
|
@ -515,6 +516,13 @@ def get_or_create_dev_uuid_var_path(path: str) -> str:
|
||||||
def is_vagrant_env_host(path: str) -> bool:
|
def is_vagrant_env_host(path: str) -> bool:
|
||||||
return '.vagrant' in os.listdir(path)
|
return '.vagrant' in os.listdir(path)
|
||||||
|
|
||||||
|
def deport(netloc: str) -> str:
|
||||||
|
"""Remove the port from a hostname:port string. Brackets on a literal
|
||||||
|
IPv6 address are included."""
|
||||||
|
r = SplitResult("", netloc, "", "", "")
|
||||||
|
assert r.hostname is not None
|
||||||
|
return "[" + r.hostname + "]" if ":" in r.hostname else r.hostname
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
if cmd == 'make_deploy_path':
|
if cmd == 'make_deploy_path':
|
||||||
|
|
|
@ -33,6 +33,7 @@ from .configured_settings import (
|
||||||
ERROR_REPORTING,
|
ERROR_REPORTING,
|
||||||
EVENT_LOGS_ENABLED,
|
EVENT_LOGS_ENABLED,
|
||||||
EXTERNAL_HOST,
|
EXTERNAL_HOST,
|
||||||
|
EXTERNAL_HOST_WITHOUT_PORT,
|
||||||
EXTERNAL_URI_SCHEME,
|
EXTERNAL_URI_SCHEME,
|
||||||
EXTRA_INSTALLED_APPS,
|
EXTRA_INSTALLED_APPS,
|
||||||
GOOGLE_OAUTH2_CLIENT_ID,
|
GOOGLE_OAUTH2_CLIENT_ID,
|
||||||
|
@ -159,8 +160,7 @@ USE_X_FORWARDED_HOST = True
|
||||||
# Extend ALLOWED_HOSTS with localhost (needed to RPC to Tornado),
|
# Extend ALLOWED_HOSTS with localhost (needed to RPC to Tornado),
|
||||||
ALLOWED_HOSTS += ['127.0.0.1', 'localhost']
|
ALLOWED_HOSTS += ['127.0.0.1', 'localhost']
|
||||||
# ... with hosts corresponding to EXTERNAL_HOST,
|
# ... with hosts corresponding to EXTERNAL_HOST,
|
||||||
ALLOWED_HOSTS += [EXTERNAL_HOST.split(":")[0],
|
ALLOWED_HOSTS += [EXTERNAL_HOST_WITHOUT_PORT, "." + EXTERNAL_HOST_WITHOUT_PORT]
|
||||||
'.' + EXTERNAL_HOST.split(":")[0]]
|
|
||||||
# ... and with the hosts in REALM_HOSTS.
|
# ... and with the hosts in REALM_HOSTS.
|
||||||
ALLOWED_HOSTS += REALM_HOSTS.values()
|
ALLOWED_HOSTS += REALM_HOSTS.values()
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,36 @@
|
||||||
|
import os
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||||
|
|
||||||
|
from scripts.lib.zulip_tools import deport
|
||||||
|
|
||||||
|
from .config import DEVELOPMENT, PRODUCTION, get_secret
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from django_auth_ldap.config import LDAPSearch
|
from django_auth_ldap.config import LDAPSearch
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
from .config import DEVELOPMENT, PRODUCTION, get_secret
|
|
||||||
|
|
||||||
if PRODUCTION:
|
if PRODUCTION:
|
||||||
from .prod_settings import EXTERNAL_HOST, ZULIP_ADMINISTRATOR
|
from .prod_settings import EXTERNAL_HOST, ZULIP_ADMINISTRATOR
|
||||||
else:
|
else:
|
||||||
from .dev_settings import EXTERNAL_HOST, ZULIP_ADMINISTRATOR
|
from .dev_settings import EXTERNAL_HOST, ZULIP_ADMINISTRATOR
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
DEBUG = DEVELOPMENT
|
DEBUG = DEVELOPMENT
|
||||||
|
|
||||||
|
EXTERNAL_HOST_WITHOUT_PORT = deport(EXTERNAL_HOST)
|
||||||
|
|
||||||
# These settings are intended for the server admin to set. We document them in
|
# These settings are intended for the server admin to set. We document them in
|
||||||
# prod_settings_template.py, and in the initial /etc/zulip/settings.py on a new
|
# prod_settings_template.py, and in the initial /etc/zulip/settings.py on a new
|
||||||
# install of the Zulip server.
|
# install of the Zulip server.
|
||||||
|
|
||||||
# Extra HTTP "Host" values to allow (standard ones added in settings.py)
|
# Extra HTTP "Host" values to allow (standard ones added in computed_settings.py)
|
||||||
ALLOWED_HOSTS: List[str] = []
|
ALLOWED_HOSTS: List[str] = []
|
||||||
|
|
||||||
# Basic email settings
|
# Basic email settings
|
||||||
NOREPLY_EMAIL_ADDRESS = "noreply@" + EXTERNAL_HOST.split(":")[0]
|
NOREPLY_EMAIL_ADDRESS = "noreply@" + EXTERNAL_HOST_WITHOUT_PORT
|
||||||
ADD_TOKENS_TO_NOREPLY_ADDRESS = True
|
ADD_TOKENS_TO_NOREPLY_ADDRESS = True
|
||||||
TOKENIZED_NOREPLY_EMAIL_ADDRESS = "noreply-{token}@" + EXTERNAL_HOST.split(":")[0]
|
TOKENIZED_NOREPLY_EMAIL_ADDRESS = "noreply-{token}@" + EXTERNAL_HOST_WITHOUT_PORT
|
||||||
PHYSICAL_ADDRESS = ''
|
PHYSICAL_ADDRESS = ''
|
||||||
FAKE_EMAIL_DOMAIN = EXTERNAL_HOST.split(":")[0]
|
FAKE_EMAIL_DOMAIN = EXTERNAL_HOST_WITHOUT_PORT
|
||||||
|
|
||||||
# SMTP settings
|
# SMTP settings
|
||||||
EMAIL_HOST: Optional[str] = None
|
EMAIL_HOST: Optional[str] = None
|
||||||
|
|
|
@ -2,6 +2,8 @@ import os
|
||||||
import pwd
|
import pwd
|
||||||
from typing import Optional, Set, Tuple
|
from typing import Optional, Set, Tuple
|
||||||
|
|
||||||
|
from six.moves.urllib.parse import SplitResult
|
||||||
|
|
||||||
ZULIP_ADMINISTRATOR = "desdemona+admin@zulip.com"
|
ZULIP_ADMINISTRATOR = "desdemona+admin@zulip.com"
|
||||||
|
|
||||||
# We want LOCAL_UPLOADS_DIR to be an absolute path so that code can
|
# We want LOCAL_UPLOADS_DIR to be an absolute path so that code can
|
||||||
|
@ -37,6 +39,12 @@ else:
|
||||||
'zulip': EXTERNAL_HOST,
|
'zulip': EXTERNAL_HOST,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: Replace with scripts.lib.zulip_tools.deport when this no longer needs to
|
||||||
|
# be Python 2 compatible for zthumbor.
|
||||||
|
r = SplitResult("", EXTERNAL_HOST, "", "", "")
|
||||||
|
assert r.hostname is not None
|
||||||
|
EXTERNAL_HOST_WITHOUT_PORT = "[" + r.hostname + "]" if ":" in r.hostname else r.hostname
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
# Uncomment extra backends if you want to test with them. Note that
|
# Uncomment extra backends if you want to test with them. Note that
|
||||||
|
@ -53,7 +61,7 @@ AUTHENTICATION_BACKENDS = (
|
||||||
) # type: Tuple[str, ...]
|
) # type: Tuple[str, ...]
|
||||||
|
|
||||||
EXTERNAL_URI_SCHEME = "http://"
|
EXTERNAL_URI_SCHEME = "http://"
|
||||||
EMAIL_GATEWAY_PATTERN = "%s@" + EXTERNAL_HOST.split(':')[0]
|
EMAIL_GATEWAY_PATTERN = "%s@" + EXTERNAL_HOST_WITHOUT_PORT
|
||||||
NOTIFICATION_BOT = "notification-bot@zulip.com"
|
NOTIFICATION_BOT = "notification-bot@zulip.com"
|
||||||
ERROR_BOT = "error-bot@zulip.com"
|
ERROR_BOT = "error-bot@zulip.com"
|
||||||
EMAIL_GATEWAY_BOT = "emailgateway@zulip.com"
|
EMAIL_GATEWAY_BOT = "emailgateway@zulip.com"
|
||||||
|
|
Loading…
Reference in New Issue