Exemple #1
0
def file_serving(filename):
    from uliweb.utils.filedown import filedown
    from uliweb.core.SimpleFrame import local
    
    fname = get_filename(filename, filesystem=True)
    action = request.GET.get('action', 'download')
    if action == 'inline':
        return filedown(local.request.environ, fname, inline=True)
    else:
        return filedown(local.request.environ, fname, download=True)
Exemple #2
0
    def download(self, filename, action='download', x_filename='', x_sendfile=None, real_filename=''):
        """
        action will be "download", "inline"
        and if the request.GET has 'action', then the action will be replaced by it.
        """
        from uliweb import request
        from uliweb.utils.common import safe_str
        from uliweb.utils.filedown import filedown
        
        s = settings.GLOBAL

        action = request.GET.get('action', action)
        
        if not real_filename:
            real_filename = self.get_filename(filename, True, convert=False)
        else:
            real_filename = files.encode_filename(real_filename, to_encoding=s.FILESYSTEM_ENCODING)

        if not x_filename:
            x_filename = safe_str(filename, s.FILESYSTEM_ENCODING)
        if self.x_file_prefix:
            x_filename = os.path.normpath(os.path.join(self.x_file_prefix, x_filename)).replace('\\', '/')
        
        xsend_flag = bool(self.x_sendfile) if x_sendfile is None else x_sendfile
        return filedown(request.environ, filename, action=action, 
            x_sendfile=xsend_flag, x_header_name=self.x_header_name, 
            x_filename=x_filename, real_filename=real_filename)
Exemple #3
0
 def download(self, filename, action=None, x_filename='', real_filename=''):
     """
     action will be "download", "inline"
     and if the request.GET has 'action', then the action will be replaced by it.
     """
     from uliweb.utils.common import safe_str
     from uliweb.utils.filedown import filedown
     from uliweb import request
     from StringIO import StringIO
     
     action = request.GET.get('action', action)
     
     fname = safe_str(filename)
     if not x_filename:
         x_filename = fname
     if self.x_file_prefix:
         x_filename = os.path.normpath(os.path.join(self.x_file_prefix, x_filename)).replace('\\', '/')
     
     if not real_filename:
         #if not real_filename, then get the file info from database
         obj = self.get_file_record(filename)
         fname = obj.filename.encode('utf8')
         fileobj = StringIO(obj.content), obj.create_time, obj.size
         #fileobj should be (filename, mtime, size)
     else:
         fileobj = None
         s = settings.GLOBAL
         real_filename = files.encode_filename(real_filename, to_encoding=s.FILESYSTEM_ENCODING)
     
     return filedown(request.environ, fname, action=action, 
         x_sendfile=bool(self.x_sendfile), x_header_name=self.x_header_name, 
         x_filename=x_filename, real_filename=real_filename, fileobj=fileobj)
Exemple #4
0
    def api_artifactfile_download(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({
                "success": False,
                "msg": "have no permission"
            },
                        status=403)

        not_found_response = json({
            "success": False,
            "msg": "not found"
        },
                                  status=404)

        id_ = request.values.get("id")
        if not id_:
            return not_found_response

        LinciArtifactFile = get_model("linciartifactfile")
        afile = LinciArtifactFile.get(int(id_))
        if not afile:
            return not_found_response

        real_filename = os.path.join(afile.artifact.get_artifact_dpath(),
                                     afile.store_path)
        filename = os.path.basename(afile.path)

        if not os.path.isfile(real_filename):
            return not_found_response

        return filedown(request.environ,
                        filename,
                        cache=False,
                        real_filename=real_filename,
                        action="download")
Exemple #5
0
def builds_dl(fn):
    fp = ""
    for dp in settings.AUTOBUILD.BUILDS_DIRS:
        fp = os.path.join(dp,fn)
        if os.path.exists(fp):
            break
    return filedown(request.environ,fp)
Exemple #6
0
    def download(self, filename, action='download', x_filename='', real_filename=''):
        """
        action will be "download", "inline"
        and if the request.GET has 'action', then the action will be replaced by it.
        """
        from uliweb.utils.common import safe_str
        from uliweb.utils.filedown import filedown
        
        s = settings.GLOBAL

        action = request.GET.get('action', action)
        
        if not real_filename:
            real_filename = self.get_filename(filename, True, convert=False)
        else:
            real_filename = files.encode_filename(real_filename, to_encoding=s.FILESYSTEM_ENCODING)

        if not x_filename:
            x_filename = safe_str(filename, s.FILESYSTEM_ENCODING)
        if self.x_file_prefix:
            x_filename = os.path.normpath(os.path.join(self.x_file_prefix, x_filename)).replace('\\', '/')
        
        return filedown(request.environ, filename, action=action, 
            x_sendfile=bool(self.x_sendfile), x_header_name=self.x_header_name, 
            x_filename=x_filename, real_filename=real_filename)
Exemple #7
0
def sfiles(fn):
    files = settings.SFILES.FILES
    if (files!=None) and files.has_key(fn):
        fp = files[fn]
        if os.path.exists(fp):
            return filedown(request.environ, fp)
    raise NotFound
Exemple #8
0
def builds_dl2(dn,fn):
    fp = ""
    for dp in settings.AUTOBUILD.BUILDS_DIRS:
        fp = os.path.join(dp,"%s/%s"%(dn,fn))
        if os.path.exists(fp):
            break
    #return filedown(request.environ,filename="%s-%s"%(dn,fn.replace("_","-")),download=True,real_filename = fp)
    return filedown(request.environ,fp)
Exemple #9
0
def download():
    from uliweb.utils.filedown import filedown
    
    token = request.GET.get('token')
    filename = download_tokens.pop(token, None)
    if filename:
        return filedown(request.environ, filename, action='download', 
            real_filename=filename)
        
    return 'Error: token is not right'
Exemple #10
0
def image():
    from uliweb.utils.filedown import filedown

    token = request.GET.get('token')
    filename = images_tokens.pop(token, None)
    if filename:
        return filedown(request.environ,
                        filename,
                        action='download',
                        real_filename=filename)

    return 'Error: token is not right'
Exemple #11
0
    def download(self, filename, action=None, x_filename='', real_filename=''):
        """
        action will be "download", "inline"
        and if the request.GET has 'action', then the action will be replaced by it.
        """
        from uliweb.utils.common import safe_str
        from uliweb.utils.filedown import filedown
        from uliweb import request
        from StringIO import StringIO
        from uliweb.utils import files

        action = request.GET.get('action', action)

        fname = safe_str(filename)
        if not x_filename:
            x_filename = fname
        if self.x_file_prefix:
            x_filename = os.path.normpath(
                os.path.join(self.x_file_prefix,
                             x_filename)).replace('\\', '/')

        if not real_filename:
            #if not real_filename, then get the file info from database
            obj = self.get_file_record(filename)
            fname = obj.filename.encode('utf8')
            fileobj = StringIO(obj.content), obj.create_time, obj.size
            #fileobj should be (filename, mtime, size)
        else:
            fileobj = None
            s = settings.GLOBAL
            real_filename = files.encode_filename(
                real_filename, to_encoding=s.FILESYSTEM_ENCODING)

        return filedown(request.environ,
                        fname,
                        action=action,
                        x_sendfile=bool(self.x_sendfile),
                        x_header_name=self.x_header_name,
                        x_filename=x_filename,
                        real_filename=real_filename,
                        fileobj=fileobj)
Exemple #12
0
    def api_artifactfile_download(self):
        if not functions.linci_artifact_has_permission("linci_artifact_read"):
            return json({"success":False,"msg":"have no permission"}, status=403)

        not_found_response = json({"success":False,"msg":"not found"}, status=404)

        id_ = request.values.get("id")
        if not id_:
            return not_found_response

        LinciArtifactFile = get_model("linciartifactfile")
        afile = LinciArtifactFile.get(int(id_))
        if not afile:
            return not_found_response

        real_filename = os.path.join(afile.artifact.get_artifact_dpath(),afile.store_path)
        filename = os.path.basename(afile.path)

        if not os.path.isfile(real_filename):
            return not_found_response

        return filedown(request.environ,filename,cache=False,real_filename=real_filename,action="download")
Exemple #13
0
    def __call__(self, environ, start_response):
        from werkzeug.exceptions import Forbidden

        # sanitize the path for non unix systems
        cleaned_path = environ.get('PATH_INFO', '').strip('/')
        for sep in os.sep, os.altsep:
            if sep and sep != '/':
                cleaned_path = cleaned_path.replace(sep, '/')
        path = '/'.join(
            [''] + [x for x in cleaned_path.split('/') if x and x != '..'])
        file_loader = None
        flag = False
        for search_path, loader in self.exports.iteritems():
            if search_path == path:
                flag = True
                real_filename, file_loader = loader(None)
                if file_loader is not None:
                    break
            if not search_path.endswith('/'):
                search_path += '/'
            if path.startswith(search_path):
                flag = True
                real_filename, file_loader = loader(path[len(search_path):])
                if file_loader is not None:
                    break
        if file_loader is None:
            if flag:
                return real_filename(environ, start_response)
            else:
                return self.app(environ, start_response)

        if not self.is_allowed(real_filename):
            return Forbidden("You can not visit the file %s." % real_filename)(
                environ, start_response)

        res = filedown(environ, real_filename, self.cache, self.cache_timeout)
        return res(environ, start_response)
Exemple #14
0
    def __call__(self, environ, start_response):
        from werkzeug.exceptions import Forbidden

        # sanitize the path for non unix systems
        cleaned_path = environ.get('PATH_INFO', '').strip('/')
        for sep in os.sep, os.altsep:
            if sep and sep != '/':
                cleaned_path = cleaned_path.replace(sep, '/')
        path = '/'.join([''] + [x for x in cleaned_path.split('/')
                                if x and x != '..'])
        file_loader = None
        flag = False
        for search_path, loader in self.exports.iteritems():
            if search_path == path:
                flag = True
                real_filename, file_loader = loader(None)
                if file_loader is not None:
                    break
            if not search_path.endswith('/'):
                search_path += '/'
            if path.startswith(search_path):
                flag = True
                real_filename, file_loader = loader(path[len(search_path):])
                if file_loader is not None:
                    break
        if file_loader is None:
            if flag:
                return real_filename(environ, start_response)
            else:
                return self.app(environ, start_response)
        
        if not self.is_allowed(real_filename):
            return Forbidden("You can not visit the file %s." % real_filename)(environ, start_response)
    
        res = filedown(environ, real_filename, self.cache, self.cache_timeout)
        return res(environ, start_response)
Exemple #15
0
def rss():
    return filedown(request.environ, application.get_file('rss.xml', dir='files'))
Exemple #16
0
def zip(filename):
    return filedown(request.environ, application.get_file(filename+'.zip', dir='files'), download=True)
Exemple #17
0
def jpg(filename):
    return filedown(request.environ, application.get_file(filename+'.jpg', dir='files'))
Exemple #18
0
def favicon():
    return filedown(request.environ, application.get_file('favicon.ico'))
Exemple #19
0
def robots():
    return filedown(request.environ, application.get_file('robots.txt'))
Exemple #20
0
def tarbz2(filename):
    return filedown(request.environ, application.get_file(filename+'.tar.bz2', dir='files'), download=True)
Exemple #21
0
def updateip():
    return filedown(request.environ, application.get_file('updateip.py'))