def processVouch(sourceURL, targetURL, vouchDomain):
    """Determine if a vouch domain is valid.

    This implements a very simple method for determining if a vouch should
    be considered valid:
    1. does the vouch domain have it's own webmention endpoint
    2. does the vouch domain have an indieauth endpoint
    3. does the domain exist in the list of domains i've linked to

    yep, super simple but enough for me to test implement vouches
    """
    vouchFile = os.path.join(cfg['basepath'], 'vouch_domains.txt')
    with open(vouchFile, 'r') as h:
        vouchDomains = []
        for domain in h.readlines():
            vouchDomains.append(domain.strip().lower())

    if vouchDomain.lower() in vouchDomains:
        result = True
    else:
        wmStatus, wmUrl = ronkyuu.discoverEndpoint(vouchDomain, test_urls=False)
        if wmUrl is not None and wmStatus == 200:
            authEndpoints = ninka.indieauth.discoverAuthEndpoints(vouchDomain)

            if 'authorization_endpoint' in authEndpoints:
                authURL = None
                for url in authEndpoints['authorization_endpoint']:
                    authURL = url
                    break
                if authURL is not None:
                    result = True
                    with open(vouchFile, 'a+') as h:
                        h.write('\n%s' % vouchDomain)
Beispiel #2
0
def processVouch(sourceURL, targetURL, vouchDomain):
    """Determine if a vouch domain is valid.

    This implements a very simple method for determining if a vouch should
    be considered valid:
    1. does the vouch domain have it's own webmention endpoint
    2. does the vouch domain have an indieauth endpoint
    3. does the domain exist in the list of domains i've linked to

    yep, super simple but enough for me to test implement vouches
    """
    vouchFile = os.path.join(cfg['basepath'], 'vouch_domains.txt')
    with open(vouchFile, 'r') as h:
        vouchDomains = []
        for domain in h.readlines():
            vouchDomains.append(domain.strip().lower())

    if vouchDomain.lower() in vouchDomains:
        result = True
    else:
        wmStatus, wmUrl = ronkyuu.discoverEndpoint(vouchDomain,
                                                   test_urls=False)
        if wmUrl is not None and wmStatus == 200:
            authEndpoints = ninka.indieauth.discoverAuthEndpoints(vouchDomain)

            if 'authorization_endpoint' in authEndpoints:
                authURL = None
                for url in authEndpoints['authorization_endpoint']:
                    authURL = url
                    break
                if authURL is not None:
                    result = True
                    with open(vouchFile, 'a+') as h:
                        h.write('\n%s' % vouchDomain)
Beispiel #3
0
def handle_root():
    source = request.form['source']
    target = request.form['target']

    if source == target:
        return Response(response='source same as target', status=400)

    if not discoverEndpoint(target)[1]:
        return Response(response='target does not support webmentions',
                        status=400)

    # find mention in source
    result = findMentions(source, target)

    if result['status'] != 200:
        return Response(response='error fetching source', status=400)

    if not result['refs']:
        return Response(response='target not found in source', status=400)

    parsed = mf2py.Parser(url=source).to_dict()
    r = commit_file(webmention_path(source, target), yaml.dump(parsed))
    if r.status_code != 201:
        print('failed to post to github: ' + r.text)
        raise Exception('failed to post to github: ' + str(r))
    return Response(status=201)
Beispiel #4
0
    def runTest(self):
        status_code, webmention_url = ronkyuu.discoverEndpoint('http://localhost:9999')

        assert status_code == 200

        result = ronkyuu.sendWebmention('http://boathole.org/testing', 'http://localhost:9999/article2', webmention_url)

        assert result.status_code == 200
Beispiel #5
0
def send_webmention(site_url, source_url, target_url):
    abs_url = os.path.join(site_url, source_url)
    print(f'Sending webmention from {abs_url} to {target_url}')
    status, endpoint_url = discoverEndpoint(target_url)
    if status == requests.codes.ok and endpoint_url is not None:
        r = sendWebmention(abs_url, target_url, endpoint_url)
        if not r.ok:
            print(f'Webmention failed with {r.status_code}')
            print(f'Error information {r.json()}')
        return r
    else:
        print(f'Failed to discover endpoint: status: {status}, ' +
              f'endpoint: {endpoint_url}')
        return None
Beispiel #6
0
    def runTest(self):
        with HTTMock(mock_response):
            for urlpath in test_data.keys():
                url = 'http://%s' % urlpath
                if urlpath in odd_endpoints:
                    endpoint = odd_endpoints[urlpath]
                else:
                    endpoint = urlparse('%s/webmention' % url).path

                rc, href, debug = discoverEndpoint(url, debug=True)

                wmUrl = urlparse(href)

                assert wmUrl.netloc == 'webmention.rocks'
                assert wmUrl.path == endpoint
Beispiel #7
0
    def runTest(self):
        with HTTMock(mock_response):
            for urlpath in test_data.keys():
                url = 'http://%s' % urlpath
                if urlpath in odd_endpoints:
                    endpoint = odd_endpoints[urlpath]
                else:
                    endpoint = urlparse('%s/webmention' % url).path

                rc, href = discoverEndpoint(url)

                wmUrl = urlparse(href)

                assert wmUrl.netloc == 'webmention.rocks'
                assert wmUrl.path   == endpoint
def handle_root():
    source = request.form['source']
    target = request.form['target']

    if source == target:
        return Response(response='source URL is the same as target URL',
                        status=400)

    if not target.startswith(os.environ['ME']):
        return Response(response='webmentions not supported on target domain',
                        status=400)

    if not discoverEndpoint(target)[1]:
        return Response(response='target URL does not support webmentions',
                        status=400)

    q = queue()
    q.enqueue(process_webmention, commit_url(source, target), source, target)
    return Response(status=202)
def handle_root():
    source = request.form['source']
    target = request.form['target']

    if source == target:
        return Response(response='source URL is the same as target URL',
                        status=400)

    if not target.startswith(app.config['WEBSITE_URL']):
        return Response(
            response='webmentions not supported on supplied target domain',
            status=400)

    if not discoverEndpoint(target)[1]:
        return Response(response='target URL does not support webmentions',
                        status=400)

    commit_url = app.config['WEBSITE_CONTENTS'] + webmention_path(
        source, target)
    q = Queue(connection=Redis())
    q.enqueue(process_webmention, commit_url, source, target)
    return Response(status=202)
Beispiel #10
0
def processVouch(sourceURL, targetURL, vouchDomain):
    """Determine if the vouch domain is valid.

    This implements a very simple method for determining if a vouch should
    be considered valid:
      1. does the vouch domain have it's own webmention endpoint
      2. does the vouch domain have an indieauth endpoint
      3. does the domain exist in the list of domains i've linked to
    """
    result       = False
    vouchDomains = []
    vouchFile    = os.path.join(current_app.config['SITE_CONTENT'], 'vouch_domains.txt')
    if os.isfile(vouchFile):
        with open(vouchFile, 'r') as h:
            for domain in h.readlines():
                vouchDomains.append(domain.strip().lower())

    # result = ronkyuu.vouch(sourceURL, targetURL, vouchDomain, vouchDomains)

    if vouchDomain.lower() in vouchDomains:
        result = True
    else:
        wmStatus, wmUrl = ronkyuu.discoverEndpoint(vouchDomain, test_urls=False)
        if wmUrl is not None and wmStatus == 200:
            authEndpoints = ninka.indieauth.discoverAuthEndpoints(vouchDomain)

            if 'authorization_endpoint' in authEndpoints:
                authURL = None
                for url in authEndpoints['authorization_endpoint']:
                    authURL = url
                    break
                if authURL is not None:
                    result = True
                    with open(vouchFile, 'a+') as h:
                        h.write('\n%s' % vouchDomain)
    return result
Beispiel #11
0
    cfg = ronkyuu.discoverConfig(args.eventConfigFile)

    domains = []  # cfg.get('domains', [])
    sourceURL = args.sourceURL
    vouchDomain = args.vouch

    print('Scanning %s for mentions' % sourceURL)
    if vouchDomain is not None:
        print('vouch domain present and will be sent')

    mentions = ronkyuu.findMentions(sourceURL, domains)

    print(mentions['refs'])

    for href in mentions['refs']:
        if sourceURL != href:
            print(href)
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href, test_urls=False)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL,
                                                     href,
                                                     wmUrl,
                                                     vouchDomain=vouchDomain)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' %
                          status_code)
Beispiel #12
0
    parser.add_argument('--vouch',           default=None)
    parser.add_argument('--eventConfigFile', default=None)

    args = parser.parse_args()
    cfg  = ronkyuu.discoverConfig(args.eventConfigFile)

    domains     = []  # cfg.get('domains', [])
    sourceURL   = args.sourceURL
    vouchDomain = args.vouch

    print('Scanning %s for mentions' % sourceURL)
    if vouchDomain is not None:
        print('vouch domain present and will be sent')

    mentions = ronkyuu.findMentions(sourceURL, domains)

    print(mentions['refs'])

    for href in mentions['refs']:
        if sourceURL != href:
            print(href)
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href, test_urls=False)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL, href, wmUrl, vouchDomain=vouchDomain)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' % status_code)
Beispiel #13
0
import argparse
import requests
import ronkyuu

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('sourceURL')
    parser.add_argument('--eventConfigFile', default=None)

    args = parser.parse_args()
    cfg  = ronkyuu.discoverConfig(args.eventConfigFile)

    domains   = [] #cfg.get('domains', [])
    sourceURL = args.sourceURL

    print('Scanning %s for mentions' % sourceURL)

    mentions = ronkyuu.findMentions(sourceURL, domains)
    for href in mentions:
        if sourceURL <> href:
            wmStatus, wmUrl = ronkyuu.discoverEndpoint(href)
            if wmUrl is not None and wmStatus == 200:
                print('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                status_code = ronkyuu.sendWebmention(sourceURL, href, wmUrl)

                if status_code == requests.codes.ok:
                    print('\twebmention sent successfully')
                else:
                    print('\twebmention send returned a status code of %s' % status_code)
Beispiel #14
0
def checkOutboundWebmentions(sourceURL, html, targetFile, update=False):
    logger.info('checking for outbound webmentions [%s]' % sourceURL)
    try:
        cached   = loadOutboundWebmentions(targetFile)
        found    = ronkyuu.findMentions(sourceURL, content=html)
        mentions = {}

        # loop thru webmentions found in our post and
        # check if they are new/updated or already seen
        for href in found['refs']:
            if sourceURL != href:
                logger.info(href)
                key     = 'webmention::%s::%s' % (sourceURL, href)
                keySeen = db.exists(key)
                if keySeen:
                    if update:
                        keySeen = False
                        s       = 'update forced'
                    else:
                        s = 'already processed'
                else:
                    s = 'new mention'
                logger.info('\t%s [%s]' % (s, key))
                mentions[key] = { 'key':     key,
                                  'href':   href,
                                  'keySeen': keySeen,
                                  'removed': False
                                }
        # loop thru found webmentions and check against cache for any removed
        for key in cached:
            if key not in mentions:
                mentions[key] = cached[key]
                mentions[key]['removed'] = True
                if 'keySeen' not in mentions[key]:
                    mentions[key]['keySeen'] = False
        removed = []
        for key in mentions:
            mention = mentions[key]
            logger.info('seen: %(keySeen)s removed: %(removed)s [%(key)s]' % mention)

            # send webmentions for new/updated or removed
            if mention['removed'] or not mention['keySeen']:
                if mention['removed']:
                    removed.append(key)

                href = mention['href']
                wmStatus, wmUrl, debug = ronkyuu.discoverEndpoint(href, test_urls=False, debug=True)
                logger.info('webmention endpoint discovery: %s [%s]' % (wmStatus, wmUrl))

                if len(debug) > 0:
                    logger.info('\n\tdebug: '.join(debug))
                if wmUrl is not None and wmStatus == 200:
                    logger.info('\tfound webmention endpoint %s for %s' % (wmUrl, href))
                    resp, debug = ronkyuu.sendWebmention(sourceURL, href, wmUrl, debug=True)
                    if len(debug) > 0:
                        logger.info('\n\tdebug: '.join(debug))
                    if resp.status_code == requests.codes.ok:
                        if key not in cached:
                            cached[key] = { 'key':    key,
                                            'href':   href,
                                            'wmUrl':  wmUrl,
                                            'status': resp.status_code
                                          }
                        if len(resp.history) == 0:
                            db.set(key, resp.status_code)
                            logger.info('\twebmention sent successfully')
                        else:
                            logger.info('\twebmention POST was redirected')
                    else:
                        logger.info('\twebmention send returned a status code of %s' % resp.status_code)
        for key in removed:
            del cached[key]
            db.delete(key)

        saveOutboundWebmentions(targetFile, cached)
    except:
        logger.exception('exception during checkOutboundWebmentions')
Beispiel #15
0
    def runTest(self):
        rc, href = discoverEndpoint('https://webmention.rocks/test/23/page')
        wmUrl = urlparse(href)

        assert wmUrl.netloc == 'webmention.rocks'
        assert wmUrl.path.startswith('/test/23/webmention-endpoint/')
Beispiel #16
0
 def runTest(self):
     result = ronkyuu.discoverEndpoint('http://localhost:9999')
     assert result[0] == 200
     assert result[1] == 'http://localhost:9999/webmention'
Beispiel #17
0
def checkOutboundWebmentions(sourceURL, html, targetFile, update=False):
    logger.info('checking for outbound webmentions [%s]' % sourceURL)
    try:
        cached = loadOutboundWebmentions(targetFile)
        found = ronkyuu.findMentions(sourceURL, content=html)
        mentions = {}

        # loop thru webmentions found in our post and
        # check if they are new/updated or already seen
        for href in found['refs']:
            if sourceURL != href:
                logger.info(href)
                key = 'webmention::%s::%s' % (sourceURL, href)
                keySeen = db.exists(key)
                if keySeen:
                    if update:
                        keySeen = False
                        s = 'update forced'
                    else:
                        s = 'already processed'
                else:
                    s = 'new mention'
                logger.info('\t%s [%s]' % (s, key))
                mentions[key] = {
                    'key': key,
                    'href': href,
                    'keySeen': keySeen,
                    'removed': False
                }
        # loop thru found webmentions and check against cache for any removed
        for key in cached:
            if key not in mentions:
                mentions[key] = cached[key]
                mentions[key]['removed'] = True
                if 'keySeen' not in mentions[key]:
                    mentions[key]['keySeen'] = False
        removed = []
        for key in mentions:
            mention = mentions[key]
            logger.info('seen: %(keySeen)s removed: %(removed)s [%(key)s]' %
                        mention)

            # send webmentions for new/updated or removed
            if mention['removed'] or not mention['keySeen']:
                if mention['removed']:
                    removed.append(key)

                href = mention['href']
                wmStatus, wmUrl, debug = ronkyuu.discoverEndpoint(
                    href, test_urls=False, debug=True)
                logger.info('webmention endpoint discovery: %s [%s]' %
                            (wmStatus, wmUrl))

                if len(debug) > 0:
                    logger.info('\n\tdebug: '.join(debug))
                if wmUrl is not None and wmStatus == 200:
                    logger.info('\tfound webmention endpoint %s for %s' %
                                (wmUrl, href))
                    resp, debug = ronkyuu.sendWebmention(sourceURL,
                                                         href,
                                                         wmUrl,
                                                         debug=True)
                    if len(debug) > 0:
                        logger.info('\n\tdebug: '.join(debug))
                    if resp.status_code == requests.codes.ok:
                        if key not in cached:
                            cached[key] = {
                                'key': key,
                                'href': href,
                                'wmUrl': wmUrl,
                                'status': resp.status_code
                            }
                        if len(resp.history) == 0:
                            db.set(key, resp.status_code)
                            logger.info('\twebmention sent successfully')
                        else:
                            logger.info('\twebmention POST was redirected')
                    else:
                        logger.info(
                            '\twebmention send returned a status code of %s' %
                            resp.status_code)
        for key in removed:
            del cached[key]
            db.delete(key)

        saveOutboundWebmentions(targetFile, cached)
    except:
        logger.exception('exception during checkOutboundWebmentions')
Beispiel #18
0
    def runTest(self):
        with HTTMock(tantek_mock):
            result = discoverEndpoint(tantek_url)

            assert result[1] == 'http://webmention.io/tantek.com/webmention'