Пример #1
0
    def run(self):
        try:
            if self.url:
                self.collection = CollectionStorer(self.url,
                                                   validateResourceNames=False)

            authFailures = 0
            while authFailures < 2:
                try:
                    self.result = self.collection.getCollectionContents()
                    if self.collection.getSpecificOption("set-cookie"):
                        self.collection.connection.cookie = self.collection.getSpecificOption(
                            "set-cookie")
                        self.cookie = self.collection.getSpecificOption(
                            "set-cookie")
                    break
                except AuthorizationError, e:
                    if e.authType == "Basic":
                        self.collection.connection.addBasicAuthorization(
                            self.auth["user"], self.auth["password"])
                    elif e.authType == "Digest":
                        info = parseDigestAuthInfo(e.authInfo)
                        self.collection.connection.addDigestAuthorization(
                            self.auth["user"],
                            self.auth["password"],
                            realm=info["realm"],
                            qop=info["qop"],
                            nonce=info["nonce"])
                    else:
                        self.error = "Error: " + str(e)

                    authFailures += 1

        except Exception, e:
            self.error = "Error: " + str(e)
Пример #2
0
    def _createConnection(self):
        """ Overwrites template method for connection creation. """

        protocol = self._configuration.protocol
        hostname = self._configuration.hostname
        port = self._configuration.port
        connection = Connection(hostname, port, protocol=protocol)
        baseCollection = CollectionStorer(self._configuration.basePath, connection)
        try:
            try:
                baseCollection.validate()
            except AuthorizationError, error:
                username = self._configuration.username or ""
                password = self._configuration.password or ""
                if error.authType == "Basic":
                    realm = re.search('realm="([^"]+)"', error.authInfo)
                    if not realm is None:
                        realm = realm.group(1)
                    connection.addBasicAuthorization(username, password, realm)
                elif error.authType == "Digest":
                    authInfo = parseDigestAuthInfo(error.authInfo)
                    connection.addDigestAuthorization(username, password, 
                                                      realm=authInfo["realm"], qop=authInfo["qop"], nonce=authInfo["nonce"])
                else:
                    raise PersistenceError("Cannot create connection. Authentication type '%s' is not supported.")
        except (AttributeError, WebdavError), error:
            errorMessage = "Cannot create connection.\nReason:'%s'" % error.reason
            raise PersistenceError(errorMessage)
Пример #3
0
    def _createConnection(self):
        """ Overwrites template method for connection creation. """

        protocol = self._configuration.protocol
        hostname = self._configuration.hostname
        port = self._configuration.port
        connection = Connection(hostname, port, protocol=protocol)
        baseCollection = CollectionStorer(self._configuration.basePath,
                                          connection)
        try:
            try:
                baseCollection.validate()
            except AuthorizationError, error:
                username = self._configuration.username or ""
                password = self._configuration.password or ""
                if error.authType == "Basic":
                    realm = re.search('realm="([^"]+)"', error.authInfo)
                    if not realm is None:
                        realm = realm.group(1)
                    connection.addBasicAuthorization(username, password, realm)
                elif error.authType == "Digest":
                    authInfo = parseDigestAuthInfo(error.authInfo)
                    connection.addDigestAuthorization(username,
                                                      password,
                                                      realm=authInfo["realm"],
                                                      qop=authInfo["qop"],
                                                      nonce=authInfo["nonce"])
                else:
                    raise PersistenceError(
                        "Cannot create connection. Authentication type '%s' is not supported."
                    )
        except (AttributeError, WebdavError), error:
            errorMessage = "Cannot create connection.\nReason:'%s'" % error.reason
            raise PersistenceError(errorMessage)
Пример #4
0
    def createConnection(self, webdavLogin, webdavPasswd):
        from webdav.WebdavClient import CollectionStorer, AuthorizationError, \
            parseDigestAuthInfo
        #from webdav.logger import _defaultLoggerName

        isConnected = False
        webdavConnection = CollectionStorer(self.webdavHost
                                            + self.webdavBasePath,
                                            validateResourceNames=False)
        webdavConnection.connection.logger.setLevel(logging.WARNING)

        time_delta = None

        #Test KhtNotes folder and authenticate
        authFailures = 0
        while authFailures < 4:
            try:
                webdavConnection.validate()
                response = webdavConnection.getSpecificOption('date')
                print response
                try:
                    import rfc822
                    local_datetime = int(time.time())
                    self.logger.debug('Timezone: %f, Timealtzone: %f',
                                      time.timezone, time.altzone)
                    self.logger.debug('Server Time: %s' % response)
                    remote_datetime = rfc822.parsedate(response)
                    self.logger.debug('Parsed server time %s' %
                                      str(remote_datetime))
                    time_delta = local2utc(time.mktime(remote_datetime)) \
                        - local_datetime
                    self.logger.debug('Time delta: %f' % time_delta)
                except Exception, err:
                    time_delta = None
                    print 'error parsing date', err
                    self.logger.error('Failed to parse datetime: %s:%s'
                                      % (unicode(type(err)), unicode(err)))
                isConnected = True
                break  # break out of the authorization failure counter
            except AuthorizationError, err:
                if err.authType == "Basic":
                    webdavConnection.connection.\
                        addBasicAuthorization(webdavLogin, webdavPasswd)
                elif err.authType == "Digest":
                    info = parseDigestAuthInfo(err.authInfo)
                    webdavConnection.connection.\
                        addDigestAuthorization(webdavLogin,
                                               webdavPasswd,
                                               realm=info["realm"],
                                               qop=info["qop"],
                                               nonce=info["nonce"])
                elif authFailures >= 2:
                    self.on_error.emit('Wrong login or password')
                    self.logger.error('Wrong login or password')
                else:
                    self.logger.error('%s:%s' % (unicode(type(err)),
                                      unicode(err)))
                    self.on_error.emit(unicode(err) + ':' + unicode(err))
Пример #5
0
 def __init__(self):
     self.storers = []
     self.url = "http://buri.sistec.kp.dlr.de/taminowebdavserver/datafinder/"
     user = "******"
     password = "******"
     if len(sys.argv) > 1:
         self.url = sys.argv[1]
     print "init ", self.url
     self.resource = CollectionStorer(self.url, Buri.connection)
     if not Buri.connection:
         Buri.connection = self.resource.connection
     if len(sys.argv) > 3:
         user = sys.argv[2]
         password = sys.argv[3]
     if user:
         self.resource.connection.addBasicAuthorization(user, password)
Пример #6
0
class WebdavTestFile(threading.Thread):
	def __init__(self, url=None, auth={}, callback=None):
		self.url = url
		self.auth = auth
		self.callback = callback
		self.error = None
		self.result = None

		threading.Thread.__init__(self)
		
	def run(self):
		try:
			self.collection = CollectionStorer(self.url, validateResourceNames = False)

			authFailures = 0
			while authFailures < 2:
				try:
					self.result = self.collection.validate()
					break
				except AuthorizationError, e:
					if e.authType == "Basic":
						self.collection.connection.addBasicAuthorization(self.auth["user"], self.auth["password"])
					elif e.authType == "Digest":
						info = parseDigestAuthInfo(e.authInfo)
						self.collection.connection.addDigestAuthorization(self.auth["user"], self.auth["password"], realm=info["realm"], qop=info["qop"], nonce=info["nonce"])						
					else:
						self.error = "Error: " + str(e)
						
					authFailures += 1
		except Exception, e:
			self.error = str(e)
Пример #7
0
	def run(self):
		try:
			if self.url:
				self.collection = CollectionStorer(self.url, validateResourceNames = False)

			authFailures = 0
			while authFailures < 2:
				try:
					self.result = self.collection.getCollectionContents()
					if self.collection.getSpecificOption("set-cookie"):
						self.collection.connection.cookie = self.collection.getSpecificOption("set-cookie")
						self.cookie = self.collection.getSpecificOption("set-cookie")
					break
				except AuthorizationError, e:
					if e.authType == "Basic":
						self.collection.connection.addBasicAuthorization(self.auth["user"], self.auth["password"])
					elif e.authType == "Digest":
						info = parseDigestAuthInfo(e.authInfo)
						self.collection.connection.addDigestAuthorization(self.auth["user"], self.auth["password"], realm=info["realm"], qop=info["qop"], nonce=info["nonce"])						
					else:
						self.error = "Error: " + str(e)
						
					authFailures += 1

		except Exception, e:
			self.error = "Error: " + str(e)
Пример #8
0
    def _connect(self):
        if self._webdavURL[-4:] == '.ics':
            self.connection = ResourceStorer(self._webdavURL,
                                             validateResourceNames=False)
        else:
            self.connection = CollectionStorer(self._webdavURL,
                                               validateResourceNames=False)

        if self._username and self._password:
            self.connection.connection.addBasicAuthorization(
                self._username, self._password)

        self.connection.connection.logger.setLevel(logging.WARNING)
Пример #9
0
 def __init__(self):
     self.storers= []
     self.url= "http://buri.sistec.kp.dlr.de/taminowebdavserver/datafinder/"
     user= "******"
     password= "******"
     if  len(sys.argv) > 1:
         self.url= sys.argv[1]
     print "init ", self.url
     self.resource= CollectionStorer(self.url, Buri.connection)
     if not Buri.connection:
         Buri.connection= self.resource.connection
     if  len(sys.argv) > 3:
         user= sys.argv[2]
         password= sys.argv[3]
     if  user:
         self.resource.connection.addBasicAuthorization(user, password)
Пример #10
0
def createCollectionStorer(persistenceIdentifier, connection, validate=False):
    """
    Creates a C{CollectionStorer} object to manage a WebDAV resource.
    
    @param persistenceIdentifier: URL identifying the collection.
    @type persistenceIdentifier: C{unicode}
    @param connection: Connection used to perform WebDAV server requests.
    @type connection: L{Connection<webdav.Connection.Connection>}
    @param validate: Flag indicating automatic existence validation. Default is C{False}.
    @type validate: C{bool}
    
    @return: Object representing the WebDAV resource.
    @rtype: instance of L{CollectionStorer<webdav.WebdavClient.CollectionStorer>}
    
    @raise PersistenceError - Indicating problems with WebDAV connection.
    """

    webdavStorer = CollectionStorer(persistenceIdentifier, connection)
    if validate:
        _checkWebdavConnection(webdavStorer)
    return webdavStorer
Пример #11
0
class WebdavTestFile(threading.Thread):
    def __init__(self, url=None, auth={}, callback=None):
        self.url = url
        self.auth = auth
        self.callback = callback
        self.error = None
        self.result = None

        threading.Thread.__init__(self)

    def run(self):
        try:
            self.collection = CollectionStorer(self.url,
                                               validateResourceNames=False)

            authFailures = 0
            while authFailures < 2:
                try:
                    self.result = self.collection.validate()
                    break
                except AuthorizationError, e:
                    if e.authType == "Basic":
                        self.collection.connection.addBasicAuthorization(
                            self.auth["user"], self.auth["password"])
                    elif e.authType == "Digest":
                        info = parseDigestAuthInfo(e.authInfo)
                        self.collection.connection.addDigestAuthorization(
                            self.auth["user"],
                            self.auth["password"],
                            realm=info["realm"],
                            qop=info["qop"],
                            nonce=info["nonce"])
                    else:
                        self.error = "Error: " + str(e)

                    authFailures += 1
        except Exception, e:
            self.error = str(e)
Пример #12
0
class Buri(object):
    connection= None
    
    def __init__(self):
        self.storers= []
        self.url= "http://buri.sistec.kp.dlr.de/taminowebdavserver/datafinder/"
        user= "******"
        password= "******"
        if  len(sys.argv) > 1:
            self.url= sys.argv[1]
        print "init ", self.url
        self.resource= CollectionStorer(self.url, Buri.connection)
        if not Buri.connection:
            Buri.connection= self.resource.connection
        if  len(sys.argv) > 3:
            user= sys.argv[2]
            password= sys.argv[3]
        if  user:
            self.resource.connection.addBasicAuthorization(user, password)

    def getMembers(self):
        print "Get members"
        items= self.resource.findProperties((NS_DAV, PROP_RESOURCE_TYPE))
        for item in items.keys():
            self.storers.append(ResourceStorer(item, Buri.connection))
            print "Path ", item
            
    def getAcls(self):
        print "Get ACLs"
        for item in self.storers:
            if item.path.endswith("tmp2"):
                aclElem= item.readProperty(NS_DAV, 'acl')
                acl= ACL(aclElem)
                print "ACL for", item.path,
                qp_xml.dump(sys.stdout, aclElem)
                break
        
    def addAdmin(self):
        print "Add Admin"
        for item in self.storers:
            newAcl= GrantAcl('admin')
            print "set ACL of", item.path, "to", newAcl.toXML()
            item.setAcl(newAcl)
        
    def denyGuy(self):
        print "Deny Guy"
        for item in self.storers:
            if item.path.endswith("public"):
                newAcl= DenyAcl('gkloss')
                print "deny ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)
        
    def removeAll(self):
        print "Add Admin"
        for item in self.storers:
            newAcl= DenyAcl('')
            print "set ACL of", item.path, "to", newAcl.toXML()
            item.setAcl(newAcl)
        
    def addUser(self, username, collection):
        print "Add User", username, "to", collection
        for item in self.storers:
            if  item.path.find(collection) >= 0:
                newAcl= GrantAcl(username)
                print "set ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)
        
    def removeUser(self, username, collections):
        print "Deny user", username, "from", collections
        for item in self.storers:
            print "Dir:", basename(item.path)
            if  basename(item.path) in collections:
                newAcl= DenyAcl(username)
                print "deny ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)
Пример #13
0
class Buri(object):
    connection = None

    def __init__(self):
        self.storers = []
        self.url = "http://buri.sistec.kp.dlr.de/taminowebdavserver/datafinder/"
        user = "******"
        password = "******"
        if len(sys.argv) > 1:
            self.url = sys.argv[1]
        print "init ", self.url
        self.resource = CollectionStorer(self.url, Buri.connection)
        if not Buri.connection:
            Buri.connection = self.resource.connection
        if len(sys.argv) > 3:
            user = sys.argv[2]
            password = sys.argv[3]
        if user:
            self.resource.connection.addBasicAuthorization(user, password)

    def getMembers(self):
        print "Get members"
        items = self.resource.findProperties((NS_DAV, PROP_RESOURCE_TYPE))
        for item in items.keys():
            self.storers.append(ResourceStorer(item, Buri.connection))
            print "Path ", item

    def getAcls(self):
        print "Get ACLs"
        for item in self.storers:
            if item.path.endswith("tmp2"):
                aclElem = item.readProperty(NS_DAV, 'acl')
                acl = ACL(aclElem)
                print "ACL for", item.path,
                qp_xml.dump(sys.stdout, aclElem)
                break

    def addAdmin(self):
        print "Add Admin"
        for item in self.storers:
            newAcl = GrantAcl('admin')
            print "set ACL of", item.path, "to", newAcl.toXML()
            item.setAcl(newAcl)

    def denyGuy(self):
        print "Deny Guy"
        for item in self.storers:
            if item.path.endswith("public"):
                newAcl = DenyAcl('gkloss')
                print "deny ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)

    def removeAll(self):
        print "Add Admin"
        for item in self.storers:
            newAcl = DenyAcl('')
            print "set ACL of", item.path, "to", newAcl.toXML()
            item.setAcl(newAcl)

    def addUser(self, username, collection):
        print "Add User", username, "to", collection
        for item in self.storers:
            if item.path.find(collection) >= 0:
                newAcl = GrantAcl(username)
                print "set ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)

    def removeUser(self, username, collections):
        print "Deny user", username, "from", collections
        for item in self.storers:
            print "Dir:", basename(item.path)
            if basename(item.path) in collections:
                newAcl = DenyAcl(username)
                print "deny ACL of", item.path, "to", newAcl.toXML()
                item.setAcl(newAcl)
Пример #14
0
    def createConnection(self, webdavLogin, webdavPasswd):
        from webdav.WebdavClient import CollectionStorer, AuthorizationError, \
            parseDigestAuthInfo
        # from webdav.logger import _defaultLoggerName

        isConnected = False
        webdavConnection = CollectionStorer(self.webdavUrl,
                                            validateResourceNames=False)
        webdavConnection.connection.logger.setLevel(logging.WARNING)
        time_delta = None

        # Test KhtNotes folder and authenticate
        authFailures = 0
        while authFailures < 4:
            try:
                webdavConnection.validate()
                response = webdavConnection.getSpecificOption('date')
                local_datetime = int(time.time())
                # print response
                try:
                    import rfc822
                    self.logger.debug('Timezone: %f, Timealtzone: %f',
                                      time.timezone, time.altzone)
                    self.logger.debug('Server Time: %s' % response)
                    remote_datetime = rfc822.parsedate(response)
                    self.logger.debug('Parsed server time %s' %
                                      str(remote_datetime))
                    time_delta = local2utc(time.mktime(remote_datetime)) \
                        - local_datetime
                    self.logger.debug('Time delta: %f' % time_delta)
                except Exception as err:
                    time_delta = None
                    print 'error parsing date', err
                    self.logger.error('Failed to parse datetime: %s:%s' %
                                      (str(type(err)), str(err)))
                isConnected = True
                break  # break out of the authorization failure counter
            except AuthorizationError as err:
                if err.authType == "Basic":
                    webdavConnection.connection.\
                        addBasicAuthorization(webdavLogin, webdavPasswd)
                elif err.authType == "Digest":
                    info = parseDigestAuthInfo(err.authInfo)
                    webdavConnection.connection.\
                        addDigestAuthorization(webdavLogin,
                                               webdavPasswd,
                                               realm=info["realm"],
                                               qop=info["qop"],
                                               nonce=info["nonce"])
                elif authFailures >= 2:
                    self.logger.error('Wrong login or password')
                    raise IncorrectSyncParameters('Wrong login or password')
                else:
                    self.logger.error('%s:%s' % (str(type(err)), str(err)))
                    raise IncorrectSyncParameters('Can\'t connect to server')

            except Exception as err2:
                self.logger.error('%s:%s' % (str(type(err2)), str(err2)))
                raise IncorrectSyncParameters('Can\'t connect to server')

            authFailures += 1
        return (isConnected, webdavConnection, time_delta)