summaryrefslogtreecommitdiff
path: root/src/leap/soledad/server/server.tac
blob: 1a4e53ee684ba5547668bb89181e87d328380d13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import os

from twisted.application import service, strports
from twisted.web import server
from twisted.python import log

from leap.soledad.server import entrypoints

application = service.Application('soledad-server')

# local entrypoint
local_port = os.getenv('LOCAL_SERVICES_PORT', 2525)
local_description = 'tcp:%s:interface=127.0.0.1' % local_port
local_site = server.Site(entrypoints.LocalServicesEntrypoint())

local_server = strports.service(local_description, local_site)
local_server.setServiceParent(application)

# public entrypoint
port = os.getenv('HTTPS_PORT', None)
if port == local_port:
    log.err("LOCAL_SERVICES_PORT and HTTPS_PORT can't be the same!")
    sys.exit(20)
if port:
    privateKey = os.getenv('PRIVKEY_PATH', '/etc/soledad/soledad-server.key')
    certKey = os.getenv('CERT_PATH', '/etc/soledad/soledad-server.pem')
    sslmethod = os.getenv('SSL_METHOD', 'SSLv23_METHOD')

    public_description = ':'.join([
        'ssl',
        'port=' + str(port),
        'privateKey=' + privateKey,
        'certKey=' + certKey,
        'sslmethod=' + sslmethod])
elif os.getenv('DEBUG_SERVER', False):
    public_description = 'tcp:port=2424:interface=0.0.0.0'
else:
    log.err("HTTPS_PORT env var is required to be set!")
    sys.exit(20)

public_site = server.Site(entrypoints.SoledadEntrypoint())

public_server = strports.service(public_description, public_site)
public_server.setServiceParent(application)