def get_cr(self, uri):
		reluri = self.uri2local(uri)
		dbname = reluri.split('/')[1]
		uid = security.login(dbname, dav_auth.auth['user'], dav_auth.auth['pwd'])
		db,pool = pooler.get_db_and_pool(dbname)
		cr = db.cursor()
		uri2 = reluri.split('/')[1:]
		return cr, uid, pool, uri2
Beispiel #2
0
 def get_cr(self, uri):
     reluri = self.uri2local(uri)
     dbname = reluri.split('/')[1]
     uid = security.login(dbname, dav_auth.auth['user'],
                          dav_auth.auth['pwd'])
     db, pool = pooler.get_db_and_pool(dbname)
     cr = db.cursor()
     uri2 = reluri.split('/')[1:]
     return cr, uid, pool, uri2
Beispiel #3
0
    def get_userinfo(self, user, pw):
        print '\tAuth', user, pw
        print '-' * 80
        if not self.db_name or self.db_name == '':
            self.db_name = self.path.split('/')[1]
            user = '******'
            pw = ''

        db, pool = pooler.get_db_and_pool(self.db_name)
        res = security.login(self.db_name, user, pw)
        print '\tAuth', user, pw, res
        if res:
            auth['user'] = user
            auth['pwd'] = pw
        return bool(res)
    def get_userinfo(self, user, pw):
        print "\tAuth", user, pw
        print "-" * 80
        if not self.db_name or self.db_name == "":
            self.db_name = self.path.split("/")[1]
            user = "******"
            pw = ""

        db, pool = pooler.get_db_and_pool(self.db_name)
        res = security.login(self.db_name, user, pw)
        print "\tAuth", user, pw, res
        if res:
            auth["user"] = user
            auth["pwd"] = pw
        return bool(res)
 def get_cr(self, path):
     path = self.ftpnorm(path)
     if path=='/':
         return None
     dbname = path.split('/')[1]
     if dbname not in self.db_list():
         return None
     try:
         db,pool = pooler.get_db_and_pool(dbname)
     except:
         raise OSError(1, 'Operation not permited.')
     cr = db.cursor()
     uid = security.login(dbname, self.username, self.password)
     if not uid:
         raise OSError(2, 'Authentification Required.')
     return cr, uid, pool
    def listdir(self, path):
        """List the content of a directory."""
        class false_node:
            object = None
            type = 'database'
            def __init__(self, db):
                self.path = '/'+db

        if path is None:
            result = []
            for db in self.db_list():
                try:
                    uid = security.login(db, self.username, self.password)
                    if uid:
                        result.append(false_node(db))                    
                except osv.except_osv:                    
                    pass
            return result
        return path.children()
Beispiel #7
0
    def get_crdata(self, line, mode='file'):
        """ Get database cursor, node and remainder data, for commands

        This is the helper function that will prepare the arguments for
        any of the subsequent commands.
        It returns a tuple in the form of:
        @code        ( cr, node, rem_path=None )

        @param line An absolute or relative ftp path, as passed to the cmd.
        @param mode A word describing the mode of operation, so that this
                    function behaves properly in the different commands.
        """
        path = self.ftpnorm(line)
        if self.cwd_node is None:
            if not os.path.isabs(path):
                path = os.path.join(self.root, path)

        if path == '/' and mode in ('list', 'cwd'):
            return (None, None, None)

        path = _to_unicode(os.path.normpath(path))  # again, for '/db/../ss'
        if path == '.': path = ''

        if os.path.isabs(path) and self.cwd_node is not None \
                and path.startswith(self.cwd):
            # make relative, so that cwd_node is used again
            path = path[len(self.cwd):]
            if path.startswith('/'):
                path = path[1:]

        p_parts = path.split('/')  # hard-code the unix sep here, by spec.

        assert '..' not in p_parts

        rem_path = None
        if mode in ('create', ):
            rem_path = p_parts[-1]
            p_parts = p_parts[:-1]

        if os.path.isabs(path):
            # we have to start from root, again
            while p_parts and p_parts[0] == '':
                p_parts = p_parts[1:]
            # self._log.debug("Path parts: %r ", p_parts)
            if not p_parts:
                raise IOError(errno.EPERM,
                              'Cannot perform operation at root dir')
            dbname = p_parts[0]
            if dbname not in self.db_list():
                raise IOError(errno.ENOENT,
                              'Invalid database path: %s' % dbname)
            try:
                db = pooler.get_db(dbname)
            except Exception:
                raise OSError(1, 'Database cannot be used.')
            cr = db.cursor()
            try:
                uid = security.login(dbname, self.username, self.password)
            except Exception:
                cr.close()
                raise
            if not uid:
                cr.close()
                raise OSError(2, 'Authentification Required.')
            n = get_node_context(cr, uid, {})
            node = n.get_uri(cr, p_parts[1:])
            return (cr, node, rem_path)
        else:
            # we never reach here if cwd_node is not set
            if p_parts and p_parts[-1] == '':
                p_parts = p_parts[:-1]
            cr, uid = self.get_node_cr_uid(self.cwd_node)
            if p_parts:
                node = self.cwd_node.get_uri(cr, p_parts)
            else:
                node = self.cwd_node
            if node is False and mode not in ('???'):
                cr.close()
                raise IOError(errno.ENOENT, 'Path does not exist')
            return (cr, node, rem_path)
Beispiel #8
0
    def get_crdata(self, line, mode="file"):
        """ Get database cursor, node and remainder data, for commands

        This is the helper function that will prepare the arguments for
        any of the subsequent commands.
        It returns a tuple in the form of:
        @code        ( cr, node, rem_path=None )

        @param line An absolute or relative ftp path, as passed to the cmd.
        @param mode A word describing the mode of operation, so that this
                    function behaves properly in the different commands.
        """
        path = self.ftpnorm(line)
        if self.cwd_node is None:
            if not os.path.isabs(path):
                path = os.path.join(self.root, path)

        if path == "/" and mode in ("list", "cwd"):
            return (None, None, None)

        path = _to_unicode(os.path.normpath(path))  # again, for '/db/../ss'
        if path == ".":
            path = ""

        if os.path.isabs(path) and self.cwd_node is not None and path.startswith(self.cwd):
            # make relative, so that cwd_node is used again
            path = path[len(self.cwd) :]
            if path.startswith("/"):
                path = path[1:]

        p_parts = path.split("/")  # hard-code the unix sep here, by spec.

        assert ".." not in p_parts

        rem_path = None
        if mode in ("create",):
            rem_path = p_parts[-1]
            p_parts = p_parts[:-1]

        if os.path.isabs(path):
            # we have to start from root, again
            while p_parts and p_parts[0] == "":
                p_parts = p_parts[1:]
            # self._log.debug("Path parts: %r ", p_parts)
            if not p_parts:
                raise IOError(errno.EPERM, "Cannot perform operation at root dir")
            dbname = p_parts[0]
            if dbname not in self.db_list():
                raise IOError(errno.ENOENT, "Invalid database path: %s" % dbname)
            try:
                db = pooler.get_db(dbname)
            except Exception:
                raise OSError(1, "Database cannot be used.")
            cr = db.cursor()
            try:
                uid = security.login(dbname, self.username, self.password)
            except Exception:
                cr.close()
                raise
            if not uid:
                cr.close()
                raise OSError(2, "Authentification Required.")
            n = get_node_context(cr, uid, {})
            node = n.get_uri(cr, p_parts[1:])
            return (cr, node, rem_path)
        else:
            # we never reach here if cwd_node is not set
            if p_parts and p_parts[-1] == "":
                p_parts = p_parts[:-1]
            cr, uid = self.get_node_cr_uid(self.cwd_node)
            if p_parts:
                node = self.cwd_node.get_uri(cr, p_parts)
            else:
                node = self.cwd_node
            if node is False and mode not in ("???"):
                cr.close()
                raise IOError(errno.ENOENT, "Path does not exist")
            return (cr, node, rem_path)