示例#1
0
 def _InitRoot( self ):
     
     root = Resource()
     
     root.putChild( b'', HydrusServerResources.HydrusResourceWelcome( self._service, REMOTE_DOMAIN ) )
     root.putChild( b'favicon.ico', HydrusServerResources.hydrus_favicon )
     root.putChild( b'robots.txt', HydrusServerResources.HydrusResourceRobotsTXT( self._service, REMOTE_DOMAIN ) )
     
     return root
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     if 'subject_identifier' not in request.parsed_request_args:
         
         raise HydrusExceptions.BadRequestException( 'I was expecting an account id, but did not get one!' )
         
     
     subject_identifier = request.parsed_request_args[ 'subject_identifier' ]
     
     if subject_identifier.HasAccountKey():
         
         subject_account_key = subject_identifier.GetAccountKey()
         
     else:
         
         raise HydrusExceptions.BadRequestException( 'The subject\'s account identifier did not include an account id!' )
         
     
     if 'message' not in request.parsed_request_args:
         
         raise HydrusExceptions.BadRequestException( 'I was expecting a new message, but did not get one!' )
         
     
     message = request.parsed_request_args[ 'message' ]
     
     if not isinstance( message, str ):
         
         raise HydrusExceptions.BadRequestException( 'The given message was not a string!' )
         
     
     HG.server_controller.WriteSynchronous( 'modify_account_set_message', self._service_key, request.hydrus_account, subject_account_key, message )
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
示例#3
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        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 = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'service_keys_to_access_keys': service_keys_to_access_keys})

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

        return response_context
示例#4
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        HG.server_controller.ShutdownFromServer()

        response_context = HydrusServerResources.ResponseContext(200)

        return response_context
示例#5
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

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

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key!'
            )

        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 = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'account_info': account_info})

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

        return response_context
示例#6
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        HG.server_controller.Write('backup')

        response_context = HydrusServerResources.ResponseContext(200)

        return response_context
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     update_period = request.parsed_request_args[ 'update_period' ]
     
     if update_period < HydrusNetwork.MIN_UPDATE_PERIOD:
         
         raise HydrusExceptions.BadRequestException( 'The update period was too low. It needs to be at least {}.'.format( HydrusData.TimeDeltaToPrettyTimeDelta( HydrusNetwork.MIN_UPDATE_PERIOD ) ) )
         
     
     if update_period > HydrusNetwork.MAX_UPDATE_PERIOD:
         
         raise HydrusExceptions.BadRequestException( 'The update period was too high. It needs to be lower than {}.'.format( HydrusData.TimeDeltaToPrettyTimeDelta( HydrusNetwork.MAX_UPDATE_PERIOD ) ) )
         
     
     old_update_period = self._service.GetUpdatePeriod()
     
     if old_update_period != update_period:
         
         self._service.SetUpdatePeriod( update_period )
         
         HydrusData.Print(
             'Account {} changed the update period to from "{}" to "{}".'.format(
                 request.hydrus_account.GetAccountKey().hex(),
                 HydrusData.TimeDeltaToPrettyTimeDelta( old_update_period ),
                 HydrusData.TimeDeltaToPrettyTimeDelta( update_period )
             )
         )
         
     
     response_context = HydrusServerResources.ResponseContext( 200 )
     
     return response_context
示例#8
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        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
示例#9
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

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

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key!'
            )

        HG.server_controller.WriteSynchronous('modify_account_unban',
                                              self._service_key,
                                              request.hydrus_account,
                                              subject_account_key)

        response_context = HydrusServerResources.ResponseContext(200)

        return response_context
示例#10
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        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 = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'registration_keys': registration_keys})

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

        return response_context
示例#11
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

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

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key!'
            )

        if 'reason' not in request.parsed_request_args:

            raise HydrusExceptions.BadRequestException(
                'I was expecting a reason for the ban, but did not get one!')

        if 'expires' not in request.parsed_request_args:

            raise HydrusExceptions.BadRequestException(
                'I was expecting a new expiration timestamp, but did not get one!'
            )

        reason = request.parsed_request_args['reason']

        if not isinstance(reason, str):

            raise HydrusExceptions.BadRequestException(
                'The given ban reason was not a string!')

        expires = request.parsed_request_args['expires']

        expires_is_none = expires is None
        expires_is_positive_integer = isinstance(expires, int) and expires > 0

        expires_is_valid = expires_is_none or expires_is_positive_integer

        if not expires_is_valid:

            raise HydrusExceptions.BadRequestException(
                'The given expiration timestamp was not null or an integer!')

        HG.server_controller.WriteSynchronous('modify_account_ban',
                                              self._service_key,
                                              request.hydrus_account,
                                              subject_account_key, reason,
                                              expires)

        response_context = HydrusServerResources.ResponseContext(200)

        return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     service_options = self._service.GetServiceOptions()
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'service_options' : service_options } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account = request.hydrus_account
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'account' : account } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account_types = HG.server_controller.Read( 'account_types', self._service_key, request.hydrus_account )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'account_types' : account_types } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # cache this
     petition_count_info = HG.server_controller.Read( 'num_petitions', self._service_key, request.hydrus_account )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'num_petitions' : petition_count_info } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     since = request.parsed_request_args[ 'since' ]
     
     metadata_slice = self._service.GetMetadataSlice( since )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'metadata_slice' : metadata_slice } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     account_type_key = request.parsed_request_args[ 'account_type_key' ]
     
     registration_key = HG.server_controller.Read( 'auto_create_registration_key', self._service_key, account_type_key )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'registration_key' : registration_key } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     updates = HG.server_controller.Read( 'immediate_update', self._service_key, request.hydrus_account )
     
     updates = HydrusSerialisable.SerialisableList( updates )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'updates' : updates } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     hash = request.parsed_request_args[ 'hash' ]
     
     ( ip, timestamp ) = HG.server_controller.Read( 'ip', self._service_key, request.hydrus_account, hash )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'ip' : ip, 'timestamp' : timestamp } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     access_key = self._parseHydrusNetworkAccessKey( request )
     
     verified = HG.server_controller.Read( 'verify_access_key', self._service_key, access_key )
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'verified' : verified } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     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
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # fetch cached summary list
     # ( account_key, reason, size of petition )
     petition_summary_list = []
     
     body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'petition_summary_list' : petition_summary_list } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoPOSTJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     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
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     # rewangle this to take an id from the summary list. probably ( account_key, reason_id )
     # and combine petitioned and pending into the same petition
     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 = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( { 'petition' : petition } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     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
示例#26
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        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
示例#27
0
    def _threadDoPOSTJob(self, request: HydrusServerRequest.HydrusRequest):

        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
 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
 def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
     
     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
示例#30
0
    def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest):

        if 'subject_identifier' not in request.parsed_request_args:

            raise HydrusExceptions.BadRequestException(
                'I was expecting an account identifier for the subject, but did not get one!'
            )

        subject_identifier = request.parsed_request_args['subject_identifier']

        if subject_identifier.HasAccountKey():

            subject_account_key = subject_identifier.GetAccountKey()

            try:

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

            except HydrusExceptions.InsufficientCredentialsException as e:

                raise HydrusExceptions.NotFoundException(e)

        elif subject_identifier.HasContent():

            subject_content = subject_identifier.GetContent()

            subject_account = HG.server_controller.Read(
                'account_from_content', self._service_key, subject_content)

        else:

            raise HydrusExceptions.BadRequestException(
                'The subject\'s account identifier did not include an account key or content!'
            )

        body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes(
            {'account': subject_account})

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

        return response_context