Exemple #1
0
 def _threadDoGETJob( self, request ):
     
     self._checkBandwidth( request )
     
     # no permission check as any functional account can get thumbnails
     
     hash = request.parsed_request_args[ 'hash' ]
     
     ( valid, mime ) = HG.server_controller.Read( 'service_has_file', self._service_key, hash )
     
     if not valid:
         
         raise HydrusExceptions.NotFoundException( 'Thumbnail not found on this service!' )
         
     
     if mime not in HC.MIMES_WITH_THUMBNAILS:
         
         raise HydrusExceptions.NotFoundException( 'That mime should not have a thumbnail!' )
         
     
     path = ServerFiles.GetThumbnailPath( hash )
     
     response_context = HydrusServerResources.ResponseContext( 200, mime = HC.APPLICATION_OCTET_STREAM, path = path )
     
     return response_context
Exemple #2
0
 def _threadDoPOSTJob( self, request ):
     
     HG.server_controller.ShutdownFromServer()
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #3
0
    def _threadDoPOSTJob(self, request):

        services = request.parsed_request_args['services']

        unique_ports = {service.GetPort() for service in services}

        if len(unique_ports) < len(services):

            raise HydrusExceptions.BadRequestException(
                'It looks like some of those services share ports! Please give them unique ports!'
            )

        with HG.dirty_object_lock:

            HG.server_controller.SetServices(services)

            service_keys_to_access_keys = HG.server_controller.WriteSynchronous(
                'services', request.hydrus_account, services)

        body = HydrusNetwork.DumpHydrusArgsToNetworkBytes(
            {'service_keys_to_access_keys': service_keys_to_access_keys})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
Exemple #4
0
    def _threadDoGETJob(self, request):

        num = request.parsed_request_args['num']
        account_type_key = request.parsed_request_args['account_type_key']

        if 'expires' in request.parsed_request_args:

            expires = request.parsed_request_args['expires']

        else:

            expires = None

        registration_keys = HG.server_controller.Read('registration_keys',
                                                      self._service_key,
                                                      request.hydrus_account,
                                                      num, account_type_key,
                                                      expires)

        body = HydrusNetwork.DumpHydrusArgsToNetworkBytes(
            {'registration_keys': registration_keys})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
Exemple #5
0
    def _threadDoGETJob(self, request):

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetData()

        else:

            raise HydrusExceptions.MissingCredentialsException(
                'I was expecting an account key, but did not get one!')

        subject_account = HG.server_controller.Read('account',
                                                    self._service_key,
                                                    subject_account_key)

        account_info = HG.server_controller.Read('account_info',
                                                 self._service_key,
                                                 request.hydrus_account,
                                                 subject_account)

        body = HydrusNetwork.DumpHydrusArgsToNetworkBytes(
            {'account_info': account_info})

        response_context = HydrusServerResources.ResponseContext(200,
                                                                 body=body)

        return response_context
Exemple #6
0
 def _threadDoGETJob( self, request ):
     
     account = request.hydrus_account
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'account' : account } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #7
0
 def _threadDoGETJob( self, request ):
     
     petition_count_info = HG.server_controller.Read( 'num_petitions', self._service_key, request.hydrus_account )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'num_petitions' : petition_count_info } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #8
0
 def _threadDoGETJob( self, request ):
     
     services = HG.server_controller.Read( 'services_from_account', request.hydrus_account )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'services' : services } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #9
0
 def _threadDoPOSTJob( self, request ):
     
     # check permission here since this is an asynchronous job
     request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_SERVICES, HC.PERMISSION_ACTION_OVERRULE )
     
     HG.server_controller.Write( 'vacuum' )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #10
0
 def _threadDoPOSTJob( self, request ):
     
     client_to_server_update = request.parsed_request_args[ 'client_to_server_update' ]
     
     timestamp = self._service.GetMetadata().GetNextUpdateBegin() + 1
     
     HG.server_controller.WriteSynchronous( 'update', self._service_key, request.hydrus_account, client_to_server_update, timestamp )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #11
0
 def _threadDoGETJob( self, request ):
     
     updates = HG.server_controller.Read( 'immediate_update', self._service_key, request.hydrus_account )
     
     updates = HydrusSerialisable.SerialisableList( updates )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'updates' : updates } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #12
0
 def _threadDoGETJob( self, request ):
     
     registration_key = request.parsed_request_args[ 'registration_key' ]
     
     access_key = HG.server_controller.Read( 'access_key', self._service_key, registration_key )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'access_key' : access_key } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #13
0
 def _threadDoGETJob( self, request ):
     
     hash = request.parsed_request_args[ 'hash' ]
     
     ( ip, timestamp ) = HG.server_controller.Read( 'ip', self._service_key, request.hydrus_account, hash )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'ip' : ip, 'timestamp' : timestamp } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #14
0
 def _threadDoGETJob( self, request ):
     
     access_key = self._parseHydrusNetworkAccessKey( request )
     
     verified = HG.server_controller.Read( 'verify_access_key', self._service_key, access_key )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'verified' : verified } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #15
0
 def _threadDoGETJob( self, request ):
     
     content_type = request.parsed_request_args[ 'content_type' ]
     status = request.parsed_request_args[ 'status' ]
     
     petition = HG.server_controller.Read( 'petition', self._service_key, request.hydrus_account, content_type, status )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'petition' : petition } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #16
0
 def _threadDoPOSTJob( self, request ):
     
     account_types = request.parsed_request_args[ 'account_types' ]
     deletee_account_type_keys_to_new_account_type_keys = request.parsed_request_args[ 'deletee_account_type_keys_to_new_account_type_keys' ]
     
     HG.server_controller.WriteSynchronous( 'account_types', self._service_key, request.hydrus_account, account_types, deletee_account_type_keys_to_new_account_type_keys )
     
     HG.server_controller.server_session_manager.RefreshAccounts( self._service_key )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #17
0
 def _threadDoGETJob( self, request ):
     
     # no permissions check as any functional account can get metadata slices
     
     since = request.parsed_request_args[ 'since' ]
     
     metadata_slice = self._service.GetMetadataSlice( since )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'metadata_slice' : metadata_slice } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
Exemple #18
0
 def _threadDoGETJob( self, request ):
     
     access_key = self._parseHydrusNetworkAccessKey( request )
     
     ( session_key, expires ) = HG.server_controller.server_session_manager.AddSession( self._service_key, access_key )
     
     now = HydrusData.GetNow()
     
     max_age = expires - now
     
     cookies = [ ( 'session_key', session_key.hex(), { 'max_age' : str( max_age ), 'path' : '/' } ) ]
     
     response_context = HydrusServerResources.ResponseContext( 200, cookies = cookies )
     
     return response_context
Exemple #19
0
 def _threadDoPOSTJob( self, request ):
     
     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
Exemple #20
0
 def _threadDoGETJob( self, request ):
     
     self._checkBandwidth( request )
     
     # no permissions check as any functional account can get updates
     
     update_hash = request.parsed_request_args[ 'update_hash' ]
     
     if not self._service.HasUpdateHash( update_hash ):
         
         raise HydrusExceptions.NotFoundException( 'This update hash does not exist on this service!' )
         
     
     path = ServerFiles.GetFilePath( update_hash )
     
     response_context = HydrusServerResources.ResponseContext( 200, mime = HC.APPLICATION_OCTET_STREAM, path = path )
     
     return response_context
Exemple #21
0
 def _threadDoPOSTJob( self, request ):
     
     action = request.parsed_request_args[ 'action' ]
     
     subject_accounts = request.parsed_request_args[ 'accounts' ]
     
     kwargs = request.parsed_request_args # for things like expires, title, and so on
     
     with HG.dirty_object_lock:
         
         HG.server_controller.WriteSynchronous( 'account_modification', self._service_key, request.hydrus_account, action, subject_accounts, **kwargs )
         
         HG.server_controller.server_session_manager.UpdateAccounts( self._service_key, subject_accounts )
         
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #22
0
 def _threadDoPOSTJob( self, request ):
     
     # check permission here since no db work
     request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_SERVICES, HC.PERMISSION_ACTION_OVERRULE )
     
     try:
         
         HG.server_busy.release()
         
     except threading.ThreadError:
         
         raise HydrusExceptions.BadRequestException( 'The server is not busy!' )
         
     
     HG.server_controller.db.PauseAndDisconnect( False )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #23
0
 def _threadDoPOSTJob( self, request ):
     
     # check permission here since no db work
     request.hydrus_account.CheckPermission( HC.CONTENT_TYPE_SERVICES, HC.PERMISSION_ACTION_OVERRULE )
     
     locked = HG.server_busy.acquire( False ) # pylint: disable=E1111
     
     if not locked:
         
         raise HydrusExceptions.BadRequestException( 'The server was already locked!' )
         
     
     HG.server_controller.db.PauseAndDisconnect( True )
     
     # shut down db, wait until it is done?
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
Exemple #24
0
 def _threadDoGETJob( self, request ):
     
     self._checkBandwidth( request )
     
     # no permission check as any functional account can get files
     
     hash = request.parsed_request_args[ 'hash' ]
     
     ( valid, mime ) = HG.server_controller.Read( 'service_has_file', self._service_key, hash )
     
     if not valid:
         
         raise HydrusExceptions.NotFoundException( 'File not found on this service!' )
         
     
     path = ServerFiles.GetFilePath( hash )
     
     response_context = HydrusServerResources.ResponseContext( 200, mime = mime, path = path )
     
     return response_context