Clean owner-less calendars support (fixes #254)
This commit is contained in:
		@@ -175,14 +175,9 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
 | 
				
			|||||||
        # ``self.path`` must be something like a posix path
 | 
					        # ``self.path`` must be something like a posix path
 | 
				
			||||||
        # ``normpath`` should clean malformed and malicious request paths
 | 
					        # ``normpath`` should clean malformed and malicious request paths
 | 
				
			||||||
        attributes = posixpath.normpath(self.path.strip("/")).split("/")
 | 
					        attributes = posixpath.normpath(self.path.strip("/")).split("/")
 | 
				
			||||||
        if len(attributes) >= 2:
 | 
					        if attributes:
 | 
				
			||||||
            path = "%s/%s" % (attributes[0], attributes[1])
 | 
					            path = "/".join(attributes[:min(len(attributes), 2)])
 | 
				
			||||||
        elif len(attributes) == 1: # no owner
 | 
					            return ical.Calendar(path)
 | 
				
			||||||
            path = attributes[0]
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            return
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        return ical.Calendar(path)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _decode(self, text):
 | 
					    def _decode(self, text):
 | 
				
			||||||
        """Try to decode text according to various parameters."""
 | 
					        """Try to decode text according to various parameters."""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,7 +56,8 @@ def _sha1(hash_value, password):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def has_right(owner, user, password):
 | 
					def has_right(owner, user, password):
 | 
				
			||||||
    """Check if ``user``/``password`` couple is valid."""
 | 
					    """Check if ``user``/``password`` couple is valid."""
 | 
				
			||||||
    if owner is None: # no owner - everybody is allowed
 | 
					    if owner is None and PERSONAL:
 | 
				
			||||||
 | 
					        # No owner and personal calendars, everybody is allowed
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for line in open(FILENAME).readlines():
 | 
					    for line in open(FILENAME).readlines():
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -135,16 +135,9 @@ class Calendar(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __init__(self, path):
 | 
					    def __init__(self, path):
 | 
				
			||||||
        """Initialize the calendar with ``cal`` and ``user`` parameters."""
 | 
					        """Initialize the calendar with ``cal`` and ``user`` parameters."""
 | 
				
			||||||
 | 
					 | 
				
			||||||
        split_path = path.split("/")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.encoding = "utf-8"
 | 
					        self.encoding = "utf-8"
 | 
				
			||||||
        
 | 
					        split_path = path.split("/")
 | 
				
			||||||
        if len(split_path) > 1:
 | 
					        self.owner = split_path[0] if len(split_path) > 1 else None
 | 
				
			||||||
            self.owner = split_path[0]
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            self.owner = None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.path = os.path.join(FOLDER, path.replace("/", os.path.sep))
 | 
					        self.path = os.path.join(FOLDER, path.replace("/", os.path.sep))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user