def make_app(app, options, basepath):
    elf = elFinder.connector(options)

    def elfinder_connector(environ, start_response):
        req = wo.Request(environ)
        if req.path_info.startswith(basepath):
            res = wo.Response()
            #call the elFinder class
            status, header, response = elf.run(req.params)
            res.status_int = status
            res.headers.update(header)
            if status == 200 and not response is None:
                if 'file' in response and isinstance(response['file'], file):
                    res.app_iter = file_streamer(response['file'])
                else:
                    res.body = json.dumps(response, indent=True)
            return res(environ, start_response)
        else:
            if app:
                st, hl, app_iter = req.call_application(app)
                try:
                    start_response(st, hl)
                    return app_iter
                finally:
                    if hasattr(app_iter, 'close'):
                        app_iter.close()
            else:
                start_response("404 NOT FOUND", [('Content-Type', 'text/html')])
                return ["No handler found for that request",]
    return elfinder_connector
예제 #2
0
def index(self):

    # init connector and pass options
    elf = elFinder.connector(opts)

    # fetch only needed GET/POST parameters
    httpRequest = {}
    form = cgi.FieldStorage()
    for field in elf.httpAllowedParameters:
	    if field in form:
		    httpRequest[field] = form.getvalue(field)

		    # Django hack by Kidwind
		    if field == 'targets[]' and hasattr(form, 'getlist'):
			    httpRequest[field] = form.getlist(field)

		    # handle CGI upload
		    if field == 'upload[]':
			    upFiles = {}
			    cgiUploadFiles = form[field]
			    if not isinstance(cgiUploadFiles, list):
				    cgiUploadFiles = [cgiUploadFiles]
			    for up in cgiUploadFiles:
				    if up.filename:
					    upFiles[up.filename] = up.file # pack dict(filename: filedescriptor)
			    httpRequest[field] = upFiles


    # run connector with parameters
    status, header, response = elf.run(httpRequest)

    # get connector output and print it out

    # code below is tested with apache only (maybe other server need other method?)
    if status == 200:
	    print 'Status: 200'
    elif status == 403:
	    print 'Status: 403'
    elif status == 404:
	    print 'Status: 404'

    if len(header) >= 1:
	    for h, v in header.iteritems():
		    print h + ': ' + v
	    print

    if not response is None and status == 200:
	    # send file
	    if 'file' in response and isinstance(response['file'], file):
		    print response['file'].read()
		    response['file'].close()
	    # output json
	    else:
		    print json.dumps(response, indent = True)
예제 #3
0
def connector(request):
    # init connector and pass options
    elf = elFinder.connector(_opts)

    # fetch only needed GET/POST parameters
    httpRequest = {}
    form=request.params
    for field in elf.httpAllowedParameters:
        if field in form:
            # Russian file names hack
            if field == 'name':
                httpRequest[field] = form.getone(field).encode('utf-8')

            elif field == 'targets[]':
                httpRequest[field] = form.getall(field)

            # handle CGI upload
            elif field == 'upload[]':
                upFiles = {}
                cgiUploadFiles = form.getall(field)
                for up in cgiUploadFiles:
                    if isinstance(up, FieldStorage):
                        upFiles[up.filename.encode('utf-8')] = up.file # pack dict(filename: filedescriptor)
                httpRequest[field] = upFiles
            else:
                httpRequest[field] = form.getone(field)

    # run connector with parameters
    status, header, response = elf.run(httpRequest)

    # get connector output and print it out

    result=Response(status=status)
    try:
        del header['Connection']
    except:
        pass
    result.headers=header

    if not response is None and status == 200:
        # send file
        if 'file' in response and isinstance(response['file'], file):
            result.body=response['file'].read()
            response['file'].close()

        # output json
        else:
            result.body=json.dumps(response)
    return result
예제 #4
0
파일: img_mgr_view.py 프로젝트: 2-fly/2fly
    def handler_file_op(self):
        img_dir = os.path.join(settings.img_dir, str(self.my_uid))
        if not os.path.exists(img_dir):
            os.makedirs(img_dir)

        opts = {
            'root': img_dir,
            'URL': '.',
            'uploadAllow' : ["image"],
            'uploadOrder' : ['allow']
        }

        elf = connector(opts)

        # fetch only needed GET/POST parameters
        httpRequest = {}
        for field in elf.httpAllowedParameters:
            if field in self.args:
                httpRequest[field] = self.args.get(field)

                if field == 'upload[]':
                    upFiles = {}
                    upload_files = self.args[field]
                    if not isinstance(upload_files, list):
                        upload_files = [upload_files]
                    for up in upload_files:
                        if up.filename:
                            upFiles[up.filename] = up.stream # pack dict(filename: filedescriptor)
                    httpRequest[field] = upFiles

        # run connector with parameters
        status, header, response = elf.run(httpRequest)

        # code below is tested with apache only (maybe other server need other method?)
        res = ""
        if not response is None and status == 200:
            if 'file' in response and isinstance(response['file'], file):
                res =  response['file'].read()
                response['file'].close()
                return res
            else:
                res = ujson.dumps(response)
                res = jsonify(response)
        return res
예제 #5
0
#!/usr/bin/env python

import elFinder

elFinder.connector({
	'root': '/home/user/Sites/elfinder/files',
	'URL': 'http://localhost/~user/elfinder/files',
	## other options
	# 'debug': True,
	# 'dirSize': True,
	# 'dotFiles': True,
	# 'perms': {
	# 	'backup': {
	# 		'read': True,
	# 		'write': False,
	# 		'rm': False
	# 	},
	# 	'^/pics': {
	# 		'read': True,
	# 		'write': False,
	# 		'rm': False
	# 	}
	# },
	# 'uploadDeny': ['image', 'application'],
	# 'uploadAllow': ['image/png', 'image/jpeg'],
	# 'uploadOrder': ['deny', 'allow']
}).run()
예제 #6
0
파일: connector.py 프로젝트: EOX-A/scribeui
	# 	'^/pics': {
	# 		'read': True,
	# 		'write': False,
	# 		'rm': False
	# 	}
	# },
	# 'uploadDeny': ['image', 'application'],
	# 'uploadAllow': ['image/png', 'image/jpeg'],
	# 'uploadOrder': ['deny', 'allow'],
	# 'disabled': ['rename', 'quicklook', 'upload'],
	# 'disabled': ['archive', 'extract'], # this will also disable archivers check
}


# init connector and pass options
elf = elFinder.connector(opts)

# fetch only needed GET/POST parameters
httpRequest = {}
form = cgi.FieldStorage()
for field in elf.httpAllowedParameters:
	if field in form:
		httpRequest[field] = form.getvalue(field)

		# Django hack by Kidwind
		if field == 'targets[]' and hasattr(form, 'getlist'):
			httpRequest[field] = form.getlist(field)

		# handle CGI upload
		if field == 'upload[]':
			upFiles = {}
예제 #7
0
#!/usr/bin/env python

import elFinder

elFinder.connector({
    'root': '/home/user/Sites/elfinder/files',
    'URL': 'http://localhost/~user/elfinder/files',
    ## other options
    # 'debug': True,
    # 'dirSize': True,
    # 'dotFiles': True,
    # 'perms': {
    # 	'backup': {
    # 		'read': True,
    # 		'write': False,
    # 		'rm': False
    # 	},
    # 	'^/pics': {
    # 		'read': True,
    # 		'write': False,
    # 		'rm': False
    # 	}
    # },
    # 'uploadDeny': ['image', 'application'],
    # 'uploadAllow': ['image/png', 'image/jpeg'],
    # 'uploadOrder': ['deny', 'allow']
}).run()
예제 #8
0
파일: app.py 프로젝트: EvilMcJerkface/ok
def connector():


    # configure per request connector options
    user = session['username']
    root = '/afs/athena.mit.edu/user/%s/%s/%s' % (user[0], user[1], user)

    print 'getting ticket'
    kerberos_client.store_service_ticket(session['afs_ticket'], user)
    print 'aquired ticket'
    output = Popen(["aklog"], stdout=PIPE).communicate()[0]
    print 'token aquired'

    opts = {''
    ## required options
    # 'root': '/path/to/files', # full path to your files
    # 'URL': 'http://mydomain.tld/path/to/files' # can be absolute or relative
    'root': root,
    'URL': 'http://localhost:5001'+root,
    ## other options
    # 'debug': True,
    }


    # init connector and pass options
    elf = elFinder.connector(opts)

    # fetch only needed GET/POST parameters
    httpRequest = {}
    files = []
    if request.method == 'POST':
        form = request.form
        files = request.files
    elif request.method == 'GET':
        form = request.args
    for field in elf.httpAllowedParameters:
        if field in form:
            httpRequest[field] = form.get(field)

            # Django hack by Kidwind
            if field == 'targets[]' and hasattr(form, 'getlist'):
                httpRequest[field] = form.getlist(field)

        # handle CGI upload
        if field == 'upload[]' and len(files) !=  0:
            upFiles = {}
            cgiUploadFiles = files['upload[]']
            if not isinstance(cgiUploadFiles, list):
                cgiUploadFiles = [cgiUploadFiles]
            for up in cgiUploadFiles:
                if up.filename:
                    upFiles[up.filename] = up.stream # pack dict(filename: filedescriptor)
            httpRequest[field] = upFiles
            httpRequest['cmd'] = 'upload'


    # run connector with parameters
    status, header, response = elf.run(httpRequest)

    # get connector output and print it out
    # code below is tested with apache only (maybe other server need other method?)
    res = ""
    # if status == 200:
    #     res +=  'Status: 200' + '\n'
    # elif status == 403:
    #     res += 'Status: 403' + '\n'
    # elif status == 404:
    #     res += 'Status: 404' + '\n'

    # if len(header) >= 1:
    #     for h, v in header.iteritems():
    #         res += h + ': ' + v  + '\n'
    # res += '\n'

    if not response is None and status == 200:
        # send file
        if 'file' in response and isinstance(response['file'], file):
            res +=  response['file'].read() + '\n'
            response['file'].close()
        # output json
        else:
            res +=  json.dumps(response, indent = True)  + '\n'

    kerberos_client.clear_service_ticket()

    return Response(res, status = status, mimetype = 'application/json')
예제 #9
0
파일: connector.py 프로젝트: patelritesh/ok
	# 	'^/pics': {
	# 		'read': True,
	# 		'write': False,
	# 		'rm': False
	# 	}
	# },
	# 'uploadDeny': ['image', 'application'],
	# 'uploadAllow': ['image/png', 'image/jpeg'],
	# 'uploadOrder': ['deny', 'allow'],
	# 'disabled': ['rename', 'quicklook', 'upload'],
	# 'disabled': ['archive', 'extract'], # this will also disable archivers check
}


# init connector and pass options
elf = elFinder.connector(opts)

# fetch only needed GET/POST parameters
httpRequest = {}
form = cgi.FieldStorage()
for field in elf.httpAllowedParameters:
	if field in form:
		httpRequest[field] = form.getvalue(field)

		# Django hack by Kidwind
		if field == 'targets[]' and hasattr(form, 'getlist'):
			httpRequest[field] = form.getlist(field)

		# handle CGI upload
		if field == 'upload[]':
			upFiles = {}
예제 #10
0
파일: app.py 프로젝트: patelritesh/ok
def connector():

    # configure per request connector options
    user = session['username']
    root = '/afs/athena.mit.edu/user/%s/%s/%s' % (user[0], user[1], user)

    print 'getting ticket'
    kerberos_client.store_service_ticket(session['afs_ticket'], user)
    print 'aquired ticket'
    output = Popen(["aklog"], stdout=PIPE).communicate()[0]
    print 'token aquired'

    opts = {
        ''
        ## required options
        # 'root': '/path/to/files', # full path to your files
        # 'URL': 'http://mydomain.tld/path/to/files' # can be absolute or relative
        'root':
        root,
        'URL':
        'http://localhost:5001' + root,
        ## other options
        # 'debug': True,
    }

    # init connector and pass options
    elf = elFinder.connector(opts)

    # fetch only needed GET/POST parameters
    httpRequest = {}
    files = []
    if request.method == 'POST':
        form = request.form
        files = request.files
    elif request.method == 'GET':
        form = request.args
    for field in elf.httpAllowedParameters:
        if field in form:
            httpRequest[field] = form.get(field)

            # Django hack by Kidwind
            if field == 'targets[]' and hasattr(form, 'getlist'):
                httpRequest[field] = form.getlist(field)

        # handle CGI upload
        if field == 'upload[]' and len(files) != 0:
            upFiles = {}
            cgiUploadFiles = files['upload[]']
            if not isinstance(cgiUploadFiles, list):
                cgiUploadFiles = [cgiUploadFiles]
            for up in cgiUploadFiles:
                if up.filename:
                    upFiles[
                        up.
                        filename] = up.stream  # pack dict(filename: filedescriptor)
            httpRequest[field] = upFiles
            httpRequest['cmd'] = 'upload'

    # run connector with parameters
    status, header, response = elf.run(httpRequest)

    # get connector output and print it out
    # code below is tested with apache only (maybe other server need other method?)
    res = ""
    # if status == 200:
    #     res +=  'Status: 200' + '\n'
    # elif status == 403:
    #     res += 'Status: 403' + '\n'
    # elif status == 404:
    #     res += 'Status: 404' + '\n'

    # if len(header) >= 1:
    #     for h, v in header.iteritems():
    #         res += h + ': ' + v  + '\n'
    # res += '\n'

    if not response is None and status == 200:
        # send file
        if 'file' in response and isinstance(response['file'], file):
            res += response['file'].read() + '\n'
            response['file'].close()
        # output json
        else:
            res += json.dumps(response, indent=True) + '\n'

    kerberos_client.clear_service_ticket()

    return Response(res, status=status, mimetype='application/json')