Пример #1
0
    def _threadDoGETJob(self, request):

        share_key = request.hydrus_args['share_key']
        hash = request.hydrus_args['hash']

        local_booru_manager = HC.app.GetManager('local_booru')

        local_booru_manager.CheckFileAuthorised(share_key, hash)

        media_result = local_booru_manager.GetMediaResult(share_key, hash)

        mime = media_result.GetMime()

        if mime in HC.MIMES_WITH_THUMBNAILS:
            path = CC.GetThumbnailPath(hash, full_size=False)
        elif mime in HC.AUDIO:
            path = HC.STATIC_DIR + os.path.sep + 'audio_resized.png'
        elif mime in HC.VIDEO:
            path = HC.STATIC_DIR + os.path.sep + 'video_resized.png'
        elif mime == HC.APPLICATION_FLASH:
            path = HC.STATIC_DIR + os.path.sep + 'flash_resized.png'
        elif mime == HC.APPLICATION_PDF:
            path = HC.STATIC_DIR + os.path.sep + 'pdf_resized.png'
        else:
            path = HC.STATIC_DIR + os.path.sep + 'hydrus_resized.png'

        response_context = HC.ResponseContext(200, path=path)

        return response_context
Пример #2
0
    def _threadDoPOSTJob(self, request):

        admin_account = request.hydrus_account

        admin_account_key = admin_account.GetAccountKey()

        action = request.hydrus_args['action']

        subject_identifiers = request.hydrus_args['subject_identifiers']

        subject_account_keys = {
            HC.app.Read('account_key_from_identifier', self._service_key,
                        subject_identifier)
            for subject_identifier in subject_identifiers
        }

        kwargs = request.hydrus_args  # for things like expires, title, and so on

        HC.app.Write('account', self._service_key, admin_account_key, action,
                     subject_account_keys, kwargs)

        session_manager = HC.app.GetManager('restricted_services_sessions')

        session_manager.RefreshAccounts(self._service_key,
                                        subject_account_keys)

        response_context = HC.ResponseContext(200)

        return response_context
Пример #3
0
    def _threadDoPOSTJob(self, request):

        news = request.hydrus_args['news']

        HC.app.Write('news', self._service_key, news)

        response_context = HC.ResponseContext(200)

        return response_context
Пример #4
0
    def _threadDoPOSTJob(self, request):

        #threading.Thread( target = HC.app.Write, args = ( 'backup', ), name = 'Backup Thread' ).start()

        HC.app.Write('backup')

        response_context = HC.ResponseContext(200)

        return response_context
Пример #5
0
    def _threadDoPOSTJob(self, request):

        edit_log = request.hydrus_args['edit_log']

        HC.app.Write('account_types', self._service_key, edit_log)

        response_context = HC.ResponseContext(200)

        return response_context
Пример #6
0
    def _threadDoGETJob(self, request):

        account_types = HC.app.Read('account_types', self._service_key)

        body = yaml.safe_dump({'account_types': account_types})

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

        return response_context
Пример #7
0
    def _threadDoGETJob(self, request):

        petition = HC.app.Read('petition', self._service_key)

        body = yaml.safe_dump({'petition': petition})

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

        return response_context
Пример #8
0
    def _threadDoGETJob(self, request):

        services_info = HC.app.Read('services_info')

        body = yaml.safe_dump({'services_info': services_info})

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

        return response_context
Пример #9
0
    def _threadDoGETJob(self, request):

        account = request.hydrus_account

        body = yaml.safe_dump({'account': account})

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

        return response_context
Пример #10
0
    def _threadDoGETJob(self, request):

        access_key = HC.app.Read('init')

        body = yaml.safe_dump({'access_key': access_key})

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

        return response_context
Пример #11
0
    def _threadDoGETJob(self, request):

        stats = HC.app.Read('stats', self._service_key)

        body = yaml.safe_dump({'stats': stats})

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

        return response_context
Пример #12
0
    def _threadDoGETJob(self, request):

        hash = request.hydrus_args['hash']

        path = CC.GetThumbnailPath(hash)

        response_context = HC.ResponseContext(200, path=path)

        return response_context
Пример #13
0
    def _threadDoGETJob(self, request):

        begin = request.hydrus_args['begin']

        path = SC.GetUpdatePath(self._service_key, begin)

        response_context = HC.ResponseContext(200, path=path, is_yaml=True)

        return response_context
Пример #14
0
    def _threadDoGETJob(self, request):

        hash = request.hydrus_args['hash']

        (ip, timestamp) = HC.app.Read('ip', self._service_key, hash)

        body = yaml.safe_dump({'ip': ip, 'timestamp': timestamp})

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

        return response_context
Пример #15
0
    def _threadDoGETJob(self, request):

        hash = request.hydrus_args['hash']

        # don't I need to check that we aren't stealing the file from another service?

        path = SC.GetPath('thumbnail', hash)

        response_context = HC.ResponseContext(200, path=path)

        return response_context
Пример #16
0
    def _threadDoGETJob(self, request):

        registration_key = self._parseAccessKey(request)

        access_key = HC.app.Read('access_key', registration_key)

        body = yaml.safe_dump({'access_key': access_key})

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

        return response_context
Пример #17
0
    def _threadDoGETJob(self, request):

        access_key = self._parseAccessKey(request)

        verified = HC.app.Read('verify_access_key', self._service_key,
                               access_key)

        body = yaml.safe_dump({'verified': verified})

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

        return response_context
Пример #18
0
    def _threadDoPOSTJob(self, request):

        account = request.hydrus_account

        account_key = account.GetAccountKey()

        update = request.hydrus_args['update']

        HC.app.Write('update', self._service_key, account_key, update)

        response_context = HC.ResponseContext(200)

        return response_context
Пример #19
0
    def _threadDoGETJob(self, request):

        share_key = request.hydrus_args['share_key']
        hash = request.hydrus_args['hash']

        local_booru_manager = HC.app.GetManager('local_booru')

        local_booru_manager.CheckFileAuthorised(share_key, hash)

        path = CC.GetFilePath(hash)

        response_context = HC.ResponseContext(200, path=path)

        return response_context
Пример #20
0
    def _threadDoPOSTJob(self, request):

        account = request.hydrus_account

        account_key = account.GetAccountKey()

        file_dict = request.hydrus_args

        file_dict['ip'] = request.getClientIP()

        HC.app.Write('file', self._service_key, account_key, file_dict)

        response_context = HC.ResponseContext(200)

        return response_context
Пример #21
0
    def _threadDoGETJob(self, request):

        subject_identifier = request.hydrus_args['subject_identifier']

        subject_account_key = HC.app.Read('account_key_from_identifier',
                                          self._service_key,
                                          subject_identifier)

        account_info = HC.app.Read('account_info', self._service_key,
                                   subject_account_key)

        body = yaml.safe_dump({'account_info': account_info})

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

        return response_context
Пример #22
0
    def _threadDoPOSTJob(self, request):

        account = request.hydrus_account

        account_key = account.GetAccountKey()

        edit_log = request.hydrus_args['edit_log']

        service_keys_to_access_keys = HC.app.Write('services', account_key,
                                                   edit_log)

        body = yaml.safe_dump(
            {'service_keys_to_access_keys': service_keys_to_access_keys})

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

        return response_context
Пример #23
0
    def _threadDoGETJob(self, request):

        num = request.hydrus_args['num']
        title = request.hydrus_args['title']

        if 'lifetime' in request.hydrus_args:
            lifetime = request.hydrus_args['lifetime']
        else:
            lifetime = None

        registration_keys = HC.app.Read('registration_keys', self._service_key,
                                        num, title, lifetime)

        body = yaml.safe_dump({'registration_keys': registration_keys})

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

        return response_context
Пример #24
0
    def _threadDoGETJob(self, request):

        access_key = self._parseAccessKey(request)

        session_manager = HC.app.GetManager('restricted_services_sessions')

        (session_key,
         expires) = session_manager.AddSession(self._service_key, access_key)

        now = HC.GetNow()

        max_age = now - expires

        cookies = [('session_key', session_key.encode('hex'), {
            'max_age': max_age,
            'path': '/'
        })]

        response_context = HC.ResponseContext(200, cookies=cookies)

        return response_context
Пример #25
0
    def _threadDoGETJob(self, request):

        # in future, make this a standard frame with a search key that'll load xml or yaml AJAX stuff
        # with file info included, so the page can sort and whatever

        share_key = request.hydrus_args['share_key']

        local_booru_manager = HC.app.GetManager('local_booru')

        local_booru_manager.CheckShareAuthorised(share_key)

        (name, text, timeout,
         media_results) = local_booru_manager.GetGalleryInfo(share_key)

        body = '''<html>
    <head>'''

        if name == '':
            body += '''
        <title>hydrus network local booru share</title>'''
        else:
            body += '''
        <title>''' + name + '''</title>'''

        body += '''
        
        <link href="hydrus.ico" rel="shortcut icon" />
        <link href="style.css" rel="stylesheet" type="text/css" />'''

        (thumbnail_width,
         thumbnail_height) = HC.options['thumbnail_dimensions']

        body += '''
        <style>
            .thumbnail_container { width: ''' + str(
            thumbnail_width) + '''px; height: ''' + str(
                thumbnail_height) + '''px; }
        </style>'''

        body += '''
    </head>
    <body>'''

        body += '''
        <div class="timeout">This share ''' + HC.ConvertTimestampToPrettyExpires(
            timeout) + '''.</div>'''

        if name != '': body += '''
        <h3>''' + name + '''</h3>'''

        if text != '':

            newline = '''</p>
        <p>'''

            body += '''
        <p>''' + text.replace(os.linesep, newline).replace(
                '\n', newline) + '''</p>'''

        body += '''
        <div class="media">'''

        for media_result in media_results:

            hash = media_result.GetHash()
            mime = media_result.GetMime()

            # if mime in flash or pdf or whatever, get other thumbnail

            body += '''
            <span class="thumbnail">
                <span class="thumbnail_container">
                    <a href="page?share_key=''' + share_key.encode(
                'hex') + '''&hash=''' + hash.encode('hex') + '''">
                        <img src="thumbnail?share_key=''' + share_key.encode(
                    'hex') + '''&hash=''' + hash.encode('hex') + '''" />
                    </a>
                </span>
            </span>'''

        body += '''
        </div>
        <div class="footer"><a href="http://hydrusnetwork.github.io/hydrus/">hydrus network</a></div>
    </body>
</html>'''

        response_context = HC.ResponseContext(200,
                                              mime=HC.TEXT_HTML,
                                              body=body)

        return response_context
Пример #26
0
    def _errbackHandleProcessingError(self, failure, request):

        do_yaml = True

        try:

            # the error may have occured before user agent was set up!
            if not request.is_hydrus_user_agent: do_yaml = False

        except:
            pass

        if do_yaml:

            default_mime = HC.APPLICATION_YAML
            default_encoding = lambda x: yaml.safe_dump(HC.u(x))

        else:

            default_mime = HC.TEXT_HTML
            default_encoding = lambda x: HC.u(x)

        if failure.type == KeyError:
            response_context = HC.ResponseContext(
                403,
                mime=default_mime,
                body=default_encoding(
                    'It appears one or more parameters required for that request were missing:'
                    + os.linesep + failure.getTraceback()))
        elif failure.type == HydrusExceptions.PermissionException:
            response_context = HC.ResponseContext(401,
                                                  mime=default_mime,
                                                  body=default_encoding(
                                                      failure.value))
        elif failure.type == HydrusExceptions.ForbiddenException:
            response_context = HC.ResponseContext(403,
                                                  mime=default_mime,
                                                  body=default_encoding(
                                                      failure.value))
        elif failure.type == HydrusExceptions.NotFoundException:
            response_context = HC.ResponseContext(404,
                                                  mime=default_mime,
                                                  body=default_encoding(
                                                      failure.value))
        elif failure.type == HydrusExceptions.NetworkVersionException:
            response_context = HC.ResponseContext(426,
                                                  mime=default_mime,
                                                  body=default_encoding(
                                                      failure.value))
        elif failure.type == HydrusExceptions.SessionException:
            response_context = HC.ResponseContext(403,
                                                  mime=default_mime,
                                                  body=default_encoding(
                                                      failure.value))
        else:

            print(failure.getTraceback())

            response_context = HC.ResponseContext(
                500,
                mime=default_mime,
                body=default_encoding(
                    'The repository encountered an error it could not handle! Here is a dump of what happened, which will also be written to your client.log file. If it persists, please forward it to [email protected]:'
                    + os.linesep * 2 + failure.getTraceback()))

        request.hydrus_response_context = response_context

        return request
Пример #27
0
    def _threadDoGETJob(self, request):

        share_key = request.hydrus_args['share_key']
        hash = request.hydrus_args['hash']

        local_booru_manager = HC.app.GetManager('local_booru')

        local_booru_manager.CheckFileAuthorised(share_key, hash)

        (name, text, timeout,
         media_result) = local_booru_manager.GetPageInfo(share_key, hash)

        body = '''<html>
    <head>'''

        if name == '':
            body += '''
        <title>hydrus network local booru share</title>'''
        else:
            body += '''
        <title>''' + name + '''</title>'''

        body += '''
        
        <link href="hydrus.ico" rel="shortcut icon" />
        <link href="style.css" rel="stylesheet" type="text/css" />'''

        body += '''
    </head>
    <body>'''

        body += '''
        <div class="timeout">This share ''' + HC.ConvertTimestampToPrettyExpires(
            timeout) + '''.</div>'''

        if name != '': body += '''
        <h3>''' + name + '''</h3>'''

        if text != '':

            newline = '''</p>
        <p>'''

            body += '''
        <p>''' + text.replace(os.linesep, newline).replace(
                '\n', newline) + '''</p>'''

        body += '''
        <div class="media">'''

        mime = media_result.GetMime()

        if mime in HC.IMAGES:

            (width, height) = media_result.GetResolution()

            body += '''
            <img width="''' + str(width) + '''" height="''' + str(
                height) + '''" src="file?share_key=''' + share_key.encode(
                    'hex') + '''&hash=''' + hash.encode('hex') + '''" />'''

        elif mime in HC.VIDEO:

            (width, height) = media_result.GetResolution()

            body += '''
            <video width="''' + str(width) + '''" height="''' + str(
                height
            ) + '''" controls="" loop="" autoplay="" src="file?share_key=''' + share_key.encode(
                'hex') + '''&hash=''' + hash.encode('hex') + '''" />
            <p><a href="file?share_key=''' + share_key.encode(
                    'hex') + '''&hash=''' + hash.encode(
                        'hex') + '''">link to ''' + HC.mime_string_lookup[
                            mime] + ''' file</a></p>'''

        elif mime == HC.APPLICATION_FLASH:

            (width, height) = media_result.GetResolution()

            body += '''
            <embed width="''' + str(width) + '''" height="''' + str(
                height) + '''" src="file?share_key=''' + share_key.encode(
                    'hex') + '''&hash=''' + hash.encode('hex') + '''" />
            <p><a href="file?share_key=''' + share_key.encode(
                        'hex') + '''&hash=''' + hash.encode(
                            'hex') + '''">link to ''' + HC.mime_string_lookup[
                                mime] + ''' file</a></p>'''

        else:

            body += '''
            <p><a href="file?share_key=''' + share_key.encode(
                'hex') + '''&hash=''' + hash.encode(
                    'hex') + '''">link to ''' + HC.mime_string_lookup[
                        mime] + ''' file</a></p>'''

        body += '''
        </div>
        <div class="footer"><a href="http://hydrusnetwork.github.io/hydrus/">hydrus network</a></div>
    </body>
</html>'''

        response_context = HC.ResponseContext(200,
                                              mime=HC.TEXT_HTML,
                                              body=body)

        return response_context