From 8a86f57304ede7db868e3bbff298f408ae18378d Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 2 Dec 2010 10:01:09 +0100 Subject: [PATCH 01/13] Adding LDAP authentification --- radicale/acl/authLdap.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 radicale/acl/authLdap.py diff --git a/radicale/acl/authLdap.py b/radicale/acl/authLdap.py new file mode 100644 index 0000000..d7c08e6 --- /dev/null +++ b/radicale/acl/authLdap.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import sys, ldap + +from radicale import config + +def has_right(owner, user, password): + if user == None: + user="" + if password == None: + password="" + if owner != user: + return False + try: + l=ldap.open(LDAPSERVER, 389) + cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) + l.simple_bind_s(cn, password); + return True + except: + return False + +LDAPSERVER = config.get("authLdap", "LDAPServer") +LDAPPREPEND = config.get("authLdap", "LDAPPrepend") +LDAPAPPEND = config.get("authLdap", "LDAPAppend") From 77ff57eb725e660960c221b0cdec1f79752665a9 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 2 Dec 2010 16:42:16 +0100 Subject: [PATCH 02/13] Add class for logging in log file --- radicale/log.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 radicale/log.py diff --git a/radicale/log.py b/radicale/log.py new file mode 100644 index 0000000..8c7cc55 --- /dev/null +++ b/radicale/log.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +import sys +import logging + +from radicale import config + +LEVELS = { 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warning': logging.WARNING, + 'error': logging.ERROR, + 'critical': logging.CRITICAL} + +level=LEVELS.get(config.get("logging", "level"), logging.NOTSET) + +logger=logging.getLogger("radicale") +logger.setLevel(level=level) + +handler=logging.FileHandler(config.get("logging", "file")) +handler.setLevel(level=level) + +formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + +handler.setFormatter(formatter) + +logger.addHandler(handler) + +sys.modules[__name__] = logger \ No newline at end of file From 766adcda509b04df0b7182edbc70316d81a757c5 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 2 Dec 2010 16:57:02 +0100 Subject: [PATCH 03/13] os.path.expanduser for logging file name --- radicale/log.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/radicale/log.py b/radicale/log.py index 8c7cc55..b188bf7 100644 --- a/radicale/log.py +++ b/radicale/log.py @@ -2,6 +2,7 @@ import sys import logging +import os from radicale import config @@ -16,7 +17,7 @@ level=LEVELS.get(config.get("logging", "level"), logging.NOTSET) logger=logging.getLogger("radicale") logger.setLevel(level=level) -handler=logging.FileHandler(config.get("logging", "file")) +handler=logging.FileHandler(os.path.expanduser(config.get("logging", "file"))) handler.setLevel(level=level) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") From 8ad91b74b6c4b8a9cc3605bbe26aba1324d8270e Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 2 Dec 2010 17:58:56 +0100 Subject: [PATCH 04/13] cn => dn Default configuration --- config | 19 ++++++++++++++++++- radicale/acl/authLdap.py | 9 +++++---- radicale/config.py | 10 +++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/config b/config index d04b3da..36df1fa 100644 --- a/config +++ b/config @@ -27,7 +27,7 @@ stock = utf-8 [acl] # Access method -# Value: fake | htpasswd +# Value: fake | htpasswd | authLdap type = fake # Personal calendars only available for logged in users (if needed) personal = False @@ -37,9 +37,26 @@ filename = /etc/radicale/users # Value: plain | sha1 | crypt encryption = crypt +[authLdap] +#LDAP Host +LDAPServer = 127.0.0.1 +#Fields to create a LDAP bind +#Value to add before the user name in a LDAP bind +LDAPPrepend = uid= +#Value to add after the user name in a LDAP bind +LDAPAppend = ou=users,dc=exmaple,dc=dom +#=> uid=corentin,ou=users,dc=exmaple,dc=dom + [storage] # Folder for storing local calendars, # created if not present folder = ~/.config/radicale/calendars +[logging] +# Full path of logfile +file = ~/.config/radicale/radicale.log +# Logging messages which are less severe than level will be ignored +# Log level are (debug, info, warning, error, critical) +level = error + # vim:ft=cfg diff --git a/radicale/acl/authLdap.py b/radicale/acl/authLdap.py index d7c08e6..385528b 100644 --- a/radicale/acl/authLdap.py +++ b/radicale/acl/authLdap.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -import sys, ldap +import sys, ldap, syslog -from radicale import config +from radicale import config, log def has_right(owner, user, password): if user == None: @@ -13,10 +13,11 @@ def has_right(owner, user, password): return False try: l=ldap.open(LDAPSERVER, 389) - cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) - l.simple_bind_s(cn, password); + dn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) + l.simple_bind_s(dn, password); return True except: + log.error(sys.exc_info()[0]) return False LDAPSERVER = config.get("authLdap", "LDAPServer") diff --git a/radicale/config.py b/radicale/config.py index 1cf9dd6..509b5f9 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -56,7 +56,15 @@ INITIAL_CONFIG = { "filename": "/etc/radicale/users", "encryption": "crypt"}, "storage": { - "folder": os.path.expanduser("~/.config/radicale/calendars")}} + "folder": os.path.expanduser("~/.config/radicale/calendars")}, + "authLdap": { + "LDAPServer": "127.0.0.1", + "LDAPPrepend": "uid=", + "LDAPAppend": "ou=users,dc=example,dc=com"}, + "logging": { + "file": os.path.expanduser("~/.config/radicale/radicale.log"), + "level": "error"} + } # Create a ConfigParser and configure it _CONFIG_PARSER = ConfigParser() From 55d67e629d5839182cfd3a07f8a20622cfc13d56 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 23 Dec 2010 10:06:37 +0100 Subject: [PATCH 05/13] Logging --- radicale/__init__.py | 2 +- radicale/xmlutils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 2fc3f80..8461f9c 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -46,7 +46,7 @@ except ImportError: import BaseHTTPServer as server # pylint: enable=F0401 -from radicale import acl, config, ical, xmlutils +from radicale import acl, config, ical, xmlutils, log VERSION = "git" diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index b49666c..9f05721 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -84,7 +84,7 @@ def propfind(path, xml_request, calendar, depth, request): """Read and answer PROPFIND requests. Read rfc4918-9.1 for info. - + """ # Reading request root = ET.fromstring(xml_request) @@ -138,7 +138,7 @@ def propfind(path, xml_request, calendar, depth, request): elif tag == _tag("D", "getcontenttype"): element.text = "text/calendar" elif tag == _tag("D", "getetag"): - element.text = element.etag + element.text = element.tag elif tag == _tag("D", "displayname"): element.text = calendar.name elif tag == _tag("D", "supported-report-set"): From 50919133acd0b72f5347595928ebf4dece78bee9 Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Wed, 16 Feb 2011 13:53:27 +0100 Subject: [PATCH 06/13] Logging --- config | 6 ++++++ radicale/__init__.py | 20 +++++++++++++++++++- radicale/acl/authLdap.py | 6 +++++- radicale/config.py | 5 ++++- radicale/log.py | 22 ++++++++++++++++++++++ radicale/xmlutils.py | 10 ++++++++-- 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 radicale/log.py diff --git a/config b/config index d04b3da..83daabf 100644 --- a/config +++ b/config @@ -42,4 +42,10 @@ encryption = crypt # created if not present folder = ~/.config/radicale/calendars +[Logging] +# Logging filename +logfile = ~/.config/radicale/radicale.log +# Log facility 10: DEBUG, 20: INFO, 30 WARNING, 40 ERROR, 50 CRITICAL +facility = 50 + # vim:ft=cfg diff --git a/radicale/__init__.py b/radicale/__init__.py index 2fc3f80..aa7e054 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -46,13 +46,14 @@ except ImportError: import BaseHTTPServer as server # pylint: enable=F0401 -from radicale import acl, config, ical, xmlutils +from radicale import acl, config, ical, xmlutils, log VERSION = "git" def _check(request, function): """Check if user has sufficient rights for performing ``request``.""" + log.log(10, "Check if user has sufficient rights for performing ``request``.") # ``_check`` decorator can access ``request`` protected functions # pylint: disable=W0212 authorization = request.headers.get("Authorization", None) @@ -64,8 +65,10 @@ def _check(request, function): user = password = None if request.server.acl.has_right(request._calendar.owner, user, password): + log.log(20, "Sufficient rights for performing ``request``.") function(request) else: + log.log(40, "No sufficient rights for performing ``request``.") request.send_response(client.UNAUTHORIZED) request.send_header( "WWW-Authenticate", @@ -82,6 +85,7 @@ class HTTPServer(server.HTTPServer): # pylint: disable=W0231 def __init__(self, address, handler): """Create server.""" + log.log(10, "Create HTTP server.") server.HTTPServer.__init__(self, address, handler) self.acl = acl.load() # pylint: enable=W0231 @@ -92,6 +96,7 @@ class HTTPSServer(HTTPServer): PROTOCOL = "https" def __init__(self, address, handler): """Create server by wrapping HTTP socket in an SSL socket.""" + log.log(10, "Create server by wrapping HTTP socket in an SSL socket.") # Fails with Python 2.5, import if needed # pylint: disable=F0401 import ssl @@ -110,6 +115,7 @@ class HTTPSServer(HTTPServer): class CalendarHTTPHandler(server.BaseHTTPRequestHandler): """HTTP requests handler for calendars.""" + log.log(10, "HTTP requests handler for calendars.") _encoding = config.get("encoding", "request") # Decorator checking rights before performing request @@ -118,6 +124,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @property def _calendar(self): """The ``ical.Calendar`` object corresponding to the given path.""" + log.log(10, "The ``ical.Calendar`` object corresponding to the given path.") # ``self.path`` must be something like a posix path # ``normpath`` should clean malformed and malicious request paths attributes = posixpath.normpath(self.path.strip("/")).split("/") @@ -127,6 +134,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): def _decode(self, text): """Try to decode text according to various parameters.""" + log.log(10, "Try to decode text according to various parameters.") # List of charsets to try charsets = [] @@ -153,12 +161,14 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): def do_GET(self): """Manage GET request.""" + log.log(10, "Manage GET request.") self.do_HEAD() self.wfile.write(self._answer) @check_rights def do_HEAD(self): """Manage HEAD request.""" + log.log(10, "Manage HEAD request.") item_name = xmlutils.name_from_path(self.path) if item_name: # Get calendar item @@ -188,6 +198,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_DELETE(self): """Manage DELETE request.""" + log.log(10, "Manage DELETE request.") item = self._calendar.get_item(xmlutils.name_from_path(self.path)) if item and self.headers.get("If-Match", item.etag) == item.etag: # No ETag precondition or precondition verified, delete item @@ -203,6 +214,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): def do_OPTIONS(self): """Manage OPTIONS request.""" + log.log(10, "Manage OPTIONS request.") self.send_response(client.OK) self.send_header( "Allow", "DELETE, HEAD, GET, OPTIONS, PROPFIND, PUT, REPORT") @@ -211,6 +223,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): def do_PROPFIND(self): """Manage PROPFIND request.""" + log.log(10, "Manage PROPFIND request.") xml_request = self.rfile.read(int(self.headers["Content-Length"])) self._answer = xmlutils.propfind( self.path, xml_request, self._calendar, @@ -226,6 +239,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_PUT(self): """Manage PUT request.""" + log.log(10, "Manage PUT request.") item_name = xmlutils.name_from_path(self.path) item = self._calendar.get_item(item_name) if (not item and not self.headers.get("If-Match")) or \ @@ -249,6 +263,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_REPORT(self): """Manage REPORT request.""" + log.log(10, "Manage REPORT request.") xml_request = self.rfile.read(int(self.headers["Content-Length"])) self._answer = xmlutils.report(self.path, xml_request, self._calendar) @@ -257,4 +272,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): self.end_headers() self.wfile.write(self._answer) + def log_message(self, format, *args): + log.log(10, format % (args)) + # pylint: enable=C0103 diff --git a/radicale/acl/authLdap.py b/radicale/acl/authLdap.py index d7c08e6..b8142b5 100644 --- a/radicale/acl/authLdap.py +++ b/radicale/acl/authLdap.py @@ -2,7 +2,7 @@ import sys, ldap -from radicale import config +from radicale import config, log def has_right(owner, user, password): if user == None: @@ -12,11 +12,15 @@ def has_right(owner, user, password): if owner != user: return False try: + log.log(10, "Open LDAP server connexion") l=ldap.open(LDAPSERVER, 389) cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) + log.log(10, "LDAP bind with dn: %s" %(cn)) l.simple_bind_s(cn, password); + log.log(20, "LDAP bind Ok") return True except: + log.log(40, "LDAP bind error") return False LDAPSERVER = config.get("authLdap", "LDAPServer") diff --git a/radicale/config.py b/radicale/config.py index 1cf9dd6..77f34af 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -56,7 +56,10 @@ INITIAL_CONFIG = { "filename": "/etc/radicale/users", "encryption": "crypt"}, "storage": { - "folder": os.path.expanduser("~/.config/radicale/calendars")}} + "folder": os.path.expanduser("~/.config/radicale/calendars")}, + "logging": { + "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), + "facility": 10}} # Create a ConfigParser and configure it _CONFIG_PARSER = ConfigParser() diff --git a/radicale/log.py b/radicale/log.py new file mode 100644 index 0000000..1861e4e --- /dev/null +++ b/radicale/log.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +import logging, sys +from radicale import config + +class log: + def __init__(self): + self.logger=logging.getLogger("radicale") + self.logger.setLevel(config.get("logging", "facility")) + + handler=logging.FileHandler(config.get("logging", "logfile")) + + formatter = logging.Formatter('%(name)s %(asctime)s %(levelname)s %(message)s') + handler.setFormatter(formatter) + + self.logger.addHandler(handler) + def log(self, level, msg): + self.logger.log(level, msg) + +_LOGGING = log() + +sys.modules[__name__] = _LOGGING \ No newline at end of file diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index b49666c..9289e9d 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -31,7 +31,7 @@ in them for XML requests (all but PUT). import xml.etree.ElementTree as ET -from radicale import client, config, ical +from radicale import client, config, ical, log NAMESPACES = { @@ -47,11 +47,13 @@ def _tag(short_name, local): def _response(code): """Return full W3C names from HTTP status codes.""" + log.log(10, "Return full W3C names from HTTP status codes.") return "HTTP/1.1 %i %s" % (code, client.responses[code]) def name_from_path(path): """Return Radicale item name from ``path``.""" + log.log(10, "Return Radicale item name from ``path``.") return path.split("/")[-1] @@ -62,6 +64,7 @@ def delete(path, calendar): """ # Reading request + log.log(10, "Read and answer DELETE requests.") calendar.remove(name_from_path(path)) # Writing answer @@ -87,8 +90,9 @@ def propfind(path, xml_request, calendar, depth, request): """ # Reading request + log.log(10, "Read and answer PROPFIND requests.") root = ET.fromstring(xml_request) - + prop_element = root.find(_tag("D", "prop")) prop_list = prop_element.getchildren() props = [prop.tag for prop in prop_list] @@ -164,6 +168,7 @@ def propfind(path, xml_request, calendar, depth, request): def put(path, ical_request, calendar): """Read PUT requests.""" + log.log(10, "Read PUT requests.") name = name_from_path(path) if name in (item.name for item in calendar.items): # PUT is modifying an existing item @@ -180,6 +185,7 @@ def report(path, xml_request, calendar): """ # Reading request + log.log(10, "Read and answer REPORT requests.") root = ET.fromstring(xml_request) prop_element = root.find(_tag("D", "prop")) From 35e277252b418ba718edc046717e6cf31b6216f9 Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Wed, 16 Feb 2011 14:50:42 +0100 Subject: [PATCH 07/13] Multiple logging sextion in default config --- radicale/config.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/radicale/config.py b/radicale/config.py index b3eb419..ca4b0da 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -63,11 +63,7 @@ INITIAL_CONFIG = { "authLdap": { "LDAPServer": "127.0.0.1", "LDAPPrepend": "uid=", - "LDAPAppend": "ou=users,dc=example,dc=com"}, - "logging": { - "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), - "facility": "error"} - } + "LDAPAppend": "ou=users,dc=example,dc=com"}} # Create a ConfigParser and configure it _CONFIG_PARSER = ConfigParser() From a4024f81831caddd652d0615f21552c9fd8cac17 Mon Sep 17 00:00:00 2001 From: System User Date: Tue, 22 Feb 2011 15:46:42 +0100 Subject: [PATCH 08/13] Logging to stdout, syslog or file --- config | 5 ++++- radicale/config.py | 2 +- radicale/log.py | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config b/config index b1ee131..6380a7f 100644 --- a/config +++ b/config @@ -53,7 +53,10 @@ LDAPAppend = ou=users,dc=exmaple,dc=dom folder = ~/.config/radicale/calendars [Logging] -# Logging filename +# Logging type +# Value: syslog | file | stdout +type = file +# Logging filename (if needed) logfile = ~/.config/radicale/radicale.log # Log facility 10: DEBUG, 20: INFO, 30 WARNING, 40 ERROR, 50 CRITICAL facility = 50 diff --git a/radicale/config.py b/radicale/config.py index 74a315e..17735a0 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -56,7 +56,7 @@ INITIAL_CONFIG = { "storage": { "folder": os.path.expanduser("~/.config/radicale/calendars")}, "logging": { - "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), + "type": "syslog", "facility": 10}, "authLdap": { "LDAPServer": "127.0.0.1", diff --git a/radicale/log.py b/radicale/log.py index 072857a..2692a7e 100644 --- a/radicale/log.py +++ b/radicale/log.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging, sys +from logging.handlers import SysLogHandler from radicale import config class log: @@ -8,8 +9,14 @@ class log: self.logger=logging.getLogger("radicale") self.logger.setLevel(config.get("logging", "facility")) - handler=logging.FileHandler(config.get("logging", "logfile")) - + loggingType=config.get("logging", "type") + if loggingType == "stdout": + handler=logging.StreamHandler(sys.stdout) + elif loggingType == "file": + handler=logging.FileHandler(config.get("logging", "logfile")) + else: + handler=logging.handlers.SysLogHandler("/dev/log") + formatter = logging.Formatter('%(name)s %(asctime)s %(levelname)s %(message)s') handler.setFormatter(formatter) From 6fc00a3197bdee4cf5c725bfbcee1a9a3ca9dab5 Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Tue, 22 Feb 2011 18:13:35 +0100 Subject: [PATCH 09/13] Default logfile --- radicale/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/radicale/config.py b/radicale/config.py index 17735a0..c6bbee4 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -57,6 +57,7 @@ INITIAL_CONFIG = { "folder": os.path.expanduser("~/.config/radicale/calendars")}, "logging": { "type": "syslog", + "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), "facility": 10}, "authLdap": { "LDAPServer": "127.0.0.1", From 6b8db006b67c9afd2f2790b0854adfd2d607d9d5 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 7 Apr 2011 16:27:47 +0200 Subject: [PATCH 10/13] Log most verbose Stdout for default log output --- radicale/__init__.py | 6 +++--- radicale/config.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 18b5426..5253ba5 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -53,7 +53,7 @@ VERSION = "git" def _check(request, function): """Check if user has sufficient rights for performing ``request``.""" - log.log(10, "Check if user has sufficient rights for performing ``request``.") + log.log(10, "Check if user has sufficient rights for performing ``request`` %s." % (request.command)) # ``_check`` decorator can access ``request`` protected functions # pylint: disable=W0212 @@ -70,7 +70,7 @@ def _check(request, function): user = password = None if request.server.acl.has_right(request._calendar.owner, user, password): - log.log(20, "Sufficient rights for performing ``request``.") + log.log(20, "Sufficient rights for performing ``request`` %s." % (request.command)) function(request) else: log.log(40, "No sufficient rights for performing ``request``.") @@ -130,7 +130,7 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @property def _calendar(self): """The ``ical.Calendar`` object corresponding to the given path.""" - log.log(10, "The ``ical.Calendar`` object corresponding to the given path.") + log.log(10, "The ``ical.Calendar`` object corresponding to the given path. (%s)" % (self.path)) # ``self.path`` must be something like a posix path # ``normpath`` should clean malformed and malicious request paths attributes = posixpath.normpath(self.path.strip("/")).split("/") diff --git a/radicale/config.py b/radicale/config.py index c6bbee4..24a7cb0 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -56,7 +56,7 @@ INITIAL_CONFIG = { "storage": { "folder": os.path.expanduser("~/.config/radicale/calendars")}, "logging": { - "type": "syslog", + "type": "stdout", "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), "facility": 10}, "authLdap": { @@ -73,7 +73,7 @@ for section, values in INITIAL_CONFIG.items(): _CONFIG_PARSER.set(section, key, value) _CONFIG_PARSER.read("/etc/radicale/config") -_CONFIG_PARSER.read(os.path.expanduser("~/.config/radicale/config")) +_CONFIG_PARSER.read(os.path.expdanuser("~/.config/radicale/config")) # Wrap config module into ConfigParser instance sys.modules[__name__] = _CONFIG_PARSER From c890d6e55a9f1e3c29a987337edea35b1d36cbde Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Sun, 10 Apr 2011 19:17:35 +0200 Subject: [PATCH 11/13] Merge with radicale/master --- radicale/__init__.py | 45 ++-------------------------------------- radicale/acl/authLdap.py | 44 +++++++++++++++++++-------------------- radicale/config.py | 12 +++-------- 3 files changed, 27 insertions(+), 74 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index ec28966..1a7afbc 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -46,11 +46,7 @@ except ImportError: import BaseHTTPServer as server # pylint: enable=F0401 -<<<<<<< HEAD -from radicale import acl, config, ical, xmlutils, log -======= from radicale import acl, config, ical, log, xmlutils ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 VERSION = "git" @@ -60,17 +56,7 @@ VERSION = "git" def _check(request, function): """Check if user has sufficient rights for performing ``request``.""" -<<<<<<< HEAD - log.log(10, "Check if user has sufficient rights for performing ``request`` %s." % (request.command)) - # ``_check`` decorator can access ``request`` protected functions - # pylint: disable=W0212 - - # If we have no calendar, don't check rights - if not request._calendar: -======= - # If we have no calendar or no acl, don't check rights if not request._calendar or not request.server.acl: ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 return function(request) log.LOGGER.info("Checking rights for %s" % request._calendar.owner) @@ -84,11 +70,9 @@ def _check(request, function): user = password = None if request.server.acl.has_right(request._calendar.owner, user, password): - log.log(20, "Sufficient rights for performing ``request`` %s." % (request.command)) function(request) log.LOGGER.info("%s allowed" % request._calendar.owner) else: - log.log(40, "No sufficient rights for performing ``request``.") request.send_response(client.UNAUTHORIZED) request.send_header( "WWW-Authenticate", @@ -122,8 +106,6 @@ class HTTPServer(server.HTTPServer): # pylint: disable=W0231 def __init__(self, address, handler, bind_and_activate=True): """Create server.""" - log.log(10, "Create HTTP server.") - server.HTTPServer.__init__(self, address, handler) ipv6 = ":" in address[0] if ipv6: @@ -150,7 +132,6 @@ class HTTPSServer(HTTPServer): def __init__(self, address, handler, bind_and_activate=True): """Create server by wrapping HTTP socket in an SSL socket.""" - log.log(10, "Create server by wrapping HTTP socket in an SSL socket.") # Fails with Python 2.5, import if needed # pylint: disable=F0401 import ssl @@ -171,7 +152,6 @@ class HTTPSServer(HTTPServer): class CalendarHTTPHandler(server.BaseHTTPRequestHandler): """HTTP requests handler for calendars.""" - log.log(10, "HTTP requests handler for calendars.") _encoding = config.get("encoding", "request") # Request handlers decorators @@ -191,17 +171,15 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @property def _calendar(self): """The ``ical.Calendar`` object corresponding to the given path.""" - log.log(10, "The ``ical.Calendar`` object corresponding to the given path. (%s)" % (self.path)) # ``self.path`` must be something like a posix path # ``normpath`` should clean malformed and malicious request paths attributes = posixpath.normpath(self.path.strip("/")).split("/") - if len(attributes) >= 2: - path = "%s/%s" % (attributes[0], attributes[1]) + if attributes: + path = "/".join(attributes[:min(len(attributes), 2)]) return ical.Calendar(path) def _decode(self, text): """Try to decode text according to various parameters.""" - log.log(10, "Try to decode text according to various parameters.") # List of charsets to try charsets = [] @@ -232,7 +210,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @log_request_content def do_GET(self): """Manage GET request.""" - log.log(10, "Manage GET request.") self.do_HEAD() if self._answer: self.wfile.write(self._answer) @@ -241,7 +218,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_HEAD(self): """Manage HEAD request.""" - log.log(10, "Manage HEAD request.") item_name = xmlutils.name_from_path(self.path) if item_name: # Get calendar item @@ -273,7 +249,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_DELETE(self): """Manage DELETE request.""" - log.log(10, "Manage DELETE request.") item = self._calendar.get_item(xmlutils.name_from_path(self.path)) if item and self.headers.get("If-Match", item.etag) == item.etag: # No ETag precondition or precondition verified, delete item @@ -297,7 +272,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @log_request_content def do_OPTIONS(self): """Manage OPTIONS request.""" - log.log(10, "Manage OPTIONS request.") self.send_response(client.OK) self.send_header( "Allow", "DELETE, HEAD, GET, MKCALENDAR, " @@ -308,11 +282,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @log_request_content def do_PROPFIND(self): """Manage PROPFIND request.""" -<<<<<<< HEAD - log.log(10, "Manage PROPFIND request.") - xml_request = self.rfile.read(int(self.headers["Content-Length"])) -======= ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 self._answer = xmlutils.propfind( self.path, self._content, self._calendar, self.headers.get("depth", "infinity")) @@ -328,7 +297,6 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_PUT(self): """Manage PUT request.""" - log.log(10, "Manage PUT request.") item_name = xmlutils.name_from_path(self.path) item = self._calendar.get_item(item_name) if (not item and not self.headers.get("If-Match")) or \ @@ -352,20 +320,11 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler): @check_rights def do_REPORT(self): """Manage REPORT request.""" -<<<<<<< HEAD - log.log(10, "Manage REPORT request.") - xml_request = self.rfile.read(int(self.headers["Content-Length"])) - self._answer = xmlutils.report(self.path, xml_request, self._calendar) -======= self._answer = xmlutils.report(self.path, self._content, self._calendar) ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 self.send_response(client.MULTI_STATUS) self.send_header("Content-Length", len(self._answer)) self.end_headers() self.wfile.write(self._answer) - def log_message(self, format, *args): - log.log(10, format % (args)) - # pylint: enable=C0103 diff --git a/radicale/acl/authLdap.py b/radicale/acl/authLdap.py index b80964a..c9c67d2 100644 --- a/radicale/acl/authLdap.py +++ b/radicale/acl/authLdap.py @@ -1,28 +1,28 @@ # -*- coding: utf-8 -*- -import sys, ldap, syslog - -from radicale import config, log - -def has_right(owner, user, password): - if user == None: - user="" - if password == None: - password="" - if owner != user: - return False - try: - log.log(10, "Open LDAP server connexion") - l=ldap.open(LDAPSERVER, 389) - cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) - log.log(10, "LDAP bind with dn: %s" %(cn)) - l.simple_bind_s(cn, password); - log.log(20, "LDAP bind Ok") - return True - except: - log.log(40, "LDAP bind error") - return False +import sys +import ldap +import radicale LDAPSERVER = config.get("authLdap", "LDAPServer") LDAPPREPEND = config.get("authLdap", "LDAPPrepend") LDAPAPPEND = config.get("authLdap", "LDAPAppend") + +def has_right(owner, user, password): + if user == None: + user="" + if password == None: + password="" + if owner != user: + return False + try: + radicale.log.LOGGER.info("Open LDAP server connexion") + l=ldap.open(LDAPSERVER, 389) + cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) + radicale.log.LOGGER.info("LDAP bind with dn: %s" % (cn)) + l.simple_bind_s(cn, password); + radicale.log.LOGGER.info("LDAP bind ok") + return True + except: + radicale.log.LOGGER.info("Nu such credential") + return False diff --git a/radicale/config.py b/radicale/config.py index 4ef8434..c285ca0 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -55,18 +55,12 @@ INITIAL_CONFIG = { "storage": { "folder": os.path.expanduser("~/.config/radicale/calendars")}, "logging": { -<<<<<<< HEAD - "type": "stdout", - "logfile": os.path.expanduser("~/.config/radicale/radicale.log"), - "facility": 10}, + "config": "/etc/radicale/logging", + "debug": "False"}, "authLdap": { "LDAPServer": "127.0.0.1", "LDAPPrepend": "uid=", "LDAPAppend": "ou=users,dc=example,dc=com"}} -======= - "config": "/etc/radicale/logging", - "debug": "False"}} ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 # Create a ConfigParser and configure it _CONFIG_PARSER = ConfigParser() @@ -77,7 +71,7 @@ for section, values in INITIAL_CONFIG.items(): _CONFIG_PARSER.set(section, key, value) _CONFIG_PARSER.read("/etc/radicale/config") -_CONFIG_PARSER.read(os.path.expdanuser("~/.config/radicale/config")) +_CONFIG_PARSER.read(os.path.expanduser("~/.config/radicale/config")) # Wrap config module into ConfigParser instance sys.modules[__name__] = _CONFIG_PARSER From 938aa85aed79e10e0b969231d003dc995e4527eb Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Sun, 10 Apr 2011 19:19:59 +0200 Subject: [PATCH 12/13] Coninuing the merge --- radicale/xmlutils.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 0f926ea..19e3380 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -45,13 +45,11 @@ def _tag(short_name, local): def _response(code): """Return full W3C names from HTTP status codes.""" - log.log(10, "Return full W3C names from HTTP status codes.") return "HTTP/1.1 %i %s" % (code, client.responses[code]) def name_from_path(path): """Return Radicale item name from ``path``.""" - log.log(10, "Return Radicale item name from ``path``.") path_parts = path.strip("/").split("/") return path_parts[-1] if len(path_parts) >= 2 else None @@ -63,7 +61,6 @@ def delete(path, calendar): """ # Reading request - log.log(10, "Read and answer DELETE requests.") calendar.remove(name_from_path(path)) # Writing answer @@ -89,7 +86,6 @@ def propfind(path, xml_request, calendar, depth): """ # Reading request - log.log(10, "Read and answer PROPFIND requests.") root = ET.fromstring(xml_request) prop_element = root.find(_tag("D", "prop")) @@ -177,7 +173,6 @@ def propfind(path, xml_request, calendar, depth): def put(path, ical_request, calendar): """Read PUT requests.""" - log.log(10, "Read PUT requests.") name = name_from_path(path) if name in (item.name for item in calendar.items): # PUT is modifying an existing item @@ -194,7 +189,6 @@ def report(path, xml_request, calendar): """ # Reading request - log.log(10, "Read and answer REPORT requests.") root = ET.fromstring(xml_request) prop_element = root.find(_tag("D", "prop")) From 643c074dcbc0fac445f567730cf1a8c4092dcfc9 Mon Sep 17 00:00:00 2001 From: Corentin Le Bail Date: Sun, 10 Apr 2011 19:21:44 +0200 Subject: [PATCH 13/13] Merge... --- config | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/config b/config index 35dd3f2..03e1457 100644 --- a/config +++ b/config @@ -28,13 +28,8 @@ stock = utf-8 [acl] # Access method -<<<<<<< HEAD -# Value: fake | htpasswd | authLdap -type = fake -======= # Value: None | htpasswd type = None ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 # Personal calendars only available for logged in users (if needed) personal = False # Htpasswd filename (if needed) @@ -58,16 +53,6 @@ LDAPAppend = ou=users,dc=exmaple,dc=dom # created if not present folder = ~/.config/radicale/calendars -<<<<<<< HEAD -[Logging] -# Logging type -# Value: syslog | file | stdout -type = file -# Logging filename (if needed) -logfile = ~/.config/radicale/radicale.log -# Log facility 10: DEBUG, 20: INFO, 30 WARNING, 40 ERROR, 50 CRITICAL -facility = 50 -======= [logging] # Logging configuration file # If no config is given, simple information is printed on the standard output @@ -76,6 +61,5 @@ facility = 50 config = /etc/radicale/logging # Set the default logging level to debug debug = False ->>>>>>> d9ea784e31687b03f1451bc5b543122f05c5deb1 # vim:ft=cfg