|
Lines 631-665
Link Here
|
| 631 |
global _upload_manager |
631 |
global _upload_manager |
| 632 |
req = umcp.Request('UPLOAD', arguments=[path]) |
632 |
req = umcp.Request('UPLOAD', arguments=[path]) |
| 633 |
|
633 |
|
|
|
634 |
self._log('info', '##### raw request: %r' % (req, )) |
| 635 |
|
| 634 |
options = [] |
636 |
options = [] |
| 635 |
body = {} |
637 |
body = {} |
| 636 |
for iid, ifield in args.iteritems(): |
|
|
| 637 |
if isinstance(ifield, cherrypy._cpreqbody.Part): |
| 638 |
# field is a FieldStorage object |
| 639 |
store = ifield |
| 640 |
tmpfile = _upload_manager.add(req.id, store) |
| 641 |
|
638 |
|
| 642 |
# check if filesize is allowed |
639 |
def _check_field_storage(iid, ifield): |
| 643 |
st = os.stat(tmpfile) |
640 |
# field is a FieldStorage object |
| 644 |
max_size = int(configRegistry.get('umc/server/upload/max', 64)) * 1024 |
641 |
store = ifield |
| 645 |
if st.st_size > max_size: |
642 |
tmpfile = _upload_manager.add(req.id, store) |
| 646 |
self._log('warn', 'file of size %d could not be uploaded' % (st.st_size)) |
|
|
| 647 |
raise cherrypy.HTTPError(httplib.BAD_REQUEST, 'The size of the uploaded file is too large') |
| 648 |
|
643 |
|
| 649 |
# check if enough free space is available |
644 |
# check if filesize is allowed |
| 650 |
min_size = int(configRegistry.get('umc/server/upload/min_free_space', 51200)) # kilobyte |
645 |
st = os.stat(tmpfile) |
| 651 |
s = os.statvfs(tmpfile) |
646 |
max_size = int(configRegistry.get('umc/server/upload/max', 64)) * 1024 |
| 652 |
free_disk_space = s.f_bavail * s.f_frsize / 1024 # kilobyte |
647 |
if st.st_size > max_size: |
| 653 |
if free_disk_space < min_size: |
648 |
self._log('warn', 'file of size %d could not be uploaded' % (st.st_size)) |
| 654 |
self._log('error', 'there is not enough free space to upload files') |
649 |
raise cherrypy.HTTPError(httplib.BAD_REQUEST, 'The size of the uploaded file is too large') |
| 655 |
raise cherrypy.HTTPError(httplib.BAD_REQUEST, 'There is not enough free space on disk') |
|
|
| 656 |
|
650 |
|
| 657 |
filename = store.filename |
651 |
# check if enough free space is available |
| 658 |
# some security |
652 |
min_size = int(configRegistry.get('umc/server/upload/min_free_space', 51200)) # kilobyte |
| 659 |
for c in ('<>/'): |
653 |
s = os.statvfs(tmpfile) |
| 660 |
filename = filename.replace(c, '_') |
654 |
free_disk_space = s.f_bavail * s.f_frsize / 1024 # kilobyte |
|
|
655 |
if free_disk_space < min_size: |
| 656 |
self._log('error', 'there is not enough free space to upload files') |
| 657 |
raise cherrypy.HTTPError(httplib.BAD_REQUEST, 'There is not enough free space on disk') |
| 661 |
|
658 |
|
| 662 |
options.append({'filename': filename, 'name': store.name, 'tmpfile': tmpfile}) |
659 |
filename = store.filename |
|
|
660 |
# some security |
| 661 |
for c in ('<>/'): |
| 662 |
filename = filename.replace(c, '_') |
| 663 |
|
| 664 |
options.append({'filename': filename, 'name': store.name, 'tmpfile': tmpfile}) |
| 665 |
|
| 666 |
|
| 667 |
for iid, ifield in args.iteritems(): |
| 668 |
self._log('info','###### iid, ifield: %r ; %r' % (iid, ifield, )) |
| 669 |
if isinstance(ifield, cherrypy._cpreqbody.Part): |
| 670 |
self._log('info', '### One File for upload') |
| 671 |
_check_field_storage(iid, ifield) |
| 672 |
elif isinstance(ifield, list): |
| 673 |
self._log('info', '### Several Files for upload') |
| 674 |
self._log('info', '### ifield: %r' % (ifield, )) |
| 675 |
for jfield in ifield: |
| 676 |
self._log('info', '### jfield: %r' % (jfield, )) |
| 677 |
if isinstance(jfield, cherrypy._cpreqbody.Part): |
| 678 |
_check_field_storage(iid, jfield) |
| 679 |
else: |
| 680 |
# we cannot handle any other type |
| 681 |
CORE.warn('Unknown type of multipart/form entry: %s=%s' % (iid, ifield)) |
| 663 |
elif isinstance(ifield, basestring): |
682 |
elif isinstance(ifield, basestring): |
| 664 |
# field is a string :) |
683 |
# field is a string :) |
| 665 |
body[iid] = ifield |
684 |
body[iid] = ifield |
|
Lines 684-689
Link Here
|
| 684 |
|
703 |
|
| 685 |
response = self.get_response(sessionid, path, kwargs) |
704 |
response = self.get_response(sessionid, path, kwargs) |
| 686 |
|
705 |
|
|
|
706 |
self._log('info','#### response %r' % (response, )) |
| 707 |
|
| 687 |
# check if the request is a iframe upload |
708 |
# check if the request is a iframe upload |
| 688 |
if 'iframe' in kwargs and (kwargs['iframe'] not in ('false', False, 0, '0')): |
709 |
if 'iframe' in kwargs and (kwargs['iframe'] not in ('false', False, 0, '0')): |
| 689 |
# this is a workaround to make iframe uploads work, they need the textarea field |
710 |
# this is a workaround to make iframe uploads work, they need the textarea field |