Example #1
0
File: dat.py Project: disunbow/saku
    def replace(match):
        link = match.group(1)
        # saku's link format
        for r in (r"^(?P<title>[^/]+)$",
                  r"^/(?P<type>[a-z]+)/(?P<title>[^/]+)$",
                  r"^(?P<title>[^/]+)/(?P<id>[0-9a-f]{8})$",
                  r"^/(?P<type>[a-z]+)/(?P<title>[^/]+)/(?P<id>[0-9a-f]{8})$"):
            m = re.match(r, link)
            if m:
                d = m.groupdict()
                _title = d['title']
                type = d.get('type', None)
                id = d.get('id', None)
                break
        else:
            return match.group(0)

        if not type:
            type = 'thread'
        file = title.file_encode(type, _title)
        datkey = keylib.get_datkey(file)
        if id is None:
            # same `board` is required for the dedicated browser to work properly
            url = 'http://{}/test/read.cgi/{}/{}/'.format(dat_host, board, datkey)
            return '[[{title}({url})]]'.format(title=_title, url=url)
        else:
            # anchor to specific comment
            cache = cachelib.Cache(file)
            table = ResTable(cache)
            no = table[id]
            # this format url expect that dedicated browser get res number
            url = 'http://{}/test/read.cgi/{}/{}/{}'.format(dat_host, board, datkey, no)
            return '[[{title}(&gt;&gt;{no} {url})]]'.format(title=_title, no=no, url=url)
Example #2
0
def post_comment_app(env, resp):
    # utils.log('post_comment_app')
    subject, name, mail, body, datkey = _get_comment_data(env)

    info = {'host': env.get('REMOTE_ADDR', ''),
            'name': name,
            'mail': mail,
            'body': body}

    if body == '':
        return error_resp('本文がありません.', resp, **info)

    if subject:
        key = title.file_encode('thread', subject)
    else:
        key = keylib.get_filekey(datkey)

    if (not subject and not key):
        return error_resp('フォームが変です.', resp, **info)



    table = dat.ResTable(cache.Cache(key))
    def replace(match):
        no = int(match.group(1))
        return '>>' + table[no]
    # replace number anchor to id anchor
    body = re.sub(r'>>([1-9][0-9]*)', replace, body)  # before escape '>>'

    if name.find('#') < 0:
        passwd = ''
    else:
        name, passwd = name.split('#', 1)

    if (passwd and not env['shingetsu.isadmin']):
        return error_resp('自ノード以外で署名機能は使えません', resp, **info)

    post_comment(key, name, mail, body, passwd)
    resp('200 OK', [('Content-Type', 'text/html; charset=shift_jis')])
    return [success_msg.encode('sjis')]
Example #3
0
File: dat.py Project: namuyan/saku
    def replace(match):
        link = match.group(1)
        # saku's link format
        for r in (r"^(?P<title>[^/]+)$",
                  r"^/(?P<type>[a-z]+)/(?P<title>[^/]+)$",
                  r"^(?P<title>[^/]+)/(?P<id>[0-9a-f]{8})$",
                  r"^/(?P<type>[a-z]+)/(?P<title>[^/]+)/(?P<id>[0-9a-f]{8})$"):
            m = re.match(r, link)
            if m:
                d = m.groupdict()
                _title = d['title']
                type = d.get('type', None)
                id = d.get('id', None)
                break
        else:
            return match.group(0)

        if not type:
            type = 'thread'
        file = title.file_encode(type, _title)
        datkey = keylib.get_datkey(file)
        if id is None:
            # same `board` is required for the dedicated browser to work properly
            url = 'http://{}/test/read.cgi/{}/{}/'.format(
                dat_host, board, datkey)
            return '[[{title}({url})]]'.format(title=_title, url=url)
        else:
            # anchor to specific comment
            cache = cachelib.Cache(file)
            table = ResTable(cache)
            no = table[id]
            # this format url expect that dedicated browser get res number
            url = 'http://{}/test/read.cgi/{}/{}/{}'.format(
                dat_host, board, datkey, no)
            return '[[{title}(&gt;&gt;{no} {url})]]'.format(title=_title,
                                                            no=no,
                                                            url=url)
Example #4
0
File: post.py Project: namuyan/saku
def post_comment_app(env, resp):
    # print('post', env)
    if env['REQUEST_METHOD'] != 'POST':
        resp("404 Not Found", [('Content-Type', 'text/plain')])
        return [b'404 Not Found']

    # utils.log('post_comment_app')
    subject, name, mail, body, datkey = _get_comment_data(env)

    info = {
        'host': env.get('REMOTE_ADDR', ''),
        'name': name,
        'mail': mail,
        'body': body
    }

    if body == '':
        return error_resp('本文がありません.', resp, **info)

    if subject:
        key = title.file_encode('thread', subject)
    else:
        key = keylib.get_filekey(datkey)

    has_auth = env.get('shingetsu.isadmin', False) or env.get(
        'shingetsu.isfriend', False)

    referer = env.get('HTTP_REFERER', '')
    m = re.search(r'/2ch_([^/]+)/', referer)
    tag = None
    if m and has_auth:
        tag = title.file_decode('dummy_' + m.group(1))

    if cache.Cache(key).exists():
        pass
    elif has_auth:
        pass
    elif subject:
        return error_resp('掲示版を作る権限がありません', resp, **info)
    else:
        return error_resp('掲示版がありません', resp, **info)

    if (not subject and not key):
        return error_resp('フォームが変です.', resp, **info)

    table = dat.ResTable(cache.Cache(key))

    def replace(match):
        no = int(match.group(1))
        return '>>' + table[no]

    # replace number anchor to id anchor
    body = re.sub(r'>>([1-9][0-9]*)', replace, body)  # before escape '>>'

    if name.find('#') < 0:
        passwd = ''
    else:
        name, passwd = name.split('#', 1)

    if (passwd and not env['shingetsu.isadmin']):
        return error_resp('自ノード以外で署名機能は使えません', resp, **info)

    try:
        post_comment(env, key, name, mail, body, passwd, tag)
    except SpamError:
        return error_resp('スパムとみなされました', resp, **info)

    resp('200 OK', [('Content-Type', 'text/html; charset=Shift_JIS')])
    return [success_msg.encode('cp932', 'replace')]
Example #5
0
def post_comment_app(env, resp):
    # print('post', env)
    if env['REQUEST_METHOD'] != 'POST':
        resp("404 Not Found", [('Content-Type', 'text/plain')])
        return [b'404 Not Found']

    # utils.log('post_comment_app')
    subject, name, mail, body, datkey = _get_comment_data(env)

    info = {'host': env.get('REMOTE_ADDR', ''),
            'name': name,
            'mail': mail,
            'body': body}

    if body == '':
        return error_resp('本文がありません.', resp, **info)


    if subject:
        key = title.file_encode('thread', subject)
    else:
        key = keylib.get_filekey(datkey)


    has_auth = env.get('shingetsu.isadmin', False) or env.get('shingetsu.isfriend', False)

    referer = env.get('HTTP_REFERER', '')
    m = re.search(r'/2ch_([^/]+)/', referer)
    tag = None
    if m and has_auth:
        tag = title.file_decode('dummy_' + m.group(1))


    if cache.Cache(key).exists():
        pass
    elif has_auth:
        pass
    elif subject:
        return error_resp('掲示版を作る権限がありません', resp, **info)
    else:
        return error_resp('掲示版がありません', resp, **info)

    if (not subject and not key):
        return error_resp('フォームが変です.', resp, **info)

    table = dat.ResTable(cache.Cache(key))
    def replace(match):
        no = int(match.group(1))
        return '>>' + table[no]
    # replace number anchor to id anchor
    body = re.sub(r'>>([1-9][0-9]*)', replace, body)  # before escape '>>'

    if name.find('#') < 0:
        passwd = ''
    else:
        name, passwd = name.split('#', 1)

    if (passwd and not env['shingetsu.isadmin']):
        return error_resp('自ノード以外で署名機能は使えません', resp, **info)


    try:
        post_comment(env, key, name, mail, body, passwd, tag)
    except SpamError:
        return error_resp('スパムとみなされました', resp, **info)

    resp('200 OK', [('Content-Type', 'text/html; charset=Shift_JIS')])
    return [success_msg.encode('cp932', 'replace')]