radicale.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 The Radicale Team
  6. #
  7. # This library is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  19. # TODO: Manage depth and calendars/collections (see xmlutils)
  20. # TODO: Manage smart and configurable logs
  21. # TODO: Manage authentication
  22. # TODO: remove this hack
  23. import sys
  24. sys.path.append("/usr/local/lib/python2.5/site-packages")
  25. from twisted.web import server
  26. from twisted.internet import reactor
  27. from twisted.python import log
  28. import radicale
  29. class ServerContextFactory(object):
  30. """
  31. SSL context factory
  32. """
  33. def getContext(self):
  34. """
  35. Get SSL context for the HTTP server
  36. """
  37. from OpenSSL import SSL
  38. ctx = SSL.Context(SSL.SSLv23_METHOD)
  39. ctx.use_certificate_file(radicale.config.get("server", "certificate"))
  40. ctx.use_privatekey_file(radicale.config.get("server", "privatekey"))
  41. return ctx
  42. log.startLogging(sys.stdout)
  43. #log.startLogging(open(radicale.config.get("server", "log"), "w"))
  44. factory = server.Site(radicale.HttpResource())
  45. if radicale.config.get("server", "type") == "http":
  46. reactor.listenTCP(radicale.config.getint("server", "port"), factory)
  47. elif radicale.config.get("server", "type") == "https":
  48. reactor.listenSSL(radicale.config.getint("server", "port"), factory, ServerContextFactory())
  49. reactor.run()