radicale.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 OpenSSL import SSL
  26. from twisted.web import server
  27. from twisted.internet import reactor
  28. from twisted.python import log
  29. import radicale
  30. class ServerContextFactory(object):
  31. """
  32. SSL context factory
  33. """
  34. def getContext(self):
  35. """
  36. Get SSL context for the HTTP server
  37. """
  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. reactor.listenSSL(radicale.config.getint("server", "port"), factory, ServerContextFactory())
  46. reactor.run()