Changeset fcfd2a in indico


Ignore:
Timestamp:
08/10/11 14:06:04 (22 months ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
15b835
Parents:
90ed06
git-author:
Stefan Petrovski <stefan.petrovski@…> (06/10/11 16:58:02)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (08/10/11 14:06:04)
Message:

[IMP] Added max file size check for upload

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • etc/indico.conf.sample

    r8234edd rfcfd2a  
    150150# IndicoSearchClass    = "MaKaC.search.invenioSEA.InvenioSEA" 
    151151 
     152#------------------------------------------------------------------------------ 
     153# FILE UPLOAD 
     154#------------------------------------------------------------------------------ 
     155# Here you can limit the maximum size of uploaded files (in MB) 
     156# default: 0 (unlimited) 
     157 
     158MaxUploadFileSize = 0 
    152159 
    153160#------------------------------------------------------------------------------ 
  • indico/MaKaC/common/Configuration.py

    r8234edd rfcfd2a  
    466466        'AuthenticatedEnforceSecure': 'yes', 
    467467        'ExportACL'           : {}, 
    468          
     468        'MaxUploadFileSize' : '1024', 
    469469        # Authentication 
    470470        'LDAPConfig': {'host': 'myldapserver.example.com', 
  • indico/MaKaC/webinterface/rh/conferenceBase.py

    r0e7b55 rfcfd2a  
    3939from MaKaC.common.logger import Logger 
    4040 
     41from indico.util import json 
     42 
     43BYTES_1MB = 1024 * 1024 
     44 
     45 
    4146class RHCustomizable( RH ): 
    4247 
     
    200205        self._setMenuStatus(params) 
    201206 
     207 
    202208class RHSubmitMaterialBase: 
    203209 
     
    211217        self._target=target 
    212218        self._callerRH = rh 
     219        self._req = rh._req 
    213220        self._repositoryIds = None 
     221        self._errorList = [] 
     222        self._cfg = Config.getInstance() 
    214223 
    215224    def _getNewTempFile( self ): 
    216225        cfg = Config.getInstance() 
    217226        tempPath = cfg.getUploadedFilesTempDir() 
    218         tempFileName = tempfile.mkstemp( suffix="Indico.tmp", dir = tempPath )[1] 
     227        tempFileName = tempfile.mkstemp(suffix="Indico.tmp", dir=tempPath)[1] 
    219228        return tempFileName 
    220229 
     
    246255        self._password = params.get("password","") 
    247256 
    248         from MaKaC.services.interface.rpc import json 
    249         self._userList = json.decode(params.get("userList", "[]")) 
     257        self._userList = json.loads(params.get("userList", "[]")) 
     258        maxUploadFileSize = self._cfg.getMaxUploadFileSize() 
    250259 
    251260        if self._uploadType == "file": 
     
    260269                if type(fileUpload) != str and fileUpload.filename.strip() != "": 
    261270                    fDict = {} 
    262                     fDict["filePath"] = self._saveFileToTemp(fileUpload.file) 
    263  
    264                     if self._callerRH != None: 
    265                         self._callerRH._tempFilesToDelete.append(fDict["filePath"]) 
    266271 
    267272                    fDict["fileName"] = fileUpload.filename 
    268                     fDict["size"] = int(os.stat(fDict["filePath"])[stat.ST_SIZE]) 
     273                    estimSize = int(self._req.headers_in["content-length"]) 
     274 
     275                    if maxUploadFileSize and estimSize > (maxUploadFileSize * BYTES_1MB): 
     276                        # if file is too big, do not save it in disk 
     277                        fDict["filePath"] = '' 
     278                        fDict["size"] = estimSize 
     279                    else: 
     280                        fDict["filePath"] = self._saveFileToTemp(fileUpload.file) 
     281                        fDict["size"] = int(os.stat(fDict["filePath"])[stat.ST_SIZE]) 
     282                        if self._callerRH != None: 
     283                            self._callerRH._tempFilesToDelete.append(fDict["filePath"]) 
     284 
     285                    self._setErrorList(fDict) 
    269286                    self._files.append(fDict) 
    270287 
     
    285302 
    286303 
    287     def _getErrorList(self): 
     304    def _setErrorList(self, fileEntry): 
    288305        res=[] 
    289306 
     307        maxUploadFileSize = self._cfg.getMaxUploadFileSize() 
     308 
    290309        if self._uploadType == "file": 
    291             if not self._files: 
    292                 res.append(_("""A file must be submitted.""")) 
    293             for fileEntry in self._files: 
    294                 if hasattr(fileEntry, "filePath") and not fileEntry["filePath"].strip(): 
    295                     res.append(_("""A valid file to be submitted must be specified.""")) 
    296                 if hasattr(fileEntry, "size") and fileEntry["size"] < 10: 
    297                     res.append(_("""The file %s seems to be empty""") % fileEntry["fileName"]) 
     310            if "filePath" in fileEntry and not fileEntry["filePath"].strip(): 
     311                self._errorList.append(_("""A valid file to be submitted must be specified. """)) 
     312            if "size" in fileEntry: 
     313                if fileEntry["size"] < 10: 
     314                    self._errorList.append(_("""The file %s seems to be empty """) % fileEntry["fileName"]) 
     315                elif maxUploadFileSize and fileEntry["size"] > (maxUploadFileSize*1024*1024): 
     316                    self._errorList.append(_("The file size of %s exceeds the upload limit (%s Mb)") % (fileEntry["fileName"], maxUploadFileSize)) 
    298317        elif self._uploadType == "link": 
    299318            if not self._links[0]["url"].strip(): 
    300                 res.append(_("""A valid URL must be specified.""")) 
     319                self._errorList.append(_("""A valid URL must be specified.""")) 
    301320 
    302321        if self._materialId=="": 
    303             res.append(_("""A material ID must be selected.""")) 
     322            self._errorList.append(_("""A material ID must be selected.""")) 
    304323        return res 
    305324 
     
    454473            text = "" 
    455474 
    456         errorList=self._getErrorList() 
    457  
    458475        try: 
    459             if len(errorList) > 0: 
    460                 status = "ERROR" 
    461                 info = errorList 
     476            if len(self._errorList) > 0: 
     477                status = "NOREPORT" 
     478                info = self._errorList 
    462479            else: 
    463480                mat, status, info = self._addMaterialType(text, user) 
     
    465482                if status == "OK": 
    466483                    for entry in info: 
    467                         entry['material'] = mat.getId(); 
     484                        entry['material'] = mat.getId() 
    468485        except Exception, e: 
    469486            status = "ERROR" 
    470             info = errorList + ["%s: %s" % (e.__class__.__name__, str(e))] 
     487            info = self._errorList + ["%s: %s" % (e.__class__.__name__, str(e))] 
    471488            Logger.get('requestHandler').exception('Error uploading file') 
    472  
    473489        # hackish, because of mime types. Konqueror, for instance, would assume text if there were no tags, 
    474490        # and would try to open it 
    475         from MaKaC.services.interface.rpc import json 
    476         return "<html><head></head><body>"+json.encode({'status': status, 'info': info})+"</body></html>" 
    477  
     491        return "<html><head></head><body>%s</body></html>" %\ 
     492               json.dumps({'status': status, 'info': info}) 
  • indico/htdocs/js/indico/MaterialEditor/Editor.js

    r8234edd rfcfd2a  
    6767        return buttonDiv; 
    6868    }, 
    69  
    7069 
    7170    /* 
     
    482481                        requestInfo: {}, 
    483482                        message: resp.info }); 
     483                } else if (resp.status == "NOREPORT") { 
     484                    IndicoUtil.errorReport({ 
     485                        type: "noReport", 
     486                        code: '0', 
     487                        requestInfo: {}, 
     488                        message: resp.info }); 
    484489                } else { 
    485490                    self.onUpload(resp.info); 
Note: See TracChangeset for help on using the changeset viewer.