| 1 |
|
#!/usr/bin/env python
|
| 2 |
|
#
|
| 3 |
1 |
# Connector for elFinder File Manager
|
| 4 |
2 |
# author Troex Nevelin <troex@fury.scancode.ru>
|
|
3 |
# django patches Dmitry Shapoval <dmitry@0fe.ru>
|
| 5 |
4 |
|
| 6 |
5 |
import hashlib
|
| 7 |
6 |
import mimetypes
|
| ... | ... | |
| 94 |
93 |
}
|
| 95 |
94 |
|
| 96 |
95 |
_time = 0
|
| 97 |
|
_request = {}
|
| 98 |
|
_response = {}
|
|
96 |
|
| 99 |
97 |
_errorData = {}
|
| 100 |
|
_form = {}
|
| 101 |
98 |
_im = None
|
| 102 |
99 |
_sp = None
|
| 103 |
100 |
_today = 0
|
| ... | ... | |
| 112 |
109 |
httpResponse = None
|
| 113 |
110 |
|
| 114 |
111 |
def __init__(self, opts):
|
|
112 |
self._response = {}
|
|
113 |
self._request = {}
|
| 115 |
114 |
self._time = time.time()
|
| 116 |
115 |
t = datetime.fromtimestamp(self._time)
|
| 117 |
116 |
self._today = time.mktime(datetime(t.year, t.month, t.day).timetuple())
|
| ... | ... | |
| 136 |
135 |
if not os.path.exists(self._options['tmbDir']):
|
| 137 |
136 |
self._options['tmbDir'] = False
|
| 138 |
137 |
|
| 139 |
|
|
| 140 |
138 |
def run(self, httpRequest = []):
|
| 141 |
139 |
"""main function"""
|
| 142 |
140 |
rootOk = True
|
| ... | ... | |
| 149 |
147 |
|
| 150 |
148 |
for field in self.httpAllowedParameters:
|
| 151 |
149 |
if field in httpRequest:
|
| 152 |
|
self._request[field] = httpRequest[field]
|
|
150 |
if field == "targets[]":
|
|
151 |
self._request[field] = httpRequest.getlist(field)
|
|
152 |
else:
|
|
153 |
self._request[field] = httpRequest[field]
|
|
154 |
|
| 153 |
155 |
|
| 154 |
156 |
if rootOk is True:
|
| 155 |
157 |
if 'cmd' in self._request:
|
| ... | ... | |
| 254 |
256 |
self.httpHeader['Content-Length'] = str(os.lstat(curFile).st_size)
|
| 255 |
257 |
self.httpHeader['Connection'] = 'close'
|
| 256 |
258 |
self._response['file'] = open(curFile, 'r')
|
| 257 |
|
return
|
| 258 |
259 |
# try dir
|
| 259 |
260 |
else:
|
| 260 |
261 |
path = self._options['root']
|
| ... | ... | |
| 269 |
270 |
path = target
|
| 270 |
271 |
|
| 271 |
272 |
self.__content(path, 'tree' in self._request)
|
| 272 |
|
pass
|
| 273 |
273 |
|
| 274 |
274 |
|
| 275 |
275 |
def __rename(self):
|
| ... | ... | |
| 372 |
372 |
|
| 373 |
373 |
if not isinstance(rmList, list):
|
| 374 |
374 |
rmList = [rmList]
|
| 375 |
|
|
|
375 |
|
| 376 |
376 |
for rm in rmList:
|
| 377 |
377 |
rmFile = self.__find(rm, curDir)
|
| 378 |
378 |
if not rmFile: continue
|
| ... | ... | |
| 383 |
383 |
|
| 384 |
384 |
def __upload(self):
|
| 385 |
385 |
"""Upload files"""
|
| 386 |
|
try: # Windows needs stdio set for binary mode.
|
| 387 |
|
import msvcrt
|
| 388 |
|
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
|
| 389 |
|
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
|
| 390 |
|
except ImportError:
|
| 391 |
|
pass
|
| 392 |
|
|
|
386 |
|
| 393 |
387 |
if 'current' in self._request:
|
| 394 |
388 |
curDir = self.__findDir(self._request['current'], None)
|
| 395 |
389 |
if not curDir:
|
| ... | ... | |
| 404 |
398 |
|
| 405 |
399 |
upFiles = self._request['upload[]']
|
| 406 |
400 |
# invalid format
|
| 407 |
|
# must be dict('filename1': 'filedescriptor1', 'filename2': 'filedescriptor2', ...)
|
| 408 |
|
if not isinstance(upFiles, dict):
|
|
401 |
# must be list of InMemoryUploadedFile
|
|
402 |
if not isinstance(upFiles, list):
|
| 409 |
403 |
self._response['error'] = 'Invalid parameters'
|
| 410 |
404 |
return
|
| 411 |
405 |
|
| ... | ... | |
| 413 |
407 |
total = 0
|
| 414 |
408 |
upSize = 0
|
| 415 |
409 |
maxSize = self._options['uploadMaxSize'] * 1024 * 1024
|
| 416 |
|
for name, data in upFiles.iteritems():
|
| 417 |
|
if name:
|
|
410 |
for upFile in upFiles:
|
|
411 |
if upFile.name:
|
| 418 |
412 |
total += 1
|
| 419 |
|
name = os.path.basename(name)
|
|
413 |
name = os.path.basename(upFile.name)
|
| 420 |
414 |
if not self.__checkName(name):
|
| 421 |
415 |
self.__errorData(name, 'Invalid name')
|
| 422 |
416 |
else:
|
| 423 |
417 |
name = os.path.join(curDir, name)
|
| 424 |
418 |
try:
|
| 425 |
419 |
f = open(name, 'wb', self._options['uploadWriteChunk'])
|
| 426 |
|
for chunk in self.__fbuffer(data):
|
| 427 |
|
f.write(chunk)
|
|
420 |
f.write(upFile.read())
|
| 428 |
421 |
f.close()
|
| 429 |
422 |
upSize += os.lstat(name).st_size
|
| 430 |
423 |
if self.__isUploadAllow(name):
|
| ... | ... | |
| 591 |
584 |
return False
|
| 592 |
585 |
else:
|
| 593 |
586 |
return False
|
| 594 |
|
|
| 595 |
587 |
self.__initImgLib()
|
| 596 |
588 |
if self.__canCreateTmb():
|
| 597 |
589 |
if self._options['tmbAtOnce'] > 0:
|
| ... | ... | |
| 784 |
776 |
pd = os.path.join(path, d)
|
| 785 |
777 |
if os.path.isdir(pd) and not os.path.islink(pd) and self.__isAccepted(d):
|
| 786 |
778 |
tree['dirs'].append(self.__tree(pd))
|
| 787 |
|
|
| 788 |
779 |
return tree
|
| 789 |
780 |
|
| 790 |
781 |
|
| ... | ... | |
| 1319 |
1310 |
if not self._options['imgLib'] is False and self._im is None:
|
| 1320 |
1311 |
try:
|
| 1321 |
1312 |
import Image
|
| 1322 |
|
Image
|
|
1313 |
#Image
|
| 1323 |
1314 |
self._im = Image
|
| 1324 |
1315 |
self._options['imgLib'] = 'PIL'
|
| 1325 |
1316 |
except:
|
| ... | ... | |
| 1357 |
1348 |
archive = { 'create': {}, 'extract': {} }
|
| 1358 |
1349 |
c = archive['create']
|
| 1359 |
1350 |
e = archive['extract']
|
|
1351 |
|
|
1352 |
#__checkArchivers is OFF
|
|
1353 |
self._options['archiveMimes'] = c.keys()
|
|
1354 |
self._options['archivers'] = archive
|
|
1355 |
return
|
|
1356 |
#__checkArchivers is OFF
|
| 1360 |
1357 |
|
| 1361 |
1358 |
tar = self.__runSubProcess(['tar', '--version'])
|
| 1362 |
1359 |
gzip = self.__runSubProcess(['gzip', '--version'])
|