def _callbackParsePOSTArgs( self, request: HydrusServerRequest.HydrusRequest ):
     
     request.content.seek( 0 )
     
     if not request.requestHeaders.hasHeader( 'Content-Type' ):
         
         parsed_request_args = HydrusNetworkVariableHandling.ParsedRequestArguments()
         
     else:
         
         content_types = request.requestHeaders.getRawHeaders( 'Content-Type' )
         
         content_type = content_types[0]
         
         try:
             
             mime = HC.mime_enum_lookup[ content_type ]
             
         except:
             
             raise HydrusExceptions.BadRequestException( 'Did not recognise Content-Type header!' )
             
         
         total_bytes_read = 0
         
         if mime == HC.APPLICATION_JSON:
             
             json_string = request.content.read()
             
             total_bytes_read += len( json_string )
             
             parsed_request_args = HydrusNetworkVariableHandling.ParseNetworkBytesToParsedHydrusArgs( json_string )
             
         else:
             
             ( os_file_handle, temp_path ) = HydrusPaths.GetTempPath()
             
             request.temp_file_info = ( os_file_handle, temp_path )
             
             with open( temp_path, 'wb' ) as f:
                 
                 for block in HydrusPaths.ReadFileLikeAsBlocks( request.content ): 
                     
                     f.write( block )
                     
                     total_bytes_read += len( block )
                     
                 
             
             decompression_bombs_ok = self._DecompressionBombsOK( request )
             
             parsed_request_args = HydrusNetworkVariableHandling.ParseFileArguments( temp_path, decompression_bombs_ok )
             
         
         self._reportDataUsed( request, total_bytes_read )
         
     
     request.parsed_request_args = parsed_request_args
     
     return request
 def _checkAccountPermissions( self, request: HydrusServerRequest.HydrusRequest ):
     
     if request.IsGET():
         
         request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_ACCOUNTS, HC.PERMISSION_ACTION_CREATE )
         
     elif request.IsPOST():
         
         request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_ACCOUNT_TYPES, HC.PERMISSION_ACTION_MODERATE )
Exemple #3
0
    def render_GET(self, request: HydrusServerRequest.HydrusRequest):

        request.setResponseCode(200)

        if HG.server_busy.locked():

            return b'1'

        else:

            return b'0'
    def render_GET(self, request: HydrusServerRequest.HydrusRequest):

        request.setResponseCode(200)

        request.setHeader('Server', self._server_version_string)

        if HG.server_busy.locked():

            return b'1'

        else:

            return b'0'
 def _checkAccountPermissions( self, request: HydrusServerRequest.HydrusRequest ):
     
     # everyone with a functional account can read files
     
     if request.IsPOST():
         
         request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_FILES, HC.PERMISSION_ACTION_CREATE )
 def _callbackParseGETArgs( self, request: HydrusServerRequest.HydrusRequest ):
     
     parsed_request_args = HydrusNetworkVariableHandling.ParseHydrusNetworkGETArgs( request.args )
     
     request.parsed_request_args = parsed_request_args
     
     return request
 def _checkAccountPermissions( self, request: HydrusServerRequest.HydrusRequest ):
     
     # everyone with a functional account can read updates
     
     if request.IsPOST():
         
         # further permissions checked in the db
         
         request.hydrus_account.CheckAtLeastOnePermission( [ ( content_type, HC.PERMISSION_ACTION_PETITION ) for content_type in HC.REPOSITORY_CONTENT_TYPES ] )
    def _callbackEstablishAccountFromHeader(
            self, request: HydrusServerRequest.HydrusRequest):

        session_key = None

        if request.requestHeaders.hasHeader('Cookie'):

            cookie_texts = request.requestHeaders.getRawHeaders('Cookie')

            cookie_text = cookie_texts[0]

            try:

                cookies = http.cookies.SimpleCookie(cookie_text)

                if 'session_key' in cookies:

                    # Morsel, for real, ha ha ha
                    morsel = cookies['session_key']

                    session_key_hex = morsel.value

                    session_key = bytes.fromhex(session_key_hex)

            except:

                raise HydrusExceptions.BadRequestException(
                    'Problem parsing cookies for Session Cookie!')

        if session_key is None:

            access_key = self._parseHydrusNetworkAccessKey(request,
                                                           key_required=False)

            if access_key is None:

                raise HydrusExceptions.MissingCredentialsException(
                    'No credentials found in request!')

            else:

                account = HG.server_controller.server_session_manager.GetAccountFromAccessKey(
                    self._service_key, access_key)

        else:

            account = HG.server_controller.server_session_manager.GetAccount(
                self._service_key, session_key)

        request.hydrus_account = account

        return request
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     file_dict = request.parsed_request_args
     
     if self._service.LogUploaderIPs():
         
         file_dict[ 'ip' ] = request.getClientIP()
         
     
     timestamp = self._service.GetMetadata().GetNextUpdateBegin() + 1
     
     HG.server_controller.WriteSynchronous( 'file', self._service, request.hydrus_account, file_dict, timestamp )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context