radicale.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python
  2. # -*- coding: utf-8; indent-tabs-mode: nil; -*-
  3. #
  4. # This file is part of Radicale Server - Calendar Server
  5. # Copyright © 2008-2009 Guillaume Ayoub
  6. # Copyright © 2008 Nicolas Kandel
  7. # Copyright © 2008 Pascal Halter
  8. #
  9. # This library is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  21. # TODO: Manage depth and calendars/collections (see xmlutils)
  22. # TODO: Manage smart and configurable logs
  23. # TODO: Manage authentication
  24. # TODO: Magage command-line options
  25. # TODO: Forget twisted?
  26. """
  27. Radicale Server entry point.
  28. Launch the Radicale Serve according to the configuration.
  29. """
  30. import sys
  31. from twisted.web import server
  32. from twisted.internet import reactor
  33. from twisted.python import log
  34. import radicale
  35. class ServerContextFactory(object):
  36. """SSL context factory."""
  37. def get_context(self):
  38. """Get SSL context for the HTTP server."""
  39. from OpenSSL import SSL
  40. context = SSL.Context(SSL.SSLv23_METHOD)
  41. context.use_certificate_file(radicale.config.get("server", "certificate"))
  42. context.use_privatekey_file(radicale.config.get("server", "privatekey"))
  43. return context
  44. log.startLogging(sys.stdout)
  45. #log.startLogging(open(radicale.config.get("server", "log"), "w"))
  46. factory = server.Site(radicale.HttpResource())
  47. if radicale.config.get("server", "type") == "http":
  48. reactor.listenTCP(radicale.config.getint("server", "port"), factory)
  49. elif radicale.config.get("server", "type") == "https":
  50. reactor.listenSSL(radicale.config.getint("server", "port"), factory, ServerContextFactory())
  51. reactor.run()