forked from Studio-42/elfinder-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnector.py
More file actions
executable file
·109 lines (94 loc) · 2.56 KB
/
connector.py
File metadata and controls
executable file
·109 lines (94 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
import cgi
import json
import elFinder
# configure connector options
opts = {
#'root': '/home/troex/Sites/git/elfinder/files',
'root': '../elfinder-2.x/files/',
'URL': '../elfinder-2.x/files/',
## other options
'debug': True,
# 'fileURL': False, # download files using connector, no direct urls to files
# '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']
# 'disabled': ['rename', 'quicklook', 'upload']
}
# 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)
if field == 'upload[]':
upFiles = {}
cgiUploadFiles = form['upload[]']
for up in cgiUploadFiles:
if up.filename:
upFiles[up.filename] = up.file # pack dict(filename: filedescriptor)
httpRequest['upload[]'] = 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)
## logging
#import sys
#log = open('/home/troex/Sites/git/elfinder-2.x/files/out.log', 'w')
#print >>log, 'cuf: ', cgiUploadFiles
#log.close()
## another aproach
## get connector output and print it out
#if elf.httpStatusCode == 200:
# print 'HTTP/1.1 200 OK'
#elif elf.httpStatusCode == 403:
# print 'HTTP/1.x 403 Access Denied'
#elif elf.httpStatusCode == 404:
# print 'HTTP/1.x 404 Not Found'
#
#if len(elf.httpHeader) >= 1:
# for header, value in elf.httpHeader.iteritems():
# print header + ': ' + value
# print
#
#if not elf.httpResponse is None:
# if isinstance(elf.httpResponse['file'], file):
# print elf.httpResponse['file'].read()
# elf.httpResponse['file'].close()
# else:
# print json.dumps(elf.httpResponse, indent = True)
#