| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/python
- # -*- coding: utf-8; indent-tabs-mode: nil; -*-
- #
- # This file is part of Radicale Server - Calendar Server
- # Copyright © 2008-2009 Guillaume Ayoub
- # Copyright © 2008 Nicolas Kandel
- # Copyright © 2008 Pascal Halter
- #
- # This library is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
- # TODO: Manage depth and calendars/collections (see xmlutils)
- # TODO: Manage smart and configurable logs
- # TODO: Manage authentication
- # TODO: Magage command-line options
- # TODO: Forget twisted?
- """
- Radicale Server entry point.
- Launch the Radicale Serve according to the configuration.
- """
- import sys
- from twisted.web import server
- from twisted.internet import reactor
- from twisted.python import log
- import radicale
- class ServerContextFactory(object):
- """SSL context factory."""
- def get_context(self):
- """Get SSL context for the HTTP server."""
- from OpenSSL import SSL
- context = SSL.Context(SSL.SSLv23_METHOD)
- context.use_certificate_file(radicale.config.get("server", "certificate"))
- context.use_privatekey_file(radicale.config.get("server", "privatekey"))
- return context
- log.startLogging(sys.stdout)
- #log.startLogging(open(radicale.config.get("server", "log"), "w"))
- factory = server.Site(radicale.HttpResource())
- if radicale.config.get("server", "type") == "http":
- reactor.listenTCP(radicale.config.getint("server", "port"), factory)
- elif radicale.config.get("server", "type") == "https":
- reactor.listenSSL(radicale.config.getint("server", "port"), factory, ServerContextFactory())
- reactor.run()
|